Use separate cache for getting epochref
...else tmpState gets overwritten when producing blocks and requesting epochRef for finalized state.
This commit is contained in:
parent
ea4d94c65c
commit
6e40ca5e15
|
@ -110,10 +110,6 @@ type
|
||||||
heads*: seq[BlockRef] ##\
|
heads*: seq[BlockRef] ##\
|
||||||
## Candidate heads of candidate chains
|
## Candidate heads of candidate chains
|
||||||
|
|
||||||
head*: BlockRef ##\
|
|
||||||
## The latest block we know about, that's been chosen as a head by the fork
|
|
||||||
## choice rule
|
|
||||||
|
|
||||||
finalizedHead*: BlockSlot ##\
|
finalizedHead*: BlockSlot ##\
|
||||||
## The latest block that was finalized according to the block in head
|
## The latest block that was finalized according to the block in head
|
||||||
## Ancestors of this block are guaranteed to have 1 child only.
|
## Ancestors of this block are guaranteed to have 1 child only.
|
||||||
|
@ -122,14 +118,18 @@ type
|
||||||
# Rewinder - Mutable state processing
|
# Rewinder - Mutable state processing
|
||||||
|
|
||||||
headState*: StateData ##\
|
headState*: StateData ##\
|
||||||
## State given by the head block; only update in `updateHead`, not anywhere
|
## State given by the head block - must only be updated in `updateHead` -
|
||||||
## else via `withState`
|
## always matches dag.head
|
||||||
|
|
||||||
tmpState*: StateData ## Scratchpad - may be any state
|
epochRefState*: StateData ##\
|
||||||
|
## State used to produce epochRef instances - must only be used in
|
||||||
|
## `getEpochRef`
|
||||||
|
|
||||||
clearanceState*: StateData ##\
|
clearanceState*: StateData ##\
|
||||||
## Cached state used during block clearance - should only be used in the
|
## Cached state used during block clearance - must only be used in
|
||||||
## clearance module to avoid the risk of modifying it in a callback
|
## clearance module
|
||||||
|
|
||||||
|
tmpState*: StateData ## Scratchpad - may be any state
|
||||||
|
|
||||||
updateFlags*: UpdateFlags
|
updateFlags*: UpdateFlags
|
||||||
|
|
||||||
|
@ -202,6 +202,8 @@ type
|
||||||
|
|
||||||
template validator_keys*(e: EpochRef): untyped = e.validator_key_store[1][]
|
template validator_keys*(e: EpochRef): untyped = e.validator_key_store[1][]
|
||||||
|
|
||||||
|
template head*(v: ChainDagRef): BlockRef = v.headState.blck
|
||||||
|
|
||||||
func shortLog*(v: BlockSlot): string =
|
func shortLog*(v: BlockSlot): string =
|
||||||
if v.blck.slot == v.slot:
|
if v.blck.slot == v.slot:
|
||||||
&"{v.blck.root.data.toOpenArray(0, 3).toHex()}:{v.blck.slot}"
|
&"{v.blck.root.data.toOpenArray(0, 3).toHex()}:{v.blck.slot}"
|
||||||
|
|
|
@ -389,13 +389,13 @@ proc init*(T: type ChainDAGRef,
|
||||||
let res = ChainDAGRef(
|
let res = ChainDAGRef(
|
||||||
blocks: blocks,
|
blocks: blocks,
|
||||||
tail: tailRef,
|
tail: tailRef,
|
||||||
head: headRef,
|
|
||||||
genesis: genesisRef,
|
genesis: genesisRef,
|
||||||
db: db,
|
db: db,
|
||||||
heads: @[headRef],
|
heads: @[headRef],
|
||||||
headState: tmpState[],
|
headState: tmpState[],
|
||||||
tmpState: tmpState[],
|
epochRefState: tmpState[],
|
||||||
clearanceState: tmpState[],
|
clearanceState: tmpState[],
|
||||||
|
tmpState: tmpState[],
|
||||||
|
|
||||||
# The only allowed flag right now is verifyFinalization, as the others all
|
# The only allowed flag right now is verifyFinalization, as the others all
|
||||||
# allow skipping some validation.
|
# allow skipping some validation.
|
||||||
|
@ -446,7 +446,7 @@ proc getEpochRef*(dag: ChainDAGRef, blck: BlockRef, epoch: Epoch): EpochRef =
|
||||||
let
|
let
|
||||||
ancestor = blck.epochAncestor(epoch)
|
ancestor = blck.epochAncestor(epoch)
|
||||||
|
|
||||||
dag.withState(dag.tmpState, ancestor):
|
dag.withState(dag.epochRefState, ancestor):
|
||||||
let
|
let
|
||||||
prevEpochRef = if dag.tail.slot.epoch >= epoch: nil
|
prevEpochRef = if dag.tail.slot.epoch >= epoch: nil
|
||||||
else: blck.findEpochRef(epoch - 1)
|
else: blck.findEpochRef(epoch - 1)
|
||||||
|
@ -702,6 +702,11 @@ proc updateStateData*(
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
|
|
||||||
|
if canAdvance(dag.epochRefState, cur):
|
||||||
|
assign(state, dag.epochRefState)
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
|
||||||
if cur.slot == cur.blck.slot:
|
if cur.slot == cur.blck.slot:
|
||||||
# This is not an empty slot, so the block will need to be applied to
|
# This is not an empty slot, so the block will need to be applied to
|
||||||
# eventually reach bs
|
# eventually reach bs
|
||||||
|
@ -812,8 +817,6 @@ proc updateHead*(
|
||||||
updateStateData(
|
updateStateData(
|
||||||
dag, dag.headState, newHead.atSlot(newHead.slot), false, cache)
|
dag, dag.headState, newHead.atSlot(newHead.slot), false, cache)
|
||||||
|
|
||||||
dag.head = newHead
|
|
||||||
|
|
||||||
if not lastHead.isAncestorOf(newHead):
|
if not lastHead.isAncestorOf(newHead):
|
||||||
notice "Updated head block with chain reorg",
|
notice "Updated head block with chain reorg",
|
||||||
lastHead = shortLog(lastHead),
|
lastHead = shortLog(lastHead),
|
||||||
|
|
Loading…
Reference in New Issue