mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-05 10:32:19 +00:00
79ed8cad35
This change introduces additional processes to manage snapshot uploading for E2 snapshots: ## erigon snapshots upload The `snapshots uploader` command starts a version of erigon customized for uploading snapshot files to a remote location. It breaks the stage execution process after the senders stage and then uses the snapshot stage to send uploaded headers, bodies and (in the case of polygon) bor spans and events to snapshot files. Because this process avoids execution in run signifigantly faster than a standard erigon configuration. The uploader uses rclone to send seedable (100K or 500K blocks) to a remote storage location specified in the rclone config file. The **uploader** is configured to minimize disk usage by doing the following: * It removes snapshots once they are loaded * It aggressively prunes the database once entities are transferred to snapshots in addition to this it has the following performance related features: * maximizes the workers allocated to snapshot processing to improve throughput * Can be started from scratch by downloading the latest snapshots from the remote location to seed processing ## snapshots command Is a stand alone command for managing remote snapshots it has the following sub commands * **cmp** - compare snapshots * **copy** - copy snapshots * **verify** - verify snapshots * **manifest** - manage the manifest file in the root of remote snapshot locations * **torrent** - manage snapshot torrent files
119 lines
3.0 KiB
Go
119 lines
3.0 KiB
Go
package commands
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/ledgerwatch/log/v3"
|
|
"github.com/spf13/cobra"
|
|
"golang.org/x/sync/semaphore"
|
|
|
|
"github.com/ledgerwatch/erigon-lib/kv"
|
|
"github.com/ledgerwatch/erigon-lib/kv/kvcfg"
|
|
kv2 "github.com/ledgerwatch/erigon-lib/kv/mdbx"
|
|
|
|
"github.com/ledgerwatch/erigon/cmd/utils"
|
|
"github.com/ledgerwatch/erigon/core/state/temporal"
|
|
"github.com/ledgerwatch/erigon/core/systemcontracts"
|
|
"github.com/ledgerwatch/erigon/migrations"
|
|
"github.com/ledgerwatch/erigon/turbo/debug"
|
|
"github.com/ledgerwatch/erigon/turbo/logging"
|
|
)
|
|
|
|
func expandHomeDir(dirpath string) string {
|
|
home, err := os.UserHomeDir()
|
|
if err != nil {
|
|
return dirpath
|
|
}
|
|
prefix := fmt.Sprintf("~%c", os.PathSeparator)
|
|
if strings.HasPrefix(dirpath, prefix) {
|
|
return filepath.Join(home, dirpath[len(prefix):])
|
|
} else if dirpath == "~" {
|
|
return home
|
|
}
|
|
return dirpath
|
|
}
|
|
|
|
var rootCmd = &cobra.Command{
|
|
Use: "integration",
|
|
Short: "long and heavy integration tests for Erigon",
|
|
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
|
datadirCli = expandHomeDir(datadirCli)
|
|
if chaindata == "" {
|
|
chaindata = filepath.Join(datadirCli, "chaindata")
|
|
} else {
|
|
chaindata = expandHomeDir(chaindata)
|
|
}
|
|
},
|
|
PersistentPostRun: func(cmd *cobra.Command, args []string) {
|
|
defer debug.Exit()
|
|
},
|
|
}
|
|
|
|
func RootCommand() *cobra.Command {
|
|
utils.CobraFlags(rootCmd, debug.Flags, utils.MetricFlags, logging.Flags)
|
|
return rootCmd
|
|
}
|
|
|
|
func dbCfg(label kv.Label, path string) kv2.MdbxOpts {
|
|
const ThreadsLimit = 9_000
|
|
limiterB := semaphore.NewWeighted(ThreadsLimit)
|
|
opts := kv2.NewMDBX(log.New()).Path(path).Label(label).RoTxsLimiter(limiterB)
|
|
// integration tool don't intent to create db, then easiest way to open db - it's pass mdbx.Accede flag, which allow
|
|
// to read all options from DB, instead of overriding them
|
|
opts = opts.Accede()
|
|
|
|
if databaseVerbosity != -1 {
|
|
opts = opts.DBVerbosity(kv.DBVerbosityLvl(databaseVerbosity))
|
|
}
|
|
return opts
|
|
}
|
|
|
|
func openDB(opts kv2.MdbxOpts, applyMigrations bool, snapshotVersion uint8, logger log.Logger) (kv.RwDB, error) {
|
|
db := opts.MustOpen()
|
|
if applyMigrations {
|
|
migrator := migrations.NewMigrator(opts.GetLabel())
|
|
has, err := migrator.HasPendingMigrations(db)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if has {
|
|
logger.Info("Re-Opening DB in exclusive mode to apply DB migrations")
|
|
db.Close()
|
|
db = opts.Exclusive().MustOpen()
|
|
if err := migrator.Apply(db, datadirCli, logger); err != nil {
|
|
return nil, err
|
|
}
|
|
db.Close()
|
|
db = opts.MustOpen()
|
|
}
|
|
}
|
|
|
|
if opts.GetLabel() == kv.ChainDB {
|
|
var h3 bool
|
|
var err error
|
|
if err := db.View(context.Background(), func(tx kv.Tx) error {
|
|
h3, err = kvcfg.HistoryV3.Enabled(tx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
if h3 {
|
|
_, _, agg := allSnapshots(context.Background(), db, snapshotVersion, logger)
|
|
tdb, err := temporal.New(db, agg, systemcontracts.SystemContractCodeLookup[chain])
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
db = tdb
|
|
}
|
|
}
|
|
|
|
return db, nil
|
|
}
|