Skip to content

Commit

Permalink
explorer cleanup: JSON RPC methods and types (MystenLabs#16845)
Browse files Browse the repository at this point in the history
## Description 

title, these endpoints were added solely for explorer, thus can be
removed too.

## Test Plan 

CI

---
If your changes are not user-facing and do not break anything, you can
skip the following section. Otherwise, please briefly describe what has
changed under the Release Notes section.

### Type of Change (Check all that apply)

- [ ] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
  • Loading branch information
gegaowp authored Mar 25, 2024
1 parent d4ef593 commit 5f28b8b
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 190 deletions.
80 changes: 1 addition & 79 deletions crates/sui-indexer/src/apis/extended_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use jsonrpsee::{core::RpcResult, RpcModule};
use sui_json_rpc::SuiRpcModule;
use sui_json_rpc_api::{validate_limit, ExtendedApiServer, QUERY_MAX_RESULT_LIMIT_CHECKPOINTS};
use sui_json_rpc_types::{
AddressMetrics, CheckpointedObjectID, EpochInfo, EpochMetrics, EpochMetricsPage, EpochPage,
MoveCallMetrics, NetworkMetrics, Page, QueryObjectsPage, SuiObjectResponseQuery,
CheckpointedObjectID, EpochInfo, EpochPage, Page, QueryObjectsPage, SuiObjectResponseQuery,
};
use sui_open_rpc::Module;
use sui_types::sui_serde::BigInt;
Expand Down Expand Up @@ -52,45 +51,6 @@ impl ExtendedApiServer for ExtendedApi {
})
}

async fn get_epoch_metrics(
&self,
cursor: Option<BigInt<u64>>,
limit: Option<usize>,
descending_order: Option<bool>,
) -> RpcResult<EpochMetricsPage> {
let limit = validate_limit(limit, QUERY_MAX_RESULT_LIMIT_CHECKPOINTS)?;
let epochs = self
.inner
.spawn_blocking(move |this| {
this.get_epochs(
cursor.map(|x| *x),
limit + 1,
descending_order.unwrap_or(false),
)
})
.await?;

let mut epoch_metrics = epochs
.into_iter()
.map(|e| EpochMetrics {
epoch: e.epoch,
epoch_total_transactions: e.epoch_total_transactions,
first_checkpoint_id: e.first_checkpoint_id,
epoch_start_timestamp: e.epoch_start_timestamp,
end_of_epoch_info: e.end_of_epoch_info,
})
.collect::<Vec<_>>();

let has_next_page = epoch_metrics.len() > limit;
epoch_metrics.truncate(limit);
let next_cursor = epoch_metrics.last().map(|e| e.epoch);
Ok(Page {
data: epoch_metrics,
next_cursor: next_cursor.map(|id| id.into()),
has_next_page,
})
}

async fn get_current_epoch(&self) -> RpcResult<EpochInfo> {
let stored_epoch = self
.inner
Expand All @@ -111,44 +71,6 @@ impl ExtendedApiServer for ExtendedApi {
.into())
}

async fn get_network_metrics(&self) -> RpcResult<NetworkMetrics> {
Err(jsonrpsee::types::error::CallError::Custom(
jsonrpsee::types::error::ErrorCode::MethodNotFound.into(),
)
.into())
}

async fn get_move_call_metrics(&self) -> RpcResult<MoveCallMetrics> {
Err(jsonrpsee::types::error::CallError::Custom(
jsonrpsee::types::error::ErrorCode::MethodNotFound.into(),
)
.into())
}

async fn get_latest_address_metrics(&self) -> RpcResult<AddressMetrics> {
Err(jsonrpsee::types::error::CallError::Custom(
jsonrpsee::types::error::ErrorCode::MethodNotFound.into(),
)
.into())
}

async fn get_checkpoint_address_metrics(&self, _checkpoint: u64) -> RpcResult<AddressMetrics> {
Err(jsonrpsee::types::error::CallError::Custom(
jsonrpsee::types::error::ErrorCode::MethodNotFound.into(),
)
.into())
}

async fn get_all_epoch_address_metrics(
&self,
_descending_order: Option<bool>,
) -> RpcResult<Vec<AddressMetrics>> {
Err(jsonrpsee::types::error::CallError::Custom(
jsonrpsee::types::error::ErrorCode::MethodNotFound.into(),
)
.into())
}

