[Ethereum] How to get Nodes on local Geth Private Network to Discover Peers OF THEIR PEERS

bootnodesdiscovery-protocolgo-ethereumnode-discoveryprivate-blockchain

I am working on a private blockchain that consists of 4 nodes running on different ports.

I am trying to get each node to communicate its connections to its peers, so the network would be fully-connected (each Node has each other Node as its peer). However, nodes are not discovering the peers of their peers.

Node 1 is designated as the bootstrap node, and Nodes 2 & 3 connect to it upon starting. However, Node 1 will have Nodes 2 & 3 as its peers while they will each only have Node 1 as its own peer. I want Nodes 2 & 3 to discover each other.

Additionally, when I run admin.addPeer(node4's enode), from Node 1, it is not broadcasted to its peers.

My question: How can I enable a peer-discovery protocol wherein every Node communicates all of its peers to each of its peers?

I understand that there are some hacks to get around this. Per instance, I can simply pass in each of the 3 other nodes' enode address to every node's --bootnodes in Geth. Or I can just use admin.addPeer() on each of its peer's admin.peers. But I think Geth has this automated somehow and I'd like to use their solution.

StartNode Script:

geth --networkid 63261 --mine --minerthreads 1 --datadir . --rpc --rpcport "8547" --port "30305" --rpccorsdomain "*" --nat "any" --rpcapi eth,web3,personal,net --unlock 0 --password "./node3password.sec" --ipcdisable --bootnodes "node1enode" console 2>> geth.log

[Edit]:

I had already initialized each of my nodes to point at my Private Network's Genesis JSON (./BCNetworkName.json) before running the StartNode script. geth --datadir ./NodeN init BCNetworkName.json

Best Answer

Bootnodes is a cheap and effective solution to aid the network self-discovery, but they need to catch up with a proper genesis file to isolate your network.

When you run geth, the genesis block is recreated from scratch and then it begin to sync with peers at block 1.

For you private blockchain, you need to provide this file to all of your nodes so they can talk to each other without having to run addpeers.

You can find more informations about the genesis block here

If you are familiar with docker, you can check this Github repository which play with the geth image in order to run a private network. You can learn a lot about peers self-discovery.

Related Topic