simplify `getBlockSSZ` and `getBlockSZ` implementation (#5521)

Use `forks` sugar to reduce code duplication in `beacon_chain_db.nim`.
This commit is contained in:
Etan Kissling 2023-10-24 11:15:34 +02:00 committed by GitHub
parent 513c9d9637
commit 468ee6a7ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 22 deletions

View File

@ -1038,17 +1038,8 @@ proc getBlockSSZ*[
proc getBlockSSZ*(
db: BeaconChainDB, key: Eth2Digest, data: var seq[byte],
fork: ConsensusFork): bool =
case fork
of ConsensusFork.Phase0:
getBlockSSZ(db, key, data, phase0.TrustedSignedBeaconBlock)
of ConsensusFork.Altair:
getBlockSSZ(db, key, data, altair.TrustedSignedBeaconBlock)
of ConsensusFork.Bellatrix:
getBlockSSZ(db, key, data, bellatrix.TrustedSignedBeaconBlock)
of ConsensusFork.Capella:
getBlockSSZ(db, key, data, capella.TrustedSignedBeaconBlock)
of ConsensusFork.Deneb:
getBlockSSZ(db, key, data, deneb.TrustedSignedBeaconBlock)
withConsensusFork(fork):
getBlockSSZ(db, key, data, consensusFork.TrustedSignedBeaconBlock)
proc getBlobSidecarSZ*(db: BeaconChainDB, root: Eth2Digest, index: BlobIndex,
data: var seq[byte]):
@ -1091,17 +1082,8 @@ proc getBlockSZ*[
proc getBlockSZ*(
db: BeaconChainDB, key: Eth2Digest, data: var seq[byte],
fork: ConsensusFork): bool =
case fork
of ConsensusFork.Phase0:
getBlockSZ(db, key, data, phase0.TrustedSignedBeaconBlock)
of ConsensusFork.Altair:
getBlockSZ(db, key, data, altair.TrustedSignedBeaconBlock)
of ConsensusFork.Bellatrix:
getBlockSZ(db, key, data, bellatrix.TrustedSignedBeaconBlock)
of ConsensusFork.Capella:
getBlockSZ(db, key, data, capella.TrustedSignedBeaconBlock)
of ConsensusFork.Deneb:
getBlockSZ(db, key, data, deneb.TrustedSignedBeaconBlock)
withConsensusFork(fork):
getBlockSZ(db, key, data, consensusFork.TrustedSignedBeaconBlock)
proc getStateOnlyMutableValidators(
immutableValidators: openArray[ImmutableValidatorData2],