The Reason
The reason why your two geth
instances on the two different computers cannot find each other is that they do not know where to start searching for each other.
Note: I've shortened the node public key for easier reading in this answer. For example,
"a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c"
has been shortened to "a979....163c"
. You will have to use the full public keys when setting up your network.
In the mainnet public blockchain, each peer upon starting up will try to connect to the "bootnodes" to obtain an initial list of peers it can connect to. The address of these bootnodes are hardcoded into eth/backend.go lines 71-78 as shown below:
defaultBootNodes = []*discover.Node{
// ETH/DEV Go Bootnodes
discover.MustParseNode("enode://[email protected]:30303"), // IE
discover.MustParseNode("enode://[email protected]:30303"), // BR
discover.MustParseNode("enode://[email protected]:30303"), // SG
// ETH/DEV cpp-ethereum (poc-9.ethdev.com)
discover.MustParseNode("enode://[email protected]:30303"),
}
Once a node connects to the bootnode, it will get a list of addresses for potential peers to connect to, and it will try to connect to these peers.
There is no such starting point in your private network.
The Solution
On your private network, your geth
instances will not know where to start searching for each other and you will have to give it some hints. There are three ways you can do this - using the --bootnodes
command line parameter, adding a static-nodes.json
to your data directory, or adding a trusted-nodes.json
to your data directory.
Run geth
on each of your computers, and type admin.nodeInfo
into the command line:
> admin.nodeInfo
{
enode: "enode://d9d9....30d9@[::]:30301?discport=0",
id: "d9d9....30d9",
ip: "::",
listenAddr: "[::]:30301",
name: "Geth/v1.3.6/linux/go1.5.1",
ports: {
discovery: 0,
listener: 30301
},
...
}
What you will have to do is to get the enode information for both your computers. Replace the [::]
in the enode information with the IP address of your two computers and remove the ?discport=0
if it is present. Your enode information for each computer should then look like:
Solution 1 - The --bootnodes
Solution
This first --bootnodes
solution will require you to specify the bootnode of one computer's geth
instance to the other computer's geth
instance. So on Computer 1, you start up geth
adding the following parameter:
--bootnodes "enode://[email protected]:30303"
Solution 2 - The static-nodes.json
Solution
This second solution is to create the file static-nodes.json
in your --datadir
, so in your case, the file name and path should be ./blockchain/static-nodes.json
. On computer #1, this file should contain the enode information of computer #2, and vice versa. Alternatively, just create one static-nodes.json
with the enode information of both computers #1 and #2, and copy this static-nodes.json
to the --datadir
of both computers. The contents of this file should look like:
[
"enode://[email protected]:30303",
"enode://[email protected]:30303"
]
Solution 3 - The trusted-nodes.json
Solution
Same as solution #2, but use the file name trusted-nodes.json
instead of static-nodes.json
. The difference here is that trusted nodes don't add to count of peer nodes when the --maxpeers
limit is reached.
Use --maxpeers
And Don't Use --nodiscover
You may have to specify a non-zero --maxpeers
to get this working, for example, use the parameter:
geth ... --maxpeers 2 ...
And don't use --nodiscover
in your geth
command line, as this will turn off peer discovery.
Related Questions
Here are some related questions that may help you resolve your connection issues:
--nodiscover
is not set. Hmm, I suspect you read also the chapter about "setting up multiple node" github.com/ethereum/go-ethereum/wiki/… and the part about "common problems with connectivity" github.com/ethereum/go-ethereum/wiki/Connecting-to-the-network ?30303
.