Skip to content

Commit

Permalink
feat(rpc): implement Filecoin.F3ListParticipants (#4910)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanabi1224 authored Oct 17, 2024
1 parent 7477856 commit 2d4b8fe
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

### Added

- [#4910](https://github.com/ChainSafe/forest/issues/4910) Add support for the
`Filecoin.F3ListParticipants` RPC method.

### Changed

### Removed
Expand Down
34 changes: 29 additions & 5 deletions src/rpc/methods/f3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,17 @@ impl RpcMethod<1> for ProtectPeer {
}

pub enum GetParticipatingMinerIDs {}

impl GetParticipatingMinerIDs {
fn run() -> Vec<u64> {
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] = [];
Expand All @@ -446,11 +457,7 @@ impl RpcMethod<0> for GetParticipatingMinerIDs {
type Ok = Vec<u64>;

async fn handle(_: Ctx<impl Blockstore>, _: Self::Params) -> Result<Self::Ok, ServerError> {
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())
}
}

Expand Down Expand Up @@ -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<Address>;

async fn handle(_: Ctx<impl Blockstore>, _: Self::Params) -> Result<Self::Ok, ServerError> {
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.
Expand Down
1 change: 1 addition & 0 deletions src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2d4b8fe

Please sign in to comment.