Test bed for chasing issue #1031
This commit is contained in:
parent
2746f52cc8
commit
4ad566a86a
|
@ -133,24 +133,6 @@ proc addOrFlushGroupwise(xp: TxPoolRef;
|
|||
|
||||
return true
|
||||
|
||||
proc findFilePath(file: string): string =
|
||||
result = "?unknown?" / file
|
||||
for dir in baseDir:
|
||||
for repo in repoDir:
|
||||
let path = dir / repo / file
|
||||
if path.fileExists:
|
||||
return path
|
||||
|
||||
proc setTraceLevel =
|
||||
discard
|
||||
when defined(chronicles_runtime_filtering) and loggingEnabled:
|
||||
setLogLevel(LogLevel.TRACE)
|
||||
|
||||
proc setErrorLevel =
|
||||
discard
|
||||
when defined(chronicles_runtime_filtering) and loggingEnabled:
|
||||
setLogLevel(LogLevel.ERROR)
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Test Runners
|
||||
# ------------------------------------------------------------------------------
|
||||
|
@ -160,7 +142,7 @@ proc runTxLoader(noisy = true; capture = loadSpecs) =
|
|||
elapNoisy = noisy
|
||||
veryNoisy = false # noisy
|
||||
fileInfo = capture.file.splitFile.name.split(".")[0]
|
||||
filePath = capture.file.findFilePath
|
||||
filePath = capture.file.findFilePath(baseDir,repoDir).value
|
||||
|
||||
# Reset/initialise
|
||||
statCount.reset
|
||||
|
@ -938,7 +920,10 @@ when isMainModule:
|
|||
|
||||
noisy.runTxLoader(capture = capts1)
|
||||
noisy.runTxPoolTests
|
||||
true.runTxPackerTests
|
||||
noisy.runTxPackerTests
|
||||
|
||||
#runTxPoolCliqueTest()
|
||||
#runTxPoolPosTest()
|
||||
|
||||
#noisy.runTxLoader(dir = ".")
|
||||
#noisy.runTxPoolTests
|
||||
|
|
|
@ -9,10 +9,11 @@
|
|||
# according to those terms.
|
||||
|
||||
import
|
||||
std/[strformat, sequtils, strutils, times],
|
||||
std/[os, strformat, sequtils, strutils, times],
|
||||
../../nimbus/utils/tx_pool/[tx_chain, tx_desc, tx_gauge, tx_item, tx_tabs],
|
||||
../../nimbus/utils/tx_pool/tx_tasks/[tx_packer, tx_recover],
|
||||
../replay/[pp, undump],
|
||||
chronicles,
|
||||
eth/[common, keys],
|
||||
stew/[keyed_queue, sorted_set],
|
||||
stint
|
||||
|
@ -195,6 +196,24 @@ proc say*(noisy = false; pfx = "***"; args: varargs[string, `$`]) =
|
|||
else:
|
||||
echo pfx, args.toSeq.join
|
||||
|
||||
proc setTraceLevel* =
|
||||
discard
|
||||
when defined(chronicles_runtime_filtering) and loggingEnabled:
|
||||
setLogLevel(LogLevel.TRACE)
|
||||
|
||||
proc setErrorLevel* =
|
||||
discard
|
||||
when defined(chronicles_runtime_filtering) and loggingEnabled:
|
||||
setLogLevel(LogLevel.ERROR)
|
||||
|
||||
proc findFilePath*(file: string;
|
||||
baseDir, repoDir: openArray[string]): Result[string,void] =
|
||||
for dir in baseDir:
|
||||
for repo in repoDir:
|
||||
let path = dir / repo / file
|
||||
if path.fileExists:
|
||||
return ok(path)
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# End
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import
|
||||
std/[os, strutils, math, tables, options],
|
||||
std/[strutils, math, tables, options, times],
|
||||
eth/[trie/db, keys, common, trie/hexary],
|
||||
stew/byteutils, nimcrypto, unittest2,
|
||||
stew/[byteutils, results], nimcrypto, unittest2,
|
||||
../nimbus/db/[db_chain, state_db],
|
||||
../nimbus/p2p/chain,
|
||||
../nimbus/p2p/clique/[clique_sealer, clique_desc],
|
||||
|
@ -11,8 +11,9 @@ import
|
|||
./macro_assembler
|
||||
|
||||
const
|
||||
baseFolder = "tests" / "customgenesis"
|
||||
genesisFile = baseFolder / "merge.json"
|
||||
baseDir = [".", "tests"]
|
||||
repoDir = [".", "customgenesis"]
|
||||
genesisFile = "merge.json"
|
||||
|
||||
type
|
||||
TestEnv = object
|
||||
|
@ -69,7 +70,7 @@ proc initEnv(ttd: Option[UInt256] = none(UInt256)): TestEnv =
|
|||
var
|
||||
conf = makeConfig(@[
|
||||
"--engine-signer:658bdf435d810c91414ec09147daa6db62406379",
|
||||
"--custom-network:" & genesisFile
|
||||
"--custom-network:" & genesisFile.findFilePath(baseDir,repoDir).value
|
||||
])
|
||||
|
||||
conf.networkParams.genesis.alloc[recipient] = GenesisAccount(
|
||||
|
@ -230,4 +231,87 @@ proc runTxPoolPosTest*() =
|
|||
let bal = sdb.getBalance(feeRecipient)
|
||||
check not bal.isZero
|
||||
|
||||
#runTxPoolPosTest()
|
||||
|
||||
|
||||
proc runTxMissingTxNoce*(noisy = true) =
|
||||
## see github.com/status-im/nimbus-eth1/issues/1031
|
||||
|
||||
suite "TxPool: Issue #1031":
|
||||
test "Reproducing issue #1031":
|
||||
var
|
||||
env = initEnv(some(100.u256))
|
||||
xp = env.xp
|
||||
chainDB = env.chainDB
|
||||
chain = env.chain
|
||||
head = chainDB.getCanonicalHead()
|
||||
timestamp = head.timestamp
|
||||
|
||||
const
|
||||
txPerblock = 20
|
||||
numBlocks = 10
|
||||
|
||||
# setTraceLevel()
|
||||
|
||||
block processBlocks:
|
||||
for n in 0..<numBlocks:
|
||||
|
||||
for tn in 0..<txPerblock:
|
||||
let tx = env.makeTx(recipient, amount)
|
||||
let res = xp.addLocal(tx, force = true)
|
||||
if res.isErr:
|
||||
noisy.say "***", "loading blocks failed",
|
||||
" error=", res.error
|
||||
break processBlocks
|
||||
|
||||
xp.jobCommit()
|
||||
|
||||
noisy.say "***", "stats",
|
||||
&" n={n}",
|
||||
&" pending/staged/packed:total/disposed={xp.nItems.pp}"
|
||||
|
||||
xp.prevRandao = prevRandao
|
||||
var blk = xp.ethBlock()
|
||||
check chain.isBlockAfterTtd(blk.header)
|
||||
|
||||
timestamp = timestamp + 1.seconds
|
||||
blk.header.difficulty = DifficultyInt.zero
|
||||
blk.header.prevRandao = prevRandao
|
||||
blk.header.nonce = default(BlockNonce)
|
||||
blk.header.extraData = @[]
|
||||
blk.header.timestamp = timestamp
|
||||
|
||||
let body = BlockBody(
|
||||
transactions: blk.txs,
|
||||
uncles: blk.uncles)
|
||||
|
||||
let rr = chain.persistBlocks([blk.header], [body])
|
||||
check rr.isOk
|
||||
|
||||
# PoS block canonical head must be explicitly set using setHead
|
||||
chainDB.setHead(blk.header)
|
||||
|
||||
discard xp.jobDeltaTxsHead(blk.header)
|
||||
xp.head = blk.header
|
||||
xp.jobCommit()
|
||||
|
||||
check chainDB.currentBlock == 10.toBlockNumber
|
||||
head = chainDB.getBlockHeader(chainDB.currentBlock)
|
||||
var
|
||||
sdb = newAccountStateDB(chainDB.db, head.stateRoot, pruneTrie = false)
|
||||
|
||||
let
|
||||
expected = u256(txPerblock * numBlocks) * amount
|
||||
balance = sdb.getBalance(recipient)
|
||||
check balance == expected
|
||||
|
||||
when isMainModule:
|
||||
const
|
||||
noisy = defined(debug)
|
||||
|
||||
setErrorLevel() # mute logger
|
||||
|
||||
runTxPoolCliqueTest()
|
||||
runTxPoolPosTest()
|
||||
|
||||
true.runTxMissingTxNoce
|
||||
|
|
Loading…
Reference in New Issue