From 754276909b673fdeef4503f5a7880198ccd9bfb9 Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Wed, 6 Dec 2023 19:12:43 +0700 Subject: [PATCH] bor snaps: "erigon snapshots retire" to build bor files (#8912) --- turbo/app/snapshots_cmd.go | 5 ++++- turbo/snapshotsync/freezeblocks/block_snapshots.go | 2 +- turbo/snapshotsync/freezeblocks/bor_snapshots.go | 6 +----- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/turbo/app/snapshots_cmd.go b/turbo/app/snapshots_cmd.go index 28d4cb9ff..9dd636206 100644 --- a/turbo/app/snapshots_cmd.go +++ b/turbo/app/snapshots_cmd.go @@ -470,12 +470,15 @@ func doRetireCommand(cliCtx *cli.Context) error { if err := br.RetireBlocks(ctx, i, i+every, log.LvlInfo, nil, nil); err != nil { panic(err) } + if err := br.RetireBorBlocks(ctx, i, i+every, log.LvlInfo, nil, nil); err != nil { + panic(err) + } if err := db.Update(ctx, func(tx kv.RwTx) error { if err := rawdb.WriteSnapshots(tx, blockReader.FrozenFiles(), agg.Files()); err != nil { return err } for j := 0; j < 10_000; j++ { // prune happens by small steps, so need many runs - if err := br.PruneAncientBlocks(tx, 100, false /* includeBor */); err != nil { + if err := br.PruneAncientBlocks(tx, 100, true /* includeBor */); err != nil { return err } } diff --git a/turbo/snapshotsync/freezeblocks/block_snapshots.go b/turbo/snapshotsync/freezeblocks/block_snapshots.go index 0456e0a4c..f62ea9ac9 100644 --- a/turbo/snapshotsync/freezeblocks/block_snapshots.go +++ b/turbo/snapshotsync/freezeblocks/block_snapshots.go @@ -1352,7 +1352,7 @@ func (br *BlockRetire) RetireBlocksInBackground(ctx context.Context, forwardProg if includeBor { blockFrom, blockTo, ok = CanRetire(forwardProgress, br.blockReader.FrozenBorBlocks()) if ok { - if err := br.RetireBorBlocks(ctx, blockFrom, blockTo, lvl, seedNewSnapshots); err != nil { + if err := br.RetireBorBlocks(ctx, blockFrom, blockTo, lvl, seedNewSnapshots, onDeleteSnapshots); err != nil { br.logger.Warn("[bor snapshots] retire blocks", "err", err, "fromBlock", blockFrom, "toBlock", blockTo) } } diff --git a/turbo/snapshotsync/freezeblocks/bor_snapshots.go b/turbo/snapshotsync/freezeblocks/bor_snapshots.go index 11899abc9..23895953a 100644 --- a/turbo/snapshotsync/freezeblocks/bor_snapshots.go +++ b/turbo/snapshotsync/freezeblocks/bor_snapshots.go @@ -174,7 +174,7 @@ type borSpanSegments struct { segments []*BorSpanSegment } -func (br *BlockRetire) RetireBorBlocks(ctx context.Context, blockFrom, blockTo uint64, lvl log.Lvl, seedNewSnapshots func(downloadRequest []services.DownloadRequest) error) error { +func (br *BlockRetire) RetireBorBlocks(ctx context.Context, blockFrom, blockTo uint64, lvl log.Lvl, seedNewSnapshots func(downloadRequest []services.DownloadRequest) error, onDelete func(l []string) error) error { chainConfig := fromdb.ChainConfig(br.db) notifier, logger, blockReader, tmpDir, db, workers := br.notifier, br.logger, br.blockReader, br.tmpDir, br.db, br.workers logger.Log(lvl, "[bor snapshots] Retire Bor Blocks", "range", fmt.Sprintf("%dk-%dk", blockFrom/1000, blockTo/1000)) @@ -211,10 +211,6 @@ func (br *BlockRetire) RetireBorBlocks(ctx context.Context, blockFrom, blockTo u } return nil } - onDelete := func(files []string) error { - //TODO: add Downloader API to delete files - return nil - } err := merger.Merge(ctx, snapshots, rangesToMerge, snapshots.Dir(), true /* doIndex */, onMerge, onDelete) if err != nil { return err