From 7288871f602751fd2d3dc8287cece55b82dac79e Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Thu, 5 Sep 2024 18:48:48 +0200 Subject: [PATCH 01/17] Submit misbehaviour messages using the CCV consumer id (Permissionless ICS) --- Cargo.lock | 5 +- Cargo.toml | 1 + crates/relayer-cli/src/commands/evidence.rs | 28 ++++++-- .../ics28_ccv/msgs/ccv_double_voting.rs | 4 ++ .../ics28_ccv/msgs/ccv_misbehaviour.rs | 4 ++ .../src/applications/ics28_ccv/msgs/mod.rs | 16 +++++ crates/relayer/src/chain/cosmos.rs | 59 +++++++++++++++- crates/relayer/src/foreign_client.rs | 68 +++++++++++++++---- flake.lock | 25 ++++++- flake.nix | 7 +- 10 files changed, 185 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2e4f2e7523..136764926d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1549,9 +1549,8 @@ dependencies = [ [[package]] name = "ibc-proto" -version = "0.47.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1678333cf68c9094ca66aaf9a271269f1f6bf5c26881161def8bd88cee831a23" +version = "0.47.1" +source = "git+https://github.com/cosmos/ibc-proto-rs?branch=romac/permissionless-ics#901f8cad529913555bccd9b2283553a2c66bb343" dependencies = [ "base64 0.22.1", "bytes", diff --git a/Cargo.toml b/Cargo.toml index ef8483f32a..b3e130b61e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -120,6 +120,7 @@ uuid = "1.10.0" overflow-checks = true [patch.crates-io] +ibc-proto = { git = "https://github.com/cosmos/ibc-proto-rs", branch = "romac/permissionless-ics" } # tendermint = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "main" } # tendermint-rpc = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "main" } # tendermint-proto = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "main" } diff --git a/crates/relayer-cli/src/commands/evidence.rs b/crates/relayer-cli/src/commands/evidence.rs index fa54be707b..f7adc601b8 100644 --- a/crates/relayer-cli/src/commands/evidence.rs +++ b/crates/relayer-cli/src/commands/evidence.rs @@ -18,7 +18,7 @@ use ibc_relayer::chain::endpoint::ChainEndpoint; use ibc_relayer::chain::handle::{BaseChainHandle, ChainHandle}; use ibc_relayer::chain::requests::{IncludeProof, PageRequest, QueryHeight}; use ibc_relayer::chain::tracking::TrackedMsgs; -use ibc_relayer::foreign_client::ForeignClient; +use ibc_relayer::foreign_client::{fetch_ccv_consumer_id, ForeignClient}; use ibc_relayer::spawn::spawn_chain_runtime_with_modified_config; use ibc_relayer_types::applications::ics28_ccv::msgs::ccv_double_voting::MsgSubmitIcsConsumerDoubleVoting; use ibc_relayer_types::applications::ics28_ccv::msgs::ccv_misbehaviour::MsgSubmitIcsConsumerMisbehaviour; @@ -323,6 +323,8 @@ fn submit_duplicate_vote_evidence( return Ok(ControlFlow::Continue(())); } + let consumer_id = fetch_ccv_consumer_id(counterparty_chain_handle, counterparty_client_id)?; + let infraction_height = evidence.vote_a.height; // Get the trusted height in the same way we do for client updates, @@ -359,6 +361,7 @@ fn submit_duplicate_vote_evidence( submitter: signer.clone(), duplicate_vote_evidence: evidence.clone(), infraction_block_header, + consumer_id, } .to_any(); @@ -578,13 +581,24 @@ fn submit_light_client_attack_evidence( counterparty.id(), ); - let msg = MsgSubmitIcsConsumerMisbehaviour { - submitter: signer.clone(), - misbehaviour: misbehaviour.clone(), + match fetch_ccv_consumer_id(counterparty, &counterparty_client_id) { + Ok(consumer_id) => { + msgs.push( + MsgSubmitIcsConsumerMisbehaviour { + submitter: signer.clone(), + misbehaviour: misbehaviour.clone(), + consumer_id, + } + .to_any(), + ); + } + Err(e) => { + error!( + "cannot submit CCV light client attack evidence to client `{}` on provider chain `{}`: {e}", + counterparty_client_id, counterparty.id() + ); + } } - .to_any(); - - msgs.push(msg); }; // We do not need to submit the misbehaviour if the client is already frozen. diff --git a/crates/relayer-types/src/applications/ics28_ccv/msgs/ccv_double_voting.rs b/crates/relayer-types/src/applications/ics28_ccv/msgs/ccv_double_voting.rs index a1ce4291d9..9f07f31539 100644 --- a/crates/relayer-types/src/applications/ics28_ccv/msgs/ccv_double_voting.rs +++ b/crates/relayer-types/src/applications/ics28_ccv/msgs/ccv_double_voting.rs @@ -9,6 +9,7 @@ use crate::signer::Signer; use crate::tx_msg::Msg; use super::error::Error; +use super::ConsumerId; pub const ICS_DOUBLE_VOTING_TYPE_URL: &str = "/interchain_security.ccv.provider.v1.MsgSubmitConsumerDoubleVoting"; @@ -18,6 +19,7 @@ pub struct MsgSubmitIcsConsumerDoubleVoting { pub submitter: Signer, pub duplicate_vote_evidence: DuplicateVoteEvidence, pub infraction_block_header: Header, + pub consumer_id: ConsumerId, } impl Msg for MsgSubmitIcsConsumerDoubleVoting { @@ -57,6 +59,7 @@ impl TryFrom for MsgSubmitIcsConsumerDoubleVoting { .map_err(|e| { Error::invalid_raw_double_voting(format!("cannot convert header: {e}")) })?, + consumer_id: ConsumerId::new(raw.consumer_id), }) } } @@ -67,6 +70,7 @@ impl From for RawIcsDoubleVoting { submitter: value.submitter.to_string(), duplicate_vote_evidence: Some(value.duplicate_vote_evidence.into()), infraction_block_header: Some(value.infraction_block_header.into()), + consumer_id: value.consumer_id.to_string(), } } } 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 index 8b5c6c2750..67a7d20102 100644 --- a/crates/relayer-types/src/applications/ics28_ccv/msgs/ccv_misbehaviour.rs +++ b/crates/relayer-types/src/applications/ics28_ccv/msgs/ccv_misbehaviour.rs @@ -10,6 +10,7 @@ use crate::signer::Signer; use crate::tx_msg::Msg; use super::error::Error; +use super::ConsumerId; pub const ICS_MISBEHAVIOR_TYPE_URL: &str = "/interchain_security.ccv.provider.v1.MsgSubmitConsumerMisbehaviour"; @@ -18,6 +19,7 @@ pub const ICS_MISBEHAVIOR_TYPE_URL: &str = pub struct MsgSubmitIcsConsumerMisbehaviour { pub submitter: Signer, pub misbehaviour: Misbehaviour, + pub consumer_id: ConsumerId, } impl Msg for MsgSubmitIcsConsumerMisbehaviour { @@ -48,6 +50,7 @@ impl TryFrom for MsgSubmitIcsConsumerMisbehaviour { .map_err(|_e| { Error::invalid_raw_misbehaviour("cannot convert misbehaviour".into()) })?, + consumer_id: ConsumerId::new(raw.consumer_id), }) } } @@ -57,6 +60,7 @@ impl From for RawIcsMisbehaviour { RawIcsMisbehaviour { submitter: value.submitter.to_string(), misbehaviour: Some(value.misbehaviour.into()), + consumer_id: value.consumer_id.to_string(), } } } diff --git a/crates/relayer-types/src/applications/ics28_ccv/msgs/mod.rs b/crates/relayer-types/src/applications/ics28_ccv/msgs/mod.rs index df28e4a73a..61710c577f 100644 --- a/crates/relayer-types/src/applications/ics28_ccv/msgs/mod.rs +++ b/crates/relayer-types/src/applications/ics28_ccv/msgs/mod.rs @@ -1,3 +1,19 @@ pub mod ccv_double_voting; pub mod ccv_misbehaviour; pub mod error; + +use derive_more::Display; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Display, Serialize, Deserialize)] +pub struct ConsumerId(String); + +impl ConsumerId { + pub const fn new(id: String) -> Self { + Self(id) + } + + pub fn as_str(&self) -> &str { + &self.0 + } +} diff --git a/crates/relayer/src/chain/cosmos.rs b/crates/relayer/src/chain/cosmos.rs index cc5b809cad..5034f08b77 100644 --- a/crates/relayer/src/chain/cosmos.rs +++ b/crates/relayer/src/chain/cosmos.rs @@ -4,6 +4,7 @@ use bytes::Bytes; use config::CosmosSdkConfig; use core::{future::Future, str::FromStr, time::Duration}; use futures::future::join_all; +use ibc_relayer_types::applications::ics28_ccv::msgs::ConsumerId; use itertools::Itertools; use num_bigint::BigInt; use prost::Message; @@ -367,6 +368,7 @@ impl CosmosSdkChain { } /// Performs a gRPC query to fetch CCV Consumer chain staking parameters. + /// Assumes we are the consumer chain. pub fn query_ccv_consumer_chain_params(&self) -> Result { crate::time!( "query_ccv_consumer_chain_params", @@ -400,6 +402,14 @@ impl CosmosSdkChain { Ok(params) } + /// Performs a gRPC query to fetch the CCV ConsumerID corresponding + /// to the given ClientID. + /// + /// Assumes we are the provider chain. + pub fn query_ccv_consumer_id(&self, client_id: &ClientId) -> Result { + self.block_on(query_ccv_consumer_id(&self.config, client_id)) + } + /// Performs a gRPC query for Cosmos chain staking parameters. pub fn query_staking_params(&self) -> Result { crate::time!( @@ -2534,6 +2544,9 @@ impl ChainEndpoint for CosmosSdkChain { } fn query_consumer_chains(&self) -> Result, Error> { + use ibc_proto::interchain_security::ccv::provider::v1::ConsumerPhase; + use ibc_proto::interchain_security::ccv::provider::v1::QueryConsumerChainsRequest; + crate::time!( "query_consumer_chains", { @@ -2547,9 +2560,10 @@ impl ChainEndpoint for CosmosSdkChain { ibc_proto::interchain_security::ccv::provider::v1::query_client::QueryClient::new, ))?; - let request = tonic::Request::new( - ibc_proto::interchain_security::ccv::provider::v1::QueryConsumerChainsRequest {}, - ); + let request = tonic::Request::new(QueryConsumerChainsRequest { + phase: ConsumerPhase::Launched as i32, + limit: 100, + }); let response = self .block_on(client.query_consumer_chains(request)) @@ -2808,6 +2822,45 @@ pub async fn fetch_compat_mode( Ok(compat_mode.into()) } +/// Performs a gRPC query to fetch the CCV ConsumerID corresponding +/// to the given ClientID. +/// +/// Assumes we are the provider chain. +pub async fn query_ccv_consumer_id( + config: &CosmosSdkConfig, + client_id: &ClientId, +) -> Result { + use ibc_proto::interchain_security::ccv::provider::v1::query_client::QueryClient; + use ibc_proto::interchain_security::ccv::provider::v1::QueryConsumerIdFromClientIdRequest; + + crate::telemetry!(query, &config.id, "query_ccv_consumer_id"); + crate::time!( + "query_ccv_consumer_id", + { + "src_chain": &config.id, + } + ); + + let grpc_addr = Uri::from_str(&config.grpc_addr.to_string()) + .map_err(|e| Error::invalid_uri(config.grpc_addr.to_string(), e))?; + + let mut client = create_grpc_client(grpc_addr, QueryClient::new) + .await? + .max_decoding_message_size(config.max_grpc_decoding_size.get_bytes() as usize); + + let request = tonic::Request::new(QueryConsumerIdFromClientIdRequest { + client_id: client_id.to_string(), + }); + + let response = client + .query_consumer_id_from_client_id(request) + .await + .map_err(|e| Error::grpc_status(e, "query_ccv_consumer_id".to_owned()))?; + + let consumer_id = response.into_inner().consumer_id; + Ok(ConsumerId::new(consumer_id)) +} + #[cfg(test)] mod tests { use super::calculate_fee; diff --git a/crates/relayer/src/foreign_client.rs b/crates/relayer/src/foreign_client.rs index c05a5739f4..744ddb7e04 100644 --- a/crates/relayer/src/foreign_client.rs +++ b/crates/relayer/src/foreign_client.rs @@ -9,6 +9,7 @@ use std::thread; use std::time::Instant; use ibc_proto::google::protobuf::Any; +use ibc_relayer_types::applications::ics28_ccv::msgs::ConsumerId; use itertools::Itertools; use tracing::{debug, error, info, instrument, trace, warn}; @@ -31,6 +32,7 @@ use ibc_relayer_types::tx_msg::Msg; use ibc_relayer_types::Height; use crate::chain::client::ClientSettings; +use crate::chain::cosmos::query_ccv_consumer_id; use crate::chain::handle::ChainHandle; use crate::chain::requests::*; use crate::chain::tracking::TrackedMsgs; @@ -41,6 +43,7 @@ use crate::error::Error as RelayerError; use crate::event::IbcEventWithHeight; use crate::misbehaviour::{AnyMisbehaviour, MisbehaviourEvidence}; use crate::telemetry; +use crate::util::block_on; use crate::util::collate::CollatedIterExt; use crate::util::pretty::{PrettyDuration, PrettySlice}; @@ -365,7 +368,7 @@ pub enum ConsensusStateTrusted { NotTrusted { elapsed: Duration, network_timestamp: Timestamp, - consensus_state_timestmap: Timestamp, + consensus_state_timestamp: Timestamp, }, Trusted { elapsed: Duration, @@ -767,12 +770,12 @@ impl ForeignClient { error!( latest_height = %client_state.latest_height(), - network_timestmap = %network_timestamp, - consensus_state_timestamp = %consensus_state_timestmap, + network_timestamp = %network_timestamp, + consensus_state_timestamp = %consensus_state_timestamp, elapsed = ?elapsed, "client state is not valid: latest height is outside of trusting period!", ); @@ -829,7 +832,7 @@ impl ForeignClient ForeignClient ForeignClient { + msgs.push( + MsgSubmitIcsConsumerMisbehaviour { + submitter: signer.clone(), + misbehaviour: tm_misbehaviour, + consumer_id, + } + .to_any(), + ); } - .to_any(), - ); + Err(e) => { + error!( + "cannot build CCV misbehaviour evidence: failed to fetch CCV consumer id for client {}: {}", + self.id, e + ); + } + } } msgs.push( @@ -1931,3 +1945,31 @@ pub fn extract_client_id(event: &IbcEvent) -> Result<&ClientId, ForeignClientErr )), } } + +pub fn fetch_ccv_consumer_id( + provider: &impl ChainHandle, + client_id: &ClientId, +) -> Result { + let provider_config = provider.config().map_err(|e| { + ForeignClientError::misbehaviour( + format!("failed to get config of provider chain {}", provider.id(),), + e, + ) + })?; + + let ChainConfig::CosmosSdk(provider_config) = provider_config; + + let consumer_id = + block_on(query_ccv_consumer_id(&provider_config, client_id)).map_err(|e| { + ForeignClientError::misbehaviour( + format!( + "failed to query CCV consumer id corresponding to client {} from provider {}", + client_id, + provider.id() + ), + e, + ) + })?; + + Ok(consumer_id) +} diff --git a/flake.lock b/flake.lock index ae1418f0a4..a661e135be 100644 --- a/flake.lock +++ b/flake.lock @@ -158,6 +158,7 @@ "gaia17-src": "gaia17-src", "gaia18-src": "gaia18-src", "gaia19-src": "gaia19-src", + "gaia20-src": "gaia20-src", "gaia5-src": "gaia5-src", "gaia6-ordered-src": "gaia6-ordered-src", "gaia6-src": "gaia6-src", @@ -225,15 +226,16 @@ "wasmvm_2_1_2-src": "wasmvm_2_1_2-src" }, "locked": { - "lastModified": 1725007328, - "narHash": "sha256-DMRDFFpXIJyKRNhiVhXaIoOJkmVyKbt6DO6M5F8CCec=", + "lastModified": 1725305683, + "narHash": "sha256-3yOKmHTsSXU5X2PiqCZ3WcmVSCNjQpJ4xQft7cOcgDo=", "owner": "informalsystems", "repo": "cosmos.nix", - "rev": "d87f011075da3ee1afbbe3443ca25461af7d49fd", + "rev": "483a52c178745ff207ba319c02e04a859d9b80a1", "type": "github" }, "original": { "owner": "informalsystems", + "ref": "luca_joss/add-gaia-v20-alpha", "repo": "cosmos.nix", "type": "github" } @@ -673,6 +675,23 @@ "type": "github" } }, + "gaia20-src": { + "flake": false, + "locked": { + "lastModified": 1725271426, + "narHash": "sha256-ApRAGsbv2+lYKLyeIVHMrx5Gg2VetLXCs8oml0QYhCg=", + "owner": "cosmos", + "repo": "gaia", + "rev": "b5b22dc6e8eef40a6de67d62409601c6e5198fed", + "type": "github" + }, + "original": { + "owner": "cosmos", + "repo": "gaia", + "rev": "b5b22dc6e8eef40a6de67d62409601c6e5198fed", + "type": "github" + } + }, "gaia5-src": { "flake": false, "locked": { diff --git a/flake.nix b/flake.nix index 1a9ae4229a..891a19b4d8 100644 --- a/flake.nix +++ b/flake.nix @@ -2,9 +2,9 @@ description = "Nix development dependencies for ibc-rs"; inputs = { - nixpkgs.url = github:nixos/nixpkgs/nixpkgs-unstable; - flake-utils.url = github:numtide/flake-utils; - cosmos-nix.url = github:informalsystems/cosmos.nix; + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + cosmos-nix.url = "github:informalsystems/cosmos.nix/luca_joss/add-gaia-v20-alpha"; }; outputs = inputs: let @@ -33,6 +33,7 @@ evmos gaia6-ordered gaia18 + gaia20 ibc-go-v2-simapp ibc-go-v3-simapp ibc-go-v4-simapp From 60291ce7875874cb3ca6eb953e0bf05e6f329066 Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Thu, 5 Sep 2024 18:59:02 +0200 Subject: [PATCH 02/17] Use Gaia v20 for ICS light client attack integration test --- .github/workflows/misbehaviour.yml | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/.github/workflows/misbehaviour.yml b/.github/workflows/misbehaviour.yml index 43dfc6635d..135ef7c9a1 100644 --- a/.github/workflows/misbehaviour.yml +++ b/.github/workflows/misbehaviour.yml @@ -43,20 +43,20 @@ jobs: fail-fast: false matrix: chain: - - package: gaia18 + - package: gaia20 command: gaiad account_prefix: cosmos steps: - uses: actions/checkout@v4 - name: Install Nix uses: DeterminateSystems/nix-installer-action@main - with: + with: extra-conf: | substituters = https://cache.nixos.org trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= - name: Install Cachix uses: cachix/cachix-action@v15 - with: + with: name: cosmos-nix - name: Install sconfig uses: jaxxstorm/action-install-gh-release@v1.12.0 @@ -102,13 +102,13 @@ jobs: - uses: actions/checkout@v4 - name: Install Nix uses: DeterminateSystems/nix-installer-action@main - with: + with: extra-conf: | substituters = https://cache.nixos.org trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= - name: Install Cachix uses: cachix/cachix-action@v15 - with: + with: name: cosmos-nix - name: Install sconfig uses: jaxxstorm/action-install-gh-release@v1.12.0 @@ -154,13 +154,13 @@ jobs: - uses: actions/checkout@v4 - name: Install Nix uses: DeterminateSystems/nix-installer-action@main - with: + with: extra-conf: | substituters = https://cache.nixos.org trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= - name: Install Cachix uses: cachix/cachix-action@v15 - with: + with: name: cosmos-nix - name: Install sconfig uses: jaxxstorm/action-install-gh-release@v1.12.0 @@ -193,7 +193,6 @@ jobs: run: | nix shell .#${{ matrix.chain.package }} -c bash light_client_attack_freeze_test.sh - ics-double-sign: runs-on: ubuntu-20.04 timeout-minutes: 20 @@ -207,13 +206,13 @@ jobs: - uses: actions/checkout@v4 - name: Install Nix uses: DeterminateSystems/nix-installer-action@main - with: + with: extra-conf: | substituters = https://cache.nixos.org trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= - name: Install Cachix uses: cachix/cachix-action@v15 - with: + with: name: cosmos-nix - name: Install sconfig uses: jaxxstorm/action-install-gh-release@v1.12.0 @@ -245,4 +244,3 @@ jobs: working-directory: ci/misbehaviour-ics run: | nix shell .#${{ matrix.chain.package }} -c bash double_sign_test.sh - From 66ecdef1ff65bef403029b157e1a88ea544dcb25 Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Thu, 5 Sep 2024 20:08:15 +0200 Subject: [PATCH 03/17] Fix new clippy warnings --- crates/relayer/src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/relayer/src/config.rs b/crates/relayer/src/config.rs index 9494a1cc1b..fa4725a6d2 100644 --- a/crates/relayer/src/config.rs +++ b/crates/relayer/src/config.rs @@ -106,7 +106,7 @@ impl PartialOrd for GasPrice { /// the parsing of other prices. pub fn parse_gas_prices(prices: String) -> Vec { prices - .split(|c| c == ',' || c == ';') + .split([',', ';']) .filter_map(|gp| GasPrice::from_str(gp).ok()) .collect() } From 90796e8a848a7c20d5cdc3ead3b13002ea9638ba Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Thu, 5 Sep 2024 20:08:27 +0200 Subject: [PATCH 04/17] Update flake.nix --- flake.lock | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/flake.lock b/flake.lock index a661e135be..337f96ac52 100644 --- a/flake.lock +++ b/flake.lock @@ -226,11 +226,11 @@ "wasmvm_2_1_2-src": "wasmvm_2_1_2-src" }, "locked": { - "lastModified": 1725305683, - "narHash": "sha256-3yOKmHTsSXU5X2PiqCZ3WcmVSCNjQpJ4xQft7cOcgDo=", + "lastModified": 1725559253, + "narHash": "sha256-MORwaPlMtu38RaG3f4QC7Am52KZOi3ia95esf7LK/2M=", "owner": "informalsystems", "repo": "cosmos.nix", - "rev": "483a52c178745ff207ba319c02e04a859d9b80a1", + "rev": "fc9bea5bff64646a92b4757d67d1f924cd0c7972", "type": "github" }, "original": { @@ -1150,16 +1150,17 @@ "interchain-security-src": { "flake": false, "locked": { - "narHash": "sha256-adBzn51PKoRsCL9gIzC5Tcqmu7u3GjxTcDj2jpZ/da8=", + "lastModified": 1725434145, + "narHash": "sha256-GiaTXIYG0ZM5mScV7bEOLf311yYCy/d/YslRosnnzf0=", "owner": "cosmos", "repo": "interchain-security", - "rev": "03aada4af3243dbf739a12adfacc7b37232df694", + "rev": "7301916eeafa3700a03d5ddf47a0779801c6d3a1", "type": "github" }, "original": { "owner": "cosmos", - "ref": "feat/ics-misbehaviour-handling", "repo": "interchain-security", + "rev": "7301916eeafa3700a03d5ddf47a0779801c6d3a1", "type": "github" } }, @@ -1463,11 +1464,11 @@ }, "nixpkgs_5": { "locked": { - "lastModified": 1725194671, - "narHash": "sha256-tLGCFEFTB5TaOKkpfw3iYT9dnk4awTP/q4w+ROpMfuw=", + "lastModified": 1725369773, + "narHash": "sha256-gT+rUDbw+TQuszQEzMUJWTW7QYtccZ5xxWmKOSrPvEw=", "owner": "nixos", "repo": "nixpkgs", - "rev": "b833ff01a0d694b910daca6e2ff4a3f26dee478c", + "rev": "8b4061fd60ccc3b3f44b73faa7c983eacf7a6f7b", "type": "github" }, "original": { From c6ad44269803d27003fed9aab24af29b11f7029e Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Thu, 5 Sep 2024 20:19:54 +0200 Subject: [PATCH 05/17] Update expedited voting period as well --- ci/misbehaviour-ics/double_sign_test.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ci/misbehaviour-ics/double_sign_test.sh b/ci/misbehaviour-ics/double_sign_test.sh index 3685868433..ca8aa652f1 100644 --- a/ci/misbehaviour-ics/double_sign_test.sh +++ b/ci/misbehaviour-ics/double_sign_test.sh @@ -9,7 +9,7 @@ if [ "$DEBUG" = true ]; then set -x fi -# User balance of stake tokens +# User balance of stake tokens USER_COINS="100000000000stake" # Amount of stake tokens staked STAKE="100000000stake" @@ -80,7 +80,7 @@ do # Build genesis file and node directory structure interchain-security-pd init $MONIKER --chain-id provider --home ${PROV_NODE_DIR} - jq ".app_state.gov.params.voting_period = \"5s\" | .app_state.staking.params.unbonding_time = \"86400s\"" \ + jq ".app_state.gov.params.voting_period = \"5s\" | .app_state.gov.params.expedited_voting_period = \"4s\" | .app_state.staking.params.unbonding_time = \"86400s\"" \ ${PROV_NODE_DIR}/config/genesis.json > \ ${PROV_NODE_DIR}/edited_genesis.json && mv ${PROV_NODE_DIR}/edited_genesis.json ${PROV_NODE_DIR}/config/genesis.json @@ -144,7 +144,7 @@ do interchain-security-pd genesis gentx $PROV_KEY $STAKE --chain-id provider --home ${PROV_NODE_DIR} --keyring-backend test --moniker $MONIKER sleep 1 - # Copy gentxs to the lead validator for possible future collection. + # Copy gentxs to the lead validator for possible future collection. # Obviously we don't need to copy the first validator's gentx to itself if [ $MONIKER != $LEAD_VALIDATOR_MONIKER ]; then cp ${PROV_NODE_DIR}/config/gentx/* ${LEAD_VALIDATOR_PROV_DIR}/config/gentx/ @@ -590,7 +590,7 @@ do sleep 5 MSG="successfully submitted double voting evidence to chain" - + if grep -c "$MSG" $HOME_DIR/hermes-evidence-logs.txt; then echo "[SUCCESS] Successfully submitted double voting evidence to provider chain" exit 0 From 79ca071330c0906c3c0d2f4d47791288cbdedf67 Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Thu, 5 Sep 2024 21:47:53 +0200 Subject: [PATCH 06/17] wip --- ci/misbehaviour-ics/consumer_gen.json | 0 ci/misbehaviour-ics/double_sign_test.sh | 86 +++++++++---------------- 2 files changed, 31 insertions(+), 55 deletions(-) create mode 100644 ci/misbehaviour-ics/consumer_gen.json diff --git a/ci/misbehaviour-ics/consumer_gen.json b/ci/misbehaviour-ics/consumer_gen.json new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ci/misbehaviour-ics/double_sign_test.sh b/ci/misbehaviour-ics/double_sign_test.sh index ca8aa652f1..1eb434bc90 100644 --- a/ci/misbehaviour-ics/double_sign_test.sh +++ b/ci/misbehaviour-ics/double_sign_test.sh @@ -221,80 +221,56 @@ done # Build consumer chain proposal file tee ${LEAD_VALIDATOR_PROV_DIR}/consumer-proposal.json< consumer_gen.json + interchain-security-pd query provider consumer-genesis $CONSUMER_ID --home ${PROV_NODE_DIR} --node ${RPC_LADDR} -o json > consumer_gen.json jq -s '.[0].app_state.ccvconsumer = .[1] | .[0]' ${CONS_NODE_DIR}/config/genesis.json consumer_gen.json > ${CONS_NODE_DIR}/edited_genesis.json \ && mv ${CONS_NODE_DIR}/edited_genesis.json ${CONS_NODE_DIR}/config/genesis.json rm consumer_gen.json From 183cd93f5fb432d3af0e858eb7aed3ddcc3eabcd Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Mon, 9 Sep 2024 14:09:00 +0200 Subject: [PATCH 07/17] wip --- ci/misbehaviour-ics/double_sign_test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/misbehaviour-ics/double_sign_test.sh b/ci/misbehaviour-ics/double_sign_test.sh index 1eb434bc90..b569538586 100644 --- a/ci/misbehaviour-ics/double_sign_test.sh +++ b/ci/misbehaviour-ics/double_sign_test.sh @@ -304,13 +304,13 @@ do interchain-security-cd genesis add-genesis-account $CONS_ACCOUNT_ADDR $USER_COINS --home ${CONS_NODE_DIR} CONS_ACCOUNT_ADDR2=$(jq -r '.address' ${CONS_NODE_DIR}/${PROV_KEY2}.json) interchain-security-cd genesis add-genesis-account $CONS_ACCOUNT_ADDR2 $USER_COINS --home ${CONS_NODE_DIR} - sleep 10 + sleep 10000 ### this probably does not have to be done for each node # Add consumer genesis states to genesis file RPC_LADDR_PORT=$(($RPC_LADDR_BASEPORT + $index)) RPC_LADDR=tcp://${NODE_IP}:${RPC_LADDR_PORT} - interchain-security-pd query provider consumer-genesis $CONSUMER_ID --home ${PROV_NODE_DIR} --node ${RPC_LADDR} -o json > consumer_gen.json + interchain-security-pd query provider consumer-genesis $CONSUMER_ID --home ${PROV_NODE_DIR} --node ${LEAD_PROV_LISTEN_ADDR} -o json > consumer_gen.json jq -s '.[0].app_state.ccvconsumer = .[1] | .[0]' ${CONS_NODE_DIR}/config/genesis.json consumer_gen.json > ${CONS_NODE_DIR}/edited_genesis.json \ && mv ${CONS_NODE_DIR}/edited_genesis.json ${CONS_NODE_DIR}/config/genesis.json rm consumer_gen.json From 4d913779285017b0f19701763cf2132ca51460fe Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Wed, 18 Sep 2024 13:00:51 +0200 Subject: [PATCH 08/17] Integrate with tendermint-rs fix for evidence reporting --- Cargo.lock | 55 ++++------- Cargo.toml | 37 +++---- .../src/applications/ics31_icq/response.rs | 4 +- .../src/applications/transfer/error.rs | 3 +- .../src/applications/transfer/msgs/send.rs | 6 +- .../clients/ics07_tendermint/client_state.rs | 6 +- .../src/core/ics02_client/error.rs | 17 ++-- .../src/core/ics02_client/events.rs | 5 +- .../src/core/ics26_routing/error.rs | 2 +- crates/relayer/src/chain/cosmos.rs | 2 +- crates/relayer/src/config/compat_mode.rs | 96 +------------------ crates/relayer/src/util/compat_mode.rs | 17 ++-- tools/test-framework/src/chain/driver.rs | 2 +- tools/test-framework/src/chain/tagged.rs | 2 +- 14 files changed, 72 insertions(+), 182 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 136764926d..0973b17189 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1549,8 +1549,8 @@ dependencies = [ [[package]] name = "ibc-proto" -version = "0.47.1" -source = "git+https://github.com/cosmos/ibc-proto-rs?branch=romac/permissionless-ics#901f8cad529913555bccd9b2283553a2c66bb343" +version = "0.48.0" +source = "git+https://github.com/cosmos/ibc-proto-rs?branch=romac/permissionless-ics#cf35684ac98d1c24ef4d6ed35e59c9606c8a1f94" dependencies = [ "base64 0.22.1", "bytes", @@ -2399,15 +2399,6 @@ dependencies = [ "syn 2.0.76", ] -[[package]] -name = "prost-types" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cee5168b05f49d4b0ca581206eb14a7b22fafd963efe729ac48eb03266e25cc2" -dependencies = [ - "prost", -] - [[package]] name = "protobuf" version = "2.28.0" @@ -3322,9 +3313,8 @@ dependencies = [ [[package]] name = "tendermint" -version = "0.38.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "505d9d6ffeb83b1de47c307c6e0d2dff56c6256989299010ad03cd80a8491e97" +version = "0.39.1" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#c190d2a72fa15e3d96412d6beacaf4fb62ed4e61" dependencies = [ "bytes", "digest 0.10.7", @@ -3336,7 +3326,6 @@ dependencies = [ "num-traits", "once_cell", "prost", - "prost-types", "ripemd", "serde", "serde_bytes", @@ -3353,9 +3342,8 @@ dependencies = [ [[package]] name = "tendermint-config" -version = "0.38.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9de111ea653b2adaef627ac2452b463c77aa615c256eaaddf279ec5a1cf9775f" +version = "0.39.1" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#c190d2a72fa15e3d96412d6beacaf4fb62ed4e61" dependencies = [ "flex-error", "serde", @@ -3367,9 +3355,8 @@ dependencies = [ [[package]] name = "tendermint-light-client" -version = "0.38.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91e5abb448c65e8abdfe0e17a3a189e005a71b4169b89f36aaa2053ff239577" +version = "0.39.1" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#c190d2a72fa15e3d96412d6beacaf4fb62ed4e61" dependencies = [ "contracts", "crossbeam-channel", @@ -3392,9 +3379,8 @@ dependencies = [ [[package]] name = "tendermint-light-client-detector" -version = "0.38.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb1ac1607eb7a3393313558b339c36eebeba15aa7f2d101d1d47299e65825152" +version = "0.39.1" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#c190d2a72fa15e3d96412d6beacaf4fb62ed4e61" dependencies = [ "crossbeam-channel", "derive_more", @@ -3415,9 +3401,8 @@ dependencies = [ [[package]] name = "tendermint-light-client-verifier" -version = "0.38.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2674adbf0dc51aa0c8eaf8462c7d6692ec79502713e50ed5432a442002be90" +version = "0.39.1" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#c190d2a72fa15e3d96412d6beacaf4fb62ed4e61" dependencies = [ "derive_more", "flex-error", @@ -3428,14 +3413,12 @@ dependencies = [ [[package]] name = "tendermint-proto" -version = "0.38.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ed14abe3b0502a3afe21ca74ca5cdd6c7e8d326d982c26f98a394445eb31d6e" +version = "0.39.1" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#c190d2a72fa15e3d96412d6beacaf4fb62ed4e61" dependencies = [ "bytes", "flex-error", "prost", - "prost-types", "serde", "serde_bytes", "subtle-encoding", @@ -3444,9 +3427,8 @@ dependencies = [ [[package]] name = "tendermint-rpc" -version = "0.38.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02f96a2b8a0d3d0b59e4024b1a6bdc1589efc6af4709d08a480a20cc4ba90f63" +version = "0.39.1" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#c190d2a72fa15e3d96412d6beacaf4fb62ed4e61" dependencies = [ "async-trait", "async-tungstenite", @@ -3478,9 +3460,8 @@ dependencies = [ [[package]] name = "tendermint-testgen" -version = "0.38.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae007e2918414ae96e4835426aace7538d23b8ddf96d71e23d241f58f386e877" +version = "0.39.1" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#c190d2a72fa15e3d96412d6beacaf4fb62ed4e61" dependencies = [ "ed25519-consensus", "gumdrop", diff --git a/Cargo.toml b/Cargo.toml index b3e130b61e..ca6eeb9410 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,14 +29,19 @@ ibc-telemetry = { version = "0.29.3", path = "crates/telemetry" } ibc-test-framework = { version = "0.29.3", path = "tools/test-framework" } ibc-integration-test = { version = "0.29.3", path = "tools/integration-test" } +# IBC dependencies +ibc-proto = "0.48.0" +ics23 = "0.12.0" + # Tendermint dependencies -tendermint = { version = "0.38.1", default-features = false } -tendermint-light-client = { version = "0.38.1", default-features = false } -tendermint-light-client-detector = { version = "0.38.1", default-features = false } -tendermint-light-client-verifier = { version = "0.38.1", default-features = false } -tendermint-proto = { version = "0.38.1" } -tendermint-rpc = { version = "0.38.1" } -tendermint-testgen = { version = "0.38.1" } +tendermint = { version = "0.39.1", default-features = false } +tendermint-light-client = { version = "0.39.1", default-features = false } +tendermint-light-client-detector = { version = "0.39.1", default-features = false } +tendermint-light-client-verifier = { version = "0.39.1", default-features = false } +tendermint-proto = { version = "0.39.1" } +tendermint-rpc = { version = "0.39.1" } +tendermint-testgen = { version = "0.39.1" } + # Other dependencies abscissa_core = "=0.6.0" @@ -72,8 +77,6 @@ hex = "0.4.3" http = "1.0.0" humantime = "2.1.0" humantime-serde = "1.1.1" -ibc-proto = "0.47.0" -ics23 = "0.12.0" itertools = "0.13.0" moka = "0.12.8" num-bigint = "0.4" @@ -120,11 +123,11 @@ uuid = "1.10.0" overflow-checks = true [patch.crates-io] -ibc-proto = { git = "https://github.com/cosmos/ibc-proto-rs", branch = "romac/permissionless-ics" } -# tendermint = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "main" } -# tendermint-rpc = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "main" } -# tendermint-proto = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "main" } -# tendermint-light-client = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "main" } -# tendermint-light-client-verifier = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "main" } -# tendermint-light-client-detector = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "main" } -# tendermint-testgen = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "main" } +ibc-proto = { git = "https://github.com/cosmos/ibc-proto-rs", branch = "romac/permissionless-ics" } +tendermint = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "romac/v038-evidence" } +tendermint-rpc = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "romac/v038-evidence" } +tendermint-proto = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "romac/v038-evidence" } +tendermint-light-client = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "romac/v038-evidence" } +tendermint-light-client-verifier = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "romac/v038-evidence" } +tendermint-light-client-detector = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "romac/v038-evidence" } +tendermint-testgen = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "romac/v038-evidence" } diff --git a/crates/relayer-types/src/applications/ics31_icq/response.rs b/crates/relayer-types/src/applications/ics31_icq/response.rs index 98b45acf06..7a5c9bb638 100644 --- a/crates/relayer-types/src/applications/ics31_icq/response.rs +++ b/crates/relayer-types/src/applications/ics31_icq/response.rs @@ -52,11 +52,13 @@ impl CrossChainQueryResponse { pub fn try_to_any(&self, signer: Signer) -> Result { let mut encoded = vec![]; + let proof_ops = into_proof_ops(self.proof.clone()); + let msg_submit_cross_chain_query_result = MsgSubmitQueryResponse { chain_id: self.chain_id.to_string(), query_id: self.query_id.to_string(), result: self.result.clone(), - proof_ops: Some(into_proof_ops(self.proof.clone())), + proof_ops: Some(proof_ops), height: self.height, from_address: signer.as_ref().to_string(), }; diff --git a/crates/relayer-types/src/applications/transfer/error.rs b/crates/relayer-types/src/applications/transfer/error.rs index f0e52d946d..71c8d04b0f 100644 --- a/crates/relayer-types/src/applications/transfer/error.rs +++ b/crates/relayer-types/src/applications/transfer/error.rs @@ -4,7 +4,6 @@ use std::string::FromUtf8Error; use flex_error::{define_error, DisplayOnly, TraceError}; use subtle_encoding::Error as EncodingError; -use tendermint_proto::Error as TendermintProtoError; use uint::FromDecStrErr; use crate::core::ics04_channel::channel::Ordering; @@ -127,7 +126,7 @@ define_error! { | _ | { "no trace associated with specified hash" }, DecodeRawMsg - [ TraceError ] + [ TraceError ] | _ | { "error decoding raw msg" }, UnknownMsgType diff --git a/crates/relayer-types/src/applications/transfer/msgs/send.rs b/crates/relayer-types/src/applications/transfer/msgs/send.rs index 36e71dc66b..fcbb34a6bb 100644 --- a/crates/relayer-types/src/applications/transfer/msgs/send.rs +++ b/crates/relayer-types/src/applications/transfer/msgs/send.rs @@ -43,11 +43,11 @@ where type Error = Error; fn try_from(value: RawMsgSend) -> Result { - let amount: Vec> = value + let amount = value .amount .into_iter() - .map(Coin::try_from) - .collect::>, _>>()?; + .map(Coin::::try_from) + .collect::, _>>()?; Ok(MsgSend { from_address: value.from_address, to_address: value.to_address, diff --git a/crates/relayer-types/src/clients/ics07_tendermint/client_state.rs b/crates/relayer-types/src/clients/ics07_tendermint/client_state.rs index 818cf13347..44888d8afa 100644 --- a/crates/relayer-types/src/clients/ics07_tendermint/client_state.rs +++ b/crates/relayer-types/src/clients/ics07_tendermint/client_state.rs @@ -305,9 +305,9 @@ impl From for RawTmClientState { Self { chain_id: value.chain_id.to_string(), trust_level: Some(value.trust_threshold.into()), - trusting_period: Some(value.trusting_period.into()), - unbonding_period: Some(value.unbonding_period.into()), - max_clock_drift: Some(value.max_clock_drift.into()), + trusting_period: Some(value.trusting_period.try_into().unwrap()), + unbonding_period: Some(value.unbonding_period.try_into().unwrap()), + max_clock_drift: Some(value.max_clock_drift.try_into().unwrap()), frozen_height: Some(value.frozen_height.map(|height| height.into()).unwrap_or( RawHeight { revision_number: 0, diff --git a/crates/relayer-types/src/core/ics02_client/error.rs b/crates/relayer-types/src/core/ics02_client/error.rs index a560a499f1..27316e2747 100644 --- a/crates/relayer-types/src/core/ics02_client/error.rs +++ b/crates/relayer-types/src/core/ics02_client/error.rs @@ -1,5 +1,4 @@ use flex_error::{define_error, TraceError}; -use tendermint_proto::Error as TendermintProtoError; use crate::core::ics02_client::client_type::ClientType; use crate::core::ics02_client::height::HeightError; @@ -109,14 +108,14 @@ define_error! { }, DecodeRawClientState - [ TraceError ] + [ TraceError ] | _ | { "error decoding raw client state" }, MissingRawClientState | _ | { "missing raw client state" }, InvalidRawConsensusState - [ TraceError ] + [ TraceError ] | _ | { "invalid raw client consensus state" }, MissingRawConsensusState @@ -138,7 +137,7 @@ define_error! { | _ | { "invalid client identifier" }, InvalidRawHeader - [ TraceError ] + [ TraceError ] | _ | { "invalid raw header" }, MalformedHeader @@ -148,7 +147,7 @@ define_error! { | _ | { "missing raw header" }, DecodeRawMisbehaviour - [ TraceError ] + [ TraceError ] | _ | { "invalid raw misbehaviour" }, InvalidRawMisbehaviour @@ -254,19 +253,19 @@ define_error! { | e | { format_args!("the local consensus state could not be retrieved for height {}", e.height) }, InvalidConnectionEnd - [ TraceError] + [ TraceError] | _ | { "invalid connection end" }, InvalidChannelEnd - [ TraceError] + [ TraceError] | _ | { "invalid channel end" }, InvalidAnyClientState - [ TraceError] + [ TraceError] | _ | { "invalid any client state" }, InvalidAnyConsensusState - [ TraceError ] + [ TraceError ] | _ | { "invalid any client consensus state" }, Signer diff --git a/crates/relayer-types/src/core/ics02_client/events.rs b/crates/relayer-types/src/core/ics02_client/events.rs index 3abe9b7b8d..da295833ef 100644 --- a/crates/relayer-types/src/core/ics02_client/events.rs +++ b/crates/relayer-types/src/core/ics02_client/events.rs @@ -1,9 +1,10 @@ //! Types for the IBC events emitted from Tendermint Websocket by the client module. -use serde_derive::{Deserialize, Serialize}; use std::fmt::{Display, Error as FmtError, Formatter}; + +use ibc_proto::Protobuf; +use serde_derive::{Deserialize, Serialize}; use tendermint::abci; -use tendermint_proto::Protobuf; use super::header::AnyHeader; use crate::core::ics02_client::client_type::ClientType; diff --git a/crates/relayer-types/src/core/ics26_routing/error.rs b/crates/relayer-types/src/core/ics26_routing/error.rs index f51581b6e0..5a4773e5af 100644 --- a/crates/relayer-types/src/core/ics26_routing/error.rs +++ b/crates/relayer-types/src/core/ics26_routing/error.rs @@ -29,7 +29,7 @@ define_error! { | e | { format_args!("unknown type URL {0}", e.url) }, MalformedMessageBytes - [ TraceError ] + [ TraceError ] | _ | { "the message is malformed and cannot be decoded" }, } } diff --git a/crates/relayer/src/chain/cosmos.rs b/crates/relayer/src/chain/cosmos.rs index 5034f08b77..0797eeee80 100644 --- a/crates/relayer/src/chain/cosmos.rs +++ b/crates/relayer/src/chain/cosmos.rs @@ -2819,7 +2819,7 @@ pub async fn fetch_compat_mode( } }?; - Ok(compat_mode.into()) + Ok(compat_mode) } /// Performs a gRPC query to fetch the CCV ConsumerID corresponding diff --git a/crates/relayer/src/config/compat_mode.rs b/crates/relayer/src/config/compat_mode.rs index cb2a035855..795081ea6f 100644 --- a/crates/relayer/src/config/compat_mode.rs +++ b/crates/relayer/src/config/compat_mode.rs @@ -1,95 +1 @@ -use core::fmt::{Display, Error as FmtError, Formatter}; -use core::str::FromStr; -use serde::Deserialize; -use serde::Deserializer; -use serde::Serialize; -use serde::Serializer; - -use tendermint_rpc::client::CompatMode as TmCompatMode; - -use crate::config::Error; - -/// CometBFT RPC compatibility mode -#[derive(Clone, Debug, Eq, PartialEq)] -pub enum CompatMode { - /// Use version 0.34 of the protocol. - V0_34, - /// Use version 0.37+ of the protocol. - V0_37, -} - -impl Display for CompatMode { - fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { - match self { - Self::V0_34 => write!(f, "v0.34"), - Self::V0_37 => write!(f, "v0.37"), - } - } -} - -impl FromStr for CompatMode { - type Err = Error; - - fn from_str(s: &str) -> Result { - const VALID_COMPAT_MODES: &str = "0.34, 0.37, 0.38"; - - // Trim leading 'v', if present - match s.trim_start_matches('v') { - "0.34" => Ok(CompatMode::V0_34), - "0.37" => Ok(CompatMode::V0_37), - "0.38" => Ok(CompatMode::V0_37), // v0.38 is compatible with v0.37 - _ => Err(Error::invalid_compat_mode( - s.to_string(), - VALID_COMPAT_MODES, - )), - } - } -} - -impl<'de> Deserialize<'de> for CompatMode { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - use serde::de; - - let s = String::deserialize(deserializer)?; - FromStr::from_str(&s).map_err(de::Error::custom) - } -} - -impl Serialize for CompatMode { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - self.to_string().serialize(serializer) - } -} - -impl From for CompatMode { - fn from(value: TmCompatMode) -> Self { - match value { - TmCompatMode::V0_34 => Self::V0_34, - TmCompatMode::V0_37 => Self::V0_37, - } - } -} - -impl From for TmCompatMode { - fn from(value: CompatMode) -> Self { - match value { - CompatMode::V0_34 => Self::V0_34, - CompatMode::V0_37 => Self::V0_37, - } - } -} - -impl CompatMode { - pub fn equal_to_tm_compat_mode(&self, tm_compat_mode: TmCompatMode) -> bool { - match self { - Self::V0_34 => tm_compat_mode == TmCompatMode::V0_34, - Self::V0_37 => tm_compat_mode == TmCompatMode::V0_37, - } - } -} +pub use tendermint_rpc::client::CompatMode; diff --git a/crates/relayer/src/util/compat_mode.rs b/crates/relayer/src/util/compat_mode.rs index 716534bb95..c637d5a247 100644 --- a/crates/relayer/src/util/compat_mode.rs +++ b/crates/relayer/src/util/compat_mode.rs @@ -1,7 +1,6 @@ use tracing::warn; use tendermint::Version; -use tendermint_rpc::client::CompatMode as TmCompatMode; use crate::chain::cosmos::version::ConsensusVersion; use crate::config::compat_mode::CompatMode; @@ -11,21 +10,21 @@ pub fn compat_mode_from_node_version( configured_version: &Option, version: Version, ) -> Result { - let queried_version = TmCompatMode::from_version(version); + let queried_version = CompatMode::from_version(version); // This will prioritize the use of the CompatMode specified in Hermes configuration file match (configured_version, queried_version) { - (Some(configured), Ok(queried)) if !configured.equal_to_tm_compat_mode(queried) => { + (Some(configured), Ok(queried)) if configured != &queried => { warn!( "potential `compat_mode` misconfiguration! Configured version '{configured}' does not match chain version '{queried}'. \ Hermes will use the configured `compat_mode` version '{configured}'. \ If this configuration is done on purpose this message can be ignored.", ); - Ok(configured.clone()) + Ok(*configured) } - (Some(configured), _) => Ok(configured.clone()), - (_, Ok(queried)) => Ok(queried.into()), + (Some(configured), _) => Ok(*configured), + (_, Ok(queried)) => Ok(queried), (_, Err(e)) => Err(Error::invalid_compat_mode(e)), } } @@ -50,7 +49,7 @@ pub fn compat_mode_from_version_specs( If this configuration is done on purpose this message can be ignored." ); - Ok(configured.clone()) + Ok(*configured) } (Some(configured), None) => { warn!( @@ -58,7 +57,7 @@ pub fn compat_mode_from_version_specs( and will use the configured `compat_mode` version `{configured}`." ); - Ok(configured.clone()) + Ok(*configured) } (None, Some(queried)) => Ok(queried), (None, None) => { @@ -77,7 +76,7 @@ fn compat_mode_from_semver(v: semver::Version) -> Option { match (v.major, v.minor) { (0, 34) => Some(CompatMode::V0_34), (0, 37) => Some(CompatMode::V0_37), - (0, 38) => Some(CompatMode::V0_37), + (0, 38) => Some(CompatMode::V0_38), _ => None, } } diff --git a/tools/test-framework/src/chain/driver.rs b/tools/test-framework/src/chain/driver.rs index 85830caf5e..27d6919304 100644 --- a/tools/test-framework/src/chain/driver.rs +++ b/tools/test-framework/src/chain/driver.rs @@ -5,11 +5,11 @@ use alloc::sync::Arc; use core::time::Duration; use eyre::eyre; -use ibc_relayer::config::compat_mode::CompatMode; use std::cmp::max; use tokio::runtime::Runtime; use ibc_relayer::chain::cosmos::types::config::TxConfig; +use ibc_relayer::config::compat_mode::CompatMode; use ibc_relayer_types::applications::transfer::amount::Amount; use ibc_relayer_types::core::ics24_host::identifier::ChainId; diff --git a/tools/test-framework/src/chain/tagged.rs b/tools/test-framework/src/chain/tagged.rs index b574c6eef1..af7a73c06a 100644 --- a/tools/test-framework/src/chain/tagged.rs +++ b/tools/test-framework/src/chain/tagged.rs @@ -132,7 +132,7 @@ impl<'a, Chain: Send> TaggedChainDriverExt for MonoTagged Date: Fri, 20 Sep 2024 08:42:27 +0200 Subject: [PATCH 09/17] Update tendermint-rs --- Cargo.lock | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 87215ea155..5989609a7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3314,7 +3314,7 @@ dependencies = [ [[package]] name = "tendermint" version = "0.39.1" -source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#c190d2a72fa15e3d96412d6beacaf4fb62ed4e61" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#58c6f4cc0aac1a421f61d743d50c4951f8d07044" dependencies = [ "bytes", "digest 0.10.7", @@ -3343,7 +3343,7 @@ dependencies = [ [[package]] name = "tendermint-config" version = "0.39.1" -source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#c190d2a72fa15e3d96412d6beacaf4fb62ed4e61" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#58c6f4cc0aac1a421f61d743d50c4951f8d07044" dependencies = [ "flex-error", "serde", @@ -3356,7 +3356,7 @@ dependencies = [ [[package]] name = "tendermint-light-client" version = "0.39.1" -source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#c190d2a72fa15e3d96412d6beacaf4fb62ed4e61" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#58c6f4cc0aac1a421f61d743d50c4951f8d07044" dependencies = [ "contracts", "crossbeam-channel", @@ -3380,7 +3380,7 @@ dependencies = [ [[package]] name = "tendermint-light-client-detector" version = "0.39.1" -source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#c190d2a72fa15e3d96412d6beacaf4fb62ed4e61" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#58c6f4cc0aac1a421f61d743d50c4951f8d07044" dependencies = [ "crossbeam-channel", "derive_more", @@ -3402,7 +3402,7 @@ dependencies = [ [[package]] name = "tendermint-light-client-verifier" version = "0.39.1" -source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#c190d2a72fa15e3d96412d6beacaf4fb62ed4e61" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#58c6f4cc0aac1a421f61d743d50c4951f8d07044" dependencies = [ "derive_more", "flex-error", @@ -3414,7 +3414,7 @@ dependencies = [ [[package]] name = "tendermint-proto" version = "0.39.1" -source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#c190d2a72fa15e3d96412d6beacaf4fb62ed4e61" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#58c6f4cc0aac1a421f61d743d50c4951f8d07044" dependencies = [ "bytes", "flex-error", @@ -3428,7 +3428,7 @@ dependencies = [ [[package]] name = "tendermint-rpc" version = "0.39.1" -source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#c190d2a72fa15e3d96412d6beacaf4fb62ed4e61" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#58c6f4cc0aac1a421f61d743d50c4951f8d07044" dependencies = [ "async-trait", "async-tungstenite", @@ -3461,7 +3461,7 @@ dependencies = [ [[package]] name = "tendermint-testgen" version = "0.39.1" -source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#c190d2a72fa15e3d96412d6beacaf4fb62ed4e61" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#58c6f4cc0aac1a421f61d743d50c4951f8d07044" dependencies = [ "ed25519-consensus", "gumdrop", From 2d47a4ec5cc8a83512da64fb378cc17142efc004 Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Tue, 24 Sep 2024 15:25:48 +0200 Subject: [PATCH 10/17] Update cosmos.nix --- flake.lock | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/flake.lock b/flake.lock index 337f96ac52..427cc01b61 100644 --- a/flake.lock +++ b/flake.lock @@ -226,11 +226,11 @@ "wasmvm_2_1_2-src": "wasmvm_2_1_2-src" }, "locked": { - "lastModified": 1725559253, - "narHash": "sha256-MORwaPlMtu38RaG3f4QC7Am52KZOi3ia95esf7LK/2M=", + "lastModified": 1727183054, + "narHash": "sha256-qO/JlbeGKi3zBgSNxPY4Vsy++tcuaroWEwBMf4xeCzs=", "owner": "informalsystems", "repo": "cosmos.nix", - "rev": "fc9bea5bff64646a92b4757d67d1f924cd0c7972", + "rev": "ece770f2d941841a11ff8e0f750dd252068eac3f", "type": "github" }, "original": { @@ -1150,17 +1150,17 @@ "interchain-security-src": { "flake": false, "locked": { - "lastModified": 1725434145, - "narHash": "sha256-GiaTXIYG0ZM5mScV7bEOLf311yYCy/d/YslRosnnzf0=", + "lastModified": 1726849313, + "narHash": "sha256-1WEvV3LoXfGvZC9fXOb8mBLKVGCVBiXZcwUewSPit+8=", "owner": "cosmos", "repo": "interchain-security", - "rev": "7301916eeafa3700a03d5ddf47a0779801c6d3a1", + "rev": "1e60637f9d8f3505208282416abfbb87fabc4795", "type": "github" }, "original": { "owner": "cosmos", + "ref": "v6.1.0", "repo": "interchain-security", - "rev": "7301916eeafa3700a03d5ddf47a0779801c6d3a1", "type": "github" } }, From 9871e5ff643613d0561c2d1bc888de592226cbc1 Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Tue, 24 Sep 2024 16:30:34 +0200 Subject: [PATCH 11/17] Update tendermint-rs --- Cargo.lock | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5989609a7c..26cb77d497 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3314,7 +3314,7 @@ dependencies = [ [[package]] name = "tendermint" version = "0.39.1" -source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#58c6f4cc0aac1a421f61d743d50c4951f8d07044" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#ccc53d4bc0e0a975754771f8e62fc299a2aa59f2" dependencies = [ "bytes", "digest 0.10.7", @@ -3343,7 +3343,7 @@ dependencies = [ [[package]] name = "tendermint-config" version = "0.39.1" -source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#58c6f4cc0aac1a421f61d743d50c4951f8d07044" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#ccc53d4bc0e0a975754771f8e62fc299a2aa59f2" dependencies = [ "flex-error", "serde", @@ -3356,7 +3356,7 @@ dependencies = [ [[package]] name = "tendermint-light-client" version = "0.39.1" -source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#58c6f4cc0aac1a421f61d743d50c4951f8d07044" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#ccc53d4bc0e0a975754771f8e62fc299a2aa59f2" dependencies = [ "contracts", "crossbeam-channel", @@ -3380,7 +3380,7 @@ dependencies = [ [[package]] name = "tendermint-light-client-detector" version = "0.39.1" -source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#58c6f4cc0aac1a421f61d743d50c4951f8d07044" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#ccc53d4bc0e0a975754771f8e62fc299a2aa59f2" dependencies = [ "crossbeam-channel", "derive_more", @@ -3402,7 +3402,7 @@ dependencies = [ [[package]] name = "tendermint-light-client-verifier" version = "0.39.1" -source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#58c6f4cc0aac1a421f61d743d50c4951f8d07044" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#ccc53d4bc0e0a975754771f8e62fc299a2aa59f2" dependencies = [ "derive_more", "flex-error", @@ -3414,7 +3414,7 @@ dependencies = [ [[package]] name = "tendermint-proto" version = "0.39.1" -source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#58c6f4cc0aac1a421f61d743d50c4951f8d07044" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#ccc53d4bc0e0a975754771f8e62fc299a2aa59f2" dependencies = [ "bytes", "flex-error", @@ -3428,7 +3428,7 @@ dependencies = [ [[package]] name = "tendermint-rpc" version = "0.39.1" -source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#58c6f4cc0aac1a421f61d743d50c4951f8d07044" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#ccc53d4bc0e0a975754771f8e62fc299a2aa59f2" dependencies = [ "async-trait", "async-tungstenite", @@ -3461,7 +3461,7 @@ dependencies = [ [[package]] name = "tendermint-testgen" version = "0.39.1" -source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#58c6f4cc0aac1a421f61d743d50c4951f8d07044" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=romac/v038-evidence#ccc53d4bc0e0a975754771f8e62fc299a2aa59f2" dependencies = [ "ed25519-consensus", "gumdrop", From 470a49c2049e7927384e4500ee13089c495e5117 Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Tue, 24 Sep 2024 17:05:18 +0200 Subject: [PATCH 12/17] Fix evidence submission --- Cargo.lock | 4 +-- crates/relayer-cli/src/commands/evidence.rs | 23 +++++++++---- .../src/applications/ics28_ccv/msgs/mod.rs | 33 +++++++++++++++++++ crates/relayer/src/chain/cosmos.rs | 12 +++---- crates/relayer/src/chain/endpoint.rs | 3 +- crates/relayer/src/chain/handle.rs | 5 +-- crates/relayer/src/chain/handle/base.rs | 16 ++++----- crates/relayer/src/chain/handle/cache.rs | 7 ++-- crates/relayer/src/chain/handle/counting.rs | 7 ++-- crates/relayer/src/chain/runtime.rs | 12 +++---- crates/relayer/src/error.rs | 5 +++ 11 files changed, 88 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 26cb77d497..f78bf86832 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1550,7 +1550,7 @@ dependencies = [ [[package]] name = "ibc-proto" version = "0.48.0" -source = "git+https://github.com/cosmos/ibc-proto-rs?branch=romac/permissionless-ics#cf35684ac98d1c24ef4d6ed35e59c9606c8a1f94" +source = "git+https://github.com/cosmos/ibc-proto-rs?branch=romac/permissionless-ics#9673ddf70674b7b9d97f2072ef6485b2776d940a" dependencies = [ "base64 0.22.1", "bytes", @@ -4187,7 +4187,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.48.0", ] [[package]] diff --git a/crates/relayer-cli/src/commands/evidence.rs b/crates/relayer-cli/src/commands/evidence.rs index f7adc601b8..020d7a4713 100644 --- a/crates/relayer-cli/src/commands/evidence.rs +++ b/crates/relayer-cli/src/commands/evidence.rs @@ -6,6 +6,7 @@ use std::time::Duration; use abscissa_core::clap::Parser; use ibc_relayer::config::{ChainConfig, Config}; +use ibc_relayer_types::applications::ics28_ccv::msgs::ConsumerId; use tokio::runtime::Runtime as TokioRuntime; use tendermint::block::Height as TendermintHeight; @@ -318,13 +319,18 @@ fn submit_duplicate_vote_evidence( let signer = counterparty_chain_handle.get_signer()?; - if !is_counterparty_provider(chain, counterparty_chain_handle, counterparty_client_id) { + let consumer_id = fetch_ccv_consumer_id(counterparty_chain_handle, counterparty_client_id)?; + + if !is_counterparty_provider( + chain, + &consumer_id, + counterparty_chain_handle, + counterparty_client_id, + ) { debug!("counterparty client `{counterparty_client_id}` on chain `{counterparty_chain_id}` is not a CCV client, skipping..."); return Ok(ControlFlow::Continue(())); } - let consumer_id = fetch_ccv_consumer_id(counterparty_chain_handle, counterparty_client_id)?; - let infraction_height = evidence.vote_a.height; // Get the trusted height in the same way we do for client updates, @@ -510,8 +516,10 @@ fn submit_light_client_attack_evidence( counterparty.id(), ); + let consumer_id = fetch_ccv_consumer_id(counterparty, &counterparty_client_id)?; + let counterparty_is_provider = - is_counterparty_provider(chain, counterparty, &counterparty_client_id); + is_counterparty_provider(chain, &consumer_id, counterparty, &counterparty_client_id); let counterparty_client_is_frozen = counterparty_client.is_frozen(); @@ -683,6 +691,7 @@ fn has_consensus_state( /// which is then definitely a provider. fn is_counterparty_provider( chain: &CosmosSdkChain, + consumer_id: &ConsumerId, counterparty_chain_handle: &BaseChainHandle, counterparty_client_id: &ClientId, ) -> bool { @@ -691,8 +700,10 @@ fn is_counterparty_provider( .query_consumer_chains() .unwrap_or_default(); // If the query fails, use an empty list of consumers - consumer_chains.iter().any(|(chain_id, client_id)| { - chain_id == chain.id() && client_id == counterparty_client_id + consumer_chains.iter().any(|consumer| { + &consumer.chain_id == chain.id() + && &consumer.client_id == counterparty_client_id + && &consumer.consumer_id == consumer_id }) } else { false diff --git a/crates/relayer-types/src/applications/ics28_ccv/msgs/mod.rs b/crates/relayer-types/src/applications/ics28_ccv/msgs/mod.rs index 61710c577f..6f992ae0f7 100644 --- a/crates/relayer-types/src/applications/ics28_ccv/msgs/mod.rs +++ b/crates/relayer-types/src/applications/ics28_ccv/msgs/mod.rs @@ -2,9 +2,15 @@ pub mod ccv_double_voting; pub mod ccv_misbehaviour; pub mod error; +use std::convert::Infallible; + use derive_more::Display; +use ibc_proto::interchain_security::ccv::provider::v1::Chain; use serde::{Deserialize, Serialize}; +use crate::core::ics24_host; +use crate::core::ics24_host::identifier::{ChainId, ClientId}; + #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Display, Serialize, Deserialize)] pub struct ConsumerId(String); @@ -17,3 +23,30 @@ impl ConsumerId { &self.0 } } + +impl std::str::FromStr for ConsumerId { + type Err = Infallible; + + fn from_str(s: &str) -> Result { + Ok(Self(s.to_string())) + } +} + +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct ConsumerChain { + pub chain_id: ChainId, + pub consumer_id: ConsumerId, + pub client_id: ClientId, +} + +impl TryFrom for ConsumerChain { + type Error = ics24_host::error::ValidationError; + + fn try_from(value: Chain) -> Result { + Ok(Self { + chain_id: ChainId::from_string(&value.chain_id), + consumer_id: ConsumerId::new(value.consumer_id), + client_id: value.client_id.parse()?, + }) + } +} diff --git a/crates/relayer/src/chain/cosmos.rs b/crates/relayer/src/chain/cosmos.rs index 0797eeee80..b326289779 100644 --- a/crates/relayer/src/chain/cosmos.rs +++ b/crates/relayer/src/chain/cosmos.rs @@ -4,7 +4,6 @@ use bytes::Bytes; use config::CosmosSdkConfig; use core::{future::Future, str::FromStr, time::Duration}; use futures::future::join_all; -use ibc_relayer_types::applications::ics28_ccv::msgs::ConsumerId; use itertools::Itertools; use num_bigint::BigInt; use prost::Message; @@ -23,6 +22,7 @@ use ibc_proto::ibc::apps::fee::v1::{ use ibc_proto::ibc::core::channel::v1::{QueryUpgradeErrorRequest, QueryUpgradeRequest}; use ibc_proto::interchain_security::ccv::v1::ConsumerParams as CcvConsumerParams; use ibc_proto::Protobuf; +use ibc_relayer_types::applications::ics28_ccv::msgs::{ConsumerChain, ConsumerId}; use ibc_relayer_types::applications::ics31_icq::response::CrossChainQueryResponse; use ibc_relayer_types::clients::ics07_tendermint::client_state::{ AllowUpdate, ClientState as TmClientState, @@ -148,7 +148,7 @@ pub mod wait; /// might be un-necessarily restrictive on the relayer side. /// The [default max. block size in Tendermint 0.37 is 21MB](tm-37-max). /// With a fraction of `0.9`, then Hermes will never permit the configuration -/// of `max_tx_size` to exceed ~18.9MB. +/// of `max_tx_size` to exceed ~18.9MB /// /// [tm-37-max]: https://github.com/tendermint/tendermint/blob/v0.37.0-rc1/types/params.go#L79 pub const BLOCK_MAX_BYTES_MAX_FRACTION: f64 = 0.9; @@ -2543,7 +2543,7 @@ impl ChainEndpoint for CosmosSdkChain { Ok(incentivized_response) } - fn query_consumer_chains(&self) -> Result, Error> { + fn query_consumer_chains(&self) -> Result, Error> { use ibc_proto::interchain_security::ccv::provider::v1::ConsumerPhase; use ibc_proto::interchain_security::ccv::provider::v1::QueryConsumerChainsRequest; @@ -2562,7 +2562,7 @@ impl ChainEndpoint for CosmosSdkChain { let request = tonic::Request::new(QueryConsumerChainsRequest { phase: ConsumerPhase::Launched as i32, - limit: 100, + pagination: Some(PageRequest::all().into()), }); let response = self @@ -2573,8 +2573,8 @@ impl ChainEndpoint for CosmosSdkChain { let result = response .chains .into_iter() - .map(|c| (c.chain_id.parse().unwrap(), c.client_id.parse().unwrap())) - .collect(); + .map(|c| ConsumerChain::try_from(c).map_err(Error::ics24_host_validation_error)) + .collect::, _>>()?; Ok(result) } diff --git a/crates/relayer/src/chain/endpoint.rs b/crates/relayer/src/chain/endpoint.rs index 0a12e73341..5545f74966 100644 --- a/crates/relayer/src/chain/endpoint.rs +++ b/crates/relayer/src/chain/endpoint.rs @@ -1,6 +1,7 @@ use alloc::sync::Arc; use ibc_proto::ibc::core::channel::v1::{QueryUpgradeErrorRequest, QueryUpgradeRequest}; +use ibc_relayer_types::applications::ics28_ccv::msgs::ConsumerChain; use ibc_relayer_types::core::ics02_client::height::Height; use tokio::runtime::Runtime as TokioRuntime; @@ -688,7 +689,7 @@ pub trait ChainEndpoint: Sized { request: QueryIncentivizedPacketRequest, ) -> Result; - fn query_consumer_chains(&self) -> Result, Error>; + fn query_consumer_chains(&self) -> Result, Error>; fn query_upgrade( &self, diff --git a/crates/relayer/src/chain/handle.rs b/crates/relayer/src/chain/handle.rs index 2137821e61..466017c360 100644 --- a/crates/relayer/src/chain/handle.rs +++ b/crates/relayer/src/chain/handle.rs @@ -8,6 +8,7 @@ use ibc_proto::ibc::apps::fee::v1::{ QueryIncentivizedPacketRequest, QueryIncentivizedPacketResponse, }; use ibc_proto::ibc::core::channel::v1::{QueryUpgradeErrorRequest, QueryUpgradeRequest}; +use ibc_relayer_types::applications::ics28_ccv::msgs::ConsumerChain; use ibc_relayer_types::{ applications::ics31_icq::response::CrossChainQueryResponse, core::{ @@ -371,7 +372,7 @@ pub enum ChainRequest { }, QueryConsumerChains { - reply_to: ReplyTo>, + reply_to: ReplyTo>, }, QueryUpgrade { @@ -699,7 +700,7 @@ pub trait ChainHandle: Clone + Display + Send + Sync + Debug + 'static { request: QueryIncentivizedPacketRequest, ) -> Result; - fn query_consumer_chains(&self) -> Result, Error>; + fn query_consumer_chains(&self) -> Result, Error>; fn query_upgrade( &self, diff --git a/crates/relayer/src/chain/handle/base.rs b/crates/relayer/src/chain/handle/base.rs index 0898269281..d07595eb08 100644 --- a/crates/relayer/src/chain/handle/base.rs +++ b/crates/relayer/src/chain/handle/base.rs @@ -8,20 +8,20 @@ use ibc_proto::ibc::{ core::channel::v1::{QueryUpgradeErrorRequest, QueryUpgradeRequest}, }; use ibc_relayer_types::{ - applications::ics31_icq::response::CrossChainQueryResponse, + applications::{ics28_ccv::msgs::ConsumerChain, ics31_icq::response::CrossChainQueryResponse}, core::{ ics02_client::{events::UpdateClient, header::AnyHeader}, - ics03_connection::connection::{ConnectionEnd, IdentifiedConnectionEnd}, - ics03_connection::version::Version, - ics04_channel::channel::{ChannelEnd, IdentifiedChannelEnd}, + ics03_connection::{ + connection::{ConnectionEnd, IdentifiedConnectionEnd}, + version::Version, + }, ics04_channel::{ + channel::{ChannelEnd, IdentifiedChannelEnd}, packet::{PacketMsgType, Sequence}, upgrade::{ErrorReceipt, Upgrade}, }, ics23_commitment::{commitment::CommitmentPrefix, merkle::MerkleProof}, - ics24_host::identifier::ChainId, - ics24_host::identifier::ChannelId, - ics24_host::identifier::{ClientId, ConnectionId, PortId}, + ics24_host::identifier::{ChainId, ChannelId, ClientId, ConnectionId, PortId}, }, proofs::Proofs, signer::Signer, @@ -522,7 +522,7 @@ impl ChainHandle for BaseChainHandle { self.send(|reply_to| ChainRequest::QueryIncentivizedPacket { request, reply_to }) } - fn query_consumer_chains(&self) -> Result, Error> { + fn query_consumer_chains(&self) -> Result, Error> { self.send(|reply_to| ChainRequest::QueryConsumerChains { reply_to }) } diff --git a/crates/relayer/src/chain/handle/cache.rs b/crates/relayer/src/chain/handle/cache.rs index 6a1731f903..d5e481dac1 100644 --- a/crates/relayer/src/chain/handle/cache.rs +++ b/crates/relayer/src/chain/handle/cache.rs @@ -1,20 +1,21 @@ use core::fmt::{Display, Error as FmtError, Formatter}; use crossbeam_channel as channel; -use ibc_relayer_types::core::ics02_client::header::AnyHeader; -use ibc_relayer_types::core::ics04_channel::upgrade::ErrorReceipt; use tracing::Span; use ibc_proto::ibc::apps::fee::v1::QueryIncentivizedPacketRequest; use ibc_proto::ibc::apps::fee::v1::QueryIncentivizedPacketResponse; use ibc_proto::ibc::core::channel::v1::{QueryUpgradeErrorRequest, QueryUpgradeRequest}; +use ibc_relayer_types::applications::ics28_ccv::msgs::ConsumerChain; use ibc_relayer_types::applications::ics31_icq::response::CrossChainQueryResponse; use ibc_relayer_types::core::ics02_client::events::UpdateClient; +use ibc_relayer_types::core::ics02_client::header::AnyHeader; use ibc_relayer_types::core::ics03_connection::connection::ConnectionEnd; use ibc_relayer_types::core::ics03_connection::connection::IdentifiedConnectionEnd; use ibc_relayer_types::core::ics03_connection::version::Version; use ibc_relayer_types::core::ics04_channel::channel::ChannelEnd; use ibc_relayer_types::core::ics04_channel::channel::IdentifiedChannelEnd; use ibc_relayer_types::core::ics04_channel::packet::{PacketMsgType, Sequence}; +use ibc_relayer_types::core::ics04_channel::upgrade::ErrorReceipt; use ibc_relayer_types::core::ics04_channel::upgrade::Upgrade; use ibc_relayer_types::core::ics23_commitment::commitment::CommitmentPrefix; use ibc_relayer_types::core::ics23_commitment::merkle::MerkleProof; @@ -515,7 +516,7 @@ impl ChainHandle for CachingChainHandle { self.inner.query_incentivized_packet(request) } - fn query_consumer_chains(&self) -> Result, Error> { + fn query_consumer_chains(&self) -> Result, Error> { self.inner.query_consumer_chains() } diff --git a/crates/relayer/src/chain/handle/counting.rs b/crates/relayer/src/chain/handle/counting.rs index 1096e1b0bf..fc1e5e6516 100644 --- a/crates/relayer/src/chain/handle/counting.rs +++ b/crates/relayer/src/chain/handle/counting.rs @@ -3,13 +3,13 @@ use std::collections::HashMap; use std::sync::{Arc, RwLock, RwLockReadGuard}; use crossbeam_channel as channel; -use ibc_proto::ibc::core::channel::v1::{QueryUpgradeErrorRequest, QueryUpgradeRequest}; -use ibc_relayer_types::core::ics04_channel::upgrade::{ErrorReceipt, Upgrade}; use tracing::{debug, Span}; use ibc_proto::ibc::apps::fee::v1::{ QueryIncentivizedPacketRequest, QueryIncentivizedPacketResponse, }; +use ibc_proto::ibc::core::channel::v1::{QueryUpgradeErrorRequest, QueryUpgradeRequest}; +use ibc_relayer_types::applications::ics28_ccv::msgs::ConsumerChain; use ibc_relayer_types::applications::ics31_icq::response::CrossChainQueryResponse; use ibc_relayer_types::core::ics02_client::events::UpdateClient; use ibc_relayer_types::core::ics02_client::header::AnyHeader; @@ -19,6 +19,7 @@ use ibc_relayer_types::core::ics03_connection::version::Version; use ibc_relayer_types::core::ics04_channel::channel::ChannelEnd; use ibc_relayer_types::core::ics04_channel::channel::IdentifiedChannelEnd; use ibc_relayer_types::core::ics04_channel::packet::{PacketMsgType, Sequence}; +use ibc_relayer_types::core::ics04_channel::upgrade::{ErrorReceipt, Upgrade}; use ibc_relayer_types::core::ics23_commitment::commitment::CommitmentPrefix; use ibc_relayer_types::core::ics23_commitment::merkle::MerkleProof; use ibc_relayer_types::core::ics24_host::identifier::{ @@ -507,7 +508,7 @@ impl ChainHandle for CountingChainHandle { self.inner.query_incentivized_packet(request) } - fn query_consumer_chains(&self) -> Result, Error> { + fn query_consumer_chains(&self) -> Result, Error> { self.inc_metric("query_consumer_chains"); self.inner.query_consumer_chains() } diff --git a/crates/relayer/src/chain/runtime.rs b/crates/relayer/src/chain/runtime.rs index 1422f386b3..d19b544245 100644 --- a/crates/relayer/src/chain/runtime.rs +++ b/crates/relayer/src/chain/runtime.rs @@ -10,10 +10,9 @@ use ibc_proto::ibc::{ core::channel::v1::{QueryUpgradeErrorRequest, QueryUpgradeRequest}, }; use ibc_relayer_types::{ - applications::ics31_icq::response::CrossChainQueryResponse, + applications::{ics28_ccv::msgs::ConsumerChain, ics31_icq::response::CrossChainQueryResponse}, core::{ - ics02_client::events::UpdateClient, - ics02_client::header::AnyHeader, + ics02_client::{events::UpdateClient, header::AnyHeader}, ics03_connection::{ connection::{ConnectionEnd, IdentifiedConnectionEnd}, version::Version, @@ -24,7 +23,7 @@ use ibc_relayer_types::{ upgrade::{ErrorReceipt, Upgrade}, }, ics23_commitment::{commitment::CommitmentPrefix, merkle::MerkleProof}, - ics24_host::identifier::{ChainId, ChannelId, ClientId, ConnectionId, PortId}, + ics24_host::identifier::{ChannelId, ClientId, ConnectionId, PortId}, }, proofs::Proofs, signer::Signer, @@ -865,10 +864,7 @@ where Ok(()) } - fn query_consumer_chains( - &self, - reply_to: ReplyTo>, - ) -> Result<(), Error> { + fn query_consumer_chains(&self, reply_to: ReplyTo>) -> Result<(), Error> { let result = self.chain.query_consumer_chains(); reply_to.send(result).map_err(Error::send)?; diff --git a/crates/relayer/src/error.rs b/crates/relayer/src/error.rs index 6d46f90fe0..8fa5bd4847 100644 --- a/crates/relayer/src/error.rs +++ b/crates/relayer/src/error.rs @@ -30,6 +30,7 @@ use ibc_relayer_types::clients::ics07_tendermint::error as tendermint_error; use ibc_relayer_types::core::ics02_client::{client_type::ClientType, error as client_error}; use ibc_relayer_types::core::ics03_connection::error as connection_error; use ibc_relayer_types::core::ics23_commitment::error as commitment_error; +use ibc_relayer_types::core::ics24_host::error::ValidationError; use ibc_relayer_types::core::ics24_host::identifier::{ChainId, ChannelId, ConnectionId}; use ibc_relayer_types::proofs::ProofError; @@ -633,6 +634,10 @@ define_error! { InvalidChannelString { channel: String } |e| { format!("invalid channel string {}", e.channel) }, + + Ics24HostValidationError + [ ValidationError ] + |_| { "ICS24 host validation error" }, } } From e48ac980d9ceec1dd13d42ff5e1c08d191978131 Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Tue, 24 Sep 2024 17:54:30 +0200 Subject: [PATCH 13/17] Fix build --- tools/test-framework/src/relayer/chain.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/test-framework/src/relayer/chain.rs b/tools/test-framework/src/relayer/chain.rs index 7c68839d30..2f7bc5b441 100644 --- a/tools/test-framework/src/relayer/chain.rs +++ b/tools/test-framework/src/relayer/chain.rs @@ -23,6 +23,7 @@ use crossbeam_channel as channel; use ibc_proto::ibc::core::channel::v1::{QueryUpgradeErrorRequest, QueryUpgradeRequest}; use ibc_relayer::chain::cosmos::version::Specs; +use ibc_relayer_types::applications::ics28_ccv::msgs::ConsumerChain; use ibc_relayer_types::core::ics04_channel::upgrade::{ErrorReceipt, Upgrade}; use tracing::Span; @@ -434,7 +435,7 @@ where self.value().query_incentivized_packet(request) } - fn query_consumer_chains(&self) -> Result, Error> { + fn query_consumer_chains(&self) -> Result, Error> { self.value().query_consumer_chains() } From b018f60dca37c9a655ff65a09be1942809b6b65c Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Tue, 24 Sep 2024 18:12:40 +0200 Subject: [PATCH 14/17] Update double sign test on CI --- ci/misbehaviour-ics/consumer_gen.json | 0 ci/misbehaviour-ics/double_sign_test.sh | 477 +++++++++++++++--------- 2 files changed, 295 insertions(+), 182 deletions(-) delete mode 100644 ci/misbehaviour-ics/consumer_gen.json diff --git a/ci/misbehaviour-ics/consumer_gen.json b/ci/misbehaviour-ics/consumer_gen.json deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/ci/misbehaviour-ics/double_sign_test.sh b/ci/misbehaviour-ics/double_sign_test.sh index b569538586..dd879f1458 100644 --- a/ci/misbehaviour-ics/double_sign_test.sh +++ b/ci/misbehaviour-ics/double_sign_test.sh @@ -1,6 +1,10 @@ #!/bin/bash # shellcheck disable=2086,2004 +## Prerequisites: +# * ICS v6.x +# * Hermes v1.10.3+45a29cc00 + set -eu DEBUG=${DEBUG:-false} @@ -9,13 +13,6 @@ if [ "$DEBUG" = true ]; then set -x fi -# User balance of stake tokens -USER_COINS="100000000000stake" -# Amount of stake tokens staked -STAKE="100000000stake" -# Node IP address -NODE_IP="127.0.0.1" - # Home directory HOME_DIR="/tmp/hermes-ics-double-sign" @@ -25,11 +22,19 @@ if [ "$DEBUG" = true ]; then else HERMES_DEBUG="" fi + # Hermes config HERMES_CONFIG="$HOME_DIR/hermes.toml" # Hermes binary HERMES_BIN="cargo run -q --bin hermes -- $HERMES_DEBUG --config $HERMES_CONFIG" +# User balance of stake tokens +USER_COINS="100000000000stake" +# Amount of stake tokens staked +STAKE="100000000stake" +# Node IP address +NODE_IP="127.0.0.1" + # Validator moniker MONIKERS=("coordinator" "alice" "bob") LEAD_VALIDATOR_MONIKER="coordinator" @@ -51,13 +56,8 @@ CLIENT_BASEPORT=29220 # Clean start pkill -f interchain-security-pd &> /dev/null || true -pkill -f interchain-security-cd &> /dev/null || true -pkill -f hermes &> /dev/null || true sleep 1 - -mkdir -p "${HOME_DIR}" -rm -rf "${PROV_NODES_ROOT_DIR}" -rm -rf "${CONS_NODES_ROOT_DIR}" +rm -rf ${PROV_NODES_ROOT_DIR} # Let lead validator create genesis file LEAD_VALIDATOR_PROV_DIR=${PROV_NODES_ROOT_DIR}/provider-${LEAD_VALIDATOR_MONIKER} @@ -70,7 +70,6 @@ do MONIKER=${MONIKERS[$index]} # validator key PROV_KEY=${MONIKER}-key - PROV_KEY2=${MONIKER}-key2 # home directory of this validator on provider PROV_NODE_DIR=${PROV_NODES_ROOT_DIR}/provider-${MONIKER} @@ -80,16 +79,17 @@ do # Build genesis file and node directory structure interchain-security-pd init $MONIKER --chain-id provider --home ${PROV_NODE_DIR} - jq ".app_state.gov.params.voting_period = \"5s\" | .app_state.gov.params.expedited_voting_period = \"4s\" | .app_state.staking.params.unbonding_time = \"86400s\"" \ + jq ".app_state.gov.params.voting_period = \"10s\" \ + | .app_state.gov.params.expedited_voting_period = \"9s\" \ + | .app_state.staking.params.unbonding_time = \"86400s\" \ + | .app_state.provider.params.blocks_per_epoch = \"5\"" \ ${PROV_NODE_DIR}/config/genesis.json > \ ${PROV_NODE_DIR}/edited_genesis.json && mv ${PROV_NODE_DIR}/edited_genesis.json ${PROV_NODE_DIR}/config/genesis.json - sleep 1 # Create account keypair - interchain-security-pd keys add $PROV_KEY --home ${PROV_NODE_DIR} --keyring-backend test --output json > ${PROV_NODE_DIR}/${PROV_KEY}.json 2>&1 - interchain-security-pd keys add $PROV_KEY2 --home ${PROV_NODE_DIR} --keyring-backend test --output json > ${PROV_NODE_DIR}/${PROV_KEY2}.json 2>&1 + interchain-security-pd keys add $PROV_KEY --home ${PROV_NODE_DIR} --keyring-backend test --output json > ${PROV_NODE_DIR}/${PROV_KEY}.json 2>&1 sleep 1 # copy genesis in, unless this validator is the lead validator @@ -100,9 +100,6 @@ do # Add stake to user PROV_ACCOUNT_ADDR=$(jq -r '.address' ${PROV_NODE_DIR}/${PROV_KEY}.json) interchain-security-pd genesis add-genesis-account $PROV_ACCOUNT_ADDR $USER_COINS --home ${PROV_NODE_DIR} --keyring-backend test - - PROV_ACCOUNT_ADDR2=$(jq -r '.address' ${PROV_NODE_DIR}/${PROV_KEY2}.json) - interchain-security-pd genesis add-genesis-account $PROV_ACCOUNT_ADDR2 $USER_COINS --home ${PROV_NODE_DIR} --keyring-backend test sleep 1 # copy genesis out, unless this validator is the lead validator @@ -141,7 +138,7 @@ do fi # Stake 1/1000 user's coins - interchain-security-pd genesis gentx $PROV_KEY $STAKE --chain-id provider --home ${PROV_NODE_DIR} --keyring-backend test --moniker $MONIKER + interchain-security-pd genesis gentx $PROV_KEY $STAKE --chain-id provider --home ${PROV_NODE_DIR} --keyring-backend test --moniker $MONIKER sleep 1 # Copy gentxs to the lead validator for possible future collection. @@ -183,7 +180,6 @@ do # validator key PROV_KEY=${MONIKER}-key - PROV_KEY2=${MONIKER}-key2 # home directory of this validator on provider PROV_NODE_DIR=${PROV_NODES_ROOT_DIR}/provider-${MONIKER} @@ -219,65 +215,192 @@ do done # Build consumer chain proposal file -tee ${LEAD_VALIDATOR_PROV_DIR}/consumer-proposal.json< /dev/null || true +sleep 1 +rm -rf ${CONS_NODES_ROOT_DIR} + for index in "${!MONIKERS[@]}" do MONIKER=${MONIKERS[$index]} # validator key PROV_KEY=${MONIKER}-key - PROV_KEY2=${MONIKER}-key2 PROV_NODE_DIR=${PROV_NODES_ROOT_DIR}/provider-${MONIKER} @@ -285,13 +408,12 @@ do CONS_NODE_DIR=${CONS_NODES_ROOT_DIR}/consumer-${MONIKER} # Build genesis file and node directory structure - interchain-security-cd init $MONIKER --chain-id consumer --home ${CONS_NODE_DIR} + interchain-security-cd init $MONIKER --chain-id consumer --home ${CONS_NODE_DIR} sleep 1 # Create account keypair - interchain-security-cd keys add $PROV_KEY --home ${CONS_NODE_DIR} --keyring-backend test --output json > ${CONS_NODE_DIR}/${PROV_KEY}.json 2>&1 - interchain-security-cd keys add $PROV_KEY2 --home ${CONS_NODE_DIR} --keyring-backend test --output json > ${CONS_NODE_DIR}/${PROV_KEY2}.json 2>&1 + interchain-security-cd keys add $PROV_KEY --home ${CONS_NODE_DIR} --keyring-backend test --output json > ${CONS_NODE_DIR}/${PROV_KEY}.json 2>&1 sleep 1 # copy genesis in, unless this validator is the lead validator @@ -302,15 +424,15 @@ do # Add stake to user CONS_ACCOUNT_ADDR=$(jq -r '.address' ${CONS_NODE_DIR}/${PROV_KEY}.json) interchain-security-cd genesis add-genesis-account $CONS_ACCOUNT_ADDR $USER_COINS --home ${CONS_NODE_DIR} - CONS_ACCOUNT_ADDR2=$(jq -r '.address' ${CONS_NODE_DIR}/${PROV_KEY2}.json) - interchain-security-cd genesis add-genesis-account $CONS_ACCOUNT_ADDR2 $USER_COINS --home ${CONS_NODE_DIR} - sleep 10000 - ### this probably does not have to be done for each node + ### this probably doesnt have to be done for each node # Add consumer genesis states to genesis file RPC_LADDR_PORT=$(($RPC_LADDR_BASEPORT + $index)) RPC_LADDR=tcp://${NODE_IP}:${RPC_LADDR_PORT} - interchain-security-pd query provider consumer-genesis $CONSUMER_ID --home ${PROV_NODE_DIR} --node ${LEAD_PROV_LISTEN_ADDR} -o json > consumer_gen.json + interchain-security-pd query provider consumer-genesis $CONSUMER_ID \ + --home ${PROV_NODE_DIR} \ + --node ${RPC_LADDR} -o json > consumer_gen.json + jq -s '.[0].app_state.ccvconsumer = .[1] | .[0]' ${CONS_NODE_DIR}/config/genesis.json consumer_gen.json > ${CONS_NODE_DIR}/edited_genesis.json \ && mv ${CONS_NODE_DIR}/edited_genesis.json ${CONS_NODE_DIR}/config/genesis.json rm consumer_gen.json @@ -352,7 +474,6 @@ done sleep 1 - for index in "${!MONIKERS[@]}" do MONIKER=${MONIKERS[$index]} @@ -413,42 +534,13 @@ do sleep 6 done -## Cause double signing - -# create directory for double signing node -mkdir $CONS_NODES_ROOT_DIR/consumer-bob-sybil/ -cp -r $CONS_NODES_ROOT_DIR/consumer-bob/* $CONS_NODES_ROOT_DIR/consumer-bob-sybil - -# clear state in consumer-bob-sybil -echo '{"height": "0","round": 0,"step": 0,"signature":"","signbytes":""}' > $CONS_NODES_ROOT_DIR/consumer-bob-sybil/data/priv_validator_state.json +## Setup Hermes -# add new node key to sybil -# key was generated using gaiad init -# if the node key is not unique, double signing cannot be achieved -# and errors such as this can be seen in the terminal -# 5:54PM ERR found conflicting vote from ourselves; did you unsafe_reset a validator? height=1961 module=consensus round=0 type=2 -# 5:54PM ERR failed to process message err="conflicting votes from validator C888306A908A217B9A943D1DAD8790044D0947A4" -echo '{"priv_key":{"type":"tendermint/PrivKeyEd25519","value":"tj55by/yYwruSz4NxsOG9y9k2WrPvKLXKQdz/9jL9Uptmi647OYpcisjwf92TyA+wCUYVDOgW7D53Q+638l9/w=="}}' > $CONS_NODES_ROOT_DIR/consumer-bob-sybil/config/node_key.json - -# does not use persistent peers; will do a lookup in genesis.json to find peers -#ARGS="--address tcp://$CHAIN_PREFIX.252:26655 --rpc.laddr tcp://$CHAIN_PREFIX.252:26658 --grpc.address $CHAIN_PREFIX.252:9091 --log_level trace --p2p.laddr tcp://$CHAIN_PREFIX.252:26656 --grpc-web.enable=false" - -# start double signing node - it should not talk to the node with the same key -#ip netns exec $HOME/nodes/consumer/consumer-bob-sybil $BIN $ARGS --home $HOME/nodes/consumer/consumer-bob-sybil start &> $HOME/nodes/consumer/consumer-bob-sybil/logs & - -# Start gaia -interchain-security-cd start \ - --home $CONS_NODES_ROOT_DIR/consumer-bob-sybil \ - --p2p.persistent_peers ${PERSISTENT_PEERS} \ - --rpc.laddr tcp://${NODE_IP}:29179 \ - --grpc.address ${NODE_IP}:29199 \ - --address tcp://${NODE_IP}:29209 \ - --p2p.laddr tcp://${NODE_IP}:29189 \ - --grpc-web.enable=false &> $CONS_NODES_ROOT_DIR/consumer-bob-sybil/logs & - -# Setup Hermes config file +HERMES_PROV_NODE_DIR=${PROV_NODES_ROOT_DIR}/provider-${HERMES_VALIDATOR_MONIKER} +HERMES_KEY=${HERMES_VALIDATOR_MONIKER}-key +HERMES_CONS_NODE_DIR=${CONS_NODES_ROOT_DIR}/consumer-${HERMES_VALIDATOR_MONIKER} -tee $HERMES_CONFIG< $HOME_DIR/hermes-start-logs.txt & +sleep 5 -$HERMES_BIN evidence --chain consumer --key-name evidence &> $HOME_DIR/hermes-evidence-logs.txt & +## Cause double signing + +CONS_NODE_SYBIL_DIR=${CONS_NODES_ROOT_DIR}/consumer-${MONIKER}-sybil + +# create directory for double signing node +mkdir $CONS_NODE_SYBIL_DIR +cp -r $CONS_NODE_DIR/* $CONS_NODE_SYBIL_DIR + +# clear state in sybil node directory +echo '{"height": "0","round": 0,"step": 0,"signature":"","signbytes":""}' \ + > $CONS_NODE_SYBIL_DIR/data/priv_validator_state.json + +# add new node key to sybil +# key was generated using gaiad init +# if the node key is not unique, double signing cannot be achieved +# and errors such as this can be seen in the terminal +# 5:54PM ERR found conflicting vote from ourselves; did you unsafe_reset a validator? height=1961 module=consensus round=0 type=2 +# 5:54PM ERR failed to process message err="conflicting votes from validator C888306A908A217B9A943D1DAD8790044D0947A4" +echo '{"priv_key":{"type":"tendermint/PrivKeyEd25519","value":"tj55by/yYwruSz4NxsOG9y9k2WrPvKLXKQdz/9jL9Uptmi647OYpcisjwf92TyA+wCUYVDOgW7D53Q+638l9/w=="}}' \ + > $CONS_NODE_SYBIL_DIR/config/node_key.json + +# does not use persistent peers; will do a lookup in genesis.json to find peers +# start double signing node - it should not talk to the node with the same key + +# Start gaia +interchain-security-cd start \ + --home ${CONS_NODE_SYBIL_DIR} \ + --rpc.laddr tcp://${NODE_IP}:$((RPC_LADDR_PORT+1)) \ + --grpc.address ${NODE_IP}:$((GRPC_LADDR_PORT+1)) \ + --address tcp://${NODE_IP}:$((NODE_ADDRESS_PORT+1)) \ + --p2p.laddr tcp://${NODE_IP}:$((P2P_LADDR_PORT+1)) \ + --grpc-web.enable=false &> ${CONS_NODE_SYBIL_DIR}/logs & + +sleep 5 + +## start Hermes in evidence mode +$HERMES_BIN evidence --chain consumer --check-past-blocks 0 &> $HOME_DIR/hermes-evidence-logs.txt & + +sleep 1 + +# Wait for Hermes to submit double signing evidence +$HERMES_BIN update client --host-chain consumer --client 07-tendermint-0 for _ in $(seq 1 10) do @@ -576,9 +692,6 @@ done echo "[ERROR] Failed to submit double voting evidence to provider chain" echo "" echo "---------------------------------------------------------------" -echo "Hermes start logs:" -cat $HOME_DIR/hermes-start-logs.txt -echo "---------------------------------------------------------------" echo "Hermes evidence logs:" cat $HOME_DIR/hermes-evidence-logs.txt echo "---------------------------------------------------------------" From 205fe350c1ea2a441023b2968875efbac24b79af Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Tue, 24 Sep 2024 18:15:03 +0200 Subject: [PATCH 15/17] Skip localhost clients --- crates/relayer-cli/src/commands/evidence.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/relayer-cli/src/commands/evidence.rs b/crates/relayer-cli/src/commands/evidence.rs index 020d7a4713..30a9dbe069 100644 --- a/crates/relayer-cli/src/commands/evidence.rs +++ b/crates/relayer-cli/src/commands/evidence.rs @@ -741,6 +741,11 @@ fn fetch_all_counterparty_clients( connection.connection_id ); + if client_id.as_str() == "09-localhost" { + debug!("skipping localhost client `{client_id}`..."); + continue; + } + debug!( "fetching client state for client `{client_id}` on connection `{}`", connection.connection_id From ff81b93a63ac02159843dfc20a68b7558eee135c Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Wed, 16 Oct 2024 13:13:52 +0200 Subject: [PATCH 16/17] Codespell fix --- ci/misbehaviour-ics/double_sign_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/misbehaviour-ics/double_sign_test.sh b/ci/misbehaviour-ics/double_sign_test.sh index dd879f1458..83f5c2609f 100644 --- a/ci/misbehaviour-ics/double_sign_test.sh +++ b/ci/misbehaviour-ics/double_sign_test.sh @@ -425,7 +425,7 @@ do CONS_ACCOUNT_ADDR=$(jq -r '.address' ${CONS_NODE_DIR}/${PROV_KEY}.json) interchain-security-cd genesis add-genesis-account $CONS_ACCOUNT_ADDR $USER_COINS --home ${CONS_NODE_DIR} - ### this probably doesnt have to be done for each node + ### this probably does not have to be done for each node # Add consumer genesis states to genesis file RPC_LADDR_PORT=$(($RPC_LADDR_BASEPORT + $index)) RPC_LADDR=tcp://${NODE_IP}:${RPC_LADDR_PORT} From a75f0316b765c7df51e72354256d8b082089f21a Mon Sep 17 00:00:00 2001 From: Luca Joss Date: Wed, 16 Oct 2024 13:21:14 +0200 Subject: [PATCH 17/17] Fix error post merge --- crates/relayer/src/chain/cosmos.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/relayer/src/chain/cosmos.rs b/crates/relayer/src/chain/cosmos.rs index ff6ed259fb..4dc9abdd5a 100644 --- a/crates/relayer/src/chain/cosmos.rs +++ b/crates/relayer/src/chain/cosmos.rs @@ -2853,7 +2853,7 @@ pub async fn query_ccv_consumer_id( let grpc_addr = Uri::from_str(&config.grpc_addr.to_string()) .map_err(|e| Error::invalid_uri(config.grpc_addr.to_string(), e))?; - let mut client = create_grpc_client(grpc_addr, QueryClient::new) + let mut client = create_grpc_client(&grpc_addr, QueryClient::new) .await? .max_decoding_message_size(config.max_grpc_decoding_size.get_bytes() as usize);