Skip to content

Commit

Permalink
fix capella+ summary loading (#4433)
Browse files Browse the repository at this point in the history
...once and for all.
  • Loading branch information
arnetheduck authored Dec 16, 2022
1 parent 1104013 commit 064d164
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions beacon_chain/beacon_chain_db.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1298,12 +1298,10 @@ proc containsBlock*(db: BeaconChainDB, key: Eth2Digest, fork: BeaconBlockFork):
else: db.blocks[fork].contains(key.data).expectDb()

proc containsBlock*(db: BeaconChainDB, key: Eth2Digest): bool =
static: doAssert high(BeaconBlockFork) == BeaconBlockFork.EIP4844
db.containsBlock(key, eip4844.TrustedSignedBeaconBlock) or
db.containsBlock(key, capella.TrustedSignedBeaconBlock) or
db.containsBlock(key, bellatrix.TrustedSignedBeaconBlock) or
db.containsBlock(key, altair.TrustedSignedBeaconBlock) or
db.containsBlock(key, phase0.TrustedSignedBeaconBlock)
for fork in countdown(BeaconBlockFork.high, BeaconBlockFork.low):
if db.containsBlock(key, fork): return true

false

proc containsState*(db: BeaconChainDBV0, key: Eth2Digest): bool =
let sk = subkey(Phase0BeaconStateNoImmutableValidators, key)
Expand All @@ -1312,12 +1310,10 @@ proc containsState*(db: BeaconChainDBV0, key: Eth2Digest): bool =
db.backend.contains(subkey(phase0.BeaconState, key)).expectDb()

proc containsState*(db: BeaconChainDB, key: Eth2Digest, legacy: bool = true): bool =
db.statesNoVal[BeaconStateFork.EIP4844].contains(key.data).expectDb or
db.statesNoVal[BeaconStateFork.Capella].contains(key.data).expectDb or
db.statesNoVal[BeaconStateFork.Bellatrix].contains(key.data).expectDb or
db.statesNoVal[BeaconStateFork.Altair].contains(key.data).expectDb or
db.statesNoVal[BeaconStateFork.Phase0].contains(key.data).expectDb or
(legacy and db.v0.containsState(key))
for fork in countdown(BeaconStateFork.high, BeaconStateFork.low):
if db.statesNoVal[fork].contains(key.data).expectDb(): return true

(legacy and db.v0.containsState(key))

proc getBeaconBlockSummary*(db: BeaconChainDB, root: Eth2Digest):
Opt[BeaconBlockSummary] =
Expand Down Expand Up @@ -1427,6 +1423,7 @@ iterator getAncestorSummaries*(db: BeaconChainDB, root: Eth2Digest):

# Backwards compat for reading old databases, or those that for whatever
# reason lost a summary along the way..
static: doAssert BeaconBlockFork.high == BeaconBlockFork.EIP4844
while true:
if db.v0.backend.getSnappySSZ(
subkey(BeaconBlockSummary, res.root), res.summary) == GetResult.found:
Expand All @@ -1437,6 +1434,10 @@ iterator getAncestorSummaries*(db: BeaconChainDB, root: Eth2Digest):
res.summary = blck.get().message.toBeaconBlockSummary()
elif (let blck = db.getBlock(res.root, bellatrix.TrustedSignedBeaconBlock); blck.isSome()):
res.summary = blck.get().message.toBeaconBlockSummary()
elif (let blck = db.getBlock(res.root, capella.TrustedSignedBeaconBlock); blck.isSome()):
res.summary = blck.get().message.toBeaconBlockSummary()
elif (let blck = db.getBlock(res.root, eip4844.TrustedSignedBeaconBlock); blck.isSome()):
res.summary = blck.get().message.toBeaconBlockSummary()
else:
break

Expand Down

0 comments on commit 064d164

Please sign in to comment.