Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Channel upgrade worker handshake #3569

Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
50f267e
Add missing CLIs for channel upgrade
ljoss17 Jul 24, 2023
80635bb
Update CLI template
ljoss17 Jul 24, 2023
edb3610
Add cargo patch for check-guide test
ljoss17 Aug 3, 2023
05b08d0
Add documentation TODO to check-guide Cargo.toml
ljoss17 Aug 3, 2023
2c65075
Set dst-channel flag to required for channel upgrade CLIs and updated…
ljoss17 Aug 3, 2023
fa8595f
Clean channel upgrade CLIs
ljoss17 Aug 7, 2023
298eaf0
Update guide templates
ljoss17 Aug 7, 2023
03da637
Merge branch 'sean/channel-upgradability' into luca_joss/channel-upgr…
ljoss17 Aug 8, 2023
e437381
Update channel upgrade test to match ibc-go changes
ljoss17 Aug 8, 2023
d337583
Merge branch 'luca_joss/channel-upgradability-clis' into luca_joss/ch…
ljoss17 Aug 8, 2023
f3ad761
WIP: waiting for new channel states during upgrade to be implemented
ljoss17 Aug 9, 2023
b910dd5
Merge branch 'sean/channel-upgradability' into luca_joss/channel-upgr…
ljoss17 Aug 24, 2023
f9ee86e
Implement channel upgrade handshake
ljoss17 Aug 28, 2023
b71453d
Merge branch 'sean/channel-upgradability' into luca_joss/channel-upgr…
ljoss17 Aug 28, 2023
f266fae
Add channel upgrade handshake test
ljoss17 Aug 28, 2023
f125142
Removed unnecessary logs
ljoss17 Aug 28, 2023
ed0f5d4
Update channel upgrade test doc
ljoss17 Aug 28, 2023
29ab35a
Add test to transfer ics29 packet after channel upgrade
ljoss17 Aug 28, 2023
c5fa9ee
Update tools/integration-test/src/tests/channel_upgrade/ics29.rs
ljoss17 Aug 29, 2023
f2f6c73
Add comments
ljoss17 Aug 29, 2023
9ca2261
Fix 'query bank balances' CLI to handle SDK v0.50 changes
ljoss17 Oct 9, 2023
8ce85c8
Merge branch 'sean/channel-upgradability' into luca_joss/channel-upgr…
ljoss17 Oct 10, 2023
f018a5f
Remove flush status from channel end
ljoss17 Oct 10, 2023
bf4b9e2
Update Nix flake and use alpha release of channel upgrade simapp for CI
ljoss17 Oct 11, 2023
af442c3
Fix test-stable and change 'into_i32' to 'as_i32' for Channel State
ljoss17 Oct 11, 2023
23c942f
Merge branch 'sean/channel-upgradability' into luca_joss/channel-upgr…
ljoss17 Oct 12, 2023
e113556
Fix python tests
ljoss17 Oct 12, 2023
db3d29e
Use state comparison method 'less_or_equal_progress' where applicable
ljoss17 Oct 12, 2023
ef4d8a9
Add tests for channel upgrade completion
ljoss17 Oct 13, 2023
fa67528
Improve less_or_equal method for channel states and add unit tests
ljoss17 Oct 13, 2023
7b8ea92
Use automatic link for URL in channel State documentation
ljoss17 Oct 13, 2023
371a620
Add comment on channel upgrade open assertion
ljoss17 Oct 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ jobs:
fail-fast: false
matrix:
chain:
- package: ibc-go-v7-channel-upgrade
- package: ibc-go-v8-channel-upgrade-simapp
command: simd
account_prefix: cosmos
steps:
Expand Down
8 changes: 1 addition & 7 deletions 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 crates/relayer-cli/src/commands/tx/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,9 @@ impl Runnable for TxUpgradeClientsCmd {
.chains
.iter()
.filter(|&chain| {
(self.reference_chain_id != chain.id
self.reference_chain_id != chain.id
&& (self.host_chain_id.is_none()
|| self.host_chain_id == Some(chain.id.clone())))
|| self.host_chain_id == Some(chain.id.clone()))
})
.map(|chain| {
self.upgrade_clients_for_chain(
Expand Down
124 changes: 57 additions & 67 deletions crates/relayer-types/src/core/ics04_channel/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use ibc_proto::protobuf::Protobuf;
use serde::{Deserialize, Serialize};

use ibc_proto::ibc::core::channel::v1::{
Channel as RawChannel, Counterparty as RawCounterparty, FlushStatus as RawFlushStatus,
Channel as RawChannel, Counterparty as RawCounterparty,
IdentifiedChannel as RawIdentifiedChannel,
};

use crate::core::ics04_channel::packet::Sequence;
use crate::core::ics04_channel::{error::Error, flush_status::FlushStatus, version::Version};
use crate::core::ics04_channel::{error::Error, version::Version};
use crate::core::ics24_host::identifier::{ChannelId, ConnectionId, PortId};

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
Expand Down Expand Up @@ -45,7 +45,6 @@ impl TryFrom<RawIdentifiedChannel> for IdentifiedChannelEnd {
connection_hops: value.connection_hops,
version: value.version,
upgrade_sequence: 0, // FIXME: proto IdentifiedChannel does not have this field, should we default to 0 ?
flush_status: 0,
};

Ok(IdentifiedChannelEnd {
Expand All @@ -59,7 +58,7 @@ impl TryFrom<RawIdentifiedChannel> for IdentifiedChannelEnd {
impl From<IdentifiedChannelEnd> for RawIdentifiedChannel {
fn from(value: IdentifiedChannelEnd) -> Self {
RawIdentifiedChannel {
state: value.channel_end.state as i32,
state: value.channel_end.state.into_i32(),
ordering: value.channel_end.ordering as i32,
counterparty: Some(value.channel_end.counterparty().clone().into()),
connection_hops: value
Expand All @@ -83,7 +82,6 @@ pub struct ChannelEnd {
pub connection_hops: Vec<ConnectionId>,
pub version: Version,
pub upgraded_sequence: Sequence,
pub flush_status: FlushStatus,
}

impl Display for ChannelEnd {
Expand All @@ -105,7 +103,6 @@ impl Default for ChannelEnd {
connection_hops: Vec::new(),
version: Version::default(),
upgraded_sequence: Sequence::from(0), // The value of 0 indicates the channel has never been upgraded
flush_status: FlushStatus::NotinflushUnspecified,
}
}
}
Expand Down Expand Up @@ -140,24 +137,21 @@ impl TryFrom<RawChannel> for ChannelEnd {

let version = value.version.into();

let flush_status = FlushStatus::try_from(value.flush_status)?;

Ok(ChannelEnd::new(
chan_state,
chan_ordering,
remote,
connection_hops,
version,
Sequence::from(value.upgrade_sequence),
flush_status,
))
}
}

impl From<ChannelEnd> for RawChannel {
fn from(value: ChannelEnd) -> Self {
RawChannel {
state: value.state as i32,
state: value.state.into_i32(),
ordering: value.ordering as i32,
counterparty: Some(value.counterparty().clone().into()),
connection_hops: value
Expand All @@ -167,7 +161,6 @@ impl From<ChannelEnd> for RawChannel {
.collect(),
version: value.version.to_string(),
upgrade_sequence: value.upgraded_sequence.into(),
flush_status: RawFlushStatus::from(value.flush_status).into(),
}
}
}
Expand All @@ -181,7 +174,6 @@ impl ChannelEnd {
connection_hops: Vec<ConnectionId>,
version: Version,
upgraded_sequence: Sequence,
flush_status: FlushStatus,
) -> Self {
Self {
state,
Expand All @@ -190,7 +182,6 @@ impl ChannelEnd {
connection_hops,
version,
upgraded_sequence,
flush_status,
}
}

Expand All @@ -207,19 +198,17 @@ impl ChannelEnd {
self.remote.channel_id = Some(c);
}

/// Returns `true` if this `ChannelEnd` is in state [`State::Open`].
/// Returns `true` if this `ChannelEnd` is in state [`State::Open`]
/// [`State::Open(UpgradeState::Upgrading)`] is only used in the channel upgrade
/// handshake so this method matches with [`State::Open(UpgradeState::NotUpgrading)`].
pub fn is_open(&self) -> bool {
self.state_matches(&State::Open)
self.state_matches(&State::Open(UpgradeState::NotUpgrading))
}

pub fn state(&self) -> &State {
&self.state
}

pub fn flush_status(&self) -> &FlushStatus {
&self.flush_status
}

pub fn ordering(&self) -> &Ordering {
&self.ordering
}
Expand Down Expand Up @@ -251,11 +240,6 @@ impl ChannelEnd {
self.state() == other
}

/// Helper function to compare the flush status of this end with another flush status.
pub fn flush_status_matches(&self, other: &FlushStatus) -> bool {
self.flush_status() == other
}

/// Helper function to compare the order of this end with another order.
pub fn order_matches(&self, other: &Ordering) -> bool {
self.ordering() == other
Expand Down Expand Up @@ -397,6 +381,15 @@ impl FromStr for Ordering {
}
}

/// This enum is used to differentiate if a channel is being upgraded when
/// a `UpgradeInitChannel` or a `UpgradeOpenChannel` is received.
/// See `handshake_step` method in `crates/relayer/src/channel.rs`.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum UpgradeState {
Upgrading,
NotUpgrading,
}

/// The possible state variants that a channel can exhibit.
///
/// These are encoded with integer discriminants so that there is
Expand All @@ -407,34 +400,25 @@ impl FromStr for Ordering {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum State {
/// Default state
Uninitialized = 0,
Uninitialized,
/// A channel has just started the opening handshake.
Init = 1,
Init,
/// A channel has acknowledged the handshake step on the counterparty chain.
TryOpen = 2,
TryOpen,
/// A channel has completed the handshake step. Open channels are ready to
/// send and receive packets.
Open = 3,
/// During some steps of channel upgrades, the state is still in Open. The
/// `UpgradeState` is used to differentiate these states during the upgrade
/// handshake.
/// https://github.com/cosmos/ibc/blob/main/spec/core/ics-004-channel-and-packet-semantics/UPGRADES.md#upgrade-handshake
Open(UpgradeState),
/// A channel has been closed and can no longer be used to send or receive
/// packets.
Closed = 4,
Closed,
/// A channel has just accepted the upgrade handshake attempt and is flushing in-flight packets.
Flushing = 5,
Flushing,
/// A channel has just completed flushing any in-flight packets.
Flushcomplete = 6,
/// A channel has just started the upgrade handshake. The chain that is
/// proposing the upgrade should set the channel state from OPEN to INITUPGRADE.
InitUpgrade = 7,
/// A channel has acknowledged the upgrade handshake step on the counterparty chain.
/// The counterparty chain that accepts the upgrade should set the channel state from
/// OPEN to TRYUPGRADE.
/// The counterparty chain blocks new packets until the channel upgrade is done or cancelled.
TryUpgrade = 8,
/// A channel has confirmed the upgrade handshake step on the counterparty chain.
/// The chain that confirmed the upgrade should set the channel state from
/// INITUPGRADE to ACKUPGRADE.
/// The chain blocks new packets until the channel upgrade is done or cancelled.
AckUpgrade = 9,
Flushcomplete,
}

impl State {
Expand All @@ -444,13 +428,10 @@ impl State {
Self::Uninitialized => "UNINITIALIZED",
Self::Init => "INIT",
Self::TryOpen => "TRYOPEN",
Self::Open => "OPEN",
Self::Open(_) => "OPEN",
Self::Closed => "CLOSED",
Self::Flushing => "FLUSHING",
Self::Flushcomplete => "FLUSHCOMPLETE",
Self::InitUpgrade => "INITUPGRADE",
Self::TryUpgrade => "TRYUPGRADE",
Self::AckUpgrade => "ACKUPGRADE",
}
}

Expand All @@ -460,20 +441,30 @@ impl State {
0 => Ok(Self::Uninitialized),
1 => Ok(Self::Init),
2 => Ok(Self::TryOpen),
3 => Ok(Self::Open),
3 => Ok(Self::Open(UpgradeState::NotUpgrading)),
4 => Ok(Self::Closed),
5 => Ok(Self::Flushing),
6 => Ok(Self::Flushcomplete),
7 => Ok(Self::InitUpgrade),
8 => Ok(Self::TryUpgrade),
9 => Ok(Self::AckUpgrade),
_ => Err(Error::unknown_state(s)),
}
}

// Parses the State out from a i32.
pub fn into_i32(&self) -> i32 {
ljoss17 marked this conversation as resolved.
Show resolved Hide resolved
match self {
State::Uninitialized => 0,
State::Init => 1,
State::TryOpen => 2,
State::Open(_) => 3,
State::Closed => 4,
State::Flushing => 5,
State::Flushcomplete => 6,
}
}
ljoss17 marked this conversation as resolved.
Show resolved Hide resolved

/// Returns whether or not this channel state is `Open`.
pub fn is_open(self) -> bool {
self == State::Open
self == State::Open(UpgradeState::NotUpgrading)
}

/// Returns whether or not this channel state is `Closed`.
Expand All @@ -498,28 +489,28 @@ impl State {

romac marked this conversation as resolved.
Show resolved Hide resolved
Init => !matches!(other, Uninitialized),
TryOpen => !matches!(other, Uninitialized | Init),
Open => !matches!(other, Uninitialized | Init | TryOpen),

Flushing => !matches!(other, Uninitialized | Init | TryOpen | Open),
Flushcomplete => !matches!(other, Uninitialized | Init | TryOpen | Open | Flushing),
InitUpgrade => !matches!(
Open(UpgradeState::NotUpgrading) => !matches!(other, Uninitialized | Init | TryOpen),
Open(UpgradeState::Upgrading) => !matches!(
other,
Uninitialized | Init | TryOpen | Open | Flushing | Flushcomplete
Uninitialized | Init | TryOpen | Open(UpgradeState::NotUpgrading)
),
TryUpgrade => !matches!(

Flushing => !matches!(
other,
Uninitialized | Init | TryOpen | Open | Flushing | Flushcomplete | InitUpgrade
Uninitialized
| Init
| TryOpen
| Open(UpgradeState::NotUpgrading)
| Open(UpgradeState::Upgrading)
),
AckUpgrade => !matches!(
Flushcomplete => !matches!(
other,
Uninitialized
| Init
| TryOpen
| Open
| Open(UpgradeState::NotUpgrading)
| Open(UpgradeState::Upgrading)
| Flushing
| Flushcomplete
| InitUpgrade
| TryUpgrade
),

Closed => false,
Expand Down Expand Up @@ -559,7 +550,6 @@ pub mod test_util {
connection_hops: vec![ConnectionId::default().to_string()],
version: "ics20".to_string(), // The version is not validated.
upgrade_sequence: 0, // The value of 0 indicates the channel has never been upgraded
flush_status: 0,
}
}
}
Expand Down
Loading