add function to import blobs to `ncli_db` (#6166)
* add function to import blobs to `ncli_db` `ncli_db` does not support importing blobs, making it impossible to complete the database solely from dumped files. Add the missing support. * pass `cfg`
This commit is contained in:
parent
7fa32b7f02
commit
8d0a4a87e7
|
@ -41,6 +41,7 @@ type
|
|||
putState = "Store a given BeaconState in the database"
|
||||
dumpBlock = "Extract a (trusted) SignedBeaconBlock from the database"
|
||||
putBlock = "Store a given SignedBeaconBlock in the database, potentially updating some of the pointers"
|
||||
putBlob = "Store a given BlobSidecar in the database"
|
||||
rewindState = "Extract any state from the database based on a given block and slot, replaying if needed"
|
||||
verifyEra = "Verify a single era file"
|
||||
exportEra = "Export historical data to era store in current directory"
|
||||
|
@ -129,6 +130,12 @@ type
|
|||
name: "set-genesis"
|
||||
desc: "Update genesis to this block"}: bool
|
||||
|
||||
of DbCmd.putBlob:
|
||||
blobFile {.
|
||||
argument
|
||||
name: "file"
|
||||
desc: "Files to import".}: seq[string]
|
||||
|
||||
of DbCmd.rewindState:
|
||||
blockRoot* {.
|
||||
argument
|
||||
|
@ -469,6 +476,30 @@ proc cmdPutBlock(conf: DbConf, cfg: RuntimeConfig) =
|
|||
if conf.setGenesis:
|
||||
db.putGenesisBlock(forkyBlck.root)
|
||||
|
||||
proc cmdPutBlob(conf: DbConf, cfg: RuntimeConfig) =
|
||||
let db = BeaconChainDB.new(conf.databaseDir.string, cfg)
|
||||
defer: db.close()
|
||||
|
||||
for file in conf.blobFile:
|
||||
if shouldShutDown: quit QuitSuccess
|
||||
|
||||
let
|
||||
blob =
|
||||
try:
|
||||
SSZ.decode(readAllBytes(file).tryGet(), BlobSidecar)
|
||||
except ResultError[IoErrorCode] as e:
|
||||
echo "Couldn't load ", file, ": ", e.msg
|
||||
continue
|
||||
except SerializationError as e:
|
||||
echo "Malformed ", file, ": ", e.msg
|
||||
continue
|
||||
res = blob.verify_blob_sidecar_inclusion_proof()
|
||||
if res.isErr:
|
||||
echo "Invalid ", file, ": ", res.error
|
||||
continue
|
||||
|
||||
db.putBlobSidecar(blob)
|
||||
|
||||
proc cmdRewindState(conf: DbConf, cfg: RuntimeConfig) =
|
||||
echo "Opening database..."
|
||||
let db = BeaconChainDB.new(conf.databaseDir.string, readOnly = true)
|
||||
|
@ -1167,6 +1198,8 @@ when isMainModule:
|
|||
cmdDumpBlock(conf)
|
||||
of DbCmd.putBlock:
|
||||
cmdPutBlock(conf, cfg)
|
||||
of DbCmd.putBlob:
|
||||
cmdPutBlob(conf, cfg)
|
||||
of DbCmd.rewindState:
|
||||
cmdRewindState(conf, cfg)
|
||||
of DbCmd.verifyEra:
|
||||
|
|
Loading…
Reference in New Issue