mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-10 14:26:26 +00:00
store empty slot states also
This commit is contained in:
parent
fb9c4fabf4
commit
7efd113a75
@ -438,7 +438,6 @@ proc add*(
|
|||||||
missing = pool.missing.len,
|
missing = pool.missing.len,
|
||||||
cat = "filtering"
|
cat = "filtering"
|
||||||
|
|
||||||
|
|
||||||
func getRef*(pool: BlockPool, root: Eth2Digest): BlockRef =
|
func getRef*(pool: BlockPool, root: Eth2Digest): BlockRef =
|
||||||
## Retrieve a resolved block reference, if available
|
## Retrieve a resolved block reference, if available
|
||||||
pool.blocks.getOrDefault(root, nil)
|
pool.blocks.getOrDefault(root, nil)
|
||||||
@ -562,12 +561,19 @@ func checkMissing*(pool: var BlockPool): seq[FetchRecord] =
|
|||||||
if v.tries.popcount() == 1:
|
if v.tries.popcount() == 1:
|
||||||
result.add(FetchRecord(root: k, historySlots: v.slots))
|
result.add(FetchRecord(root: k, historySlots: v.slots))
|
||||||
|
|
||||||
|
proc skipAndUpdateState(
|
||||||
|
state: var HashedBeaconState, slot: Slot,
|
||||||
|
afterUpdate: proc (state: HashedBeaconState)) =
|
||||||
|
while state.data.slot < slot:
|
||||||
|
# Process slots one at a time in case afterUpdate needs to see empty states
|
||||||
|
process_slots(state, state.data.slot + 1)
|
||||||
|
afterUpdate(state)
|
||||||
|
|
||||||
proc skipAndUpdateState(
|
proc skipAndUpdateState(
|
||||||
state: var HashedBeaconState, blck: BeaconBlock, flags: UpdateFlags,
|
state: var HashedBeaconState, blck: BeaconBlock, flags: UpdateFlags,
|
||||||
afterUpdate: proc (state: HashedBeaconState)): bool =
|
afterUpdate: proc (state: HashedBeaconState)): bool =
|
||||||
|
|
||||||
process_slots(state, blck.slot - 1)
|
skipAndUpdateState(state, blck.slot - 1, afterUpdate)
|
||||||
afterUpdate(state)
|
|
||||||
|
|
||||||
let ok = state_transition(state, blck, flags)
|
let ok = state_transition(state, blck, flags)
|
||||||
|
|
||||||
@ -689,9 +695,8 @@ proc updateStateData*(pool: BlockPool, state: var StateData, bs: BlockSlot) =
|
|||||||
if state.blck.root == bs.blck.root and state.data.data.slot <= bs.slot:
|
if state.blck.root == bs.blck.root and state.data.data.slot <= bs.slot:
|
||||||
if state.data.data.slot != bs.slot:
|
if state.data.data.slot != bs.slot:
|
||||||
# Might be that we're moving to the same block but later slot
|
# Might be that we're moving to the same block but later slot
|
||||||
process_slots(state.data, bs.slot)
|
skipAndUpdateState(state.data, bs.slot) do(state: HashedBeaconState):
|
||||||
# TODO we will not save if multiple slots are skipped here
|
pool.maybePutState(state, bs.blck)
|
||||||
pool.maybePutState(state.data, bs.blck)
|
|
||||||
|
|
||||||
return # State already at the right spot
|
return # State already at the right spot
|
||||||
|
|
||||||
@ -712,10 +717,8 @@ proc updateStateData*(pool: BlockPool, state: var StateData, bs: BlockSlot) =
|
|||||||
pool.maybePutState(state, ancestors[i].refs)
|
pool.maybePutState(state, ancestors[i].refs)
|
||||||
doAssert ok, "Blocks in database should never fail to apply.."
|
doAssert ok, "Blocks in database should never fail to apply.."
|
||||||
|
|
||||||
# TODO check if this triggers rest of state transition, or should
|
skipAndUpdateState(state.data, bs.slot) do(state: HashedBeaconState):
|
||||||
# TODO we will not save if multiple slots are skipped here
|
pool.maybePutState(state, bs.blck)
|
||||||
process_slots(state.data, bs.slot)
|
|
||||||
pool.maybePutState(state.data, bs.blck)
|
|
||||||
|
|
||||||
state.blck = bs.blck
|
state.blck = bs.blck
|
||||||
|
|
||||||
|
@ -197,6 +197,7 @@ proc process_slots*(state: var HashedBeaconState, slot: Slot) =
|
|||||||
if state.data.slot > slot:
|
if state.data.slot > slot:
|
||||||
notice(
|
notice(
|
||||||
"Unusual request for a slot in the past",
|
"Unusual request for a slot in the past",
|
||||||
|
state_root = shortLog(state.root),
|
||||||
current_slot = state.data.slot,
|
current_slot = state.data.slot,
|
||||||
target_slot = slot
|
target_slot = slot
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user