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 2 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
150 changes: 129 additions & 21 deletions crates/relayer-types/src/core/ics04_channel/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@
/// 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

Check warning on line 413 in crates/relayer-types/src/core/ics04_channel/channel.rs

View workflow job for this annotation

GitHub Actions / cargo-doc

this URL is not a hyperlink
Open(UpgradeState),
/// A channel has been closed and can no longer be used to send or receive
/// packets.
Expand Down Expand Up @@ -474,6 +474,7 @@

/// Returns whether or not the channel with this state
/// has progressed less or the same than the argument.
/// This only takes into account the open channel handshake.
///
/// # Example
/// ```rust,ignore
Expand All @@ -490,30 +491,22 @@
Init => !matches!(other, Uninitialized),
TryOpen => !matches!(other, Uninitialized | Init),
Open(UpgradeState::NotUpgrading) => !matches!(other, Uninitialized | Init | TryOpen),
Open(UpgradeState::Upgrading) => !matches!(
other,
Uninitialized | Init | TryOpen | Open(UpgradeState::NotUpgrading)
),
_ => false,
}
}

Flushing => !matches!(
other,
Uninitialized
| Init
| TryOpen
| Open(UpgradeState::NotUpgrading)
| Open(UpgradeState::Upgrading)
),
Flushcomplete => !matches!(
/// Returns whether or not the channel with this state is
/// being upgraded.
pub fn is_upgrading(self, other: Self) -> bool {
use State::*;

match self {
Open(UpgradeState::NotUpgrading) => matches!(
other,
Uninitialized
| Init
| TryOpen
| Open(UpgradeState::NotUpgrading)
| Open(UpgradeState::Upgrading)
| Flushing
Open(UpgradeState::Upgrading) | Flushing | Flushcomplete
),

Closed => false,
Open(UpgradeState::Upgrading) | Flushing | Flushcomplete => true,
_ => false,
}
}
}
Expand Down Expand Up @@ -690,4 +683,119 @@
}
}
}

#[test]
fn less_or_equal_progress_uninitialized() {
use crate::core::ics04_channel::channel::State;
use crate::core::ics04_channel::channel::UpgradeState;

let higher_or_equal_states = vec![
State::Uninitialized,
State::Init,
State::TryOpen,
State::Open(UpgradeState::NotUpgrading),
State::Open(UpgradeState::Upgrading),
State::Closed,
State::Flushing,
State::Flushcomplete,
];
for state in higher_or_equal_states {
assert!(State::Uninitialized.less_or_equal_progress(state))
}
}

#[test]
fn less_or_equal_progress_init() {
use crate::core::ics04_channel::channel::State;
use crate::core::ics04_channel::channel::UpgradeState;

let lower_states = vec![State::Uninitialized];
let higher_or_equal_states = vec![
State::Init,
State::TryOpen,
State::Open(UpgradeState::NotUpgrading),
State::Open(UpgradeState::Upgrading),
State::Closed,
State::Flushing,
State::Flushcomplete,
];
for state in lower_states {
assert!(!State::Init.less_or_equal_progress(state));
}
for state in higher_or_equal_states {
assert!(State::Init.less_or_equal_progress(state))
}
}

#[test]
fn less_or_equal_progress_tryopen() {
use crate::core::ics04_channel::channel::State;
use crate::core::ics04_channel::channel::UpgradeState;

let lower_states = vec![State::Uninitialized, State::Init];
let higher_or_equal_states = vec![
State::TryOpen,
State::Open(UpgradeState::NotUpgrading),
State::Open(UpgradeState::Upgrading),
State::Closed,
State::Flushing,
State::Flushcomplete,
];
for state in lower_states {
assert!(!State::TryOpen.less_or_equal_progress(state));
}
for state in higher_or_equal_states {
assert!(State::TryOpen.less_or_equal_progress(state))
}
}

#[test]
fn less_or_equal_progress_open_not_upgrading() {
use crate::core::ics04_channel::channel::State;
use crate::core::ics04_channel::channel::UpgradeState;

let lower_states = vec![State::Uninitialized, State::Init, State::TryOpen];
let higher_or_equal_states = vec![
State::Open(UpgradeState::NotUpgrading),
State::Open(UpgradeState::Upgrading),
State::Closed,
State::Flushing,
State::Flushcomplete,
];
for state in lower_states {
assert!(!State::Open(UpgradeState::NotUpgrading).less_or_equal_progress(state));
}
for state in higher_or_equal_states {
assert!(State::Open(UpgradeState::NotUpgrading).less_or_equal_progress(state))
}
}

#[test]
fn less_or_equal_progress_upgrading_states() {
use crate::core::ics04_channel::channel::State;
use crate::core::ics04_channel::channel::UpgradeState;

let states = [
State::Uninitialized,
State::Init,
State::TryOpen,
State::Open(UpgradeState::NotUpgrading),
State::Open(UpgradeState::Upgrading),
State::Closed,
State::Flushing,
State::Flushcomplete,
];

let upgrading_states = vec![
State::Open(UpgradeState::Upgrading),
State::Closed,
State::Flushing,
State::Flushcomplete,
];
for upgrade_state in upgrading_states {
for state in states.iter() {
assert!(!upgrade_state.less_or_equal_progress(*state));
}
}
}
}
2 changes: 1 addition & 1 deletion crates/relayer/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ impl<ChainA: ChainHandle, ChainB: ChainHandle> Channel<ChainA, ChainB> {
(State::Flushcomplete, State::Flushing) => {
Some(self.build_chan_upgrade_confirm_and_send()?)
}
(State::Open(UpgradeState::Upgrading), State::Flushcomplete) => {
(State::Open(_), State::Flushcomplete) => {
Some(self.build_chan_upgrade_open_and_send()?)
}

Expand Down
4 changes: 3 additions & 1 deletion crates/relayer/src/supervisor/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,14 +315,16 @@ impl<'a, Chain: ChainHandle> SpawnContext<'a, Chain> {
let open_handshake = chan_state_dst.less_or_equal_progress(ChannelState::TryOpen)
&& chan_state_dst.less_or_equal_progress(chan_state_src);

let upgrade_handshake = chan_state_dst.is_upgrading(chan_state_src);

// Determine if close handshake is required, i.e. if channel state on source is `Closed`,
// and on destination channel state is not `Closed, and there are no pending packets.
// If there are pending packets on destination then we let the packet worker clear the
// packets and we do not finish the channel handshake.
let close_handshake =
chan_state_src.is_closed() && !chan_state_dst.is_closed() && !has_packets();

if open_handshake || close_handshake {
if open_handshake || upgrade_handshake || close_handshake {
// create worker for channel handshake that will advance the counterparty state
let channel_object = Object::Channel(Channel {
dst_chain_id: counterparty_chain.id(),
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion tools/integration-test/src/tests/channel_upgrade/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod ics29;
pub mod manual_channel_upgrade;
pub mod upgrade_handshake;
pub mod upgrade_handshake_steps;
Loading
Loading