mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-08 03:51:20 +00:00
41185e2518
Basically, pruning is specified by the user, by default, 1 million (in the PR set to 100 for pruning purposes). the pruning for the database is stored inside the db
40 lines
936 B
Go
40 lines
936 B
Go
package db_config
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
)
|
|
|
|
type DatabaseConfiguration struct {
|
|
PruneDepth uint64
|
|
}
|
|
|
|
var DefaultDatabaseConfiguration = DatabaseConfiguration{
|
|
PruneDepth: 10, // should be 1_000_000
|
|
}
|
|
|
|
func WriteConfigurationIfNotExist(ctx context.Context, tx *sql.Tx, cfg DatabaseConfiguration) error {
|
|
var count int
|
|
err := tx.QueryRow("SELECT COUNT(*) FROM data_config;").Scan(&count)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if count > 0 {
|
|
return nil
|
|
}
|
|
_, err = tx.ExecContext(ctx, "INSERT INTO data_config (prune_depth) VALUES (?);", cfg.PruneDepth)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func ReadConfiguration(ctx context.Context, tx *sql.Tx) (DatabaseConfiguration, error) {
|
|
var pruneDepth uint64
|
|
err := tx.QueryRowContext(ctx, "SELECT prune_depth FROM data_config").Scan(&pruneDepth)
|
|
if err != nil {
|
|
return DatabaseConfiguration{}, err
|
|
}
|
|
return DatabaseConfiguration{PruneDepth: pruneDepth}, nil
|
|
}
|