Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add blobGasPrice and blobGasUsed to ReceiptObject of RPC #1879

Merged
merged 1 commit into from
Nov 2, 2023
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
Add blobGasPrice and blobGasUsed to ReceiptObject of RPC
  • Loading branch information
jangko committed Nov 2, 2023
commit 25bc8e4b221d1690095eacb796b0a346fb160ac0
4 changes: 2 additions & 2 deletions hive_integration/nodocker/engine/cancun/step_newpayloads.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions hive_integration/nodocker/engine/engine_client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ type
stateRoot*: Option[Hash256]
status*: Option[bool]
effectiveGasPrice*: GasInt
blobGasUsed*: Option[uint64]
blobGasPrice*: Option[UInt256]

RPCTx* = object
txType*: TxType
Expand Down Expand Up @@ -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 =
Expand Down
8 changes: 4 additions & 4 deletions hive_integration/nodocker/engine/engine_sim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions hive_integration/nodocker/engine/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions nimbus/rpc/rpc_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 17 additions & 7 deletions nimbus/rpc/rpc_utils.nim
Original file line number Diff line number Diff line change
@@ -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))
Expand All @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))))
Loading