Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add solana monitoring data #5277

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions state-chain/custom-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use cf_chains::{
address::{ForeignChainAddressHumanreadable, ToHumanreadableAddress},
dot::PolkadotAccountId,
eth::Address as EthereumAddress,
sol::SolAddress,
Chain,
};
use cf_primitives::{
Expand Down Expand Up @@ -40,9 +41,9 @@ use state_chain_runtime::{
chainflip::{BlockUpdate, Offence},
constants::common::TX_FEE_MULTIPLIER,
monitoring_apis::{
AuthoritiesInfo, BtcUtxos, EpochState, ExternalChainsBlockHeight, FeeImbalance, FlipSupply,
LastRuntimeUpgradeInfo, MonitoringData, OpenDepositChannels, PendingBroadcasts,
PendingTssCeremonies, RedemptionsInfo,
ActivateKeysBroadcastIds, AuthoritiesInfo, BtcUtxos, EpochState, ExternalChainsBlockHeight,
FeeImbalance, FlipSupply, LastRuntimeUpgradeInfo, MonitoringData, OpenDepositChannels,
PendingBroadcasts, PendingTssCeremonies, RedemptionsInfo, SolanaNonces,
},
runtime_apis::{
BoostPoolDepth, BoostPoolDetails, BrokerInfo, CustomRuntimeApi, DispatchErrorWithMessage,
Expand Down Expand Up @@ -123,6 +124,10 @@ pub struct RpcMonitoringData {
pub pending_swaps: u32,
pub dot_aggkey: PolkadotAccountId,
pub flip_supply: RpcFlipSupply,
pub sol_aggkey: SolAddress,
pub sol_onchain_key: SolAddress,
pub sol_nonces: SolanaNonces,
pub activating_key_broadcast_ids: ActivateKeysBroadcastIds,
}
impl From<MonitoringData> for RpcMonitoringData {
fn from(monitoring_data: MonitoringData) -> Self {
Expand All @@ -141,6 +146,10 @@ impl From<MonitoringData> for RpcMonitoringData {
pending_swaps: monitoring_data.pending_swaps,
dot_aggkey: monitoring_data.dot_aggkey,
flip_supply: monitoring_data.flip_supply.into(),
sol_aggkey: monitoring_data.sol_aggkey,
sol_onchain_key: monitoring_data.sol_onchain_key,
sol_nonces: monitoring_data.sol_nonces,
activating_key_broadcast_ids: monitoring_data.activating_key_broadcast_ids,
}
}
}
Expand Down
25 changes: 20 additions & 5 deletions state-chain/custom-rpc/src/monitoring.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use crate::{
to_rpc_error, BlockT, CustomRpc, RpcAccountInfoV2, RpcFeeImbalance, RpcMonitoringData,
};
use cf_chains::dot::PolkadotAccountId;
use cf_chains::{dot::PolkadotAccountId, sol::SolAddress};
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
use sc_client_api::{BlockchainEvents, HeaderBackend};
use sp_core::{bounded_vec::BoundedVec, ConstU32};
use state_chain_runtime::{
chainflip::Offence,
monitoring_apis::{
AuthoritiesInfo, BtcUtxos, EpochState, ExternalChainsBlockHeight, LastRuntimeUpgradeInfo,
MonitoringRuntimeApi, OpenDepositChannels, PendingBroadcasts, PendingTssCeremonies,
RedemptionsInfo,
ActivateKeysBroadcastIds, AuthoritiesInfo, BtcUtxos, EpochState, ExternalChainsBlockHeight,
LastRuntimeUpgradeInfo, MonitoringRuntimeApi, OpenDepositChannels, PendingBroadcasts,
PendingTssCeremonies, RedemptionsInfo, SolanaNonces,
},
};

Expand Down Expand Up @@ -61,6 +61,17 @@ pub trait MonitoringApi {
&self,
at: Option<state_chain_runtime::Hash>,
) -> RpcResult<LastRuntimeUpgradeInfo>;
#[method(name = "rotation_broadcast_ids")]
fn cf_rotation_broadcast_ids(
&self,
at: Option<state_chain_runtime::Hash>,
) -> RpcResult<ActivateKeysBroadcastIds>;
#[method(name = "sol_nonces")]
fn cf_sol_nonces(&self, at: Option<state_chain_runtime::Hash>) -> RpcResult<SolanaNonces>;
#[method(name = "sol_aggkey")]
fn cf_sol_aggkey(&self, at: Option<state_chain_runtime::Hash>) -> RpcResult<SolAddress>;
#[method(name = "sol_onchain_key")]
fn cf_sol_onchain_key(&self, at: Option<state_chain_runtime::Hash>) -> RpcResult<SolAddress>;
#[method(name = "data")]
fn cf_monitoring_data(
&self,
Expand Down Expand Up @@ -111,7 +122,11 @@ where
cf_pending_tss_ceremonies_count -> PendingTssCeremonies,
cf_pending_swaps_count -> u32,
cf_open_deposit_channels_count -> OpenDepositChannels,
cf_build_version -> LastRuntimeUpgradeInfo
cf_build_version -> LastRuntimeUpgradeInfo,
cf_rotation_broadcast_ids -> ActivateKeysBroadcastIds,
cf_sol_nonces -> SolanaNonces,
cf_sol_aggkey -> SolAddress,
cf_sol_onchain_key -> SolAddress
}

fn cf_fee_imbalance(
Expand Down
37 changes: 33 additions & 4 deletions state-chain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ use crate::{
},
migrations::serialize_solana_broadcast::{NoopUpgrade, SerializeSolanaBroadcastMigration},
monitoring_apis::{
AuthoritiesInfo, BtcUtxos, EpochState, ExternalChainsBlockHeight, FeeImbalance, FlipSupply,
LastRuntimeUpgradeInfo, MonitoringData, OpenDepositChannels, PendingBroadcasts,
PendingTssCeremonies, RedemptionsInfo,
ActivateKeysBroadcastIds, AuthoritiesInfo, BtcUtxos, EpochState, ExternalChainsBlockHeight,
FeeImbalance, FlipSupply, LastRuntimeUpgradeInfo, MonitoringData, OpenDepositChannels,
PendingBroadcasts, PendingTssCeremonies, RedemptionsInfo, SolanaNonces,
},
runtime_apis::{
runtime_decl_for_custom_runtime_api::CustomRuntimeApiV1, AuctionState, BoostPoolDepth,
Expand All @@ -47,7 +47,7 @@ use cf_chains::{
dot::{self, PolkadotAccountId, PolkadotCrypto},
eth::{self, api::EthereumApi, Address as EthereumAddress, Ethereum},
evm::EvmCrypto,
sol::SolanaCrypto,
sol::{SolAddress, SolanaCrypto},
Arbitrum, Bitcoin, DefaultRetryPolicy, ForeignChain, Polkadot, Solana, TransactionBuilder,
};
use cf_primitives::{BroadcastId, EpochIndex, NetworkEnvironment, STABLE_ASSET};
Expand Down Expand Up @@ -2154,6 +2154,31 @@ impl_runtime_apis! {
spec_name: info.spec_name,
}
}
fn cf_rotation_broadcast_ids() -> ActivateKeysBroadcastIds{
ActivateKeysBroadcastIds{
ethereum: pallet_cf_broadcast::IncomingKeyAndBroadcastId::<Runtime, EthereumInstance>::get().map(|val| val.1),
bitcoin: pallet_cf_broadcast::IncomingKeyAndBroadcastId::<Runtime, BitcoinInstance>::get().map(|val| val.1),
polkadot: pallet_cf_broadcast::IncomingKeyAndBroadcastId::<Runtime, PolkadotInstance>::get().map(|val| val.1),
arbitrum: pallet_cf_broadcast::IncomingKeyAndBroadcastId::<Runtime, ArbitrumInstance>::get().map(|val| val.1),
solana: {
let broadcast_id = pallet_cf_broadcast::IncomingKeyAndBroadcastId::<Runtime, SolanaInstance>::get().map(|val| val.1);
(broadcast_id, pallet_cf_broadcast::AwaitingBroadcast::<Runtime, SolanaInstance>::get(broadcast_id.unwrap_or_default()).map(|broadcast_data| broadcast_data.transaction_out_id))
}
}
}
fn cf_sol_nonces() -> SolanaNonces{
SolanaNonces {
available: pallet_cf_environment::SolanaAvailableNonceAccounts::<Runtime>::get(),
unavailable: pallet_cf_environment::SolanaUnavailableNonceAccounts::<Runtime>::iter_keys().collect()
}
}
fn cf_sol_aggkey() -> SolAddress{
let epoch = SolanaThresholdSigner::current_key_epoch().unwrap_or_default();
SolanaThresholdSigner::keys(epoch).unwrap_or_default()
}
fn cf_sol_onchain_key() -> SolAddress{
SolanaBroadcaster::current_on_chain_key().unwrap_or_default()
}
fn cf_monitoring_data() -> MonitoringData {
MonitoringData{
external_chains_height: Self::cf_external_chains_block_height(),
Expand All @@ -2173,6 +2198,10 @@ impl_runtime_apis! {
let flip = Self::cf_flip_supply();
FlipSupply { total_supply: flip.0, offchain_supply: flip.1}
},
sol_aggkey: Self::cf_sol_aggkey(),
sol_onchain_key: Self::cf_sol_onchain_key(),
sol_nonces: Self::cf_sol_nonces(),
activating_key_broadcast_ids: Self::cf_rotation_broadcast_ids(),
}
}
fn cf_accounts_info(accounts: BoundedVec<AccountId, ConstU32<10>>) -> Vec<ValidatorInfo> {
Expand Down
28 changes: 27 additions & 1 deletion state-chain/runtime/src/monitoring_apis.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::{chainflip::Offence, ValidatorInfo};
use cf_chains::dot::PolkadotAccountId;
use cf_chains::{
dot::PolkadotAccountId,
sol::{api::DurableNonceAndAccount, SolAddress, SolSignature},
};
use cf_primitives::AssetAmount;
use codec::{Decode, Encode};
use frame_support::sp_runtime::AccountId32;
Expand Down Expand Up @@ -103,6 +106,21 @@ pub struct FlipSupply {
pub offchain_supply: u128,
}

#[derive(Serialize, Deserialize, Encode, Decode, Eq, PartialEq, TypeInfo, Debug)]
pub struct SolanaNonces {
pub available: Vec<DurableNonceAndAccount>,
pub unavailable: Vec<SolAddress>,
}

#[derive(Serialize, Deserialize, Encode, Decode, Eq, PartialEq, TypeInfo, Debug)]
pub struct ActivateKeysBroadcastIds {
pub ethereum: Option<u32>,
pub bitcoin: Option<u32>,
pub polkadot: Option<u32>,
pub arbitrum: Option<u32>,
pub solana: (Option<u32>, Option<SolSignature>),
}

#[derive(Serialize, Deserialize, Encode, Decode, Eq, PartialEq, TypeInfo, Debug)]
pub struct MonitoringData {
pub external_chains_height: ExternalChainsBlockHeight,
Expand All @@ -119,6 +137,10 @@ pub struct MonitoringData {
pub pending_swaps: u32,
pub dot_aggkey: PolkadotAccountId,
pub flip_supply: FlipSupply,
pub sol_aggkey: SolAddress,
pub sol_onchain_key: SolAddress,
pub sol_nonces: SolanaNonces,
pub activating_key_broadcast_ids: ActivateKeysBroadcastIds,
}

decl_runtime_apis!(
Expand All @@ -136,6 +158,10 @@ decl_runtime_apis!(
fn cf_open_deposit_channels_count() -> OpenDepositChannels;
fn cf_fee_imbalance() -> FeeImbalance<AssetAmount>;
fn cf_build_version() -> LastRuntimeUpgradeInfo;
fn cf_rotation_broadcast_ids() -> ActivateKeysBroadcastIds;
fn cf_sol_nonces() -> SolanaNonces;
fn cf_sol_aggkey() -> SolAddress;
fn cf_sol_onchain_key() -> SolAddress;
fn cf_monitoring_data() -> MonitoringData;
fn cf_accounts_info(
accounts: BoundedVec<AccountId32, sp_core::ConstU32<10>>,
Expand Down
Loading