Skip to content

Commit

Permalink
Query event (#350)
Browse files Browse the repository at this point in the history
* query event

* more commands

* fix conneciton

* more cli

* fix relayer

* skip empty height

* more logs

* wait for execution result

* more logging

* Update ipc/cli/src/commands/checkpoint/bottomup_height.rs

Co-authored-by: adlrocha <6717133+adlrocha@users.noreply.github.com>

* Update ipc/cli/src/commands/checkpoint/bottomup_bundles.rs

Co-authored-by: adlrocha <6717133+adlrocha@users.noreply.github.com>

* Update ipc/cli/src/commands/checkpoint/bottomup_submitted.rs

Co-authored-by: adlrocha <6717133+adlrocha@users.noreply.github.com>

* Update ipc/provider/src/manager/subnet.rs

Co-authored-by: adlrocha <6717133+adlrocha@users.noreply.github.com>

* review fixes

* fmt

---------

Co-authored-by: adlrocha <6717133+adlrocha@users.noreply.github.com>
  • Loading branch information
cryptoAtwill and adlrocha authored Nov 2, 2023
1 parent 3aab33d commit 203afed
Show file tree
Hide file tree
Showing 11 changed files with 418 additions and 31 deletions.
51 changes: 51 additions & 0 deletions ipc/cli/src/commands/checkpoint/bottomup_bundles.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2022-2023 Protocol Labs
// SPDX-License-Identifier: MIT
//! List bottom up bundles
use std::fmt::Debug;
use std::str::FromStr;

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

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

/// The command to get bottom up bundles at height.
pub(crate) struct GetBottomUpBundles;

#[async_trait]
impl CommandLineHandler for GetBottomUpBundles {
type Arguments = GetBottomUpBundlesArgs;

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

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

for h in arguments.from_epoch..=arguments.to_epoch {
let bundle = provider.get_bottom_up_bundle(&subnet, h).await?;
println!(
"checkpoint: {:?}, signatures: {:?}, signatories: {:?}, cross_msgs: {:?}",
bundle.checkpoint, bundle.signatures, bundle.signatories, bundle.cross_msgs,
);
println!("{bundle:?}");
}

Ok(())
}
}

#[derive(Debug, Args)]
#[command(about = "List bottom up checkpoint signature bundle for a child subnet")]
pub(crate) struct GetBottomUpBundlesArgs {
#[arg(long, short, help = "The target subnet to perform query")]
pub subnet: String,
#[arg(long, short, help = "Include checkpoints from this epoch")]
pub from_epoch: ChainEpoch,
#[arg(long, short, help = "Include checkpoints up to this epoch")]
pub to_epoch: ChainEpoch,
}
42 changes: 42 additions & 0 deletions ipc/cli/src/commands/checkpoint/bottomup_height.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2022-2023 Protocol Labs
// SPDX-License-Identifier: MIT

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

use async_trait::async_trait;
use clap::Args;
use ipc_sdk::subnet_id::SubnetID;

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

/// The command to get the last bottom up checkpoint height in a subnet.
pub(crate) struct LastBottomUpCheckpointHeight;

#[async_trait]
impl CommandLineHandler for LastBottomUpCheckpointHeight {
type Arguments = LastBottomUpCheckpointHeightArgs;

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

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

let height = provider.last_bottom_up_checkpoint_height(&subnet).await?;
println!("height: {height}");

Ok(())
}
}

#[derive(Debug, Args)]
#[command(about = "Last bottom up checkpoint height committed in a child subnet")]
pub(crate) struct LastBottomUpCheckpointHeightArgs {
#[arg(long, short, help = "The target subnet to perform query")]
pub subnet: String,
}
50 changes: 50 additions & 0 deletions ipc/cli/src/commands/checkpoint/bottomup_submitted.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2022-2023 Protocol Labs
// SPDX-License-Identifier: MIT

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

use async_trait::async_trait;
use clap::Args;
use fvm_shared::address::Address;
use ipc_sdk::subnet_id::SubnetID;

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

/// The command to check if the address has submitted in the last bottom up checkpoint height.
pub(crate) struct SubmittedInBottomUpHeight;

#[async_trait]
impl CommandLineHandler for SubmittedInBottomUpHeight {
type Arguments = SubmittedInBottomUpHeightArgs;

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

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

let submitted = provider
.has_submitted_in_last_checkpoint_height(&subnet, &address)
.await?;
println!("has submitted: {submitted}");

Ok(())
}
}

#[derive(Debug, Args)]
#[command(
about = "Check if the address has submitted a signature in the last bottom up checkpoint of a child subnet"
)]
pub(crate) struct SubmittedInBottomUpHeightArgs {
#[arg(long, short, help = "The target subnet to perform query")]
pub subnet: String,
#[arg(long, short, help = "The hex encoded address of the submitter")]
pub submitter: String,
}
28 changes: 28 additions & 0 deletions ipc/cli/src/commands/checkpoint/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
// Copyright 2022-2023 Protocol Labs
// SPDX-License-Identifier: MIT
use crate::commands::checkpoint::bottomup_bundles::{GetBottomUpBundles, GetBottomUpBundlesArgs};
use crate::commands::checkpoint::bottomup_height::{
LastBottomUpCheckpointHeight, LastBottomUpCheckpointHeightArgs,
};
use crate::commands::checkpoint::bottomup_submitted::{
SubmittedInBottomUpHeight, SubmittedInBottomUpHeightArgs,
};
use crate::commands::checkpoint::list_checkpoints::{
ListBottomUpCheckpoints, ListBottomUpCheckpointsArgs,
};
use crate::commands::checkpoint::list_validator_changes::{
ListValidatorChanges, ListValidatorChangesArgs,
};
use crate::commands::checkpoint::quorum_reached::{
GetQuorumReacehdEvents, GetQuorumReachedEventsArgs,
};
use crate::commands::checkpoint::relayer::{BottomUpRelayer, BottomUpRelayerArgs};
use crate::{CommandLineHandler, GlobalArguments};
use clap::{Args, Subcommand};

