fix txpool + POA regression, header.coinbase should empty

This commit is contained in:
jangko 2023-07-02 19:23:01 +07:00
parent a7c088843d
commit 0589d49dbc
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
2 changed files with 40 additions and 6 deletions

View File

@ -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

View File

@ -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