From 25bc8e4b221d1690095eacb796b0a346fb160ac0 Mon Sep 17 00:00:00 2001 From: jangko Date: Thu, 2 Nov 2023 11:38:07 +0700 Subject: [PATCH] Add blobGasPrice and blobGasUsed to ReceiptObject of RPC --- .../engine/cancun/step_newpayloads.nim | 4 ++-- .../nodocker/engine/engine_client.nim | 4 ++++ .../nodocker/engine/engine_sim.nim | 8 +++---- hive_integration/nodocker/engine/types.nim | 18 ++++++++++++++ nimbus/rpc/rpc_types.nim | 3 +++ nimbus/rpc/rpc_utils.nim | 24 +++++++++++++------ 6 files changed, 48 insertions(+), 13 deletions(-) diff --git a/hive_integration/nodocker/engine/cancun/step_newpayloads.nim b/hive_integration/nodocker/engine/cancun/step_newpayloads.nim index 0aefd95f8..a796f94d3 100644 --- a/hive_integration/nodocker/engine/cancun/step_newpayloads.nim +++ b/hive_integration/nodocker/engine/cancun/step_newpayloads.nim @@ -106,8 +106,8 @@ proc verifyPayload(step: NewPayloads, let r = client.txReceipt(tx.rlpHash) let expectedBlobGasUsed = blobCount.uint64 * GAS_PER_BLOB - #r.ExpectBlobGasUsed(expectedBlobGasUsed) - #r.ExpectBlobGasPrice(expectedBlobGasPrice) + r.expectBlobGasUsed(expectedBlobGasUsed) + r.expectBlobGasPrice(expectedBlobGasPrice) if totalBlobCount != step.expectedIncludedBlobCount: error "expected blobs in transactions", diff --git a/hive_integration/nodocker/engine/engine_client.nim b/hive_integration/nodocker/engine/engine_client.nim index 6c48132a6..66ed828f2 100644 --- a/hive_integration/nodocker/engine/engine_client.nim +++ b/hive_integration/nodocker/engine/engine_client.nim @@ -312,6 +312,8 @@ type stateRoot*: Option[Hash256] status*: Option[bool] effectiveGasPrice*: GasInt + blobGasUsed*: Option[uint64] + blobGasPrice*: Option[UInt256] RPCTx* = object txType*: TxType @@ -353,6 +355,8 @@ proc toRPCReceipt(rec: eth_api.ReceiptObject): RPCReceipt = stateRoot: rec.root, status: maybeBool(rec.status), effectiveGasPrice: hexToInt(string rec.effectiveGasPrice, GasInt), + blobGasUsed: maybeU64(rec.blobGasUsed), + blobGasPrice: maybeU256(rec.blobGasPrice), ) proc toRPCTx(tx: eth_api.TransactionObject): RPCTx = diff --git a/hive_integration/nodocker/engine/engine_sim.nim b/hive_integration/nodocker/engine/engine_sim.nim index b0da8ce92..b0d6f058b 100644 --- a/hive_integration/nodocker/engine/engine_sim.nim +++ b/hive_integration/nodocker/engine/engine_sim.nim @@ -24,10 +24,10 @@ import ./cancun_tests proc combineTests(): seq[TestDesc] = - result.add wdTestList - result.add ecTestList - result.add authTestList - result.add engineTestList + #result.add wdTestList + #result.add ecTestList + #result.add authTestList + #result.add engineTestList result.add cancunTestList let diff --git a/hive_integration/nodocker/engine/types.nim b/hive_integration/nodocker/engine/types.nim index 1a11ed002..00eca2cc4 100644 --- a/hive_integration/nodocker/engine/types.nim +++ b/hive_integration/nodocker/engine/types.nim @@ -240,6 +240,24 @@ template expectBalanceEqual*(res: untyped, expectedBalance: UInt256) = testCond res.get == expectedBalance: error "invalid balance", expect=expectedBalance, get=res.get +template expectBlobGasUsed*(res: untyped, expected: uint64) = + testCond res.isOk: + error "expectBlobGasUsed", msg=res.error + let rec = res.get + testCond rec.blobGasUsed.isSome: + error "expect blobGasUsed isSome" + testCond rec.blobGasUsed.get == expected: + error "expectBlobGasUsed", expect=expected, get=rec.blobGasUsed.get + +template expectBlobGasPrice*(res: untyped, expected: UInt256) = + testCond res.isOk: + error "expectBlobGasPrice", msg=res.error + let rec = res.get + testCond rec.blobGasPrice.isSome: + error "expect blobGasPrice isSome" + testCond rec.blobGasPrice.get == expected: + error "expectBlobGasPrice", expect=expected, get=rec.blobGasPrice.get + func timestamp*(x: ExecutableData): auto = x.basePayload.timestamp diff --git a/nimbus/rpc/rpc_types.nim b/nimbus/rpc/rpc_types.nim index 8790a7e5e..ca9cf3231 100644 --- a/nimbus/rpc/rpc_types.nim +++ b/nimbus/rpc/rpc_types.nim @@ -157,6 +157,9 @@ type # Before EIP-1559, this is equal to the transaction's gas price. # After, it is equal to baseFeePerGas + min(maxFeePerGas - baseFeePerGas, maxPriorityFeePerGas). + blobGasUsed*: Option[HexQuantityStr] # uint64 + blobGasPrice*: Option[HexQuantityStr] # UInt256 + FilterOptions* = object # Parameter from user fromBlock*: Option[string] # (optional, default: "latest") integer block number, or "latest" for the last mined block or "pending", "earliest" for not yet mined transactions. diff --git a/nimbus/rpc/rpc_utils.nim b/nimbus/rpc/rpc_utils.nim index cda4945fe..01d052809 100644 --- a/nimbus/rpc/rpc_utils.nim +++ b/nimbus/rpc/rpc_utils.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2018 Status Research & Development GmbH +# Copyright (c) 2018-2023 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) # * MIT license ([LICENSE-MIT](LICENSE-MIT)) @@ -9,11 +9,17 @@ {.push raises: [].} -import hexstrings, eth/[common, keys], stew/byteutils, - ../db/core_db, strutils, algorithm, options, json, - ../constants, stint, rpc_types, +import + std/[strutils, algorithm, options, json], + ./hexstrings, + ./rpc_types, + eth/[common, keys], + stew/byteutils, + ../db/core_db, + ../constants, stint, ../utils/utils, ../transaction, - ../transaction/call_evm + ../transaction/call_evm, + ../core/eip4844 const defaultTag = "latest" @@ -164,8 +170,8 @@ proc toAccessTupleList(list: openArray[AccessPair]): seq[AccessTuple] = for x in list: result.add toAccessTuple(x) -proc populateTransactionObject*(tx: Transaction, - header: Option[BlockHeader] = none(BlockHeader), +proc populateTransactionObject*(tx: Transaction, + header: Option[BlockHeader] = none(BlockHeader), txIndex: Option[int] = none(int)): TransactionObject {.gcsafe, raises: [ValidationError].} = result.`type` = encodeQuantity(tx.txType.uint64) @@ -304,3 +310,7 @@ proc populateReceipt*(receipt: Receipt, gasUsed: GasInt, tx: Transaction, let normTx = eip1559TxNormalization(tx, header.baseFee.truncate(GasInt)) result.effectiveGasPrice = encodeQuantity(normTx.gasPrice.uint64) + + if tx.txType == TxEip4844: + result.blobGasUsed = some(encodeQuantity(tx.versionedHashes.len.uint64 * GAS_PER_BLOB.uint64)) + result.blobGasPrice = some(encodeQuantity(getBlobGasprice(header.excessBlobGas.get(0'u64))))