Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix txpool + POA regression, header.coinbase should empty #1624

Merged
merged 1 commit into from
Jul 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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