mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-08 12:01:20 +00:00
6464da7670
* save state * save state * save state * refactoring * fix * save state * save state * fmt * fix lint * restore torrents for external downloader * fix lint * download * skip debug test * debug * remote debug * small cli fixes * skip debug test * external snapshot predownloader * get rid of remote downloader * fix lint * clean makefile * fix lint * fix lint * cleanup * fix ci * fmt * remove proto from interfaces * Squashed 'interfaces/' content from commit acd02bb94 git-subtree-dir: interfaces git-subtree-split: acd02bb94c5a421aa8f8d1fd76cd8aad668e9fcb
77 lines
2.3 KiB
Go
77 lines
2.3 KiB
Go
package snapshotsync
|
|
|
|
import (
|
|
"github.com/ledgerwatch/turbo-geth/common/dbutils"
|
|
"github.com/ledgerwatch/turbo-geth/ethdb"
|
|
"github.com/ledgerwatch/turbo-geth/log"
|
|
)
|
|
|
|
var (
|
|
bucketConfigs = map[SnapshotType]dbutils.BucketsCfg{
|
|
SnapshotType_bodies: {
|
|
dbutils.BlockBodyPrefix: dbutils.BucketConfigItem{},
|
|
dbutils.SnapshotInfoBucket: dbutils.BucketConfigItem{},
|
|
},
|
|
SnapshotType_headers: {
|
|
dbutils.HeaderPrefix: dbutils.BucketConfigItem{},
|
|
dbutils.SnapshotInfoBucket: dbutils.BucketConfigItem{},
|
|
},
|
|
}
|
|
)
|
|
|
|
func WrapBySnapshots(kv ethdb.KV, snapshotDir string, mode SnapshotMode) (ethdb.KV, error) {
|
|
log.Info("Wrap db to snapshots", "dir", snapshotDir, "mode", mode.ToString())
|
|
if mode.Bodies {
|
|
snapshotKV, err := ethdb.NewLMDB().Path(snapshotDir + "/bodies").WithBucketsConfig(func(defaultBuckets dbutils.BucketsCfg) dbutils.BucketsCfg {
|
|
return bucketConfigs[SnapshotType_bodies]
|
|
}).ReadOnly().Open()
|
|
if err != nil {
|
|
log.Error("Can't open body snapshot", "err", err)
|
|
return nil, err
|
|
} else { //nolint
|
|
kv = ethdb.NewSnapshotKV().SnapshotDB(snapshotKV).
|
|
For(dbutils.BlockBodyPrefix).
|
|
For(dbutils.SnapshotInfoBucket).
|
|
DB(kv).MustOpen()
|
|
}
|
|
}
|
|
|
|
if mode.Headers {
|
|
snapshotKV, err := ethdb.NewLMDB().Path(snapshotDir + "/headers").WithBucketsConfig(func(defaultBuckets dbutils.BucketsCfg) dbutils.BucketsCfg {
|
|
return bucketConfigs[SnapshotType_headers]
|
|
}).ReadOnly().Open()
|
|
if err != nil {
|
|
log.Error("Can't open headers snapshot", "err", err)
|
|
return nil, err
|
|
} else { //nolint
|
|
kv = ethdb.NewSnapshotKV().SnapshotDB(snapshotKV).
|
|
For(dbutils.HeaderPrefix).
|
|
For(dbutils.SnapshotInfoBucket).
|
|
DB(kv).MustOpen()
|
|
}
|
|
}
|
|
return kv, nil
|
|
}
|
|
|
|
func WrapBySnapshots2(kv ethdb.KV, snapshots map[SnapshotType]*SnapshotsInfo) (ethdb.KV, error) {
|
|
|
|
for k, v := range snapshots {
|
|
log.Info("Wrap db by", "snapshot", k.String(), "dir", v.Dbpath)
|
|
cfg := bucketConfigs[k]
|
|
snapshotKV, err := ethdb.NewLMDB().Path(v.Dbpath).WithBucketsConfig(func(defaultBuckets dbutils.BucketsCfg) dbutils.BucketsCfg {
|
|
return cfg
|
|
}).ReadOnly().Open()
|
|
if err != nil {
|
|
log.Error("Can't open snapshot", "err", err)
|
|
return nil, err
|
|
} else { //nolint
|
|
snKV := ethdb.NewSnapshotKV().SnapshotDB(snapshotKV)
|
|
for i := range bucketConfigs[k] {
|
|
snKV.For(i)
|
|
}
|
|
kv = snKV.DB(kv).MustOpen()
|
|
}
|
|
}
|
|
return kv, nil
|
|
}
|