Skip to content

Commit 04b5c29

Browse files
committed
refactor: add clear on start option to historical accounts state
1 parent 58e284c commit 04b5c29

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

modules/historical_accounts_state/src/historical_accounts_state.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const DEFAULT_PARAMETERS_SUBSCRIBE_TOPIC: (&str, &str) =
3636

3737
// Configuration defaults
3838
const DEFAULT_HISTORICAL_ACCOUNTS_DB_PATH: (&str, &str) = ("db-path", "./fjall-accounts");
39+
const DEFAULT_CLEAR_ON_START: (&str, bool) = ("clear-on-start", true);
3940
const DEFAULT_STORE_REWARDS_HISTORY: (&str, bool) = ("store-rewards-history", false);
4041
const DEFAULT_STORE_ACTIVE_STAKE_HISTORY: (&str, bool) = ("store-active-stake-history", false);
4142
const DEFAULT_STORE_REGISTRATION_HISTORY: (&str, bool) = ("store-registration-history", false);
@@ -270,6 +271,9 @@ impl HistoricalAccountsState {
270271
db_path: config
271272
.get_string(DEFAULT_HISTORICAL_ACCOUNTS_DB_PATH.0)
272273
.unwrap_or(DEFAULT_HISTORICAL_ACCOUNTS_DB_PATH.1.to_string()),
274+
clear_on_start: config
275+
.get_bool(DEFAULT_CLEAR_ON_START.0)
276+
.unwrap_or(DEFAULT_CLEAR_ON_START.1),
273277
store_rewards_history: config
274278
.get_bool(DEFAULT_STORE_REWARDS_HISTORY.0)
275279
.unwrap_or(DEFAULT_STORE_REWARDS_HISTORY.1),

modules/historical_accounts_state/src/immutable_historical_account_store.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ pub struct ImmutableHistoricalAccountStore {
3131
}
3232

3333
impl ImmutableHistoricalAccountStore {
34-
pub fn new(path: impl AsRef<Path>) -> Result<Self> {
34+
pub fn new(path: impl AsRef<Path>, clear_on_start: bool) -> Result<Self> {
35+
let path = path.as_ref();
36+
if clear_on_start && path.exists() {
37+
std::fs::remove_dir_all(path)?;
38+
}
39+
3540
let cfg = fjall::Config::new(path).max_write_buffer_size(512 * 1024 * 1024).temporary(true);
3641
let keyspace = Keyspace::open(cfg)?;
3742

modules/historical_accounts_state/src/state.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub struct ActiveStakeHistory {
4545
#[derive(Debug, Clone)]
4646
pub struct HistoricalAccountsConfig {
4747
pub db_path: String,
48+
pub clear_on_start: bool,
4849

4950
pub store_rewards_history: bool,
5051
pub store_active_stake_history: bool,
@@ -80,7 +81,10 @@ pub struct State {
8081
impl State {
8182
pub async fn new(config: HistoricalAccountsConfig) -> Result<Self> {
8283
let db_path = Path::new(&config.db_path);
83-
let store = Arc::new(ImmutableHistoricalAccountStore::new(db_path)?);
84+
let store = Arc::new(ImmutableHistoricalAccountStore::new(
85+
db_path,
86+
config.clear_on_start,
87+
)?);
8488

8589
Ok(Self {
8690
config,

processes/omnibus/omnibus.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ store-stake-addresses = false
6565
store-spdd = false
6666

6767
[module.historical-accounts-state]
68+
# Clear state on start up (default true)
69+
clear-on-start = true
6870
# Enables /accounts/{stake_address}/rewards endpoint
6971
store-rewards-history = false
7072
# Enables /accounts/{stake_address}/history endpoint

0 commit comments

Comments
 (0)