Add solana-test-validator --warp-slot argument

This commit is contained in:
Michael Vines
2021-01-21 18:34:51 -08:00
parent dd5a2ef05f
commit bf1943e489
12 changed files with 147 additions and 24 deletions

View File

@ -158,7 +158,7 @@ mod tests {
let output_tar_path = snapshot_utils::get_snapshot_archive_path(
&snapshot_package_output_path,
&(42, Hash::default()),
&ArchiveFormat::TarBzip2,
ArchiveFormat::TarBzip2,
);
let snapshot_package = AccountsPackage::new(
5,

View File

@ -14,7 +14,7 @@ use {
},
solana_sdk::{
account::Account,
clock::DEFAULT_MS_PER_SLOT,
clock::{Slot, DEFAULT_MS_PER_SLOT},
commitment_config::CommitmentConfig,
fee_calculator::{FeeCalculator, FeeRateGovernor},
hash::Hash,
@ -48,6 +48,7 @@ pub struct TestValidatorGenesis {
rent: Rent,
rpc_config: JsonRpcConfig,
rpc_ports: Option<(u16, u16)>, // (JsonRpc, JsonRpcPubSub), None == random ports
warp_slot: Option<Slot>,
accounts: HashMap<Pubkey, Account>,
programs: Vec<ProgramInfo>,
}
@ -78,6 +79,11 @@ impl TestValidatorGenesis {
self
}
pub fn warp_slot(&mut self, warp_slot: Slot) -> &mut Self {
self.warp_slot = Some(warp_slot);
self
}
/// Add an account to the test environment
pub fn add_account(&mut self, address: Pubkey, account: Account) -> &mut Self {
self.accounts.insert(address, account);
@ -99,9 +105,10 @@ impl TestValidatorGenesis {
T: IntoIterator<Item = Pubkey>,
{
for address in addresses {
info!("Fetching {}...", address);
info!("Fetching {} over RPC...", address);
let account = rpc_client.get_account(&address).unwrap_or_else(|err| {
panic!("Failed to fetch {}: {}", address, err);
error!("Failed to fetch {}: {}", address, err);
crate::validator::abort();
});
self.add_account(address, account);
}
@ -280,7 +287,7 @@ impl TestValidator {
);
}
let genesis_config = create_genesis_config_with_leader_ex(
let mut genesis_config = create_genesis_config_with_leader_ex(
mint_lamports,
&mint_address,
&validator_identity.pubkey(),
@ -293,6 +300,7 @@ impl TestValidator {
solana_sdk::genesis_config::ClusterType::Development,
accounts.into_iter().collect(),
);
genesis_config.epoch_schedule = solana_sdk::epoch_schedule::EpochSchedule::without_warmup();
let ledger_path = match &config.ledger_path {
None => create_new_tmp_ledger!(&genesis_config).0,
@ -385,6 +393,7 @@ impl TestValidator {
snapshot_version: SnapshotVersion::default(),
}),
enforce_ulimit_nofile: false,
warp_slot: config.warp_slot,
..ValidatorConfig::default()
};

View File

@ -120,6 +120,7 @@ pub struct ValidatorConfig {
pub poh_pinned_cpu_core: usize,
pub account_indexes: HashSet<AccountIndex>,
pub accounts_db_caching_enabled: bool,
pub warp_slot: Option<Slot>,
}
impl Default for ValidatorConfig {
@ -166,6 +167,7 @@ impl Default for ValidatorConfig {
poh_pinned_cpu_core: poh_service::DEFAULT_PINNED_CPU_CORE,
account_indexes: HashSet::new(),
accounts_db_caching_enabled: false,
warp_slot: None,
}
}
}
@ -223,9 +225,14 @@ pub struct Validator {
}
// in the distant future, get rid of ::new()/exit() and use Result properly...
fn abort() -> ! {
pub(crate) fn abort() -> ! {
#[cfg(not(test))]
std::process::exit(1);
{
// standard error is usually redirected to a log file, cry for help on standard output as
// well
println!("Validator process aborted. The validator log may contain further details");
std::process::exit(1);
}
#[cfg(test)]
panic!("process::exit(1) is intercepted for friendly test failure...");
@ -848,6 +855,13 @@ fn post_process_restored_tower(
}
}
if let Some(warp_slot) = config.warp_slot {
// unconditionally relax tower requirement so that we can always restore tower
// from root bank after the warp
should_require_tower = false;
return Err(crate::consensus::TowerError::HardFork(warp_slot));
}
tower
})
.unwrap_or_else(|err| {
@ -991,6 +1005,50 @@ fn new_banks_from_ledger(
abort()
});
if let Some(warp_slot) = config.warp_slot {
let snapshot_config = config.snapshot_config.as_ref().unwrap_or_else(|| {
error!("warp slot requires a snapshot config");
abort();
});
let working_bank = bank_forks.working_bank();
if warp_slot <= working_bank.slot() {
error!(
"warp slot ({}) cannot be less than the working bank slot ({})",
warp_slot,
working_bank.slot()
);
abort();
}
info!("warping to slot {}", warp_slot);
bank_forks.insert(Bank::warp_from_parent(
&bank_forks.root_bank(),
&Pubkey::default(),
warp_slot,
));
bank_forks.set_root(
warp_slot,
&solana_runtime::accounts_background_service::ABSRequestSender::default(),
Some(warp_slot),
);
leader_schedule_cache.set_root(&bank_forks.root_bank());
let archive_file = solana_runtime::snapshot_utils::bank_to_snapshot_archive(
ledger_path,
&bank_forks.root_bank(),
None,
&snapshot_config.snapshot_package_output_path,
snapshot_config.archive_format,
)
.unwrap_or_else(|err| {
error!("Unable to create snapshot: {}", err);
abort();
});
info!("created snapshot: {}", archive_file.display());
}
let tower = post_process_restored_tower(
restored_tower,
&validator_identity,