2022-01-22 04:18:24 +00:00
|
|
|
package snapshotsynccli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/ledgerwatch/erigon-lib/kv"
|
|
|
|
"github.com/ledgerwatch/erigon/eth/ethconfig"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2022-03-16 02:57:48 +00:00
|
|
|
blockSnapshotEnabledKey = []byte("blocksSnapshotEnabled")
|
2022-01-22 04:18:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func EnsureNotChanged(tx kv.GetPut, cfg ethconfig.Snapshot) error {
|
|
|
|
ok, v, err := kv.EnsureNotChangedBool(tx, kv.DatabaseInfo, blockSnapshotEnabledKey, cfg.Enabled)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if !ok {
|
2022-04-01 08:00:50 +00:00
|
|
|
if v {
|
2022-04-10 06:20:20 +00:00
|
|
|
return fmt.Errorf("we recently changed default of --syncmode flag, please add flag --syncmode=snap")
|
2022-04-01 08:00:50 +00:00
|
|
|
} else {
|
2022-04-26 15:19:24 +00:00
|
|
|
return fmt.Errorf("we recently changed default of --syncmode flag, please add flag --syncmode=full")
|
2022-04-01 08:00:50 +00:00
|
|
|
}
|
2022-01-22 04:18:24 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2022-03-16 08:35:36 +00:00
|
|
|
|
|
|
|
// ForceSetFlags - if you know what you are doing
|
|
|
|
func ForceSetFlags(tx kv.GetPut, cfg ethconfig.Snapshot) error {
|
|
|
|
if cfg.Enabled {
|
|
|
|
if err := tx.Put(kv.DatabaseInfo, blockSnapshotEnabledKey, []byte{1}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err := tx.Put(kv.DatabaseInfo, blockSnapshotEnabledKey, []byte{0}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|