Add --warp-slot argument to |solana-ledger-tool create-snapshot| (#10473)

automerge
This commit is contained in:
mergify[bot]
2020-06-09 11:09:32 -07:00
committed by GitHub
parent a705764ca7
commit 7d448eb1a9
3 changed files with 51 additions and 5 deletions

View File

@ -14,6 +14,7 @@ use solana_ledger::{
rooted_slot_iterator::RootedSlotIterator, rooted_slot_iterator::RootedSlotIterator,
snapshot_utils, snapshot_utils,
}; };
use solana_runtime::bank::Bank;
use solana_sdk::{ use solana_sdk::{
clock::Slot, genesis_config::GenesisConfig, native_token::lamports_to_sol, pubkey::Pubkey, clock::Slot, genesis_config::GenesisConfig, native_token::lamports_to_sol, pubkey::Pubkey,
shred_version::compute_shred_version, shred_version::compute_shred_version,
@ -28,6 +29,7 @@ use std::{
path::{Path, PathBuf}, path::{Path, PathBuf},
process::{exit, Command, Stdio}, process::{exit, Command, Stdio},
str::FromStr, str::FromStr,
sync::Arc,
}; };
use log::*; use log::*;
@ -754,6 +756,17 @@ fn main() {
.takes_value(true) .takes_value(true)
.help("Output directory for the snapshot"), .help("Output directory for the snapshot"),
) )
.arg(
Arg::with_name("warp_slot")
.required(false)
.long("warp-slot")
.takes_value(true)
.value_name("WARP_SLOT")
.validator(is_slot)
.help("After loading the snapshot slot warp the ledger to WARP_SLOT, \
which could be a slot in a galaxy far far away"),
)
).subcommand( ).subcommand(
SubCommand::with_name("accounts") SubCommand::with_name("accounts")
.about("Print account contents after processing in the ledger") .about("Print account contents after processing in the ledger")
@ -990,6 +1003,7 @@ fn main() {
("create-snapshot", Some(arg_matches)) => { ("create-snapshot", Some(arg_matches)) => {
let snapshot_slot = value_t_or_exit!(arg_matches, "snapshot_slot", Slot); let snapshot_slot = value_t_or_exit!(arg_matches, "snapshot_slot", Slot);
let output_directory = value_t_or_exit!(arg_matches, "output_directory", String); let output_directory = value_t_or_exit!(arg_matches, "output_directory", String);
let warp_slot = value_t!(arg_matches, "warp_slot", Slot).ok();
let process_options = ProcessOptions { let process_options = ProcessOptions {
dev_halt_at_slot: Some(snapshot_slot), dev_halt_at_slot: Some(snapshot_slot),
@ -1006,12 +1020,26 @@ fn main() {
AccessType::TryPrimaryThenSecondary, AccessType::TryPrimaryThenSecondary,
) { ) {
Ok((bank_forks, _bank_forks_info, _leader_schedule_cache, _snapshot_hash)) => { Ok((bank_forks, _bank_forks_info, _leader_schedule_cache, _snapshot_hash)) => {
let bank = bank_forks.get(snapshot_slot).unwrap_or_else(|| { let bank = bank_forks
eprintln!("Error: Slot {} is not available", snapshot_slot); .get(snapshot_slot)
exit(1); .unwrap_or_else(|| {
}); eprintln!("Error: Slot {} is not available", snapshot_slot);
exit(1);
})
.clone();
let bank = if let Some(warp_slot) = warp_slot {
Arc::new(Bank::warp_from_parent(
&bank,
bank.collector_id(),
warp_slot,
))
} else {
bank
};
println!("Creating a snapshot of slot {}", bank.slot()); println!("Creating a snapshot of slot {}", bank.slot());
assert!(bank.is_complete());
bank.squash(); bank.squash();
let temp_dir = tempfile::TempDir::new().unwrap_or_else(|err| { let temp_dir = tempfile::TempDir::new().unwrap_or_else(|err| {
@ -1035,7 +1063,8 @@ fn main() {
snapshot_utils::archive_snapshot_package(&package).map(|ok| { snapshot_utils::archive_snapshot_package(&package).map(|ok| {
println!( println!(
"Successfully created snapshot for slot {}: {:?}", "Successfully created snapshot for slot {}: {:?}",
snapshot_slot, package.tar_output_file bank.slot(),
package.tar_output_file
); );
println!( println!(
"Shred version: {}", "Shred version: {}",

View File

@ -33,6 +33,9 @@ while [[ -n $1 ]]; do
elif [[ $1 = --gossip-port ]]; then elif [[ $1 = --gossip-port ]]; then
args+=("$1" "$2") args+=("$1" "$2")
shift 2 shift 2
elif [[ $1 = --dev-halt-at-slot ]]; then
args+=("$1" "$2")
shift 2
elif [[ $1 = --dynamic-port-range ]]; then elif [[ $1 = --dynamic-port-range ]]; then
args+=("$1" "$2") args+=("$1" "$2")
shift 2 shift 2

View File

@ -536,6 +536,20 @@ impl Bank {
new new
} }
/// Like `new_from_parent` but additionally:
/// * Doesn't assume that the parent is anywhere near `slot`, parent could be millions of slots
/// in the past
/// * Adjusts the new bank's tick height to avoid having to run PoH for millions of slots
/// * Freezes the new bank, assuming that the user will `Bank::new_from_parent` from this bank
pub fn warp_from_parent(parent: &Arc<Bank>, collector_id: &Pubkey, slot: Slot) -> Self {
let mut new = Bank::new_from_parent(parent, collector_id, slot);
new.update_epoch_stakes(new.epoch_schedule().get_epoch(slot));
new.tick_height
.store(new.max_tick_height(), Ordering::Relaxed);
new.freeze();
new
}
pub fn collector_id(&self) -> &Pubkey { pub fn collector_id(&self) -> &Pubkey {
&self.collector_id &self.collector_id
} }