[Ethereum] Extremely slow geth mining and synchronization for private blockchain

dockergo-ethereumminingprivate-blockchain

I am constructing a very simple 2 nodes private Ethereum network to study the mining behaviour. The consensus algorithm is ethash. In order for the 2 nodes to discover each other, I also setup a bootnode. All these nodes are running on different IP addresses. Basically I created a docker network and ran 1 bootnode container and 2 geth containers.

I successfully initialized the block (via geth init…), created 10 accounts for each node. Then I initiated the 2 geth instances to start mining, it went through the usual DAG generation. While generating DAG for epoch 1, the mining also started and I can see node1 mined 2 blocks and node2 mined 1 block. After DAG generation is completed, the mining simply stopped.

Here is my genesis.json file, BTW I had lowered the difficulty to 0x000010

{
  "config": {
    "chainId": 5493,
    "homesteadBlock": 1,
    "eip150Block": 2,
    "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "eip155Block": 3,
    "eip158Block": 3,
    "byzantiumBlock": 4,
    "ethash": {}
  },
  "nonce": "0x0",
  "timestamp": "0x5a9d2b4e",
  "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "gasLimit": "0x47b760",
  "difficulty": "0x000010",
  "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x0000000000000000000000000000000000000000",
  "alloc": {
    "0000000000000000000000000000000000000000": {
      "balance": "0x1"
    }
  },
  "number": "0x0",
  "gasUsed": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}

Here is the screenshots of my geth console. The top is node1 and bottom is node2. The geth instances are still busy working away – my CPU utilisation is max'ed out. But for the last 15 minutes, there is no activity reported on the geth consoles.

Screenshots of 2 geth consoles

Somehow things started to move again but very slowly.
As you see in the below screenshot, node1 continues to mine new block and it also discarded a bad propagated block (from node2). It also has some lines that said "Regenerated local transaction journal"

For node2, it also mined 1 new block and synchronised other blocks from node1.
As shown on the screenshot, the duration between block is very long 7mins to 20 mins. There is also a sidefork on node2.

This experiment is done with plain vanilla geth, no externally triggered transferred or smartcontract call.

Is there anything I miss here? I simply want the private network to behave like the ethereum mainnet, i.e. mine new block roughly every 10 seconds.

Very slow mining
The commands to launch the various nodes are

bootnode
file="/root/bootnode/enode"
if [ ! -f "$file" ]
  then
    echo "initialize bootnode"
    bootnode -genkey /root/bootnode/nodekeyfile
fi
bootnode -nodekey /root/bootnode/nodekeyfile

geth node
geth --networkid 5493 --bootnodes "$(echo -n 'enode://'; bootnode --writeaddress -nodekey /root/bootnode/nodekeyfile | tr -d '\n'; echo '@192.168.2.2:30301')" --mine --rpc --rpcport "8545" --port "30303" --rpccorsdomain "*" --nat "any" --rpcapi eth,web3,personal,net --etherbase 0 --unlock "$(cat /root/.ethereum/geth/security/coinbase)" --password /root/.ethereum/geth/security/password.sec

I basically shared the volume where bootnode nodekeyfile is stored among the 3 containers thus they can all construct the bootnode URL. Anyway, I don't think the bootnode is the issue as the 2 geth nodes are able to talk to each other.

Best Answer

I found the issue to the problem. I didn't allocate sufficient memory to my docker process. After I increased the docker memory allocation to 6GB, it works fine. Due to the lowered difficulty, I was even having blocks mined every 2 seconds.

Related Topic