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

Commit

Permalink
Rename to get_fee_for_message
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcmay committed Aug 12, 2021
1 parent 8defa3a commit 8d5a44c
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 59 deletions.
4 changes: 2 additions & 2 deletions accounts-cluster-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ fn run_accounts_bench(
}

let fee = client
.get_fee_for_transaction(&blockhash, &message)
.expect("get_fee_for_transaction");
.get_fee_for_message(&blockhash, &message)
.expect("get_fee_for_message");
let lamports = min_balance + fee;

for (i, balance) in balances.iter_mut().enumerate() {
Expand Down
2 changes: 1 addition & 1 deletion bench-tps/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ pub fn generate_and_fund_keypairs<T: 'static + Client + Send + Sync>(
);
let blockhash = client.get_latest_blockhash().unwrap();
let max_fee = client
.get_fee_for_transaction(&blockhash, &single_sig_message)
.get_fee_for_message(&blockhash, &single_sig_message)
.unwrap();
let extra_fees = extra * max_fee;
let total_keypairs = keypairs.len() as u64 + 1; // Add one for funding keypair
Expand Down
24 changes: 12 additions & 12 deletions cli/src/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn check_account_for_spend_multiple_fees_with_commitment(
messages: &[&Message],
commitment: CommitmentConfig,
) -> Result<(), CliError> {
let fee = get_fee_for_transaction(rpc_client, blockhash, messages)?;
let fee = get_fee_for_message(rpc_client, blockhash, messages)?;
if !check_account_for_balance_with_commitment(
rpc_client,
account_pubkey,
Expand All @@ -98,14 +98,14 @@ pub fn check_account_for_spend_multiple_fees_with_commitment(
Ok(())
}

pub fn get_fee_for_transaction(
pub fn get_fee_for_message(
rpc_client: &RpcClient,
blockhash: &Hash,
messages: &[&Message],
) -> Result<u64, CliError> {
Ok(messages
.iter()
.map(|message| rpc_client.get_fee_for_transaction(blockhash, message))
.map(|message| rpc_client.get_fee_for_message(blockhash, message))
.collect::<Result<Vec<_>, _>>()?
.iter()
.sum())
Expand Down Expand Up @@ -194,7 +194,7 @@ mod tests {
value: json!(2),
});
let mut mocks = HashMap::new();
mocks.insert(RpcRequest::GetFeeForTransaction, check_fee_response);
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());
Expand All @@ -204,7 +204,7 @@ mod tests {
value: json!(2),
});
let mut mocks = HashMap::new();
mocks.insert(RpcRequest::GetFeeForTransaction, check_fee_response);
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(
Expand All @@ -226,7 +226,7 @@ mod tests {
});

let mut mocks = HashMap::new();
mocks.insert(RpcRequest::GetFeeForTransaction, check_fee_response);
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);

Expand All @@ -253,19 +253,19 @@ mod tests {
}

