Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Deprecate FeeCalculator returning APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcmay committed Aug 10, 2021
1 parent 5874f75 commit 8b66dd4
Show file tree
Hide file tree
Showing 44 changed files with 1,013 additions and 366 deletions.
39 changes: 26 additions & 13 deletions accounts-cluster-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use solana_measure::measure::Measure;
use solana_runtime::inline_spl_token_v2_0;
use solana_sdk::{
commitment_config::CommitmentConfig,
instruction::{AccountMeta, Instruction},
message::Message,
pubkey::Pubkey,
rpc_port::DEFAULT_RPC_PORT,
Expand All @@ -33,10 +34,6 @@ use std::{
time::{Duration, Instant},
};

// Create and close messages both require 2 signatures; if transaction construction changes, update
// this magic number
const NUM_SIGNATURES: u64 = 2;

pub fn airdrop_lamports(
client: &RpcClient,
faucet_addr: &SocketAddr,
Expand All @@ -55,7 +52,7 @@ pub fn airdrop_lamports(
id.pubkey(),
);

let (blockhash, _fee_calculator) = client.get_recent_blockhash().unwrap();
let blockhash = client.get_last_blockhash().unwrap();
match request_airdrop_transaction(faucet_addr, &id.pubkey(), airdrop_amount, blockhash) {
Ok(transaction) => {
let mut tries = 0;
Expand Down Expand Up @@ -378,7 +375,7 @@ fn run_accounts_bench(
let mut last_blockhash = Instant::now();
let mut last_log = Instant::now();
let mut count = 0;
let mut recent_blockhash = client.get_recent_blockhash().expect("blockhash");
let mut blockhash = client.get_last_blockhash().expect("blockhash");
let mut tx_sent_count = 0;
let mut total_accounts_created = 0;
let mut total_accounts_closed = 0;
Expand Down Expand Up @@ -406,16 +403,32 @@ fn run_accounts_bench(

let executor = TransactionExecutor::new(entrypoint_addr);

// Create and close messages both require 2 signatures, fake a 2 signature message to calculate fees
let message = Message::new(
&[
Instruction::new_with_bytes(
Pubkey::new_unique(),
&[],
vec![AccountMeta::new(Pubkey::new_unique(), true)],
),
Instruction::new_with_bytes(
Pubkey::new_unique(),
&[],
vec![AccountMeta::new(Pubkey::new_unique(), true)],
),
],
None,
);

loop {
if last_blockhash.elapsed().as_millis() > 10_000 {
recent_blockhash = client.get_recent_blockhash().expect("blockhash");
blockhash = client.get_last_blockhash().expect("blockhash");
last_blockhash = Instant::now();
}

let fee = recent_blockhash
.1
.lamports_per_signature
.saturating_mul(NUM_SIGNATURES);
let fee = client
.calculate_fee(&blockhash, &message)
.expect("calculate_fee");
let lamports = min_balance + fee;

for (i, balance) in balances.iter_mut().enumerate() {
Expand Down Expand Up @@ -464,7 +477,7 @@ fn run_accounts_bench(
mint,
);
let signers: Vec<&Keypair> = vec![keypair, &base_keypair];
Transaction::new(&signers, message, recent_blockhash.0)
Transaction::new(&signers, message, blockhash)
})
.collect();
balances[i] = balances[i].saturating_sub(lamports * txs.len() as u64);
Expand Down Expand Up @@ -496,7 +509,7 @@ fn run_accounts_bench(
mint.is_some(),
);
let signers: Vec<&Keypair> = vec![payer_keypairs[0], &base_keypair];
Transaction::new(&signers, message, recent_blockhash.0)
Transaction::new(&signers, message, blockhash)
})
.collect();
balances[0] = balances[0].saturating_sub(fee * txs.len() as u64);
Expand Down
1 change: 1 addition & 0 deletions banks-server/src/banks_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ impl Banks for BanksServer {
commitment: CommitmentLevel,
) -> (FeeCalculator, Hash, Slot) {
let bank = self.bank(commitment);
#[allow(deprecated)]
let (blockhash, fee_calculator) = bank.last_blockhash_with_fee_calculator();
let last_valid_slot = bank.get_blockhash_last_valid_slot(&blockhash).unwrap();
(fee_calculator, blockhash, last_valid_slot)
Expand Down
40 changes: 24 additions & 16 deletions bench-tps/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use solana_sdk::{
client::Client,
clock::{DEFAULT_S_PER_SLOT, MAX_PROCESSING_AGE},
commitment_config::CommitmentConfig,
fee_calculator::FeeCalculator,
hash::Hash,
instruction::{AccountMeta, Instruction},
message::Message,
pubkey::Pubkey,
signature::{Keypair, Signer},
Expand Down Expand Up @@ -45,14 +45,12 @@ pub type Result<T> = std::result::Result<T, BenchTpsError>;

pub type SharedTransactions = Arc<RwLock<VecDeque<Vec<(Transaction, u64)>>>>;

fn get_recent_blockhash<T: Client>(client: &T) -> (Hash, FeeCalculator) {
fn get_last_blockhash<T: Client>(client: &T) -> Hash {
loop {
match client.get_recent_blockhash_with_commitment(CommitmentConfig::processed()) {
Ok((blockhash, fee_calculator, _last_valid_slot)) => {
return (blockhash, fee_calculator)
}
match client.get_last_blockhash_with_commitment(CommitmentConfig::processed()) {
Ok((blockhash, _, _)) => return blockhash,
Err(err) => {
info!("Couldn't get recent blockhash: {:?}", err);
info!("Couldn't get last blockhash: {:?}", err);
sleep(Duration::from_secs(1));
}
};
Expand Down Expand Up @@ -239,19 +237,19 @@ where

let shared_txs: SharedTransactions = Arc::new(RwLock::new(VecDeque::new()));

let recent_blockhash = Arc::new(RwLock::new(get_recent_blockhash(client.as_ref()).0));
let blockhash = Arc::new(RwLock::new(get_last_blockhash(client.as_ref())));
let shared_tx_active_thread_count = Arc::new(AtomicIsize::new(0));
let total_tx_sent_count = Arc::new(AtomicUsize::new(0));

let blockhash_thread = {
let exit_signal = exit_signal.clone();
let recent_blockhash = recent_blockhash.clone();
let blockhash = blockhash.clone();
let client = client.clone();
let id = id.pubkey();
Builder::new()
.name("solana-blockhash-poller".to_string())
.spawn(move || {
poll_blockhash(&exit_signal, &recent_blockhash, &client, &id);
poll_blockhash(&exit_signal, &blockhash, &client, &id);
})
.unwrap()
};
Expand All @@ -271,7 +269,7 @@ where
let start = Instant::now();

generate_chunked_transfers(
recent_blockhash,
blockhash,
&shared_txs,
shared_tx_active_thread_count,
source_keypair_chunks,
Expand Down Expand Up @@ -402,7 +400,7 @@ fn poll_blockhash<T: Client>(
loop {
let blockhash_updated = {
let old_blockhash = *blockhash.read().unwrap();
if let Ok((new_blockhash, _fee)) = client.get_new_blockhash(&old_blockhash) {
if let Ok(new_blockhash) = client.get_new_last_blockhash(&old_blockhash) {
*blockhash.write().unwrap() = new_blockhash;
blockhash_last_updated = Instant::now();
true
Expand Down Expand Up @@ -540,7 +538,7 @@ impl<'a> FundingTransactions<'a> for Vec<(&'a Keypair, Transaction)> {
self.len(),
);

let (blockhash, _fee_calculator) = get_recent_blockhash(client.as_ref());
let blockhash = get_last_blockhash(client.as_ref());

// re-sign retained to_fund_txes with updated blockhash
self.sign(blockhash);
Expand Down Expand Up @@ -732,7 +730,7 @@ pub fn airdrop_lamports<T: Client>(
id.pubkey(),
);

let (blockhash, _fee_calculator) = get_recent_blockhash(client);
let blockhash = get_last_blockhash(client);
match request_airdrop_transaction(faucet_addr, &id.pubkey(), airdrop_amount, blockhash) {
Ok(transaction) => {
let mut tries = 0;
Expand Down Expand Up @@ -890,8 +888,18 @@ pub fn generate_and_fund_keypairs<T: 'static + Client + Send + Sync>(
// pay for the transaction fees in a new run.
let enough_lamports = 8 * lamports_per_account / 10;
if first_keypair_balance < enough_lamports || last_keypair_balance < enough_lamports {
let fee_rate_governor = client.get_fee_rate_governor().unwrap();
let max_fee = fee_rate_governor.max_lamports_per_signature;
let single_sig_message = Message::new(
&[Instruction::new_with_bytes(
Pubkey::new_unique(),
&[],
vec![AccountMeta::new(Pubkey::new_unique(), true)],
)],
None,
);
let blockhash = client.get_last_blockhash().unwrap();
let max_fee = client
.calculate_fee(&blockhash, &single_sig_message)
.unwrap();
let extra_fees = extra * max_fee;
let total_keypairs = keypairs.len() as u64 + 1; // Add one for funding keypair
let total = lamports_per_account * total_keypairs + extra_fees;
Expand Down
Loading

0 comments on commit 8b66dd4

Please sign in to comment.