Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ValidatorConfig contain a BlockstoreOptions #3452

Merged
merged 6 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 8 additions & 20 deletions core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ use {
MAX_REPLAY_WAKE_UP_SIGNALS,
},
blockstore_metric_report_service::BlockstoreMetricReportService,
blockstore_options::{BlockstoreOptions, BlockstoreRecoveryMode, LedgerColumnOptions},
blockstore_options::BlockstoreOptions,
blockstore_processor::{self, TransactionStatusSender},
entry_notifier_interface::EntryNotifierArc,
entry_notifier_service::{EntryNotifierSender, EntryNotifierService},
Expand Down Expand Up @@ -230,9 +230,9 @@ pub struct ValidatorConfig {
pub pubsub_config: PubSubConfig,
pub snapshot_config: SnapshotConfig,
pub max_ledger_shreds: Option<u64>,
pub blockstore_options: BlockstoreOptions,
pub broadcast_stage_type: BroadcastStageType,
pub turbine_disabled: Arc<AtomicBool>,
pub enforce_ulimit_nofile: bool,
pub fixed_leader_schedule: Option<FixedSchedule>,
pub wait_for_supermajority: Option<Slot>,
pub new_hard_forks: Option<Vec<Slot>>,
Expand All @@ -242,7 +242,6 @@ pub struct ValidatorConfig {
pub gossip_validators: Option<HashSet<Pubkey>>, // None = gossip with all
pub accounts_hash_interval_slots: u64,
pub max_genesis_archive_unpacked_size: u64,
pub wal_recovery_mode: Option<BlockstoreRecoveryMode>,
/// Run PoH, transaction signature and other transaction verifications during blockstore
/// processing.
pub run_verification: bool,
Expand Down Expand Up @@ -270,7 +269,6 @@ pub struct ValidatorConfig {
pub validator_exit: Arc<RwLock<Exit>>,
pub no_wait_for_vote_to_start_leader: bool,
pub wait_to_vote_slot: Option<Slot>,
pub ledger_column_options: LedgerColumnOptions,
pub runtime_config: RuntimeConfig,
pub banking_trace_dir_byte_limit: banking_trace::DirByteLimit,
pub block_verification_method: BlockVerificationMethod,
Expand Down Expand Up @@ -298,6 +296,7 @@ impl Default for ValidatorConfig {
expected_shred_version: None,
voting_disabled: false,
max_ledger_shreds: None,
blockstore_options: BlockstoreOptions::default(),
account_paths: Vec::new(),
account_snapshot_paths: Vec::new(),
rpc_config: JsonRpcConfig::default(),
Expand All @@ -307,7 +306,6 @@ impl Default for ValidatorConfig {
snapshot_config: SnapshotConfig::new_load_only(),
broadcast_stage_type: BroadcastStageType::Standard,
turbine_disabled: Arc::<AtomicBool>::default(),
enforce_ulimit_nofile: true,
fixed_leader_schedule: None,
wait_for_supermajority: None,
new_hard_forks: None,
Expand All @@ -317,7 +315,6 @@ impl Default for ValidatorConfig {
gossip_validators: None,
accounts_hash_interval_slots: u64::MAX,
max_genesis_archive_unpacked_size: MAX_GENESIS_ARCHIVE_UNPACKED_SIZE,
wal_recovery_mode: None,
run_verification: true,
require_tower: false,
tower_storage: Arc::new(NullTowerStorage::default()),
Expand All @@ -343,7 +340,6 @@ impl Default for ValidatorConfig {
no_wait_for_vote_to_start_leader: true,
accounts_db_config: None,
wait_to_vote_slot: None,
ledger_column_options: LedgerColumnOptions::default(),
runtime_config: RuntimeConfig::default(),
banking_trace_dir_byte_limit: 0,
block_verification_method: BlockVerificationMethod::default(),
Expand All @@ -370,8 +366,8 @@ impl ValidatorConfig {
NonZeroUsize::new(get_max_thread_count()).expect("thread count is non-zero");

Self {
enforce_ulimit_nofile: false,
accounts_db_config: Some(ACCOUNTS_DB_CONFIG_FOR_TESTING),
blockstore_options: BlockstoreOptions::default_for_tests(),
rpc_config: JsonRpcConfig::default_for_test(),
block_production_method: BlockProductionMethod::default(),
enable_block_production_forwarding: true, // enable forwarding by default for tests
Expand Down Expand Up @@ -1857,15 +1853,6 @@ fn post_process_restored_tower(
Ok(restored_tower)
}

fn blockstore_options_from_config(config: &ValidatorConfig) -> BlockstoreOptions {
BlockstoreOptions {
recovery_mode: config.wal_recovery_mode.clone(),
column_options: config.ledger_column_options.clone(),
enforce_ulimit_nofile: config.enforce_ulimit_nofile,
..BlockstoreOptions::default()
}
}

fn load_genesis(
config: &ValidatorConfig,
ledger_path: &Path,
Expand Down Expand Up @@ -1926,7 +1913,7 @@ fn load_blockstore(
*start_progress.write().unwrap() = ValidatorStartProgress::LoadingLedger;

let mut blockstore =
Blockstore::open_with_options(ledger_path, blockstore_options_from_config(config))
Blockstore::open_with_options(ledger_path, config.blockstore_options.clone())
.map_err(|err| format!("Failed to open Blockstore: {err:?}"))?;

let (ledger_signal_sender, ledger_signal_receiver) = bounded(MAX_REPLAY_WAKE_UP_SIGNALS);
Expand Down Expand Up @@ -2353,7 +2340,8 @@ fn cleanup_blockstore_incorrect_shred_versions(
let backup_folder = format!(
"{}_backup_{}_{}_{}",
config
.ledger_column_options
.blockstore_options
.column_options
.shred_storage_type
.blockstore_directory(),
incorrect_shred_version,
Expand All @@ -2362,7 +2350,7 @@ fn cleanup_blockstore_incorrect_shred_versions(
);
match Blockstore::open_with_options(
&blockstore.ledger_path().join(backup_folder),
blockstore_options_from_config(config),
config.blockstore_options.clone(),
) {
Ok(backup_blockstore) => {
info!("Backing up slots from {start_slot} to {end_slot}");
Expand Down
12 changes: 12 additions & 0 deletions ledger/src/blockstore_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use {
std::path::Path,
};

#[derive(Debug, Clone)]
pub struct BlockstoreOptions {
// The access type of blockstore. Default: Primary
pub access_type: AccessType,
Expand All @@ -28,6 +29,17 @@ impl Default for BlockstoreOptions {
}
}

impl BlockstoreOptions {
pub fn default_for_tests() -> Self {
Self {
access_type: AccessType::Primary,
recovery_mode: None,
enforce_ulimit_nofile: false,
column_options: LedgerColumnOptions::default(),
}
}
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum AccessType {
/// Primary (read/write) access; only one process can have Primary access.
Expand Down
4 changes: 1 addition & 3 deletions local-cluster/src/validator_configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ pub fn safe_clone_config(config: &ValidatorConfig) -> ValidatorConfig {
pubsub_config: config.pubsub_config.clone(),
snapshot_config: config.snapshot_config.clone(),
max_ledger_shreds: config.max_ledger_shreds,
blockstore_options: config.blockstore_options.clone(),
broadcast_stage_type: config.broadcast_stage_type.clone(),
turbine_disabled: config.turbine_disabled.clone(),
enforce_ulimit_nofile: config.enforce_ulimit_nofile,
fixed_leader_schedule: config.fixed_leader_schedule.clone(),
wait_for_supermajority: config.wait_for_supermajority,
new_hard_forks: config.new_hard_forks.clone(),
Expand All @@ -31,7 +31,6 @@ pub fn safe_clone_config(config: &ValidatorConfig) -> ValidatorConfig {
gossip_validators: config.gossip_validators.clone(),
accounts_hash_interval_slots: config.accounts_hash_interval_slots,
max_genesis_archive_unpacked_size: config.max_genesis_archive_unpacked_size,
wal_recovery_mode: config.wal_recovery_mode.clone(),
run_verification: config.run_verification,
require_tower: config.require_tower,
tower_storage: config.tower_storage.clone(),
Expand All @@ -57,7 +56,6 @@ pub fn safe_clone_config(config: &ValidatorConfig) -> ValidatorConfig {
no_wait_for_vote_to_start_leader: config.no_wait_for_vote_to_start_leader,
accounts_db_config: config.accounts_db_config.clone(),
wait_to_vote_slot: config.wait_to_vote_slot,
ledger_column_options: config.ledger_column_options.clone(),
runtime_config: config.runtime_config.clone(),
banking_trace_dir_byte_limit: config.banking_trace_dir_byte_limit,
block_verification_method: config.block_verification_method.clone(),
Expand Down
1 change: 0 additions & 1 deletion test-validator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,6 @@ impl TestValidator {
incremental_snapshot_archives_dir: ledger_path.to_path_buf(),
..SnapshotConfig::default()
},
enforce_ulimit_nofile: false,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value is still set to false via ValidatorConfig::default_for_test() which will then call BlockstoreOptions::default_for_tests()

warp_slot: config.warp_slot,
validator_exit: config.validator_exit.clone(),
max_ledger_shreds: config.max_ledger_shreds,
Expand Down
21 changes: 15 additions & 6 deletions validator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ use {
solana_ledger::{
blockstore_cleanup_service::{DEFAULT_MAX_LEDGER_SHREDS, DEFAULT_MIN_MAX_LEDGER_SHREDS},
blockstore_options::{
BlockstoreCompressionType, BlockstoreRecoveryMode, LedgerColumnOptions,
ShredStorageType,
AccessType, BlockstoreCompressionType, BlockstoreOptions, BlockstoreRecoveryMode,
LedgerColumnOptions, ShredStorageType,
},
use_snapshot_archives_at_startup::{self, UseSnapshotArchivesAtStartup},
},
Expand Down Expand Up @@ -1019,7 +1019,7 @@ pub fn main() {
.pop()
.unwrap();

let wal_recovery_mode = matches
let recovery_mode = matches
.value_of("wal_recovery_mode")
.map(BlockstoreRecoveryMode::from);

Expand All @@ -1040,7 +1040,7 @@ pub fn main() {
None
};

let ledger_column_options = LedgerColumnOptions {
let column_options = LedgerColumnOptions {
compression_type: match matches.value_of("rocksdb_ledger_compression") {
None => BlockstoreCompressionType::default(),
Some(ledger_compression_string) => match ledger_compression_string {
Expand Down Expand Up @@ -1085,6 +1085,16 @@ pub fn main() {
),
};

let blockstore_options = BlockstoreOptions {
recovery_mode,
column_options,
// The validator needs to open many files, check that the process has
// permission to do so in order to fail quickly and give a direct error
enforce_ulimit_nofile: true,
// The validator needs primary (read/write)
access_type: AccessType::Primary,
};

let accounts_hash_cache_path = matches
.value_of("accounts_hash_cache_path")
.map(Into::into)
Expand Down Expand Up @@ -1551,9 +1561,8 @@ pub fn main() {
repair_validators,
repair_whitelist,
gossip_validators,
wal_recovery_mode,
max_ledger_shreds,
ledger_column_options,
blockstore_options,
run_verification: !(matches.is_present("skip_poh_verify")
|| matches.is_present("skip_startup_ledger_verification")),
debug_keys,
Expand Down
Loading