erigon-pulse/turbo/snapshotsync/snap/flags.go
Alex Sharov e5023775aa
Enforce blockReader interface (#7737)
- breaks dependency from staged_sync to package with block_reader
implementation
- breaks dependency from snap_sync to package with block_reader
implementation
- breaks dependency from mining to txpool implementation
2023-06-15 13:11:51 +07:00

40 lines
963 B
Go

package snap
import (
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon/eth/ethconfig"
)
var (
blockSnapshotEnabledKey = []byte("blocksSnapshotEnabled")
)
func Enabled(tx kv.Getter) (bool, error) {
return kv.GetBool(tx, kv.DatabaseInfo, blockSnapshotEnabledKey)
}
func EnsureNotChanged(tx kv.GetPut, cfg ethconfig.BlocksFreezing) (bool, bool, error) {
ok, v, err := kv.EnsureNotChangedBool(tx, kv.DatabaseInfo, blockSnapshotEnabledKey, cfg.Enabled)
if err != nil {
return false, false, err
}
if !ok {
return false, v, nil
}
return true, false, nil
}
// ForceSetFlags - if you know what you are doing
func ForceSetFlags(tx kv.GetPut, cfg ethconfig.BlocksFreezing) 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
}