mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-12 21:34:33 +00:00
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
|
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
|
# Test Runners
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
@ -160,7 +142,7 @@ proc runTxLoader(noisy = true; capture = loadSpecs) =
|
|||||||
elapNoisy = noisy
|
elapNoisy = noisy
|
||||||
veryNoisy = false # noisy
|
veryNoisy = false # noisy
|
||||||
fileInfo = capture.file.splitFile.name.split(".")[0]
|
fileInfo = capture.file.splitFile.name.split(".")[0]
|
||||||
filePath = capture.file.findFilePath
|
filePath = capture.file.findFilePath(baseDir,repoDir).value
|
||||||
|
|
||||||
# Reset/initialise
|
# Reset/initialise
|
||||||
statCount.reset
|
statCount.reset
|
||||||
@ -938,7 +920,10 @@ when isMainModule:
|
|||||||
|
|
||||||
noisy.runTxLoader(capture = capts1)
|
noisy.runTxLoader(capture = capts1)
|
||||||
noisy.runTxPoolTests
|
noisy.runTxPoolTests
|
||||||
true.runTxPackerTests
|
noisy.runTxPackerTests
|
||||||
|
|
||||||
|
#runTxPoolCliqueTest()
|
||||||
|
#runTxPoolPosTest()
|
||||||
|
|
||||||
#noisy.runTxLoader(dir = ".")
|
#noisy.runTxLoader(dir = ".")
|
||||||
#noisy.runTxPoolTests
|
#noisy.runTxPoolTests
|
||||||
|
@ -9,10 +9,11 @@
|
|||||||
# according to those terms.
|
# according to those terms.
|
||||||
|
|
||||||
import
|
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_chain, tx_desc, tx_gauge, tx_item, tx_tabs],
|
||||||
../../nimbus/utils/tx_pool/tx_tasks/[tx_packer, tx_recover],
|
../../nimbus/utils/tx_pool/tx_tasks/[tx_packer, tx_recover],
|
||||||
../replay/[pp, undump],
|
../replay/[pp, undump],
|
||||||
|
chronicles,
|
||||||
eth/[common, keys],
|
eth/[common, keys],
|
||||||
stew/[keyed_queue, sorted_set],
|
stew/[keyed_queue, sorted_set],
|
||||||
stint
|
stint
|
||||||
@ -195,6 +196,24 @@ proc say*(noisy = false; pfx = "***"; args: varargs[string, `$`]) =
|
|||||||
else:
|
else:
|
||||||
echo pfx, args.toSeq.join
|
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
|
# End
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import
|
import
|
||||||
std/[os, strutils, math, tables, options],
|
std/[strutils, math, tables, options, times],
|
||||||
eth/[trie/db, keys, common, trie/hexary],
|
eth/[trie/db, keys, common, trie/hexary],
|
||||||
stew/byteutils, nimcrypto, unittest2,
|
stew/[byteutils, results], nimcrypto, unittest2,
|
||||||
../nimbus/db/[db_chain, state_db],
|
../nimbus/db/[db_chain, state_db],
|
||||||
../nimbus/p2p/chain,
|
../nimbus/p2p/chain,
|
||||||
../nimbus/p2p/clique/[clique_sealer, clique_desc],
|
../nimbus/p2p/clique/[clique_sealer, clique_desc],
|
||||||
@ -11,8 +11,9 @@ import
|
|||||||
./macro_assembler
|
./macro_assembler
|
||||||
|
|
||||||
const
|
const
|
||||||
baseFolder = "tests" / "customgenesis"
|
baseDir = [".", "tests"]
|
||||||
genesisFile = baseFolder / "merge.json"
|
repoDir = [".", "customgenesis"]
|
||||||
|
genesisFile = "merge.json"
|
||||||
|
|
||||||
type
|
type
|
||||||
TestEnv = object
|
TestEnv = object
|
||||||
@ -69,7 +70,7 @@ proc initEnv(ttd: Option[UInt256] = none(UInt256)): TestEnv =
|
|||||||
var
|
var
|
||||||
conf = makeConfig(@[
|
conf = makeConfig(@[
|
||||||
"--engine-signer:658bdf435d810c91414ec09147daa6db62406379",
|
"--engine-signer:658bdf435d810c91414ec09147daa6db62406379",
|
||||||
"--custom-network:" & genesisFile
|
"--custom-network:" & genesisFile.findFilePath(baseDir,repoDir).value
|
||||||
])
|
])
|
||||||
|
|
||||||
conf.networkParams.genesis.alloc[recipient] = GenesisAccount(
|
conf.networkParams.genesis.alloc[recipient] = GenesisAccount(
|
||||||
@ -230,4 +231,87 @@ proc runTxPoolPosTest*() =
|
|||||||
let bal = sdb.getBalance(feeRecipient)
|
let bal = sdb.getBalance(feeRecipient)
|
||||||
check not bal.isZero
|
check not bal.isZero
|
||||||
|
|
||||||
runTxPoolPosTest()
|
#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…
x
Reference in New Issue
Block a user