Use rooted bank by default in rpc bank selection (#6759)

* Name anonymous parameters for clarity

* Add CommitmentConfig to select bank for rpc

* Add commitment information to jsonrpc docs

* Update send_and_confirm retries as per commitment defaults

* Pass CommitmentConfig into client requests; also various 'use' cleanup

* Use _with_commitment methods to speed local_cluster tests

* Pass CommitmentConfig into Archiver in order to enable quick confirmations in local_cluster tests

* Restore solana ping speed

* Increase wallet-sanity timeout to account for longer confirmation time
This commit is contained in:
Tyera Eulberg
2019-11-06 14:15:00 -07:00
committed by GitHub
parent 5e8668799c
commit b3a75a60a4
27 changed files with 1225 additions and 463 deletions

View File

@@ -1,9 +1,9 @@
use rand::{thread_rng, Rng};
use solana_client::thin_client::create_client;
/// Cluster independant integration tests
///
/// All tests must start from an entry point and a funding keypair and
/// discover the rest of the network.
use rand::{thread_rng, Rng};
use solana_client::thin_client::create_client;
use solana_core::{
cluster_info::VALIDATOR_PORT_RANGE, consensus::VOTE_THRESHOLD_DEPTH, contact_info::ContactInfo,
gossip_service::discover_cluster,
@@ -15,6 +15,7 @@ use solana_ledger::{
use solana_sdk::{
client::SyncClient,
clock::{Slot, DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT, NUM_CONSECUTIVE_LEADER_SLOTS},
commitment_config::CommitmentConfig,
epoch_schedule::MINIMUM_SLOTS_PER_EPOCH,
hash::Hash,
poh_config::PohConfig,
@@ -49,10 +50,12 @@ pub fn spend_and_verify_all_nodes<S: ::std::hash::BuildHasher>(
let random_keypair = Keypair::new();
let client = create_client(ingress_node.client_facing_addr(), VALIDATOR_PORT_RANGE);
let bal = client
.poll_get_balance(&funding_keypair.pubkey())
.poll_get_balance_with_commitment(&funding_keypair.pubkey(), CommitmentConfig::recent())
.expect("balance in source");
assert!(bal > 0);
let (blockhash, _fee_calculator) = client.get_recent_blockhash().unwrap();
let (blockhash, _fee_calculator) = client
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
.unwrap();
let mut transaction =
system_transaction::transfer(&funding_keypair, &random_keypair.pubkey(), 1, blockhash);
let confs = VOTE_THRESHOLD_DEPTH + 1;
@@ -75,7 +78,9 @@ pub fn verify_balances<S: ::std::hash::BuildHasher>(
) {
let client = create_client(node.client_facing_addr(), VALIDATOR_PORT_RANGE);
for (pk, b) in expected_balances {
let bal = client.poll_get_balance(&pk).expect("balance in source");
let bal = client
.poll_get_balance_with_commitment(&pk, CommitmentConfig::recent())
.expect("balance in source");
assert_eq!(bal, b);
}
}
@@ -91,10 +96,12 @@ pub fn send_many_transactions(
for _ in 0..num_txs {
let random_keypair = Keypair::new();
let bal = client
.poll_get_balance(&funding_keypair.pubkey())
.poll_get_balance_with_commitment(&funding_keypair.pubkey(), CommitmentConfig::recent())
.expect("balance in source");
assert!(bal > 0);
let (blockhash, _fee_calculator) = client.get_recent_blockhash().unwrap();
let (blockhash, _fee_calculator) = client
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
.unwrap();
let transfer_amount = thread_rng().gen_range(1, max_tokens_per_transfer);
let mut transaction = system_transaction::transfer(
@@ -188,7 +195,7 @@ pub fn kill_entry_and_spend_and_verify_rest(
for ingress_node in &cluster_nodes {
client
.poll_get_balance(&ingress_node.id)
.poll_get_balance_with_commitment(&ingress_node.id, CommitmentConfig::recent())
.unwrap_or_else(|err| panic!("Node {} has no balance: {}", ingress_node.id, err));
}
@@ -212,7 +219,7 @@ pub fn kill_entry_and_spend_and_verify_rest(
let client = create_client(ingress_node.client_facing_addr(), VALIDATOR_PORT_RANGE);
let balance = client
.poll_get_balance(&funding_keypair.pubkey())
.poll_get_balance_with_commitment(&funding_keypair.pubkey(), CommitmentConfig::recent())
.expect("balance in source");
assert_ne!(balance, 0);
@@ -225,7 +232,9 @@ pub fn kill_entry_and_spend_and_verify_rest(
}
let random_keypair = Keypair::new();
let (blockhash, _fee_calculator) = client.get_recent_blockhash().unwrap();
let (blockhash, _fee_calculator) = client
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
.unwrap();
let mut transaction = system_transaction::transfer(
&funding_keypair,
&random_keypair.pubkey(),

View File

@@ -13,6 +13,7 @@ use solana_ledger::blocktree::create_new_tmp_ledger;
use solana_sdk::{
client::SyncClient,
clock::{DEFAULT_SLOTS_PER_EPOCH, DEFAULT_SLOTS_PER_SEGMENT, DEFAULT_TICKS_PER_SLOT},
commitment_config::CommitmentConfig,
epoch_schedule::EpochSchedule,
genesis_block::{GenesisBlock, OperatingMode},
message::Message,
@@ -386,6 +387,7 @@ impl LocalCluster {
self.entry_point_info.clone(),
archiver_keypair,
storage_keypair,
CommitmentConfig::recent(),
)
.unwrap_or_else(|err| panic!("Archiver::new() failed: {:?}", err));
@@ -424,7 +426,9 @@ impl LocalCluster {
lamports: u64,
) -> u64 {
trace!("getting leader blockhash");
let (blockhash, _fee_calculator) = client.get_recent_blockhash().unwrap();
let (blockhash, _fee_calculator) = client
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
.unwrap();
let mut tx =
system_transaction::transfer(&source_keypair, dest_pubkey, lamports, blockhash);
info!(
@@ -437,7 +441,11 @@ impl LocalCluster {
.retry_transfer(&source_keypair, &mut tx, 10)
.expect("client transfer");
client
.wait_for_balance(dest_pubkey, Some(lamports))
.wait_for_balance_with_commitment(
dest_pubkey,
Some(lamports),
CommitmentConfig::recent(),
)
.expect("get balance")
}
@@ -453,7 +461,11 @@ impl LocalCluster {
let stake_account_pubkey = stake_account_keypair.pubkey();
// Create the vote account if necessary
if client.poll_get_balance(&vote_account_pubkey).unwrap_or(0) == 0 {
if client
.poll_get_balance_with_commitment(&vote_account_pubkey, CommitmentConfig::recent())
.unwrap_or(0)
== 0
{
// 1) Create vote account
let mut transaction = Transaction::new_signed_instructions(
@@ -469,13 +481,20 @@ impl LocalCluster {
},
amount,
),
client.get_recent_blockhash().unwrap().0,
client
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
.unwrap()
.0,
);
client
.retry_transfer(&from_account, &mut transaction, 10)
.expect("fund vote");
client
.wait_for_balance(&vote_account_pubkey, Some(amount))
.wait_for_balance_with_commitment(
&vote_account_pubkey,
Some(amount),
CommitmentConfig::recent(),
)
.expect("get balance");
let mut transaction = Transaction::new_signed_instructions(
@@ -487,7 +506,10 @@ impl LocalCluster {
&StakeAuthorized::auto(&stake_account_pubkey),
amount,
),
client.get_recent_blockhash().unwrap().0,
client
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
.unwrap()
.0,
);
client
@@ -499,7 +521,11 @@ impl LocalCluster {
)
.expect("delegate stake");
client
.wait_for_balance(&stake_account_pubkey, Some(amount))
.wait_for_balance_with_commitment(
&stake_account_pubkey,
Some(amount),
CommitmentConfig::recent(),
)
.expect("get balance");
} else {
warn!(
@@ -509,8 +535,8 @@ impl LocalCluster {
}
info!("Checking for vote account registration of {}", node_pubkey);
match (
client.get_account(&stake_account_pubkey),
client.get_account(&vote_account_pubkey),
client.get_account_with_commitment(&stake_account_pubkey, CommitmentConfig::recent()),
client.get_account_with_commitment(&vote_account_pubkey, CommitmentConfig::recent()),
) {
(Ok(Some(stake_account)), Ok(Some(vote_account))) => {
match (
@@ -568,7 +594,10 @@ impl LocalCluster {
Some(&from_keypair.pubkey()),
);
let signer_keys = vec![from_keypair.as_ref()];
let blockhash = client.get_recent_blockhash().unwrap().0;
let blockhash = client
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
.unwrap()
.0;
let mut transaction = Transaction::new(&signer_keys, message, blockhash);
client
.retry_transfer(&from_keypair, &mut transaction, 10)

View File

@@ -1,17 +1,24 @@
use crate::local_cluster::{ClusterConfig, LocalCluster};
use serial_test_derive::serial;
use solana_client::thin_client::create_client;
use solana_core::archiver::Archiver;
use solana_core::cluster_info::{ClusterInfo, Node, VALIDATOR_PORT_RANGE};
use solana_core::contact_info::ContactInfo;
use solana_core::gossip_service::discover_cluster;
use solana_core::storage_stage::SLOTS_PER_TURN_TEST;
use solana_core::validator::ValidatorConfig;
use solana_core::{
archiver::Archiver,
cluster_info::{ClusterInfo, Node, VALIDATOR_PORT_RANGE},
contact_info::ContactInfo,
gossip_service::discover_cluster,
storage_stage::SLOTS_PER_TURN_TEST,
validator::ValidatorConfig,
};
use solana_ledger::blocktree::{create_new_tmp_ledger, get_tmp_ledger_path, Blocktree};
use solana_sdk::genesis_block::create_genesis_block;
use solana_sdk::signature::{Keypair, KeypairUtil};
use std::fs::remove_dir_all;
use std::sync::{Arc, RwLock};
use solana_sdk::{
commitment_config::CommitmentConfig,
genesis_block::create_genesis_block,
signature::{Keypair, KeypairUtil},
};
use std::{
fs::remove_dir_all,
sync::{Arc, RwLock},
};
/// Start the cluster with the given configuration and wait till the archivers are discovered
/// Then download blobs from one of them.
@@ -99,6 +106,7 @@ fn test_archiver_startup_leader_hang() {
leader_info,
archiver_keypair,
storage_keypair,
CommitmentConfig::recent(),
);
assert!(archiver_res.is_err());
@@ -134,6 +142,7 @@ fn test_archiver_startup_ledger_hang() {
cluster.entry_point_info.clone(),
bad_keys,
storage_keypair,
CommitmentConfig::recent(),
);
assert!(archiver_res.is_err());
@@ -168,7 +177,10 @@ fn test_account_setup() {
cluster.archiver_infos.iter().for_each(|(_, value)| {
assert_eq!(
client
.poll_get_balance(&value.archiver_storage_pubkey)
.poll_get_balance_with_commitment(
&value.archiver_storage_pubkey,
CommitmentConfig::recent()
)
.unwrap(),
1
);

View File

@@ -15,14 +15,15 @@ use solana_runtime::accounts_db::AccountsDB;
use solana_sdk::{
client::SyncClient,
clock,
commitment_config::CommitmentConfig,
epoch_schedule::{EpochSchedule, MINIMUM_SLOTS_PER_EPOCH},
genesis_block::OperatingMode,
poh_config::PohConfig,
};
use std::path::{Path, PathBuf};
use std::{
collections::{HashMap, HashSet},
fs,
path::{Path, PathBuf},
thread::sleep,
time::Duration,
};
@@ -329,7 +330,12 @@ fn test_softlaunch_operating_mode() {
.iter()
{
assert_eq!(
(program_id, client.get_account(program_id).unwrap()),
(
program_id,
client
.get_account_with_commitment(program_id, CommitmentConfig::recent())
.unwrap()
),
(program_id, None)
);
}
@@ -460,7 +466,7 @@ fn test_snapshots_blocktree_floor() {
let target_slot = slot_floor + 40;
while current_slot <= target_slot {
trace!("current_slot: {}", current_slot);
if let Ok(slot) = validator_client.get_slot() {
if let Ok(slot) = validator_client.get_slot_with_commitment(CommitmentConfig::recent()) {
current_slot = slot;
} else {
continue;
@@ -751,7 +757,7 @@ fn run_repairman_catchup(num_repairmen: u64) {
let target_slot = (num_warmup_epochs) * num_slots_per_epoch + 1;
while current_slot <= target_slot {
trace!("current_slot: {}", current_slot);
if let Ok(slot) = repairee_client.get_slot() {
if let Ok(slot) = repairee_client.get_slot_with_commitment(CommitmentConfig::recent()) {
current_slot = slot;
} else {
continue;
@@ -765,7 +771,9 @@ fn wait_for_next_snapshot<P: AsRef<Path>>(cluster: &LocalCluster, tar: P) {
let client = cluster
.get_validator_client(&cluster.entry_point_info.id)
.unwrap();
let last_slot = client.get_slot().expect("Couldn't get slot");
let last_slot = client
.get_slot_with_commitment(CommitmentConfig::recent())
.expect("Couldn't get slot");
// Wait for a snapshot for a bank >= last_slot to be made so we know that the snapshot
// must include the transactions just pushed