#[test]
fn test_get_fee_for_transaction() {
fn test_get_fee_for_message() {
let check_fee_response = json!(Response {
context: RpcResponseContext { slot: 1 },
value: json!(1),
});
let mut mocks = HashMap::new();
mocks.insert(RpcRequest::GetFeeForTransaction, check_fee_response);
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_transaction(&rpc_client, &blockhash, &[]).unwrap(),
get_fee_for_message(&rpc_client, &blockhash, &[]).unwrap(),
0
);

Expand All @@ -275,7 +275,7 @@ mod tests {
let ix0 = system_instruction::transfer(&pubkey0, &pubkey1, 1);
let message0 = Message::new(&[ix0], Some(&pubkey0));
assert_eq!(
get_fee_for_transaction(&rpc_client, &blockhash, &[&message0]).unwrap(),
get_fee_for_message(&rpc_client, &blockhash, &[&message0]).unwrap(),
1
);

Expand All @@ -285,11 +285,11 @@ mod tests {
value: json!(0),
});
let mut mocks = HashMap::new();
mocks.insert(RpcRequest::GetFeeForTransaction, check_fee_response);
mocks.insert(RpcRequest::GetFeeForMessage, check_fee_response);
let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks);
let message = Message::default();
assert_eq!(
get_fee_for_transaction(&rpc_client, &blockhash, &[&message, &message]).unwrap(),
get_fee_for_message(&rpc_client, &blockhash, &[&message, &message]).unwrap(),
0
);
}
Expand Down
4 changes: 2 additions & 2 deletions cli/src/spend_utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
checks::{check_account_for_balance_with_commitment, get_fee_for_transaction},
checks::{check_account_for_balance_with_commitment, get_fee_for_message},
cli::CliError,
};
use clap::ArgMatches;
Expand Down Expand Up @@ -146,7 +146,7 @@ where
let fee = match blockhash {
Some(blockhash) => {
let dummy_message = build_message(0);
get_fee_for_transaction(rpc_client, blockhash, &[&dummy_message])?
get_fee_for_message(rpc_client, blockhash, &[&dummy_message])?
}
None => 0, // Offline, cannot calulate fee
};
Expand Down
2 changes: 1 addition & 1 deletion client/src/mock_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ impl RpcSender for MockSender {
last_valid_block_height: 0,
},
})?,
"getFeeForTransaction" => serde_json::to_value(Response {
"getFeeForMessage" => serde_json::to_value(Response {
context: RpcResponseContext { slot: 1 },
value: json!(Some(0)),
})?,
Expand Down
16 changes: 6 additions & 10 deletions client/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2207,7 +2207,7 @@ impl RpcClient {

#[deprecated(
since = "1.8.0",
note = "Please use `get_latest_blockhash` and `get_fee_for_transaction` instead"
note = "Please use `get_latest_blockhash` and `get_fee_for_message` instead"
)]
#[allow(deprecated)]
pub fn get_fees(&self) -> ClientResult<Fees> {
Expand All @@ -2217,7 +2217,7 @@ impl RpcClient {

#[deprecated(
since = "1.8.0",
note = "Please use `get_latest_blockhash_with_commitment` and `get_fee_for_transaction` instead"
note = "Please use `get_latest_blockhash_with_commitment` and `get_fee_for_message` instead"
)]
#[allow(deprecated)]
pub fn get_fees_with_commitment(&self, commitment_config: CommitmentConfig) -> RpcResult<Fees> {
Expand Down Expand Up @@ -2322,7 +2322,7 @@ impl RpcClient {
})
}

#[deprecated(since = "1.8.0", note = "Please `get_fee_for_transaction` instead")]
#[deprecated(since = "1.8.0", note = "Please `get_fee_for_message` instead")]
#[allow(deprecated)]
pub fn get_fee_calculator_for_blockhash(
&self,
Expand All @@ -2336,7 +2336,7 @@ impl RpcClient {

#[deprecated(
since = "1.8.0",
note = "Please `get_latest_blockhash_with_commitment` and `get_fee_for_transaction` instead"
note = "Please `get_latest_blockhash_with_commitment` and `get_fee_for_message` instead"
)]
#[allow(deprecated)]
pub fn get_fee_calculator_for_blockhash_with_commitment(
Expand Down Expand Up @@ -3001,17 +3001,13 @@ impl RpcClient {
Ok(result.value)
}

pub fn get_fee_for_transaction(
&self,
blockhash: &Hash,
message: &Message,
) -> ClientResult<u64> {
pub fn get_fee_for_message(&self, blockhash: &Hash, message: &Message) -> ClientResult<u64> {
let serialized_encoded = serialize_encode_transaction(
&Transaction::new_unsigned(message.clone()),
UiTransactionEncoding::Base64,
)?;
let result = self.send::<Response<Option<u64>>>(
RpcRequest::GetFeeForTransaction,
RpcRequest::GetFeeForMessage,
json!([
blockhash.to_string(),
serialized_encoded,
Expand Down
8 changes: 4 additions & 4 deletions client/src/rpc_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ pub enum RpcRequest {
GetEpochSchedule,
#[deprecated(
since = "1.8.0",
note = "Please use RpcRequest::GetFeeForTransaction instead"
note = "Please use RpcRequest::GetFeeForMessage instead"
)]
GetFeeCalculatorForBlockhash,
GetFeeForTransaction,
GetFeeForMessage,
#[deprecated(
since = "1.8.0",
note = "Please do not use, will no longer be available in the future"
)]
GetFeeRateGovernor,
#[deprecated(
since = "1.8.0",
note = "Please use RpcRequest::GetFeeForTransaction instead"
note = "Please use RpcRequest::GetFeeForMessage instead"
)]
GetFees,
GetFirstAvailableBlock,
Expand Down Expand Up @@ -131,7 +131,7 @@ impl fmt::Display for RpcRequest {
RpcRequest::GetEpochInfo => "getEpochInfo",
RpcRequest::GetEpochSchedule => "getEpochSchedule",
RpcRequest::GetFeeCalculatorForBlockhash => "getFeeCalculatorForBlockhash",
RpcRequest::GetFeeForTransaction => "getFeeForTransaction",
RpcRequest::GetFeeForMessage => "getFeeForMessage",
RpcRequest::GetFeeRateGovernor => "getFeeRateGovernor",
RpcRequest::GetFees => "getFees",
RpcRequest::GetFirstAvailableBlock => "getFirstAvailableBlock",
Expand Down
4 changes: 2 additions & 2 deletions client/src/thin_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,9 @@ impl SyncClient for ThinClient {
.map_err(|e| e.into())
}

fn get_fee_for_transaction(&self, blockhash: &Hash, message: &Message) -> TransportResult<u64> {
fn get_fee_for_message(&self, blockhash: &Hash, message: &Message) -> TransportResult<u64> {
self.rpc_client()
.get_fee_for_transaction(blockhash, message)
.get_fee_for_message(blockhash, message)
.map_err(|e| e.into())
}

Expand Down
5 changes: 2 additions & 3 deletions core/src/test_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,15 +570,14 @@ impl TestValidator {
}
println!("Waiting for fees to stabilize {:?}...", num_tries);
match rpc_client.get_latest_blockhash() {
Ok(blockhash) => match rpc_client.get_fee_for_transaction(&blockhash, &message)
{
Ok(blockhash) => match rpc_client.get_fee_for_message(&blockhash, &message) {
Ok(fee) => {
if fee != 0 {
break;
}
}
Err(err) => {
warn!("get_fee_for_transaction() failed: {:?}", err);
warn!("get_fee_for_message() failed: {:?}", err);
break;
}
},
Expand Down
14 changes: 7 additions & 7 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1929,14 +1929,14 @@ impl JsonRpcRequestProcessor {
new_response(&bank, is_valid)
}

fn get_fee_for_transaction(
fn get_fee_for_message(
&self,
blockhash: &Hash,
transaction: &Transaction,
commitment: Option<CommitmentConfig>,
) -> Result<RpcResponse<Option<u64>>> {
let bank = self.bank(commitment);
let fee = bank.get_fee_for_transaction(blockhash, &transaction.message);
let fee = bank.get_fee_for_message(blockhash, &transaction.message);
Ok(new_response(&bank, fee))
}
}
Expand Down Expand Up @@ -3077,8 +3077,8 @@ pub mod rpc_full {
commitment: Option<CommitmentConfig>,
) -> Result<RpcResponse<bool>>;

#[rpc(meta, name = "getFeeForTransaction")]
fn get_fee_for_transaction(
#[rpc(meta, name = "getFeeForMessage")]
fn get_fee_for_message(
&self,
meta: Self::Metadata,
blockhash: String,
Expand Down Expand Up @@ -3601,19 +3601,19 @@ pub mod rpc_full {
Ok(meta.is_blockhash_valid(&blockhash, commitment))
}

fn get_fee_for_transaction(
fn get_fee_for_message(
&self,
meta: Self::Metadata,
blockhash: String,
data: String,
encoding: UiTransactionEncoding,
commitment: Option<CommitmentConfig>,
) -> Result<RpcResponse<Option<u64>>> {
debug!("get_fee_for_transaction rpc request received");
debug!("get_fee_for_message rpc request received");
let blockhash = Hash::from_str(&blockhash)
.map_err(|e| Error::invalid_params(format!("{:?}", e)))?;
let (_, transaction) = deserialize_transaction(data, encoding)?;
meta.get_fee_for_transaction(&blockhash, &transaction, commitment)
meta.get_fee_for_message(&blockhash, &transaction, commitment)
}
}
}
Expand Down
12 changes: 5 additions & 7 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2678,7 +2678,7 @@ impl Bank {

#[deprecated(
since = "1.8.0",
note = "Please use `last_blockhash` and `get_fee_for_transaction` instead"
note = "Please use `last_blockhash` and `get_fee_for_message` instead"
)]
pub fn last_blockhash_with_fee_calculator(&self) -> (Hash, FeeCalculator) {
let blockhash_queue = self.blockhash_queue.read().unwrap();
Expand All @@ -2693,19 +2693,19 @@ impl Bank {
)
}

#[deprecated(since = "1.8.0", note = "Please use `get_fee_for_transaction` instead")]
#[deprecated(since = "1.8.0", note = "Please use `get_fee_for_message` instead")]
pub fn get_fee_calculator(&self, hash: &Hash) -> Option<FeeCalculator> {
let blockhash_queue = self.blockhash_queue.read().unwrap();
#[allow(deprecated)]
blockhash_queue.get_fee_calculator(hash).cloned()
}

#[deprecated(since = "1.8.0", note = "Please use `get_fee_for_transaction` instead")]
#[deprecated(since = "1.8.0", note = "Please use `get_fee_for_message` instead")]
pub fn get_fee_rate_governor(&self) -> &FeeRateGovernor {
&self.fee_rate_governor
}

pub fn get_fee_for_transaction(&self, hash: &Hash, message: &Message) -> Option<u64> {
pub fn get_fee_for_message(&self, hash: &Hash, message: &Message) -> Option<u64> {
let blockhash_queue = self.blockhash_queue.read().unwrap();
#[allow(deprecated)]
let fee_calculator = blockhash_queue.get_fee_calculator(hash)?;
Expand Down Expand Up @@ -2737,7 +2737,7 @@ impl Bank {

#[deprecated(
since = "1.8.0",
note = "Please use `confirmed_last_blockhash` and `get_fee_for_transaction` instead"
note = "Please use `confirmed_last_blockhash` and `get_fee_for_message` instead"
)]
pub fn confirmed_last_blockhash_with_fee_calculator(&self) -> (Hash, FeeCalculator) {
const NUM_BLOCKHASH_CONFIRMATIONS: usize = 3;
Expand All @@ -2758,11 +2758,9 @@ impl Bank {

let parents = self.parents();
if parents.is_empty() {
#[allow(deprecated)]
self.last_blockhash()
} else {
let index = NUM_BLOCKHASH_CONFIRMATIONS.min(parents.len() - 1);
#[allow(deprecated)]
parents[index].last_blockhash()
}
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/bank_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ impl SyncClient for BankClient {
Ok(self.bank.is_blockhash_valid(blockhash))
}

fn get_fee_for_transaction(&self, blockhash: &Hash, message: &Message) -> Result<u64> {
fn get_fee_for_message(&self, blockhash: &Hash, message: &Message) -> Result<u64> {
self.bank
.get_fee_for_transaction(blockhash, message)
.get_fee_for_message(blockhash, message)
.ok_or_else(|| {
TransportError::IoError(io::Error::new(
io::ErrorKind::Other,
Expand Down
2 changes: 1 addition & 1 deletion sdk/program/src/fee_calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl FeeCalculator {
let mut num_secp256k1_signatures: u64 = 0;
for instruction in &message.instructions {
let program_index = instruction.program_id_index as usize;
// Transaction may not be sanitized here
// Message may not be sanitized here
if program_index < message.account_keys.len() {
let id = message.account_keys[program_index];
if secp256k1_program::check_id(&id) && !instruction.data.is_empty() {
Expand Down
Loading

0 comments on commit 8d5a44c

Please sign in to comment.