Skip to content

Commit 064d164

Browse files
authored
fix capella+ summary loading (#4433)
...once and for all.
1 parent 1104013 commit 064d164

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

beacon_chain/beacon_chain_db.nim

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,12 +1298,10 @@ proc containsBlock*(db: BeaconChainDB, key: Eth2Digest, fork: BeaconBlockFork):
12981298
else: db.blocks[fork].contains(key.data).expectDb()
12991299

13001300
proc containsBlock*(db: BeaconChainDB, key: Eth2Digest): bool =
1301-
static: doAssert high(BeaconBlockFork) == BeaconBlockFork.EIP4844
1302-
db.containsBlock(key, eip4844.TrustedSignedBeaconBlock) or
1303-
db.containsBlock(key, capella.TrustedSignedBeaconBlock) or
1304-
db.containsBlock(key, bellatrix.TrustedSignedBeaconBlock) or
1305-
db.containsBlock(key, altair.TrustedSignedBeaconBlock) or
1306-
db.containsBlock(key, phase0.TrustedSignedBeaconBlock)
1301+
for fork in countdown(BeaconBlockFork.high, BeaconBlockFork.low):
1302+
if db.containsBlock(key, fork): return true
1303+
1304+
false
13071305

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

13141312
proc containsState*(db: BeaconChainDB, key: Eth2Digest, legacy: bool = true): bool =
1315-
db.statesNoVal[BeaconStateFork.EIP4844].contains(key.data).expectDb or
1316-
db.statesNoVal[BeaconStateFork.Capella].contains(key.data).expectDb or
1317-
db.statesNoVal[BeaconStateFork.Bellatrix].contains(key.data).expectDb or
1318-
db.statesNoVal[BeaconStateFork.Altair].contains(key.data).expectDb or
1319-
db.statesNoVal[BeaconStateFork.Phase0].contains(key.data).expectDb or
1320-
(legacy and db.v0.containsState(key))
1313+
for fork in countdown(BeaconStateFork.high, BeaconStateFork.low):
1314+
if db.statesNoVal[fork].contains(key.data).expectDb(): return true
1315+
1316+
(legacy and db.v0.containsState(key))
13211317

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

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

0 commit comments

Comments
 (0)