Skip to content

Commit b4e2b2a

Browse files
committed
Make channel-upgrade execute command fully idempotent
The channel-upgrade execute command is basically idempotent. However, since proposed upgrades are deleted after the channel upgrade completes, re-running the command previously failed with the error: "Error: channel upgrade is not initialized." This behavior caused instability in tests such as: https://github.com/datachainlab/cosmos-ethereum-ibc-lcp/blob/v0.2.24/tests/e2e/cases/tm2eth/scripts/test-channel-upgrade#L122 To address this, the command now exits with exit code 0 even when no proposed upgrades exist. Although some users might forget to run the channel-upgrade init command, they will be notified through the newly added log message. Signed-off-by: Takeshi Arabiki <takeshi.arabiki@datachain.jp>
1 parent 2f856cc commit b4e2b2a

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

core/channel-upgrade.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,12 @@ func upgradeChannelStep(ctx context.Context, src, dst *ProvableChain, targetSrcS
382382
)}
383383

384384
// check if both chains have reached the target states or UNINIT states
385-
if !firstCall && srcState == UPGRADE_STATE_UNINIT && dstState == UPGRADE_STATE_UNINIT ||
386-
srcState != UPGRADE_STATE_UNINIT && dstState != UPGRADE_STATE_UNINIT && srcState == targetSrcState && dstState == targetDstState {
387-
logger.InfoContext(ctx, "both chains have reached the target states")
385+
if srcState == targetSrcState && dstState == targetDstState {
386+
if firstCall && srcState == UPGRADE_STATE_UNINIT && dstState == UPGRADE_STATE_UNINIT {
387+
logger.InfoContext(ctx, "both chains have already reached the target states, or the channel upgrade has not been initialized")
388+
} else {
389+
logger.InfoContext(ctx, "both chains have reached the target states")
390+
}
388391
out.Last = true
389392
return out, nil
390393
}
@@ -394,7 +397,7 @@ func upgradeChannelStep(ctx context.Context, src, dst *ProvableChain, targetSrcS
394397
dstAction := UPGRADE_ACTION_NONE
395398
switch {
396399
case srcState == UPGRADE_STATE_UNINIT && dstState == UPGRADE_STATE_UNINIT:
397-
return nil, errors.New("channel upgrade is not initialized")
400+
return nil, errors.New("channel upgrade has not been initialized; it will never reach the target states")
398401
case srcState == UPGRADE_STATE_INIT && dstState == UPGRADE_STATE_UNINIT:
399402
if dstChan.Channel.UpgradeSequence >= srcChan.Channel.UpgradeSequence {
400403
srcAction = UPGRADE_ACTION_CANCEL

tests/cases/tm2tm/scripts/test-channel-upgrade

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,16 @@ $RLY tx channel-upgrade execute ibc01 --target-src-state FLUSHING --target-dst-s
140140
sleep 20 # Both chains exceed upgrade.timeout.timestamp
141141
$RLY tx channel-upgrade execute ibc01 # ibc0,ibc1 <= chanUpgradeTimeout
142142
checkResult orig
143+
144+
echo '##### case 10 #####'
145+
# Both chains have already reached the target states, or the channel upgrade has not been initialized
146+
$RLY tx channel-upgrade execute ibc01
147+
checkResult orig
148+
149+
echo '##### case 11 #####'
150+
# The target states will never be reached
151+
if $RLY tx channel-upgrade execute ibc01 --target-src-state INIT --target-dst-state FLUSHING; then
152+
echo 'channel-upgrade completed with exit code 0, but non-zero code was expected' >&2
153+
exit 1
154+
fi
155+
checkResult orig

0 commit comments

Comments
 (0)