mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-22 16:58:21 +00:00
Fix typo in tx_head.nim delta calculator
why: Causes havoc in most bit fringe cases. details: When setting the head forward, the delta was wrongly registered from the static "left" end (which limits the loop) rather than the moving "right" end.
This commit is contained in:
parent
4ad566a86a
commit
f11b1a8d8e
@ -600,6 +600,10 @@ proc jobDeltaTxsHead*(xp: TxPoolRef; newHead: BlockHeader): bool
|
||||
|
||||
# Re-inject transactions, do that via job queue
|
||||
if 0 < changes.addTxs.len:
|
||||
debug "queuing delta txs",
|
||||
mode = "inject",
|
||||
num = changes.addTxs.len
|
||||
|
||||
discard xp.job(TxJobDataRef(
|
||||
kind: txJobAddTxs,
|
||||
addTxsArgs: (
|
||||
@ -608,6 +612,10 @@ proc jobDeltaTxsHead*(xp: TxPoolRef; newHead: BlockHeader): bool
|
||||
|
||||
# Delete already *mined* transactions
|
||||
if 0 < changes.remTxs.len:
|
||||
debug "queuing delta txs",
|
||||
mode = "remove",
|
||||
num = changes.remTxs.len
|
||||
|
||||
discard xp.job(TxJobDataRef(
|
||||
kind: txJobDelItemIDs,
|
||||
delItemIDsArgs: (
|
||||
|
@ -164,8 +164,10 @@ proc headDiff*(xp: TxPoolRef;
|
||||
# | |
|
||||
# new << current (step back this one)
|
||||
#
|
||||
# preserve transactions on the upper branch block numbers
|
||||
# between #new..#current to be re-inserted into the pool
|
||||
# + preserve transactions on the upper branch blocks,
|
||||
#
|
||||
# + txs of blocks with numbers between #new..#current need to be
|
||||
# re-inserted into the pool
|
||||
#
|
||||
while newHead.blockNumber < curBranchHead.blockNumber:
|
||||
xp.insert(txDiffs, curBranchHash)
|
||||
@ -190,11 +192,13 @@ proc headDiff*(xp: TxPoolRef;
|
||||
# | |
|
||||
# current << new (step back this one)
|
||||
#
|
||||
# preserve transactions on the upper branch block numbers
|
||||
# between #current..#new to be deleted from the pool
|
||||
# + preserve some transactions on the upper branch blocks,
|
||||
#
|
||||
# + txs of blocks with numbers between #current..#new need to be
|
||||
# deleted from the pool (as they are on the block chain, now)
|
||||
#
|
||||
while curHead.blockNumber < newBranchHead.blockNumber:
|
||||
xp.remove(txDiffs, curBranchHash)
|
||||
xp.remove(txDiffs, newBranchHash)
|
||||
let
|
||||
tmpHead = newBranchHead # cache value for error logging
|
||||
tmpHash = newBranchHash
|
||||
|
@ -905,8 +905,9 @@ proc txPoolMain*(noisy = defined(debug)) =
|
||||
noisy.runTxLoader
|
||||
noisy.runTxPoolTests
|
||||
noisy.runTxPackerTests
|
||||
test_txpool2.runTxPoolCliqueTest()
|
||||
test_txpool2.runTxPoolPosTest()
|
||||
runTxPoolCliqueTest()
|
||||
runTxPoolPosTest()
|
||||
noisy.runTxHeadDelta
|
||||
|
||||
when isMainModule:
|
||||
const
|
||||
@ -922,8 +923,9 @@ when isMainModule:
|
||||
noisy.runTxPoolTests
|
||||
noisy.runTxPackerTests
|
||||
|
||||
#runTxPoolCliqueTest()
|
||||
#runTxPoolPosTest()
|
||||
runTxPoolCliqueTest()
|
||||
runTxPoolPosTest()
|
||||
noisy.runTxHeadDelta
|
||||
|
||||
#noisy.runTxLoader(dir = ".")
|
||||
#noisy.runTxPoolTests
|
||||
|
@ -6,7 +6,7 @@ import
|
||||
../nimbus/p2p/chain,
|
||||
../nimbus/p2p/clique/[clique_sealer, clique_desc],
|
||||
../nimbus/[chain_config, config, genesis, transaction, constants],
|
||||
../nimbus/utils/[tx_pool],
|
||||
../nimbus/utils/tx_pool,
|
||||
./test_txpool/helpers,
|
||||
./macro_assembler
|
||||
|
||||
@ -234,11 +234,11 @@ proc runTxPoolPosTest*() =
|
||||
#runTxPoolPosTest()
|
||||
|
||||
|
||||
proc runTxMissingTxNoce*(noisy = true) =
|
||||
proc runTxHeadDelta*(noisy = true) =
|
||||
## see github.com/status-im/nimbus-eth1/issues/1031
|
||||
|
||||
suite "TxPool: Issue #1031":
|
||||
test "Reproducing issue #1031":
|
||||
suite "TxPool: Synthesising blocks (covers issue #1031)":
|
||||
test "Packing and adding multiple blocks to chain":
|
||||
var
|
||||
env = initEnv(some(100.u256))
|
||||
xp = env.xp
|
||||
@ -266,9 +266,10 @@ proc runTxMissingTxNoce*(noisy = true) =
|
||||
|
||||
xp.jobCommit()
|
||||
|
||||
noisy.say "***", "stats",
|
||||
noisy.say "***", "txDB",
|
||||
&" n={n}",
|
||||
&" pending/staged/packed:total/disposed={xp.nItems.pp}"
|
||||
# pending/staged/packed : total/disposed
|
||||
&" stats={xp.nItems.pp}"
|
||||
|
||||
xp.prevRandao = prevRandao
|
||||
var blk = xp.ethBlock()
|
||||
@ -285,15 +286,27 @@ proc runTxMissingTxNoce*(noisy = true) =
|
||||
transactions: blk.txs,
|
||||
uncles: blk.uncles)
|
||||
|
||||
let rr = chain.persistBlocks([blk.header], [body])
|
||||
check rr.isOk
|
||||
# Commit to block chain
|
||||
check chain.persistBlocks([blk.header], [body]).isOk
|
||||
|
||||
# PoS block canonical head must be explicitly set using setHead
|
||||
# PoS block canonical head must be explicitly set using setHead. The
|
||||
# function `persistHeaderToDb()` used in `persistBlocks()` does not
|
||||
# reliably do so due to scoring.
|
||||
chainDB.setHead(blk.header)
|
||||
|
||||
discard xp.jobDeltaTxsHead(blk.header)
|
||||
# Synchronise TxPool against new chain head, register txs differences.
|
||||
# In this particular case, these differences will simply flush the
|
||||
# packer bucket.
|
||||
check xp.jobDeltaTxsHead(blk.header)
|
||||
check xp.nJobs == 1
|
||||
|
||||
# Move TxPool chain head to new chain head and apply delta jobs
|
||||
xp.head = blk.header
|
||||
xp.jobCommit()
|
||||
check xp.nItems.staged == 0
|
||||
check xp.nItems.packed == 0
|
||||
|
||||
setErrorLevel() # in case we set trace level
|
||||
|
||||
check chainDB.currentBlock == 10.toBlockNumber
|
||||
head = chainDB.getBlockHeader(chainDB.currentBlock)
|
||||
@ -311,7 +324,7 @@ when isMainModule:
|
||||
|
||||
setErrorLevel() # mute logger
|
||||
|
||||
runTxPoolCliqueTest()
|
||||
runTxPoolPosTest()
|
||||
#runTxPoolCliqueTest()
|
||||
#runTxPoolPosTest()
|
||||
|
||||
true.runTxMissingTxNoce
|
||||
true.runTxHeadDelta
|
||||
|
Loading…
x
Reference in New Issue
Block a user