diff --git a/execution_chain/core/chain/forked_chain.nim b/execution_chain/core/chain/forked_chain.nim index 6af4a03ad9..91825f6317 100644 --- a/execution_chain/core/chain/forked_chain.nim +++ b/execution_chain/core/chain/forked_chain.nim @@ -60,7 +60,7 @@ func updateBranch(c: ForkedChainRef, blk: Block, blkHash: Hash32, txFrame: CoreDbTxRef, - receipts: sink seq[Receipt]) = + receipts: sink seq[StoredReceipt]) = if parent.isHead: parent.appendBlock(blk, blkHash, txFrame, move(receipts)) c.hashToBlock[blkHash] = parent.lastBlockPos @@ -862,7 +862,7 @@ proc blockHeader*(c: ForkedChainRef, blk: BlockHashOrNumber): Result[Header, str return c.headerByHash(blk.hash) c.headerByNumber(blk.number) -proc receiptsByBlockHash*(c: ForkedChainRef, blockHash: Hash32): Result[seq[Receipt], string] = +proc receiptsByBlockHash*(c: ForkedChainRef, blockHash: Hash32): Result[seq[StoredReceipt], string] = if blockHash != c.baseBranch.tailHash: c.hashToBlock.withValue(blockHash, loc): return ok(loc[].receipts) diff --git a/execution_chain/core/chain/forked_chain/chain_branch.nim b/execution_chain/core/chain/forked_chain/chain_branch.nim index 326a3415a2..6eef09b62c 100644 --- a/execution_chain/core/chain/forked_chain/chain_branch.nim +++ b/execution_chain/core/chain/forked_chain/chain_branch.nim @@ -19,7 +19,7 @@ type BlockDesc* = object blk* : Block txFrame* : CoreDbTxRef - receipts*: seq[Receipt] + receipts*: seq[StoredReceipt] hash* : Hash32 BlockPos* = object @@ -105,7 +105,7 @@ func branch*(header: Header, hash: Hash32, txFrame: CoreDbTxRef): BranchRef = func branch*(parent: BranchRef, blk: Block, hash: Hash32, txFrame: CoreDbTxRef, - receipts: sink seq[Receipt]): BranchRef = + receipts: sink seq[StoredReceipt]): BranchRef = BranchRef( blocks: @[BlockDesc( blk: blk, @@ -126,7 +126,7 @@ func header*(loc: BlockPos): Header = func blk*(loc: BlockPos): Block = loc.branch.blocks[loc.index].blk -func receipts*(loc: BlockPos): seq[Receipt] = +func receipts*(loc: BlockPos): seq[StoredReceipt] = loc.branch.blocks[loc.index].receipts func number*(loc: BlockPos): BlockNumber = @@ -154,7 +154,7 @@ func appendBlock*(loc: BlockPos, blk: Block, blkHash: Hash32, txFrame: CoreDbTxRef, - receipts: sink seq[Receipt]) = + receipts: sink seq[StoredReceipt]) = loc.branch.append(BlockDesc( blk : blk, txFrame : txFrame, diff --git a/execution_chain/core/chain/forked_chain/chain_private.nim b/execution_chain/core/chain/forked_chain/chain_private.nim index f5ea4c10bd..857518b1d0 100644 --- a/execution_chain/core/chain/forked_chain/chain_private.nim +++ b/execution_chain/core/chain/forked_chain/chain_private.nim @@ -21,7 +21,7 @@ import proc writeBaggage*(c: ForkedChainRef, blk: Block, blkHash: Hash32, txFrame: CoreDbTxRef, - receipts: openArray[Receipt]) = + receipts: openArray[StoredReceipt]) = template header(): Header = blk.header @@ -58,7 +58,7 @@ proc processBlock*(c: ForkedChainRef, txFrame: CoreDbTxRef, blk: Block, blkHash: Hash32, - finalized: bool): Result[seq[Receipt], string] = + finalized: bool): Result[seq[StoredReceipt], string] = template header(): Header = blk.header diff --git a/execution_chain/core/executor/executor_helpers.nim b/execution_chain/core/executor/executor_helpers.nim index a3d2294931..aef116f160 100644 --- a/execution_chain/core/executor/executor_helpers.nim +++ b/execution_chain/core/executor/executor_helpers.nim @@ -41,15 +41,15 @@ func logsBloom(logs: openArray[Log]): LogsBloom = # Public functions # ------------------------------------------------------------------------------ -func createBloom*(receipts: openArray[Receipt]): Bloom = +func createBloom*(receipts: openArray[StoredReceipt]): Bloom = var bloom: LogsBloom for rec in receipts: bloom.value = bloom.value or logsBloom(rec.logs).value bloom.value.to(Bloom) proc makeReceipt*( - vmState: BaseVMState; txType: TxType, callResult: LogResult): Receipt = - var rec: Receipt + vmState: BaseVMState; txType: TxType, callResult: LogResult): StoredReceipt = + var rec: StoredReceipt if vmState.com.isByzantiumOrLater(vmState.blockNumber): rec.isHash = false rec.status = vmState.status @@ -62,7 +62,6 @@ proc makeReceipt*( rec.receiptType = txType rec.cumulativeGasUsed = vmState.cumulativeGasUsed assign(rec.logs, callResult.logEntries) - rec.logsBloom = logsBloom(rec.logs).value.to(Bloom) rec # ------------------------------------------------------------------------------ diff --git a/execution_chain/db/core_db/core_apps.nim b/execution_chain/db/core_db/core_apps.nim index 49f5fa9078..29c7e1ceb5 100644 --- a/execution_chain/db/core_db/core_apps.nim +++ b/execution_chain/db/core_db/core_apps.nim @@ -129,7 +129,7 @@ iterator getWithdrawals*( iterator getReceipts*( db: CoreDbTxRef; receiptsRoot: Hash32; - ): Receipt + ): StoredReceipt {.gcsafe, raises: [RlpError].} = block body: if receiptsRoot == EMPTY_ROOT_HASH: @@ -142,7 +142,7 @@ iterator getReceipts*( break body if data.len == 0: break body - yield rlp.decode(data, Receipt) + yield rlp.decode(data, StoredReceipt) # ------------------------------------------------------------------------------ # Public functions @@ -493,7 +493,7 @@ proc setHead*( proc persistReceipts*( db: CoreDbTxRef; receiptsRoot: Hash32; - receipts: openArray[Receipt]; + receipts: openArray[StoredReceipt]; ) = const info = "persistReceipts()" if receipts.len == 0: @@ -507,9 +507,9 @@ proc persistReceipts*( proc getReceipts*( db: CoreDbTxRef; receiptsRoot: Hash32; - ): Result[seq[Receipt], string] = + ): Result[seq[StoredReceipt], string] = wrapRlpException "getReceipts": - var receipts = newSeq[Receipt]() + var receipts = newSeq[StoredReceipt]() for r in db.getReceipts(receiptsRoot): receipts.add(r) return ok(receipts) diff --git a/execution_chain/evm/types.nim b/execution_chain/evm/types.nim index 7a936f3347..12e5f2304b 100644 --- a/execution_chain/evm/types.nim +++ b/execution_chain/evm/types.nim @@ -49,7 +49,7 @@ type flags* : set[VMFlag] fork* : EVMFork tracer* : TracerRef - receipts* : seq[Receipt] + receipts* : seq[StoredReceipt] cumulativeGasUsed*: GasInt gasCosts* : GasCosts blobGasUsed* : uint64 diff --git a/execution_chain/rpc/filters.nim b/execution_chain/rpc/filters.nim index 46d60a3fe5..6bd2ad5c52 100644 --- a/execution_chain/rpc/filters.nim +++ b/execution_chain/rpc/filters.nim @@ -64,9 +64,9 @@ proc match*( proc deriveLogs*( header: Header, transactions: openArray[Transaction], - receipts: openArray[Receipt], + receipts: openArray[StoredReceipt | Receipt], filterOptions: FilterOptions, - txHashes: Opt[seq[Hash32]] = Opt.none(seq[Hash32]) + txHashes: Opt[seq[Hash32]] = Opt.none(seq[Hash32]), ): seq[FilterLog] = ## Derive log fields, does not deal with pending log, only the logs with ## full data set @@ -81,12 +81,13 @@ proc deriveLogs*( var logIndex = 0'u64 for i, receipt in receipts: - let logs = receipt.logs.filterIt(it.match(filterOptions.address, filterOptions.topics)) + let logs = + receipt.logs.filterIt(it.match(filterOptions.address, filterOptions.topics)) if logs.len > 0: # TODO avoid recomputing entirely - we should have this cached somewhere let txHash = if txHashes.isSome: - txHashes.get[i] # cached txHashes + txHashes.get[i] # cached txHashes else: transactions[i].computeRlpHash diff --git a/execution_chain/rpc/oracle.nim b/execution_chain/rpc/oracle.nim index 6a8498a131..ebe39d7f21 100644 --- a/execution_chain/rpc/oracle.nim +++ b/execution_chain/rpc/oracle.nim @@ -44,7 +44,7 @@ type blockNumber: uint64 header : Header txs : seq[Transaction] - receipts : seq[Receipt] + receipts : seq[StoredReceipt] CacheKey = object number: uint64 diff --git a/execution_chain/rpc/rpc_utils.nim b/execution_chain/rpc/rpc_utils.nim index b569d9fd5e..52982f2bd4 100644 --- a/execution_chain/rpc/rpc_utils.nim +++ b/execution_chain/rpc/rpc_utils.nim @@ -179,9 +179,11 @@ proc populateBlockObject*(blockHash: Hash32, result.excessBlobGas = w3Qty(header.excessBlobGas) result.requestsHash = header.requestsHash -proc populateReceipt*(receipt: Receipt, gasUsed: GasInt, tx: Transaction, +proc populateReceipt*(rec: StoredReceipt, gasUsed: GasInt, tx: Transaction, txIndex: uint64, header: Header, com: CommonRef): ReceiptObject = - let sender = tx.recoverSender() + let + sender = tx.recoverSender() + receipt = rec.to(Receipt) var res = ReceiptObject() res.transactionHash = tx.computeRlpHash res.transactionIndex = Quantity(txIndex) diff --git a/execution_chain/sync/wire_protocol/handler.nim b/execution_chain/sync/wire_protocol/handler.nim index 7a6ec54adc..d5c0f89c5d 100644 --- a/execution_chain/sync/wire_protocol/handler.nim +++ b/execution_chain/sync/wire_protocol/handler.nim @@ -89,7 +89,7 @@ proc getReceipts*(ctx: EthWireRef, continue totalBytes += getEncodedLength(receiptList) - list.add(move(receiptList)) + list.add(receiptList.to(seq[Receipt])) if list.len >= MAX_RECEIPTS_SERVE or totalBytes > SOFT_RESPONSE_LIMIT: @@ -109,7 +109,7 @@ proc getStoredReceipts*(ctx: EthWireRef, continue totalBytes += getEncodedLength(receiptList) - list.add(receiptList.to(seq[StoredReceipt])) + list.add(move(receiptList)) if list.len >= MAX_RECEIPTS_SERVE or totalBytes > SOFT_RESPONSE_LIMIT: diff --git a/execution_chain/utils/utils.nim b/execution_chain/utils/utils.nim index 334a8c9e5a..50fc3f3350 100644 --- a/execution_chain/utils/utils.nim +++ b/execution_chain/utils/utils.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2018-2024 Status Research & Development GmbH +# Copyright (c) 2018-2025 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) @@ -30,6 +30,10 @@ template calcTxRoot*(transactions: openArray[Transaction]): Root = template calcWithdrawalsRoot*(withdrawals: openArray[Withdrawal]): Root = orderedTrieRoot(withdrawals) +template calcReceiptsRoot*(receipts: openArray[StoredReceipt]): Root = + let recs = receipts.to(seq[Receipt]) + orderedTrieRoot(recs) + template calcReceiptsRoot*(receipts: openArray[Receipt]): Root = orderedTrieRoot(receipts) diff --git a/scripts/check_copyright_year.sh b/scripts/check_copyright_year.sh old mode 100644 new mode 100755 diff --git a/tests/test_block_fixture.nim b/tests/test_block_fixture.nim index 6a6b1d4f72..d81cca5b49 100644 --- a/tests/test_block_fixture.nim +++ b/tests/test_block_fixture.nim @@ -1,4 +1,4 @@ -# Copyright (c) 2023-2024 Status Research & Development GmbH +# Copyright (c) 2023-2025 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) # * MIT license ([LICENSE-MIT](LICENSE-MIT)) @@ -19,7 +19,8 @@ var receitsRlp = rlpb.listElem(2) let blockHeader4514995* = headerRlp.read(Header) let blockBody4514995* = bodyRlp.read(BlockBody) -let receipts4514995* = receitsRlp.read(seq[Receipt]) +let recs = receitsRlp.read(seq[Receipt]) +let receipts4514995* = recs.to(seq[StoredReceipt]) proc getBlockHeader4514995*(): Header {.gcsafe.} = var headerRlp = rlpb.listElem(0) @@ -29,6 +30,7 @@ proc getBlockBody4514995*(): BlockBody {.gcsafe.} = var bodyRlp = rlpb.listElem(1) return bodyRlp.read(BlockBody) -proc getReceipts4514995*(): seq[Receipt] {.gcsafe.} = +proc getReceipts4514995*(): seq[StoredReceipt] {.gcsafe.} = var receitsRlp = rlpb.listElem(2) - return receitsRlp.read(seq[Receipt]) + let recs = receitsRlp.read(seq[Receipt]) + return recs.to(seq[StoredReceipt]) diff --git a/tools/t8n/transition.nim b/tools/t8n/transition.nim index d4cdf308c8..540e5df930 100644 --- a/tools/t8n/transition.nim +++ b/tools/t8n/transition.nim @@ -119,13 +119,15 @@ proc genAddress(tx: Transaction, sender: Address): Address = if tx.to.isNone: result = generateAddress(sender, tx.nonce) -proc toTxReceipt(rec: Receipt, +proc toTxReceipt(receipt: StoredReceipt, tx: Transaction, sender: Address, txIndex: int, gasUsed: GasInt): TxReceipt = - let contractAddress = genAddress(tx, sender) + let + contractAddress = genAddress(tx, sender) + rec = receipt.to(Receipt) TxReceipt( txType: tx.txType, root: if rec.isHash: rec.hash else: default(Hash32), @@ -140,7 +142,7 @@ proc toTxReceipt(rec: Receipt, transactionIndex: txIndex ) -proc calcLogsHash(receipts: openArray[Receipt]): Hash32 = +proc calcLogsHash(receipts: openArray[StoredReceipt]): Hash32 = var logs: seq[Log] for rec in receipts: logs.add rec.logs @@ -231,7 +233,7 @@ proc exec(ctx: TransContext, vmState.mutateLedger: db.applyDAOHardFork() - vmState.receipts = newSeqOfCap[Receipt](ctx.txList.len) + vmState.receipts = newSeqOfCap[StoredReceipt](ctx.txList.len) vmState.cumulativeGasUsed = 0 if ctx.env.parentBeaconBlockRoot.isSome: