Deprecate FeeCalculator returning APIs (#19120)
This commit is contained in:
@ -19,6 +19,7 @@ pub enum Source {
|
||||
}
|
||||
|
||||
impl Source {
|
||||
#[deprecated(since = "1.8.0", note = "Please use `get_blockhash` instead")]
|
||||
pub fn get_blockhash_and_fee_calculator(
|
||||
&self,
|
||||
rpc_client: &RpcClient,
|
||||
@ -26,6 +27,7 @@ impl Source {
|
||||
) -> Result<(Hash, FeeCalculator), Box<dyn std::error::Error>> {
|
||||
match self {
|
||||
Self::Cluster => {
|
||||
#[allow(deprecated)]
|
||||
let res = rpc_client
|
||||
.get_recent_blockhash_with_commitment(commitment)?
|
||||
.value;
|
||||
@ -39,6 +41,10 @@ impl Source {
|
||||
}
|
||||
}
|
||||
|
||||
#[deprecated(
|
||||
since = "1.8.0",
|
||||
note = "Please do not use, will no longer be available in the future"
|
||||
)]
|
||||
pub fn get_fee_calculator(
|
||||
&self,
|
||||
rpc_client: &RpcClient,
|
||||
@ -47,6 +53,7 @@ impl Source {
|
||||
) -> Result<Option<FeeCalculator>, Box<dyn std::error::Error>> {
|
||||
match self {
|
||||
Self::Cluster => {
|
||||
#[allow(deprecated)]
|
||||
let res = rpc_client
|
||||
.get_fee_calculator_for_blockhash_with_commitment(blockhash, commitment)?
|
||||
.value;
|
||||
@ -61,6 +68,40 @@ impl Source {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_blockhash(
|
||||
&self,
|
||||
rpc_client: &RpcClient,
|
||||
commitment: CommitmentConfig,
|
||||
) -> Result<Hash, Box<dyn std::error::Error>> {
|
||||
match self {
|
||||
Self::Cluster => {
|
||||
let (blockhash, _) = rpc_client.get_latest_blockhash_with_commitment(commitment)?;
|
||||
Ok(blockhash)
|
||||
}
|
||||
Self::NonceAccount(ref pubkey) => {
|
||||
let data = nonce_utils::get_account_with_commitment(rpc_client, pubkey, commitment)
|
||||
.and_then(|ref a| nonce_utils::data_from_account(a))?;
|
||||
Ok(data.blockhash)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_blockhash_valid(
|
||||
&self,
|
||||
rpc_client: &RpcClient,
|
||||
blockhash: &Hash,
|
||||
commitment: CommitmentConfig,
|
||||
) -> Result<bool, Box<dyn std::error::Error>> {
|
||||
Ok(match self {
|
||||
Self::Cluster => rpc_client.is_blockhash_valid(blockhash, commitment)?,
|
||||
Self::NonceAccount(ref pubkey) => {
|
||||
let _ = nonce_utils::get_account_with_commitment(rpc_client, pubkey, commitment)
|
||||
.and_then(|ref a| nonce_utils::data_from_account(a))?;
|
||||
true
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
@ -90,6 +131,7 @@ impl BlockhashQuery {
|
||||
BlockhashQuery::new(blockhash, sign_only, nonce_account)
|
||||
}
|
||||
|
||||
#[deprecated(since = "1.8.0", note = "Please use `get_blockhash` instead")]
|
||||
pub fn get_blockhash_and_fee_calculator(
|
||||
&self,
|
||||
rpc_client: &RpcClient,
|
||||
@ -98,16 +140,36 @@ impl BlockhashQuery {
|
||||
match self {
|
||||
BlockhashQuery::None(hash) => Ok((*hash, FeeCalculator::default())),
|
||||
BlockhashQuery::FeeCalculator(source, hash) => {
|
||||
#[allow(deprecated)]
|
||||
let fee_calculator = source
|
||||
.get_fee_calculator(rpc_client, hash, commitment)?
|
||||
.ok_or(format!("Hash has expired {:?}", hash))?;
|
||||
Ok((*hash, fee_calculator))
|
||||
}
|
||||
BlockhashQuery::All(source) => {
|
||||
BlockhashQuery::All(source) =>
|
||||
{
|
||||
#[allow(deprecated)]
|
||||
source.get_blockhash_and_fee_calculator(rpc_client, commitment)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_blockhash(
|
||||
&self,
|
||||
rpc_client: &RpcClient,
|
||||
commitment: CommitmentConfig,
|
||||
) -> Result<Hash, Box<dyn std::error::Error>> {
|
||||
match self {
|
||||
BlockhashQuery::None(hash) => Ok(*hash),
|
||||
BlockhashQuery::FeeCalculator(source, hash) => {
|
||||
if !source.is_blockhash_valid(rpc_client, hash, commitment)? {
|
||||
return Err(format!("Hash has expired {:?}", hash).into());
|
||||
}
|
||||
Ok(*hash)
|
||||
}
|
||||
BlockhashQuery::All(source) => source.get_blockhash(rpc_client, commitment),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for BlockhashQuery {
|
||||
@ -282,6 +344,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn test_blockhash_query_get_blockhash_fee_calc() {
|
||||
let test_blockhash = hash(&[0u8]);
|
||||
let rpc_blockhash = hash(&[1u8]);
|
||||
|
@ -6,9 +6,9 @@ use {
|
||||
rpc_config::RpcBlockProductionConfig,
|
||||
rpc_request::RpcRequest,
|
||||
rpc_response::{
|
||||
Response, RpcAccountBalance, RpcBlockProduction, RpcBlockProductionRange, RpcFees,
|
||||
RpcResponseContext, RpcSimulateTransactionResult, RpcStakeActivation, RpcSupply,
|
||||
RpcVersionInfo, RpcVoteAccountStatus, StakeActivationState,
|
||||
Response, RpcAccountBalance, RpcBlockProduction, RpcBlockProductionRange, RpcBlockhash,
|
||||
RpcFees, RpcResponseContext, RpcSimulateTransactionResult, RpcStakeActivation,
|
||||
RpcSupply, RpcVersionInfo, RpcVoteAccountStatus, StakeActivationState,
|
||||
},
|
||||
rpc_sender::RpcSender,
|
||||
},
|
||||
@ -271,6 +271,17 @@ impl RpcSender for MockSender {
|
||||
feature_set: Some(version.feature_set),
|
||||
})
|
||||
}
|
||||
"getLatestBlockhash" => serde_json::to_value(Response {
|
||||
context: RpcResponseContext { slot: 1 },
|
||||
value: RpcBlockhash {
|
||||
blockhash: PUBKEY.to_string(),
|
||||
last_valid_block_height: 0,
|
||||
},
|
||||
})?,
|
||||
"getFeeForMessage" => serde_json::to_value(Response {
|
||||
context: RpcResponseContext { slot: 1 },
|
||||
value: json!(Some(0)),
|
||||
})?,
|
||||
_ => Value::Null,
|
||||
};
|
||||
Ok(val)
|
||||
|
@ -38,6 +38,7 @@ use {
|
||||
epoch_schedule::EpochSchedule,
|
||||
fee_calculator::{FeeCalculator, FeeRateGovernor},
|
||||
hash::Hash,
|
||||
message::Message,
|
||||
pubkey::Pubkey,
|
||||
signature::Signature,
|
||||
transaction::{self, uses_durable_nonce, Transaction},
|
||||
@ -722,7 +723,7 @@ impl RpcClient {
|
||||
preflight_commitment: Some(preflight_commitment.commitment),
|
||||
..config
|
||||
};
|
||||
let serialized_encoded = serialize_encode_transaction(transaction, encoding)?;
|
||||
let serialized_encoded = serialize_and_encode::<Transaction>(transaction, encoding)?;
|
||||
let signature_base58_str: String = match self.send(
|
||||
RpcRequest::SendTransaction,
|
||||
json!([serialized_encoded, config]),
|
||||
@ -859,7 +860,7 @@ impl RpcClient {
|
||||
commitment: Some(commitment),
|
||||
..config
|
||||
};
|
||||
let serialized_encoded = serialize_encode_transaction(transaction, encoding)?;
|
||||
let serialized_encoded = serialize_and_encode::<Transaction>(transaction, encoding)?;
|
||||
self.send(
|
||||
RpcRequest::SimulateTransaction,
|
||||
json!([serialized_encoded, config]),
|
||||
@ -1981,9 +1982,8 @@ impl RpcClient {
|
||||
let signature = self.send_transaction(transaction)?;
|
||||
|
||||
let recent_blockhash = if uses_durable_nonce(transaction).is_some() {
|
||||
let (recent_blockhash, ..) = self
|
||||
.get_recent_blockhash_with_commitment(CommitmentConfig::processed())?
|
||||
.value;
|
||||
let (recent_blockhash, ..) =
|
||||
self.get_latest_blockhash_with_commitment(CommitmentConfig::processed())?;
|
||||
recent_blockhash
|
||||
} else {
|
||||
transaction.message.recent_blockhash
|
||||
@ -1994,13 +1994,9 @@ impl RpcClient {
|
||||
Some(Ok(_)) => return Ok(signature),
|
||||
Some(Err(e)) => return Err(e.into()),
|
||||
None => {
|
||||
let fee_calculator = self
|
||||
.get_fee_calculator_for_blockhash_with_commitment(
|
||||
&recent_blockhash,
|
||||
CommitmentConfig::processed(),
|
||||
)?
|
||||
.value;
|
||||
if fee_calculator.is_none() {
|
||||
if !self
|
||||
.is_blockhash_valid(&recent_blockhash, CommitmentConfig::processed())?
|
||||
{
|
||||
// Block hash is not found by some reason
|
||||
break 'sending;
|
||||
} else if cfg!(not(test))
|
||||
@ -2209,10 +2205,21 @@ impl RpcClient {
|
||||
)
|
||||
}
|
||||
|
||||
#[deprecated(
|
||||
since = "1.8.0",
|
||||
note = "Please use `get_latest_blockhash` and `get_fee_for_message` instead"
|
||||
)]
|
||||
#[allow(deprecated)]
|
||||
pub fn get_fees(&self) -> ClientResult<Fees> {
|
||||
#[allow(deprecated)]
|
||||
Ok(self.get_fees_with_commitment(self.commitment())?.value)
|
||||
}
|
||||
|
||||
#[deprecated(
|
||||
since = "1.8.0",
|
||||
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> {
|
||||
let Response {
|
||||
context,
|
||||
@ -2237,13 +2244,21 @@ impl RpcClient {
|
||||
})
|
||||
}
|
||||
|
||||
#[deprecated(since = "1.8.0", note = "Please use `get_latest_blockhash` instead")]
|
||||
#[allow(deprecated)]
|
||||
pub fn get_recent_blockhash(&self) -> ClientResult<(Hash, FeeCalculator)> {
|
||||
#[allow(deprecated)]
|
||||
let (blockhash, fee_calculator, _last_valid_slot) = self
|
||||
.get_recent_blockhash_with_commitment(self.commitment())?
|
||||
.value;
|
||||
Ok((blockhash, fee_calculator))
|
||||
}
|
||||
|
||||
#[deprecated(
|
||||
since = "1.8.0",
|
||||
note = "Please use `get_latest_blockhash_with_commitment` instead"
|
||||
)]
|
||||
#[allow(deprecated)]
|
||||
pub fn get_recent_blockhash_with_commitment(
|
||||
&self,
|
||||
commitment_config: CommitmentConfig,
|
||||
@ -2307,15 +2322,23 @@ impl RpcClient {
|
||||
})
|
||||
}
|
||||
|
||||
#[deprecated(since = "1.8.0", note = "Please `get_fee_for_message` instead")]
|
||||
#[allow(deprecated)]
|
||||
pub fn get_fee_calculator_for_blockhash(
|
||||
&self,
|
||||
blockhash: &Hash,
|
||||
) -> ClientResult<Option<FeeCalculator>> {
|
||||
#[allow(deprecated)]
|
||||
Ok(self
|
||||
.get_fee_calculator_for_blockhash_with_commitment(blockhash, self.commitment())?
|
||||
.value)
|
||||
}
|
||||
|
||||
#[deprecated(
|
||||
since = "1.8.0",
|
||||
note = "Please `get_latest_blockhash_with_commitment` and `get_fee_for_message` instead"
|
||||
)]
|
||||
#[allow(deprecated)]
|
||||
pub fn get_fee_calculator_for_blockhash_with_commitment(
|
||||
&self,
|
||||
blockhash: &Hash,
|
||||
@ -2335,6 +2358,11 @@ impl RpcClient {
|
||||
})
|
||||
}
|
||||
|
||||
#[deprecated(
|
||||
since = "1.8.0",
|
||||
note = "Please do not use, will no longer be available in the future"
|
||||
)]
|
||||
#[allow(deprecated)]
|
||||
pub fn get_fee_rate_governor(&self) -> RpcResult<FeeRateGovernor> {
|
||||
let Response {
|
||||
context,
|
||||
@ -2348,10 +2376,16 @@ impl RpcClient {
|
||||
})
|
||||
}
|
||||
|
||||
#[deprecated(
|
||||
since = "1.8.0",
|
||||
note = "Please use `get_new_latest_blockhash` instead"
|
||||
)]
|
||||
#[allow(deprecated)]
|
||||
pub fn get_new_blockhash(&self, blockhash: &Hash) -> ClientResult<(Hash, FeeCalculator)> {
|
||||
let mut num_retries = 0;
|
||||
let start = Instant::now();
|
||||
while start.elapsed().as_secs() < 5 {
|
||||
#[allow(deprecated)]
|
||||
if let Ok((new_blockhash, fee_calculator)) = self.get_recent_blockhash() {
|
||||
if new_blockhash != *blockhash {
|
||||
return Ok((new_blockhash, fee_calculator));
|
||||
@ -2831,8 +2865,7 @@ impl RpcClient {
|
||||
config: RpcSendTransactionConfig,
|
||||
) -> ClientResult<Signature> {
|
||||
let recent_blockhash = if uses_durable_nonce(transaction).is_some() {
|
||||
self.get_recent_blockhash_with_commitment(CommitmentConfig::processed())?
|
||||
.value
|
||||
self.get_latest_blockhash_with_commitment(CommitmentConfig::processed())?
|
||||
.0
|
||||
} else {
|
||||
transaction.message.recent_blockhash
|
||||
@ -2872,13 +2905,8 @@ impl RpcClient {
|
||||
let status = self
|
||||
.get_signature_status_with_commitment(signature, CommitmentConfig::processed())?;
|
||||
if status.is_none() {
|
||||
let blockhash_not_found = self
|
||||
.get_fee_calculator_for_blockhash_with_commitment(
|
||||
recent_blockhash,
|
||||
CommitmentConfig::processed(),
|
||||
)?
|
||||
.value
|
||||
.is_none();
|
||||
let blockhash_not_found =
|
||||
!self.is_blockhash_valid(recent_blockhash, CommitmentConfig::processed())?;
|
||||
if blockhash_not_found && now.elapsed() >= confirm_transaction_initial_timeout {
|
||||
break (signature, status);
|
||||
}
|
||||
@ -2936,6 +2964,84 @@ impl RpcClient {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_latest_blockhash(&self) -> ClientResult<Hash> {
|
||||
let (blockhash, _) = self.get_latest_blockhash_with_commitment(self.commitment())?;
|
||||
Ok(blockhash)
|
||||
}
|
||||
|
||||
pub fn get_latest_blockhash_with_commitment(
|
||||
&self,
|
||||
commitment: CommitmentConfig,
|
||||
) -> ClientResult<(Hash, u64)> {
|
||||
let latest_blockhash = self
|
||||
.send::<Response<RpcBlockhash>>(
|
||||
RpcRequest::GetLatestBlockhash,
|
||||
json!([self.maybe_map_commitment(commitment)?]),
|
||||
)?
|
||||
.value;
|
||||
|
||||
let blockhash = latest_blockhash.blockhash.parse().map_err(|_| {
|
||||
ClientError::new_with_request(
|
||||
RpcError::ParseError("Hash".to_string()).into(),
|
||||
RpcRequest::GetLatestBlockhash,
|
||||
)
|
||||
})?;
|
||||
Ok((blockhash, latest_blockhash.last_valid_block_height))
|
||||
}
|
||||
|
||||
pub fn is_blockhash_valid(
|
||||
&self,
|
||||
blockhash: &Hash,
|
||||
commitment: CommitmentConfig,
|
||||
) -> ClientResult<bool> {
|
||||
let result = self.send::<Response<bool>>(
|
||||
RpcRequest::IsBlockhashValid,
|
||||
json!([blockhash.to_string(), commitment,]),
|
||||
)?;
|
||||
Ok(result.value)
|
||||
}
|
||||
|
||||
pub fn get_fee_for_message(&self, blockhash: &Hash, message: &Message) -> ClientResult<u64> {
|
||||
let serialized_encoded =
|
||||
serialize_and_encode::<Message>(message, UiTransactionEncoding::Base64)?;
|
||||
let result = self.send::<Response<Option<u64>>>(
|
||||
RpcRequest::GetFeeForMessage,
|
||||
json!([
|
||||
blockhash.to_string(),
|
||||
serialized_encoded,
|
||||
UiTransactionEncoding::Base64,
|
||||
self.commitment(),
|
||||
]),
|
||||
)?;
|
||||
result
|
||||
.value
|
||||
.ok_or_else(|| ClientErrorKind::Custom("Invalid blockhash".to_string()).into())
|
||||
}
|
||||
|
||||
pub fn get_new_latest_blockhash(&self, blockhash: &Hash) -> ClientResult<Hash> {
|
||||
let mut num_retries = 0;
|
||||
let start = Instant::now();
|
||||
while start.elapsed().as_secs() < 5 {
|
||||
if let Ok(new_blockhash) = self.get_latest_blockhash() {
|
||||
if new_blockhash != *blockhash {
|
||||
return Ok(new_blockhash);
|
||||
}
|
||||
}
|
||||
debug!("Got same blockhash ({:?}), will retry...", blockhash);
|
||||
|
||||
// Retry ~twice during a slot
|
||||
sleep(Duration::from_millis(DEFAULT_MS_PER_SLOT / 2));
|
||||
num_retries += 1;
|
||||
}
|
||||
Err(RpcError::ForUser(format!(
|
||||
"Unable to get new blockhash after {}ms (retried {} times), stuck at {}",
|
||||
start.elapsed().as_millis(),
|
||||
num_retries,
|
||||
blockhash
|
||||
))
|
||||
.into())
|
||||
}
|
||||
|
||||
pub fn send<T>(&self, request: RpcRequest, params: Value) -> ClientResult<T>
|
||||
where
|
||||
T: serde::de::DeserializeOwned,
|
||||
@ -2951,18 +3057,18 @@ impl RpcClient {
|
||||
}
|
||||
}
|
||||
|
||||
fn serialize_encode_transaction(
|
||||
transaction: &Transaction,
|
||||
encoding: UiTransactionEncoding,
|
||||
) -> ClientResult<String> {
|
||||
let serialized = serialize(transaction)
|
||||
.map_err(|e| ClientErrorKind::Custom(format!("transaction serialization failed: {}", e)))?;
|
||||
pub fn serialize_and_encode<T>(input: &T, encoding: UiTransactionEncoding) -> ClientResult<String>
|
||||
where
|
||||
T: serde::ser::Serialize,
|
||||
{
|
||||
let serialized = serialize(input)
|
||||
.map_err(|e| ClientErrorKind::Custom(format!("Serialization failed: {}", e)))?;
|
||||
let encoded = match encoding {
|
||||
UiTransactionEncoding::Base58 => bs58::encode(serialized).into_string(),
|
||||
UiTransactionEncoding::Base64 => base64::encode(serialized),
|
||||
_ => {
|
||||
return Err(ClientErrorKind::Custom(format!(
|
||||
"unsupported transaction encoding: {}. Supported encodings: base58, base64",
|
||||
"unsupported encoding: {}. Supported encodings: base58, base64",
|
||||
encoding
|
||||
))
|
||||
.into())
|
||||
@ -3094,12 +3200,14 @@ mod tests {
|
||||
.unwrap();
|
||||
assert_eq!(balance, 50);
|
||||
|
||||
#[allow(deprecated)]
|
||||
let blockhash: String = rpc_client
|
||||
.send(RpcRequest::GetRecentBlockhash, Value::Null)
|
||||
.unwrap();
|
||||
assert_eq!(blockhash, "deadbeefXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNHhx");
|
||||
|
||||
// Send erroneous parameter
|
||||
#[allow(deprecated)]
|
||||
let blockhash: ClientResult<String> =
|
||||
rpc_client.send(RpcRequest::GetRecentBlockhash, json!(["parameter"]));
|
||||
assert!(blockhash.is_err());
|
||||
@ -3134,12 +3242,14 @@ mod tests {
|
||||
|
||||
let expected_blockhash: Hash = PUBKEY.parse().unwrap();
|
||||
|
||||
let (blockhash, _fee_calculator) = rpc_client.get_recent_blockhash().expect("blockhash ok");
|
||||
let blockhash = rpc_client.get_latest_blockhash().expect("blockhash ok");
|
||||
assert_eq!(blockhash, expected_blockhash);
|
||||
|
||||
let rpc_client = RpcClient::new_mock("fails".to_string());
|
||||
|
||||
assert!(rpc_client.get_recent_blockhash().is_err());
|
||||
#[allow(deprecated)]
|
||||
let result = rpc_client.get_recent_blockhash();
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -3229,4 +3339,20 @@ mod tests {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_latest_blockhash() {
|
||||
let rpc_client = RpcClient::new_mock("succeeds".to_string());
|
||||
|
||||
let expected_blockhash: Hash = PUBKEY.parse().unwrap();
|
||||
|
||||
let blockhash = rpc_client.get_latest_blockhash().expect("blockhash ok");
|
||||
assert_eq!(blockhash, expected_blockhash);
|
||||
|
||||
let rpc_client = RpcClient::new_mock("fails".to_string());
|
||||
|
||||
#[allow(deprecated)]
|
||||
let is_err = rpc_client.get_latest_blockhash().is_err();
|
||||
assert!(is_err);
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,9 @@ use {
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
|
||||
pub enum RpcRequest {
|
||||
Custom {
|
||||
method: &'static str,
|
||||
},
|
||||
DeregisterNode,
|
||||
GetAccountInfo,
|
||||
GetBalance,
|
||||
@ -18,7 +21,6 @@ pub enum RpcRequest {
|
||||
GetBlocksWithLimit,
|
||||
GetBlockTime,
|
||||
GetClusterNodes,
|
||||
|
||||
#[deprecated(since = "1.7.0", note = "Please use RpcRequest::GetBlock instead")]
|
||||
GetConfirmedBlock,
|
||||
#[deprecated(since = "1.7.0", note = "Please use RpcRequest::GetBlocks instead")]
|
||||
@ -38,11 +40,23 @@ pub enum RpcRequest {
|
||||
note = "Please use RpcRequest::GetTransaction instead"
|
||||
)]
|
||||
GetConfirmedTransaction,
|
||||
|
||||
GetEpochInfo,
|
||||
GetEpochSchedule,
|
||||
#[deprecated(
|
||||
since = "1.8.0",
|
||||
note = "Please use RpcRequest::GetFeeForMessage instead"
|
||||
)]
|
||||
GetFeeCalculatorForBlockhash,
|
||||
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::GetFeeForMessage instead"
|
||||
)]
|
||||
GetFees,
|
||||
GetFirstAvailableBlock,
|
||||
GetGenesisHash,
|
||||
@ -52,12 +66,17 @@ pub enum RpcRequest {
|
||||
GetInflationRate,
|
||||
GetInflationReward,
|
||||
GetLargestAccounts,
|
||||
GetLatestBlockhash,
|
||||
GetLeaderSchedule,
|
||||
GetMaxRetransmitSlot,
|
||||
GetMaxShredInsertSlot,
|
||||
GetMinimumBalanceForRentExemption,
|
||||
GetMultipleAccounts,
|
||||
GetProgramAccounts,
|
||||
#[deprecated(
|
||||
since = "1.8.0",
|
||||
note = "Please use RpcRequest::GetLatestBlockhash instead"
|
||||
)]
|
||||
GetRecentBlockhash,
|
||||
GetRecentPerformanceSamples,
|
||||
GetSnapshotSlot,
|
||||
@ -80,21 +99,20 @@ pub enum RpcRequest {
|
||||
GetTransactionCount,
|
||||
GetVersion,
|
||||
GetVoteAccounts,
|
||||
IsBlockhashValid,
|
||||
MinimumLedgerSlot,
|
||||
RegisterNode,
|
||||
RequestAirdrop,
|
||||
SendTransaction,
|
||||
SimulateTransaction,
|
||||
SignVote,
|
||||
Custom {
|
||||
method: &'static str,
|
||||
},
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl fmt::Display for RpcRequest {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let method = match self {
|
||||
RpcRequest::Custom { method } => method,
|
||||
RpcRequest::DeregisterNode => "deregisterNode",
|
||||
RpcRequest::GetAccountInfo => "getAccountInfo",
|
||||
RpcRequest::GetBalance => "getBalance",
|
||||
@ -113,6 +131,7 @@ impl fmt::Display for RpcRequest {
|
||||
RpcRequest::GetEpochInfo => "getEpochInfo",
|
||||
RpcRequest::GetEpochSchedule => "getEpochSchedule",
|
||||
RpcRequest::GetFeeCalculatorForBlockhash => "getFeeCalculatorForBlockhash",
|
||||
RpcRequest::GetFeeForMessage => "getFeeForMessage",
|
||||
RpcRequest::GetFeeRateGovernor => "getFeeRateGovernor",
|
||||
RpcRequest::GetFees => "getFees",
|
||||
RpcRequest::GetFirstAvailableBlock => "getFirstAvailableBlock",
|
||||
@ -123,6 +142,7 @@ impl fmt::Display for RpcRequest {
|
||||
RpcRequest::GetInflationRate => "getInflationRate",
|
||||
RpcRequest::GetInflationReward => "getInflationReward",
|
||||
RpcRequest::GetLargestAccounts => "getLargestAccounts",
|
||||
RpcRequest::GetLatestBlockhash => "getLatestBlockhash",
|
||||
RpcRequest::GetLeaderSchedule => "getLeaderSchedule",
|
||||
RpcRequest::GetMaxRetransmitSlot => "getMaxRetransmitSlot",
|
||||
RpcRequest::GetMaxShredInsertSlot => "getMaxShredInsertSlot",
|
||||
@ -151,13 +171,13 @@ impl fmt::Display for RpcRequest {
|
||||
RpcRequest::GetTransactionCount => "getTransactionCount",
|
||||
RpcRequest::GetVersion => "getVersion",
|
||||
RpcRequest::GetVoteAccounts => "getVoteAccounts",
|
||||
RpcRequest::IsBlockhashValid => "isBlockhashValid",
|
||||
RpcRequest::MinimumLedgerSlot => "minimumLedgerSlot",
|
||||
RpcRequest::RegisterNode => "registerNode",
|
||||
RpcRequest::RequestAirdrop => "requestAirdrop",
|
||||
RpcRequest::SendTransaction => "sendTransaction",
|
||||
RpcRequest::SimulateTransaction => "simulateTransaction",
|
||||
RpcRequest::SignVote => "signVote",
|
||||
RpcRequest::Custom { method } => method,
|
||||
};
|
||||
|
||||
write!(f, "{}", method)
|
||||
@ -261,14 +281,17 @@ mod tests {
|
||||
let request = test_request.build_request_json(1, Value::Null);
|
||||
assert_eq!(request["method"], "getEpochInfo");
|
||||
|
||||
#[allow(deprecated)]
|
||||
let test_request = RpcRequest::GetRecentBlockhash;
|
||||
let request = test_request.build_request_json(1, Value::Null);
|
||||
assert_eq!(request["method"], "getRecentBlockhash");
|
||||
|
||||
#[allow(deprecated)]
|
||||
let test_request = RpcRequest::GetFeeCalculatorForBlockhash;
|
||||
let request = test_request.build_request_json(1, json!([addr]));
|
||||
assert_eq!(request["method"], "getFeeCalculatorForBlockhash");
|
||||
|
||||
#[allow(deprecated)]
|
||||
let test_request = RpcRequest::GetFeeRateGovernor;
|
||||
let request = test_request.build_request_json(1, Value::Null);
|
||||
assert_eq!(request["method"], "getFeeRateGovernor");
|
||||
@ -298,6 +321,7 @@ mod tests {
|
||||
let addr = json!("deadbeefXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNHhx");
|
||||
|
||||
// Test request with CommitmentConfig and no params
|
||||
#[allow(deprecated)]
|
||||
let test_request = RpcRequest::GetRecentBlockhash;
|
||||
let request = test_request.build_request_json(1, json!([commitment_config]));
|
||||
assert_eq!(request["params"], json!([commitment_config.clone()]));
|
||||
|
@ -41,6 +41,13 @@ pub struct RpcBlockhashFeeCalculator {
|
||||
pub fee_calculator: FeeCalculator,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RpcBlockhash {
|
||||
pub blockhash: String,
|
||||
pub last_valid_block_height: u64,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RpcFees {
|
||||
|
@ -246,7 +246,7 @@ impl ThinClient {
|
||||
}
|
||||
}
|
||||
info!("{} tries failed transfer to {}", x, self.tpu_addr());
|
||||
let (blockhash, _fee_calculator) = self.get_recent_blockhash()?;
|
||||
let blockhash = self.get_latest_blockhash()?;
|
||||
transaction.sign(keypairs, blockhash);
|
||||
}
|
||||
Err(io::Error::new(
|
||||
@ -333,7 +333,7 @@ impl SyncClient for ThinClient {
|
||||
keypairs: &T,
|
||||
message: Message,
|
||||
) -> TransportResult<Signature> {
|
||||
let (blockhash, _fee_calculator) = self.get_recent_blockhash()?;
|
||||
let blockhash = self.get_latest_blockhash()?;
|
||||
let mut transaction = Transaction::new(keypairs, message, blockhash);
|
||||
let signature = self.send_and_confirm_transaction(keypairs, &mut transaction, 5, 0)?;
|
||||
Ok(signature)
|
||||
@ -404,6 +404,7 @@ impl SyncClient for ThinClient {
|
||||
}
|
||||
|
||||
fn get_recent_blockhash(&self) -> TransportResult<(Hash, FeeCalculator)> {
|
||||
#[allow(deprecated)]
|
||||
let (blockhash, fee_calculator, _last_valid_slot) =
|
||||
self.get_recent_blockhash_with_commitment(CommitmentConfig::default())?;
|
||||
Ok((blockhash, fee_calculator))
|
||||
@ -415,6 +416,7 @@ impl SyncClient for ThinClient {
|
||||
) -> TransportResult<(Hash, FeeCalculator, Slot)> {
|
||||
let index = self.optimizer.experiment();
|
||||
let now = Instant::now();
|
||||
#[allow(deprecated)]
|
||||
let recent_blockhash =
|
||||
self.rpc_clients[index].get_recent_blockhash_with_commitment(commitment_config);
|
||||
match recent_blockhash {
|
||||
@ -433,12 +435,14 @@ impl SyncClient for ThinClient {
|
||||
&self,
|
||||
blockhash: &Hash,
|
||||
) -> TransportResult<Option<FeeCalculator>> {
|
||||
#[allow(deprecated)]
|
||||
self.rpc_client()
|
||||
.get_fee_calculator_for_blockhash(blockhash)
|
||||
.map_err(|e| e.into())
|
||||
}
|
||||
|
||||
fn get_fee_rate_governor(&self) -> TransportResult<FeeRateGovernor> {
|
||||
#[allow(deprecated)]
|
||||
self.rpc_client()
|
||||
.get_fee_rate_governor()
|
||||
.map_err(|e| e.into())
|
||||
@ -556,10 +560,57 @@ impl SyncClient for ThinClient {
|
||||
}
|
||||
|
||||
fn get_new_blockhash(&self, blockhash: &Hash) -> TransportResult<(Hash, FeeCalculator)> {
|
||||
#[allow(deprecated)]
|
||||
self.rpc_client()
|
||||
.get_new_blockhash(blockhash)
|
||||
.map_err(|e| e.into())
|
||||
}
|
||||
|
||||
fn get_latest_blockhash(&self) -> TransportResult<Hash> {
|
||||
let (blockhash, _) =
|
||||
self.get_latest_blockhash_with_commitment(CommitmentConfig::default())?;
|
||||
Ok(blockhash)
|
||||
}
|
||||
|
||||
fn get_latest_blockhash_with_commitment(
|
||||
&self,
|
||||
commitment_config: CommitmentConfig,
|
||||
) -> TransportResult<(Hash, u64)> {
|
||||
let index = self.optimizer.experiment();
|
||||
let now = Instant::now();
|
||||
match self.rpc_clients[index].get_latest_blockhash_with_commitment(commitment_config) {
|
||||
Ok((blockhash, last_valid_block_height)) => {
|
||||
self.optimizer.report(index, duration_as_ms(&now.elapsed()));
|
||||
Ok((blockhash, last_valid_block_height))
|
||||
}
|
||||
Err(e) => {
|
||||
self.optimizer.report(index, std::u64::MAX);
|
||||
Err(e.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn is_blockhash_valid(
|
||||
&self,
|
||||
blockhash: &Hash,
|
||||
commitment_config: CommitmentConfig,
|
||||
) -> TransportResult<bool> {
|
||||
self.rpc_client()
|
||||
.is_blockhash_valid(blockhash, commitment_config)
|
||||
.map_err(|e| e.into())
|
||||
}
|
||||
|
||||
fn get_fee_for_message(&self, blockhash: &Hash, message: &Message) -> TransportResult<u64> {
|
||||
self.rpc_client()
|
||||
.get_fee_for_message(blockhash, message)
|
||||
.map_err(|e| e.into())
|
||||
}
|
||||
|
||||
fn get_new_latest_blockhash(&self, blockhash: &Hash) -> TransportResult<Hash> {
|
||||
self.rpc_client()
|
||||
.get_new_latest_blockhash(blockhash)
|
||||
.map_err(|e| e.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl AsyncClient for ThinClient {
|
||||
|
Reference in New Issue
Block a user