Skip to content

Commit

Permalink
Remove dependent deprecated program-test methods
Browse files Browse the repository at this point in the history
  • Loading branch information
CriesofCarrots committed Jul 1, 2024
1 parent c9565fa commit 9c42f9f
Showing 1 changed file with 1 addition and 36 deletions.
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 9c42f9f

Please sign in to comment.