async fn get_total_transactions(&self) -> RpcResult<BigInt<u64>> {
let latest_checkpoint = self
.inner
Expand Down
34 changes: 1 addition & 33 deletions crates/sui-json-rpc-api/src/extended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use jsonrpsee::core::RpcResult;
use jsonrpsee::proc_macros::rpc;

use sui_json_rpc_types::{
AddressMetrics, CheckpointedObjectID, EpochInfo, EpochMetricsPage, EpochPage, MoveCallMetrics,
NetworkMetrics, QueryObjectsPage, SuiObjectResponseQuery,
CheckpointedObjectID, EpochInfo, EpochPage, QueryObjectsPage, SuiObjectResponseQuery,
};
use sui_open_rpc_macros::open_rpc;
use sui_types::sui_serde::BigInt;
Expand All @@ -26,18 +25,6 @@ pub trait ExtendedApi {
descending_order: Option<bool>,
) -> RpcResult<EpochPage>;

/// Return a list of epoch metrics, which is a subset of epoch info
#[method(name = "getEpochMetrics")]
async fn get_epoch_metrics(
&self,
/// optional paging cursor
cursor: Option<BigInt<u64>>,
/// maximum number of items per page
limit: Option<usize>,
/// flag to return results in descending order
descending_order: Option<bool>,
) -> RpcResult<EpochMetricsPage>;

/// Return current epoch info
#[method(name = "getCurrentEpoch")]
async fn get_current_epoch(&self) -> RpcResult<EpochInfo>;
Expand All @@ -54,25 +41,6 @@ pub trait ExtendedApi {
limit: Option<usize>,
) -> RpcResult<QueryObjectsPage>;

/// Return Network metrics
#[method(name = "getNetworkMetrics")]
async fn get_network_metrics(&self) -> RpcResult<NetworkMetrics>;

/// Return Network metrics
#[method(name = "getMoveCallMetrics")]
async fn get_move_call_metrics(&self) -> RpcResult<MoveCallMetrics>;

/// Address related metrics
#[method(name = "getLatestAddressMetrics")]
async fn get_latest_address_metrics(&self) -> RpcResult<AddressMetrics>;
#[method(name = "getCheckpointAddressMetrics")]
async fn get_checkpoint_address_metrics(&self, checkpoint: u64) -> RpcResult<AddressMetrics>;
#[method(name = "getAllEpochAddressMetrics")]
async fn get_all_epoch_address_metrics(
&self,
descending_order: Option<bool>,
) -> RpcResult<Vec<AddressMetrics>>;

#[method(name = "getTotalTransactions")]
async fn get_total_transactions(&self) -> RpcResult<BigInt<u64>>;
}
78 changes: 0 additions & 78 deletions crates/sui-json-rpc-types/src/sui_extended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use sui_types::sui_system_state::sui_system_state_summary::SuiValidatorSummary;
use crate::Page;

pub type EpochPage = Page<EpochInfo, BigInt<u64>>;
pub type EpochMetricsPage = Page<EpochMetrics, BigInt<u64>>;

#[serde_as]
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
Expand Down Expand Up @@ -59,26 +58,6 @@ impl EpochInfo {
}
}

/// a light-weight version of `EpochInfo` for faster loading
#[serde_as]
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct EpochMetrics {
#[schemars(with = "BigInt<u64>")]
#[serde_as(as = "BigInt<u64>")]
pub epoch: EpochId,
#[schemars(with = "BigInt<u64>")]
#[serde_as(as = "BigInt<u64>")]
pub epoch_total_transactions: u64,
#[schemars(with = "BigInt<u64>")]
#[serde_as(as = "BigInt<u64>")]
pub first_checkpoint_id: CheckpointSequenceNumber,
#[schemars(with = "BigInt<u64>")]
#[serde_as(as = "BigInt<u64>")]
pub epoch_start_timestamp: u64,
pub end_of_epoch_info: Option<EndOfEpochInfo>,
}

#[serde_as]
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -125,51 +104,6 @@ pub struct EndOfEpochInfo {
pub leftover_storage_fund_inflow: u64,
}

#[serde_as]
#[derive(Serialize, Deserialize, Debug, JsonSchema, Clone)]
#[serde(rename_all = "camelCase")]
pub struct NetworkMetrics {
/// Current TPS - Transaction Blocks per Second.
pub current_tps: f64,
/// Peak TPS in the past 30 days
pub tps_30_days: f64,
/// Total number of packages published in the network
#[schemars(with = "BigInt<u64>")]
#[serde_as(as = "BigInt<u64>")]
pub total_packages: u64,
/// Total number of addresses seen in the network
#[schemars(with = "BigInt<u64>")]
#[serde_as(as = "BigInt<u64>")]
pub total_addresses: u64,
/// Total number of live objects in the network
#[schemars(with = "BigInt<u64>")]
#[serde_as(as = "BigInt<u64>")]
pub total_objects: u64,
/// Current epoch number
#[schemars(with = "BigInt<u64>")]
#[serde_as(as = "BigInt<u64>")]
pub current_epoch: u64,
/// Current checkpoint number
#[schemars(with = "BigInt<u64>")]
#[serde_as(as = "BigInt<u64>")]
pub current_checkpoint: u64,
}

#[serde_as]
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct MoveCallMetrics {
#[schemars(with = "Vec<(MoveFunctionName, BigInt<usize>)>")]
#[serde_as(as = "Vec<(_, BigInt<usize>)>")]
pub rank_3_days: Vec<(MoveFunctionName, usize)>,
#[schemars(with = "Vec<(MoveFunctionName, BigInt<usize>)>")]
#[serde_as(as = "Vec<(_, BigInt<usize>)>")]
pub rank_7_days: Vec<(MoveFunctionName, usize)>,
#[schemars(with = "Vec<(MoveFunctionName, BigInt<usize>)>")]
#[serde_as(as = "Vec<(_, BigInt<usize>)>")]
pub rank_30_days: Vec<(MoveFunctionName, usize)>,
}

#[serde_as]
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[serde(rename_all = "camelCase")]
Expand All @@ -182,15 +116,3 @@ pub struct MoveFunctionName {
#[serde_as(as = "DisplayFromStr")]
pub function: Identifier,
}

#[serde_as]
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct AddressMetrics {
pub checkpoint: u64,
pub epoch: u64,
pub timestamp_ms: u64,
pub cumulative_addresses: u64,
pub cumulative_active_addresses: u64,
pub daily_active_addresses: u64,
}

0 comments on commit 5f28b8b

Please sign in to comment.