Skip to content

Commit

Permalink
Remove deprecated BanksClient methods and dependent ProgramTest metho…
Browse files Browse the repository at this point in the history
…ds (anza-xyz#1956)

* Remove deprecated Banks client/interface methods

* Remove dependent deprecated program-test methods
  • Loading branch information
CriesofCarrots authored and samkim-crypto committed Jul 31, 2024
1 parent 6fb947e commit d29431b
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 105 deletions.
43 changes: 1 addition & 42 deletions banks-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ use {
BanksTransactionResultWithSimulation,
},
solana_program::{
clock::Slot, fee_calculator::FeeCalculator, hash::Hash, program_pack::Pack, pubkey::Pubkey,
rent::Rent, sysvar::Sysvar,
clock::Slot, hash::Hash, program_pack::Pack, pubkey::Pubkey, rent::Rent, sysvar::Sysvar,
},
solana_sdk::{
account::{from_account, Account},
Expand Down Expand Up @@ -69,21 +68,6 @@ impl BanksClient {
.map_err(Into::into)
}

#[deprecated(
since = "1.9.0",
note = "Please use `get_fee_for_message` or `is_blockhash_valid` instead"
)]
pub fn get_fees_with_commitment_and_context(
&mut self,
ctx: Context,
commitment: CommitmentLevel,
) -> impl Future<Output = Result<(FeeCalculator, Hash, u64), BanksClientError>> + '_ {
#[allow(deprecated)]
self.inner
.get_fees_with_commitment_and_context(ctx, commitment)
.map_err(Into::into)
}

pub fn get_transaction_status_with_context(
&mut self,
ctx: Context,
Expand Down Expand Up @@ -185,20 +169,6 @@ impl BanksClient {
self.send_transaction_with_context(context::current(), transaction.into())
}

/// Return the fee parameters associated with a recent, rooted blockhash. The cluster
/// will use the transaction's blockhash to look up these same fee parameters and
/// use them to calculate the transaction fee.
#[deprecated(
since = "1.9.0",
note = "Please use `get_fee_for_message` or `is_blockhash_valid` instead"
)]
pub fn get_fees(
&mut self,
) -> impl Future<Output = Result<(FeeCalculator, Hash, u64), BanksClientError>> + '_ {
#[allow(deprecated)]
self.get_fees_with_commitment_and_context(context::current(), CommitmentLevel::default())
}

/// Return the cluster Sysvar
pub fn get_sysvar<T: Sysvar>(
&mut self,
Expand All @@ -216,17 +186,6 @@ impl BanksClient {
self.get_sysvar::<Rent>()
}

/// Return a recent, rooted blockhash from the server. The cluster will only accept
/// transactions with a blockhash that has not yet expired. Use the `get_fees`
/// method to get both a blockhash and the blockhash's last valid slot.
#[deprecated(since = "1.9.0", note = "Please use `get_latest_blockhash` instead")]
pub fn get_recent_blockhash(
&mut self,
) -> impl Future<Output = Result<Hash, BanksClientError>> + '_ {
#[allow(deprecated)]
self.get_fees().map(|result| Ok(result?.1))
}

