Split rpc_accounts api to identify calls that scan accountsDB (#28968)
* Update stale comment * Collect RPC endpoints that perform accounts scans
This commit is contained in:
parent
a665d679cc
commit
fd13323f4b
237
rpc/src/rpc.rs
237
rpc/src/rpc.rs
|
@ -2991,8 +2991,7 @@ pub mod rpc_bank {
|
||||||
}
|
}
|
||||||
|
|
||||||
// RPC interface that depends on AccountsDB
|
// RPC interface that depends on AccountsDB
|
||||||
// Expected to be provided by API nodes, but collected for easy separation and offloading to
|
// Expected to be provided by API nodes
|
||||||
// accounts replica nodes in the future.
|
|
||||||
pub mod rpc_accounts {
|
pub mod rpc_accounts {
|
||||||
use super::*;
|
use super::*;
|
||||||
#[rpc]
|
#[rpc]
|
||||||
|
@ -3015,22 +3014,6 @@ pub mod rpc_accounts {
|
||||||
config: Option<RpcAccountInfoConfig>,
|
config: Option<RpcAccountInfoConfig>,
|
||||||
) -> Result<RpcResponse<Vec<Option<UiAccount>>>>;
|
) -> Result<RpcResponse<Vec<Option<UiAccount>>>>;
|
||||||
|
|
||||||
#[rpc(meta, name = "getProgramAccounts")]
|
|
||||||
fn get_program_accounts(
|
|
||||||
&self,
|
|
||||||
meta: Self::Metadata,
|
|
||||||
program_id_str: String,
|
|
||||||
config: Option<RpcProgramAccountsConfig>,
|
|
||||||
) -> Result<OptionalContext<Vec<RpcKeyedAccount>>>;
|
|
||||||
|
|
||||||
#[rpc(meta, name = "getSecondaryIndexKeySize")]
|
|
||||||
fn get_secondary_index_key_size(
|
|
||||||
&self,
|
|
||||||
meta: Self::Metadata,
|
|
||||||
pubkey_str: String,
|
|
||||||
config: Option<RpcContextConfig>,
|
|
||||||
) -> Result<RpcResponse<HashMap<RpcAccountIndex, usize>>>;
|
|
||||||
|
|
||||||
#[rpc(meta, name = "getBlockCommitment")]
|
#[rpc(meta, name = "getBlockCommitment")]
|
||||||
fn get_block_commitment(
|
fn get_block_commitment(
|
||||||
&self,
|
&self,
|
||||||
|
@ -3038,20 +3021,6 @@ pub mod rpc_accounts {
|
||||||
block: Slot,
|
block: Slot,
|
||||||
) -> Result<RpcBlockCommitment<BlockCommitmentArray>>;
|
) -> Result<RpcBlockCommitment<BlockCommitmentArray>>;
|
||||||
|
|
||||||
#[rpc(meta, name = "getLargestAccounts")]
|
|
||||||
fn get_largest_accounts(
|
|
||||||
&self,
|
|
||||||
meta: Self::Metadata,
|
|
||||||
config: Option<RpcLargestAccountsConfig>,
|
|
||||||
) -> Result<RpcResponse<Vec<RpcAccountBalance>>>;
|
|
||||||
|
|
||||||
#[rpc(meta, name = "getSupply")]
|
|
||||||
fn get_supply(
|
|
||||||
&self,
|
|
||||||
meta: Self::Metadata,
|
|
||||||
config: Option<RpcSupplyConfig>,
|
|
||||||
) -> Result<RpcResponse<RpcSupply>>;
|
|
||||||
|
|
||||||
#[rpc(meta, name = "getStakeActivation")]
|
#[rpc(meta, name = "getStakeActivation")]
|
||||||
fn get_stake_activation(
|
fn get_stake_activation(
|
||||||
&self,
|
&self,
|
||||||
|
@ -3079,32 +3048,6 @@ pub mod rpc_accounts {
|
||||||
mint_str: String,
|
mint_str: String,
|
||||||
commitment: Option<CommitmentConfig>,
|
commitment: Option<CommitmentConfig>,
|
||||||
) -> Result<RpcResponse<UiTokenAmount>>;
|
) -> Result<RpcResponse<UiTokenAmount>>;
|
||||||
|
|
||||||
#[rpc(meta, name = "getTokenLargestAccounts")]
|
|
||||||
fn get_token_largest_accounts(
|
|
||||||
&self,
|
|
||||||
meta: Self::Metadata,
|
|
||||||
mint_str: String,
|
|
||||||
commitment: Option<CommitmentConfig>,
|
|
||||||
) -> Result<RpcResponse<Vec<RpcTokenAccountBalance>>>;
|
|
||||||
|
|
||||||
#[rpc(meta, name = "getTokenAccountsByOwner")]
|
|
||||||
fn get_token_accounts_by_owner(
|
|
||||||
&self,
|
|
||||||
meta: Self::Metadata,
|
|
||||||
owner_str: String,
|
|
||||||
token_account_filter: RpcTokenAccountsFilter,
|
|
||||||
config: Option<RpcAccountInfoConfig>,
|
|
||||||
) -> Result<RpcResponse<Vec<RpcKeyedAccount>>>;
|
|
||||||
|
|
||||||
#[rpc(meta, name = "getTokenAccountsByDelegate")]
|
|
||||||
fn get_token_accounts_by_delegate(
|
|
||||||
&self,
|
|
||||||
meta: Self::Metadata,
|
|
||||||
delegate_str: String,
|
|
||||||
token_account_filter: RpcTokenAccountsFilter,
|
|
||||||
config: Option<RpcAccountInfoConfig>,
|
|
||||||
) -> Result<RpcResponse<Vec<RpcKeyedAccount>>>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AccountsDataImpl;
|
pub struct AccountsDataImpl;
|
||||||
|
@ -3150,6 +3093,132 @@ pub mod rpc_accounts {
|
||||||
meta.get_multiple_accounts(pubkeys, config)
|
meta.get_multiple_accounts(pubkeys, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_block_commitment(
|
||||||
|
&self,
|
||||||
|
meta: Self::Metadata,
|
||||||
|
block: Slot,
|
||||||
|
) -> Result<RpcBlockCommitment<BlockCommitmentArray>> {
|
||||||
|
debug!("get_block_commitment rpc request received");
|
||||||
|
Ok(meta.get_block_commitment(block))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_stake_activation(
|
||||||
|
&self,
|
||||||
|
meta: Self::Metadata,
|
||||||
|
pubkey_str: String,
|
||||||
|
config: Option<RpcEpochConfig>,
|
||||||
|
) -> Result<RpcStakeActivation> {
|
||||||
|
debug!(
|
||||||
|
"get_stake_activation rpc request received: {:?}",
|
||||||
|
pubkey_str
|
||||||
|
);
|
||||||
|
let pubkey = verify_pubkey(&pubkey_str)?;
|
||||||
|
meta.get_stake_activation(&pubkey, config)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_token_account_balance(
|
||||||
|
&self,
|
||||||
|
meta: Self::Metadata,
|
||||||
|
pubkey_str: String,
|
||||||
|
commitment: Option<CommitmentConfig>,
|
||||||
|
) -> Result<RpcResponse<UiTokenAmount>> {
|
||||||
|
debug!(
|
||||||
|
"get_token_account_balance rpc request received: {:?}",
|
||||||
|
pubkey_str
|
||||||
|
);
|
||||||
|
let pubkey = verify_pubkey(&pubkey_str)?;
|
||||||
|
meta.get_token_account_balance(&pubkey, commitment)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_token_supply(
|
||||||
|
&self,
|
||||||
|
meta: Self::Metadata,
|
||||||
|
mint_str: String,
|
||||||
|
commitment: Option<CommitmentConfig>,
|
||||||
|
) -> Result<RpcResponse<UiTokenAmount>> {
|
||||||
|
debug!("get_token_supply rpc request received: {:?}", mint_str);
|
||||||
|
let mint = verify_pubkey(&mint_str)?;
|
||||||
|
meta.get_token_supply(&mint, commitment)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// RPC interface that depends on AccountsDB and requires accounts scan
|
||||||
|
// Expected to be provided by API nodes for now, but collected for easy separation and removal in
|
||||||
|
// the future.
|
||||||
|
pub mod rpc_accounts_scan {
|
||||||
|
use super::*;
|
||||||
|
#[rpc]
|
||||||
|
pub trait AccountsScan {
|
||||||
|
type Metadata;
|
||||||
|
|
||||||
|
#[rpc(meta, name = "getProgramAccounts")]
|
||||||
|
fn get_program_accounts(
|
||||||
|
&self,
|
||||||
|
meta: Self::Metadata,
|
||||||
|
program_id_str: String,
|
||||||
|
config: Option<RpcProgramAccountsConfig>,
|
||||||
|
) -> Result<OptionalContext<Vec<RpcKeyedAccount>>>;
|
||||||
|
|
||||||
|
// This method does not itself do an accounts scan, but returns data only relevant to nodes
|
||||||
|
// that do support accounts-scan RPC apis
|
||||||
|
#[rpc(meta, name = "getSecondaryIndexKeySize")]
|
||||||
|
fn get_secondary_index_key_size(
|
||||||
|
&self,
|
||||||
|
meta: Self::Metadata,
|
||||||
|
pubkey_str: String,
|
||||||
|
config: Option<RpcContextConfig>,
|
||||||
|
) -> Result<RpcResponse<HashMap<RpcAccountIndex, usize>>>;
|
||||||
|
|
||||||
|
#[rpc(meta, name = "getLargestAccounts")]
|
||||||
|
fn get_largest_accounts(
|
||||||
|
&self,
|
||||||
|
meta: Self::Metadata,
|
||||||
|
config: Option<RpcLargestAccountsConfig>,
|
||||||
|
) -> Result<RpcResponse<Vec<RpcAccountBalance>>>;
|
||||||
|
|
||||||
|
#[rpc(meta, name = "getSupply")]
|
||||||
|
fn get_supply(
|
||||||
|
&self,
|
||||||
|
meta: Self::Metadata,
|
||||||
|
config: Option<RpcSupplyConfig>,
|
||||||
|
) -> Result<RpcResponse<RpcSupply>>;
|
||||||
|
|
||||||
|
// SPL Token-specific RPC endpoints
|
||||||
|
// See https://github.com/solana-labs/solana-program-library/releases/tag/token-v2.0.0 for
|
||||||
|
// program details
|
||||||
|
|
||||||
|
#[rpc(meta, name = "getTokenLargestAccounts")]
|
||||||
|
fn get_token_largest_accounts(
|
||||||
|
&self,
|
||||||
|
meta: Self::Metadata,
|
||||||
|
mint_str: String,
|
||||||
|
commitment: Option<CommitmentConfig>,
|
||||||
|
) -> Result<RpcResponse<Vec<RpcTokenAccountBalance>>>;
|
||||||
|
|
||||||
|
#[rpc(meta, name = "getTokenAccountsByOwner")]
|
||||||
|
fn get_token_accounts_by_owner(
|
||||||
|
&self,
|
||||||
|
meta: Self::Metadata,
|
||||||
|
owner_str: String,
|
||||||
|
token_account_filter: RpcTokenAccountsFilter,
|
||||||
|
config: Option<RpcAccountInfoConfig>,
|
||||||
|
) -> Result<RpcResponse<Vec<RpcKeyedAccount>>>;
|
||||||
|
|
||||||
|
#[rpc(meta, name = "getTokenAccountsByDelegate")]
|
||||||
|
fn get_token_accounts_by_delegate(
|
||||||
|
&self,
|
||||||
|
meta: Self::Metadata,
|
||||||
|
delegate_str: String,
|
||||||
|
token_account_filter: RpcTokenAccountsFilter,
|
||||||
|
config: Option<RpcAccountInfoConfig>,
|
||||||
|
) -> Result<RpcResponse<Vec<RpcKeyedAccount>>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct AccountsScanImpl;
|
||||||
|
impl AccountsScan for AccountsScanImpl {
|
||||||
|
type Metadata = JsonRpcRequestProcessor;
|
||||||
|
|
||||||
fn get_program_accounts(
|
fn get_program_accounts(
|
||||||
&self,
|
&self,
|
||||||
meta: Self::Metadata,
|
meta: Self::Metadata,
|
||||||
|
@ -3196,15 +3265,6 @@ pub mod rpc_accounts {
|
||||||
meta.get_secondary_index_key_size(&index_key, config)
|
meta.get_secondary_index_key_size(&index_key, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_block_commitment(
|
|
||||||
&self,
|
|
||||||
meta: Self::Metadata,
|
|
||||||
block: Slot,
|
|
||||||
) -> Result<RpcBlockCommitment<BlockCommitmentArray>> {
|
|
||||||
debug!("get_block_commitment rpc request received");
|
|
||||||
Ok(meta.get_block_commitment(block))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_largest_accounts(
|
fn get_largest_accounts(
|
||||||
&self,
|
&self,
|
||||||
meta: Self::Metadata,
|
meta: Self::Metadata,
|
||||||
|
@ -3223,45 +3283,6 @@ pub mod rpc_accounts {
|
||||||
Ok(meta.get_supply(config)?)
|
Ok(meta.get_supply(config)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_stake_activation(
|
|
||||||
&self,
|
|
||||||
meta: Self::Metadata,
|
|
||||||
pubkey_str: String,
|
|
||||||
config: Option<RpcEpochConfig>,
|
|
||||||
) -> Result<RpcStakeActivation> {
|
|
||||||
debug!(
|
|
||||||
"get_stake_activation rpc request received: {:?}",
|
|
||||||
pubkey_str
|
|
||||||
);
|
|
||||||
let pubkey = verify_pubkey(&pubkey_str)?;
|
|
||||||
meta.get_stake_activation(&pubkey, config)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_token_account_balance(
|
|
||||||
&self,
|
|
||||||
meta: Self::Metadata,
|
|
||||||
pubkey_str: String,
|
|
||||||
commitment: Option<CommitmentConfig>,
|
|
||||||
) -> Result<RpcResponse<UiTokenAmount>> {
|
|
||||||
debug!(
|
|
||||||
"get_token_account_balance rpc request received: {:?}",
|
|
||||||
pubkey_str
|
|
||||||
);
|
|
||||||
let pubkey = verify_pubkey(&pubkey_str)?;
|
|
||||||
meta.get_token_account_balance(&pubkey, commitment)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_token_supply(
|
|
||||||
&self,
|
|
||||||
meta: Self::Metadata,
|
|
||||||
mint_str: String,
|
|
||||||
commitment: Option<CommitmentConfig>,
|
|
||||||
) -> Result<RpcResponse<UiTokenAmount>> {
|
|
||||||
debug!("get_token_supply rpc request received: {:?}", mint_str);
|
|
||||||
let mint = verify_pubkey(&mint_str)?;
|
|
||||||
meta.get_token_supply(&mint, commitment)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_token_largest_accounts(
|
fn get_token_largest_accounts(
|
||||||
&self,
|
&self,
|
||||||
meta: Self::Metadata,
|
meta: Self::Metadata,
|
||||||
|
@ -4652,7 +4673,8 @@ pub fn populate_blockstore_for_tests(
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
use {
|
use {
|
||||||
super::{
|
super::{
|
||||||
rpc_accounts::*, rpc_bank::*, rpc_deprecated_v1_9::*, rpc_full::*, rpc_minimal::*, *,
|
rpc_accounts::*, rpc_accounts_scan::*, rpc_bank::*, rpc_deprecated_v1_9::*,
|
||||||
|
rpc_full::*, rpc_minimal::*, *,
|
||||||
},
|
},
|
||||||
crate::{
|
crate::{
|
||||||
optimistically_confirmed_bank_tracker::{
|
optimistically_confirmed_bank_tracker::{
|
||||||
|
@ -4843,6 +4865,7 @@ pub mod tests {
|
||||||
io.extend_with(rpc_minimal::MinimalImpl.to_delegate());
|
io.extend_with(rpc_minimal::MinimalImpl.to_delegate());
|
||||||
io.extend_with(rpc_bank::BankDataImpl.to_delegate());
|
io.extend_with(rpc_bank::BankDataImpl.to_delegate());
|
||||||
io.extend_with(rpc_accounts::AccountsDataImpl.to_delegate());
|
io.extend_with(rpc_accounts::AccountsDataImpl.to_delegate());
|
||||||
|
io.extend_with(rpc_accounts_scan::AccountsScanImpl.to_delegate());
|
||||||
io.extend_with(rpc_full::FullImpl.to_delegate());
|
io.extend_with(rpc_full::FullImpl.to_delegate());
|
||||||
io.extend_with(rpc_deprecated_v1_9::DeprecatedV1_9Impl.to_delegate());
|
io.extend_with(rpc_deprecated_v1_9::DeprecatedV1_9Impl.to_delegate());
|
||||||
Self {
|
Self {
|
||||||
|
|
|
@ -6,8 +6,8 @@ use {
|
||||||
max_slots::MaxSlots,
|
max_slots::MaxSlots,
|
||||||
optimistically_confirmed_bank_tracker::OptimisticallyConfirmedBank,
|
optimistically_confirmed_bank_tracker::OptimisticallyConfirmedBank,
|
||||||
rpc::{
|
rpc::{
|
||||||
rpc_accounts::*, rpc_bank::*, rpc_deprecated_v1_7::*, rpc_deprecated_v1_9::*,
|
rpc_accounts::*, rpc_accounts_scan::*, rpc_bank::*, rpc_deprecated_v1_7::*,
|
||||||
rpc_full::*, rpc_minimal::*, rpc_obsolete_v1_7::*, *,
|
rpc_deprecated_v1_9::*, rpc_full::*, rpc_minimal::*, rpc_obsolete_v1_7::*, *,
|
||||||
},
|
},
|
||||||
rpc_cache::LargestAccountsCache,
|
rpc_cache::LargestAccountsCache,
|
||||||
rpc_health::*,
|
rpc_health::*,
|
||||||
|
@ -497,6 +497,7 @@ impl JsonRpcService {
|
||||||
if full_api {
|
if full_api {
|
||||||
io.extend_with(rpc_bank::BankDataImpl.to_delegate());
|
io.extend_with(rpc_bank::BankDataImpl.to_delegate());
|
||||||
io.extend_with(rpc_accounts::AccountsDataImpl.to_delegate());
|
io.extend_with(rpc_accounts::AccountsDataImpl.to_delegate());
|
||||||
|
io.extend_with(rpc_accounts_scan::AccountsScanImpl.to_delegate());
|
||||||
io.extend_with(rpc_full::FullImpl.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_7::DeprecatedV1_7Impl.to_delegate());
|
||||||
io.extend_with(rpc_deprecated_v1_9::DeprecatedV1_9Impl.to_delegate());
|
io.extend_with(rpc_deprecated_v1_9::DeprecatedV1_9Impl.to_delegate());
|
||||||
|
|
Loading…
Reference in New Issue