Go-Ethereum

如何將交易發送到專用網路?

  • June 29, 2016

我已經在本地網路上建立了一個私有區塊鏈。我有一個節點在 Android 智能手機上執行,另一個在 Windows 7 上執行,我在兩者上都使用 Geth。

我從 Android 節點使用 eth.sendTransaction() 方法發送 Ether,結果得到 Tx Hash。然後我在 Windows 節點上開始探勘,但交易沒有添加到任何塊中。

我知道我的節點是連接的,因為 admin.peers() 的返回以及如果我從挖礦節點發送交易我可以轉移 Ether 的事實。

挖礦節點是否還有其他事情要做才能查看其他節點的交易?

編輯:節點的資訊

在 Windows 上執行節點:

geth --identity "ethRpi" --genesis "genesis.json" --rpc --rpcport "8080" --rpccorsdomain "*" --datadir "eth" --port "30303" --rpcapi "db,eth,net,web3" --networkid 2016 console

在 Android 上:

geth --ipcdisable --identity "ethRpi" --genesis genesis.json --fast --rpc --rpcport 8545 --rpcaddr 0.0.0.0 --port 30303 --rpcapi admin,db,eth,miner,net,personal,web3 --networkid 2016 --datadir=eth

在安卓上

>admin.peers
[{
   caps: [←[32m"eth/61"←[0m, ←[32m"eth/62"←[0m, ←[32m"eth/63"←[0m],
   id: ←[32m"efaa00ffc1d7955e97f4883d8497f4705520eca5a0f7ea63b3d2e2bcf9536fa0edd0cc2ebcf9974d6b2a90790491eefb351b0e135a61e8228f042c16d57d2df0"←[0m,
   name: ←[32m"Geth/v1.5.0-unstable-4f3f6e28/windows/go1.6.2/ethRpi"←[0m,
   network: {
     localAddress: ←[32m"192.168.68.111:30303"←[0m,
     remoteAddress: ←[32m"192.168.68.107:50740"←[0m
   },
   protocols: {
     eth: {
       difficulty: ←[31m9659008←[0m,
       head: ←[32m"163f33b0b9ba7c04cbef8e36796b6b2ef0bcb9af1fe1fa5be8fd05979cbcdc57"←[0m,
       version: ←[31m63←[0m
     }
   }
}]
>eth.pendingTransactions
[{
   blockHash: ←[1mnull←[0m,
   blockNumber: ←[1mnull←[0m,
   from: ←[32m"0xacc8770ed788bcb76fc14c570251585dd83925a8"←[0m,
   gas: ←[31m90000←[0m,
   gasPrice: ←[31m20000000000←[0m,
   hash: ←[32m"0x1d5ec2db286c52440b94e0d596467a15076c1a3ea2cb0995639d85677d051d69"←[0m,
   input: ←[32m"0x"←[0m,
   nonce: ←[31m0←[0m,
   to: ←[32m"0x52fa5791e401a4a33f045d5e34aea9976e5afd4f"←[0m,
   transactionIndex: ←[1mnull←[0m,
   value: ←[31m1000000000000000000←[0m
}]

在窗戶上

> admin.peers
[{
   caps: ["eth/61", "eth/62", "eth/63"],
   id: "a7ae958bf83ad6c659567110abd8a15535a23acd66cd2ccc5bf2333b5f2b4a49a35e80450c9848e658b625b69078ab675882b51e44c17cea4c278746381c0447",
   name: "Geth/v1.5.0-unstable-4f3f6e28/android/go1.6.2/\"ethRpi\"",
   network: {
     localAddress: "192.168.68.107:50740",
     remoteAddress: "192.168.68.111:30303"
   },
   protocols: {
     eth: {
       difficulty: 9659008,
       head: "163f33b0b9ba7c04cbef8e36796b6b2ef0bcb9af1fe1fa5be8fd05979cbcdc57",
       version: 63
     }
   }
}]
> eth.pendingTransactions
[]
>miner.start()
I0628 09:54:58.658192 miner/miner.go:119] Starting mining operation (CPU=4 TOT=5)
I0628 09:54:58.660192 miner/worker.go:555] commit new work on block 74 with 0 txs & 0 uncles. Took 999.8µs
I0628 10:00:26.560682 miner/worker.go:337] ??  Mined block (#74 / 0bebfb50). Wait 5 blocks for confirmatio
I0628 10:00:26.562682 miner/worker.go:555] commit new work on block 75 with 0 txs & 0 uncles. Took 999.9µs
I0628 10:00:26.562682 miner/worker.go:555] commit new work on block 75 with 0 txs & 0 uncles. Took 0
I0628 10:00:26.608677 miner/worker.go:337] ??  Mined stale block (#74 / 0bd0e716).
I0628 10:00:26.647674 miner/worker.go:555] commit new work on block 75 with 0 txs & 0 uncles. Took 0
I0628 10:00:29.670371 miner/worker.go:337] ??  Mined block (#74 / cd692c59). Wait 5 blocks for confirmation
I0628 10:00:29.671371 miner/worker.go:555] commit new work on block 75 with 0 txs & 0 uncles. Took 0
I0628 10:00:29.687370 miner/worker.go:337] ??  Mined block (#74 / c082d521). Wait 5 blocks for confirmation
I0628 10:00:29.688369 miner/worker.go:555] commit new work on block 75 with 0 txs & 0 uncles. Took 0
I0628 10:00:29.703368 miner/worker.go:555] commit new work on block 75 with 0 txs & 0 uncles. Took 0
I0628 10:00:31.953143 miner/worker.go:337] ??  Mined block (#75 / 542384a4). Wait 5 blocks for confirmation
I0628 10:00:35.181820 miner/worker.go:555] commit new work on block 76 with 0 txs & 2 uncles. Took 8.9991ms
I0628 10:00:35.183820 miner/worker.go:555] commit new work on block 76 with 0 txs & 2 uncles. Took 999.9µs
I0628 10:00:35.185820 miner/worker.go:555] commit new work on block 76 with 0 txs & 2 uncles. Took 0
I0628 10:00:39.623376 miner/worker.go:337] ??  Mined block (#76 / 18796f50). Wait 5 blocks for confirmation
I0628 10:00:39.743364 miner/worker.go:555] commit new work on block 77 with 0 txs & 0 uncles. Took 999.9µs
I0628 10:00:39.750363 miner/worker.go:555] commit new work on block 77 with 0 txs & 0 uncles. Took 0
I0628 10:00:42.795059 miner/worker.go:337] ??  Mined block (#77 / 651df4a0). Wait 5 blocks for confirmation
I0628 10:00:42.796059 miner/worker.go:555] commit new work on block 78 with 0 txs & 0 uncles. Took 999.9µs
I0628 10:00:42.815057 miner/worker.go:555] commit new work on block 78 with 0 txs & 0 uncles. Took 0
I0628 10:00:43.384000 miner/worker.go:337] ??  Mined block (#78 / 021c7f6a). Wait 5 blocks for confirmation
I0628 10:00:43.400998 miner/worker.go:555] commit new work on block 79 with 0 txs & 0 uncles. Took 0
I0628 10:00:43.444994 miner/worker.go:555] commit new work on block 79 with 0 txs & 0 uncles. Took 0
mI0628 10:00:43.923946 miner/worker.go:337] ??  Mined block (#79 / 8eef4802). Wait 5 blocks for confirmation

感謝@karalabe 在此消息中的解決方案:https ://gitter.im/ethereum/go-ethereum?at=57737aed1ac8bd1a4d8c8fef

實際上,在從其他節點探勘交易之前,必須先同步探勘節點。如果網路中只有一個礦工,它不會從其他節點獲取塊並認為自己沒有同步,因此它不包括完全同步之前的交易。

所以我只是在網路中添加了一個節點(Ubuntu 虛擬機)並用它探勘了一些塊。一旦兩個節點同步,他們就可以使用來自網路中任何節點的交易來探勘區塊。

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