Go-Ethereum

net.peerCount 為零:兩個礦工沒有連接

  • June 23, 2020

我正在嘗試在我自己的 PC 上使用Geth v1.9.15-stable-0f77f34b. 我已經使用 VMware Workstation Pro 在具有 Ubuntu 18.04 作業系統的虛擬機中安裝了 Geth。我想在虛擬機中創建兩個礦工。每個都在不同的終端執行,我遵循以下步驟:

1)創建兩個節點:

geth --datadir node1 account new
geth --datadir node2 account new

2)genesis.json

{
   "nonce": "0x0000000000000042",
   "timestamp": "0x0",
   "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
   "extraData": "0x",
   "gasLimit": "0x8000000",
   "difficulty": "0x400",
   "config": {},
   "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
   "coinbase": "0x3333333333333333333333333333333333333333", "alloc": { }
}

3)初始化創世:

geth --datadir node1 init ./genesis.json
geth --datadir node2 init ./genesis.json

4)要啟用我使用的節點:

geth --identity "name_of_your_node" --rpc --rpcport "8000" --rpccorsdomain "*" --datadir mode1 --port "30303" --nodiscover --rpcapi "db,eth,net,web3,personal,miner,admin" --networkid 1900 --nat "any"

geth --identity "name_of_your_node" --rpc --rpcport "8001" --rpccorsdomain "*" --datadir mode2 --port "30301" --nodiscover --rpcapi "db,eth,net,web3,personal,miner,admin" --networkid 1900 --nat "any"

5)互連節點:

geth attach http://127.0.0.1:8001
geth attach http://127.0.0.1:8000
  1. 將 Node1 設為管理節點,我使用此程式碼查找資訊:
admin.nodeInfo
{
 enode: "enode://b378a4f7d9454811a89954cb97bb19589564a8e1ef24ebda07c25c2ae2a8acf35c4c14b2fd84d2a0cf92b1586eff0ea592de5f8effb0e08b1616917edf3306f1@100.69.54.149:30303?discport=0",
 enr: "enr:-JO4QI-9oLlq2ZVbjMfEry_Kk7VJ65divD9HL7jFC3tl2WwkbTc6Bc4sIqaD9MTKAEQuDfWqSw_bwoy2nqy5MAfYgssHg2V0aMrJhPxk7ASDEYwwgmlkgnY0gmlwhGRFNpWJc2VjcDI1NmsxoQOzeKT32UVIEaiZVMuXuxlYlWSo4e8k69oHwlwq4qis84N0Y3CCdl8",
 id: "fb25937ad7ced1cf77a820fc34f93d42135cf2760508db94dd56c2ca05bb92b5",
 ip: "100.69.54.149",
 listenAddr: "[::]:30303",
 name: "Geth/name_of_your_node/v1.9.15-stable-0f77f34b/linux-amd64/go1.14.2",
 ports: {
   discovery: 0,
   listener: 30303
 },
 protocols: {
   eth: {
     config: {
       byzantiumBlock: 4370000,
       chainId: 1,
       constantinopleBlock: 7280000,
       daoForkBlock: 1920000,
       daoForkSupport: true,
       eip150Block: 2463000,
       eip150Hash: "0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0",
       eip155Block: 2675000,
       eip158Block: 2675000,
       ethash: {},
       homesteadBlock: 1150000,
       istanbulBlock: 9069000,
       muirGlacierBlock: 9200000,
       petersburgBlock: 7280000
     },
     difficulty: 17179869184,
     genesis: "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
     head: "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
     network: 1900
   }
 }
}

7)另一個節點我使用此程式碼連接到節點1:

admin.addPeer("enode://b378a4f7d9454811a89954cb97bb19589564a8e1ef24ebda07c25c2ae2a8acf35c4c14b2fd84d2a0cf92b1586eff0ea592de5f8effb0e08b1616917edf3306f1@100.69.54.149:30303?discport=0")
true

8)但節點未連接:

> net.peerCount
0
> net.listening
true

我錯過了什麼嗎?請幫忙?我還有一個問題:為什麼IPadmin.nodeInfo"100.69.54.149",不是我的IP怎麼改?

解決方案是添加--nat nonegeth --identity "name_of_your_node" --rpc --rpcport "8000" --rpccorsdomain "*" --datadir mode1 --port "30303" --nodiscover --rpcapi "db,eth,net,web3,personal,miner,admin" --networkid 1900 --nat none

引用自:https://ethereum.stackexchange.com/questions/84424