diff --git a/nimbus/rpc/p2p.nim b/nimbus/rpc/p2p.nim index 2c72d4833..f43e6effb 100644 --- a/nimbus/rpc/p2p.nim +++ b/nimbus/rpc/p2p.nim @@ -17,7 +17,8 @@ import ../db/[db_chain, state_db], rpc_types, rpc_utils, ../transaction/call_evm, - ../utils/tx_pool + ../utils/tx_pool, + ../chain_config #[ Note: @@ -387,12 +388,13 @@ proc setupEthRpc*(node: EthereumNode, ctx: EthContext, chain: BaseChainDB, txPoo var idx = 0 prevGasUsed = GasInt(0) + fork = toFork(chain.networkParams.config, header.blockNumber) for receipt in chain.getReceipts(header.receiptRoot): let gasUsed = receipt.cumulativeGasUsed - prevGasUsed prevGasUsed = receipt.cumulativeGasUsed if idx == txDetails.index: - return some(populateReceipt(receipt, gasUsed, tx, txDetails.index, header)) + return some(populateReceipt(receipt, gasUsed, tx, txDetails.index, header, fork)) idx.inc server.rpc("eth_getUncleByBlockHashAndIndex") do(data: EthHashStr, quantity: HexQuantityStr) -> Option[BlockObject]: diff --git a/nimbus/rpc/rpc_types.nim b/nimbus/rpc/rpc_types.nim index bef79110c..5a1eb639e 100644 --- a/nimbus/rpc/rpc_types.nim +++ b/nimbus/rpc/rpc_types.nim @@ -117,6 +117,9 @@ type logsBloom*: FixedBytes[256] # bloom filter for light clients to quickly retrieve related logs. root*: Option[Hash256] # post-transaction stateroot (pre Byzantium). status*: Option[int] # 1 = success, 0 = failure. + effectiveGasPrice*: HexQuantityStr # The actual value per gas deducted from the senders account. + # Before EIP-1559, this is equal to the transaction's gas price. + # After, it is equal to baseFeePerGas + min(maxFeePerGas - baseFeePerGas, maxPriorityFeePerGas). FilterDataKind* = enum fkItem, fkList FilterData* = object diff --git a/nimbus/rpc/rpc_utils.nim b/nimbus/rpc/rpc_utils.nim index 96ae8fcb9..b940dea4e 100644 --- a/nimbus/rpc/rpc_utils.nim +++ b/nimbus/rpc/rpc_utils.nim @@ -11,7 +11,7 @@ import hexstrings, eth/[common, rlp, keys, trie/db], stew/byteutils, nimcrypto, ../db/db_chain, strutils, algorithm, options, times, json, ../constants, stint, hexstrings, rpc_types, ../utils, ../transaction, - ../transaction/call_evm + ../transaction/call_evm, ../forks func toAddress*(value: EthAddressStr): EthAddress = hexToPaddedByteArray[20](value.string) @@ -170,7 +170,7 @@ proc populateBlockObject*(header: BlockHeader, chain: BaseChainDB, fullTx: bool, for x in chain.getBlockTransactionHashes(header): result.transactions.add %(x) -proc populateReceipt*(receipt: Receipt, gasUsed: GasInt, tx: Transaction, txIndex: int, header: BlockHeader): ReceiptObject = +proc populateReceipt*(receipt: Receipt, gasUsed: GasInt, tx: Transaction, txIndex: int, header: BlockHeader, fork: Fork): ReceiptObject = result.transactionHash = tx.rlpHash result.transactionIndex = encodeQuantity(txIndex.uint) result.blockHash = header.hash @@ -195,3 +195,6 @@ proc populateReceipt*(receipt: Receipt, gasUsed: GasInt, tx: Transaction, txInde else: # 1 = success, 0 = failure. result.status = some(receipt.status.int) + + let normTx = eip1559TxNormalization(tx, header.baseFee.truncate(GasInt), fork) + result.effectiveGasPrice = encodeQuantity(normTx.gasPrice.uint64)