Skip to content

Commit

Permalink
fix: min_active_bid returned as NumberOrHex
Browse files Browse the repository at this point in the history
  • Loading branch information
marcellorigotti authored and dandanlen committed Oct 18, 2024
1 parent 025a199 commit b345fa9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 29 deletions.
27 changes: 4 additions & 23 deletions state-chain/custom-rpc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::boost_pool_rpc::BoostPoolFeesRpc;
use crate::{boost_pool_rpc::BoostPoolFeesRpc, monitoring::RpcEpochStateV2};
use boost_pool_rpc::BoostPoolDetailsRpc;
use cf_amm::{
common::{Amount, PoolPairsMap, Side, Tick},
Expand Down Expand Up @@ -41,7 +41,7 @@ use state_chain_runtime::{
chainflip::{BlockUpdate, Offence},
constants::common::TX_FEE_MULTIPLIER,
monitoring_apis::{
ActivateKeysBroadcastIds, AuthoritiesInfo, BtcUtxos, EpochState, ExternalChainsBlockHeight,
ActivateKeysBroadcastIds, AuthoritiesInfo, BtcUtxos, ExternalChainsBlockHeight,
FeeImbalance, FlipSupply, LastRuntimeUpgradeInfo, MonitoringData, OpenDepositChannels,
PendingBroadcasts, PendingTssCeremonies, RedemptionsInfo, SolanaNonces,
},
Expand All @@ -62,26 +62,7 @@ use std::{
pub mod monitoring;
pub mod order_fills;

#[derive(Serialize, Deserialize, Clone)]
pub struct RpcEpochState {
pub epoch_duration: u32,
pub current_epoch_started_at: u32,
pub current_epoch_index: u32,
pub min_active_bid: Option<NumberOrHex>,
pub rotation_phase: String,
}
impl From<EpochState> for RpcEpochState {
fn from(rotation_state: EpochState) -> Self {
Self {
epoch_duration: rotation_state.epoch_duration,
current_epoch_started_at: rotation_state.current_epoch_started_at,
current_epoch_index: rotation_state.current_epoch_index,
rotation_phase: rotation_state.rotation_phase,
min_active_bid: rotation_state.min_active_bid.map(Into::into),
}
}
}
#[derive(Serialize, Deserialize, Clone)]
#[derive(Serialize, Deserialize)]
pub struct RpcRedemptionsInfo {
pub total_balance: NumberOrHex,
pub count: u32,
Expand Down Expand Up @@ -112,7 +93,7 @@ impl From<FlipSupply> for RpcFlipSupply {
pub struct RpcMonitoringData {
pub external_chains_height: ExternalChainsBlockHeight,
pub btc_utxos: BtcUtxos,
pub epoch: RpcEpochState,
pub epoch: RpcEpochStateV2,
pub pending_redemptions: RpcRedemptionsInfo,
pub pending_broadcasts: PendingBroadcasts,
pub pending_tss: PendingTssCeremonies,
Expand Down
32 changes: 26 additions & 6 deletions state-chain/custom-rpc/src/monitoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{
to_rpc_error, BlockT, CustomRpc, RpcAccountInfoV2, RpcFeeImbalance, RpcMonitoringData,
};
use cf_chains::{dot::PolkadotAccountId, sol::SolAddress};
use cf_utilities::rpc::NumberOrHex;
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
use sc_client_api::{BlockchainEvents, HeaderBackend};
use serde::{Deserialize, Serialize};
Expand All @@ -14,23 +15,42 @@ use state_chain_runtime::{
PendingTssCeremonies, RedemptionsInfo, SolanaNonces,
},
};
impl From<EpochState> for RpcEpochState {
fn from(rotation_state: EpochState) -> Self {
Self {
epoch_duration: rotation_state.epoch_duration,
current_epoch_started_at: rotation_state.current_epoch_started_at,
current_epoch_index: rotation_state.current_epoch_index,
rotation_phase: rotation_state.rotation_phase,
min_active_bid: rotation_state.min_active_bid.map(Into::into),
}
}
}
#[derive(Serialize, Deserialize)]
pub struct RpcEpochState {
pub epoch_duration: u32,
pub current_epoch_started_at: u32,
pub current_epoch_index: u32,
pub min_active_bid: Option<NumberOrHex>,
pub rotation_phase: String,
}

// Temporary struct to hold the deprecated blocks_per_epoch field.
// Can be deleted after v1.7 is released (meaning: after the version is bumped to 1.8).
#[derive(Serialize, Deserialize)]
pub struct RpcEpochState {
pub struct RpcEpochStateV2 {
#[deprecated(
since = "1.8.0",
note = "This field is deprecated and will be removed in v1.8. Use blocks_per_epoch instead."
)]
blocks_per_epoch: u32,
#[serde(flatten)]
epoch_state: EpochState,
epoch_state: RpcEpochState,
}

impl From<EpochState> for RpcEpochState {
impl From<EpochState> for RpcEpochStateV2 {
fn from(epoch_state: EpochState) -> Self {
Self { blocks_per_epoch: epoch_state.epoch_duration, epoch_state }
Self { blocks_per_epoch: epoch_state.epoch_duration, epoch_state: epoch_state.into() }
}
}

Expand All @@ -53,7 +73,7 @@ pub trait MonitoringApi {
at: Option<state_chain_runtime::Hash>,
) -> RpcResult<Vec<(Offence, u32)>>;
#[method(name = "epoch_state")]
fn cf_epoch_state(&self, at: Option<state_chain_runtime::Hash>) -> RpcResult<RpcEpochState>;
fn cf_epoch_state(&self, at: Option<state_chain_runtime::Hash>) -> RpcResult<RpcEpochStateV2>;
#[method(name = "redemptions")]
fn cf_redemptions(&self, at: Option<state_chain_runtime::Hash>) -> RpcResult<RedemptionsInfo>;
#[method(name = "pending_broadcasts")]
Expand Down Expand Up @@ -137,7 +157,7 @@ where
cf_btc_utxos -> BtcUtxos,
cf_dot_aggkey -> PolkadotAccountId,
cf_suspended_validators -> Vec<(Offence, u32)>,
cf_epoch_state -> RpcEpochState [with: RpcEpochState::from],
cf_epoch_state -> RpcEpochStateV2 [with: RpcEpochStateV2::from],
cf_redemptions -> RedemptionsInfo,
cf_pending_broadcasts_count -> PendingBroadcasts,
cf_pending_tss_ceremonies_count -> PendingTssCeremonies,
Expand Down

0 comments on commit b345fa9

Please sign in to comment.