mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-13 05:44:40 +00:00
piggyback generate block witness test on test_blockchain_json
This commit is contained in:
parent
7c026e1b48
commit
3947e9a853
@ -17,7 +17,8 @@ import
|
|||||||
../nimbus/db/[db_chain, accounts_cache],
|
../nimbus/db/[db_chain, accounts_cache],
|
||||||
../nimbus/utils/header,
|
../nimbus/utils/header,
|
||||||
../nimbus/p2p/[executor, dao],
|
../nimbus/p2p/[executor, dao],
|
||||||
../nimbus/config
|
../nimbus/config,
|
||||||
|
../stateless/[multi_keys, tree_from_witness, witness_from_tree, witness_types]
|
||||||
|
|
||||||
type
|
type
|
||||||
SealEngine = enum
|
SealEngine = enum
|
||||||
@ -280,6 +281,28 @@ proc parseTester(fixture: JsonNode, testStatusIMPL: var TestStatus): Tester =
|
|||||||
#if result.network in ["HomesteadToDaoAt5"]:
|
#if result.network in ["HomesteadToDaoAt5"]:
|
||||||
#result.good = false
|
#result.good = false
|
||||||
|
|
||||||
|
proc blockWitness(vmState: BaseVMState, fork: Fork, chainDB: BaseChainDB) =
|
||||||
|
let rootHash = vmState.accountDb.rootHash
|
||||||
|
let mkeys = vmState.accountDb.makeMultiKeys()
|
||||||
|
let flags = if fork >= FKSpurious: {wfEIP170} else: {}
|
||||||
|
|
||||||
|
# build witness from tree
|
||||||
|
var wb = initWitnessBuilder(chainDB.db, rootHash, flags)
|
||||||
|
let witness = wb.buildWitness(mkeys)
|
||||||
|
|
||||||
|
# build tree from witness
|
||||||
|
var db = newMemoryDB()
|
||||||
|
when defined(useInputStream):
|
||||||
|
var input = memoryInput(witness)
|
||||||
|
var tb = initTreeBuilder(input, db, flags)
|
||||||
|
else:
|
||||||
|
var tb = initTreeBuilder(witness, db, flags)
|
||||||
|
let root = tb.buildTree()
|
||||||
|
|
||||||
|
# compare the result
|
||||||
|
if root != rootHash:
|
||||||
|
raise newException(ValidationError, "Invalid trie generated from block witness")
|
||||||
|
|
||||||
proc assignBlockRewards(minedBlock: PlainBlock, vmState: BaseVMState, fork: Fork, chainDB: BaseChainDB) =
|
proc assignBlockRewards(minedBlock: PlainBlock, vmState: BaseVMState, fork: Fork, chainDB: BaseChainDB) =
|
||||||
let blockReward = blockRewards[fork]
|
let blockReward = blockRewards[fork]
|
||||||
var mainReward = blockReward
|
var mainReward = blockReward
|
||||||
@ -299,6 +322,8 @@ proc assignBlockRewards(minedBlock: PlainBlock, vmState: BaseVMState, fork: Fork
|
|||||||
# Reward beneficiary
|
# Reward beneficiary
|
||||||
vmState.mutateStateDB:
|
vmState.mutateStateDB:
|
||||||
db.addBalance(minedBlock.header.coinbase, mainReward)
|
db.addBalance(minedBlock.header.coinbase, mainReward)
|
||||||
|
if vmState.generateWitness:
|
||||||
|
db.collectWitnessData()
|
||||||
db.persist()
|
db.persist()
|
||||||
|
|
||||||
let stateDb = vmState.accountDb
|
let stateDb = vmState.accountDb
|
||||||
@ -317,6 +342,9 @@ proc assignBlockRewards(minedBlock: PlainBlock, vmState: BaseVMState, fork: Fork
|
|||||||
if minedBlock.header.txRoot != txRoot:
|
if minedBlock.header.txRoot != txRoot:
|
||||||
raise newException(ValidationError, "wrong txRoot")
|
raise newException(ValidationError, "wrong txRoot")
|
||||||
|
|
||||||
|
if vmState.generateWitness:
|
||||||
|
blockWitness(vmState, fork, chainDB)
|
||||||
|
|
||||||
proc processBlock(chainDB: BaseChainDB, vmState: BaseVMState, minedBlock: PlainBlock, fork: Fork) =
|
proc processBlock(chainDB: BaseChainDB, vmState: BaseVMState, minedBlock: PlainBlock, fork: Fork) =
|
||||||
var dbTx = chainDB.db.beginTransaction()
|
var dbTx = chainDB.db.beginTransaction()
|
||||||
defer: dbTx.dispose()
|
defer: dbTx.dispose()
|
||||||
@ -697,6 +725,8 @@ proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus, debugMode = fal
|
|||||||
var vmState = newBaseVMState(emptyRlpHash,
|
var vmState = newBaseVMState(emptyRlpHash,
|
||||||
tester.genesisBlockHeader, chainDB)
|
tester.genesisBlockHeader, chainDB)
|
||||||
|
|
||||||
|
vmState.generateWitness = true
|
||||||
|
|
||||||
vmState.mutateStateDB:
|
vmState.mutateStateDB:
|
||||||
setupStateDB(fixture["pre"], db)
|
setupStateDB(fixture["pre"], db)
|
||||||
db.persist()
|
db.persist()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user