2019-11-04 19:10:06 -07:00
|
|
|
use crate::{
|
|
|
|
bank_forks::{BankForks, SnapshotConfig},
|
|
|
|
blocktree::Blocktree,
|
|
|
|
blocktree_processor::{self, BankForksInfo, BlocktreeProcessorError, ProcessOptions},
|
|
|
|
leader_schedule_cache::LeaderScheduleCache,
|
|
|
|
snapshot_utils,
|
|
|
|
};
|
|
|
|
use log::*;
|
2019-11-08 23:56:57 -05:00
|
|
|
use solana_sdk::genesis_config::GenesisConfig;
|
2019-12-05 21:41:29 -05:00
|
|
|
use std::{fs, path::PathBuf, sync::Arc};
|
2019-11-04 19:10:06 -07:00
|
|
|
|
|
|
|
pub fn load(
|
2019-11-08 23:56:57 -05:00
|
|
|
genesis_config: &GenesisConfig,
|
2019-11-04 19:10:06 -07:00
|
|
|
blocktree: &Blocktree,
|
2019-12-05 21:41:29 -05:00
|
|
|
account_paths: Vec<PathBuf>,
|
2019-11-04 19:10:06 -07:00
|
|
|
snapshot_config: Option<&SnapshotConfig>,
|
|
|
|
process_options: ProcessOptions,
|
|
|
|
) -> Result<(BankForks, Vec<BankForksInfo>, LeaderScheduleCache), BlocktreeProcessorError> {
|
|
|
|
if let Some(snapshot_config) = snapshot_config.as_ref() {
|
|
|
|
info!(
|
|
|
|
"Initializing snapshot path: {:?}",
|
|
|
|
snapshot_config.snapshot_path
|
|
|
|
);
|
|
|
|
let _ = fs::remove_dir_all(&snapshot_config.snapshot_path);
|
|
|
|
fs::create_dir_all(&snapshot_config.snapshot_path)
|
|
|
|
.expect("Couldn't create snapshot directory");
|
|
|
|
|
|
|
|
let tar =
|
|
|
|
snapshot_utils::get_snapshot_tar_path(&snapshot_config.snapshot_package_output_path);
|
|
|
|
if tar.exists() {
|
|
|
|
info!("Loading snapshot package: {:?}", tar);
|
|
|
|
// Fail hard here if snapshot fails to load, don't silently continue
|
2019-12-05 21:41:29 -05:00
|
|
|
|
|
|
|
if account_paths.is_empty() {
|
|
|
|
panic!("Account paths not present when booting from snapshot")
|
|
|
|
}
|
|
|
|
|
2019-11-04 19:10:06 -07:00
|
|
|
let deserialized_bank = snapshot_utils::bank_from_archive(
|
2019-12-05 21:41:29 -05:00
|
|
|
&account_paths,
|
2019-11-04 19:10:06 -07:00
|
|
|
&snapshot_config.snapshot_path,
|
|
|
|
&tar,
|
|
|
|
)
|
|
|
|
.expect("Load from snapshot failed");
|
|
|
|
|
|
|
|
return blocktree_processor::process_blocktree_from_root(
|
2019-11-08 23:56:57 -05:00
|
|
|
genesis_config,
|
2019-11-04 19:10:06 -07:00
|
|
|
blocktree,
|
|
|
|
Arc::new(deserialized_bank),
|
|
|
|
&process_options,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
info!("Snapshot package does not exist: {:?}", tar);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
info!("Snapshots disabled");
|
|
|
|
}
|
|
|
|
|
|
|
|
info!("Processing ledger from genesis");
|
|
|
|
blocktree_processor::process_blocktree(
|
2019-11-08 23:56:57 -05:00
|
|
|
&genesis_config,
|
2019-11-04 19:10:06 -07:00
|
|
|
&blocktree,
|
|
|
|
account_paths,
|
|
|
|
process_options,
|
|
|
|
)
|
|
|
|
}
|