diff --git a/execution_chain/rpc/rpc_utils.nim b/execution_chain/rpc/rpc_utils.nim index 8fd5dead94..d2663771ac 100644 --- a/execution_chain/rpc/rpc_utils.nim +++ b/execution_chain/rpc/rpc_utils.nim @@ -128,7 +128,7 @@ proc populateTransactionObject*(tx: Transaction, proc populateBlockObject*(blockHash: Hash32, blk: Block, - totalDifficulty: UInt256, + totalDifficulty: Opt[UInt256], fullTx: bool, withUncles: bool = false): BlockObject = template header: auto = blk.header @@ -389,3 +389,7 @@ proc getEthConfigObject*(com: CommonRef, res.last = Opt.none(ConfigObject) return res + +proc getTotalDifficulty*(chain: ForkedChainRef, blockHash: Hash32): Opt[UInt256] = + # Note: It's ok to use baseTxFrame for TD as this is for historical blocks + chain.baseTxFrame().getScore(blockHash) diff --git a/execution_chain/rpc/server_api.nim b/execution_chain/rpc/server_api.nim index cb9c234000..9d953f952a 100644 --- a/execution_chain/rpc/server_api.nim +++ b/execution_chain/rpc/server_api.nim @@ -48,11 +48,8 @@ template chain(api: ServerAPIRef): ForkedChainRef = func newServerAPI*(txPool: TxPoolRef): ServerAPIRef = ServerAPIRef(txPool: txPool) -proc getTotalDifficulty*(api: ServerAPIRef, blockHash: Hash32): UInt256 = - # TODO forkedchain! - let totalDifficulty = api.com.db.baseTxFrame().getScore(blockHash).valueOr: - return api.com.db.baseTxFrame().headTotalDifficulty() - return totalDifficulty +proc getTotalDifficulty*(api: ServerAPIRef, blockHash: Hash32): Opt[UInt256] = + api.txPool.chain.getTotalDifficulty(blockHash) proc getProof*( accDB: LedgerRef, address: Address, slots: seq[UInt256] diff --git a/portal/bridge/common/rpc_helpers.nim b/portal/bridge/common/rpc_helpers.nim index e239707331..c52d022a22 100644 --- a/portal/bridge/common/rpc_helpers.nim +++ b/portal/bridge/common/rpc_helpers.nim @@ -145,7 +145,7 @@ proc getHeaderByNumber*( proc getBlockByNumber*( client: RpcClient, blockId: BlockIdentifier -): Future[Result[(Header, BlockBody, UInt256), string]] {. +): Future[Result[(Header, BlockBody, Opt[UInt256]), string]] {. async: (raises: [CancelledError]) .} = let blockObject = diff --git a/portal/tools/eth_data_exporter.nim b/portal/tools/eth_data_exporter.nim index 701da1399c..4a595978a7 100644 --- a/portal/tools/eth_data_exporter.nim +++ b/portal/tools/eth_data_exporter.nim @@ -109,7 +109,7 @@ proc cmdExportEra1(config: ExporterConf) = var headerRecords: seq[historical_hashes_accumulator.HeaderRecord] for blockNumber in startNumber .. endNumber: let - (header, body, totalDifficulty) = ( + (header, body, totalDifficultyOpt) = ( waitFor noCancel(client.getBlockByNumber(blockId(blockNumber))) ).valueOr: error "Failed retrieving block, skip creation of era1 file", @@ -121,6 +121,10 @@ proc cmdExportEra1(config: ExporterConf) = error "Failed retrieving receipts, skip creation of era1 file", blockNumber, error break writeFileBlock + totalDifficulty = totalDifficultyOpt.valueOr: + error "Pre-merge block request failed returning total difficulty, era1 file will not be fully valid", + blockNumber + 0.u256 headerRecords.add( historical_hashes_accumulator.HeaderRecord( diff --git a/vendor/nim-web3 b/vendor/nim-web3 index cf0a857737..5c3bbadd9c 160000 --- a/vendor/nim-web3 +++ b/vendor/nim-web3 @@ -1 +1 @@ -Subproject commit cf0a857737765575acc8223113cbccdd865a5cdf +Subproject commit 5c3bbadd9c0179f1a2ef828afebdf58d88d2ec03