diff --git a/client/src/rpc_response.rs b/client/src/rpc_response.rs index 390a5e592..b98bc57a1 100644 --- a/client/src/rpc_response.rs +++ b/client/src/rpc_response.rs @@ -275,6 +275,15 @@ pub struct RpcConfirmedTransactionStatusWithSignature { pub memo: Option, } +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RpcPerfSample { + pub slot: Slot, + pub num_transactions: u64, + pub num_slots: u64, + pub sample_period_secs: u16, +} + impl From for RpcConfirmedTransactionStatusWithSignature { fn from(value: ConfirmedTransactionStatusWithSignature) -> Self { let ConfirmedTransactionStatusWithSignature { diff --git a/core/src/rpc.rs b/core/src/rpc.rs index b3611e948..c4d137a27 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -33,10 +33,7 @@ use solana_client::{ rpc_response::*, }; use solana_faucet::faucet::request_airdrop_transaction; -use solana_ledger::{ - blockstore::Blockstore, blockstore_db::BlockstoreError, blockstore_meta::PerfSample, - get_tmp_ledger_path, -}; +use solana_ledger::{blockstore::Blockstore, blockstore_db::BlockstoreError, get_tmp_ledger_path}; use solana_perf::packet::PACKET_DATA_SIZE; use solana_runtime::{ accounts::AccountAddressFilter, @@ -1506,7 +1503,7 @@ pub trait RpcSol { &self, meta: Self::Metadata, limit: Option, - ) -> Result>; + ) -> Result>; #[rpc(meta, name = "getEpochInfo")] fn get_epoch_info( @@ -1901,7 +1898,7 @@ impl RpcSol for RpcSolImpl { &self, meta: Self::Metadata, limit: Option, - ) -> Result> { + ) -> Result> { debug!("get_recent_performance_samples request received"); let limit = limit.unwrap_or(PERFORMANCE_SAMPLES_LIMIT); @@ -1913,12 +1910,21 @@ impl RpcSol for RpcSolImpl { ))); } - meta.blockstore + Ok(meta + .blockstore .get_recent_perf_samples(limit) .map_err(|err| { warn!("get_recent_performance_samples failed: {:?}", err); Error::invalid_request() + })? + .iter() + .map(|(slot, sample)| RpcPerfSample { + slot: *slot, + num_transactions: sample.num_transactions, + num_slots: sample.num_slots, + sample_period_secs: sample.sample_period_secs, }) + .collect()) } fn get_cluster_nodes(&self, meta: Self::Metadata) -> Result> { @@ -2547,6 +2553,7 @@ pub mod tests { use solana_client::rpc_filter::{Memcmp, MemcmpEncodedBytes}; use solana_ledger::{ blockstore::entries_to_test_shreds, + blockstore_meta::PerfSample, blockstore_processor::fill_blockstore_slot_with_ticks, entry::next_entry_mut, genesis_utils::{create_genesis_config, GenesisConfigInfo}, @@ -2861,14 +2868,12 @@ pub mod tests { "jsonrpc": "2.0", "id": 1, "result": [ - [ - 0, - { - "num_slots": 1, - "num_transactions": 4, - "sample_period_secs": 60 - } - ] + { + "slot": 0, + "numSlots": 1, + "numTransactions": 4, + "samplePeriodSecs": 60 + } ], });