Skip to content

Commit

Permalink
ICS4: Change location where upgrade sequence gets incremented (#804)
Browse files Browse the repository at this point in the history
* increment sequence at start of new handshake rather than at end of old one

* changelog

* Update CHANGELOG.md
  • Loading branch information
AdityaSripal authored Aug 1, 2022
1 parent 93a2e7f commit 3270efe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

- [\#803](https://github.com/cosmos/ibc/pull/803) Changed UpgradeState enums to match the opening handshake enum style.
- [\#802](https://github.com/cosmos/ibc/pull/802) Move `ClientState` to the `provableStore` and add `ClientState` validation in `connOpenTry` and `connOpenAck`
- [\#803](https://github.com/cosmos/ibc/pull/803) Changed UpgradeState enums to match the opening handshake enum style.
- [\#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
- [\#807](https://github.com/cosmos/ibc/pull/807) Upgrade keys will now prefix the channel path to align with the rest of ICS4 keys
18 changes: 7 additions & 11 deletions spec/core/ics-004-channel-and-packet-semantics/UPGRADES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
```

Expand Down Expand Up @@ -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)
}
```

Expand Down

0 comments on commit 3270efe

Please sign in to comment.