Go-Ethereum

net.getPeerCount() 給出了什麼?

  • March 21, 2022

我正在嘗試同步到乙太坊主網。

當將正在執行的 geth 附加到控制台並執行時,admin.peers 我得到以下輸出

[{
   caps: ["eth/63"],
   id: "147fd0986cdba18279e309149290431e874a2ff0d72a18d2a81bb02d2bf0b65456b7419eb21800516177767b5037449950a9ad7f3d06c910df760c89d76c9ff1",
   name: "Geth/v1.7.3-stable-4bb3c89d/darwin-amd64/go1.9.2",
   network: {
     localAddress: "10.10.25.218:59778",
     remoteAddress: "71.236.189.250:30303"
   },
   protocols: {
     eth: {
       difficulty: 17179869184,
       head: "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
       version: 63
     }
   }
}, {
   caps: ["eth/63"],
   id: "1bba662f185f45cd68465ee3b340ed107a1bc309c6e7f3ad4634e69fa5f864d4daf1a1188cf2cd38659027aee5d33daecf9d04f1a003b136cfa3605f22ca590b",
   name: "Geth/v1.7.2-stable-1db4ecdc/windows-amd64/go1.9",
   network: {
     localAddress: "10.10.25.218:59736",
     remoteAddress: "85.72.54.240:30303"
   },
   protocols: {
     eth: {
       difficulty: 17179869184,
       head: "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
       version: 63
     }
   }
}, {
   caps: ["eth/63"],
   id: "4630000bc70b789a45b58beba3944c050ac9998e55db40b6e8ea5df1da95bf1452863c3271f48341854a0de4f1a5ce6578c424ab04af510d68b1745125d26dac",
   name: "Geth/v1.7.2-stable-1db4ecdc/linux-amd64/go1.9",
   network: {
     localAddress: "10.10.25.218:50086",
     remoteAddress: "189.27.174.216:30303"
   },
   protocols: {
     eth: {
       difficulty: 17179869184,
       head: "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
       version: 63
     }
   }
}, {
   caps: ["eth/63"],
   id: "a4c00346511940ed69d408fb8801efd5ad2822985817c6f5f534591463befc00ba21c23a76c19e4ee9bb91b215b02300b9b7d14105711a0a4f75951f89e148a9",
   name: "Geth/v1.8.0-unstable-a139041d/linux-amd64/go1.9.2",
   network: {
     localAddress: "10.10.25.218:38442",
     remoteAddress: "46.29.13.213:30303"
   },
   protocols: {
     eth: {
       difficulty: 17179869184,
       head: "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
       version: 63
     }
   }
}, {
   caps: ["eth/63"],
   id: "ab3662c8e1b62b36444a50f87af14e7668a6afcf15f4d7a1fd3bb160dc945360378edb6ab63a7d518d26372c89fb559fd37f00010f9d090c2ecfdc303874a3f9",
   name: "Geth/v1.7.2-stable-1db4ecdc/windows-amd64/go1.9",
   network: {
     localAddress: "10.10.25.218:35660",
     remoteAddress: "95.43.38.32:30303"
   },
   protocols: {
     eth: {
       difficulty: 17179869184,
       head: "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
       version: 63
     }
   }
}, {
   caps: ["eth/63"],
   id: "d1254b0d24582469d3f0e8a4692f27155ad40d46ebc2c74a700d94e68d9f8fc903022140661185aa2367f5738ea9b75066e66f83076198e12643257701668467",
   name: "Geth/v1.8.0-unstable-3a5a5599/linux-amd64/go1.7.4",
   network: {
     localAddress: "10.10.25.218:33204",
     remoteAddress: "144.76.60.212:30303"
   },
   protocols: {
     eth: {
       difficulty: 17179869184,
       head: "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
       version: 63
     }
   }
}]

如果我執行net.getPeerCount(),我會得到低於輸出

   > net.getPeerCount()
     undefined
   >

我希望它能給我輸出的同行的數量admin.peers

如上所述,要查看屬性值 use net.peerCount,而不是 net.getPeerCount

net.peerCount()是一個返回連接到您的節點的 Peers 數量的命令。

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