/// Send a transaction and return after the transaction has been rejected or
/// reached the given level of commitment.
pub fn process_transaction_with_commitment(
Expand Down
8 changes: 0 additions & 8 deletions banks-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use {
account::Account,
clock::Slot,
commitment_config::CommitmentLevel,
fee_calculator::FeeCalculator,
hash::Hash,
inner_instruction::InnerInstructions,
message::Message,
Expand Down Expand Up @@ -64,13 +63,6 @@ pub struct BanksTransactionResultWithMetadata {
#[tarpc::service]
pub trait Banks {
async fn send_transaction_with_context(transaction: VersionedTransaction);
#[deprecated(
since = "1.9.0",
note = "Please use `get_fee_for_message_with_commitment_and_context` instead"
)]
async fn get_fees_with_commitment_and_context(
commitment: CommitmentLevel,
) -> (FeeCalculator, Hash, Slot);
async fn get_transaction_status_with_context(signature: Signature)
-> Option<TransactionStatus>;
async fn get_slot_with_context(commitment: CommitmentLevel) -> Slot;
Expand Down
19 changes: 0 additions & 19 deletions banks-server/src/banks_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use {
clock::Slot,
commitment_config::CommitmentLevel,
feature_set::FeatureSet,
fee_calculator::FeeCalculator,
hash::Hash,
message::{Message, SanitizedMessage},
pubkey::Pubkey,
Expand Down Expand Up @@ -232,24 +231,6 @@ impl Banks for BanksServer {
self.transaction_sender.send(info).unwrap();
}

async fn get_fees_with_commitment_and_context(
self,
_: Context,
commitment: CommitmentLevel,
) -> (FeeCalculator, Hash, u64) {
let bank = self.bank(commitment);
let blockhash = bank.last_blockhash();
let lamports_per_signature = bank.get_lamports_per_signature();
let last_valid_block_height = bank
.get_blockhash_last_valid_block_height(&blockhash)
.unwrap();
(
FeeCalculator::new(lamports_per_signature),
blockhash,
last_valid_block_height,
)
}

async fn get_transaction_status_with_context(
self,
_: Context,
Expand Down
37 changes: 1 addition & 36 deletions program-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use {
clock::{Epoch, Slot},
entrypoint::{deserialize, ProgramResult, SUCCESS},
feature_set::FEATURE_NAMES,
fee_calculator::{FeeCalculator, FeeRateGovernor, DEFAULT_TARGET_LAMPORTS_PER_SIGNATURE},
fee_calculator::{FeeRateGovernor, DEFAULT_TARGET_LAMPORTS_PER_SIGNATURE},
genesis_config::{ClusterType, GenesisConfig},
hash::Hash,
instruction::{Instruction, InstructionError},
Expand Down Expand Up @@ -973,47 +973,12 @@ impl ProgramTest {

#[async_trait]
pub trait ProgramTestBanksClientExt {
/// Get a new blockhash, similar in spirit to RpcClient::get_new_blockhash()
///
/// This probably should eventually be moved into BanksClient proper in some form
#[deprecated(
since = "1.9.0",
note = "Please use `get_new_latest_blockhash `instead"
)]
async fn get_new_blockhash(&mut self, blockhash: &Hash) -> io::Result<(Hash, FeeCalculator)>;
/// Get a new latest blockhash, similar in spirit to RpcClient::get_latest_blockhash()
async fn get_new_latest_blockhash(&mut self, blockhash: &Hash) -> io::Result<Hash>;
}

#[async_trait]
impl ProgramTestBanksClientExt for BanksClient {
async fn get_new_blockhash(&mut self, blockhash: &Hash) -> io::Result<(Hash, FeeCalculator)> {
let mut num_retries = 0;
let start = Instant::now();
while start.elapsed().as_secs() < 5 {
#[allow(deprecated)]
if let Ok((fee_calculator, new_blockhash, _slot)) = self.get_fees().await {
if new_blockhash != *blockhash {
return Ok((new_blockhash, fee_calculator));
}
}
debug!("Got same blockhash ({:?}), will retry...", blockhash);

tokio::time::sleep(Duration::from_millis(200)).await;
num_retries += 1;
}

Err(io::Error::new(
io::ErrorKind::Other,
format!(
"Unable to get new blockhash after {}ms (retried {} times), stuck at {}",
start.elapsed().as_millis(),
num_retries,
blockhash
),
))
}

async fn get_new_latest_blockhash(&mut self, blockhash: &Hash) -> io::Result<Hash> {
let mut num_retries = 0;
let start = Instant::now();
Expand Down

0 comments on commit d29431b

Please sign in to comment.