2022-04-28 05:13:30 +00:00
|
|
|
package snap
|
2022-01-22 04:18:24 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"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
|
|
|
)
|
|
|
|
|
2022-05-10 08:54:44 +00:00
|
|
|
func Enabled(tx kv.Getter) (bool, error) {
|
|
|
|
return kv.GetBool(tx, kv.DatabaseInfo, blockSnapshotEnabledKey)
|
|
|
|
}
|
|
|
|
|
2023-06-15 06:11:51 +00:00
|
|
|
func EnsureNotChanged(tx kv.GetPut, cfg ethconfig.BlocksFreezing) (bool, bool, error) {
|
2022-01-22 04:18:24 +00:00
|
|
|
ok, v, err := kv.EnsureNotChangedBool(tx, kv.DatabaseInfo, blockSnapshotEnabledKey, cfg.Enabled)
|
|
|
|
if err != nil {
|
2022-06-05 06:33:55 +00:00
|
|
|
return false, false, err
|
2022-01-22 04:18:24 +00:00
|
|
|
}
|
|
|
|
if !ok {
|
2022-06-05 06:33:55 +00:00
|
|
|
return false, v, nil
|
2022-01-22 04:18:24 +00:00
|
|
|
}
|
2022-06-05 06:33:55 +00:00
|
|
|
return true, false, nil
|
2022-01-22 04:18:24 +00:00
|
|
|
}
|
2022-03-16 08:35:36 +00:00
|
|
|
|
|
|
|
// ForceSetFlags - if you know what you are doing
|
2023-06-15 06:11:51 +00:00
|
|
|
func ForceSetFlags(tx kv.GetPut, cfg ethconfig.BlocksFreezing) error {
|
2022-03-16 08:35:36 +00:00
|
|
|
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
|
|
|
|
}
|