fix `ncli_db`
This commit is contained in:
parent
d028baea2a
commit
5fe9e93ee7
|
@ -1497,6 +1497,35 @@ func readSszForkedSignedBeaconBlock*(
|
||||||
withBlck(result):
|
withBlck(result):
|
||||||
readSszBytes(data, forkyBlck)
|
readSszBytes(data, forkyBlck)
|
||||||
|
|
||||||
|
func readSszForkedBlobSidecar*(
|
||||||
|
cfg: RuntimeConfig, data: openArray[byte]
|
||||||
|
): ForkedBlobSidecar {.raises: [SerializationError].} =
|
||||||
|
## Helper to read `BlobSidecar` from bytes when it's not certain what
|
||||||
|
## `BlobFork` it is
|
||||||
|
type ForkedBlobSidecarHeader = object
|
||||||
|
index: BlobIndex
|
||||||
|
blob: Blob
|
||||||
|
kzg_commitment: KzgCommitment
|
||||||
|
kzg_proof: KzgProof
|
||||||
|
signed_block_header*: SignedBeaconBlockHeader
|
||||||
|
|
||||||
|
const numHeaderBytes = fixedPortionSize(ForkedBlobSidecarHeader)
|
||||||
|
if data.len() < numHeaderBytes:
|
||||||
|
raise (ref MalformedSszError)(msg: "Incomplete BlobSidecar header")
|
||||||
|
let
|
||||||
|
header = SSZ.decode(
|
||||||
|
data.toOpenArray(0, numHeaderBytes - 1), ForkedBlobSidecarHeader)
|
||||||
|
consensusFork = cfg.consensusForkAtEpoch(
|
||||||
|
header.signed_block_header.message.slot.epoch)
|
||||||
|
blobFork = blobForkAtConsensusFork(consensusFork).valueOr:
|
||||||
|
raise (ref MalformedSszError)(msg: "BlobSidecar slot is pre-Deneb")
|
||||||
|
|
||||||
|
# TODO https://github.com/nim-lang/Nim/issues/19357
|
||||||
|
result = ForkedBlobSidecar(kind: blobFork)
|
||||||
|
withForkyBlob(result):
|
||||||
|
forkyBlob = new blobFork.BlobSidecar()
|
||||||
|
readSszBytes(data, forkyBlob[])
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.4.0/specs/phase0/beacon-chain.md#compute_fork_data_root
|
# https://github.com/ethereum/consensus-specs/blob/v1.4.0/specs/phase0/beacon-chain.md#compute_fork_data_root
|
||||||
func compute_fork_data_root*(current_version: Version,
|
func compute_fork_data_root*(current_version: Version,
|
||||||
genesis_validators_root: Eth2Digest): Eth2Digest =
|
genesis_validators_root: Eth2Digest): Eth2Digest =
|
||||||
|
|
|
@ -489,19 +489,22 @@ proc cmdPutBlob(conf: DbConf, cfg: RuntimeConfig) =
|
||||||
let
|
let
|
||||||
blob =
|
blob =
|
||||||
try:
|
try:
|
||||||
SSZ.decode(readAllBytes(file).tryGet(), BlobSidecar)
|
readSszForkedBlobSidecar(
|
||||||
|
cfg, readAllBytes(file).tryGet())
|
||||||
except ResultError[IoErrorCode] as e:
|
except ResultError[IoErrorCode] as e:
|
||||||
echo "Couldn't load ", file, ": ", e.msg
|
echo "Couldn't load ", file, ": ", e.msg
|
||||||
continue
|
continue
|
||||||
except SerializationError as e:
|
except SerializationError as e:
|
||||||
echo "Malformed ", file, ": ", e.msg
|
echo "Malformed ", file, ": ", e.msg
|
||||||
continue
|
continue
|
||||||
res = blob.verify_blob_sidecar_inclusion_proof()
|
res = withForkyBlob(blob):
|
||||||
|
forkyBlob[].verify_blob_sidecar_inclusion_proof()
|
||||||
if res.isErr:
|
if res.isErr:
|
||||||
echo "Invalid ", file, ": ", res.error
|
echo "Invalid ", file, ": ", res.error
|
||||||
continue
|
continue
|
||||||
|
|
||||||
db.putBlobSidecar(blob)
|
withForkyBlob(blob):
|
||||||
|
db.putBlobSidecar(forkyBlob[])
|
||||||
|
|
||||||
proc cmdRewindState(conf: DbConf, cfg: RuntimeConfig) =
|
proc cmdRewindState(conf: DbConf, cfg: RuntimeConfig) =
|
||||||
echo "Opening database..."
|
echo "Opening database..."
|
||||||
|
@ -1214,4 +1217,4 @@ when isMainModule:
|
||||||
of DbCmd.validatorPerf:
|
of DbCmd.validatorPerf:
|
||||||
cmdValidatorPerf(conf, cfg)
|
cmdValidatorPerf(conf, cfg)
|
||||||
of DbCmd.validatorDb:
|
of DbCmd.validatorDb:
|
||||||
cmdValidatorDb(conf, cfg)
|
cmdValidatorDb(conf, cfg)
|
||||||
|
|
Loading…
Reference in New Issue