From 064d164a88c74f22a7ff3756c304437d59fd5a3b Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Fri, 16 Dec 2022 13:11:08 +0100 Subject: [PATCH] fix capella+ summary loading (#4433) ...once and for all. --- beacon_chain/beacon_chain_db.nim | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/beacon_chain/beacon_chain_db.nim b/beacon_chain/beacon_chain_db.nim index 32ad185d0..98b815816 100644 --- a/beacon_chain/beacon_chain_db.nim +++ b/beacon_chain/beacon_chain_db.nim @@ -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) @@ -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] = @@ -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: @@ -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