Fix bugs discovered by engine api simulator

This commit is contained in:
jangko 2023-08-17 11:08:01 +07:00
parent 2e85e6b2de
commit 5644749de9
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
5 changed files with 53 additions and 50 deletions

View File

@ -319,6 +319,7 @@ proc persistStorage(acc: RefAccount, db: CoreDbRef, clearCache: bool) =
if not clearCache and acc.originalStorage.isNil: if not clearCache and acc.originalStorage.isNil:
acc.originalStorage = newTable[UInt256, UInt256]() acc.originalStorage = newTable[UInt256, UInt256]()
db.compensateLegacySetup()
var storageTrie = getStorageTrie(db, acc) var storageTrie = getStorageTrie(db, acc)
for slot, value in acc.overlayStorage: for slot, value in acc.overlayStorage:

View File

@ -425,6 +425,8 @@ proc start(nimbus: NimbusNode, conf: NimbusConf) =
) )
com.initializeEmptyDb() com.initializeEmptyDb()
com.db.compensateLegacySetup()
let protocols = conf.getProtocolFlags() let protocols = conf.getProtocolFlags()
case conf.cmd case conf.cmd

View File

@ -493,8 +493,9 @@ proc handle_getPayloadBodiesByHash(sealingEngine: SealingEngineRef,
for tx in body.transactions: for tx in body.transactions:
typedTransactions.add(tx.toTypedTransaction) typedTransactions.add(tx.toTypedTransaction)
var withdrawals: seq[WithdrawalV1] var withdrawals: seq[WithdrawalV1]
for w in body.withdrawals.get: if body.withdrawals.isSome:
withdrawals.add(w.toWithdrawalV1) for w in body.withdrawals.get:
withdrawals.add(w.toWithdrawalV1)
result.add( result.add(
some(ExecutionPayloadBodyV1( some(ExecutionPayloadBodyV1(
transactions: typedTransactions, transactions: typedTransactions,
@ -529,8 +530,9 @@ proc handle_getPayloadBodiesByRange(sealingEngine: SealingEngineRef,
for tx in body.transactions: for tx in body.transactions:
typedTransactions.add(tx.toTypedTransaction) typedTransactions.add(tx.toTypedTransaction)
var withdrawals: seq[WithdrawalV1] var withdrawals: seq[WithdrawalV1]
for w in body.withdrawals.get: if body.withdrawals.isSome:
withdrawals.add(w.toWithdrawalV1) for w in body.withdrawals.get:
withdrawals.add(w.toWithdrawalV1)
result.add( result.add(
some(ExecutionPayloadBodyV1( some(ExecutionPayloadBodyV1(
transactions: typedTransactions, transactions: typedTransactions,

View File

@ -53,27 +53,27 @@ type
## Note that this includes slightly different information from eth/common.BlockHeader ## Note that this includes slightly different information from eth/common.BlockHeader
BlockObject* = object BlockObject* = object
# Returned to user # Returned to user
number*: Option[HexQuantityStr] # the block number. null when its pending block. number*: Option[HexQuantityStr] # the block number. null when its pending block.
hash*: Option[Hash256] # hash of the block. null when its pending block. hash*: Option[Hash256] # hash of the block. null when its pending block.
parentHash*: Hash256 # hash of the parent block. parentHash*: Hash256 # hash of the parent block.
nonce*: Option[HexDataStr] # hash of the generated proof-of-work. null when its pending block. nonce*: Option[HexDataStr] # hash of the generated proof-of-work. null when its pending block.
sha3Uncles*: Hash256 # SHA3 of the uncles data in the block. sha3Uncles*: Hash256 # SHA3 of the uncles data in the block.
logsBloom*: FixedBytes[256] # the bloom filter for the logs of the block. null when its pending block. logsBloom*: FixedBytes[256] # the bloom filter for the logs of the block. null when its pending block.
transactionsRoot*: Hash256 # the root of the transaction trie of the block. transactionsRoot*: Hash256 # the root of the transaction trie of the block.
stateRoot*: Hash256 # the root of the final state trie of the block. stateRoot*: Hash256 # the root of the final state trie of the block.
receiptsRoot*: Hash256 # the root of the receipts trie of the block. receiptsRoot*: Hash256 # the root of the receipts trie of the block.
miner*: EthAddress # the address of the beneficiary to whom the mining rewards were given. miner*: EthAddress # the address of the beneficiary to whom the mining rewards were given.
difficulty*: HexQuantityStr # integer of the difficulty for this block. difficulty*: HexQuantityStr # integer of the difficulty for this block.
totalDifficulty*: HexQuantityStr# integer of the total difficulty of the chain until this block. totalDifficulty*: HexQuantityStr # integer of the total difficulty of the chain until this block.
extraData*: HexDataStr # the "extra data" field of this block. extraData*: HexDataStr # the "extra data" field of this block.
mixHash*: Hash256 mixHash*: Hash256
size*: HexQuantityStr # integer the size of this block in bytes. size*: HexQuantityStr # integer the size of this block in bytes.
gasLimit*: HexQuantityStr # the maximum gas allowed in this block. gasLimit*: HexQuantityStr # the maximum gas allowed in this block.
gasUsed*: HexQuantityStr # the total used gas by all transactions in this block. gasUsed*: HexQuantityStr # the total used gas by all transactions in this block.
timestamp*: HexQuantityStr # the unix timestamp for when the block was collated. timestamp*: HexQuantityStr # the unix timestamp for when the block was collated.
baseFeePerGas*: Option[HexQuantityStr] baseFeePerGas*: Option[HexQuantityStr]
transactions*: seq[JsonNode] # list of transaction objects, or 32 Bytes transaction hashes depending on the last given parameter. transactions*: seq[JsonNode] # list of transaction objects, or 32 Bytes transaction hashes depending on the last given parameter.
uncles*: seq[Hash256] # list of uncle hashes. uncles*: seq[Hash256] # list of uncle hashes.
withdrawals*: Option[seq[WithdrawalObject]] # list of validator withdrawals withdrawals*: Option[seq[WithdrawalObject]] # list of validator withdrawals
withdrawalsRoot*: Option[Hash256] # EIP-4895 withdrawalsRoot*: Option[Hash256] # EIP-4895
blobGasUsed*: Option[HexQuantityStr] # EIP-4844 blobGasUsed*: Option[HexQuantityStr] # EIP-4844
@ -81,27 +81,27 @@ type
TransactionObject* = object # A transaction object, or null when no transaction was found: TransactionObject* = object # A transaction object, or null when no transaction was found:
# Returned to user # Returned to user
blockHash*: Option[Hash256] # hash of the block where this transaction was in. null when its pending. `type`*: HexQuantityStr # EIP-2718, with 0x0 for Legacy
blockNumber*: Option[HexQuantityStr] # block number where this transaction was in. null when its pending. blockHash*: Option[Hash256] # hash of the block where this transaction was in. null when its pending.
`from`*: EthAddress # address of the sender. blockNumber*: Option[HexQuantityStr] # block number where this transaction was in. null when its pending.
gas*: HexQuantityStr # gas provided by the sender. `from`*: EthAddress # address of the sender.
gasPrice*: HexQuantityStr # gas price provided by the sender in Wei. gas*: HexQuantityStr # gas provided by the sender.
hash*: Hash256 # hash of the transaction. gasPrice*: HexQuantityStr # gas price provided by the sender in Wei.
input*: Blob # the data send along with the transaction. maxFeePerGas*: HexQuantityStr # EIP-1559
nonce*: HexQuantityStr # the number of transactions made by the sender prior to this one. maxPriorityFeePerGas*: HexQuantityStr # EIP-1559
to*: Option[EthAddress] # address of the receiver. null when its a contract creation transaction. hash*: Hash256 # hash of the transaction.
input*: Blob # the data send along with the transaction.
nonce*: HexQuantityStr # the number of transactions made by the sender prior to this one.
to*: Option[EthAddress] # address of the receiver. null when its a contract creation transaction.
transactionIndex*: Option[HexQuantityStr] # integer of the transactions index position in the block. null when its pending. transactionIndex*: Option[HexQuantityStr] # integer of the transactions index position in the block. null when its pending.
value*: HexQuantityStr # value transferred in Wei. value*: HexQuantityStr # value transferred in Wei.
v*: HexQuantityStr # ECDSA recovery id v*: HexQuantityStr # ECDSA recovery id
r*: HexQuantityStr # 32 Bytes - ECDSA signature r r*: HexQuantityStr # 32 Bytes - ECDSA signature r
s*: HexQuantityStr # 32 Bytes - ECDSA signature s s*: HexQuantityStr # 32 Bytes - ECDSA signature s
`type`*: Option[HexQuantityStr] # EIP-2718, with 0x0 for Legacy chainId*: Option[HexQuantityStr] # EIP-159
chainId*: Option[HexQuantityStr] # EIP-159 accessList*: Option[seq[AccessTuple]] # EIP-2930
accessList*: Option[seq[AccessTuple]] # EIP-2930 maxFeePerBlobGas*: Option[HexQuantityStr] # EIP-4844
maxFeePerGas*: Option[HexQuantityStr] # EIP-1559 versionedHashes*: Option[VersionedHashes] # EIP-4844
maxPriorityFeePerGas*: Option[HexQuantityStr] # EIP-1559
maxFeePerBlobGas*: Option[HexQuantityStr] # EIP-4844
versionedHashes*: Option[VersionedHashes] # EIP-4844
AccessTuple* = object AccessTuple* = object
address*: EthAddress address*: EthAddress

View File

@ -166,6 +166,7 @@ proc toAccessTupleList(list: openArray[AccessPair]): seq[AccessTuple] =
proc populateTransactionObject*(tx: Transaction, header: BlockHeader, txIndex: int): TransactionObject proc populateTransactionObject*(tx: Transaction, header: BlockHeader, txIndex: int): TransactionObject
{.gcsafe, raises: [ValidationError].} = {.gcsafe, raises: [ValidationError].} =
result.`type` = encodeQuantity(tx.txType.uint64)
result.blockHash = some(header.hash) result.blockHash = some(header.hash)
result.blockNumber = some(encodeQuantity(header.blockNumber)) result.blockNumber = some(encodeQuantity(header.blockNumber))
result.`from` = tx.getSender() result.`from` = tx.getSender()
@ -180,16 +181,13 @@ proc populateTransactionObject*(tx: Transaction, header: BlockHeader, txIndex: i
result.v = encodeQuantity(tx.V.uint) result.v = encodeQuantity(tx.V.uint)
result.r = encodeQuantity(tx.R) result.r = encodeQuantity(tx.R)
result.s = encodeQuantity(tx.S) result.s = encodeQuantity(tx.S)
result.maxFeePerGas = encodeQuantity(tx.maxFee.uint64)
result.maxPriorityFeePerGas = encodeQuantity(tx.maxPriorityFee.uint64)
if tx.txType >= TxEip2930: if tx.txType >= TxEip2930:
result.chainId = some(encodeQuantity(tx.chainId.uint64)) result.chainId = some(encodeQuantity(tx.chainId.uint64))
result.`type` = some(encodeQuantity(tx.txType.uint64))
result.accessList = some(toAccessTupleList(tx.accessList)) result.accessList = some(toAccessTupleList(tx.accessList))
if tx.txType >= TxEIP1559:
result.maxFeePerGas = some(encodeQuantity(tx.maxFee.uint64))
result.maxPriorityFeePerGas = some(encodeQuantity(tx.maxPriorityFee.uint64))
if tx.txType >= TxEIP4844: if tx.txType >= TxEIP4844:
result.maxFeePerBlobGas = some(encodeQuantity(tx.maxFeePerBlobGas.uint64)) result.maxFeePerBlobGas = some(encodeQuantity(tx.maxFeePerBlobGas.uint64))
#result.versionedHashes = some(tx.versionedHashes) #result.versionedHashes = some(tx.versionedHashes)