Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion execution_chain/rpc/rpc_utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
7 changes: 2 additions & 5 deletions execution_chain/rpc/server_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion portal/bridge/common/rpc_helpers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
6 changes: 5 additions & 1 deletion portal/tools/eth_data_exporter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion vendor/nim-web3
Loading