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(rpc): implement Filecoin.F3ListParticipants #4910

Merged
merged 2 commits into from
Oct 17, 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
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
Loading