diff --git a/runtime/src/accounts_index.rs b/runtime/src/accounts_index.rs index 8dfc03a58..b75c821b2 100644 --- a/runtime/src/accounts_index.rs +++ b/runtime/src/accounts_index.rs @@ -52,6 +52,7 @@ pub const ACCOUNTS_INDEX_CONFIG_FOR_TESTING: AccountsIndexConfig = AccountsIndex index_limit_mb: None, ages_to_stay_in_cache: None, scan_results_limit_bytes: None, + started_from_validator: false, }; pub const ACCOUNTS_INDEX_CONFIG_FOR_BENCHMARKS: AccountsIndexConfig = AccountsIndexConfig { bins: Some(BINS_FOR_BENCHMARKS), @@ -60,6 +61,7 @@ pub const ACCOUNTS_INDEX_CONFIG_FOR_BENCHMARKS: AccountsIndexConfig = AccountsIn index_limit_mb: None, ages_to_stay_in_cache: None, scan_results_limit_bytes: None, + started_from_validator: false, }; pub type ScanResult = Result; pub type SlotList = Vec<(Slot, T)>; @@ -162,6 +164,8 @@ pub struct AccountsIndexConfig { pub index_limit_mb: Option, pub ages_to_stay_in_cache: Option, pub scan_results_limit_bytes: Option, + /// true if the accounts index is being created as a result of being started as a validator (as opposed to test, etc.) + pub started_from_validator: bool, } #[derive(Debug, Default, Clone)] @@ -858,13 +862,7 @@ pub struct AccountsIndex { impl AccountsIndex { pub fn default_for_tests() -> Self { - let mut config = ACCOUNTS_INDEX_CONFIG_FOR_TESTING; - if let Ok(limit) = std::env::var("SOLANA_TEST_ACCOUNTS_INDEX_MEMORY_LIMIT_MB") { - // allocate with disk buckets - config.index_limit_mb = Some(limit.parse::().unwrap()); - } - - Self::new(Some(config)) + Self::new(Some(ACCOUNTS_INDEX_CONFIG_FOR_TESTING)) } pub fn new(config: Option) -> Self { diff --git a/runtime/src/bucket_map_holder.rs b/runtime/src/bucket_map_holder.rs index b206b6288..87b2ee26f 100644 --- a/runtime/src/bucket_map_holder.rs +++ b/runtime/src/bucket_map_holder.rs @@ -153,7 +153,20 @@ impl BucketMapHolder { let mut bucket_config = BucketMapConfig::new(bins); bucket_config.drives = config.as_ref().and_then(|config| config.drives.clone()); - let mem_budget_mb = config.as_ref().and_then(|config| config.index_limit_mb); + let mut mem_budget_mb = config.as_ref().and_then(|config| config.index_limit_mb); + let bucket_map_tests_allowed = mem_budget_mb.is_none() + && !config + .as_ref() + .map(|config| config.started_from_validator) + .unwrap_or_default(); + if bucket_map_tests_allowed { + if let Ok(limit) = std::env::var("SOLANA_TEST_ACCOUNTS_INDEX_MEMORY_LIMIT_MB") { + // allocate with disk buckets if mem budget was not set, we were NOT started from validator, and env var was set + // we do not want the env var to have an effect when running the validator (only tests, benches, etc.) + mem_budget_mb = Some(limit.parse::().unwrap()); + } + } + // only allocate if mem_budget_mb is Some let disk = mem_budget_mb.map(|_| BucketMap::new(bucket_config)); Self { diff --git a/validator/src/main.rs b/validator/src/main.rs index 9e0bf1ffa..46c818308 100644 --- a/validator/src/main.rs +++ b/validator/src/main.rs @@ -2117,7 +2117,10 @@ pub fn main() { _ => unreachable!(), }; - let mut accounts_index_config = AccountsIndexConfig::default(); + let mut accounts_index_config = AccountsIndexConfig { + started_from_validator: true, // this is the only place this is set + ..AccountsIndexConfig::default() + }; if let Some(bins) = value_t!(matches, "accounts_index_bins", usize).ok() { accounts_index_config.bins = Some(bins); }