From da45be366a4b6c9541fd8e03991d9832fff3ef93 Mon Sep 17 00:00:00 2001 From: Jack May Date: Wed, 13 Oct 2021 13:10:58 -0700 Subject: [PATCH] Remove blockhash from fee calculation (#20641) --- accounts-cluster-bench/src/main.rs | 2 +- bench-tps/src/bench.rs | 5 +-- cli/src/checks.rs | 55 ++++++++------------------- cli/src/nonce.rs | 3 -- cli/src/program.rs | 3 -- cli/src/spend_utils.rs | 4 +- cli/src/stake.rs | 7 ---- cli/src/vote.rs | 5 --- client/src/rpc_client.rs | 4 +- client/src/thin_client.rs | 4 +- core/src/test_validator.rs | 2 +- rpc/src/rpc.rs | 9 +---- rpc/src/transaction_status_service.rs | 4 +- runtime/src/accounts.rs | 3 +- runtime/src/bank.rs | 31 +++++---------- runtime/src/bank_client.rs | 4 +- runtime/src/snapshot_utils.rs | 4 +- sdk/program/src/message/sanitized.rs | 15 ++++---- sdk/src/client.rs | 2 +- tokens/src/commands.rs | 3 +- tokens/src/spl_token.rs | 3 +- 21 files changed, 53 insertions(+), 119 deletions(-) diff --git a/accounts-cluster-bench/src/main.rs b/accounts-cluster-bench/src/main.rs index 0c2a926676..5ead497e06 100644 --- a/accounts-cluster-bench/src/main.rs +++ b/accounts-cluster-bench/src/main.rs @@ -271,7 +271,7 @@ fn run_accounts_bench( } let fee = client - .get_fee_for_message(&blockhash, &message) + .get_fee_for_message(&message) .expect("get_fee_for_message"); let lamports = min_balance + fee; diff --git a/bench-tps/src/bench.rs b/bench-tps/src/bench.rs index 01c16a6686..15017d28ef 100644 --- a/bench-tps/src/bench.rs +++ b/bench-tps/src/bench.rs @@ -896,10 +896,7 @@ pub fn generate_and_fund_keypairs( )], None, ); - let blockhash = client.get_latest_blockhash().unwrap(); - let max_fee = client - .get_fee_for_message(&blockhash, &single_sig_message) - .unwrap(); + let max_fee = client.get_fee_for_message(&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; diff --git a/cli/src/checks.rs b/cli/src/checks.rs index 660b9a4b77..f084ae0e3a 100644 --- a/cli/src/checks.rs +++ b/cli/src/checks.rs @@ -4,30 +4,27 @@ use solana_client::{ rpc_client::RpcClient, }; use solana_sdk::{ - commitment_config::CommitmentConfig, hash::Hash, message::Message, - native_token::lamports_to_sol, pubkey::Pubkey, + commitment_config::CommitmentConfig, message::Message, native_token::lamports_to_sol, + pubkey::Pubkey, }; pub fn check_account_for_fee( rpc_client: &RpcClient, account_pubkey: &Pubkey, - blockhash: &Hash, message: &Message, ) -> Result<(), CliError> { - check_account_for_multiple_fees(rpc_client, account_pubkey, blockhash, &[message]) + check_account_for_multiple_fees(rpc_client, account_pubkey, &[message]) } pub fn check_account_for_fee_with_commitment( rpc_client: &RpcClient, account_pubkey: &Pubkey, - blockhash: &Hash, message: &Message, commitment: CommitmentConfig, ) -> Result<(), CliError> { check_account_for_multiple_fees_with_commitment( rpc_client, account_pubkey, - blockhash, &[message], commitment, ) @@ -36,13 +33,11 @@ pub fn check_account_for_fee_with_commitment( pub fn check_account_for_multiple_fees( rpc_client: &RpcClient, account_pubkey: &Pubkey, - blockhash: &Hash, messages: &[&Message], ) -> Result<(), CliError> { check_account_for_multiple_fees_with_commitment( rpc_client, account_pubkey, - blockhash, messages, CommitmentConfig::default(), ) @@ -51,7 +46,6 @@ pub fn check_account_for_multiple_fees( pub fn check_account_for_multiple_fees_with_commitment( rpc_client: &RpcClient, account_pubkey: &Pubkey, - blockhash: &Hash, messages: &[&Message], commitment: CommitmentConfig, ) -> Result<(), CliError> { @@ -59,7 +53,6 @@ pub fn check_account_for_multiple_fees_with_commitment( rpc_client, account_pubkey, 0, - blockhash, messages, commitment, ) @@ -69,11 +62,10 @@ pub fn check_account_for_spend_multiple_fees_with_commitment( rpc_client: &RpcClient, account_pubkey: &Pubkey, balance: u64, - blockhash: &Hash, messages: &[&Message], commitment: CommitmentConfig, ) -> Result<(), CliError> { - let fee = get_fee_for_message(rpc_client, blockhash, messages)?; + let fee = get_fee_for_message(rpc_client, messages)?; if !check_account_for_balance_with_commitment( rpc_client, account_pubkey, @@ -98,14 +90,10 @@ pub fn check_account_for_spend_multiple_fees_with_commitment( Ok(()) } -pub fn get_fee_for_message( - rpc_client: &RpcClient, - blockhash: &Hash, - messages: &[&Message], -) -> Result { +pub fn get_fee_for_message(rpc_client: &RpcClient, messages: &[&Message]) -> Result { Ok(messages .iter() - .map(|message| rpc_client.get_fee_for_message(blockhash, message)) + .map(|message| rpc_client.get_fee_for_message(message)) .collect::, _>>()? .iter() .sum()) @@ -185,9 +173,7 @@ mod tests { let mut mocks = HashMap::new(); mocks.insert(RpcRequest::GetBalance, account_balance_response.clone()); let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks); - let blockhash = rpc_client.get_latest_blockhash().unwrap(); - check_account_for_fee(&rpc_client, &pubkey, &blockhash, &message0) - .expect("unexpected result"); + check_account_for_fee(&rpc_client, &pubkey, &message0).expect("unexpected result"); let check_fee_response = json!(Response { context: RpcResponseContext { slot: 1 }, @@ -197,7 +183,7 @@ mod tests { mocks.insert(RpcRequest::GetFeeForMessage, check_fee_response); mocks.insert(RpcRequest::GetBalance, account_balance_response.clone()); let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks); - assert!(check_account_for_fee(&rpc_client, &pubkey, &blockhash, &message1).is_err()); + assert!(check_account_for_fee(&rpc_client, &pubkey, &message1).is_err()); let check_fee_response = json!(Response { context: RpcResponseContext { slot: 1 }, @@ -207,13 +193,9 @@ mod tests { mocks.insert(RpcRequest::GetFeeForMessage, check_fee_response); mocks.insert(RpcRequest::GetBalance, account_balance_response); let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks); - assert!(check_account_for_multiple_fees( - &rpc_client, - &pubkey, - &blockhash, - &[&message0, &message0] - ) - .is_err()); + assert!( + check_account_for_multiple_fees(&rpc_client, &pubkey, &[&message0, &message0]).is_err() + ); let account_balance = 2; let account_balance_response = json!(Response { @@ -230,7 +212,7 @@ mod tests { mocks.insert(RpcRequest::GetBalance, account_balance_response); let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks); - check_account_for_multiple_fees(&rpc_client, &pubkey, &blockhash, &[&message0, &message0]) + check_account_for_multiple_fees(&rpc_client, &pubkey, &[&message0, &message0]) .expect("unexpected result"); } @@ -261,23 +243,16 @@ mod tests { let mut mocks = HashMap::new(); mocks.insert(RpcRequest::GetFeeForMessage, check_fee_response); let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks); - let blockhash = rpc_client.get_latest_blockhash().unwrap(); // No messages, no fee. - assert_eq!( - get_fee_for_message(&rpc_client, &blockhash, &[]).unwrap(), - 0 - ); + assert_eq!(get_fee_for_message(&rpc_client, &[]).unwrap(), 0); // One message w/ one signature, a fee. let pubkey0 = Pubkey::new(&[0; 32]); let pubkey1 = Pubkey::new(&[1; 32]); let ix0 = system_instruction::transfer(&pubkey0, &pubkey1, 1); let message0 = Message::new(&[ix0], Some(&pubkey0)); - assert_eq!( - get_fee_for_message(&rpc_client, &blockhash, &[&message0]).unwrap(), - 1 - ); + assert_eq!(get_fee_for_message(&rpc_client, &[&message0]).unwrap(), 1); // No signatures, no fee. let check_fee_response = json!(Response { @@ -289,7 +264,7 @@ mod tests { let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks); let message = Message::default(); assert_eq!( - get_fee_for_message(&rpc_client, &blockhash, &[&message, &message]).unwrap(), + get_fee_for_message(&rpc_client, &[&message, &message]).unwrap(), 0 ); } diff --git a/cli/src/nonce.rs b/cli/src/nonce.rs index c64e945934..0c90ff656a 100644 --- a/cli/src/nonce.rs +++ b/cli/src/nonce.rs @@ -367,7 +367,6 @@ pub fn process_authorize_nonce_account( check_account_for_fee_with_commitment( rpc_client, &config.signers[0].pubkey(), - &latest_blockhash, &tx.message, config.commitment, )?; @@ -552,7 +551,6 @@ pub fn process_new_nonce( check_account_for_fee_with_commitment( rpc_client, &config.signers[0].pubkey(), - &latest_blockhash, &tx.message, config.commitment, )?; @@ -628,7 +626,6 @@ pub fn process_withdraw_from_nonce_account( check_account_for_fee_with_commitment( rpc_client, &config.signers[0].pubkey(), - &latest_blockhash, &tx.message, config.commitment, )?; diff --git a/cli/src/program.rs b/cli/src/program.rs index 551d240f99..5da385e98a 100644 --- a/cli/src/program.rs +++ b/cli/src/program.rs @@ -2071,14 +2071,11 @@ fn check_payer( balance_needed: u64, messages: &[&Message], ) -> Result<(), Box> { - let blockhash = rpc_client.get_latest_blockhash()?; - // Does the payer have enough? check_account_for_spend_multiple_fees_with_commitment( rpc_client, &config.signers[0].pubkey(), balance_needed, - &blockhash, messages, config.commitment, )?; diff --git a/cli/src/spend_utils.rs b/cli/src/spend_utils.rs index f525b803fa..8c3dd5ffcc 100644 --- a/cli/src/spend_utils.rs +++ b/cli/src/spend_utils.rs @@ -144,9 +144,9 @@ where F: Fn(u64) -> Message, { let fee = match blockhash { - Some(blockhash) => { + Some(_) => { let dummy_message = build_message(0); - get_fee_for_message(rpc_client, blockhash, &[&dummy_message])? + get_fee_for_message(rpc_client, &[&dummy_message])? } None => 0, // Offline, cannot calulate fee }; diff --git a/cli/src/stake.rs b/cli/src/stake.rs index 525ea1110c..d2b209a328 100644 --- a/cli/src/stake.rs +++ b/cli/src/stake.rs @@ -1455,7 +1455,6 @@ pub fn process_stake_authorize( check_account_for_fee_with_commitment( rpc_client, &tx.message.account_keys[0], - &recent_blockhash, &tx.message, config.commitment, )?; @@ -1534,7 +1533,6 @@ pub fn process_deactivate_stake_account( check_account_for_fee_with_commitment( rpc_client, &tx.message.account_keys[0], - &recent_blockhash, &tx.message, config.commitment, )?; @@ -1632,7 +1630,6 @@ pub fn process_withdraw_stake( check_account_for_fee_with_commitment( rpc_client, &tx.message.account_keys[0], - &recent_blockhash, &tx.message, config.commitment, )?; @@ -1776,7 +1773,6 @@ pub fn process_split_stake( check_account_for_fee_with_commitment( rpc_client, &tx.message.account_keys[0], - &recent_blockhash, &tx.message, config.commitment, )?; @@ -1882,7 +1878,6 @@ pub fn process_merge_stake( check_account_for_fee_with_commitment( rpc_client, &tx.message.account_keys[0], - &recent_blockhash, &tx.message, config.commitment, )?; @@ -1977,7 +1972,6 @@ pub fn process_stake_set_lockup( check_account_for_fee_with_commitment( rpc_client, &tx.message.account_keys[0], - &recent_blockhash, &tx.message, config.commitment, )?; @@ -2419,7 +2413,6 @@ pub fn process_delegate_stake( check_account_for_fee_with_commitment( rpc_client, &tx.message.account_keys[0], - &recent_blockhash, &tx.message, config.commitment, )?; diff --git a/cli/src/vote.rs b/cli/src/vote.rs index 5d2e04a39c..cefa2c2fb4 100644 --- a/cli/src/vote.rs +++ b/cli/src/vote.rs @@ -774,7 +774,6 @@ pub fn process_vote_authorize( check_account_for_fee_with_commitment( rpc_client, &config.signers[0].pubkey(), - &latest_blockhash, &tx.message, config.commitment, )?; @@ -811,7 +810,6 @@ pub fn process_vote_update_validator( check_account_for_fee_with_commitment( rpc_client, &config.signers[0].pubkey(), - &latest_blockhash, &tx.message, config.commitment, )?; @@ -842,7 +840,6 @@ pub fn process_vote_update_commission( check_account_for_fee_with_commitment( rpc_client, &config.signers[0].pubkey(), - &latest_blockhash, &tx.message, config.commitment, )?; @@ -980,7 +977,6 @@ pub fn process_withdraw_from_vote_account( check_account_for_fee_with_commitment( rpc_client, &config.signers[0].pubkey(), - &latest_blockhash, &transaction.message, config.commitment, )?; @@ -1036,7 +1032,6 @@ pub fn process_close_vote_account( check_account_for_fee_with_commitment( rpc_client, &config.signers[0].pubkey(), - &latest_blockhash, &transaction.message, config.commitment, )?; diff --git a/client/src/rpc_client.rs b/client/src/rpc_client.rs index eaa673f7f9..f4fd2bf4de 100644 --- a/client/src/rpc_client.rs +++ b/client/src/rpc_client.rs @@ -4800,7 +4800,7 @@ impl RpcClient { } #[allow(deprecated)] - pub fn get_fee_for_message(&self, blockhash: &Hash, message: &Message) -> ClientResult { + pub fn get_fee_for_message(&self, message: &Message) -> ClientResult { if self.get_node_version()? < semver::Version::new(1, 8, 0) { let Fees { fee_calculator, .. } = self.get_fees()?; Ok(fee_calculator @@ -4811,7 +4811,7 @@ impl RpcClient { serialize_and_encode::(message, UiTransactionEncoding::Base64)?; let result = self.send::>>( RpcRequest::GetFeeForMessage, - json!([blockhash.to_string(), serialized_encoded, self.commitment()]), + json!([serialized_encoded, self.commitment()]), )?; result .value diff --git a/client/src/thin_client.rs b/client/src/thin_client.rs index 0e372e4278..7305a80a91 100644 --- a/client/src/thin_client.rs +++ b/client/src/thin_client.rs @@ -600,9 +600,9 @@ impl SyncClient for ThinClient { .map_err(|e| e.into()) } - fn get_fee_for_message(&self, blockhash: &Hash, message: &Message) -> TransportResult { + fn get_fee_for_message(&self, message: &Message) -> TransportResult { self.rpc_client() - .get_fee_for_message(blockhash, message) + .get_fee_for_message(message) .map_err(|e| e.into()) } diff --git a/core/src/test_validator.rs b/core/src/test_validator.rs index 3da344233b..e54d2da384 100644 --- a/core/src/test_validator.rs +++ b/core/src/test_validator.rs @@ -577,7 +577,7 @@ impl TestValidator { } println!("Waiting for fees to stabilize {:?}...", num_tries); match rpc_client.get_latest_blockhash() { - Ok(blockhash) => match rpc_client.get_fee_for_message(&blockhash, &message) { + Ok(_) => match rpc_client.get_fee_for_message(&message) { Ok(fee) => { if fee != 0 { break; diff --git a/rpc/src/rpc.rs b/rpc/src/rpc.rs index e30b6b37a3..fdfa821ba1 100644 --- a/rpc/src/rpc.rs +++ b/rpc/src/rpc.rs @@ -1961,12 +1961,11 @@ impl JsonRpcRequestProcessor { fn get_fee_for_message( &self, - blockhash: &Hash, message: &SanitizedMessage, commitment: Option, ) -> Result>> { let bank = self.bank(commitment); - let fee = bank.get_fee_for_message(blockhash, message); + let fee = bank.get_fee_for_message(message); Ok(new_response(&bank, fee)) } } @@ -3124,7 +3123,6 @@ pub mod rpc_full { fn get_fee_for_message( &self, meta: Self::Metadata, - blockhash: String, data: String, commitment: Option, ) -> Result>>; @@ -3640,20 +3638,17 @@ pub mod rpc_full { fn get_fee_for_message( &self, meta: Self::Metadata, - blockhash: String, data: String, commitment: Option, ) -> Result>> { debug!("get_fee_for_message rpc request received"); - let blockhash = Hash::from_str(&blockhash) - .map_err(|e| Error::invalid_params(format!("{:?}", e)))?; let (_, message) = decode_and_deserialize::(data, UiTransactionEncoding::Base64)?; SanitizedMessage::try_from(message) .map_err(|err| { Error::invalid_params(format!("invalid transaction message: {}", err)) }) - .and_then(|message| meta.get_fee_for_message(&blockhash, &message, commitment)) + .and_then(|message| meta.get_fee_for_message(&message, commitment)) } } } diff --git a/rpc/src/transaction_status_service.rs b/rpc/src/transaction_status_service.rs index 62630d3a17..bb4cf85644 100644 --- a/rpc/src/transaction_status_service.rs +++ b/rpc/src/transaction_status_service.rs @@ -112,7 +112,9 @@ impl TransactionStatusService { bank.get_fee_calculator(transaction.message().recent_blockhash()) }) .expect("FeeCalculator must exist"); - let fee = transaction.message().calculate_fee(&fee_calculator); + let fee = transaction + .message() + .calculate_fee(fee_calculator.lamports_per_signature); let tx_account_locks = transaction.get_account_locks(bank.demote_program_write_locks()); diff --git a/runtime/src/accounts.rs b/runtime/src/accounts.rs index af25bb9b00..b2e3cd1a98 100644 --- a/runtime/src/accounts.rs +++ b/runtime/src/accounts.rs @@ -486,7 +486,8 @@ impl Accounts { .cloned() }); let fee = if let Some(fee_calculator) = fee_calculator { - tx.message().calculate_fee(&fee_calculator) + tx.message() + .calculate_fee(fee_calculator.lamports_per_signature) } else { return (Err(TransactionError::BlockhashNotFound), None); }; diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 3c2b675f00..9307428e69 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -3108,11 +3108,8 @@ impl Bank { &self.fee_rate_governor } - pub fn get_fee_for_message(&self, hash: &Hash, message: &SanitizedMessage) -> Option { - let blockhash_queue = self.blockhash_queue.read().unwrap(); - #[allow(deprecated)] - let fee_calculator = blockhash_queue.get_fee_calculator(hash)?; - Some(message.calculate_fee(fee_calculator)) + pub fn get_fee_for_message(&self, message: &SanitizedMessage) -> Option { + Some(message.calculate_fee(self.fee_rate_governor.lamports_per_signature)) } #[deprecated( @@ -4042,7 +4039,9 @@ impl Bank { }); let fee_calculator = fee_calculator.ok_or(TransactionError::BlockhashNotFound)?; - let fee = tx.message().calculate_fee(&fee_calculator); + let fee = tx + .message() + .calculate_fee(fee_calculator.lamports_per_signature); match *res { Err(TransactionError::InstructionError(_, _)) => { @@ -10920,10 +10919,7 @@ pub(crate) mod tests { /* Check balances */ let mut expected_balance = 4_650_000 - bank - .get_fee_for_message( - &bank.last_blockhash(), - &durable_tx.message.try_into().unwrap(), - ) + .get_fee_for_message(&durable_tx.message.try_into().unwrap()) .unwrap(); assert_eq!(bank.get_balance(&custodian_pubkey), expected_balance); assert_eq!(bank.get_balance(&nonce_pubkey), 250_000); @@ -10977,10 +10973,7 @@ pub(crate) mod tests { ); /* Check fee charged and nonce has advanced */ expected_balance -= bank - .get_fee_for_message( - &bank.last_blockhash(), - &SanitizedMessage::try_from(durable_tx.message.clone()).unwrap(), - ) + .get_fee_for_message(&SanitizedMessage::try_from(durable_tx.message.clone()).unwrap()) .unwrap(); assert_eq!(bank.get_balance(&custodian_pubkey), expected_balance); assert_ne!(nonce_hash, get_nonce_account(&bank, &nonce_pubkey).unwrap()); @@ -11044,10 +11037,7 @@ pub(crate) mod tests { bank.get_balance(&custodian_pubkey), initial_custodian_balance - bank - .get_fee_for_message( - &bank.last_blockhash(), - &durable_tx.message.try_into().unwrap() - ) + .get_fee_for_message(&durable_tx.message.try_into().unwrap()) .unwrap() ); assert_eq!(nonce_hash, get_nonce_account(&bank, &nonce_pubkey).unwrap()); @@ -11099,10 +11089,7 @@ pub(crate) mod tests { bank.get_balance(&nonce_pubkey), nonce_starting_balance - bank - .get_fee_for_message( - &bank.last_blockhash(), - &durable_tx.message.try_into().unwrap() - ) + .get_fee_for_message(&durable_tx.message.try_into().unwrap()) .unwrap() ); assert_ne!(nonce_hash, get_nonce_account(&bank, &nonce_pubkey).unwrap()); diff --git a/runtime/src/bank_client.rs b/runtime/src/bank_client.rs index e51b1630f0..cf5b049e6c 100644 --- a/runtime/src/bank_client.rs +++ b/runtime/src/bank_client.rs @@ -303,10 +303,10 @@ impl SyncClient for BankClient { Ok(self.bank.is_blockhash_valid(blockhash)) } - fn get_fee_for_message(&self, blockhash: &Hash, message: &Message) -> Result { + fn get_fee_for_message(&self, message: &Message) -> Result { SanitizedMessage::try_from(message.clone()) .ok() - .and_then(|message| self.bank.get_fee_for_message(blockhash, &message)) + .and_then(|message| self.bank.get_fee_for_message(&message)) .ok_or_else(|| { TransportError::IoError(io::Error::new( io::ErrorKind::Other, diff --git a/runtime/src/snapshot_utils.rs b/runtime/src/snapshot_utils.rs index 428f5fd527..593252df91 100644 --- a/runtime/src/snapshot_utils.rs +++ b/runtime/src/snapshot_utils.rs @@ -3049,9 +3049,7 @@ mod tests { bank2.last_blockhash(), )) .unwrap(); - let fee = bank2 - .get_fee_for_message(&bank2.last_blockhash(), tx.message()) - .unwrap(); + let fee = bank2.get_fee_for_message(tx.message()).unwrap(); let tx = system_transaction::transfer( &key1, &key2.pubkey(), diff --git a/sdk/program/src/message/sanitized.rs b/sdk/program/src/message/sanitized.rs index e5932f90a6..cfaf621828 100644 --- a/sdk/program/src/message/sanitized.rs +++ b/sdk/program/src/message/sanitized.rs @@ -1,6 +1,5 @@ use { crate::{ - fee_calculator::FeeCalculator, hash::Hash, instruction::{CompiledInstruction, Instruction}, message::{MappedAddresses, MappedMessage, Message, MessageHeader}, @@ -292,7 +291,7 @@ impl SanitizedMessage { } /// Calculate the total fees for a transaction given a fee calculator - pub fn calculate_fee(&self, fee_calculator: &FeeCalculator) -> u64 { + pub fn calculate_fee(&self, lamports_per_signature: u64) -> u64 { let mut num_signatures = u64::from(self.header().num_required_signatures); for (program_id, instruction) in self.program_instructions_iter() { if secp256k1_program::check_id(program_id) { @@ -303,7 +302,7 @@ impl SanitizedMessage { } } - fee_calculator.lamports_per_signature.saturating_mul(num_signatures) + lamports_per_signature.saturating_mul(num_signatures) } /// Inspect all message keys for the bpf upgradeable loader @@ -465,10 +464,10 @@ mod tests { // Default: no fee. let message = SanitizedMessage::try_from(Message::new(&[], Some(&Pubkey::new_unique()))).unwrap(); - assert_eq!(message.calculate_fee(&FeeCalculator::default()), 0); + assert_eq!(message.calculate_fee(0), 0); // One signature, a fee. - assert_eq!(message.calculate_fee(&FeeCalculator::new(1)), 1); + assert_eq!(message.calculate_fee(1), 1); // Two signatures, double the fee. let key0 = Pubkey::new_unique(); @@ -476,7 +475,7 @@ mod tests { let ix0 = system_instruction::transfer(&key0, &key1, 1); let ix1 = system_instruction::transfer(&key1, &key0, 1); let message = SanitizedMessage::try_from(Message::new(&[ix0, ix1], Some(&key0))).unwrap(); - assert_eq!(message.calculate_fee(&FeeCalculator::new(2)), 4); + assert_eq!(message.calculate_fee(2), 4); } #[test] @@ -588,7 +587,7 @@ mod tests { Some(&key0), )) .unwrap(); - assert_eq!(message.calculate_fee(&FeeCalculator::new(1)), 2); + assert_eq!(message.calculate_fee(1), 2); secp_instruction1.data = vec![0]; secp_instruction2.data = vec![10]; @@ -597,6 +596,6 @@ mod tests { Some(&key0), )) .unwrap(); - assert_eq!(message.calculate_fee(&FeeCalculator::new(1)), 11); + assert_eq!(message.calculate_fee(1), 11); } } diff --git a/sdk/src/client.rs b/sdk/src/client.rs index 7bfc229428..8e24423653 100644 --- a/sdk/src/client.rs +++ b/sdk/src/client.rs @@ -168,7 +168,7 @@ pub trait SyncClient { fn is_blockhash_valid(&self, blockhash: &Hash, commitment: CommitmentConfig) -> Result; /// Calculate the fee for a `Message` - fn get_fee_for_message(&self, blockhash: &Hash, message: &Message) -> Result; + fn get_fee_for_message(&self, message: &Message) -> Result; /// Get a new blockhash after the one specified fn get_new_latest_blockhash(&self, blockhash: &Hash) -> Result; diff --git a/tokens/src/commands.rs b/tokens/src/commands.rs index 03ee118bb1..b5815e80d8 100644 --- a/tokens/src/commands.rs +++ b/tokens/src/commands.rs @@ -730,10 +730,9 @@ fn check_payer_balances( ) -> Result<(), Error> { let mut undistributed_tokens: u64 = allocations.iter().map(|x| x.amount).sum(); - let blockhash = client.get_latest_blockhash()?; let fees = messages .iter() - .map(|message| client.get_fee_for_message(&blockhash, message)) + .map(|message| client.get_fee_for_message(message)) .collect::, _>>() .unwrap() .iter() diff --git a/tokens/src/spl_token.rs b/tokens/src/spl_token.rs index 5e0627737b..d9cbda71db 100644 --- a/tokens/src/spl_token.rs +++ b/tokens/src/spl_token.rs @@ -97,10 +97,9 @@ pub fn check_spl_token_balances( .expect("spl_token_args must be some"); let allocation_amount: u64 = allocations.iter().map(|x| x.amount).sum(); - let blockhash = client.get_latest_blockhash()?; let fees: u64 = messages .iter() - .map(|message| client.get_fee_for_message(&blockhash, message)) + .map(|message| client.get_fee_for_message(message)) .collect::, _>>() .unwrap() .iter()