Skip to content

Commit

Permalink
deps: upgrade ibc-proto-rs to 0.42.2 (#1125)
Browse files Browse the repository at this point in the history
* ibc-proto v0.42.1

* handle new data fields

* impl new service methods

* new mock client header in testkit

* update fixtures with new fields

* patch crates-io release

* refactor MockClientState methods

* chore: set ibc-proto-rs to v0.42.2

* chore: add changelog

* fix: make fmt happy

---------

Co-authored-by: Farhad Shabani <[email protected]>
  • Loading branch information
rnbguy and Farhad-Shabani authored Mar 14, 2024
1 parent 5e7ff8e commit 3b11b12
Show file tree
Hide file tree
Showing 16 changed files with 107 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [ibc] Upgrade `ibc-proto-rs` to `v0.42.2`
([\#1125](https://github.com/cosmos/ibc-rs/pull/1125))
6 changes: 3 additions & 3 deletions .changelog/unreleased/breaking-changes/973-update-meta.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- Merge client update time and height modification method pairs into
one, that is replace
- [ibc-core-client] Merge client update time and height modification method
pairs into one, that is replace
a) client_update_{time,height} by update_meta,
b) store_update_{time,height} by store_update_meta and
c) delete_update_{time,height} by delete_update_meta.
([\#972](https://github.com/cosmos/ibc-rs/pull/972))
([\#973](https://github.com/cosmos/ibc-rs/issues/973))
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
- [types] Refactor `Default` implementations with concrete names
- [ibc-data-types] Refactor `Default` implementations with concrete names
([\#1074](https://github.com/cosmos/ibc-rs/issues/1074))
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ ibc-client-wasm-types = { version = "0.50.0", path = "./ibc-clients/ics08-
ibc-app-transfer-types = { version = "0.50.0", path = "./ibc-apps/ics20-transfer/types", default-features = false }
ibc-app-nft-transfer-types = { version = "0.50.0", path = "./ibc-apps/ics721-nft-transfer/types", default-features = false }

ibc-proto = { version = "0.41.0", default-features = false }
ibc-proto = { version = "0.42.2", default-features = false }

# cosmos dependencies
tendermint = { version = "0.34.0", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions ci/cw-check/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ci/no-std-check/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ci/no-std-check/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resolver = "2"

[dependencies]
ibc = { path = "../../ibc", default-features = false, features = ["serde"] }
ibc-proto = { version = "0.41.0", default-features = false, features = [
ibc-proto = { version = "0.42.2", default-features = false, features = [
"parity-scale-codec",
"borsh",
"serde",
Expand Down
7 changes: 7 additions & 0 deletions ibc-core/ics04-channel/types/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,17 @@ impl TryFrom<RawIdentifiedChannel> for IdentifiedChannelEnd {
type Error = ChannelError;

fn try_from(value: RawIdentifiedChannel) -> Result<Self, Self::Error> {
if value.upgrade_sequence != 0 {
return Err(ChannelError::UnsupportedChannelUpgradeSequence);
}

let raw_channel_end = RawChannel {
state: value.state,
ordering: value.ordering,
counterparty: value.counterparty,
connection_hops: value.connection_hops,
version: value.version,
upgrade_sequence: value.upgrade_sequence,
};

Ok(IdentifiedChannelEnd {
Expand All @@ -83,6 +88,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: 0,
}
}
}
Expand Down Expand Up @@ -161,6 +167,7 @@ impl From<ChannelEnd> for RawChannel {
.map(|v| v.as_str().to_string())
.collect(),
version: value.version.to_string(),
upgrade_sequence: 0,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions ibc-core/ics04-channel/types/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub enum ChannelError {
NonUtf8PacketData,
/// missing counterparty
MissingCounterparty,
/// unsupported channel upgrade sequence
UnsupportedChannelUpgradeSequence,
/// version not supported: expected `{expected}`, actual `{actual}`
VersionNotSupported { expected: Version, actual: Version },
/// missing channel end
Expand Down
5 changes: 5 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 @@ -35,6 +35,10 @@ impl TryFrom<RawMsgChannelCloseConfirm> for MsgChannelCloseConfirm {
type Error = ChannelError;

fn try_from(raw_msg: RawMsgChannelCloseConfirm) -> Result<Self, Self::Error> {
if raw_msg.counterparty_upgrade_sequence != 0 {
return Err(ChannelError::UnsupportedChannelUpgradeSequence);
}

Ok(MsgChannelCloseConfirm {
port_id_on_b: raw_msg.port_id.parse()?,
chan_id_on_b: raw_msg.channel_id.parse()?,
Expand All @@ -59,6 +63,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: 0,
}
}
}
9 changes: 8 additions & 1 deletion ibc-core/ics04-channel/types/src/msgs/timeout_on_close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ibc_primitives::Signer;
use ibc_proto::ibc::core::channel::v1::MsgTimeoutOnClose as RawMsgTimeoutOnClose;
use ibc_proto::Protobuf;

use crate::error::PacketError;
use crate::error::{ChannelError, PacketError};
use crate::packet::Packet;

pub const TIMEOUT_ON_CLOSE_TYPE_URL: &str = "/ibc.core.channel.v1.MsgTimeoutOnClose";
Expand Down Expand Up @@ -39,6 +39,12 @@ impl TryFrom<RawMsgTimeoutOnClose> for MsgTimeoutOnClose {
return Err(PacketError::ZeroPacketSequence);
}

if raw_msg.counterparty_upgrade_sequence != 0 {
return Err(PacketError::Channel(
ChannelError::UnsupportedChannelUpgradeSequence,
));
}

Ok(MsgTimeoutOnClose {
packet: raw_msg
.packet
Expand Down Expand Up @@ -71,6 +77,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: 0,
}
}
}
31 changes: 30 additions & 1 deletion ibc-query/src/core/channel/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use ibc_proto::google::protobuf::Any;
use ibc_proto::ibc::core::channel::v1::query_server::Query as ChannelQuery;
use ibc_proto::ibc::core::channel::v1::{
QueryChannelClientStateRequest, QueryChannelClientStateResponse,
QueryChannelConsensusStateRequest, QueryChannelConsensusStateResponse, QueryChannelRequest,
QueryChannelConsensusStateRequest, QueryChannelConsensusStateResponse,
QueryChannelParamsRequest, QueryChannelParamsResponse, QueryChannelRequest,
QueryChannelResponse, QueryChannelsRequest, QueryChannelsResponse,
QueryConnectionChannelsRequest, QueryConnectionChannelsResponse,
QueryNextSequenceReceiveRequest, QueryNextSequenceReceiveResponse,
Expand All @@ -18,6 +19,7 @@ use ibc_proto::ibc::core::channel::v1::{
QueryPacketCommitmentResponse, QueryPacketCommitmentsRequest, QueryPacketCommitmentsResponse,
QueryPacketReceiptRequest, QueryPacketReceiptResponse, QueryUnreceivedAcksRequest,
QueryUnreceivedAcksResponse, QueryUnreceivedPacketsRequest, QueryUnreceivedPacketsResponse,
QueryUpgradeErrorRequest, QueryUpgradeErrorResponse, QueryUpgradeRequest, QueryUpgradeResponse,
};
use tonic::{Request, Response, Status};

Expand Down Expand Up @@ -188,4 +190,31 @@ where

Ok(Response::new(response))
}

async fn upgrade_error(
&self,
_request: Request<QueryUpgradeErrorRequest>,
) -> Result<Response<QueryUpgradeErrorResponse>, Status> {
Err(Status::unimplemented(
"Querying UpgradeError is not supported yet",
))
}

async fn upgrade(
&self,
_request: Request<QueryUpgradeRequest>,
) -> Result<Response<QueryUpgradeResponse>, Status> {
Err(Status::unimplemented(
"Querying Upgrade is not supported yet",
))
}

async fn channel_params(
&self,
_request: Request<QueryChannelParamsRequest>,
) -> Result<Response<QueryChannelParamsResponse>, Status> {
Err(Status::unimplemented(
"Querying ChannelParams is not supported yet",
))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub fn dummy_raw_msg_chan_close_confirm(proof_height: u64) -> RawMsgChannelClose
revision_height: proof_height,
}),
signer: dummy_bech32_account(),
counterparty_upgrade_sequence: 0,
}
}

Expand Down
1 change: 1 addition & 0 deletions ibc-testkit/src/fixtures/core/channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub fn dummy_raw_channel_end(state: i32, channel_id: Option<u64>) -> RawChannel
counterparty: Some(dummy_raw_counterparty_chan(channel_id)),
connection_hops: vec![ConnectionId::zero().to_string()],
version: "".to_string(), // The version is not validated.
upgrade_sequence: 0,
}
}

Expand Down
1 change: 1 addition & 0 deletions ibc-testkit/src/fixtures/core/channel/timeout_on_close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub fn dummy_raw_msg_timeout_on_close(height: u64, timeout_timestamp: u64) -> Ra
}),
next_sequence_recv: 1,
signer: dummy_bech32_account(),
counterparty_upgrade_sequence: 0,
}
}

Expand Down
54 changes: 40 additions & 14 deletions ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ use crate::testapp::ibc::clients::mock::client_state::client_type as mock_client
use crate::testapp::ibc::clients::mock::consensus_state::MockConsensusState;
use crate::testapp::ibc::clients::mock::header::{MockHeader, MOCK_HEADER_TYPE_URL};
use crate::testapp::ibc::clients::mock::misbehaviour::{Misbehaviour, MOCK_MISBEHAVIOUR_TYPE_URL};
use crate::testapp::ibc::clients::mock::proto::{
ClientState as RawMockClientState, Header as RawMockHeader,
};
use crate::testapp::ibc::clients::mock::proto::ClientState as RawMockClientState;

pub const MOCK_CLIENT_STATE_TYPE_URL: &str = "/ibc.mock.ClientState";
pub const MOCK_CLIENT_TYPE: &str = "9999-mock";
Expand All @@ -35,14 +33,16 @@ pub fn client_type() -> ClientType {
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct MockClientState {
pub header: MockHeader,
pub frozen_height: Option<Height>,
pub trusting_period: Duration,
pub frozen: bool,
}

impl MockClientState {
pub fn new(header: MockHeader) -> Self {
Self {
header,
frozen_height: None,
trusting_period: Duration::from_nanos(0),
frozen: false,
}
}

Expand All @@ -54,15 +54,29 @@ impl MockClientState {
None
}

pub fn with_frozen_height(self, frozen_height: Height) -> Self {
pub fn with_trusting_period(self, trusting_period: Duration) -> Self {
Self {
trusting_period,
..self
}
}

pub fn frozen(self) -> Self {
Self {
frozen_height: Some(frozen_height),
frozen: true,
..self
}
}

pub fn unfrozen(self) -> Self {
Self {
frozen: false,
..self
}
}

pub fn is_frozen(&self) -> bool {
self.frozen_height.is_some()
self.frozen
}

fn expired(&self, _elapsed: Duration) -> bool {
Expand All @@ -76,17 +90,29 @@ impl TryFrom<RawMockClientState> for MockClientState {
type Error = ClientError;

fn try_from(raw: RawMockClientState) -> Result<Self, Self::Error> {
Ok(Self::new(raw.header.expect("Never fails").try_into()?))
Ok(Self {
header: raw
.header
.ok_or(ClientError::Other {
description: "header is not present".into(),
})?
.try_into()?,
trusting_period: Duration::from_nanos(raw.trusting_period),
frozen: raw.frozen,
})
}
}

impl From<MockClientState> for RawMockClientState {
fn from(value: MockClientState) -> Self {
RawMockClientState {
header: Some(RawMockHeader {
height: Some(value.header.height().into()),
timestamp: value.header.timestamp.nanoseconds(),
}),
header: Some(value.header.into()),
trusting_period: value
.trusting_period
.as_nanos()
.try_into()
.expect("no error"),
frozen: value.frozen,
}
}
}
Expand Down Expand Up @@ -354,7 +380,7 @@ where
client_id: &ClientId,
_client_message: Any,
) -> Result<(), ClientError> {
let frozen_client_state = self.with_frozen_height(Height::min(0));
let frozen_client_state = self.frozen();

ctx.store_client_state(
ClientStatePath::new(client_id.clone()),
Expand Down

0 comments on commit 3b11b12

Please sign in to comment.