Add Incremental Snapshot support to RPC (#19559)

#### Problem

There's no way to get incremental snapshot information from RPC.

#### Summary of Changes

- Add new RPC method, `getHighestSnapshotSlot` that returns a `SnapshotSlotInfo`, which contains both the highest full snapshot slot, and the highest incremental snapshot slot _based on_ the full snapshot.
- Deprecate old RPC method, `getSnapshotSlot`
- Update API docs

Fixes #19579
This commit is contained in:
Brooks Prumo
2021-09-02 15:25:42 -05:00
committed by GitHub
parent f4f14c42bb
commit 8ac94b2cf4
9 changed files with 227 additions and 78 deletions

View File

@ -8,8 +8,9 @@ use {
rpc_response::{
Response, RpcAccountBalance, RpcBlockProduction, RpcBlockProductionRange, RpcBlockhash,
RpcConfirmedTransactionStatusWithSignature, RpcContactInfo, RpcFees, RpcPerfSample,
RpcResponseContext, RpcSimulateTransactionResult, RpcStakeActivation, RpcSupply,
RpcVersionInfo, RpcVoteAccountInfo, RpcVoteAccountStatus, StakeActivationState,
RpcResponseContext, RpcSimulateTransactionResult, RpcSnapshotSlotInfo,
RpcStakeActivation, RpcSupply, RpcVersionInfo, RpcVoteAccountInfo,
RpcVoteAccountStatus, StakeActivationState,
},
rpc_sender::RpcSender,
},
@ -222,6 +223,10 @@ impl RpcSender for MockSender {
"getMaxShredInsertSlot" => json![0],
"requestAirdrop" => Value::String(Signature::new(&[8; 64]).to_string()),
"getSnapshotSlot" => Value::Number(Number::from(0)),
"getHighestSnapshotSlot" => json!(RpcSnapshotSlotInfo {
full: 100,
incremental: Some(110),
}),
"getBlockHeight" => Value::Number(Number::from(1234)),
"getSlotLeaders" => json!([PUBKEY]),
"getBlockProduction" => {

View File

@ -1018,13 +1018,16 @@ impl RpcClient {
)
}
/// Returns the highest slot that the node has a snapshot for.
/// Returns the highest slot information that the node has snapshots for.
///
/// This will find the highest full snapshot slot, and the highest incremental snapshot slot
/// _based on_ the full snapshot slot, if there is one.
///
/// # RPC Reference
///
/// This method corresponds directly to the [`getSnapshotSlot`] RPC method.
/// This method corresponds directly to the [`getHighestSnapshotSlot`] RPC method.
///
/// [`getSnapshotSlot`]: https://docs.solana.com/developing/clients/jsonrpc-api#getsnapshotslot
/// [`getHighestSnapshotSlot`]: https://docs.solana.com/developing/clients/jsonrpc-api#gethighestsnapshotslot
///
/// # Examples
///
@ -1034,9 +1037,18 @@ impl RpcClient {
/// # client_error::ClientError,
/// # };
/// # let rpc_client = RpcClient::new_mock("succeeds".to_string());
/// let slot = rpc_client.get_snapshot_slot()?;
/// let snapshot_slot_info = rpc_client.get_highest_snapshot_slot()?;
/// # Ok::<(), ClientError>(())
/// ```
pub fn get_highest_snapshot_slot(&self) -> ClientResult<RpcSnapshotSlotInfo> {
self.send(RpcRequest::GetHighestSnapshotSlot, Value::Null)
}
#[deprecated(
since = "1.8.0",
note = "Please use RpcClient::get_highest_snapshot_slot() instead"
)]
#[allow(deprecated)]
pub fn get_snapshot_slot(&self) -> ClientResult<Slot> {
self.send(RpcRequest::GetSnapshotSlot, Value::Null)
}

View File

@ -79,6 +79,11 @@ pub enum RpcRequest {
)]
GetRecentBlockhash,
GetRecentPerformanceSamples,
GetHighestSnapshotSlot,
#[deprecated(
since = "1.8.0",
note = "Please use RpcRequest::GetHighestSnapshotSlot instead"
)]
GetSnapshotSlot,
GetSignaturesForAddress,
GetSignatureStatuses,
@ -151,6 +156,7 @@ impl fmt::Display for RpcRequest {
RpcRequest::GetProgramAccounts => "getProgramAccounts",
RpcRequest::GetRecentBlockhash => "getRecentBlockhash",
RpcRequest::GetRecentPerformanceSamples => "getRecentPerformanceSamples",
RpcRequest::GetHighestSnapshotSlot => "getHighestSnapshotSlot",
RpcRequest::GetSnapshotSlot => "getSnapshotSlot",
RpcRequest::GetSignaturesForAddress => "getSignaturesForAddress",
RpcRequest::GetSignatureStatuses => "getSignatureStatuses",

View File

@ -435,3 +435,9 @@ impl From<ConfirmedTransactionStatusWithSignature> for RpcConfirmedTransactionSt
}
}
}
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq)]
pub struct RpcSnapshotSlotInfo {
pub full: Slot,
pub incremental: Option<Slot>,
}