Skip to content

Commit

Permalink
Rewrite test_txpool
Browse files Browse the repository at this point in the history
  • Loading branch information
jangko committed Dec 25, 2024
1 parent 207135f commit 4d1b321
Show file tree
Hide file tree
Showing 10 changed files with 343 additions and 2,553 deletions.
4 changes: 1 addition & 3 deletions nimbus/core/tx_pool/tx_desc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,7 @@ proc addTx*(xp: TxPoolRef, ptx: PooledTransaction): Result[void, TxError] =
validateTxBasic(
ptx.tx,
xp.nextFork,
# A new transaction of the next fork may be
# coming before the fork activated
validateFork = false).isOkOr:
validateFork = true).isOkOr:
return err(txErrorBasicValidation)

let
Expand Down
3 changes: 1 addition & 2 deletions nimbus/core/tx_pool/tx_packer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,10 @@ proc classifyValidatePacked(vmState: BaseVMState; item: TxItemRef): bool =
baseFee = vmState.blockCtx.baseFeePerGas.get(0.u256)
fork = vmState.fork
gasLimit = vmState.blockCtx.gasLimit
tx = item.tx.eip1559TxNormalization(baseFee.truncate(GasInt))
excessBlobGas = calcExcessBlobGas(vmState.parent, vmState.fork >= FkPrague)

roDB.validateTransaction(
tx, item.sender, gasLimit, baseFee, excessBlobGas, fork).isOk
item.tx, item.sender, gasLimit, baseFee, excessBlobGas, fork).isOk

proc classifyPacked(vmState: BaseVMState; moreBurned: GasInt): bool =
## Classifier for *packing* (i.e. adding up `gasUsed` values after executing
Expand Down
4 changes: 2 additions & 2 deletions nimbus/rpc/rpc_utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ proc populateReceipt*(receipt: Receipt, gasUsed: GasInt, tx: Transaction,
res.status = Opt.some(Quantity(receipt.status.uint64))

let baseFeePerGas = header.baseFeePerGas.get(0.u256)
let normTx = eip1559TxNormalization(tx, baseFeePerGas.truncate(GasInt))
res.effectiveGasPrice = Quantity(normTx.gasPrice)
let gasPrice = effectiveGasPrice(tx, baseFeePerGas.truncate(GasInt))
res.effectiveGasPrice = Quantity(gasPrice)

if tx.txType == TxEip4844:
res.blobGasUsed = Opt.some(Quantity(tx.versionedHashes.len.uint64 * GAS_PER_BLOB.uint64))
Expand Down
13 changes: 0 additions & 13 deletions nimbus/transaction.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,6 @@ func validateChainId*(tx: Transaction, chainId: ChainId): bool =
else:
chainId.uint64 == tx.chainId.uint64

func eip1559TxNormalization*(tx: Transaction;
baseFeePerGas: GasInt): Transaction =
## This function adjusts a legacy transaction to EIP-1559 standard. This
## is needed particularly when using the `validateTransaction()` utility
## with legacy transactions.
result = tx
if tx.txType < TxEip1559:
result.maxPriorityFeePerGas = tx.gasPrice
result.maxFeePerGas = tx.gasPrice
else:
result.gasPrice = baseFeePerGas +
min(result.maxPriorityFeePerGas, result.maxFeePerGas - baseFeePerGas)

func maxPriorityFeePerGasNorm*(tx: Transaction): GasInt =
if tx.txType < TxEip1559:
tx.gasPrice
Expand Down
2 changes: 1 addition & 1 deletion tests/all_tests.nim
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ cliBuilder:
./test_multi_keys,
#./test_graphql, -- fails
./test_configuration,
#./test_txpool, -- fails
./test_txpool,
./test_txpool2,
./test_engine_api,
./test_getproof_json,
Expand Down
Loading

0 comments on commit 4d1b321

Please sign in to comment.