Add maybe clone flag to solana-test-validator
add --maybe-clone, which silently ignores accounts to be cloned, rather than dying
This commit is contained in:
parent
3abd46010c
commit
4aeb566c85
|
@ -260,17 +260,26 @@ impl TestValidatorGenesis {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn clone_accounts<T>(&mut self, addresses: T, rpc_client: &RpcClient) -> &mut Self
|
||||
pub fn clone_accounts<T>(
|
||||
&mut self,
|
||||
addresses: T,
|
||||
rpc_client: &RpcClient,
|
||||
skip_missing: bool,
|
||||
) -> &mut Self
|
||||
where
|
||||
T: IntoIterator<Item = Pubkey>,
|
||||
{
|
||||
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
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue