From 5e866bb9a45a40d5b251cd3e188d76893da0485b Mon Sep 17 00:00:00 2001 From: Tyera Date: Fri, 6 Jan 2023 23:04:34 -0700 Subject: [PATCH] Add rust client support for getRecentPrioritizationFees (#29558) (cherry picked from commit e0d2a40d85fad759f5f312244fc82c5ae8c009f6) --- client/src/mock_sender.rs | 8 ++++-- client/src/nonblocking/rpc_client.rs | 43 ++++++++++++++++++++++++++++ client/src/rpc_client.rs | 35 ++++++++++++++++++++++ client/src/rpc_request.rs | 2 ++ 4 files changed, 86 insertions(+), 2 deletions(-) diff --git a/client/src/mock_sender.rs b/client/src/mock_sender.rs index d94cf0c53451b0..057dbed5c84c38 100644 --- a/client/src/mock_sender.rs +++ b/client/src/mock_sender.rs @@ -9,8 +9,8 @@ use { Response, RpcAccountBalance, RpcBlockProduction, RpcBlockProductionRange, RpcBlockhash, RpcConfirmedTransactionStatusWithSignature, RpcContactInfo, RpcFees, RpcIdentity, RpcInflationGovernor, RpcInflationRate, RpcInflationReward, RpcKeyedAccount, - RpcPerfSample, RpcResponseContext, RpcSimulateTransactionResult, RpcSnapshotSlotInfo, - RpcStakeActivation, RpcSupply, RpcVersionInfo, RpcVoteAccountInfo, + RpcPerfSample, RpcPrioritizationFee, RpcResponseContext, RpcSimulateTransactionResult, + RpcSnapshotSlotInfo, RpcStakeActivation, RpcSupply, RpcVersionInfo, RpcVoteAccountInfo, RpcVoteAccountStatus, StakeActivationState, }, rpc_sender::*, @@ -418,6 +418,10 @@ impl RpcSender for MockSender { num_slots: 123, sample_period_secs: 60, }])?, + "getRecentPrioritizationFees" => serde_json::to_value(vec![RpcPrioritizationFee { + slot: 123_456_789, + prioritization_fee: 10_000, + }])?, "getIdentity" => serde_json::to_value(RpcIdentity { identity: PUBKEY.to_string(), })?, diff --git a/client/src/nonblocking/rpc_client.rs b/client/src/nonblocking/rpc_client.rs index e48b49db7b2c21..97a9b365e3f1eb 100644 --- a/client/src/nonblocking/rpc_client.rs +++ b/client/src/nonblocking/rpc_client.rs @@ -3603,6 +3603,49 @@ impl RpcClient { .await } + /// Returns a list of minimum prioritization fees from recent blocks. + /// Takes an optional vector of addresses; if any addresses are provided, the response will + /// reflect the minimum prioritization fee to land a transaction locking all of the provided + /// accounts as writable. + /// + /// Currently, a node's prioritization-fee cache stores data from up to 150 blocks. + /// + /// # RPC Reference + /// + /// This method corresponds directly to the [`getRecentPrioritizationFees`] RPC method. + /// + /// [`getRecentPrioritizationFees`]: https://docs.solana.com/developing/clients/jsonrpc-api#getrecentprioritizationfees + /// + /// # Examples + /// + /// ``` + /// # use solana_rpc_client_api::client_error::Error; + /// # use solana_rpc_client::nonblocking::rpc_client::RpcClient; + /// # use solana_sdk::signature::{Keypair, Signer}; + /// # futures::executor::block_on(async { + /// # let rpc_client = RpcClient::new_mock("succeeds".to_string()); + /// # let alice = Keypair::new(); + /// # let bob = Keypair::new(); + /// let addresses = vec![alice.pubkey(), bob.pubkey()]; + /// let prioritization_fees = rpc_client.get_recent_prioritization_fees( + /// &addresses, + /// ).await?; + /// # Ok::<(), Error>(()) + /// # })?; + /// # Ok::<(), Error>(()) + /// ``` + pub async fn get_recent_prioritization_fees( + &self, + addresses: &[Pubkey], + ) -> ClientResult> { + let addresses: Vec<_> = addresses + .iter() + .map(|address| address.to_string()) + .collect(); + self.send(RpcRequest::GetRecentPrioritizationFees, json!([addresses])) + .await + } + /// Returns the identity pubkey for the current node. /// /// # RPC Reference diff --git a/client/src/rpc_client.rs b/client/src/rpc_client.rs index 4c1e805a9ea8b4..95bfbfa8029589 100644 --- a/client/src/rpc_client.rs +++ b/client/src/rpc_client.rs @@ -3023,6 +3023,41 @@ impl RpcClient { self.invoke(self.rpc_client.get_recent_performance_samples(limit)) } + /// Returns a list of minimum prioritization fees from recent blocks. + /// Takes an optional vector of addresses; if any addresses are provided, the response will + /// reflect the minimum prioritization fee to land a transaction locking all of the provided + /// accounts as writable. + /// + /// Currently, a node's prioritization-fee cache stores data from up to 150 blocks. + /// + /// # RPC Reference + /// + /// This method corresponds directly to the [`getRecentPrioritizationFees`] RPC method. + /// + /// [`getRecentPrioritizationFees`]: https://docs.solana.com/developing/clients/jsonrpc-api#getrecentprioritizationfees + /// + /// # Examples + /// + /// ``` + /// # use solana_rpc_client_api::client_error::Error; + /// # use solana_rpc_client::rpc_client::RpcClient; + /// # use solana_sdk::signature::{Keypair, Signer}; + /// # let rpc_client = RpcClient::new_mock("succeeds".to_string()); + /// # let alice = Keypair::new(); + /// # let bob = Keypair::new(); + /// let addresses = vec![alice.pubkey(), bob.pubkey()]; + /// let prioritization_fees = rpc_client.get_recent_prioritization_fees( + /// &addresses, + /// )?; + /// # Ok::<(), Error>(()) + /// ``` + pub fn get_recent_prioritization_fees( + &self, + addresses: &[Pubkey], + ) -> ClientResult> { + self.invoke((self.rpc_client.as_ref()).get_recent_prioritization_fees(addresses)) + } + /// Returns the identity pubkey for the current node. /// /// # RPC Reference diff --git a/client/src/rpc_request.rs b/client/src/rpc_request.rs index d3f0ceb1c0ad54..42cd79686b76d3 100644 --- a/client/src/rpc_request.rs +++ b/client/src/rpc_request.rs @@ -79,6 +79,7 @@ pub enum RpcRequest { )] GetRecentBlockhash, GetRecentPerformanceSamples, + GetRecentPrioritizationFees, GetHighestSnapshotSlot, #[deprecated( since = "1.9.0", @@ -157,6 +158,7 @@ impl fmt::Display for RpcRequest { RpcRequest::GetProgramAccounts => "getProgramAccounts", RpcRequest::GetRecentBlockhash => "getRecentBlockhash", RpcRequest::GetRecentPerformanceSamples => "getRecentPerformanceSamples", + RpcRequest::GetRecentPrioritizationFees => "getRecentPrioritizationFees", RpcRequest::GetHighestSnapshotSlot => "getHighestSnapshotSlot", RpcRequest::GetSnapshotSlot => "getSnapshotSlot", RpcRequest::GetSignaturesForAddress => "getSignaturesForAddress",