Skip to content

Commit

Permalink
Bulk change of tendermint impots to cometbft
Browse files Browse the repository at this point in the history
Had to augment some IBC data structures due to changes in protos.
  • Loading branch information
mzabaluev committed Feb 28, 2024
1 parent b63a035 commit f0b4bc9
Show file tree
Hide file tree
Showing 31 changed files with 79 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use cometbft_light_client_verifier::Verifier;
use ibc_client_tendermint_types::error::{Error, IntoResult};
use ibc_client_tendermint_types::{Header as TmHeader, Misbehaviour as TmMisbehaviour};
use ibc_core_client::types::error::ClientError;
use ibc_core_host::types::identifiers::ClientId;
use ibc_core_host::types::path::ClientConsensusStatePath;
use ibc_primitives::prelude::*;
use ibc_primitives::Timestamp;
use tendermint_light_client_verifier::Verifier;

use super::{ClientState as TmClientState, TmValidationContext};
use crate::consensus_state::ConsensusState as TmConsensusState;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use cometbft_light_client_verifier::types::{TrustedBlockState, UntrustedBlockState};
use cometbft_light_client_verifier::Verifier;
use ibc_client_tendermint_types::error::{Error, IntoResult};
use ibc_client_tendermint_types::{ConsensusState as ConsensusStateType, Header as TmHeader};
use ibc_core_client::context::ClientExecutionContext;
use ibc_core_client::types::error::ClientError;
use ibc_core_host::types::identifiers::ClientId;
use ibc_core_host::types::path::ClientConsensusStatePath;
use ibc_primitives::prelude::*;
use tendermint_light_client_verifier::types::{TrustedBlockState, UntrustedBlockState};
use tendermint_light_client_verifier::Verifier;

use super::ClientState;
use crate::consensus_state::ConsensusState as TmConsensusState;
Expand Down
6 changes: 3 additions & 3 deletions ibc-clients/ics07-tendermint/src/consensus_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//! implementations that serve to pass through traits implemented on the wrapped
//! `ConsensusState` type.
use cometbft::{block, Hash, Time};
use ibc_client_tendermint_types::error::Error;
use ibc_client_tendermint_types::proto::v1::ConsensusState as RawTmConsensusState;
use ibc_client_tendermint_types::ConsensusState as ConsensusStateType;
Expand All @@ -15,7 +16,6 @@ use ibc_core_commitment_types::commitment::CommitmentRoot;
use ibc_primitives::prelude::*;
use ibc_primitives::proto::{Any, Protobuf};
use ibc_primitives::Timestamp;
use tendermint::{Hash, Time};

/// Newtype wrapper around the `ConsensusState` type imported from the
/// `ibc-client-tendermint-types` crate. This wrapper exists so that we can
Expand Down Expand Up @@ -77,8 +77,8 @@ impl From<ConsensusState> for Any {
}
}

