2019-11-04 19:10:06 -07:00
|
|
|
use crate::{
|
2020-02-20 19:53:26 -07:00
|
|
|
bank_forks::{BankForks, SnapshotConfig},
|
2020-01-13 14:13:52 -07:00
|
|
|
blockstore::Blockstore,
|
2020-02-20 19:53:26 -07:00
|
|
|
blockstore_processor::{
|
|
|
|
self, BankForksInfo, BlockstoreProcessorError, BlockstoreProcessorResult, ProcessOptions,
|
|
|
|
},
|
2020-01-15 09:15:26 +08:00
|
|
|
entry::VerifyRecyclers,
|
2020-02-20 19:53:26 -07:00
|
|
|
leader_schedule_cache::LeaderScheduleCache,
|
2019-11-04 19:10:06 -07:00
|
|
|
snapshot_utils,
|
|
|
|
};
|
|
|
|
use log::*;
|
2020-02-20 19:53:26 -07:00
|
|
|
use solana_sdk::{clock::Slot, genesis_config::GenesisConfig, hash::Hash};
|
|
|
|
use std::{fs, path::PathBuf, result, sync::Arc};
|
|
|
|
|
|
|
|
pub type LoadResult = result::Result<
|
|
|
|
(
|
|
|
|
BankForks,
|
|
|
|
Vec<BankForksInfo>,
|
|
|
|
LeaderScheduleCache,
|
|
|
|
Option<(Slot, Hash)>,
|
|
|
|
),
|
|
|
|
BlockstoreProcessorError,
|
|
|
|
>;
|
|
|
|
|
|
|
|
fn to_loadresult(
|
|
|
|
brp: BlockstoreProcessorResult,
|
|
|
|
snapshot_hash: Option<(Slot, Hash)>,
|
|
|
|
) -> LoadResult {
|
|
|
|
brp.map(|(bank_forks, bank_forks_info, leader_schedule_cache)| {
|
|
|
|
(
|
|
|
|
bank_forks,
|
|
|
|
bank_forks_info,
|
|
|
|
leader_schedule_cache,
|
|
|
|
snapshot_hash,
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
2019-11-04 19:10:06 -07:00
|
|
|
|
|
|
|
pub fn load(
|
2019-11-08 23:56:57 -05:00
|
|
|
genesis_config: &GenesisConfig,
|
2020-01-13 14:13:52 -07:00
|
|
|
blockstore: &Blockstore,
|
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,
|
2020-02-20 19:53:26 -07:00
|
|
|
) -> LoadResult {
|
2019-11-04 19:10:06 -07:00
|
|
|
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");
|
|
|
|
|
2020-01-23 11:22:37 -07:00
|
|
|
let tar = snapshot_utils::get_snapshot_archive_path(
|
|
|
|
&snapshot_config.snapshot_package_output_path,
|
|
|
|
);
|
2019-11-04 19:10:06 -07:00
|
|
|
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");
|
|
|
|
|
2020-02-24 10:23:47 -08:00
|
|
|
let snapshot_hash = (
|
|
|
|
deserialized_bank.slot(),
|
|
|
|
deserialized_bank.get_accounts_hash(),
|
|
|
|
);
|
2020-02-20 19:53:26 -07:00
|
|
|
return to_loadresult(
|
|
|
|
blockstore_processor::process_blockstore_from_root(
|
|
|
|
genesis_config,
|
|
|
|
blockstore,
|
|
|
|
Arc::new(deserialized_bank),
|
|
|
|
&process_options,
|
|
|
|
&VerifyRecyclers::default(),
|
|
|
|
),
|
|
|
|
Some(snapshot_hash),
|
2019-11-04 19:10:06 -07:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
info!("Snapshot package does not exist: {:?}", tar);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
info!("Snapshots disabled");
|
|
|
|
}
|
|
|
|
|
|
|
|
info!("Processing ledger from genesis");
|
2020-02-20 19:53:26 -07:00
|
|
|
to_loadresult(
|
|
|
|
blockstore_processor::process_blockstore(
|
|
|
|
&genesis_config,
|
|
|
|
&blockstore,
|
|
|
|
account_paths,
|
|
|
|
process_options,
|
|
|
|
),
|
|
|
|
None,
|
2019-11-04 19:10:06 -07:00
|
|
|
)
|
|
|
|
}
|