2019-11-04 18:10:06 -08:00
|
|
|
use crate::{
|
2020-01-13 13:13:52 -08:00
|
|
|
blockstore::Blockstore,
|
2020-02-20 18:53:26 -08:00
|
|
|
blockstore_processor::{
|
2020-05-06 08:24:59 -07:00
|
|
|
self, BlockstoreProcessorError, BlockstoreProcessorResult, ProcessOptions,
|
2020-08-07 11:21:35 -07:00
|
|
|
TransactionStatusSender,
|
2020-02-20 18:53:26 -08:00
|
|
|
},
|
2020-01-14 17:15:26 -08:00
|
|
|
entry::VerifyRecyclers,
|
2020-02-20 18:53:26 -08:00
|
|
|
leader_schedule_cache::LeaderScheduleCache,
|
2019-11-04 18:10:06 -08:00
|
|
|
};
|
|
|
|
use log::*;
|
2020-06-17 08:27:03 -07:00
|
|
|
use solana_runtime::{
|
|
|
|
bank_forks::{BankForks, SnapshotConfig},
|
|
|
|
snapshot_utils,
|
|
|
|
};
|
2020-02-20 18:53:26 -08:00
|
|
|
use solana_sdk::{clock::Slot, genesis_config::GenesisConfig, hash::Hash};
|
2020-09-24 12:23:09 -07:00
|
|
|
use std::{fs, path::PathBuf, process, result};
|
2020-02-20 18:53:26 -08:00
|
|
|
|
|
|
|
pub type LoadResult = result::Result<
|
2020-05-06 08:24:59 -07:00
|
|
|
(BankForks, LeaderScheduleCache, Option<(Slot, Hash)>),
|
2020-02-20 18:53:26 -08:00
|
|
|
BlockstoreProcessorError,
|
|
|
|
>;
|
|
|
|
|
|
|
|
fn to_loadresult(
|
|
|
|
brp: BlockstoreProcessorResult,
|
|
|
|
snapshot_hash: Option<(Slot, Hash)>,
|
|
|
|
) -> LoadResult {
|
2020-05-06 08:24:59 -07:00
|
|
|
brp.map(|(bank_forks, leader_schedule_cache)| {
|
|
|
|
(bank_forks, leader_schedule_cache, snapshot_hash)
|
2020-02-20 18:53:26 -08:00
|
|
|
})
|
|
|
|
}
|
2019-11-04 18:10:06 -08:00
|
|
|
|
|
|
|
pub fn load(
|
2019-11-08 20:56:57 -08:00
|
|
|
genesis_config: &GenesisConfig,
|
2020-01-13 13:13:52 -08:00
|
|
|
blockstore: &Blockstore,
|
2019-12-05 18:41:29 -08:00
|
|
|
account_paths: Vec<PathBuf>,
|
2020-12-21 21:33:37 -08:00
|
|
|
shrink_paths: Option<Vec<PathBuf>>,
|
2019-11-04 18:10:06 -08:00
|
|
|
snapshot_config: Option<&SnapshotConfig>,
|
|
|
|
process_options: ProcessOptions,
|
2020-07-14 20:14:48 -07:00
|
|
|
transaction_status_sender: Option<TransactionStatusSender>,
|
2020-02-20 18:53:26 -08:00
|
|
|
) -> LoadResult {
|
2019-11-04 18:10:06 -08: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-02-24 12:37:14 -08:00
|
|
|
match snapshot_utils::get_highest_snapshot_archive_path(
|
2020-01-23 10:22:37 -08:00
|
|
|
&snapshot_config.snapshot_package_output_path,
|
2020-02-24 12:37:14 -08:00
|
|
|
) {
|
2020-04-03 13:13:49 -07:00
|
|
|
Some((archive_filename, (archive_slot, archive_snapshot_hash, compression))) => {
|
2020-02-26 18:04:18 -08:00
|
|
|
info!("Loading snapshot package: {:?}", archive_filename);
|
|
|
|
// Fail hard here if snapshot fails to load, don't silently continue
|
2019-12-05 18:41:29 -08:00
|
|
|
|
2020-02-26 18:04:18 -08:00
|
|
|
if account_paths.is_empty() {
|
|
|
|
error!("Account paths not present when booting from snapshot");
|
|
|
|
process::exit(1);
|
|
|
|
}
|
2019-12-05 18:41:29 -08:00
|
|
|
|
2020-02-26 18:04:18 -08:00
|
|
|
let deserialized_bank = snapshot_utils::bank_from_archive(
|
|
|
|
&account_paths,
|
2020-03-22 11:10:04 -07:00
|
|
|
&process_options.frozen_accounts,
|
2020-02-26 18:04:18 -08:00
|
|
|
&snapshot_config.snapshot_path,
|
|
|
|
&archive_filename,
|
2020-04-03 13:13:49 -07:00
|
|
|
compression,
|
2020-05-13 00:22:14 -07:00
|
|
|
genesis_config,
|
2020-09-23 18:46:42 -07:00
|
|
|
process_options.debug_keys.clone(),
|
2020-12-15 20:29:09 -08:00
|
|
|
Some(&crate::builtins::get(process_options.bpf_jit)),
|
2020-12-31 18:06:03 -08:00
|
|
|
process_options.account_indexes.clone(),
|
2021-01-11 17:00:23 -08:00
|
|
|
process_options.accounts_db_caching_enabled,
|
2020-02-26 18:04:18 -08:00
|
|
|
)
|
|
|
|
.expect("Load from snapshot failed");
|
2020-12-21 21:33:37 -08:00
|
|
|
if let Some(shrink_paths) = shrink_paths {
|
|
|
|
deserialized_bank.set_shrink_paths(shrink_paths);
|
|
|
|
}
|
2019-11-04 18:10:06 -08:00
|
|
|
|
2020-02-26 18:04:18 -08:00
|
|
|
let deserialized_snapshot_hash = (
|
|
|
|
deserialized_bank.slot(),
|
|
|
|
deserialized_bank.get_accounts_hash(),
|
|
|
|
);
|
|
|
|
|
2020-04-03 13:13:49 -07:00
|
|
|
if deserialized_snapshot_hash != (archive_slot, archive_snapshot_hash) {
|
2020-02-26 18:04:18 -08:00
|
|
|
error!(
|
|
|
|
"Snapshot has mismatch:\narchive: {:?}\ndeserialized: {:?}",
|
|
|
|
archive_snapshot_hash, deserialized_snapshot_hash
|
2020-02-24 12:37:14 -08:00
|
|
|
);
|
2020-02-26 18:04:18 -08:00
|
|
|
process::exit(1);
|
2020-02-24 12:37:14 -08:00
|
|
|
}
|
2020-02-26 18:04:18 -08:00
|
|
|
|
|
|
|
return to_loadresult(
|
|
|
|
blockstore_processor::process_blockstore_from_root(
|
|
|
|
blockstore,
|
2020-09-24 12:23:09 -07:00
|
|
|
deserialized_bank,
|
2020-02-26 18:04:18 -08:00
|
|
|
&process_options,
|
|
|
|
&VerifyRecyclers::default(),
|
2020-07-14 20:14:48 -07:00
|
|
|
transaction_status_sender,
|
2020-02-26 18:04:18 -08:00
|
|
|
),
|
|
|
|
Some(deserialized_snapshot_hash),
|
|
|
|
);
|
2020-02-24 12:37:14 -08:00
|
|
|
}
|
|
|
|
None => info!("No snapshot package available"),
|
2019-11-04 18:10:06 -08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
info!("Snapshots disabled");
|
|
|
|
}
|
|
|
|
|
|
|
|
info!("Processing ledger from genesis");
|
2020-02-20 18:53:26 -08:00
|
|
|
to_loadresult(
|
|
|
|
blockstore_processor::process_blockstore(
|
|
|
|
&genesis_config,
|
|
|
|
&blockstore,
|
|
|
|
account_paths,
|
|
|
|
process_options,
|
|
|
|
),
|
|
|
|
None,
|
2019-11-04 18:10:06 -08:00
|
|
|
)
|
|
|
|
}
|