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

Eng 766. List bottom up checkpoint status. #748

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 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
4 changes: 4 additions & 0 deletions ipc/cli/src/commands/checkpoint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::commands::checkpoint::quorum_reached::{
GetQuorumReacehdEvents, GetQuorumReachedEventsArgs,
};
use crate::commands::checkpoint::relayer::{BottomUpRelayer, BottomUpRelayerArgs};
use crate::commands::checkpoint::status::{Status, StatusArgs};
use crate::{CommandLineHandler, GlobalArguments};
use clap::{Args, Subcommand};

Expand All @@ -23,6 +24,7 @@ mod list_checkpoints;
mod list_validator_changes;
mod quorum_reached;
mod relayer;
mod status;

#[derive(Debug, Args)]
#[command(name = "checkpoint", about = "checkpoint related commands")]
Expand All @@ -35,6 +37,7 @@ pub(crate) struct CheckpointCommandsArgs {
impl CheckpointCommandsArgs {
pub async fn handle(&self, global: &GlobalArguments) -> anyhow::Result<()> {
match &self.command {
Commands::Status(args) => Status::handle(global, args).await,
Commands::ListBottomup(args) => ListBottomUpCheckpoints::handle(global, args).await,
Commands::Relayer(args) => BottomUpRelayer::handle(global, args).await,
Commands::ListValidatorChanges(args) => {
Expand All @@ -59,4 +62,5 @@ pub(crate) enum Commands {
ListBottomupBundle(GetBottomUpBundlesArgs),
QuorumReachedEvents(GetQuorumReachedEventsArgs),
LastBottomupCheckpointHeight(LastBottomUpCheckpointHeightArgs),
Status(StatusArgs),
}
76 changes: 76 additions & 0 deletions ipc/cli/src/commands/checkpoint/status.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright 2022-2024 Protocol Labs
// SPDX-License-Identifier: MIT
//! List the bottom up checkpoint status

use std::fmt::Debug;
use std::str::FromStr;

use async_trait::async_trait;
use clap::Args;
use fvm_shared::clock::ChainEpoch;
use ipc_api::subnet_id::SubnetID;

use crate::commands::get_ipc_provider;
use crate::{CommandLineHandler, GlobalArguments};

const DEFAULT_LIMIT_UNSUBMITTED: usize = 10;

/// The command to list bottom up checkpoint status.
pub(crate) struct Status;

#[async_trait]
impl CommandLineHandler for Status {
type Arguments = StatusArgs;

async fn handle(global: &GlobalArguments, arguments: &Self::Arguments) -> anyhow::Result<()> {
log::debug!("bottom up checkpoint status with args: {:?}", arguments);

let provider = get_ipc_provider(global)?;
let subnet = SubnetID::from_str(&arguments.subnet)?;

let last_checkpointed_height = provider.last_bottom_up_checkpoint_height(&subnet).await?;
let checkpoint = provider
.get_bottom_up_bundle(&subnet, last_checkpointed_height)
.await?;
let period = provider.checkpoint_period(&subnet).await?;
let chain_head = provider.get_chain_head_height(&subnet).await?;

println!("subnet chain head height: {}", chain_head);
println!(
"last submitted checkpoint (@ subnet height {}): {:?}",
last_checkpointed_height, checkpoint
);

let limit_unsubmitted = arguments
.limit_unsubmitted
.unwrap_or(DEFAULT_LIMIT_UNSUBMITTED);

let start = last_checkpointed_height + 1;
let ending = limit_unsubmitted as ChainEpoch * period + start;
Comment on lines +48 to +49
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to explain what's happening.

For example I don't know if last_checkpointed_height is a) height in the subnet of the last created checkpoint or b) the last submitted checkpoint in the parent.

let mut checkpoints_ahead = 0;
for h in start..=ending {
let c = provider.get_bottom_up_bundle(&subnet, h).await?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be cleaner to make this return an Option?

Copy link
Contributor Author

@cryptoAtwill cryptoAtwill Mar 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is handled in previous PR: #743

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you query the whole bundle at every height to see if there is a potential checkpoint, right? Can't this be queried with the events API?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is indeed a PR that I changed the query from height to height to a range query, but somehow that PR is not merged. I can recreate that on a follow up.

if c.checkpoint.block_height != 0 {
checkpoints_ahead += 1;
}
}
println!(
"there are at least {} unsubmitted checkpoints (limiting query to: {})",
checkpoints_ahead, limit_unsubmitted
);

Ok(())
}
}

#[derive(Debug, Args)]
#[command(about = "Summarise the bottom up checkpointing status of a subnet")]
pub(crate) struct StatusArgs {
#[arg(long, help = "The subnet to inspect")]
pub subnet: String,
#[arg(
long,
help = "Limit unsubmitted checkpoints to print (looking forward from last submitted), default: 10"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it doesn't necessarily limit the number of checkpoints to print, only the number of checkpoint periods to look ahead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also find it confusing that the title and the docs say that it "lists checkpoint statuses", but I don't see any listing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basically just display a bunch of metrics/fields related to bottom up checkpointing.

)]
pub limit_unsubmitted: Option<usize>,
}
9 changes: 9 additions & 0 deletions ipc/provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,15 @@ impl IpcProvider {
conn.manager().chain_head_height().await
}

pub async fn checkpoint_period(&self, subnet: &SubnetID) -> anyhow::Result<ChainEpoch> {
let conn = match self.connection(subnet) {
None => return Err(anyhow!("target subnet not found")),
Some(conn) => conn,
};

conn.manager().checkpoint_period(subnet).await
}

pub async fn get_bottom_up_bundle(
&self,
subnet: &SubnetID,
Expand Down
1 change: 1 addition & 0 deletions ipc/provider/src/manager/evm/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,7 @@ impl BottomUpCheckpointRelayer for EthSubnetManager {

Ok(events)
}

async fn current_epoch(&self) -> Result<ChainEpoch> {
let epoch = self
.ipc_contract_info
Expand Down
Loading