Skip to content

Commit

Permalink
feat(cli): forest-cli f3 status (#4949)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanabi1224 authored Oct 29, 2024
1 parent dbdeae7 commit e81e3de
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
- [#4937](https://github.com/ChainSafe/forest/pull/4937) Added
`forest-cli f3 manifest` CLI command.

- [#4949](https://github.com/ChainSafe/forest/pull/4949) Added
`forest-cli f3 status` CLI command.

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

Expand Down
31 changes: 30 additions & 1 deletion src/cli/subcommands/f3_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Copyright 2019-2024 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use crate::rpc::{self, f3::F3Manifest, prelude::*};
use crate::rpc::{
self,
f3::{F3Instant, F3Manifest},
prelude::*,
};
use cid::Cid;
use clap::{Subcommand, ValueEnum};
use sailfish::TemplateSimple;
Expand All @@ -27,6 +31,8 @@ pub enum F3Commands {
#[arg(long, value_enum, default_value_t = F3OutputFormat::Text)]
output: F3OutputFormat,
},
/// Checks the F3 status.
Status,
}

impl F3Commands {
Expand All @@ -45,6 +51,17 @@ impl F3Commands {
}
Ok(())
}
Self::Status => {
let is_running = client.call(F3IsRunning::request(())?).await?;
println!("Running: {is_running}");
let progress = client.call(F3GetProgress::request(())?).await?;
let progress_template = ProgressTemplate::new(progress);
println!("{}", progress_template.render_once()?);
let manifest = client.call(F3GetManifest::request(())?).await?;
let manifest_template = ManifestTemplate::new(manifest);
println!("{}", manifest_template.render_once()?);
Ok(())
}
}
}
}
Expand All @@ -66,6 +83,18 @@ impl ManifestTemplate {
}
}

#[derive(TemplateSimple, Debug, Clone, Serialize, Deserialize)]
#[template(path = "cli/f3/progress.stpl")]
struct ProgressTemplate {
progress: F3Instant,
}

impl ProgressTemplate {
fn new(progress: F3Instant) -> Self {
Self { progress }
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/methods/f3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
mod types;
mod util;

pub use self::types::{F3LeaseManager, F3Manifest};
pub use self::types::{F3Instant, F3LeaseManager, F3Manifest};
use self::{types::*, util::*};
use super::wallet::WalletSign;
use crate::{
Expand Down Expand Up @@ -650,7 +650,7 @@ impl RpcMethod<0> for F3IsRunning {
const PERMISSION: Permission = Permission::Read;

type Params = ();
type Ok = serde_json::Value;
type Ok = bool;

async fn handle(_: Ctx<impl Blockstore>, (): Self::Params) -> Result<Self::Ok, ServerError> {
let client = get_rpc_http_client()?;
Expand Down
15 changes: 15 additions & 0 deletions src/rpc/methods/f3/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,21 @@ pub struct F3Instant {
}
lotus_json_with_self!(F3Instant);

impl F3Instant {
pub fn phase_string(&self) -> &'static str {
match self.phase {
0 => "INITIAL",
1 => "QUALITY",
2 => "CONVERGE",
3 => "PREPARE",
4 => "COMMIT",
5 => "DECIDE",
6 => "TERMINATED",
_ => "UNKNOWN",
}
}
}

#[derive(PartialEq, Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
pub struct GpbftConfig {
Expand Down
4 changes: 4 additions & 0 deletions templates/cli/f3/progress.stpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Progress:
Instance: <%= progress.id %>
Round: <%= progress.round %>
Phase: <%= progress.phase_string() %>

0 comments on commit e81e3de

Please sign in to comment.