Factor out bank_forks_utils::load_bank_forks()
This commit is contained in:
parent
63324be5b3
commit
115f376465
|
@ -550,11 +550,8 @@ mod tests {
|
||||||
full_leader_cache: true,
|
full_leader_cache: true,
|
||||||
..ProcessOptions::default()
|
..ProcessOptions::default()
|
||||||
};
|
};
|
||||||
let (bank_forks, cached_leader_schedule, _) = test_process_blockstore(
|
let (bank_forks, cached_leader_schedule, _) =
|
||||||
&genesis_config,
|
test_process_blockstore(&genesis_config, &blockstore, opts);
|
||||||
&blockstore,
|
|
||||||
opts,
|
|
||||||
);
|
|
||||||
let leader_schedule_cache = Arc::new(cached_leader_schedule);
|
let leader_schedule_cache = Arc::new(cached_leader_schedule);
|
||||||
let bank_forks = Arc::new(RwLock::new(bank_forks));
|
let bank_forks = Arc::new(RwLock::new(bank_forks));
|
||||||
|
|
||||||
|
|
|
@ -1322,31 +1322,40 @@ fn new_banks_from_ledger(
|
||||||
TransactionHistoryServices::default()
|
TransactionHistoryServices::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let (
|
let cache_block_meta_sender = transaction_history_services
|
||||||
mut bank_forks,
|
.cache_block_meta_sender
|
||||||
mut leader_schedule_cache,
|
.as_ref();
|
||||||
last_full_snapshot_slot,
|
|
||||||
starting_snapshot_hashes,
|
let (bank_forks, starting_snapshot_hashes) = bank_forks_utils::load_bank_forks(
|
||||||
) = bank_forks_utils::load(
|
|
||||||
&genesis_config,
|
&genesis_config,
|
||||||
&blockstore,
|
&blockstore,
|
||||||
config.account_paths.clone(),
|
config.account_paths.clone(),
|
||||||
config.account_shrink_paths.clone(),
|
config.account_shrink_paths.clone(),
|
||||||
config.snapshot_config.as_ref(),
|
config.snapshot_config.as_ref(),
|
||||||
process_options,
|
&process_options,
|
||||||
transaction_history_services
|
cache_block_meta_sender,
|
||||||
.transaction_status_sender
|
|
||||||
.as_ref(),
|
|
||||||
transaction_history_services
|
|
||||||
.cache_block_meta_sender
|
|
||||||
.as_ref(),
|
|
||||||
accounts_package_sender,
|
|
||||||
accounts_update_notifier,
|
accounts_update_notifier,
|
||||||
)
|
);
|
||||||
.unwrap_or_else(|err| {
|
|
||||||
error!("Failed to load ledger: {:?}", err);
|
let (mut bank_forks, mut leader_schedule_cache, last_full_snapshot_slot) =
|
||||||
abort()
|
blockstore_processor::process_blockstore_from_root(
|
||||||
});
|
&blockstore,
|
||||||
|
bank_forks,
|
||||||
|
&process_options,
|
||||||
|
transaction_history_services
|
||||||
|
.transaction_status_sender
|
||||||
|
.as_ref(),
|
||||||
|
cache_block_meta_sender,
|
||||||
|
config.snapshot_config.as_ref(),
|
||||||
|
accounts_package_sender,
|
||||||
|
)
|
||||||
|
.unwrap_or_else(|err| {
|
||||||
|
error!("Failed to load ledger: {:?}", err);
|
||||||
|
abort()
|
||||||
|
});
|
||||||
|
|
||||||
|
let last_full_snapshot_slot =
|
||||||
|
last_full_snapshot_slot.or_else(|| starting_snapshot_hashes.map(|x| x.full.hash.0));
|
||||||
|
|
||||||
if let Some(warp_slot) = config.warp_slot {
|
if let Some(warp_slot) = config.warp_slot {
|
||||||
let snapshot_config = config.snapshot_config.as_ref().unwrap_or_else(|| {
|
let snapshot_config = config.snapshot_config.as_ref().unwrap_or_else(|| {
|
||||||
|
|
|
@ -27,7 +27,7 @@ use {
|
||||||
self, AccessType, BlockstoreAdvancedOptions, BlockstoreOptions, BlockstoreRecoveryMode,
|
self, AccessType, BlockstoreAdvancedOptions, BlockstoreOptions, BlockstoreRecoveryMode,
|
||||||
Database,
|
Database,
|
||||||
},
|
},
|
||||||
blockstore_processor::ProcessOptions,
|
blockstore_processor::{BlockstoreProcessorError, ProcessOptions},
|
||||||
shred::Shred,
|
shred::Shred,
|
||||||
},
|
},
|
||||||
solana_measure::measure::Measure,
|
solana_measure::measure::Measure,
|
||||||
|
@ -41,6 +41,7 @@ use {
|
||||||
hardened_unpack::{open_genesis_config, MAX_GENESIS_ARCHIVE_UNPACKED_SIZE},
|
hardened_unpack::{open_genesis_config, MAX_GENESIS_ARCHIVE_UNPACKED_SIZE},
|
||||||
snapshot_archive_info::SnapshotArchiveInfoGetter,
|
snapshot_archive_info::SnapshotArchiveInfoGetter,
|
||||||
snapshot_config::SnapshotConfig,
|
snapshot_config::SnapshotConfig,
|
||||||
|
snapshot_hash::StartingSnapshotHashes,
|
||||||
snapshot_utils::{
|
snapshot_utils::{
|
||||||
self, ArchiveFormat, SnapshotVersion, DEFAULT_MAX_FULL_SNAPSHOT_ARCHIVES_TO_RETAIN,
|
self, ArchiveFormat, SnapshotVersion, DEFAULT_MAX_FULL_SNAPSHOT_ARCHIVES_TO_RETAIN,
|
||||||
DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN,
|
DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN,
|
||||||
|
@ -711,7 +712,7 @@ fn load_bank_forks(
|
||||||
blockstore: &Blockstore,
|
blockstore: &Blockstore,
|
||||||
process_options: ProcessOptions,
|
process_options: ProcessOptions,
|
||||||
snapshot_archive_path: Option<PathBuf>,
|
snapshot_archive_path: Option<PathBuf>,
|
||||||
) -> bank_forks_utils::LoadResult {
|
) -> Result<(BankForks, Option<StartingSnapshotHashes>), BlockstoreProcessorError> {
|
||||||
let bank_snapshots_dir = blockstore
|
let bank_snapshots_dir = blockstore
|
||||||
.ledger_path()
|
.ledger_path()
|
||||||
.join(if blockstore.is_primary_access() {
|
.join(if blockstore.is_primary_access() {
|
||||||
|
@ -764,6 +765,7 @@ fn load_bank_forks(
|
||||||
accounts_package_sender,
|
accounts_package_sender,
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
.map(|(bank_forks, .., starting_snapshot_hashes)| (bank_forks, starting_snapshot_hashes))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_slot_cost(blockstore: &Blockstore, slot: Slot) -> Result<(), String> {
|
fn compute_slot_cost(blockstore: &Blockstore, slot: Slot) -> Result<(), String> {
|
||||||
|
@ -2221,7 +2223,7 @@ fn main() {
|
||||||
},
|
},
|
||||||
snapshot_archive_path,
|
snapshot_archive_path,
|
||||||
) {
|
) {
|
||||||
Ok((bank_forks, .., starting_snapshot_hashes)) => {
|
Ok((bank_forks, starting_snapshot_hashes)) => {
|
||||||
let mut bank = bank_forks
|
let mut bank = bank_forks
|
||||||
.get(snapshot_slot)
|
.get(snapshot_slot)
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
|
@ -2439,10 +2441,11 @@ fn main() {
|
||||||
}
|
}
|
||||||
let full_snapshot_slot = starting_snapshot_hashes.unwrap().full.hash.0;
|
let full_snapshot_slot = starting_snapshot_hashes.unwrap().full.hash.0;
|
||||||
if bank.slot() <= full_snapshot_slot {
|
if bank.slot() <= full_snapshot_slot {
|
||||||
eprintln!("Unable to create incremental snapshot: Slot must be greater than full snapshot slot. slot: {}, full snapshot slot: {}",
|
eprintln!(
|
||||||
bank.slot(),
|
"Unable to create incremental snapshot: Slot must be greater than full snapshot slot. slot: {}, full snapshot slot: {}",
|
||||||
full_snapshot_slot,
|
bank.slot(),
|
||||||
);
|
full_snapshot_slot,
|
||||||
|
);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2463,12 +2466,12 @@ fn main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"Successfully created incremental snapshot for slot {}, hash {}, base slot: {}: {}",
|
"Successfully created incremental snapshot for slot {}, hash {}, base slot: {}: {}",
|
||||||
bank.slot(),
|
bank.slot(),
|
||||||
bank.hash(),
|
bank.hash(),
|
||||||
full_snapshot_slot,
|
full_snapshot_slot,
|
||||||
incremental_snapshot_archive_info.path().display(),
|
incremental_snapshot_archive_info.path().display(),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
let full_snapshot_archive_info =
|
let full_snapshot_archive_info =
|
||||||
snapshot_utils::bank_to_full_snapshot_archive(
|
snapshot_utils::bank_to_full_snapshot_archive(
|
||||||
|
|
|
@ -17,7 +17,7 @@ use {
|
||||||
snapshot_package::AccountsPackageSender,
|
snapshot_package::AccountsPackageSender,
|
||||||
snapshot_utils,
|
snapshot_utils,
|
||||||
},
|
},
|
||||||
solana_sdk::{clock::Slot, genesis_config::GenesisConfig},
|
solana_sdk::genesis_config::GenesisConfig,
|
||||||
std::{fs, path::PathBuf, process, result},
|
std::{fs, path::PathBuf, process, result},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -25,13 +25,12 @@ pub type LoadResult = result::Result<
|
||||||
(
|
(
|
||||||
BankForks,
|
BankForks,
|
||||||
LeaderScheduleCache,
|
LeaderScheduleCache,
|
||||||
Option<Slot>,
|
|
||||||
Option<StartingSnapshotHashes>,
|
Option<StartingSnapshotHashes>,
|
||||||
),
|
),
|
||||||
BlockstoreProcessorError,
|
BlockstoreProcessorError,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
/// Load the banks and accounts
|
/// Load the banks via genesis or a snapshot then processes all full blocks in blockstore
|
||||||
///
|
///
|
||||||
/// If a snapshot config is given, and a snapshot is found, it will be loaded. Otherwise, load
|
/// If a snapshot config is given, and a snapshot is found, it will be loaded. Otherwise, load
|
||||||
/// from genesis.
|
/// from genesis.
|
||||||
|
@ -48,6 +47,42 @@ pub fn load(
|
||||||
accounts_package_sender: AccountsPackageSender,
|
accounts_package_sender: AccountsPackageSender,
|
||||||
accounts_update_notifier: Option<AccountsUpdateNotifier>,
|
accounts_update_notifier: Option<AccountsUpdateNotifier>,
|
||||||
) -> LoadResult {
|
) -> LoadResult {
|
||||||
|
let (bank_forks, starting_snapshot_hashes) = load_bank_forks(
|
||||||
|
genesis_config,
|
||||||
|
blockstore,
|
||||||
|
account_paths,
|
||||||
|
shrink_paths,
|
||||||
|
snapshot_config,
|
||||||
|
&process_options,
|
||||||
|
cache_block_meta_sender,
|
||||||
|
accounts_update_notifier,
|
||||||
|
);
|
||||||
|
|
||||||
|
blockstore_processor::process_blockstore_from_root(
|
||||||
|
blockstore,
|
||||||
|
bank_forks,
|
||||||
|
&process_options,
|
||||||
|
transaction_status_sender,
|
||||||
|
cache_block_meta_sender,
|
||||||
|
snapshot_config,
|
||||||
|
accounts_package_sender,
|
||||||
|
)
|
||||||
|
.map(|(bank_forks, leader_schedule_cache, ..)| {
|
||||||
|
(bank_forks, leader_schedule_cache, starting_snapshot_hashes)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
pub fn load_bank_forks(
|
||||||
|
genesis_config: &GenesisConfig,
|
||||||
|
blockstore: &Blockstore,
|
||||||
|
account_paths: Vec<PathBuf>,
|
||||||
|
shrink_paths: Option<Vec<PathBuf>>,
|
||||||
|
snapshot_config: Option<&SnapshotConfig>,
|
||||||
|
process_options: &ProcessOptions,
|
||||||
|
cache_block_meta_sender: Option<&CacheBlockMetaSender>,
|
||||||
|
accounts_update_notifier: Option<AccountsUpdateNotifier>,
|
||||||
|
) -> (BankForks, Option<StartingSnapshotHashes>) {
|
||||||
let snapshot_present = if let Some(snapshot_config) = snapshot_config {
|
let snapshot_present = if let Some(snapshot_config) = snapshot_config {
|
||||||
info!(
|
info!(
|
||||||
"Initializing bank snapshot path: {}",
|
"Initializing bank snapshot path: {}",
|
||||||
|
@ -72,13 +107,13 @@ pub fn load(
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
|
|
||||||
let (bank_forks, starting_snapshot_hashes) = if snapshot_present {
|
if snapshot_present {
|
||||||
bank_forks_from_snapshot(
|
bank_forks_from_snapshot(
|
||||||
genesis_config,
|
genesis_config,
|
||||||
account_paths,
|
account_paths,
|
||||||
shrink_paths,
|
shrink_paths,
|
||||||
snapshot_config.as_ref().unwrap(),
|
snapshot_config.as_ref().unwrap(),
|
||||||
&process_options,
|
process_options,
|
||||||
accounts_update_notifier,
|
accounts_update_notifier,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
@ -98,35 +133,13 @@ pub fn load(
|
||||||
genesis_config,
|
genesis_config,
|
||||||
blockstore,
|
blockstore,
|
||||||
account_paths,
|
account_paths,
|
||||||
&process_options,
|
process_options,
|
||||||
cache_block_meta_sender,
|
cache_block_meta_sender,
|
||||||
accounts_update_notifier,
|
accounts_update_notifier,
|
||||||
),
|
),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
};
|
}
|
||||||
|
|
||||||
blockstore_processor::process_blockstore_from_root(
|
|
||||||
blockstore,
|
|
||||||
bank_forks,
|
|
||||||
&process_options,
|
|
||||||
transaction_status_sender,
|
|
||||||
cache_block_meta_sender,
|
|
||||||
snapshot_config,
|
|
||||||
accounts_package_sender,
|
|
||||||
)
|
|
||||||
.map(
|
|
||||||
|(bank_forks, leader_schedule_cache, last_full_snapshot_slot)| {
|
|
||||||
let last_full_snapshot_slot =
|
|
||||||
last_full_snapshot_slot.or_else(|| starting_snapshot_hashes.map(|x| x.full.hash.0));
|
|
||||||
(
|
|
||||||
bank_forks,
|
|
||||||
leader_schedule_cache,
|
|
||||||
last_full_snapshot_slot,
|
|
||||||
starting_snapshot_hashes,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
|
|
@ -630,7 +630,7 @@ pub(crate) fn process_blockstore_for_bank_0(
|
||||||
|
|
||||||
/// Process blockstore from a known root bank
|
/// Process blockstore from a known root bank
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub(crate) fn process_blockstore_from_root(
|
pub fn process_blockstore_from_root(
|
||||||
blockstore: &Blockstore,
|
blockstore: &Blockstore,
|
||||||
mut bank_forks: BankForks,
|
mut bank_forks: BankForks,
|
||||||
opts: &ProcessOptions,
|
opts: &ProcessOptions,
|
||||||
|
@ -3170,7 +3170,6 @@ pub mod tests {
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
accounts_package_sender,
|
accounts_package_sender,
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -3278,7 +3277,6 @@ pub mod tests {
|
||||||
None,
|
None,
|
||||||
Some(&snapshot_config),
|
Some(&snapshot_config),
|
||||||
accounts_package_sender.clone(),
|
accounts_package_sender.clone(),
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue