Deprecate FeeCalculator returning APIs (#19120)
This commit is contained in:
375
rpc/src/rpc.rs
375
rpc/src/rpc.rs
@ -60,6 +60,7 @@ use {
|
||||
epoch_schedule::EpochSchedule,
|
||||
exit::Exit,
|
||||
hash::Hash,
|
||||
message::Message,
|
||||
pubkey::Pubkey,
|
||||
sanitize::Sanitize,
|
||||
signature::{Keypair, Signature, Signer},
|
||||
@ -80,6 +81,7 @@ use {
|
||||
state::{Account as TokenAccount, Mint},
|
||||
},
|
||||
std::{
|
||||
any::type_name,
|
||||
cmp::{max, min},
|
||||
collections::{HashMap, HashSet},
|
||||
net::SocketAddr,
|
||||
@ -531,7 +533,8 @@ impl JsonRpcRequestProcessor {
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> RpcResponse<RpcBlockhashFeeCalculator> {
|
||||
let bank = self.bank(commitment);
|
||||
let (blockhash, fee_calculator) = bank.confirmed_last_blockhash();
|
||||
#[allow(deprecated)]
|
||||
let (blockhash, fee_calculator) = bank.confirmed_last_blockhash_with_fee_calculator();
|
||||
new_response(
|
||||
&bank,
|
||||
RpcBlockhashFeeCalculator {
|
||||
@ -543,7 +546,8 @@ impl JsonRpcRequestProcessor {
|
||||
|
||||
fn get_fees(&self, commitment: Option<CommitmentConfig>) -> RpcResponse<RpcFees> {
|
||||
let bank = self.bank(commitment);
|
||||
let (blockhash, fee_calculator) = bank.confirmed_last_blockhash();
|
||||
#[allow(deprecated)]
|
||||
let (blockhash, fee_calculator) = bank.confirmed_last_blockhash_with_fee_calculator();
|
||||
#[allow(deprecated)]
|
||||
let last_valid_slot = bank
|
||||
.get_blockhash_last_valid_slot(&blockhash)
|
||||
@ -568,6 +572,7 @@ impl JsonRpcRequestProcessor {
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> RpcResponse<Option<RpcFeeCalculator>> {
|
||||
let bank = self.bank(commitment);
|
||||
#[allow(deprecated)]
|
||||
let fee_calculator = bank.get_fee_calculator(blockhash);
|
||||
new_response(
|
||||
&bank,
|
||||
@ -577,6 +582,7 @@ impl JsonRpcRequestProcessor {
|
||||
|
||||
fn get_fee_rate_governor(&self) -> RpcResponse<RpcFeeRateGovernor> {
|
||||
let bank = self.bank(None);
|
||||
#[allow(deprecated)]
|
||||
let fee_rate_governor = bank.get_fee_rate_governor();
|
||||
new_response(
|
||||
&bank,
|
||||
@ -1896,6 +1902,45 @@ impl JsonRpcRequestProcessor {
|
||||
self.get_filtered_program_accounts(bank, &spl_token_id_v2_0(), filters)
|
||||
}
|
||||
}
|
||||
|
||||
fn get_latest_blockhash(
|
||||
&self,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> RpcResponse<RpcBlockhash> {
|
||||
let bank = self.bank(commitment);
|
||||
let blockhash = bank.last_blockhash();
|
||||
let last_valid_block_height = bank
|
||||
.get_blockhash_last_valid_block_height(&blockhash)
|
||||
.expect("bank blockhash queue should contain blockhash");
|
||||
new_response(
|
||||
&bank,
|
||||
RpcBlockhash {
|
||||
blockhash: blockhash.to_string(),
|
||||
last_valid_block_height,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn is_blockhash_valid(
|
||||
&self,
|
||||
blockhash: &Hash,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> RpcResponse<bool> {
|
||||
let bank = self.bank(commitment);
|
||||
let is_valid = bank.is_blockhash_valid(blockhash);
|
||||
new_response(&bank, is_valid)
|
||||
}
|
||||
|
||||
fn get_fee_for_message(
|
||||
&self,
|
||||
blockhash: &Hash,
|
||||
message: &Message,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> Result<RpcResponse<Option<u64>>> {
|
||||
let bank = self.bank(commitment);
|
||||
let fee = bank.get_fee_for_message(blockhash, message);
|
||||
Ok(new_response(&bank, fee))
|
||||
}
|
||||
}
|
||||
|
||||
fn verify_transaction(
|
||||
@ -2410,34 +2455,6 @@ pub mod rpc_bank {
|
||||
#[rpc(meta, name = "getEpochSchedule")]
|
||||
fn get_epoch_schedule(&self, meta: Self::Metadata) -> Result<EpochSchedule>;
|
||||
|
||||
#[rpc(meta, name = "getRecentBlockhash")]
|
||||
fn get_recent_blockhash(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> Result<RpcResponse<RpcBlockhashFeeCalculator>>;
|
||||
|
||||
#[rpc(meta, name = "getFees")]
|
||||
fn get_fees(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> Result<RpcResponse<RpcFees>>;
|
||||
|
||||
#[rpc(meta, name = "getFeeCalculatorForBlockhash")]
|
||||
fn get_fee_calculator_for_blockhash(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
blockhash: String,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> Result<RpcResponse<Option<RpcFeeCalculator>>>;
|
||||
|
||||
#[rpc(meta, name = "getFeeRateGovernor")]
|
||||
fn get_fee_rate_governor(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
) -> Result<RpcResponse<RpcFeeRateGovernor>>;
|
||||
|
||||
#[rpc(meta, name = "getSlotLeader")]
|
||||
fn get_slot_leader(
|
||||
&self,
|
||||
@ -2500,44 +2517,6 @@ pub mod rpc_bank {
|
||||
Ok(meta.get_epoch_schedule())
|
||||
}
|
||||
|
||||
fn get_recent_blockhash(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> Result<RpcResponse<RpcBlockhashFeeCalculator>> {
|
||||
debug!("get_recent_blockhash rpc request received");
|
||||
Ok(meta.get_recent_blockhash(commitment))
|
||||
}
|
||||
|
||||
fn get_fees(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> Result<RpcResponse<RpcFees>> {
|
||||
debug!("get_fees rpc request received");
|
||||
Ok(meta.get_fees(commitment))
|
||||
}
|
||||
|
||||
fn get_fee_calculator_for_blockhash(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
blockhash: String,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> Result<RpcResponse<Option<RpcFeeCalculator>>> {
|
||||
debug!("get_fee_calculator_for_blockhash rpc request received");
|
||||
let blockhash = Hash::from_str(&blockhash)
|
||||
.map_err(|e| Error::invalid_params(format!("{:?}", e)))?;
|
||||
Ok(meta.get_fee_calculator_for_blockhash(&blockhash, commitment))
|
||||
}
|
||||
|
||||
fn get_fee_rate_governor(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
) -> Result<RpcResponse<RpcFeeRateGovernor>> {
|
||||
debug!("get_fee_rate_governor rpc request received");
|
||||
Ok(meta.get_fee_rate_governor())
|
||||
}
|
||||
|
||||
fn get_slot_leader(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
@ -3084,6 +3063,31 @@ pub mod rpc_full {
|
||||
|
||||
#[rpc(meta, name = "getFirstAvailableBlock")]
|
||||
fn get_first_available_block(&self, meta: Self::Metadata) -> BoxFuture<Result<Slot>>;
|
||||
|
||||
#[rpc(meta, name = "getLatestBlockhash")]
|
||||
fn get_latest_blockhash(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> Result<RpcResponse<RpcBlockhash>>;
|
||||
|
||||
#[rpc(meta, name = "isBlockhashValid")]
|
||||
fn is_blockhash_valid(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
blockhash: String,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> Result<RpcResponse<bool>>;
|
||||
|
||||
#[rpc(meta, name = "getFeeForMessage")]
|
||||
fn get_fee_for_message(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
blockhash: String,
|
||||
data: String,
|
||||
encoding: UiTransactionEncoding,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> Result<RpcResponse<Option<u64>>>;
|
||||
}
|
||||
|
||||
pub struct FullImpl;
|
||||
@ -3232,7 +3236,7 @@ pub mod rpc_full {
|
||||
let blockhash = if let Some(blockhash) = config.recent_blockhash {
|
||||
verify_hash(&blockhash)?
|
||||
} else {
|
||||
bank.confirmed_last_blockhash().0
|
||||
bank.confirmed_last_blockhash()
|
||||
};
|
||||
let last_valid_block_height = bank
|
||||
.get_blockhash_last_valid_block_height(&blockhash)
|
||||
@ -3269,7 +3273,8 @@ pub mod rpc_full {
|
||||
debug!("send_transaction rpc request received");
|
||||
let config = config.unwrap_or_default();
|
||||
let encoding = config.encoding.unwrap_or(UiTransactionEncoding::Base58);
|
||||
let (wire_transaction, transaction) = deserialize_transaction(data, encoding)?;
|
||||
let (wire_transaction, transaction) =
|
||||
decode_and_deserialize::<Transaction>(data, encoding)?;
|
||||
|
||||
let preflight_commitment = config
|
||||
.preflight_commitment
|
||||
@ -3369,7 +3374,7 @@ pub mod rpc_full {
|
||||
debug!("simulate_transaction rpc request received");
|
||||
let config = config.unwrap_or_default();
|
||||
let encoding = config.encoding.unwrap_or(UiTransactionEncoding::Base58);
|
||||
let (_, mut transaction) = deserialize_transaction(data, encoding)?;
|
||||
let (_, mut transaction) = decode_and_deserialize::<Transaction>(data, encoding)?;
|
||||
|
||||
let bank = &*meta.bank(config.commitment);
|
||||
if config.sig_verify {
|
||||
@ -3578,10 +3583,126 @@ pub mod rpc_full {
|
||||
|
||||
Box::pin(async move { meta.get_inflation_reward(addresses, config).await })
|
||||
}
|
||||
|
||||
fn get_latest_blockhash(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> Result<RpcResponse<RpcBlockhash>> {
|
||||
debug!("get_latest_blockhash rpc request received");
|
||||
Ok(meta.get_latest_blockhash(commitment))
|
||||
}
|
||||
|
||||
fn is_blockhash_valid(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
blockhash: String,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> Result<RpcResponse<bool>> {
|
||||
let blockhash = Hash::from_str(&blockhash)
|
||||
.map_err(|e| Error::invalid_params(format!("{:?}", e)))?;
|
||||
Ok(meta.is_blockhash_valid(&blockhash, commitment))
|
||||
}
|
||||
|
||||
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_message rpc request received");
|
||||
let blockhash = Hash::from_str(&blockhash)
|
||||
.map_err(|e| Error::invalid_params(format!("{:?}", e)))?;
|
||||
let (_, message) = decode_and_deserialize::<Message>(data, encoding)?;
|
||||
meta.get_fee_for_message(&blockhash, &message, commitment)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Deprecated RPC methods, collected for easy deactivation and removal in v1.8
|
||||
// RPC methods deprecated in v1.8
|
||||
pub mod rpc_deprecated_v1_8 {
|
||||
#![allow(deprecated)]
|
||||
use super::*;
|
||||
#[rpc]
|
||||
pub trait DeprecatedV1_8 {
|
||||
type Metadata;
|
||||
|
||||
#[rpc(meta, name = "getRecentBlockhash")]
|
||||
fn get_recent_blockhash(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> Result<RpcResponse<RpcBlockhashFeeCalculator>>;
|
||||
|
||||
#[rpc(meta, name = "getFees")]
|
||||
fn get_fees(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> Result<RpcResponse<RpcFees>>;
|
||||
|
||||
#[rpc(meta, name = "getFeeCalculatorForBlockhash")]
|
||||
fn get_fee_calculator_for_blockhash(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
blockhash: String,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> Result<RpcResponse<Option<RpcFeeCalculator>>>;
|
||||
|
||||
#[rpc(meta, name = "getFeeRateGovernor")]
|
||||
fn get_fee_rate_governor(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
) -> Result<RpcResponse<RpcFeeRateGovernor>>;
|
||||
}
|
||||
|
||||
pub struct DeprecatedV1_8Impl;
|
||||
impl DeprecatedV1_8 for DeprecatedV1_8Impl {
|
||||
type Metadata = JsonRpcRequestProcessor;
|
||||
|
||||
fn get_recent_blockhash(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> Result<RpcResponse<RpcBlockhashFeeCalculator>> {
|
||||
debug!("get_recent_blockhash rpc request received");
|
||||
Ok(meta.get_recent_blockhash(commitment))
|
||||
}
|
||||
|
||||
fn get_fees(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> Result<RpcResponse<RpcFees>> {
|
||||
debug!("get_fees rpc request received");
|
||||
Ok(meta.get_fees(commitment))
|
||||
}
|
||||
|
||||
fn get_fee_calculator_for_blockhash(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
blockhash: String,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) -> Result<RpcResponse<Option<RpcFeeCalculator>>> {
|
||||
debug!("get_fee_calculator_for_blockhash rpc request received");
|
||||
let blockhash = Hash::from_str(&blockhash)
|
||||
.map_err(|e| Error::invalid_params(format!("{:?}", e)))?;
|
||||
Ok(meta.get_fee_calculator_for_blockhash(&blockhash, commitment))
|
||||
}
|
||||
|
||||
fn get_fee_rate_governor(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
) -> Result<RpcResponse<RpcFeeRateGovernor>> {
|
||||
debug!("get_fee_rate_governor rpc request received");
|
||||
Ok(meta.get_fee_rate_governor())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// RPC methods deprecated in v1.7
|
||||
pub mod rpc_deprecated_v1_7 {
|
||||
#![allow(deprecated)]
|
||||
use super::*;
|
||||
@ -3874,51 +3995,56 @@ pub mod rpc_obsolete_v1_7 {
|
||||
}
|
||||
}
|
||||
|
||||
const WORST_CASE_BASE58_TX: usize = 1683; // Golden, bump if PACKET_DATA_SIZE changes
|
||||
const WORST_CASE_BASE64_TX: usize = 1644; // Golden, bump if PACKET_DATA_SIZE changes
|
||||
fn deserialize_transaction(
|
||||
encoded_transaction: String,
|
||||
const MAX_BASE58_SIZE: usize = 1683; // Golden, bump if PACKET_DATA_SIZE changes
|
||||
const MAX_BASE64_SIZE: usize = 1644; // Golden, bump if PACKET_DATA_SIZE changes
|
||||
fn decode_and_deserialize<T>(
|
||||
encoded: String,
|
||||
encoding: UiTransactionEncoding,
|
||||
) -> Result<(Vec<u8>, Transaction)> {
|
||||
let wire_transaction = match encoding {
|
||||
) -> Result<(Vec<u8>, T)>
|
||||
where
|
||||
T: serde::de::DeserializeOwned + Sanitize,
|
||||
{
|
||||
let wire_output = match encoding {
|
||||
UiTransactionEncoding::Base58 => {
|
||||
inc_new_counter_info!("rpc-base58_encoded_tx", 1);
|
||||
if encoded_transaction.len() > WORST_CASE_BASE58_TX {
|
||||
if encoded.len() > MAX_BASE58_SIZE {
|
||||
return Err(Error::invalid_params(format!(
|
||||
"encoded transaction too large: {} bytes (max: encoded/raw {}/{})",
|
||||
encoded_transaction.len(),
|
||||
WORST_CASE_BASE58_TX,
|
||||
"encoded {} too large: {} bytes (max: encoded/raw {}/{})",
|
||||
type_name::<T>(),
|
||||
encoded.len(),
|
||||
MAX_BASE58_SIZE,
|
||||
PACKET_DATA_SIZE,
|
||||
)));
|
||||
}
|
||||
bs58::decode(encoded_transaction)
|
||||
bs58::decode(encoded)
|
||||
.into_vec()
|
||||
.map_err(|e| Error::invalid_params(format!("{:?}", e)))?
|
||||
}
|
||||
UiTransactionEncoding::Base64 => {
|
||||
inc_new_counter_info!("rpc-base64_encoded_tx", 1);
|
||||
if encoded_transaction.len() > WORST_CASE_BASE64_TX {
|
||||
if encoded.len() > MAX_BASE64_SIZE {
|
||||
return Err(Error::invalid_params(format!(
|
||||
"encoded transaction too large: {} bytes (max: encoded/raw {}/{})",
|
||||
encoded_transaction.len(),
|
||||
WORST_CASE_BASE64_TX,
|
||||
"encoded {} too large: {} bytes (max: encoded/raw {}/{})",
|
||||
type_name::<T>(),
|
||||
encoded.len(),
|
||||
MAX_BASE64_SIZE,
|
||||
PACKET_DATA_SIZE,
|
||||
)));
|
||||
}
|
||||
base64::decode(encoded_transaction)
|
||||
.map_err(|e| Error::invalid_params(format!("{:?}", e)))?
|
||||
base64::decode(encoded).map_err(|e| Error::invalid_params(format!("{:?}", e)))?
|
||||
}
|
||||
_ => {
|
||||
return Err(Error::invalid_params(format!(
|
||||
"unsupported transaction encoding: {}. Supported encodings: base58, base64",
|
||||
"unsupported encoding: {}. Supported encodings: base58, base64",
|
||||
encoding
|
||||
)))
|
||||
}
|
||||
};
|
||||
if wire_transaction.len() > PACKET_DATA_SIZE {
|
||||
if wire_output.len() > PACKET_DATA_SIZE {
|
||||
let err = format!(
|
||||
"transaction too large: {} bytes (max: {} bytes)",
|
||||
wire_transaction.len(),
|
||||
"encoded {} too large: {} bytes (max: {} bytes)",
|
||||
type_name::<T>(),
|
||||
wire_output.len(),
|
||||
PACKET_DATA_SIZE
|
||||
);
|
||||
info!("{}", err);
|
||||
@ -3928,22 +4054,23 @@ fn deserialize_transaction(
|
||||
.with_limit(PACKET_DATA_SIZE as u64)
|
||||
.with_fixint_encoding()
|
||||
.allow_trailing_bytes()
|
||||
.deserialize_from(&wire_transaction[..])
|
||||
.deserialize_from(&wire_output[..])
|
||||
.map_err(|err| {
|
||||
info!("transaction deserialize error: {:?}", err);
|
||||
info!("deserialize error: {}", err);
|
||||
Error::invalid_params(&err.to_string())
|
||||
})
|
||||
.and_then(|transaction: Transaction| {
|
||||
if let Err(err) = transaction.sanitize() {
|
||||
.and_then(|output: T| {
|
||||
if let Err(err) = output.sanitize() {
|
||||
Err(Error::invalid_params(format!(
|
||||
"invalid transaction: {}",
|
||||
"invalid {}: {}",
|
||||
type_name::<T>(),
|
||||
err
|
||||
)))
|
||||
} else {
|
||||
Ok(transaction)
|
||||
Ok(output)
|
||||
}
|
||||
})
|
||||
.map(|transaction| (wire_transaction, transaction))
|
||||
.map(|output| (wire_output, output))
|
||||
}
|
||||
|
||||
pub(crate) fn create_validator_exit(exit: &Arc<AtomicBool>) -> Arc<RwLock<Exit>> {
|
||||
@ -3966,7 +4093,7 @@ pub fn create_test_transactions_and_populate_blockstore(
|
||||
let keypair2 = keypairs[2];
|
||||
let keypair3 = keypairs[3];
|
||||
let slot = bank.slot();
|
||||
let blockhash = bank.confirmed_last_blockhash().0;
|
||||
let blockhash = bank.confirmed_last_blockhash();
|
||||
|
||||
// Generate transactions for processing
|
||||
// Successful transaction
|
||||
@ -4032,7 +4159,9 @@ pub fn create_test_transactions_and_populate_blockstore(
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use {
|
||||
super::{rpc_accounts::*, rpc_bank::*, rpc_full::*, rpc_minimal::*, *},
|
||||
super::{
|
||||
rpc_accounts::*, rpc_bank::*, rpc_deprecated_v1_8::*, rpc_full::*, rpc_minimal::*, *,
|
||||
},
|
||||
crate::{
|
||||
optimistically_confirmed_bank_tracker::{
|
||||
BankNotification, OptimisticallyConfirmedBankTracker,
|
||||
@ -4196,7 +4325,7 @@ pub mod tests {
|
||||
let exit = Arc::new(AtomicBool::new(false));
|
||||
let validator_exit = create_validator_exit(&exit);
|
||||
|
||||
let blockhash = bank.confirmed_last_blockhash().0;
|
||||
let blockhash = bank.confirmed_last_blockhash();
|
||||
let tx = system_transaction::transfer(&alice, pubkey, 20, blockhash);
|
||||
bank.process_transaction(&tx).expect("process transaction");
|
||||
let tx =
|
||||
@ -4267,6 +4396,7 @@ pub mod tests {
|
||||
io.extend_with(rpc_bank::BankDataImpl.to_delegate());
|
||||
io.extend_with(rpc_accounts::AccountsDataImpl.to_delegate());
|
||||
io.extend_with(rpc_full::FullImpl.to_delegate());
|
||||
io.extend_with(rpc_deprecated_v1_8::DeprecatedV1_8Impl.to_delegate());
|
||||
RpcHandler {
|
||||
io,
|
||||
meta,
|
||||
@ -5675,6 +5805,7 @@ pub mod tests {
|
||||
let bob_pubkey = solana_sdk::pubkey::new_rand();
|
||||
let RpcHandler { io, meta, bank, .. } = start_rpc_handler_with_tx(&bob_pubkey);
|
||||
|
||||
#[allow(deprecated)]
|
||||
let (blockhash, fee_calculator) = bank.last_blockhash_with_fee_calculator();
|
||||
let fee_calculator = RpcFeeCalculator { fee_calculator };
|
||||
|
||||
@ -5855,7 +5986,7 @@ pub mod tests {
|
||||
assert_eq!(
|
||||
res,
|
||||
Some(
|
||||
r#"{"jsonrpc":"2.0","error":{"code":-32602,"message":"invalid transaction: index out of bounds"},"id":1}"#.to_string(),
|
||||
r#"{"jsonrpc":"2.0","error":{"code":-32602,"message":"invalid solana_sdk::transaction::Transaction: index out of bounds"},"id":1}"#.to_string(),
|
||||
)
|
||||
);
|
||||
let mut bad_transaction = system_transaction::transfer(
|
||||
@ -5919,7 +6050,7 @@ pub mod tests {
|
||||
assert_eq!(
|
||||
res,
|
||||
Some(
|
||||
r#"{"jsonrpc":"2.0","error":{"code":-32602,"message":"invalid transaction: index out of bounds"},"id":1}"#.to_string(),
|
||||
r#"{"jsonrpc":"2.0","error":{"code":-32602,"message":"invalid solana_sdk::transaction::Transaction: index out of bounds"},"id":1}"#.to_string(),
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -7615,66 +7746,68 @@ pub mod tests {
|
||||
fn test_worst_case_encoded_tx_goldens() {
|
||||
let ff_tx = vec![0xffu8; PACKET_DATA_SIZE];
|
||||
let tx58 = bs58::encode(&ff_tx).into_string();
|
||||
assert_eq!(tx58.len(), WORST_CASE_BASE58_TX);
|
||||
assert_eq!(tx58.len(), MAX_BASE58_SIZE);
|
||||
let tx64 = base64::encode(&ff_tx);
|
||||
assert_eq!(tx64.len(), WORST_CASE_BASE64_TX);
|
||||
assert_eq!(tx64.len(), MAX_BASE64_SIZE);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_deserialize_transaction_too_large_payloads_fail() {
|
||||
fn test_decode_and_deserialize_too_large_payloads_fail() {
|
||||
// +2 because +1 still fits in base64 encoded worst-case
|
||||
let too_big = PACKET_DATA_SIZE + 2;
|
||||
let tx_ser = vec![0xffu8; too_big];
|
||||
let tx58 = bs58::encode(&tx_ser).into_string();
|
||||
let tx58_len = tx58.len();
|
||||
let expect58 = Error::invalid_params(format!(
|
||||
"encoded transaction too large: {} bytes (max: encoded/raw {}/{})",
|
||||
tx58_len, WORST_CASE_BASE58_TX, PACKET_DATA_SIZE,
|
||||
"encoded solana_sdk::transaction::Transaction too large: {} bytes (max: encoded/raw {}/{})",
|
||||
tx58_len, MAX_BASE58_SIZE, PACKET_DATA_SIZE,
|
||||
));
|
||||
assert_eq!(
|
||||
deserialize_transaction(tx58, UiTransactionEncoding::Base58).unwrap_err(),
|
||||
decode_and_deserialize::<Transaction>(tx58, UiTransactionEncoding::Base58).unwrap_err(),
|
||||
expect58
|
||||
);
|
||||
let tx64 = base64::encode(&tx_ser);
|
||||
let tx64_len = tx64.len();
|
||||
let expect64 = Error::invalid_params(format!(
|
||||
"encoded transaction too large: {} bytes (max: encoded/raw {}/{})",
|
||||
tx64_len, WORST_CASE_BASE64_TX, PACKET_DATA_SIZE,
|
||||
"encoded solana_sdk::transaction::Transaction too large: {} bytes (max: encoded/raw {}/{})",
|
||||
tx64_len, MAX_BASE64_SIZE, PACKET_DATA_SIZE,
|
||||
));
|
||||
assert_eq!(
|
||||
deserialize_transaction(tx64, UiTransactionEncoding::Base64).unwrap_err(),
|
||||
decode_and_deserialize::<Transaction>(tx64, UiTransactionEncoding::Base64).unwrap_err(),
|
||||
expect64
|
||||
);
|
||||
let too_big = PACKET_DATA_SIZE + 1;
|
||||
let tx_ser = vec![0x00u8; too_big];
|
||||
let tx58 = bs58::encode(&tx_ser).into_string();
|
||||
let expect = Error::invalid_params(format!(
|
||||
"transaction too large: {} bytes (max: {} bytes)",
|
||||
"encoded solana_sdk::transaction::Transaction too large: {} bytes (max: {} bytes)",
|
||||
too_big, PACKET_DATA_SIZE
|
||||
));
|
||||
assert_eq!(
|
||||
deserialize_transaction(tx58, UiTransactionEncoding::Base58).unwrap_err(),
|
||||
decode_and_deserialize::<Transaction>(tx58, UiTransactionEncoding::Base58).unwrap_err(),
|
||||
expect
|
||||
);
|
||||
let tx64 = base64::encode(&tx_ser);
|
||||
assert_eq!(
|
||||
deserialize_transaction(tx64, UiTransactionEncoding::Base64).unwrap_err(),
|
||||
decode_and_deserialize::<Transaction>(tx64, UiTransactionEncoding::Base64).unwrap_err(),
|
||||
expect
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_deserialize_transaction_unsanitary() {
|
||||
fn test_decode_and_deserialize_unsanitary() {
|
||||
let unsanitary_tx58 = "ju9xZWuDBX4pRxX2oZkTjxU5jB4SSTgEGhX8bQ8PURNzyzqKMPPpNvWihx8zUe\
|
||||
FfrbVNoAaEsNKZvGzAnTDy5bhNT9kt6KFCTBixpvrLCzg4M5UdFUQYrn1gdgjX\
|
||||
pLHxcaShD81xBNaFDgnA2nkkdHnKtZt4hVSfKAmw3VRZbjrZ7L2fKZBx21CwsG\
|
||||
hD6onjM2M3qZW5C8J6d1pj41MxKmZgPBSha3MyKkNLkAGFASK"
|
||||
.to_string();
|
||||
|
||||
let expect58 =
|
||||
Error::invalid_params("invalid transaction: index out of bounds".to_string());
|
||||
let expect58 = Error::invalid_params(
|
||||
"invalid solana_sdk::transaction::Transaction: index out of bounds".to_string(),
|
||||
);
|
||||
assert_eq!(
|
||||
deserialize_transaction(unsanitary_tx58, UiTransactionEncoding::Base58).unwrap_err(),
|
||||
decode_and_deserialize::<Transaction>(unsanitary_tx58, UiTransactionEncoding::Base58)
|
||||
.unwrap_err(),
|
||||
expect58
|
||||
);
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ use {
|
||||
max_slots::MaxSlots,
|
||||
optimistically_confirmed_bank_tracker::OptimisticallyConfirmedBank,
|
||||
rpc::{
|
||||
rpc_accounts::*, rpc_bank::*, rpc_deprecated_v1_7::*, rpc_full::*, rpc_minimal::*,
|
||||
rpc_obsolete_v1_7::*, *,
|
||||
rpc_accounts::*, rpc_bank::*, rpc_deprecated_v1_7::*, rpc_deprecated_v1_8::*,
|
||||
rpc_full::*, rpc_minimal::*, rpc_obsolete_v1_7::*, *,
|
||||
},
|
||||
rpc_health::*,
|
||||
send_transaction_service::{LeaderInfo, SendTransactionService},
|
||||
@ -408,6 +408,7 @@ impl JsonRpcService {
|
||||
io.extend_with(rpc_accounts::AccountsDataImpl.to_delegate());
|
||||
io.extend_with(rpc_full::FullImpl.to_delegate());
|
||||
io.extend_with(rpc_deprecated_v1_7::DeprecatedV1_7Impl.to_delegate());
|
||||
io.extend_with(rpc_deprecated_v1_8::DeprecatedV1_8Impl.to_delegate());
|
||||
}
|
||||
if obsolete_v1_7_api {
|
||||
io.extend_with(rpc_obsolete_v1_7::ObsoleteV1_7Impl.to_delegate());
|
||||
|
@ -106,9 +106,11 @@ impl TransactionStatusService {
|
||||
let fee_calculator = nonce_rollback
|
||||
.map(|nonce_rollback| nonce_rollback.fee_calculator())
|
||||
.unwrap_or_else(|| {
|
||||
#[allow(deprecated)]
|
||||
bank.get_fee_calculator(&transaction.message().recent_blockhash)
|
||||
})
|
||||
.expect("FeeCalculator must exist");
|
||||
#[allow(deprecated)]
|
||||
let fee = fee_calculator.calculate_fee(transaction.message());
|
||||
let (writable_keys, readonly_keys) =
|
||||
transaction.message.get_account_keys_by_lock_type();
|
||||
|
Reference in New Issue
Block a user