mod bottomup_bundles;
mod bottomup_height;
mod bottomup_submitted;
mod list_checkpoints;
mod list_validator_changes;
mod quorum_reached;
mod relayer;

#[derive(Debug, Args)]
Expand All @@ -30,6 +44,16 @@ impl CheckpointCommandsArgs {
Commands::ListValidatorChanges(args) => {
ListValidatorChanges::handle(global, args).await
}
Commands::ListBottomupBundle(args) => GetBottomUpBundles::handle(global, args).await,
Commands::QuorumReachedEvents(args) => {
GetQuorumReacehdEvents::handle(global, args).await
}
Commands::LastBottomUpCheckpointHeight(args) => {
LastBottomUpCheckpointHeight::handle(global, args).await
}
Commands::HasSubmittedBottomUpHeight(args) => {
SubmittedInBottomUpHeight::handle(global, args).await
}
}
}
}
Expand All @@ -39,4 +63,8 @@ pub(crate) enum Commands {
ListBottomup(ListBottomUpCheckpointsArgs),
Relayer(BottomUpRelayerArgs),
ListValidatorChanges(ListValidatorChangesArgs),
ListBottomupBundle(GetBottomUpBundlesArgs),
QuorumReachedEvents(GetQuorumReachedEventsArgs),
LastBottomUpCheckpointHeight(LastBottomUpCheckpointHeightArgs),
HasSubmittedBottomUpHeight(SubmittedInBottomUpHeightArgs),
}
49 changes: 49 additions & 0 deletions ipc/cli/src/commands/checkpoint/quorum_reached.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2022-2023 Protocol Labs
// SPDX-License-Identifier: MIT
//! List quorum reached events
use std::fmt::Debug;
use std::str::FromStr;

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

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

/// The command to list quorum reached at height.
pub(crate) struct GetQuorumReacehdEvents;

#[async_trait]
impl CommandLineHandler for GetQuorumReacehdEvents {
type Arguments = GetQuorumReachedEventsArgs;

async fn handle(global: &GlobalArguments, arguments: &Self::Arguments) -> anyhow::Result<()> {
log::debug!("get quorum reached events with args: {:?}", arguments);

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

for h in arguments.from_epoch..=arguments.to_epoch {
let events = provider.quorum_reached_events(&subnet, h).await?;
for e in events {
println!("{e}");
}
}

Ok(())
}
}

#[derive(Debug, Args)]
#[command(about = "List quorum reached events for a child subnet")]
pub(crate) struct GetQuorumReachedEventsArgs {
#[arg(long, short, help = "The target subnet to perform query")]
pub subnet: String,
#[arg(long, short, help = "Include events from this epoch")]
pub from_epoch: ChainEpoch,
#[arg(long, short, help = "Include events up to this epoch")]
pub to_epoch: ChainEpoch,
}
21 changes: 17 additions & 4 deletions ipc/cli/src/commands/checkpoint/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ use anyhow::anyhow;
use async_trait::async_trait;
use clap::Args;
use fvm_shared::address::Address;
use fvm_shared::clock::ChainEpoch;
use ipc_identity::EvmKeyStore;
use ipc_provider::checkpoint::BottomUpCheckpointManager;
use ipc_provider::new_evm_keystore_from_path;
use ipc_provider::config::Config;
use ipc_provider::new_evm_keystore_from_config;
use ipc_sdk::subnet_id::SubnetID;
use std::str::FromStr;
use std::sync::{Arc, RwLock};
Expand All @@ -28,8 +30,8 @@ impl CommandLineHandler for BottomUpRelayer {
log::debug!("start bottom up relayer with args: {:?}", arguments);

let config_path = global.config_path();

let mut keystore = new_evm_keystore_from_path(&config_path)?;
let config = Arc::new(Config::from_file(&config_path)?);
let mut keystore = new_evm_keystore_from_config(config)?;
let submitter = match (arguments.submitter.as_ref(), keystore.get_default()?) {
(Some(submitter), _) => Address::from_str(submitter)?,
(None, Some(addr)) => {
Expand All @@ -49,13 +51,17 @@ impl CommandLineHandler for BottomUpRelayer {
let child = get_subnet_config(&config_path, &subnet)?;
let parent = get_subnet_config(&config_path, &parent)?;

let manager = BottomUpCheckpointManager::new_evm_manager(
let mut manager = BottomUpCheckpointManager::new_evm_manager(
parent.clone(),
child.clone(),
Arc::new(RwLock::new(keystore)),
)
.await?;

if let Some(v) = arguments.finalization_blocks {
manager = manager.with_finalization_blocks(v as ChainEpoch);
}

let interval = Duration::from_secs(
arguments
.checkpoint_interval_sec
Expand All @@ -74,6 +80,13 @@ pub(crate) struct BottomUpRelayerArgs {
pub subnet: String,
#[arg(long, short, help = "The number of seconds to submit checkpoint")]
pub checkpoint_interval_sec: Option<u64>,
#[arg(
long,
short,
default_value = "0",
help = "The number of blocks away from chain head that is considered final"
)]
pub finalization_blocks: Option<u64>,
#[arg(long, short, help = "The hex encoded address of the submitter")]
pub submitter: Option<String>,
}
Loading

0 comments on commit 203afed

Please sign in to comment.