From 08106b46311192d40e2c4d45f545fc29b0a16a06 Mon Sep 17 00:00:00 2001 From: hanabi1224 Date: Thu, 17 Oct 2024 13:25:46 +0800 Subject: [PATCH 1/2] feat(rpc): implement Filecoin.F3ListParticipants --- src/rpc/methods/f3.rs | 34 +++++++++++++++++++++++++++++----- src/rpc/mod.rs | 1 + 2 files changed, 30 insertions(+), 5 deletions(-) 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 6b43a10cfac..83869656ee6 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); From c29d9fab6cce17571840b74572196f6cdb1575d7 Mon Sep 17 00:00:00 2001 From: hanabi1224 Date: Thu, 17 Oct 2024 13:27:51 +0800 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) 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