From ab016560c35d98c28f8ce167ac1c81a334c46208 Mon Sep 17 00:00:00 2001 From: Anca Zamfir Date: Tue, 25 Apr 2023 13:07:52 +0200 Subject: [PATCH 01/96] evidence worker PoC for testing --- config.toml | 5 +- crates/relayer-cli/src/commands.rs | 8 +- crates/relayer-cli/src/commands/evidence.rs | 131 ++++++++++++++++++++ crates/relayer/src/chain/cosmos.rs | 5 +- 4 files changed, 143 insertions(+), 6 deletions(-) create mode 100644 crates/relayer-cli/src/commands/evidence.rs diff --git a/config.toml b/config.toml index 949d67d2c7..276a221ccd 100644 --- a/config.toml +++ b/config.toml @@ -254,7 +254,8 @@ max_gas = 400000 # paid for each unit of gas per transaction. # # Required -gas_price = { price = 0.001, denom = 'stake' } +#gas_price = { price = 0.025, denom = 'stake' } +gas_price = { price = 0, denom = 'stake' } # Multiply this amount with the gas estimate, used to compute the fee # and account for potential estimation error. @@ -372,7 +373,7 @@ key_name = 'testkey' store_prefix = 'ibc' default_gas = 100000 max_gas = 400000 -gas_price = { price = 0.001, denom = 'stake' } +gas_price = { price = 0.025, denom = 'stake' } gas_multiplier = 1.1 max_msg_num = 30 max_tx_size = 2097152 diff --git a/crates/relayer-cli/src/commands.rs b/crates/relayer-cli/src/commands.rs index fd1b9fb1b5..eb3f79a9b9 100644 --- a/crates/relayer-cli/src/commands.rs +++ b/crates/relayer-cli/src/commands.rs @@ -4,6 +4,7 @@ mod clear; mod completions; mod config; mod create; +mod evidence; mod fee; mod health; mod keys; @@ -18,7 +19,7 @@ mod version; use self::{ clear::ClearCmds, completions::CompletionsCmd, config::ConfigCmd, create::CreateCmds, - fee::FeeCmd, health::HealthCheckCmd, keys::KeysCmd, listen::ListenCmd, + evidence::EvidenceCmd, fee::FeeCmd, health::HealthCheckCmd, keys::KeysCmd, listen::ListenCmd, misbehaviour::MisbehaviourCmd, query::QueryCmd, start::StartCmd, tx::TxCmd, update::UpdateCmds, upgrade::UpgradeCmds, version::VersionCmd, }; @@ -85,9 +86,12 @@ pub enum CliCmd { /// Listen to and display IBC events emitted by a chain Listen(ListenCmd), - /// Listen to client update IBC events and handles misbehaviour + /// Listen to client update IBC events and handle misbehaviour Misbehaviour(MisbehaviourCmd), + /// Listen to block events and handles evidence + Evidence(EvidenceCmd), + /// The `version` subcommand, retained for backward compatibility. Version(VersionCmd), diff --git a/crates/relayer-cli/src/commands/evidence.rs b/crates/relayer-cli/src/commands/evidence.rs new file mode 100644 index 0000000000..53998e432d --- /dev/null +++ b/crates/relayer-cli/src/commands/evidence.rs @@ -0,0 +1,131 @@ +use alloc::sync::Arc; +use std::cmp::min; +use std::ops::Deref; +use tokio::runtime::Runtime as TokioRuntime; + +use abscissa_core::clap::Parser; +use abscissa_core::{Command, Runnable}; +use ibc_relayer::chain::endpoint::ChainEndpoint; +use ibc_relayer_types::core::ics24_host::identifier::ChainId; +use ibc_relayer_types::events::IbcEvent; + +use crate::conclude::Output; +use crate::prelude::*; +use ibc_relayer::chain::cosmos::CosmosSdkChain; +use ibc_relayer_types::core::ics02_client::height::Height; + +#[derive(Clone, Command, Debug, Parser, PartialEq, Eq)] +pub struct EvidenceCmd { + #[clap( + long = "chain", + required = true, + value_name = "CHAIN_ID", + help_heading = "REQUIRED", + help = "Identifier of the chain where blocks are monitored for misbehaviour" + )] + chain_id: ChainId, +} + +impl Runnable for EvidenceCmd { + fn run(&self) { + let config = app_config(); + let rt = Arc::new(TokioRuntime::new().unwrap()); + let chain_config = config.find_chain(&self.chain_id).cloned().unwrap(); + + let mut chain = CosmosSdkChain::bootstrap(chain_config, rt).unwrap(); + + // let res = + // if !chain_config.ccv_consumer_chain { + // monitor_equivocation(&mut chain) + // } else { + // Ok(None) + // }; + let res = monitor_equivocation(&mut chain); + + match res { + Ok(some_event) => Output::success(some_event).exit(), + Err(e) => Output::error(e).exit(), + } + } +} + +fn monitor_equivocation(chain: &mut CosmosSdkChain) -> eyre::Result> { + let subscription = chain.subscribe()?; + + // check previous blocks for equivocation that may have been missed + let tm_latest_height = chain + .block_on(chain.rpc_client.status()) + .unwrap() + .sync_info + .latest_block_height; + let latest_height = Height::new(chain.id().version(), tm_latest_height.value()).unwrap(); + let num_blocks = min(tm_latest_height.value(), 100); + let mut height = latest_height; + for _h in 0..num_blocks - 1 { + debug!("trying to check for evidence at height {}", height); + equivocation_handling(chain, height)?; + height = height.decrement().unwrap(); + } + // process new block events + while let Ok(event_batch) = subscription.recv() { + match event_batch.deref() { + Ok(event_batch) => { + for event_with_height in &event_batch.events { + if let IbcEvent::NewBlock(new_block) = &event_with_height.event { + debug!("{:?}", new_block); + equivocation_handling(chain, new_block.height)?; + } + } + } + Err(e) => { + dbg!(e); + } + } + } + + Ok(None) +} + +use tendermint_rpc::Client; +fn equivocation_handling(chain: &CosmosSdkChain, height: Height) -> eyre::Result<()> { + let tm_height = tendermint::block::Height::try_from(height.revision_height()).unwrap(); + let evidence_list = chain + .block_on(chain.rpc_client.block(tm_height)) + .unwrap() + .block + .evidence; + for evidence in evidence_list.iter() { + match evidence { + tendermint::evidence::Evidence::DuplicateVote(dv) => { + debug!("found duplicate vote evidence {:?}", dv); + } + tendermint::evidence::Evidence::LightClientAttack(lc) => { + debug!("found light client attack evidence {:?}", lc); + } + } + } + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::EvidenceCmd; + + use abscissa_core::clap::Parser; + use ibc_relayer_types::core::ics24_host::identifier::ChainId; + + #[test] + fn test_misbehaviour() { + assert_eq!( + EvidenceCmd { + chain_id: ChainId::from_string("chain_id"), + }, + EvidenceCmd::parse_from(["test", "--chain", "chain_id"]) + ) + } + + #[test] + fn test_misbehaviour_no_chain() { + assert!(EvidenceCmd::try_parse_from(["test"]).is_err()) + } +} diff --git a/crates/relayer/src/chain/cosmos.rs b/crates/relayer/src/chain/cosmos.rs index 94bd7bf8dd..a77ca4c527 100644 --- a/crates/relayer/src/chain/cosmos.rs +++ b/crates/relayer/src/chain/cosmos.rs @@ -140,7 +140,7 @@ pub const BLOCK_MAX_BYTES_MAX_FRACTION: f64 = 0.9; pub struct CosmosSdkChain { config: ChainConfig, tx_config: TxConfig, - rpc_client: HttpClient, + pub rpc_client: HttpClient, compat_mode: CompatMode, grpc_addr: Uri, light_client: TmLightClient, @@ -515,7 +515,8 @@ impl CosmosSdkChain { } /// Run a future to completion on the Tokio runtime. - fn block_on(&self, f: F) -> F::Output { + pub fn block_on(&self, f: F) -> F::Output { + crate::time!("block_on"); self.rt.block_on(f) } From 0d6df8de7b787cc819adb1393ba7d4dcc283e39a Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Mon, 19 Jun 2023 15:16:03 +0200 Subject: [PATCH 02/96] Cleanup --- crates/relayer-cli/src/commands/evidence.rs | 40 ++++++++++++--------- crates/relayer/src/chain/cosmos.rs | 2 +- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/crates/relayer-cli/src/commands/evidence.rs b/crates/relayer-cli/src/commands/evidence.rs index 53998e432d..f7e61bd4cb 100644 --- a/crates/relayer-cli/src/commands/evidence.rs +++ b/crates/relayer-cli/src/commands/evidence.rs @@ -32,7 +32,7 @@ impl Runnable for EvidenceCmd { let rt = Arc::new(TokioRuntime::new().unwrap()); let chain_config = config.find_chain(&self.chain_id).cloned().unwrap(); - let mut chain = CosmosSdkChain::bootstrap(chain_config, rt).unwrap(); + let mut chain = CosmosSdkChain::bootstrap(chain_config, rt.clone()).unwrap(); // let res = // if !chain_config.ccv_consumer_chain { @@ -40,7 +40,8 @@ impl Runnable for EvidenceCmd { // } else { // Ok(None) // }; - let res = monitor_equivocation(&mut chain); + + let res = rt.block_on(monitor_equivocation(&mut chain)); match res { Ok(some_event) => Output::success(some_event).exit(), @@ -49,31 +50,38 @@ impl Runnable for EvidenceCmd { } } -fn monitor_equivocation(chain: &mut CosmosSdkChain) -> eyre::Result> { +async fn monitor_equivocation(chain: &mut CosmosSdkChain) -> eyre::Result> { let subscription = chain.subscribe()?; // check previous blocks for equivocation that may have been missed let tm_latest_height = chain - .block_on(chain.rpc_client.status()) - .unwrap() + .rpc_client + .status() + .await? .sync_info .latest_block_height; + let latest_height = Height::new(chain.id().version(), tm_latest_height.value()).unwrap(); let num_blocks = min(tm_latest_height.value(), 100); let mut height = latest_height; + for _h in 0..num_blocks - 1 { - debug!("trying to check for evidence at height {}", height); - equivocation_handling(chain, height)?; + debug!("trying to check for evidence at height {height}"); + + equivocation_handling(chain, height).await?; + height = height.decrement().unwrap(); } + // process new block events while let Ok(event_batch) = subscription.recv() { match event_batch.deref() { Ok(event_batch) => { for event_with_height in &event_batch.events { if let IbcEvent::NewBlock(new_block) = &event_with_height.event { - debug!("{:?}", new_block); - equivocation_handling(chain, new_block.height)?; + debug!("{new_block:?}"); + + equivocation_handling(chain, new_block.height).await?; } } } @@ -87,23 +95,21 @@ fn monitor_equivocation(chain: &mut CosmosSdkChain) -> eyre::Result eyre::Result<()> { + +async fn equivocation_handling(chain: &CosmosSdkChain, height: Height) -> eyre::Result<()> { let tm_height = tendermint::block::Height::try_from(height.revision_height()).unwrap(); - let evidence_list = chain - .block_on(chain.rpc_client.block(tm_height)) - .unwrap() - .block - .evidence; + let evidence_list = chain.rpc_client.block(tm_height).await?.block.evidence; for evidence in evidence_list.iter() { match evidence { tendermint::evidence::Evidence::DuplicateVote(dv) => { - debug!("found duplicate vote evidence {:?}", dv); + debug!("found duplicate vote evidence {dv:?}"); } tendermint::evidence::Evidence::LightClientAttack(lc) => { - debug!("found light client attack evidence {:?}", lc); + debug!("found light client attack evidence {lc:?}"); } } } + Ok(()) } diff --git a/crates/relayer/src/chain/cosmos.rs b/crates/relayer/src/chain/cosmos.rs index a77ca4c527..5cc3493426 100644 --- a/crates/relayer/src/chain/cosmos.rs +++ b/crates/relayer/src/chain/cosmos.rs @@ -515,7 +515,7 @@ impl CosmosSdkChain { } /// Run a future to completion on the Tokio runtime. - pub fn block_on(&self, f: F) -> F::Output { + fn block_on(&self, f: F) -> F::Output { crate::time!("block_on"); self.rt.block_on(f) } From 1709d1a63fba6cec746bd4cb52b9bb5e949d6d89 Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Mon, 19 Jun 2023 15:16:27 +0200 Subject: [PATCH 03/96] Use ibc-proto branch with new provider message --- Cargo.lock | 3 +-- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ebe24b23e1..696b26ec6f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1485,8 +1485,7 @@ dependencies = [ [[package]] name = "ibc-proto" version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c888103095b45bee90cb9104513ade30abd69902153b0682b5ad81940ae1f865" +source = "git+https://github.com/cosmos/ibc-proto-rs.git?branch=ccv-protos#370f916d54dc92603cd24970e0763f5c0a52e257" dependencies = [ "base64 0.21.2", "bytes", diff --git a/Cargo.toml b/Cargo.toml index 4a4c5cd801..ff3e7d9846 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ exclude = [ overflow-checks = true [patch.crates-io] -# ibc-proto = { git = "https://github.com/cosmos/ibc-proto-rs.git", branch = "main" } +ibc-proto = { git = "https://github.com/cosmos/ibc-proto-rs.git", branch = "ccv-protos" } # tendermint = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "romac/new-misbehavior-detector" } # tendermint-rpc = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "romac/new-misbehavior-detector" } # tendermint-proto = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "romac/new-misbehavior-detector" } From fc3aea445d41f4abc9ad541a33988a59db355186 Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Wed, 21 Jun 2023 10:25:44 +0200 Subject: [PATCH 04/96] Add `MsgSubmitIcsConsumerMisbehaviour` domain type from `anca/ics-misbehaviour-handling` branch --- .../src/applications/ics28_ccv/mod.rs | 4 ++ .../ics28_ccv/msgs/ccv_misbehaviour.rs | 68 +++++++++++++++++++ .../src/applications/ics28_ccv/msgs/error.rs | 16 +++++ .../src/applications/ics28_ccv/msgs/mod.rs | 2 + crates/relayer-types/src/applications/mod.rs | 1 + 5 files changed, 91 insertions(+) create mode 100644 crates/relayer-types/src/applications/ics28_ccv/mod.rs create mode 100644 crates/relayer-types/src/applications/ics28_ccv/msgs/ccv_misbehaviour.rs create mode 100644 crates/relayer-types/src/applications/ics28_ccv/msgs/error.rs create mode 100644 crates/relayer-types/src/applications/ics28_ccv/msgs/mod.rs diff --git a/crates/relayer-types/src/applications/ics28_ccv/mod.rs b/crates/relayer-types/src/applications/ics28_ccv/mod.rs new file mode 100644 index 0000000000..7ba0198166 --- /dev/null +++ b/crates/relayer-types/src/applications/ics28_ccv/mod.rs @@ -0,0 +1,4 @@ +//! The implementation of the ICS 28 Cross-Chain Validation (CCV). +//! Please see the [specification](https://github.com/cosmos/ibc/tree/main/spec/app/ics-028-cross-chain-validation#readme). + +pub mod msgs; diff --git a/crates/relayer-types/src/applications/ics28_ccv/msgs/ccv_misbehaviour.rs b/crates/relayer-types/src/applications/ics28_ccv/msgs/ccv_misbehaviour.rs new file mode 100644 index 0000000000..e053eee9f6 --- /dev/null +++ b/crates/relayer-types/src/applications/ics28_ccv/msgs/ccv_misbehaviour.rs @@ -0,0 +1,68 @@ +use core::fmt; + +use serde::{Deserialize, Serialize}; + +use ibc_proto::interchain_security::ccv::provider::v1::MsgSubmitConsumerMisbehaviour as RawIcsMisbehaviour; +use ibc_proto::protobuf::Protobuf; + +use crate::clients::ics07_tendermint::misbehaviour::Misbehaviour; +use crate::signer::Signer; +use crate::tx_msg::Msg; + +use super::error::Error; + +pub const ICS_MISBEHAVIOR_TYPE_URL: &str = + "/interchain_security.ccv.provider.v1.MsgSubmitConsumerMisbehaviour"; + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct MsgSubmitIcsConsumerMisbehaviour { + pub submitter: Signer, + pub misbehaviour: Misbehaviour, +} + +impl Msg for MsgSubmitIcsConsumerMisbehaviour { + type ValidationError = crate::core::ics24_host::error::ValidationError; + type Raw = RawIcsMisbehaviour; + + fn route(&self) -> String { + crate::keys::ROUTER_KEY.to_string() + } + + fn type_url(&self) -> String { + ICS_MISBEHAVIOR_TYPE_URL.to_string() + } +} + +impl Protobuf for MsgSubmitIcsConsumerMisbehaviour {} + +impl TryFrom for MsgSubmitIcsConsumerMisbehaviour { + type Error = Error; + + fn try_from(raw: RawIcsMisbehaviour) -> Result { + let mis = raw + .misbehaviour + .ok_or_else(|| Error::invalid_raw_misbehaviour("missing misbehaviour".into()))?; + + Ok(Self { + submitter: raw.submitter.parse().map_err(Error::signer)?, + misbehaviour: mis.try_into().map_err(|_e| { + Error::invalid_raw_misbehaviour("cannot convert misbehaviour".into()) + })?, + }) + } +} + +impl From for RawIcsMisbehaviour { + fn from(value: MsgSubmitIcsConsumerMisbehaviour) -> Self { + RawIcsMisbehaviour { + submitter: value.submitter.to_string(), + misbehaviour: Some(value.misbehaviour.into()), + } + } +} + +impl fmt::Display for MsgSubmitIcsConsumerMisbehaviour { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { + write!(f, "{}: {}", self.submitter, self.misbehaviour) + } +} diff --git a/crates/relayer-types/src/applications/ics28_ccv/msgs/error.rs b/crates/relayer-types/src/applications/ics28_ccv/msgs/error.rs new file mode 100644 index 0000000000..12e143d71d --- /dev/null +++ b/crates/relayer-types/src/applications/ics28_ccv/msgs/error.rs @@ -0,0 +1,16 @@ +use flex_error::define_error; + +use crate::signer::SignerError; + +define_error! { + #[derive(Debug, PartialEq, Eq)] + Error { + InvalidRawMisbehaviour + { reason: String } + | e | { format_args!("invalid raw misbehaviour: {}", e.reason) }, + + Signer + [ SignerError ] + | _ | { "failed to parse signer" }, + } +} diff --git a/crates/relayer-types/src/applications/ics28_ccv/msgs/mod.rs b/crates/relayer-types/src/applications/ics28_ccv/msgs/mod.rs new file mode 100644 index 0000000000..17de82ab91 --- /dev/null +++ b/crates/relayer-types/src/applications/ics28_ccv/msgs/mod.rs @@ -0,0 +1,2 @@ +pub mod ccv_misbehaviour; +pub mod error; diff --git a/crates/relayer-types/src/applications/mod.rs b/crates/relayer-types/src/applications/mod.rs index 539225bf08..7080c37fc4 100644 --- a/crates/relayer-types/src/applications/mod.rs +++ b/crates/relayer-types/src/applications/mod.rs @@ -1,6 +1,7 @@ //! Various packet encoding semantics which underpin the various types of transactions. pub mod ics27_ica; +pub mod ics28_ccv; pub mod ics29_fee; pub mod ics31_icq; pub mod transfer; From 81ef9dd8d9cd561488155b4e5cbf0b4b2f50527a Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Wed, 21 Jun 2023 18:10:02 +0200 Subject: [PATCH 05/96] Report misbehavior evidence to all counterparty clients of the misbehaving chain --- crates/relayer-cli/src/cli_utils.rs | 3 +- .../src/commands/create/channel.rs | 1 - .../src/commands/create/connection.rs | 1 - crates/relayer-cli/src/commands/evidence.rs | 228 ++++++++++++++---- .../src/commands/query/channel_ends.rs | 1 - .../src/commands/query/channels.rs | 1 - .../relayer-cli/src/commands/query/clients.rs | 1 - .../src/commands/query/connections.rs | 1 - crates/relayer-cli/src/commands/tx/client.rs | 1 - .../clients/ics07_tendermint/misbehaviour.rs | 14 ++ .../src/core/ics03_connection/connection.rs | 4 +- crates/relayer/src/chain/counterparty.rs | 1 - crates/relayer/src/client_state.rs | 9 + crates/relayer/src/object.rs | 2 +- .../src/supervisor/client_state_filter.rs | 1 - crates/relayer/src/supervisor/scan.rs | 1 - crates/relayer/src/supervisor/spawn.rs | 2 +- 17 files changed, 214 insertions(+), 58 deletions(-) diff --git a/crates/relayer-cli/src/cli_utils.rs b/crates/relayer-cli/src/cli_utils.rs index 5a2aae7fc0..f3c86385dc 100644 --- a/crates/relayer-cli/src/cli_utils.rs +++ b/crates/relayer-cli/src/cli_utils.rs @@ -2,6 +2,7 @@ use alloc::sync::Arc; use eyre::eyre; +use ibc_relayer_types::core::ics24_host::identifier::{ChainId, ChannelId, PortId}; use tokio::runtime::Runtime as TokioRuntime; use tracing::debug; @@ -16,8 +17,6 @@ use ibc_relayer::{ config::Config, spawn, }; -use ibc_relayer_types::core::ics02_client::client_state::ClientState; -use ibc_relayer_types::core::ics24_host::identifier::{ChainId, ChannelId, PortId}; use crate::error::Error; diff --git a/crates/relayer-cli/src/commands/create/channel.rs b/crates/relayer-cli/src/commands/create/channel.rs index 3de03a257a..b949adff72 100644 --- a/crates/relayer-cli/src/commands/create/channel.rs +++ b/crates/relayer-cli/src/commands/create/channel.rs @@ -11,7 +11,6 @@ use ibc_relayer::chain::requests::{ use ibc_relayer::channel::Channel; use ibc_relayer::connection::Connection; use ibc_relayer::foreign_client::ForeignClient; -use ibc_relayer_types::core::ics02_client::client_state::ClientState; use ibc_relayer_types::core::ics03_connection::connection::IdentifiedConnectionEnd; use ibc_relayer_types::core::ics04_channel::channel::Ordering; use ibc_relayer_types::core::ics04_channel::version::Version; diff --git a/crates/relayer-cli/src/commands/create/connection.rs b/crates/relayer-cli/src/commands/create/connection.rs index 16c0fa1e6e..052411d069 100644 --- a/crates/relayer-cli/src/commands/create/connection.rs +++ b/crates/relayer-cli/src/commands/create/connection.rs @@ -7,7 +7,6 @@ use ibc_relayer::chain::handle::ChainHandle; use ibc_relayer::chain::requests::{IncludeProof, QueryClientStateRequest, QueryHeight}; use ibc_relayer::connection::Connection; use ibc_relayer::foreign_client::ForeignClient; -use ibc_relayer_types::core::ics02_client::client_state::ClientState; use ibc_relayer_types::core::ics24_host::identifier::{ChainId, ClientId}; use crate::cli_utils::{spawn_chain_runtime, ChainHandlePair}; diff --git a/crates/relayer-cli/src/commands/evidence.rs b/crates/relayer-cli/src/commands/evidence.rs index f7e61bd4cb..b963ada01b 100644 --- a/crates/relayer-cli/src/commands/evidence.rs +++ b/crates/relayer-cli/src/commands/evidence.rs @@ -1,18 +1,28 @@ use alloc::sync::Arc; -use std::cmp::min; +use ibc_relayer::chain::tracking::TrackedMsgs; +use ibc_relayer_types::core::ics02_client::msgs::misbehaviour::MsgSubmitMisbehaviour; +use ibc_relayer_types::tx_msg::Msg; use std::ops::Deref; -use tokio::runtime::Runtime as TokioRuntime; use abscissa_core::clap::Parser; use abscissa_core::{Command, Runnable}; +use tokio::runtime::Runtime as TokioRuntime; + +use tendermint::block::Height as TendermintHeight; +use tendermint::evidence::LightClientAttackEvidence; +use tendermint::validator; + +use ibc_relayer::chain::cosmos::CosmosSdkChain; use ibc_relayer::chain::endpoint::ChainEndpoint; -use ibc_relayer_types::core::ics24_host::identifier::ChainId; +use ibc_relayer::chain::requests::{IncludeProof, QueryHeight}; +use ibc_relayer_types::clients::ics07_tendermint::header::Header as TendermintHeader; +use ibc_relayer_types::clients::ics07_tendermint::misbehaviour::Misbehaviour as TendermintMisbehaviour; +use ibc_relayer_types::core::ics02_client::height::Height; +use ibc_relayer_types::core::ics24_host::identifier::{ChainId, ClientId}; use ibc_relayer_types::events::IbcEvent; use crate::conclude::Output; use crate::prelude::*; -use ibc_relayer::chain::cosmos::CosmosSdkChain; -use ibc_relayer_types::core::ics02_client::height::Height; #[derive(Clone, Command, Debug, Parser, PartialEq, Eq)] pub struct EvidenceCmd { @@ -32,46 +42,41 @@ impl Runnable for EvidenceCmd { let rt = Arc::new(TokioRuntime::new().unwrap()); let chain_config = config.find_chain(&self.chain_id).cloned().unwrap(); - let mut chain = CosmosSdkChain::bootstrap(chain_config, rt.clone()).unwrap(); - - // let res = - // if !chain_config.ccv_consumer_chain { - // monitor_equivocation(&mut chain) - // } else { - // Ok(None) - // }; - - let res = rt.block_on(monitor_equivocation(&mut chain)); + let chain = CosmosSdkChain::bootstrap(chain_config, rt.clone()).unwrap(); + let res = rt.block_on(monitor_equivocation(rt.clone(), chain)); match res { - Ok(some_event) => Output::success(some_event).exit(), + Ok(()) => Output::success(()).exit(), Err(e) => Output::error(e).exit(), } } } -async fn monitor_equivocation(chain: &mut CosmosSdkChain) -> eyre::Result> { +async fn monitor_equivocation( + rt: Arc, + mut chain: CosmosSdkChain, +) -> eyre::Result<()> { let subscription = chain.subscribe()?; // check previous blocks for equivocation that may have been missed - let tm_latest_height = chain - .rpc_client - .status() - .await? - .sync_info - .latest_block_height; - - let latest_height = Height::new(chain.id().version(), tm_latest_height.value()).unwrap(); - let num_blocks = min(tm_latest_height.value(), 100); - let mut height = latest_height; - - for _h in 0..num_blocks - 1 { - debug!("trying to check for evidence at height {height}"); - - equivocation_handling(chain, height).await?; - - height = height.decrement().unwrap(); - } + // let tm_latest_height = chain + // .rpc_client + // .status() + // .await? + // .sync_info + // .latest_block_height; + // + // let latest_height = Height::new(chain.id().version(), tm_latest_height.value()).unwrap(); + // let num_blocks = min(tm_latest_height.value(), 100); + // let mut height = latest_height; + // + // for _height in 0..num_blocks - 1 { + // debug!("trying to check for evidence at height {height}"); + // + // equivocation_handling(&chain, height).await?; + // + // height = height.decrement().unwrap(); + // } // process new block events while let Ok(event_batch) = subscription.recv() { @@ -81,7 +86,7 @@ async fn monitor_equivocation(chain: &mut CosmosSdkChain) -> eyre::Result