Add blobGasPrice and blobGasUsed to ReceiptObject of RPC

This commit is contained in:
jangko 2023-11-02 11:38:07 +07:00
parent 69254e614f
commit 25bc8e4b22
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
6 changed files with 48 additions and 13 deletions

View File

@ -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",

View File

@ -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 =

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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))))