mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-12 05:14:14 +00:00
fixes regression caused by recent changes in eth state handling
detected when running hive consensus simulator. when processing an invalid block header and then a new valid block header with the same block number, the state root of the stateDB object should be updated or reverted to parent stateRoot. using intermediate stateRoot will trigger the hexary trie assertion.
This commit is contained in:
parent
e710aa9423
commit
7b67914453
@ -43,6 +43,7 @@ type
|
||||
forkIds: array[ChainFork, ForkID]
|
||||
blockZeroHash: KeccakHash
|
||||
lastBlockHash: KeccakHash
|
||||
parentStateRoot: KeccakHash
|
||||
|
||||
extraValidation: bool ##\
|
||||
## Trigger extra validation, currently within `persistBlocks()`
|
||||
@ -227,6 +228,10 @@ proc lastBlockHash*(c: Chain): auto {.inline.} =
|
||||
## Getter
|
||||
c.lastBlockHash
|
||||
|
||||
proc parentStateRoot*(c: Chain): auto {.inline.} =
|
||||
## Getter
|
||||
c.parentStateRoot
|
||||
|
||||
proc currentBlock*(c: Chain): BlockHeader
|
||||
{.gcsafe, raises: [Defect,CatchableError].} =
|
||||
## currentBlock retrieves the current head block of the canonical chain.
|
||||
@ -253,6 +258,10 @@ proc `lastBlockHash=`*(c: Chain; blockHash: KeccakHash) {.inline.} =
|
||||
## Setter.
|
||||
c.lastBlockHash = blockHash
|
||||
|
||||
proc `parentStateRoot=`*(c: Chain; stateRoot: KeccakHash) {.inline.} =
|
||||
## Setter.
|
||||
c.parentStateRoot = stateRoot
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# End
|
||||
# ------------------------------------------------------------------------------
|
||||
|
@ -51,9 +51,12 @@ proc persistBlocksImpl(c: Chain; headers: openarray[BlockHeader];
|
||||
let (header, body) = (headers[i], bodies[i])
|
||||
|
||||
if header.parentHash != c.lastBlockHash:
|
||||
# reinit the stateDB if there is some interruption
|
||||
let parent = c.db.getBlockHeader(header.parentHash)
|
||||
c.db.initStateDB(parent.stateRoot)
|
||||
c.parentStateRoot = parent.stateRoot
|
||||
|
||||
# initStateDB will return the last known state
|
||||
# if the stateRoot is match
|
||||
c.db.initStateDB(c.parentStateRoot)
|
||||
|
||||
let
|
||||
vmState = newBaseVMState(c.db.stateDB, header, c.db)
|
||||
@ -99,8 +102,9 @@ proc persistBlocksImpl(c: Chain; headers: openarray[BlockHeader];
|
||||
# so the rpc return consistent result
|
||||
# between eth_blockNumber and eth_syncing
|
||||
c.db.currentBlock = header.blockNumber
|
||||
c.lastBlockHash = header.blockHash
|
||||
c.parentStateRoot = header.stateRoot
|
||||
|
||||
c.lastBlockHash = headers[^1].blockHash
|
||||
transaction.commit()
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user