diff --git a/rpc/src/rpc.rs b/rpc/src/rpc.rs index 1167b21eaf..5d1ac664bf 100644 --- a/rpc/src/rpc.rs +++ b/rpc/src/rpc.rs @@ -2991,8 +2991,7 @@ pub mod rpc_bank { } // RPC interface that depends on AccountsDB -// Expected to be provided by API nodes, but collected for easy separation and offloading to -// accounts replica nodes in the future. +// Expected to be provided by API nodes pub mod rpc_accounts { use super::*; #[rpc] @@ -3015,22 +3014,6 @@ pub mod rpc_accounts { config: Option, ) -> Result>>>; - #[rpc(meta, name = "getProgramAccounts")] - fn get_program_accounts( - &self, - meta: Self::Metadata, - program_id_str: String, - config: Option, - ) -> Result>>; - - #[rpc(meta, name = "getSecondaryIndexKeySize")] - fn get_secondary_index_key_size( - &self, - meta: Self::Metadata, - pubkey_str: String, - config: Option, - ) -> Result>>; - #[rpc(meta, name = "getBlockCommitment")] fn get_block_commitment( &self, @@ -3038,20 +3021,6 @@ pub mod rpc_accounts { block: Slot, ) -> Result>; - #[rpc(meta, name = "getLargestAccounts")] - fn get_largest_accounts( - &self, - meta: Self::Metadata, - config: Option, - ) -> Result>>; - - #[rpc(meta, name = "getSupply")] - fn get_supply( - &self, - meta: Self::Metadata, - config: Option, - ) -> Result>; - #[rpc(meta, name = "getStakeActivation")] fn get_stake_activation( &self, @@ -3079,32 +3048,6 @@ pub mod rpc_accounts { mint_str: String, commitment: Option, ) -> Result>; - - #[rpc(meta, name = "getTokenLargestAccounts")] - fn get_token_largest_accounts( - &self, - meta: Self::Metadata, - mint_str: String, - commitment: Option, - ) -> Result>>; - - #[rpc(meta, name = "getTokenAccountsByOwner")] - fn get_token_accounts_by_owner( - &self, - meta: Self::Metadata, - owner_str: String, - token_account_filter: RpcTokenAccountsFilter, - config: Option, - ) -> Result>>; - - #[rpc(meta, name = "getTokenAccountsByDelegate")] - fn get_token_accounts_by_delegate( - &self, - meta: Self::Metadata, - delegate_str: String, - token_account_filter: RpcTokenAccountsFilter, - config: Option, - ) -> Result>>; } pub struct AccountsDataImpl; @@ -3150,6 +3093,132 @@ pub mod rpc_accounts { meta.get_multiple_accounts(pubkeys, config) } + fn get_block_commitment( + &self, + meta: Self::Metadata, + block: Slot, + ) -> Result> { + 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, + ) -> Result { + 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, + ) -> Result> { + 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, + ) -> Result> { + 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, + ) -> Result>>; + + // 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, + ) -> Result>>; + + #[rpc(meta, name = "getLargestAccounts")] + fn get_largest_accounts( + &self, + meta: Self::Metadata, + config: Option, + ) -> Result>>; + + #[rpc(meta, name = "getSupply")] + fn get_supply( + &self, + meta: Self::Metadata, + config: Option, + ) -> Result>; + + // 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, + ) -> Result>>; + + #[rpc(meta, name = "getTokenAccountsByOwner")] + fn get_token_accounts_by_owner( + &self, + meta: Self::Metadata, + owner_str: String, + token_account_filter: RpcTokenAccountsFilter, + config: Option, + ) -> Result>>; + + #[rpc(meta, name = "getTokenAccountsByDelegate")] + fn get_token_accounts_by_delegate( + &self, + meta: Self::Metadata, + delegate_str: String, + token_account_filter: RpcTokenAccountsFilter, + config: Option, + ) -> Result>>; + } + + pub struct AccountsScanImpl; + impl AccountsScan for AccountsScanImpl { + type Metadata = JsonRpcRequestProcessor; + fn get_program_accounts( &self, meta: Self::Metadata, @@ -3196,15 +3265,6 @@ pub mod rpc_accounts { meta.get_secondary_index_key_size(&index_key, config) } - fn get_block_commitment( - &self, - meta: Self::Metadata, - block: Slot, - ) -> Result> { - debug!("get_block_commitment rpc request received"); - Ok(meta.get_block_commitment(block)) - } - fn get_largest_accounts( &self, meta: Self::Metadata, @@ -3223,45 +3283,6 @@ pub mod rpc_accounts { Ok(meta.get_supply(config)?) } - fn get_stake_activation( - &self, - meta: Self::Metadata, - pubkey_str: String, - config: Option, - ) -> Result { - 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, - ) -> Result> { - 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, - ) -> Result> { - 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( &self, meta: Self::Metadata, @@ -4652,7 +4673,8 @@ pub fn populate_blockstore_for_tests( pub mod tests { use { 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::{ optimistically_confirmed_bank_tracker::{ @@ -4843,6 +4865,7 @@ pub mod tests { io.extend_with(rpc_minimal::MinimalImpl.to_delegate()); io.extend_with(rpc_bank::BankDataImpl.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_deprecated_v1_9::DeprecatedV1_9Impl.to_delegate()); Self { diff --git a/rpc/src/rpc_service.rs b/rpc/src/rpc_service.rs index e34f854c9f..08fb3bab4a 100644 --- a/rpc/src/rpc_service.rs +++ b/rpc/src/rpc_service.rs @@ -6,8 +6,8 @@ use { max_slots::MaxSlots, optimistically_confirmed_bank_tracker::OptimisticallyConfirmedBank, rpc::{ - rpc_accounts::*, rpc_bank::*, rpc_deprecated_v1_7::*, rpc_deprecated_v1_9::*, - rpc_full::*, rpc_minimal::*, rpc_obsolete_v1_7::*, *, + rpc_accounts::*, rpc_accounts_scan::*, rpc_bank::*, rpc_deprecated_v1_7::*, + rpc_deprecated_v1_9::*, rpc_full::*, rpc_minimal::*, rpc_obsolete_v1_7::*, *, }, rpc_cache::LargestAccountsCache, rpc_health::*, @@ -497,6 +497,7 @@ impl JsonRpcService { if full_api { io.extend_with(rpc_bank::BankDataImpl.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_deprecated_v1_7::DeprecatedV1_7Impl.to_delegate()); io.extend_with(rpc_deprecated_v1_9::DeprecatedV1_9Impl.to_delegate());