From d79f49f98af1b214d3e29d1092e15707c3f999ec Mon Sep 17 00:00:00 2001 From: Aditya Sripal Date: Wed, 27 Jul 2022 15:08:58 +0200 Subject: [PATCH 1/3] increment sequence at start of new handshake rather than at end of old one --- .../UPGRADES.md | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/spec/core/ics-004-channel-and-packet-semantics/UPGRADES.md b/spec/core/ics-004-channel-and-packet-semantics/UPGRADES.md index b435bc6e6..284664fdf 100644 --- a/spec/core/ics-004-channel-and-packet-semantics/UPGRADES.md +++ b/spec/core/ics-004-channel-and-packet-semantics/UPGRADES.md @@ -237,9 +237,6 @@ function restoreChannel() { channelIdentifier ) - // increment sequence in preparation for the next upgrade - provableStore.set(channelUpgradeSequencePath(portIdentifier, channelIdentifier), sequence+1) - // caller should return as well } ``` @@ -307,6 +304,11 @@ function chanUpgradeInit( } sequence := provableStore.get(channelUpgradeSequencePath(portIdentifier, channelIdentifier)) + if sequence == nil { + sequence = 1 + } else { + sequence++ + } // call modules onChanUpgradeInit callback module = lookupModule(portIdentifier) @@ -388,11 +390,11 @@ function chanUpgradeTry( // get current sequence on this channel // if the counterparty sequence is greater than the current sequence, we fast forward to the counterparty sequence // so that both channel ends are using the same sequence for the current upgrade - // if the counterparty sequence is less than the current sequence, then either the counterparty chain is out-of-sync or + // if the counterparty sequence is less than or equal to the current sequence, then either the counterparty chain is out-of-sync or // the message is out-of-sync and we write an error receipt with our own sequence so that the counterparty can update // their sequence as well. We must then increment our sequence so both sides start the next upgrade with a fresh sequence. currentSequence = provableStore.get(channelUpgradeSequencePath(portIdentifier, channelIdentifier)) - if counterpartySequence >= currentSequence { + if counterpartySequence > currentSequence { provableStore.set(channelUpgradeSequencePath(portIdentifier, channelIdentifier), counterpartySequence) } else { // error on the higher sequence so that both chains move to a fresh sequence @@ -540,9 +542,6 @@ function chanUpgradeAck( provableStore.set(channelPath(portIdentifier, channelIdentifier), currentChannel) provableStore.delete(channelUpgradeTimeoutPath(portIdentifier, channelIdentifier)) privateStore.delete(channelRestorePath(portIdentifier, channelIdentifier)) - - // increment sequence in preparation for the next upgrade - provableStore.set(channelUpgradeSequencePath(portIdentifier, channelIdentifier), sequence+1) } ``` @@ -596,9 +595,6 @@ function chanUpgradeConfirm( provableStore.set(channelPath(portIdentifier, channelIdentifier), currentChannel) provableStore.delete(channelUpgradeTimeoutPath(portIdentifier, channelIdentifier)) privateStore.delete(channelRestorePath(portIdentifier, channelIdentifier)) - - // increment sequence in preparation for the next upgrade - provableStore.set(channelUpgradeSequencePath(portIdentifier, channelIdentifier), sequence+1) } ``` From a84e64ba4c88b242f671014999fef7788ee1faa1 Mon Sep 17 00:00:00 2001 From: Aditya Sripal Date: Wed, 27 Jul 2022 18:25:56 +0200 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a799ba40..2b1ba366f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,3 +38,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ # Changelog ## [Unreleased] + +### Improvements + +- [/#804](https://github.com/cosmos/ibc/pull/804) Increment upgrade sequence at the start of a new handshake rather than the end of a completed handshake \ No newline at end of file From 7bb5c81b709b1cc614f3d0136a9ffdc5ca09ebc7 Mon Sep 17 00:00:00 2001 From: Aditya Date: Wed, 27 Jul 2022 18:34:23 +0200 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b1ba366f..492c53bac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,4 +41,4 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements -- [/#804](https://github.com/cosmos/ibc/pull/804) Increment upgrade sequence at the start of a new handshake rather than the end of a completed handshake \ No newline at end of file +- [\#804](https://github.com/cosmos/ibc/pull/804) Increment upgrade sequence at the start of a new handshake rather than the end of a completed handshake