diff --git a/nimbus/p2p/chain/chain_misc.nim b/nimbus/p2p/chain/chain_misc.nim index 2cf30ce23..a23f2f73f 100644 --- a/nimbus/p2p/chain/chain_misc.nim +++ b/nimbus/p2p/chain/chain_misc.nim @@ -67,9 +67,10 @@ method getAncestorHeader*(c: Chain, h: BlockHeader, output: var BlockHeader, result = c.db.getBlockHeader(h.blockNumber - offset, output) -method getBlockBody*(c: Chain, blockHash: KeccakHash): BlockBodyRef = - ## Always `nil` - result = nil +method getBlockBody*(c: Chain, blockHash: KeccakHash): BlockBodyRef {.gcsafe, raises: [Defect,RlpError].} = + result = BlockBodyRef() + if not c.db.getBlockBody(blockHash, result[]): + result = nil method getForkId*(c: Chain, n: BlockNumber): ForkID {.gcsafe.} = @@ -77,6 +78,10 @@ method getForkId*(c: Chain, n: BlockNumber): ForkID {.gcsafe.} = let fork = c.db.config.toChainFork(n) c.forkIds[fork] + +method getTotalDifficulty*(c: Chain): DifficultyInt {.gcsafe, raises: [Defect,RlpError].} = + c.db.headTotalDifficulty() + # ------------------------------------------------------------------------------ # End # ------------------------------------------------------------------------------ diff --git a/nimbus/sync/protocol/eth66.nim b/nimbus/sync/protocol/eth66.nim index e9c128d38..0ab5c805d 100644 --- a/nimbus/sync/protocol/eth66.nim +++ b/nimbus/sync/protocol/eth66.nim @@ -131,13 +131,14 @@ p2pProtocol eth66(version = ethVersion, network = peer.network chain = network.chain bestBlock = chain.getBestBlockHeader + totalDifficulty = chain.getTotalDifficulty chainForkId = chain.getForkId(bestBlock.blockNumber) forkId = ForkId( forkHash: chainForkId.crc.toBytesBE, forkNext: chainForkId.nextFork.toBlockNumber) trace trEthSendSending & "Status (0x00)", peer, - td=bestBlock.difficulty, + td=totalDifficulty, bestHash=bestBlock.blockHash.toHex, networkId=network.networkId, genesis=chain.genesisHash.toHex, @@ -145,7 +146,7 @@ p2pProtocol eth66(version = ethVersion, let m = await peer.status(ethVersion, network.networkId, - bestBlock.difficulty, + totalDifficulty, bestBlock.blockHash, chain.genesisHash, forkId, diff --git a/nimbus/sync/protocol/eth67.nim b/nimbus/sync/protocol/eth67.nim index 0d33c1808..3889e5ed1 100644 --- a/nimbus/sync/protocol/eth67.nim +++ b/nimbus/sync/protocol/eth67.nim @@ -91,13 +91,14 @@ p2pProtocol eth67(version = ethVersion, network = peer.network chain = network.chain bestBlock = chain.getBestBlockHeader + totalDifficulty = chain.getTotalDifficulty chainForkId = chain.getForkId(bestBlock.blockNumber) forkId = ForkId( forkHash: chainForkId.crc.toBytesBE, forkNext: chainForkId.nextFork.toBlockNumber) trace trEthSendSending & "Status (0x00)", peer, - td=bestBlock.difficulty, + td=totalDifficulty, bestHash=bestBlock.blockHash.toHex, networkId=network.networkId, genesis=chain.genesisHash.toHex, @@ -105,7 +106,7 @@ p2pProtocol eth67(version = ethVersion, let m = await peer.status(ethVersion, network.networkId, - bestBlock.difficulty, + totalDifficulty, bestBlock.blockHash, chain.genesisHash, forkId, diff --git a/vendor/nim-eth b/vendor/nim-eth index d31abca01..2186d6716 160000 --- a/vendor/nim-eth +++ b/vendor/nim-eth @@ -1 +1 @@ -Subproject commit d31abca0104528dbca040e9fc1984edd280003c0 +Subproject commit 2186d671636c19233064b6124335105a67853082