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(cli): forest-cli f3 status #4949

Merged
merged 2 commits into from
Oct 29, 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 @@ -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() %>
Loading