2018-11-22 06:40:09 +00:00
|
|
|
# Nimbus
|
2024-02-20 03:07:38 +00:00
|
|
|
# Copyright (c) 2018-2024 Status Research & Development GmbH
|
2018-11-22 06:40:09 +00:00
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
|
|
|
# at your option.
|
|
|
|
# This file may not be copied, modified, or distributed except according to
|
|
|
|
# those terms.
|
|
|
|
|
2023-08-04 11:10:09 +00:00
|
|
|
{.push raises: [].}
|
|
|
|
|
2023-11-02 04:38:07 +00:00
|
|
|
import
|
2024-06-14 07:31:08 +00:00
|
|
|
std/[strutils, algorithm],
|
2023-11-02 04:38:07 +00:00
|
|
|
./rpc_types,
|
2024-04-16 12:52:07 +00:00
|
|
|
./params,
|
2024-03-21 11:24:32 +00:00
|
|
|
../common/common,
|
2023-11-02 04:38:07 +00:00
|
|
|
../db/core_db,
|
2024-03-21 11:24:32 +00:00
|
|
|
../db/ledger,
|
2023-11-02 04:38:07 +00:00
|
|
|
../constants, stint,
|
2023-12-08 09:35:50 +00:00
|
|
|
../utils/utils,
|
|
|
|
../transaction,
|
2023-11-02 04:38:07 +00:00
|
|
|
../transaction/call_evm,
|
2023-12-08 09:35:50 +00:00
|
|
|
../core/eip4844,
|
2024-03-21 11:24:32 +00:00
|
|
|
../beacon/web3_eth_conv,
|
2024-06-17 07:56:39 +00:00
|
|
|
../evm/types,
|
|
|
|
../evm/state,
|
2024-03-21 11:24:32 +00:00
|
|
|
../evm/precompiles,
|
2024-06-07 08:24:32 +00:00
|
|
|
../evm/tracer/access_list_tracer,
|
|
|
|
../evm/evm_errors
|
2024-03-21 11:24:32 +00:00
|
|
|
|
2020-07-23 15:30:42 +00:00
|
|
|
|
2022-06-29 15:44:08 +00:00
|
|
|
const
|
2023-12-27 00:48:53 +00:00
|
|
|
defaultTag = blockId("latest")
|
2022-06-29 15:44:08 +00:00
|
|
|
|
2023-12-08 09:35:50 +00:00
|
|
|
type
|
|
|
|
BlockHeader = common.BlockHeader
|
2020-07-23 15:30:42 +00:00
|
|
|
|
2023-12-27 00:48:53 +00:00
|
|
|
proc headerFromTag*(chain: CoreDbRef, blockId: BlockTag): BlockHeader
|
2023-01-31 01:32:17 +00:00
|
|
|
{.gcsafe, raises: [CatchableError].} =
|
2020-07-22 16:51:26 +00:00
|
|
|
|
2023-12-27 00:48:53 +00:00
|
|
|
if blockId.kind == bidAlias:
|
|
|
|
let tag = blockId.alias.toLowerAscii
|
|
|
|
case tag
|
|
|
|
of "latest": result = chain.getCanonicalHead()
|
|
|
|
of "earliest": result = chain.getBlockHeader(GENESIS_BLOCK_NUMBER)
|
|
|
|
of "safe": result = chain.safeHeader()
|
|
|
|
of "finalized": result = chain.finalizedHeader()
|
|
|
|
of "pending":
|
|
|
|
#TODO: Implement get pending block
|
2024-05-13 13:42:28 +00:00
|
|
|
# We currently fall back to `latest` so that the `tx-spammer` in
|
2024-06-13 14:03:19 +00:00
|
|
|
# `ethpandaops/ethereum-package` can make progress. A real
|
2024-05-13 13:42:28 +00:00
|
|
|
# implementation is still required that takes into account any
|
|
|
|
# pending transactions that have not yet been bundled into a block.
|
|
|
|
result = chain.getCanonicalHead()
|
2023-12-08 09:35:50 +00:00
|
|
|
else:
|
2023-12-27 00:48:53 +00:00
|
|
|
raise newException(ValueError, "Unsupported block tag " & tag)
|
2022-06-29 15:44:08 +00:00
|
|
|
else:
|
2024-06-14 07:31:08 +00:00
|
|
|
let blockNum = blockId.number.uint64
|
2023-12-27 00:48:53 +00:00
|
|
|
result = chain.getBlockHeader(blockNum)
|
|
|
|
|
2024-06-14 07:31:08 +00:00
|
|
|
proc headerFromTag*(chain: CoreDbRef, blockTag: Opt[BlockTag]): BlockHeader
|
2023-12-27 00:48:53 +00:00
|
|
|
{.gcsafe, raises: [CatchableError].} =
|
|
|
|
let blockId = blockTag.get(defaultTag)
|
|
|
|
chain.headerFromTag(blockId)
|
2022-06-29 15:44:08 +00:00
|
|
|
|
2023-08-04 11:10:09 +00:00
|
|
|
proc calculateMedianGasPrice*(chain: CoreDbRef): GasInt
|
2023-01-31 01:32:17 +00:00
|
|
|
{.gcsafe, raises: [CatchableError].} =
|
2020-07-22 16:51:26 +00:00
|
|
|
var prices = newSeqOfCap[GasInt](64)
|
|
|
|
let header = chain.getCanonicalHead()
|
|
|
|
for encodedTx in chain.getBlockTransactionData(header.txRoot):
|
2022-12-15 06:30:18 +00:00
|
|
|
let tx = decodeTx(encodedTx)
|
2020-07-22 16:51:26 +00:00
|
|
|
prices.add(tx.gasPrice)
|
|
|
|
|
|
|
|
if prices.len > 0:
|
|
|
|
sort(prices)
|
|
|
|
let middle = prices.len div 2
|
|
|
|
if prices.len mod 2 == 0:
|
|
|
|
# prevent overflow
|
|
|
|
let price = prices[middle].uint64 + prices[middle - 1].uint64
|
|
|
|
result = (price div 2).GasInt
|
|
|
|
else:
|
|
|
|
result = prices[middle]
|
2020-07-23 15:30:42 +00:00
|
|
|
|
2024-05-28 06:36:38 +00:00
|
|
|
# TODO: This should properly incorporate the base fee in the block data,
|
|
|
|
# and recommend a gas fee that likely gets the block to confirm.
|
|
|
|
# This also has to work on Genesis where no prior transaction data exists.
|
2024-06-13 14:03:19 +00:00
|
|
|
# For compatibility with `ethpandaops/ethereum-package`, set this to a
|
2024-05-28 06:36:38 +00:00
|
|
|
# sane minimum for compatibility to unblock testing.
|
|
|
|
# Note: When this is fixed, update `tests/graphql/queries.toml` and
|
|
|
|
# re-enable the "query.gasPrice" test case (remove `skip = true`).
|
|
|
|
const minGasPrice = 30_000_000_000.GasInt
|
|
|
|
result = max(result, minGasPrice)
|
|
|
|
|
2024-03-21 01:05:22 +00:00
|
|
|
proc unsignedTx*(tx: TransactionArgs, chain: CoreDbRef, defaultNonce: AccountNonce): Transaction
|
2023-01-31 01:32:17 +00:00
|
|
|
{.gcsafe, raises: [CatchableError].} =
|
2020-07-23 15:30:42 +00:00
|
|
|
if tx.to.isSome:
|
2024-06-14 07:31:08 +00:00
|
|
|
result.to = Opt.some(ethAddr(tx.to.get))
|
2020-07-23 15:30:42 +00:00
|
|
|
|
|
|
|
if tx.gas.isSome:
|
2023-12-08 09:35:50 +00:00
|
|
|
result.gasLimit = tx.gas.get.GasInt
|
2020-07-23 15:30:42 +00:00
|
|
|
else:
|
|
|
|
result.gasLimit = 90000.GasInt
|
|
|
|
|
|
|
|
if tx.gasPrice.isSome:
|
2023-12-08 09:35:50 +00:00
|
|
|
result.gasPrice = tx.gasPrice.get.GasInt
|
2020-07-23 15:30:42 +00:00
|
|
|
else:
|
|
|
|
result.gasPrice = calculateMedianGasPrice(chain)
|
|
|
|
|
|
|
|
if tx.value.isSome:
|
2023-12-08 09:35:50 +00:00
|
|
|
result.value = tx.value.get
|
2020-07-23 15:30:42 +00:00
|
|
|
else:
|
|
|
|
result.value = 0.u256
|
|
|
|
|
|
|
|
if tx.nonce.isSome:
|
2023-12-08 09:35:50 +00:00
|
|
|
result.nonce = tx.nonce.get.AccountNonce
|
2020-07-23 15:30:42 +00:00
|
|
|
else:
|
|
|
|
result.nonce = defaultNonce
|
|
|
|
|
2024-03-21 01:05:22 +00:00
|
|
|
result.payload = tx.payload
|
2020-07-23 15:30:42 +00:00
|
|
|
|
2023-08-16 10:05:14 +00:00
|
|
|
proc toWd(wd: Withdrawal): WithdrawalObject =
|
|
|
|
WithdrawalObject(
|
2023-12-08 09:35:50 +00:00
|
|
|
index: w3Qty wd.index,
|
|
|
|
validatorIndex: w3Qty wd.validatorIndex,
|
|
|
|
address: w3Addr wd.address,
|
|
|
|
amount: w3Qty wd.amount,
|
2023-08-16 10:05:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
proc toWdList(list: openArray[Withdrawal]): seq[WithdrawalObject] =
|
|
|
|
result = newSeqOfCap[WithdrawalObject](list.len)
|
|
|
|
for x in list:
|
|
|
|
result.add toWd(x)
|
|
|
|
|
2023-11-02 04:38:07 +00:00
|
|
|
proc populateTransactionObject*(tx: Transaction,
|
2024-06-14 07:31:08 +00:00
|
|
|
optionalHeader: Opt[BlockHeader] = Opt.none(BlockHeader),
|
|
|
|
txIndex: Opt[uint64] = Opt.none(uint64)): TransactionObject
|
2023-01-31 01:32:17 +00:00
|
|
|
{.gcsafe, raises: [ValidationError].} =
|
2023-12-08 09:35:50 +00:00
|
|
|
result = TransactionObject()
|
2024-06-14 07:31:08 +00:00
|
|
|
result.`type` = Opt.some Quantity(tx.txType)
|
2023-12-08 09:35:50 +00:00
|
|
|
if optionalHeader.isSome:
|
|
|
|
let header = optionalHeader.get
|
2024-06-14 07:31:08 +00:00
|
|
|
result.blockHash = Opt.some(w3Hash header.blockHash)
|
|
|
|
result.blockNumber = Opt.some(w3BlockNumber(header.number))
|
2023-12-08 09:35:50 +00:00
|
|
|
|
|
|
|
result.`from` = w3Addr tx.getSender()
|
|
|
|
result.gas = w3Qty(tx.gasLimit)
|
|
|
|
result.gasPrice = w3Qty(tx.gasPrice)
|
|
|
|
result.hash = w3Hash tx.rlpHash
|
2022-04-08 04:54:11 +00:00
|
|
|
result.input = tx.payload
|
2023-12-08 09:35:50 +00:00
|
|
|
result.nonce = w3Qty(tx.nonce)
|
2024-06-14 07:31:08 +00:00
|
|
|
result.to = Opt.some(w3Addr tx.destination)
|
2023-10-20 08:30:05 +00:00
|
|
|
if txIndex.isSome:
|
2024-06-14 07:31:08 +00:00
|
|
|
result.transactionIndex = Opt.some(Quantity(txIndex.get))
|
2023-12-08 09:35:50 +00:00
|
|
|
result.value = tx.value
|
|
|
|
result.v = w3Qty(tx.V)
|
2024-06-14 07:31:08 +00:00
|
|
|
result.r = tx.R
|
|
|
|
result.s = tx.S
|
|
|
|
result.maxFeePerGas = Opt.some w3Qty(tx.maxFeePerGas)
|
|
|
|
result.maxPriorityFeePerGas = Opt.some w3Qty(tx.maxPriorityFeePerGas)
|
2020-07-30 07:21:11 +00:00
|
|
|
|
2023-08-16 10:05:14 +00:00
|
|
|
if tx.txType >= TxEip2930:
|
2024-06-14 07:31:08 +00:00
|
|
|
result.chainId = Opt.some(Web3Quantity(tx.chainId))
|
|
|
|
result.accessList = Opt.some(w3AccessList(tx.accessList))
|
2023-08-17 04:08:01 +00:00
|
|
|
|
2023-08-16 10:05:14 +00:00
|
|
|
if tx.txType >= TxEIP4844:
|
2024-06-14 07:31:08 +00:00
|
|
|
result.maxFeePerBlobGas = Opt.some(tx.maxFeePerBlobGas)
|
|
|
|
result.blobVersionedHashes = Opt.some(w3Hashes tx.versionedHashes)
|
2023-08-16 10:05:14 +00:00
|
|
|
|
2023-08-04 11:10:09 +00:00
|
|
|
proc populateBlockObject*(header: BlockHeader, chain: CoreDbRef, fullTx: bool, isUncle = false): BlockObject
|
2023-01-31 01:32:17 +00:00
|
|
|
{.gcsafe, raises: [CatchableError].} =
|
2020-07-30 07:21:11 +00:00
|
|
|
let blockHash = header.blockHash
|
2023-12-08 09:35:50 +00:00
|
|
|
result = BlockObject()
|
2020-07-30 07:21:11 +00:00
|
|
|
|
2024-06-14 07:31:08 +00:00
|
|
|
result.number = w3BlockNumber(header.number)
|
2023-12-08 09:35:50 +00:00
|
|
|
result.hash = w3Hash blockHash
|
|
|
|
result.parentHash = w3Hash header.parentHash
|
2024-06-14 07:31:08 +00:00
|
|
|
result.nonce = Opt.some(FixedBytes[8] header.nonce)
|
2023-12-08 09:35:50 +00:00
|
|
|
result.sha3Uncles = w3Hash header.ommersHash
|
2024-06-14 07:31:08 +00:00
|
|
|
result.logsBloom = FixedBytes[256] header.logsBloom
|
2023-12-08 09:35:50 +00:00
|
|
|
result.transactionsRoot = w3Hash header.txRoot
|
|
|
|
result.stateRoot = w3Hash header.stateRoot
|
2024-06-14 07:31:08 +00:00
|
|
|
result.receiptsRoot = w3Hash header.receiptsRoot
|
2023-12-08 09:35:50 +00:00
|
|
|
result.miner = w3Addr header.coinbase
|
|
|
|
result.difficulty = header.difficulty
|
|
|
|
result.extraData = HistoricExtraData header.extraData
|
2024-06-14 07:31:08 +00:00
|
|
|
result.mixHash = w3Hash header.mixHash
|
2020-07-30 07:21:11 +00:00
|
|
|
|
|
|
|
# discard sizeof(seq[byte]) of extraData and use actual length
|
2024-03-21 01:05:22 +00:00
|
|
|
let size = sizeof(BlockHeader) - sizeof(common.Blob) + header.extraData.len
|
2024-06-14 07:31:08 +00:00
|
|
|
result.size = Quantity(size)
|
2020-07-30 07:21:11 +00:00
|
|
|
|
2023-12-08 09:35:50 +00:00
|
|
|
result.gasLimit = w3Qty(header.gasLimit)
|
|
|
|
result.gasUsed = w3Qty(header.gasUsed)
|
|
|
|
result.timestamp = w3Qty(header.timestamp)
|
2024-06-14 07:31:08 +00:00
|
|
|
result.baseFeePerGas = header.baseFeePerGas
|
|
|
|
|
2020-07-30 07:21:11 +00:00
|
|
|
if not isUncle:
|
2024-06-14 05:10:00 +00:00
|
|
|
result.totalDifficulty = chain.getScore(blockHash).valueOr(0.u256)
|
2023-12-08 09:35:50 +00:00
|
|
|
result.uncles = w3Hashes chain.getUncleHashes(header)
|
2020-07-30 07:21:11 +00:00
|
|
|
|
|
|
|
if fullTx:
|
2024-06-14 07:31:08 +00:00
|
|
|
var i = 0'u64
|
2020-07-30 07:21:11 +00:00
|
|
|
for tx in chain.getBlockTransactions(header):
|
2024-06-14 07:31:08 +00:00
|
|
|
result.transactions.add txOrHash(populateTransactionObject(tx, Opt.some(header), Opt.some(i)))
|
2020-07-30 07:21:11 +00:00
|
|
|
inc i
|
|
|
|
else:
|
|
|
|
for x in chain.getBlockTransactionHashes(header):
|
2023-12-08 09:35:50 +00:00
|
|
|
result.transactions.add txOrHash(w3Hash(x))
|
2020-07-30 07:21:11 +00:00
|
|
|
|
2023-08-16 10:05:14 +00:00
|
|
|
if header.withdrawalsRoot.isSome:
|
2024-06-14 07:31:08 +00:00
|
|
|
result.withdrawalsRoot = Opt.some(w3Hash header.withdrawalsRoot.get)
|
|
|
|
result.withdrawals = Opt.some(toWdList(chain.getWithdrawals(header.withdrawalsRoot.get)))
|
2023-08-16 10:05:14 +00:00
|
|
|
|
|
|
|
if header.blobGasUsed.isSome:
|
2024-06-14 07:31:08 +00:00
|
|
|
result.blobGasUsed = Opt.some(w3Qty(header.blobGasUsed.get))
|
2023-08-16 10:05:14 +00:00
|
|
|
|
|
|
|
if header.excessBlobGas.isSome:
|
2024-06-14 07:31:08 +00:00
|
|
|
result.excessBlobGas = Opt.some(w3Qty(header.excessBlobGas.get))
|
2023-08-16 10:05:14 +00:00
|
|
|
|
2023-12-08 09:35:50 +00:00
|
|
|
if header.parentBeaconBlockRoot.isSome:
|
2024-06-14 07:31:08 +00:00
|
|
|
result.parentBeaconBlockRoot = Opt.some(w3Hash header.parentBeaconBlockRoot.get)
|
2023-08-30 16:29:48 +00:00
|
|
|
|
2022-12-02 04:39:12 +00:00
|
|
|
proc populateReceipt*(receipt: Receipt, gasUsed: GasInt, tx: Transaction,
|
2024-06-14 07:31:08 +00:00
|
|
|
txIndex: uint64, header: BlockHeader): ReceiptObject
|
2023-01-31 01:32:17 +00:00
|
|
|
{.gcsafe, raises: [ValidationError].} =
|
2023-12-08 09:35:50 +00:00
|
|
|
result = ReceiptObject()
|
|
|
|
result.transactionHash = w3Hash tx.rlpHash
|
|
|
|
result.transactionIndex = w3Qty(txIndex)
|
2024-06-14 05:10:00 +00:00
|
|
|
result.blockHash = w3Hash header.blockHash
|
2024-06-14 07:31:08 +00:00
|
|
|
result.blockNumber = w3BlockNumber(header.number)
|
2023-12-08 09:35:50 +00:00
|
|
|
result.`from` = w3Addr tx.getSender()
|
2024-06-14 07:31:08 +00:00
|
|
|
result.to = Opt.some(w3Addr tx.destination)
|
2023-12-08 09:35:50 +00:00
|
|
|
result.cumulativeGasUsed = w3Qty(receipt.cumulativeGasUsed)
|
|
|
|
result.gasUsed = w3Qty(gasUsed)
|
2024-06-14 07:31:08 +00:00
|
|
|
result.`type` = Opt.some Quantity(receipt.receiptType)
|
2020-07-30 07:21:11 +00:00
|
|
|
|
2021-06-27 04:19:43 +00:00
|
|
|
if tx.contractCreation:
|
2020-07-30 07:21:11 +00:00
|
|
|
var sender: EthAddress
|
|
|
|
if tx.getSender(sender):
|
2021-05-15 07:18:21 +00:00
|
|
|
let contractAddress = generateAddress(sender, tx.nonce)
|
2024-06-14 07:31:08 +00:00
|
|
|
result.contractAddress = Opt.some(w3Addr contractAddress)
|
2020-07-30 07:21:11 +00:00
|
|
|
|
2023-03-27 19:10:43 +00:00
|
|
|
for log in receipt.logs:
|
|
|
|
# TODO: Work everywhere with either `Hash256` as topic or `array[32, byte]`
|
2023-12-08 09:35:50 +00:00
|
|
|
var topics: seq[Web3Topic]
|
2023-03-27 19:10:43 +00:00
|
|
|
for topic in log.topics:
|
2023-12-08 09:35:50 +00:00
|
|
|
topics.add Web3Topic(topic)
|
2023-03-27 19:10:43 +00:00
|
|
|
|
|
|
|
let logObject = FilterLog(
|
|
|
|
removed: false,
|
|
|
|
# TODO: Not sure what is difference between logIndex and TxIndex and how
|
|
|
|
# to calculate it.
|
2024-06-14 07:31:08 +00:00
|
|
|
logIndex: Opt.some(result.transactionIndex),
|
2023-03-27 19:10:43 +00:00
|
|
|
# Note: the next 4 fields cause a lot of duplication of data, but the spec
|
|
|
|
# is what it is. Not sure if other clients actually add this.
|
2024-06-14 07:31:08 +00:00
|
|
|
transactionIndex: Opt.some(result.transactionIndex),
|
|
|
|
transactionHash: Opt.some(result.transactionHash),
|
|
|
|
blockHash: Opt.some(result.blockHash),
|
|
|
|
blockNumber: Opt.some(result.blockNumber),
|
2023-03-27 19:10:43 +00:00
|
|
|
# The actual fields
|
2023-12-08 09:35:50 +00:00
|
|
|
address: w3Addr log.address,
|
2023-03-27 19:10:43 +00:00
|
|
|
data: log.data,
|
|
|
|
topics: topics
|
|
|
|
)
|
|
|
|
result.logs.add(logObject)
|
|
|
|
|
2024-06-14 07:31:08 +00:00
|
|
|
result.logsBloom = FixedBytes[256] receipt.logsBloom
|
2020-07-30 07:21:11 +00:00
|
|
|
|
|
|
|
# post-transaction stateroot (pre Byzantium).
|
|
|
|
if receipt.hasStateRoot:
|
2024-06-14 07:31:08 +00:00
|
|
|
result.root = Opt.some(w3Hash receipt.stateRoot)
|
2020-07-30 07:21:11 +00:00
|
|
|
else:
|
|
|
|
# 1 = success, 0 = failure.
|
2024-06-14 07:31:08 +00:00
|
|
|
result.status = Opt.some(w3Qty(receipt.status.uint64))
|
2022-04-05 10:32:54 +00:00
|
|
|
|
2024-06-14 07:31:08 +00:00
|
|
|
let baseFeePerGas = header.baseFeePerGas.get(0.u256)
|
|
|
|
let normTx = eip1559TxNormalization(tx, baseFeePerGas.truncate(GasInt))
|
2023-12-08 09:35:50 +00:00
|
|
|
result.effectiveGasPrice = w3Qty(normTx.gasPrice)
|
2023-11-02 04:38:07 +00:00
|
|
|
|
|
|
|
if tx.txType == TxEip4844:
|
2024-06-14 07:31:08 +00:00
|
|
|
result.blobGasUsed = Opt.some(w3Qty(tx.versionedHashes.len.uint64 * GAS_PER_BLOB.uint64))
|
|
|
|
result.blobGasPrice = Opt.some(getBlobBaseFee(header.excessBlobGas.get(0'u64)))
|
2024-03-21 11:24:32 +00:00
|
|
|
|
|
|
|
proc createAccessList*(header: BlockHeader,
|
|
|
|
com: CommonRef,
|
2024-06-07 08:24:32 +00:00
|
|
|
args: TransactionArgs): AccessListResult =
|
|
|
|
|
|
|
|
template handleError(msg: string) =
|
|
|
|
return AccessListResult(
|
2024-06-14 07:31:08 +00:00
|
|
|
error: Opt.some(msg),
|
2024-06-07 08:24:32 +00:00
|
|
|
)
|
|
|
|
|
2024-03-21 11:24:32 +00:00
|
|
|
var args = args
|
|
|
|
|
|
|
|
# If the gas amount is not set, default to RPC gas cap.
|
2024-04-16 12:52:07 +00:00
|
|
|
if args.gas.isNone:
|
2024-06-14 07:31:08 +00:00
|
|
|
args.gas = Opt.some(Quantity DEFAULT_RPC_GAS_CAP)
|
2024-03-21 11:24:32 +00:00
|
|
|
|
|
|
|
let
|
2024-06-07 08:24:32 +00:00
|
|
|
vmState = BaseVMState.new(header, com).valueOr:
|
|
|
|
handleError("failed to create vmstate: " & $error.code)
|
2024-06-14 07:31:08 +00:00
|
|
|
fork = com.toEVMFork(forkDeterminationInfo(header.number, header.timestamp))
|
2024-04-16 12:52:07 +00:00
|
|
|
sender = args.sender
|
2024-03-21 11:24:32 +00:00
|
|
|
# TODO: nonce should be retrieved from txPool
|
|
|
|
nonce = vmState.stateDB.getNonce(sender)
|
2024-04-16 12:52:07 +00:00
|
|
|
to = if args.to.isSome: ethAddr args.to.get
|
2024-03-21 11:24:32 +00:00
|
|
|
else: generateAddress(sender, nonce)
|
|
|
|
precompiles = activePrecompilesList(fork)
|
|
|
|
|
2024-04-16 12:52:07 +00:00
|
|
|
var
|
|
|
|
prevTracer = AccessListTracer.new(
|
|
|
|
ethAccessList args.accessList,
|
|
|
|
sender,
|
|
|
|
to,
|
|
|
|
precompiles)
|
2024-03-21 11:24:32 +00:00
|
|
|
|
|
|
|
while true:
|
|
|
|
# Retrieve the current access list to expand
|
|
|
|
let accessList = prevTracer.accessList()
|
|
|
|
|
|
|
|
# Set the accesslist to the last accessList
|
|
|
|
# generated by prevTracer
|
2024-06-14 07:31:08 +00:00
|
|
|
args.accessList = Opt.some(w3AccessList accessList)
|
2024-03-21 11:24:32 +00:00
|
|
|
|
|
|
|
# Apply the transaction with the access list tracer
|
|
|
|
let
|
|
|
|
tracer = AccessListTracer.new(accessList, sender, to, precompiles)
|
2024-06-07 08:24:32 +00:00
|
|
|
vmState = BaseVMState.new(header, com, tracer).valueOr:
|
|
|
|
handleError("failed to create vmstate: " & $error.code)
|
|
|
|
res = rpcCallEvm(args, header, com, vmState).valueOr:
|
|
|
|
handleError("failed to call evm: " & $error.code)
|
2024-03-21 11:24:32 +00:00
|
|
|
|
|
|
|
if res.isError:
|
2024-06-07 08:24:32 +00:00
|
|
|
handleError("failed to apply transaction: " & res.error)
|
2024-03-21 11:24:32 +00:00
|
|
|
|
|
|
|
if tracer.equal(prevTracer):
|
|
|
|
return AccessListResult(
|
|
|
|
accessList: w3AccessList accessList,
|
|
|
|
gasUsed: w3Qty res.gasUsed,
|
|
|
|
)
|
|
|
|
|
|
|
|
prevTracer = tracer
|