cleanup unused chaindag epoch features
these are somewhat obsoleted by the more extensive use of EpochRef
This commit is contained in:
parent
3d39757321
commit
3b6a8a692d
|
@ -32,8 +32,7 @@ proc putBlock*(
|
||||||
dag.db.putBlock(signedBlock)
|
dag.db.putBlock(signedBlock)
|
||||||
|
|
||||||
proc updateStateData*(
|
proc updateStateData*(
|
||||||
dag: ChainDAGRef, state: var StateData, bs: BlockSlot,
|
dag: ChainDAGRef, state: var StateData, bs: BlockSlot) {.gcsafe.}
|
||||||
matchEpoch: bool = false) {.gcsafe.}
|
|
||||||
|
|
||||||
template withState*(
|
template withState*(
|
||||||
dag: ChainDAGRef, cache: var StateData, blockSlot: BlockSlot, body: untyped): untyped =
|
dag: ChainDAGRef, cache: var StateData, blockSlot: BlockSlot, body: untyped): untyped =
|
||||||
|
@ -129,22 +128,6 @@ func get_ancestor*(blck: BlockRef, slot: Slot): BlockRef =
|
||||||
|
|
||||||
blck = blck.parent
|
blck = blck.parent
|
||||||
|
|
||||||
iterator get_ancestors_in_epoch(blockSlot: BlockSlot): BlockSlot =
|
|
||||||
let min_slot =
|
|
||||||
blockSlot.slot.compute_epoch_at_slot.compute_start_slot_at_epoch
|
|
||||||
var blockSlot = blockSlot
|
|
||||||
|
|
||||||
while true:
|
|
||||||
for slot in countdown(blockSlot.slot, max(blockSlot.blck.slot, min_slot)):
|
|
||||||
yield BlockSlot(blck: blockSlot.blck, slot: slot)
|
|
||||||
|
|
||||||
if blockSlot.blck.parent.isNil or blockSlot.blck.slot <= min_slot:
|
|
||||||
break
|
|
||||||
|
|
||||||
doAssert blockSlot.blck.slot > blockSlot.blck.parent.slot
|
|
||||||
blockSlot =
|
|
||||||
BlockSlot(blck: blockSlot.blck.parent, slot: blockSlot.blck.slot - 1)
|
|
||||||
|
|
||||||
func atSlot*(blck: BlockRef, slot: Slot): BlockSlot =
|
func atSlot*(blck: BlockRef, slot: Slot): BlockSlot =
|
||||||
## Return a BlockSlot at a given slot, with the block set to the closest block
|
## Return a BlockSlot at a given slot, with the block set to the closest block
|
||||||
## available. If slot comes from before the block, a suitable block ancestor
|
## available. If slot comes from before the block, a suitable block ancestor
|
||||||
|
@ -511,8 +494,7 @@ proc skipAndUpdateState(
|
||||||
ok
|
ok
|
||||||
|
|
||||||
proc rewindState(
|
proc rewindState(
|
||||||
dag: ChainDAGRef, state: var StateData, bs: BlockSlot,
|
dag: ChainDAGRef, state: var StateData, bs: BlockSlot): seq[BlockRef] =
|
||||||
matchEpoch: bool): seq[BlockRef] =
|
|
||||||
logScope:
|
logScope:
|
||||||
blockSlot = shortLog(bs)
|
blockSlot = shortLog(bs)
|
||||||
pcs = "replay_state"
|
pcs = "replay_state"
|
||||||
|
@ -581,8 +563,7 @@ proc rewindState(
|
||||||
ancestors
|
ancestors
|
||||||
|
|
||||||
proc getStateDataCached(
|
proc getStateDataCached(
|
||||||
dag: ChainDAGRef, state: var StateData, bs: BlockSlot,
|
dag: ChainDAGRef, state: var StateData, bs: BlockSlot): bool =
|
||||||
matchEpoch: bool): bool =
|
|
||||||
# This pointedly does not run rewindState or state_transition, but otherwise
|
# This pointedly does not run rewindState or state_transition, but otherwise
|
||||||
# mostly matches updateStateData(...), because it's too expensive to run the
|
# mostly matches updateStateData(...), because it's too expensive to run the
|
||||||
# rewindState(...)/skipAndUpdateState(...)/state_transition(...) procs, when
|
# rewindState(...)/skipAndUpdateState(...)/state_transition(...) procs, when
|
||||||
|
@ -595,21 +576,8 @@ proc getStateDataCached(
|
||||||
|
|
||||||
false
|
false
|
||||||
|
|
||||||
template withEpochState*(
|
|
||||||
dag: ChainDAGRef, cache: var StateData, blockSlot: BlockSlot,
|
|
||||||
body: untyped): untyped =
|
|
||||||
## Helper template that updates state to a particular BlockSlot - usage of
|
|
||||||
## cache is unsafe outside of block.
|
|
||||||
## TODO async transformations will lead to a race where cache gets updated
|
|
||||||
## while waiting for future to complete - catch this here somehow?
|
|
||||||
# TODO implement the looser constraints allowed by epoch, not precise slot target
|
|
||||||
# allow expressing preference to opt-in to looser constraints regardless
|
|
||||||
dag.withState(cache, blockSlot):
|
|
||||||
body
|
|
||||||
|
|
||||||
proc updateStateData*(
|
proc updateStateData*(
|
||||||
dag: ChainDAGRef, state: var StateData, bs: BlockSlot,
|
dag: ChainDAGRef, state: var StateData, bs: BlockSlot) =
|
||||||
matchEpoch: bool = false) =
|
|
||||||
## Rewind or advance state such that it matches the given block and slot -
|
## Rewind or advance state such that it matches the given block and slot -
|
||||||
## this may include replaying from an earlier snapshot if blck is on a
|
## this may include replaying from an earlier snapshot if blck is on a
|
||||||
## different branch or has advanced to a higher slot number than slot
|
## different branch or has advanced to a higher slot number than slot
|
||||||
|
@ -625,10 +593,10 @@ proc updateStateData*(
|
||||||
|
|
||||||
return # State already at the right spot
|
return # State already at the right spot
|
||||||
|
|
||||||
if dag.getStateDataCached(state, bs, matchEpoch):
|
if dag.getStateDataCached(state, bs):
|
||||||
return
|
return
|
||||||
|
|
||||||
let ancestors = rewindState(dag, state, bs, matchEpoch)
|
let ancestors = rewindState(dag, state, bs)
|
||||||
|
|
||||||
# If we come this far, we found the state root. The last block on the stack
|
# If we come this far, we found the state root. The last block on the stack
|
||||||
# is the one that produced this particular state, so we can pop it
|
# is the one that produced this particular state, so we can pop it
|
||||||
|
|
Loading…
Reference in New Issue