Skip to content

Commit

Permalink
fix txpool + POA regression, header.coinbase should empty
Browse files Browse the repository at this point in the history
  • Loading branch information
jangko committed Jul 2, 2023
1 parent a7c0888 commit 0589d49
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
7 changes: 4 additions & 3 deletions nimbus/core/tx_pool/tx_chain.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
39 changes: 36 additions & 3 deletions tests/test_txpool2.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import
std/[math, tables, times],
std/[math, tables, times, os],
eth/[keys],
stew/[byteutils, results], unittest2,
../nimbus/db/state_db,
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -303,7 +336,7 @@ when isMainModule:
setErrorLevel() # mute logger

runTxPoolCliqueTest()
runTxPoolPosTest()
noisy.runTxHeadDelta
#runTxPoolPosTest()
#noisy.runTxHeadDelta

# End

0 comments on commit 0589d49

Please sign in to comment.