mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-05 10:32:19 +00:00
57bcbaa21f
* Correct naming of hash func in Eth2 * Customizable mode of operation for Caplin
37 lines
885 B
Go
37 lines
885 B
Go
package db_config
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"math"
|
|
|
|
"github.com/ledgerwatch/erigon-lib/kv"
|
|
"github.com/ledgerwatch/erigon/ethdb/cbor"
|
|
)
|
|
|
|
type DatabaseConfiguration struct{ PruneDepth uint64 }
|
|
|
|
var DefaultDatabaseConfiguration = DatabaseConfiguration{PruneDepth: math.MaxUint64}
|
|
|
|
func WriteConfigurationIfNotExist(ctx context.Context, tx kv.RwTx, cfg DatabaseConfiguration) error {
|
|
var b bytes.Buffer
|
|
if err := cbor.Encoder(&b).Encode(cfg); err != nil {
|
|
return err
|
|
}
|
|
|
|
return tx.Put(kv.DatabaseInfo, []byte("config"), b.Bytes())
|
|
}
|
|
|
|
func ReadConfiguration(ctx context.Context, tx kv.Tx) (DatabaseConfiguration, error) {
|
|
var cfg DatabaseConfiguration
|
|
|
|
cfgEncoded, err := tx.GetOne(kv.DatabaseInfo, []byte("config"))
|
|
if err != nil {
|
|
return cfg, err
|
|
}
|
|
if err := cbor.Decoder(bytes.NewReader(cfgEncoded)).Decode(&cfg); err != nil {
|
|
return cfg, err
|
|
}
|
|
return cfg, err
|
|
}
|