From 0589d49dbc71492d20365fabc4247beed92adb8b Mon Sep 17 00:00:00 2001 From: jangko Date: Sun, 2 Jul 2023 19:23:01 +0700 Subject: [PATCH] fix txpool + POA regression, header.coinbase should empty --- nimbus/core/tx_pool/tx_chain.nim | 7 +++--- tests/test_txpool2.nim | 39 +++++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/nimbus/core/tx_pool/tx_chain.nim b/nimbus/core/tx_pool/tx_chain.nim index 2771e23c02..566c370389 100644 --- a/nimbus/core/tx_pool/tx_chain.nim +++ b/nimbus/core/tx_pool/tx_chain.nim @@ -91,7 +91,6 @@ proc prepareHeader(dh: TxChainRef; parent: BlockHeader, timestamp: EthTime) # but BaseVMState.minerAddress == signerAddress # - minerAddress is extracted from header.extraData # - header.coinbase is from clique engine - dh.prepHeader.coinbase = dh.miner of ConsensusType.POS: dh.com.pos.prepare(dh.prepHeader) @@ -118,6 +117,8 @@ proc getTimestamp(dh: TxChainRef, parent: BlockHeader): EthTime = of ConsensusType.POS: dh.com.pos.timestamp +proc feeRecipient*(dh: TxChainRef): EthAddress {.gcsafe.} + proc resetTxEnv(dh: TxChainRef; parent: BlockHeader; fee: Option[UInt256]) {.gcsafe,raises: [CatchableError].} = dh.txEnv.reset @@ -138,7 +139,7 @@ proc resetTxEnv(dh: TxChainRef; parent: BlockHeader; fee: Option[UInt256]) fee = fee, prevRandao= dh.prepHeader.prevRandao, difficulty= dh.prepHeader.difficulty, - miner = dh.prepHeader.coinbase, + miner = dh.feeRecipient, com = dh.com) dh.txEnv.txRoot = EMPTY_ROOT_HASH @@ -260,7 +261,7 @@ proc maxMode*(dh: TxChainRef): bool = ## Getter dh.maxMode -proc feeRecipient*(dh: TxChainRef): EthAddress = +proc feeRecipient*(dh: TxChainRef): EthAddress {.gcsafe.} = ## Getter if dh.com.consensus == ConsensusType.POS: dh.com.pos.feeRecipient diff --git a/tests/test_txpool2.nim b/tests/test_txpool2.nim index 2199fbb353..09ddb95ced 100644 --- a/tests/test_txpool2.nim +++ b/tests/test_txpool2.nim @@ -1,5 +1,5 @@ import - std/[math, tables, times], + std/[math, tables, times, os], eth/[keys], stew/[byteutils, results], unittest2, ../nimbus/db/state_db, @@ -172,6 +172,39 @@ proc runTxPoolCliqueTest*() = let rr = chain.persistBlocks([blk.header], [body]) check rr == ValidationResult.OK + test "Do not kick the signer out of list": + let timestamp = blk.header.timestamp + check xp.smartHead(blk.header) + + let tx = env.makeTx(recipient, amount) + let res = xp.addLocal(tx, force = true) + check res.isOk + if res.isErr: + debugEcho res.error + return + check xp.nItems.total == 1 + + blk = xp.ethBlock() + body = BlockBody( + transactions: blk.txs, + uncles: blk.uncles + ) + check blk.txs.len == 1 + + let rx = clique.seal(blk) + check rx.isOk + if rx.isErr: + debugEcho rx.error + return + + # prevent block from future detected in persistBlocks + os.sleep(com.cliquePeriod * 1000) + + xp.chain.clearAccounts + check xp.chain.vmState.processBlock(com.poa, blk.header, body).isOK + let rr = chain.persistBlocks([blk.header], [body]) + check rr == ValidationResult.OK + proc runTxPoolPosTest*() = var env = initEnv(some(100.u256)) @@ -303,7 +336,7 @@ when isMainModule: setErrorLevel() # mute logger runTxPoolCliqueTest() - runTxPoolPosTest() - noisy.runTxHeadDelta + #runTxPoolPosTest() + #noisy.runTxHeadDelta # End