From 2d4b8fe5cc707f0d7c2385afbc04213161d011dd Mon Sep 17 00:00:00 2001 From: hanabi1224 Date: Thu, 17 Oct 2024 17:58:06 +0800 Subject: [PATCH] feat(rpc): implement Filecoin.F3ListParticipants (#4910) --- CHANGELOG.md | 3 +++ src/rpc/methods/f3.rs | 34 +++++++++++++++++++++++++++++----- src/rpc/mod.rs | 1 + 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71e94303418..81a3f1ca148 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,9 @@ ### Added +- [#4910](https://github.com/ChainSafe/forest/issues/4910) Add support for the + `Filecoin.F3ListParticipants` RPC method. + ### Changed ### Removed diff --git a/src/rpc/methods/f3.rs b/src/rpc/methods/f3.rs index f874a6324c4..c717c43fed4 100644 --- a/src/rpc/methods/f3.rs +++ b/src/rpc/methods/f3.rs @@ -436,6 +436,17 @@ impl RpcMethod<1> for ProtectPeer { } pub enum GetParticipatingMinerIDs {} + +impl GetParticipatingMinerIDs { + fn run() -> Vec { + let mut ids = F3_LEASE_MANAGER.get_active_participants(); + if let Some(permanent_miner_ids) = (*F3_PERMANENT_PARTICIPATING_MINER_IDS).clone() { + ids.extend(permanent_miner_ids); + } + ids.into_iter().collect() + } +} + impl RpcMethod<0> for GetParticipatingMinerIDs { const NAME: &'static str = "F3.GetParticipatingMinerIDs"; const PARAM_NAMES: [&'static str; 0] = []; @@ -446,11 +457,7 @@ impl RpcMethod<0> for GetParticipatingMinerIDs { type Ok = Vec; async fn handle(_: Ctx, _: Self::Params) -> Result { - let mut ids = F3_LEASE_MANAGER.get_active_participants(); - if let Some(permanent_miner_ids) = (*F3_PERMANENT_PARTICIPATING_MINER_IDS).clone() { - ids.extend(permanent_miner_ids); - } - Ok(ids.into_iter().collect()) + Ok(Self::run()) } } @@ -659,6 +666,23 @@ impl RpcMethod<0> for F3GetProgress { } } +/// returns the list of miner addresses that are currently participating in F3 via this node. +pub enum F3ListParticipants {} +impl RpcMethod<0> for F3ListParticipants { + const NAME: &'static str = "Filecoin.F3ListParticipants"; + const PARAM_NAMES: [&'static str; 0] = []; + const API_PATHS: ApiPaths = ApiPaths::V1; + const PERMISSION: Permission = Permission::Read; + + type Params = (); + type Ok = Vec
; + + async fn handle(_: Ctx, _: Self::Params) -> Result { + let ids = GetParticipatingMinerIDs::run(); + Ok(ids.into_iter().map(Address::new_id).collect()) + } +} + /// F3Participate should be called by a storage provider to participate in signing F3 consensus. /// Calling this API gives the node a lease to sign in F3 on behalf of given SP. /// The lease should be active only on one node. The lease will expire at the newLeaseExpiration. diff --git a/src/rpc/mod.rs b/src/rpc/mod.rs index d0abd4f6740..145693a6b39 100644 --- a/src/rpc/mod.rs +++ b/src/rpc/mod.rs @@ -240,6 +240,7 @@ macro_rules! for_each_method { $callback!(crate::rpc::f3::F3GetF3PowerTable); $callback!(crate::rpc::f3::F3IsRunning); $callback!(crate::rpc::f3::F3GetProgress); + $callback!(crate::rpc::f3::F3ListParticipants); $callback!(crate::rpc::f3::F3GetLatestCertificate); $callback!(crate::rpc::f3::F3Participate); $callback!(crate::rpc::f3::GetHead);