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:
@ -10,6 +10,7 @@
|
||||
use crate::{
|
||||
account::Account,
|
||||
clock::Slot,
|
||||
commitment_config::CommitmentConfig,
|
||||
fee_calculator::FeeCalculator,
|
||||
hash::Hash,
|
||||
instruction::Instruction,
|
||||
@ -44,24 +45,60 @@ pub trait SyncClient {
|
||||
/// Get an account or None if not found.
|
||||
fn get_account(&self, pubkey: &Pubkey) -> Result<Option<Account>>;
|
||||
|
||||
/// Get an account or None if not found. Uses explicit commitment configuration.
|
||||
fn get_account_with_commitment(
|
||||
&self,
|
||||
pubkey: &Pubkey,
|
||||
commitment_config: CommitmentConfig,
|
||||
) -> Result<Option<Account>>;
|
||||
|
||||
/// Get account balance or 0 if not found.
|
||||
fn get_balance(&self, pubkey: &Pubkey) -> Result<u64>;
|
||||
|
||||
/// Get account balance or 0 if not found. Uses explicit commitment configuration.
|
||||
fn get_balance_with_commitment(
|
||||
&self,
|
||||
pubkey: &Pubkey,
|
||||
commitment_config: CommitmentConfig,
|
||||
) -> Result<u64>;
|
||||
|
||||
/// Get recent blockhash
|
||||
fn get_recent_blockhash(&self) -> Result<(Hash, FeeCalculator)>;
|
||||
|
||||
/// Get recent blockhash. Uses explicit commitment configuration.
|
||||
fn get_recent_blockhash_with_commitment(
|
||||
&self,
|
||||
commitment_config: CommitmentConfig,
|
||||
) -> Result<(Hash, FeeCalculator)>;
|
||||
|
||||
/// Get signature status.
|
||||
fn get_signature_status(
|
||||
&self,
|
||||
signature: &Signature,
|
||||
) -> Result<Option<transaction::Result<()>>>;
|
||||
|
||||
/// Get signature status. Uses explicit commitment configuration.
|
||||
fn get_signature_status_with_commitment(
|
||||
&self,
|
||||
signature: &Signature,
|
||||
commitment_config: CommitmentConfig,
|
||||
) -> Result<Option<transaction::Result<()>>>;
|
||||
|
||||
/// Get last known slot
|
||||
fn get_slot(&self) -> Result<Slot>;
|
||||
|
||||
/// Get last known slot. Uses explicit commitment configuration.
|
||||
fn get_slot_with_commitment(&self, commitment_config: CommitmentConfig) -> Result<u64>;
|
||||
|
||||
/// Get transaction count
|
||||
fn get_transaction_count(&self) -> Result<u64>;
|
||||
|
||||
/// Get transaction count. Uses explicit commitment configuration.
|
||||
fn get_transaction_count_with_commitment(
|
||||
&self,
|
||||
commitment_config: CommitmentConfig,
|
||||
) -> Result<u64>;
|
||||
|
||||
/// Poll until the signature has been confirmed by at least `min_confirmed_blocks`
|
||||
fn poll_for_signature_confirmation(
|
||||
&self,
|
||||
|
36
sdk/src/commitment_config.rs
Normal file
36
sdk/src/commitment_config.rs
Normal file
@ -0,0 +1,36 @@
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CommitmentConfig {
|
||||
pub commitment: CommitmentLevel,
|
||||
}
|
||||
|
||||
impl Default for CommitmentConfig {
|
||||
fn default() -> Self {
|
||||
CommitmentConfig {
|
||||
commitment: CommitmentLevel::Max,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CommitmentConfig {
|
||||
pub fn recent() -> Self {
|
||||
Self {
|
||||
commitment: CommitmentLevel::Recent,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ok(&self) -> Option<Self> {
|
||||
if self == &Self::default() {
|
||||
None
|
||||
} else {
|
||||
Some(self.clone())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum CommitmentLevel {
|
||||
Max,
|
||||
Recent,
|
||||
}
|
@ -35,6 +35,8 @@ pub mod bank_hash;
|
||||
#[cfg(not(feature = "program"))]
|
||||
pub mod client;
|
||||
#[cfg(not(feature = "program"))]
|
||||
pub mod commitment_config;
|
||||
#[cfg(not(feature = "program"))]
|
||||
pub mod genesis_block;
|
||||
#[cfg(not(feature = "program"))]
|
||||
pub mod packet;
|
||||
|
Reference in New Issue
Block a user