diff --git a/cmd/integration/commands/stages.go b/cmd/integration/commands/stages.go index 1b59872ed..e7f2163cf 100644 --- a/cmd/integration/commands/stages.go +++ b/cmd/integration/commands/stages.go @@ -1104,10 +1104,7 @@ var _allSnapshotsSingleton *snapshotsync.RoSnapshots func allSnapshots(cc *params.ChainConfig, db kv.RwDB) *snapshotsync.RoSnapshots { openSnapshotOnce.Do(func() { - syncmode, err := ethconfig.SyncModeByChainName(cc.ChainName, syncmodeStr) - if err != nil { - panic(err) - } + syncmode := ethconfig.SyncModeByChainName(cc.ChainName, syncmodeStr) snapCfg := ethconfig.NewSnapCfg(syncmode == ethconfig.SnapSync, true, true) if err := db.Update(context.Background(), func(tx kv.RwTx) error { return snap.EnsureNotChanged(tx, snapCfg) }); err != nil { panic(err) diff --git a/cmd/state/commands/check_change_sets.go b/cmd/state/commands/check_change_sets.go index a92c78bab..e80a495bb 100644 --- a/cmd/state/commands/check_change_sets.go +++ b/cmd/state/commands/check_change_sets.go @@ -114,10 +114,7 @@ func CheckChangeSets(genesis *core.Genesis, logger log.Logger, blockNum uint64, var blockReader services.FullBlockReader var allSnapshots *snapshotsync.RoSnapshots - syncMode, err := ethconfig.SyncModeByChainName(chainConfig.ChainName, syncmodeCli) - if err != nil { - return err - } + syncMode := ethconfig.SyncModeByChainName(chainConfig.ChainName, syncmodeCli) if syncMode == ethconfig.SnapSync { allSnapshots = snapshotsync.NewRoSnapshots(ethconfig.NewSnapCfg(true, false, true), path.Join(datadir, "snapshots")) defer allSnapshots.Close() diff --git a/cmd/state/commands/erigon2.go b/cmd/state/commands/erigon2.go index 38fd76090..358af7ec2 100644 --- a/cmd/state/commands/erigon2.go +++ b/cmd/state/commands/erigon2.go @@ -224,10 +224,7 @@ func Erigon2(genesis *core.Genesis, chainConfig *params.ChainConfig, logger log. var blockReader services.FullBlockReader var allSnapshots *snapshotsync.RoSnapshots - syncMode, err := ethconfig.SyncModeByChainName(chainConfig.ChainName, syncmodeCli) - if err != nil { - return err - } + syncMode := ethconfig.SyncModeByChainName(chainConfig.ChainName, syncmodeCli) if syncMode == ethconfig.SnapSync { allSnapshots = snapshotsync.NewRoSnapshots(ethconfig.NewSnapCfg(true, false, true), path.Join(datadir, "snapshots")) defer allSnapshots.Close() diff --git a/eth/backend.go b/eth/backend.go index af1c752df..e08016361 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -180,10 +180,8 @@ func New(stack *node.Node, config *ethconfig.Config, logger log.Logger) (*Ethere return nil, genesisErr } - config.Sync.Mode, err = ethconfig.SyncModeByChainName(chainConfig.ChainName, config.Sync.ModeCli) - if err != nil { - return nil, err - } + config.Sync.Mode = ethconfig.SyncModeByChainName(chainConfig.ChainName, config.Sync.ModeCli) + log.Info("Syncmode", "type", config.Sync.Mode) config.Snapshot.Enabled = config.Sync.Mode == ethconfig.SnapSync types.SetHeaderSealFlag(chainConfig.IsHeaderWithSeal()) diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index d52e5a56d..0da8b0d37 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -18,7 +18,6 @@ package ethconfig import ( - "fmt" "math/big" "os" "os/user" @@ -37,6 +36,7 @@ import ( "github.com/ledgerwatch/erigon/ethdb/prune" "github.com/ledgerwatch/erigon/params" "github.com/ledgerwatch/erigon/params/networkname" + "github.com/ledgerwatch/log/v3" ) // FullNodeGPO contains default gasprice oracle settings for full node. @@ -246,19 +246,19 @@ const ( SnapSync SyncMode = "snap" ) -func SyncModeByChainName(chain, syncCliFlag string) (SyncMode, error) { +func SyncModeByChainName(chain, syncCliFlag string) SyncMode { if syncCliFlag == "full" { - return FullSync, nil + return FullSync } else if syncCliFlag == "snap" { - return SnapSync, nil + return SnapSync } else if syncCliFlag != "" { - return FullSync, fmt.Errorf("unexpected syncmode: %s, only next options are valid: %s, %s", syncCliFlag, FullSync, SnapSync) + log.Warn("Unexpected Syncmode", "got", syncCliFlag, "option_1", FullSync, "option_2 ", SnapSync) } switch chain { case networkname.MainnetChainName, networkname.BSCChainName, networkname.GoerliChainName, networkname.RopstenChainName: - return SnapSync, nil + return SnapSync default: - return FullSync, nil + return FullSync } } diff --git a/turbo/snapshotsync/snap/flags.go b/turbo/snapshotsync/snap/flags.go index 4b1ade54e..f05eb8175 100644 --- a/turbo/snapshotsync/snap/flags.go +++ b/turbo/snapshotsync/snap/flags.go @@ -15,6 +15,7 @@ func Enabled(tx kv.Getter) (bool, error) { return kv.GetBool(tx, kv.DatabaseInfo, blockSnapshotEnabledKey) } +// makes sure that erigon is on the same syncmode used previously func EnsureNotChanged(tx kv.GetPut, cfg ethconfig.Snapshot) error { ok, v, err := kv.EnsureNotChangedBool(tx, kv.DatabaseInfo, blockSnapshotEnabledKey, cfg.Enabled) if err != nil {