fix txpool usage at the beginning of process

This commit is contained in:
jangko 2023-08-04 10:59:12 +07:00
parent 4d207e49ce
commit 70d718119e
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
6 changed files with 58 additions and 8 deletions

View File

@ -88,6 +88,11 @@ proc setupELClient*(t: TestEnv, chainFile: string, enableAuth: bool) =
t.com.initializeEmptyDb()
let txPool = TxPoolRef.new(t.com, t.conf.engineSigner)
# txPool must be informed of active head
# so it can know the latest account state
let head = t.com.db.getCanonicalHead()
doAssert txPool.smartHead(head)
var key: JwtSharedKey
let kr = key.fromHex(jwtSecret)
if kr.isErr:

View File

@ -92,8 +92,11 @@ proc main() =
var stat: SimStat
let start = getTime()
#let fileName = caseFolder & "/37_eth_sendRawTransaction_nonceTooLow.json"
#block:
# txPool must be informed of active head
# so it can know the latest account state
# e.g. "sendRawTransaction Nonce too low" case
let head = com.db.getCanonicalHead()
doAssert txPool.smartHead(head)
for fileName in walkDirRec(
caseFolder, yieldFilter = {pcFile,pcLinkToFile}):

View File

@ -105,6 +105,12 @@ proc setupEnv*(): TestEnv =
let chainRef = newChain(com)
let txPool = TxPoolRef.new(com, conf.engineSigner)
# txPool must be informed of active head
# so it can know the latest account state
let head = com.db.getCanonicalHead()
doAssert txPool.smartHead(head)
let sealingEngine = SealingEngineRef.new(
chainRef, ethCtx, conf.engineSigner,
txPool, EngineStopped

View File

@ -80,6 +80,12 @@ proc basicServices(nimbus: NimbusNode,
# the engineSigner is zero.
nimbus.txPool = TxPoolRef.new(com, conf.engineSigner)
# txPool must be informed of active head
# so it can know the latest account state
# e.g. sender nonce, etc
let head = com.db.getCanonicalHead()
doAssert nimbus.txPool.smartHead(head)
# chainRef: some name to avoid module-name/filed/function misunderstandings
nimbus.chainRef = newChain(com)
if conf.verifyFrom.isSome:

View File

@ -853,7 +853,7 @@ proc runTxPackerTests(noisy = true) =
# even though the difficulty or the blocknumber is lower than
# previous canonical head
check hdr.blockHash == xq.chain.com.db.getCanonicalHead.blockHash
# Is the withdrawals persisted and loaded properly?
var blockBody: BlockBody
check xq.chain.com.db.getBlockBody(hdr, blockBody)
@ -882,6 +882,7 @@ proc txPoolMain*(noisy = defined(debug)) =
noisy.runTxPackerTests
runTxPoolCliqueTest()
runTxPoolPosTest()
runTxPoolBlobhashTest()
noisy.runTxHeadDelta
when isMainModule:

View File

@ -7,6 +7,7 @@ import
../nimbus/core/clique/[clique_sealer, clique_desc],
../nimbus/[config, transaction, constants],
../nimbus/core/tx_pool,
../nimbus/core/tx_pool/tx_item,
../nimbus/core/casper,
../nimbus/core/executor,
../nimbus/common/common,
@ -70,6 +71,11 @@ proc makeTx*(t: var TestEnv, recipient: EthAddress, amount: UInt256, payload: op
inc t.nonce
signTransaction(tx, t.vaultKey, t.chainId, eip155 = true)
proc signTxWithNonce(t: TestEnv, tx: Transaction, nonce: AccountNonce): Transaction =
var tx = tx
tx.nonce = nonce
signTransaction(tx, t.vaultKey, t.chainId, eip155 = true)
proc initEnv(envFork: HardFork): TestEnv =
var
conf = makeConfig(@[
@ -265,12 +271,18 @@ proc runTxPoolPosTest*() =
let bal = sdb.getBalance(feeRecipient)
check not bal.isZero
proc inPoolAndOk(txPool: TxPoolRef, txHash: Hash256): bool =
let res = txPool.getItem(txHash)
if res.isErr: return false
res.get().reject == txInfoOk
proc runTxPoolBlobhashTest*() =
var
env = initEnv(Cancun)
var
tx = env.makeTx(recipient, amount)
tx1 = env.makeTx(recipient, amount)
tx2 = env.makeTx(recipient, amount)
xp = env.xp
com = env.com
chain = env.chain
@ -279,14 +291,16 @@ proc runTxPoolBlobhashTest*() =
suite "Test TxPool with blobhash block":
test "TxPool addLocal":
let res = xp.addLocal(tx, force = true)
let res = xp.addLocal(tx1, force = true)
check res.isOk
if res.isErr:
debugEcho res.error
return
let res2 = xp.addLocal(tx2, force = true)
check res2.isOk
test "TxPool jobCommit":
check xp.nItems.total == 1
check xp.nItems.total == 2
test "TxPool ethBlock":
com.pos.prevRandao = prevRandao
@ -302,7 +316,7 @@ proc runTxPoolBlobhashTest*() =
uncles: blk.uncles,
withdrawals: some[seq[Withdrawal]](@[])
)
check blk.txs.len == 1
check blk.txs.len == 2
test "Blobhash persistBlocks":
let rr = chain.persistBlocks([blk.header], [body])
@ -321,6 +335,21 @@ proc runTxPoolBlobhashTest*() =
let bal = sdb.getBalance(feeRecipient)
check not bal.isZero
test "add tx with nonce too low":
let
tx3 = env.makeTx(recipient, amount)
tx4 = env.signTxWithNonce(tx3, AccountNonce(env.nonce-2))
xp = env.xp
check xp.smartHead(blk.header)
let res = xp.addLocal(tx4, force = true)
check res.isOk
if res.isErr:
debugEcho res.error
return
check inPoolAndOk(xp, rlpHash(tx4)) == false
proc runTxHeadDelta*(noisy = true) =
## see github.com/status-im/nimbus-eth1/issues/1031
@ -399,6 +428,6 @@ when isMainModule:
runTxPoolCliqueTest()
runTxPoolPosTest()
runTxPoolBlobhashTest()
noisy.runTxHeadDelta
#noisy.runTxHeadDelta
# End