From 4aeb566c856cf904456cf31b20eef07c40e4be15 Mon Sep 17 00:00:00 2001 From: hanako mumei <81144685+2501babe@users.noreply.github.com> Date: Mon, 25 Apr 2022 15:24:43 -0700 Subject: [PATCH] Add maybe clone flag to solana-test-validator add --maybe-clone, which silently ignores accounts to be cloned, rather than dying --- test-validator/src/lib.rs | 19 ++++++++++---- validator/src/bin/solana-test-validator.rs | 29 ++++++++++++++++++++++ 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/test-validator/src/lib.rs b/test-validator/src/lib.rs index 13e0d3895d..1e34d1a507 100644 --- a/test-validator/src/lib.rs +++ b/test-validator/src/lib.rs @@ -260,17 +260,26 @@ impl TestValidatorGenesis { self } - pub fn clone_accounts(&mut self, addresses: T, rpc_client: &RpcClient) -> &mut Self + pub fn clone_accounts( + &mut self, + addresses: T, + rpc_client: &RpcClient, + skip_missing: bool, + ) -> &mut Self where T: IntoIterator, { for address in addresses { info!("Fetching {} over RPC...", address); - let account = rpc_client.get_account(&address).unwrap_or_else(|err| { - error!("Failed to fetch {}: {}", address, err); + let res = rpc_client.get_account(&address); + if let Ok(account) = res { + self.add_account(address, AccountSharedData::from(account)); + } else if skip_missing { + warn!("Could not find {}, skipping.", address); + } else { + error!("Failed to fetch {}: {}", address, res.unwrap_err()); solana_core::validator::abort(); - }); - self.add_account(address, AccountSharedData::from(account)); + } } self } diff --git a/validator/src/bin/solana-test-validator.rs b/validator/src/bin/solana-test-validator.rs index 3dd6ff63f3..66e455faa9 100644 --- a/validator/src/bin/solana-test-validator.rs +++ b/validator/src/bin/solana-test-validator.rs @@ -296,6 +296,20 @@ fn main() { If the ledger already exists then this parameter is silently ignored", ), ) + .arg( + Arg::with_name("maybe_clone_account") + .long("maybe-clone") + .value_name("ADDRESS") + .takes_value(true) + .validator(is_pubkey_or_keypair) + .multiple(true) + .requires("json_rpc_url") + .help( + "Copy an account from the cluster referenced by the --url argument, \ + skipping it if it doesn't exist. \ + If the ledger already exists then this parameter is silently ignored", + ), + ) .arg( Arg::with_name("warp_slot") .required(false) @@ -533,6 +547,10 @@ fn main() { .map(|v| v.into_iter().collect()) .unwrap_or_default(); + let accounts_to_maybe_clone: HashSet<_> = pubkeys_of(&matches, "maybe_clone_account") + .map(|v| v.into_iter().collect()) + .unwrap_or_default(); + let warp_slot = if matches.is_present("warp_slot") { Some(match matches.value_of("warp_slot") { Some(_) => value_t_or_exit!(matches, "warp_slot", Slot), @@ -687,6 +705,17 @@ fn main() { cluster_rpc_client .as_ref() .expect("bug: --url argument missing?"), + false, + ); + } + + if !accounts_to_maybe_clone.is_empty() { + genesis.clone_accounts( + accounts_to_maybe_clone, + cluster_rpc_client + .as_ref() + .expect("bug: --url argument missing?"), + true, ); }