work around Nim assignment bug that breaks state pruning (#3545)

See https://github.com/nim-lang/Nim/issues/19613
This commit is contained in:
Jacek Sieka 2022-03-24 15:37:37 +01:00 committed by GitHub
parent 6983dacc26
commit e009728858
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View File

@ -1499,7 +1499,9 @@ proc pruneStateCachesDAG*(dag: ChainDAGRef) =
if not isFinalizedStateSnapshot(cur.get().slot) and
cur.get().slot != dag.tail.slot:
dag.delState(cur.get())
cur = dag.parentOrSlot(cur.get())
# TODO https://github.com/nim-lang/Nim/issues/19613
let tmp = cur.get()
cur = dag.parentOrSlot(tmp)
let statePruneTick = Moment.now()

View File

@ -415,6 +415,34 @@ suite "chain DAG finalization tests" & preset():
check:
dag.db.immutableValidators.len() == getStateField(dag.headState, validators).len()
block:
var cur = dag.head.bid
while true:
let parent = dag.parent(cur)
if cur.slot > 0:
check:
parent.isSome and parent.get().slot < cur.slot
cur = parent.get()
else:
check:
parent.isErr()
break
check: cur.slot == 0
block:
var cur = dag.head.bid.atSlot()
while true:
let parent = dag.parentOrSlot(cur)
if cur.slot > 0:
check:
parent.isSome and (parent.get().slot < cur.slot or parent.get().bid != cur.bid)
cur = parent.get()
else:
check:
parent.isErr()
break
check: cur.slot == 0
let
finalER = dag.getEpochRef(
dag.finalizedHead.blck, dag.finalizedHead.slot.epoch, false)
@ -458,9 +486,11 @@ suite "chain DAG finalization tests" & preset():
let
finalizedCheckpoint = dag.stateCheckpoint(dag.finalizedHead.toBlockSlotId().get())
headCheckpoint = dag.stateCheckpoint(dag.head.bid.atSlot())
prunedCheckpoint = dag.stateCheckpoint(dag.parent(dag.finalizedHead.blck.bid).get().atSlot())
check:
db.getStateRoot(headCheckpoint.bid.root, headCheckpoint.slot).isSome
db.getStateRoot(finalizedCheckpoint.bid.root, finalizedCheckpoint.slot).isSome
db.getStateRoot(prunedCheckpoint.bid.root, prunedCheckpoint.slot).isNone
let
validatorMonitor2 = newClone(ValidatorMonitor.init())