impl From<tendermint::block::Header> for ConsensusState {
fn from(header: tendermint::block::Header) -> Self {
impl From<block::Header> for ConsensusState {
fn from(header: block::Header) -> Self {
Self(ConsensusStateType::from(header))
}
}
Expand Down
10 changes: 5 additions & 5 deletions ibc-clients/ics07-tendermint/types/src/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ use core::cmp::max;
use core::str::FromStr;
use core::time::Duration;

use cometbft::chain::id::MAX_LENGTH as MaxChainIdLen;
use cometbft::trust_threshold::TrustThresholdFraction as TendermintTrustThresholdFraction;
use cometbft_light_client_verifier::options::Options;
use cometbft_light_client_verifier::ProdVerifier;
use ibc_core_client_types::error::ClientError;
use ibc_core_client_types::proto::v1::Height as RawHeight;
use ibc_core_client_types::Height;
Expand All @@ -14,10 +18,6 @@ use ibc_primitives::ZERO_DURATION;
use ibc_proto::google::protobuf::Any;
use ibc_proto::ibc::lightclients::tendermint::v1::ClientState as RawTmClientState;
use ibc_proto::Protobuf;
use tendermint::chain::id::MAX_LENGTH as MaxChainIdLen;
use tendermint::trust_threshold::TrustThresholdFraction as TendermintTrustThresholdFraction;
use tendermint_light_client_verifier::options::Options;
use tendermint_light_client_verifier::ProdVerifier;

use crate::error::Error;
use crate::header::Header as TmHeader;
Expand Down Expand Up @@ -377,9 +377,9 @@ impl From<ClientState> for Any {

#[cfg(all(test, feature = "serde"))]
pub(crate) mod serde_tests {
use cometbft_rpc::endpoint::abci_query::AbciQuery;
use serde::de::DeserializeOwned;
use serde::Serialize;
use tendermint_rpc::endpoint::abci_query::AbciQuery;

pub fn test_serialization_roundtrip<T>(json_data: &str)
where
Expand Down
15 changes: 8 additions & 7 deletions ibc-clients/ics07-tendermint/types/src/consensus_state.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
//! Defines Tendermint's `ConsensusState` type
use cometbft::block;
use cometbft::hash::Algorithm;
use cometbft::time::Time;
use cometbft::Hash;
use cometbft_proto::google::protobuf as tpb;
use ibc_core_client_types::error::ClientError;
use ibc_core_commitment_types::commitment::CommitmentRoot;
use ibc_primitives::prelude::*;
use ibc_proto::google::protobuf::Any;
use ibc_proto::ibc::lightclients::tendermint::v1::ConsensusState as RawConsensusState;
use ibc_proto::Protobuf;
use tendermint::hash::Algorithm;
use tendermint::time::Time;
use tendermint::Hash;
use tendermint_proto::google::protobuf as tpb;

use crate::error::Error;
use crate::header::Header;
Expand Down Expand Up @@ -132,8 +133,8 @@ impl From<ConsensusState> for Any {
}
}

impl From<tendermint::block::Header> for ConsensusState {
fn from(header: tendermint::block::Header) -> Self {
impl From<block::Header> for ConsensusState {
fn from(header: block::Header) -> Self {
Self {
root: CommitmentRoot::from_bytes(header.app_hash.as_ref()),
timestamp: header.time,
Expand All @@ -150,7 +151,7 @@ impl From<Header> for ConsensusState {

#[cfg(all(test, feature = "serde"))]
mod tests {
use tendermint_rpc::endpoint::abci_query::AbciQuery;
use cometbft_rpc::endpoint::abci_query::AbciQuery;

use crate::serde_tests::test_serialization_roundtrip;

Expand Down
8 changes: 4 additions & 4 deletions ibc-clients/ics07-tendermint/types/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
use core::time::Duration;

use cometbft::{Error as TendermintError, Hash};
use cometbft_light_client_verifier::errors::VerificationErrorDetail as LightClientErrorDetail;
use cometbft_light_client_verifier::operations::VotingPowerTally;
use cometbft_light_client_verifier::Verdict;
use displaydoc::Display;
use ibc_core_client_types::error::ClientError;
use ibc_core_client_types::Height;
use ibc_core_host_types::error::IdentifierError;
use ibc_core_host_types::identifiers::ClientId;
use ibc_primitives::prelude::*;
use tendermint::{Error as TendermintError, Hash};
use tendermint_light_client_verifier::errors::VerificationErrorDetail as LightClientErrorDetail;
use tendermint_light_client_verifier::operations::VotingPowerTally;
use tendermint_light_client_verifier::Verdict;

/// The main error type
#[derive(Debug, Display)]
Expand Down
8 changes: 4 additions & 4 deletions ibc-clients/ics07-tendermint/types/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
use core::fmt::{Display, Error as FmtError, Formatter};
use core::str::FromStr;

use cometbft::block::signed_header::SignedHeader;
use cometbft::chain::Id as TmChainId;
use cometbft::validator::Set as ValidatorSet;
use cometbft_light_client_verifier::types::{TrustedBlockState, UntrustedBlockState};
use ibc_core_client_types::error::ClientError;
use ibc_core_client_types::Height;
use ibc_core_host_types::identifiers::ChainId;
Expand All @@ -12,10 +16,6 @@ use ibc_proto::google::protobuf::Any;
use ibc_proto::ibc::lightclients::tendermint::v1::Header as RawHeader;
use ibc_proto::Protobuf;
use pretty::{PrettySignedHeader, PrettyValidatorSet};
use tendermint::block::signed_header::SignedHeader;
use tendermint::chain::Id as TmChainId;
use tendermint::validator::Set as ValidatorSet;
use tendermint_light_client_verifier::types::{TrustedBlockState, UntrustedBlockState};

use crate::consensus_state::ConsensusState as TmConsensusState;
use crate::error::Error;
Expand Down
2 changes: 1 addition & 1 deletion ibc-clients/ics07-tendermint/types/src/trust_threshold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
use core::fmt::{Display, Error as FmtError, Formatter};

use cometbft::trust_threshold::TrustThresholdFraction;
use ibc_core_client_types::error::ClientError;
use ibc_proto::ibc::lightclients::tendermint::v1::Fraction;
use ibc_proto::Protobuf;
use tendermint::trust_threshold::TrustThresholdFraction;

/// [`TrustThreshold`] defines the level of trust that a client has
/// towards a set of validators of a chain.
Expand Down
2 changes: 1 addition & 1 deletion ibc-core/ics02-client/types/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Types for the IBC events emitted from Tendermint Websocket by the client module.
use cometbft::abci;
use derive_more::From;
use ibc_core_host_types::identifiers::{ClientId, ClientType};
use ibc_primitives::prelude::*;
use subtle_encoding::hex;
use tendermint::abci;

use crate::height::Height;

Expand Down
4 changes: 2 additions & 2 deletions ibc-core/ics03-connection/types/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Types for the IBC events emitted from Tendermint Websocket by the connection module.
use cometbft::abci;
use ibc_core_host_types::identifiers::{ClientId, ConnectionId};
use ibc_primitives::prelude::*;
use tendermint::abci;

/// Connection event types
const CONNECTION_OPEN_INIT_EVENT: &str = "connection_open_init";
Expand Down Expand Up @@ -307,8 +307,8 @@ mod tests {

use core::str::FromStr;

use cometbft::abci::Event as AbciEvent;
use ibc_core_host_types::identifiers::ClientType;
use tendermint::abci::Event as AbciEvent;

use super::*;

Expand Down
9 changes: 8 additions & 1 deletion ibc-core/ics04-channel/types/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ impl TryFrom<RawIdentifiedChannel> for IdentifiedChannelEnd {
counterparty: value.counterparty,
connection_hops: value.connection_hops,
version: value.version,
upgrade_sequence: value.upgrade_sequence,
};

Ok(IdentifiedChannelEnd {
Expand All @@ -83,6 +84,7 @@ impl From<IdentifiedChannelEnd> for RawIdentifiedChannel {
version: value.channel_end.version.to_string(),
port_id: value.port_id.to_string(),
channel_id: value.channel_id.to_string(),
upgrade_sequence: value.channel_end.upgrade_sequence,
}
}
}
Expand All @@ -108,6 +110,8 @@ pub struct ChannelEnd {
pub remote: Counterparty,
pub connection_hops: Vec<ConnectionId>,
pub version: Version,
// FIXME: model with a domain type
pub upgrade_sequence: u64,
}

impl Display for ChannelEnd {
Expand Down Expand Up @@ -161,6 +165,7 @@ impl From<ChannelEnd> for RawChannel {
.map(|v| v.as_str().to_string())
.collect(),
version: value.version.to_string(),
upgrade_sequence: value.upgrade_sequence,
}
}
}
Expand All @@ -177,13 +182,15 @@ impl ChannelEnd {
remote: Counterparty,
connection_hops: Vec<ConnectionId>,
version: Version,
upgrade_sequence: u64,
) -> Self {
Self {
state,
ordering,
remote,
connection_hops,
version,
upgrade_sequence,
}
}

Expand All @@ -196,7 +203,7 @@ impl ChannelEnd {
version: Version,
) -> Result<Self, ChannelError> {
let channel_end =
Self::new_without_validation(state, ordering, remote, connection_hops, version);
Self::new_without_validation(state, ordering, remote, connection_hops, version, 0);
channel_end.validate_basic()?;
Ok(channel_end)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! This module holds all the abci event attributes for IBC events emitted
//! during the channel handshake.
use cometbft::abci;
use derive_more::From;
use ibc_core_host_types::identifiers::{ChannelId, ConnectionId, PortId};
use tendermint::abci;

use crate::Version;

Expand Down
4 changes: 2 additions & 2 deletions ibc-core/ics04-channel/types/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
mod channel_attributes;
mod packet_attributes;

use cometbft::abci;
use ibc_core_host_types::identifiers::{ChannelId, ConnectionId, PortId, Sequence};
use ibc_primitives::prelude::*;
use ibc_primitives::Timestamp;
use tendermint::abci;

use self::channel_attributes::{
ChannelIdAttribute, ConnectionIdAttribute, CounterpartyChannelIdAttribute,
Expand Down Expand Up @@ -1118,7 +1118,7 @@ impl TryFrom<TimeoutPacket> for abci::Event {

#[cfg(test)]
mod tests {
use tendermint::abci::Event as AbciEvent;
use cometbft::abci::Event as AbciEvent;

use super::*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
//!
use core::str;

use cometbft::abci;
use derive_more::From;
use ibc_core_host_types::identifiers::{ChannelId, ConnectionId, PortId, Sequence};
use ibc_primitives::prelude::*;
use ibc_primitives::Timestamp;
use subtle_encoding::hex;
use tendermint::abci;

use crate::acknowledgement::Acknowledgement;
use crate::channel::Order;
Expand Down
4 changes: 4 additions & 0 deletions ibc-core/ics04-channel/types/src/msgs/chan_close_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub struct MsgChannelCloseConfirm {
pub proof_chan_end_on_a: CommitmentProofBytes,
pub proof_height_on_a: Height,
pub signer: Signer,
// FIXME: model with a domain type
pub counterparty_upgrade_sequence: u64,
}

impl Protobuf<RawMsgChannelCloseConfirm> for MsgChannelCloseConfirm {}
Expand All @@ -47,6 +49,7 @@ impl TryFrom<RawMsgChannelCloseConfirm> for MsgChannelCloseConfirm {
.and_then(|raw_height| raw_height.try_into().ok())
.ok_or(ChannelError::MissingHeight)?,
signer: raw_msg.signer.into(),
counterparty_upgrade_sequence: raw_msg.counterparty_upgrade_sequence,
})
}
}
Expand All @@ -59,6 +62,7 @@ impl From<MsgChannelCloseConfirm> for RawMsgChannelCloseConfirm {
proof_init: domain_msg.proof_chan_end_on_a.clone().into(),
proof_height: Some(domain_msg.proof_height_on_a.into()),
signer: domain_msg.signer.to_string(),
counterparty_upgrade_sequence: domain_msg.counterparty_upgrade_sequence,
}
}
}
1 change: 1 addition & 0 deletions ibc-core/ics04-channel/types/src/msgs/chan_open_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ impl From<MsgChannelOpenInit> for RawMsgChannelOpenInit {
Counterparty::new(domain_msg.port_id_on_b, None),
domain_msg.connection_hops_on_a,
domain_msg.version_proposal,
0,
);
RawMsgChannelOpenInit {
port_id: domain_msg.port_id_on_a.to_string(),
Expand Down
1 change: 1 addition & 0 deletions ibc-core/ics04-channel/types/src/msgs/chan_open_try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl From<MsgChannelOpenTry> for RawMsgChannelOpenTry {
Counterparty::new(domain_msg.port_id_on_a, Some(domain_msg.chan_id_on_a)),
domain_msg.connection_hops_on_b,
Version::empty(), // Excessive field to satisfy the type conversion
0,
);
#[allow(deprecated)]
RawMsgChannelOpenTry {
Expand Down
4 changes: 4 additions & 0 deletions ibc-core/ics04-channel/types/src/msgs/timeout_on_close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub struct MsgTimeoutOnClose {
pub proof_close_on_b: CommitmentProofBytes,
pub proof_height_on_b: Height,
pub signer: Signer,
// FIXME: model with a domain type
pub counterparty_upgrade_sequence: u64,
}

impl Protobuf<RawMsgTimeoutOnClose> for MsgTimeoutOnClose {}
Expand Down Expand Up @@ -58,6 +60,7 @@ impl TryFrom<RawMsgTimeoutOnClose> for MsgTimeoutOnClose {
.and_then(|raw_height| raw_height.try_into().ok())
.ok_or(PacketError::MissingHeight)?,
signer: raw_msg.signer.into(),
counterparty_upgrade_sequence: raw_msg.counterparty_upgrade_sequence,
})
}
}
Expand All @@ -71,6 +74,7 @@ impl From<MsgTimeoutOnClose> for RawMsgTimeoutOnClose {
proof_height: Some(domain_msg.proof_height_on_b.into()),
next_sequence_recv: domain_msg.next_seq_recv_on_b.into(),
signer: domain_msg.signer.to_string(),
counterparty_upgrade_sequence: domain_msg.counterparty_upgrade_sequence,
}
}
}
2 changes: 1 addition & 1 deletion ibc-core/ics24-host/cosmos/src/upgrade_proposal/events.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Definitions of events emitted when an upgrade client is proposed or executed.
use cometbft::abci;
use derive_more::From;
use ibc_primitives::prelude::*;
use tendermint::abci;

const UPGRADE_CHAIN_EVENT: &str = "upgrade_chain";
const UPGRADE_CLIENT_PROPOSAL_EVENT: &str = "upgrade_client_proposal";
Expand Down
Loading

0 comments on commit f0b4bc9

Please sign in to comment.