From 42bd8266c72edb50dbf147f85a5c0555be76c7b8 Mon Sep 17 00:00:00 2001 From: Giulio Date: Mon, 7 Oct 2024 17:18:37 +0200 Subject: [PATCH] save --- cmd/capcli/cli.go | 53 +++++++++++++++++++ .../freezeblocks/caplin_snapshots.go | 4 +- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/cmd/capcli/cli.go b/cmd/capcli/cli.go index 577bd830432..c59750eb336 100644 --- a/cmd/capcli/cli.go +++ b/cmd/capcli/cli.go @@ -1115,3 +1115,56 @@ func (c *CheckBlobsSnapshotsCount) Run(ctx *Context) error { } return nil } + +type DumpBlobsSnapshotsToStore struct { + chainCfg + outputFolder + withPPROF +} + +func (c *DumpBlobsSnapshotsToStore) Run(ctx *Context) error { + _, beaconConfig, _, err := clparams.GetConfigsByNetworkName(c.Chain) + if err != nil { + return err + } + c.withProfile() + log.Root().SetHandler(log.LvlFilterHandler(log.LvlDebug, log.StderrHandler)) + log.Info("Started the checking process", "chain", c.Chain) + dirs := datadir.New(c.Datadir) + log.Root().SetHandler(log.LvlFilterHandler(log.LvlInfo, log.StderrHandler)) + + db, blobStore, err := caplin1.OpenCaplinDatabase(ctx, beaconConfig, nil, dirs.CaplinIndexing, dirs.CaplinBlobs, nil, false, 0) + if err != nil { + return err + } + tx, err := db.BeginRo(ctx) + if err != nil { + return err + } + defer tx.Rollback() + + csn := freezeblocks.NewCaplinSnapshots(ethconfig.BlocksFreezing{}, beaconConfig, dirs, log.Root()) + if err := csn.ReopenFolder(); err != nil { + return err + } + to := csn.FrozenBlobs() + start := max(beaconConfig.SlotsPerEpoch * beaconConfig.DenebForkEpoch) + for i := start; i < to; i++ { + sds, err := csn.ReadBlobSidecars(i) + if err != nil { + return err + } + blockRoot, err := beacon_indicies.ReadCanonicalBlockRoot(tx, i) + if err != nil { + return err + } + if blockRoot == (libcommon.Hash{}) { + continue + } + if err := blobStore.WriteBlobSidecars(ctx, blockRoot, sds); err != nil { + return err + } + } + + return nil +} diff --git a/turbo/snapshotsync/freezeblocks/caplin_snapshots.go b/turbo/snapshotsync/freezeblocks/caplin_snapshots.go index 6e110eab1c3..4127560eb4c 100644 --- a/turbo/snapshotsync/freezeblocks/caplin_snapshots.go +++ b/turbo/snapshotsync/freezeblocks/caplin_snapshots.go @@ -556,7 +556,7 @@ func dumpBeaconBlocksRange(ctx context.Context, db kv.RoDB, fromSlot uint64, toS return BeaconSimpleIdx(ctx, f, salt, tmpDir, p, lvl, logger) } -func dumpBlobSidecarsRange(ctx context.Context, db kv.RoDB, storage blob_storage.BlobStorage, fromSlot uint64, toSlot uint64, salt uint32, dirs datadir.Dirs, workers int, blobCountFn BlobCountBySlotFn, lvl log.Lvl, logger log.Logger) error { +func DumpBlobSidecarsRange(ctx context.Context, db kv.RoDB, storage blob_storage.BlobStorage, fromSlot uint64, toSlot uint64, salt uint32, dirs datadir.Dirs, workers int, blobCountFn BlobCountBySlotFn, lvl log.Lvl, logger log.Logger) error { tmpDir, snapDir := dirs.Tmp, dirs.Snap segName := snaptype.BlobSidecars.FileName(0, fromSlot, toSlot) @@ -671,7 +671,7 @@ func DumpBlobsSidecar(ctx context.Context, blobStorage blob_storage.BlobStorage, } to := chooseSegmentEnd(i, toSlot, snaptype.CaplinEnums.BlobSidecars, nil) logger.Log(lvl, "Dumping blobs sidecars", "from", i, "to", to) - if err := dumpBlobSidecarsRange(ctx, db, blobStorage, i, to, salt, dirs, compressWorkers, blobCountFn, lvl, logger); err != nil { + if err := DumpBlobSidecarsRange(ctx, db, blobStorage, i, to, salt, dirs, compressWorkers, blobCountFn, lvl, logger); err != nil { return err } }