fix capella+ summary loading (#4433)

...once and for all.
This commit is contained in:
Jacek Sieka 2022-12-16 13:11:08 +01:00 committed by GitHub
parent 110401394b
commit 064d164a88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 12 deletions

View File

@ -1298,12 +1298,10 @@ proc containsBlock*(db: BeaconChainDB, key: Eth2Digest, fork: BeaconBlockFork):
else: db.blocks[fork].contains(key.data).expectDb() else: db.blocks[fork].contains(key.data).expectDb()
proc containsBlock*(db: BeaconChainDB, key: Eth2Digest): bool = proc containsBlock*(db: BeaconChainDB, key: Eth2Digest): bool =
static: doAssert high(BeaconBlockFork) == BeaconBlockFork.EIP4844 for fork in countdown(BeaconBlockFork.high, BeaconBlockFork.low):
db.containsBlock(key, eip4844.TrustedSignedBeaconBlock) or if db.containsBlock(key, fork): return true
db.containsBlock(key, capella.TrustedSignedBeaconBlock) or
db.containsBlock(key, bellatrix.TrustedSignedBeaconBlock) or false
db.containsBlock(key, altair.TrustedSignedBeaconBlock) or
db.containsBlock(key, phase0.TrustedSignedBeaconBlock)
proc containsState*(db: BeaconChainDBV0, key: Eth2Digest): bool = proc containsState*(db: BeaconChainDBV0, key: Eth2Digest): bool =
let sk = subkey(Phase0BeaconStateNoImmutableValidators, key) let sk = subkey(Phase0BeaconStateNoImmutableValidators, key)
@ -1312,12 +1310,10 @@ proc containsState*(db: BeaconChainDBV0, key: Eth2Digest): bool =
db.backend.contains(subkey(phase0.BeaconState, key)).expectDb() db.backend.contains(subkey(phase0.BeaconState, key)).expectDb()
proc containsState*(db: BeaconChainDB, key: Eth2Digest, legacy: bool = true): bool = proc containsState*(db: BeaconChainDB, key: Eth2Digest, legacy: bool = true): bool =
db.statesNoVal[BeaconStateFork.EIP4844].contains(key.data).expectDb or for fork in countdown(BeaconStateFork.high, BeaconStateFork.low):
db.statesNoVal[BeaconStateFork.Capella].contains(key.data).expectDb or if db.statesNoVal[fork].contains(key.data).expectDb(): return true
db.statesNoVal[BeaconStateFork.Bellatrix].contains(key.data).expectDb or
db.statesNoVal[BeaconStateFork.Altair].contains(key.data).expectDb or (legacy and db.v0.containsState(key))
db.statesNoVal[BeaconStateFork.Phase0].contains(key.data).expectDb or
(legacy and db.v0.containsState(key))
proc getBeaconBlockSummary*(db: BeaconChainDB, root: Eth2Digest): proc getBeaconBlockSummary*(db: BeaconChainDB, root: Eth2Digest):
Opt[BeaconBlockSummary] = Opt[BeaconBlockSummary] =
@ -1427,6 +1423,7 @@ iterator getAncestorSummaries*(db: BeaconChainDB, root: Eth2Digest):
# Backwards compat for reading old databases, or those that for whatever # Backwards compat for reading old databases, or those that for whatever
# reason lost a summary along the way.. # reason lost a summary along the way..
static: doAssert BeaconBlockFork.high == BeaconBlockFork.EIP4844
while true: while true:
if db.v0.backend.getSnappySSZ( if db.v0.backend.getSnappySSZ(
subkey(BeaconBlockSummary, res.root), res.summary) == GetResult.found: subkey(BeaconBlockSummary, res.root), res.summary) == GetResult.found:
@ -1437,6 +1434,10 @@ iterator getAncestorSummaries*(db: BeaconChainDB, root: Eth2Digest):
res.summary = blck.get().message.toBeaconBlockSummary() res.summary = blck.get().message.toBeaconBlockSummary()
elif (let blck = db.getBlock(res.root, bellatrix.TrustedSignedBeaconBlock); blck.isSome()): elif (let blck = db.getBlock(res.root, bellatrix.TrustedSignedBeaconBlock); blck.isSome()):
res.summary = blck.get().message.toBeaconBlockSummary() 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: else:
break break