Implement eth_blobBaseFee (#2124)

This commit is contained in:
andri lim 2024-04-04 07:25:56 +07:00 committed by GitHub
parent 1502014e36
commit 516dd95566
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 0 deletions

View File

@ -20,6 +20,7 @@ import
rpc_types, rpc_utils, rpc_types, rpc_utils,
../transaction/call_evm, ../transaction/call_evm,
../core/tx_pool, ../core/tx_pool,
../core/eip4844,
../common/[common, context], ../common/[common, context],
../utils/utils, ../utils/utils,
../beacon/web3_eth_conv, ../beacon/web3_eth_conv,
@ -555,6 +556,7 @@ proc setupEthRpc*(
getProof(accDB, address, slots) getProof(accDB, address, slots)
server.rpc("eth_getBlockReceipts") do(quantityTag: BlockTag) -> Opt[seq[ReceiptObject]]: server.rpc("eth_getBlockReceipts") do(quantityTag: BlockTag) -> Opt[seq[ReceiptObject]]:
## Returns the receipts of a block.
try: try:
let header = chainDB.headerFromTag(quantityTag) let header = chainDB.headerFromTag(quantityTag)
var var
@ -577,6 +579,7 @@ proc setupEthRpc*(
return Opt.none(seq[ReceiptObject]) return Opt.none(seq[ReceiptObject])
server.rpc("eth_createAccessList") do(args: TransactionArgs, quantityTag: BlockTag) -> AccessListResult: server.rpc("eth_createAccessList") do(args: TransactionArgs, quantityTag: BlockTag) -> AccessListResult:
## Generates an access list for a transaction.
try: try:
let let
header = chainDB.headerFromTag(quantityTag) header = chainDB.headerFromTag(quantityTag)
@ -588,6 +591,18 @@ proc setupEthRpc*(
error: some("createAccessList error: " & exc.msg), error: some("createAccessList error: " & exc.msg),
) )
server.rpc("eth_blobBaseFee") do() -> Web3Quantity:
## Returns the base fee per blob gas in wei.
let header = chainDB.headerFromTag(blockId("latest"))
if header.blobGasUsed.isNone:
raise newException(ValueError, "blobGasUsed missing from latest header")
if header.excessBlobGas.isNone:
raise newException(ValueError, "excessBlobGas missing from latest header")
let blobBaseFee = getBlobBaseFee(header.excessBlobGas.get) * header.blobGasUsed.get.u256
if blobBaseFee > high(uint64).u256:
raise newException(ValueError, "blobBaseFee is bigger than uint64.max")
return w3Qty blobBaseFee.truncate(uint64)
#[ #[
server.rpc("eth_newFilter") do(filterOptions: FilterOptions) -> int: server.rpc("eth_newFilter") do(filterOptions: FilterOptions) -> int:
## Creates a filter object, based on filter options, to notify when the state changes (logs). ## Creates a filter object, based on filter options, to notify when the state changes (logs).