cosmos / ibc

Interchain Standards (ICS) for the Cosmos network & interchain ecosystem.
Other
936 stars 381 forks source link

ICS004(channel-upgrades): change counterparty `LastSequenceSend` to `NextSequenceSend` #1015

Closed damiannolan closed 11 months ago

damiannolan commented 1 year ago

In the current channel upgradability spec, we introduce a new concept of LastSequenceSend / LatestSequenceSend in order to provide a "watermark" or checkpoint for packet flushing while within the upgrade handshake.

This can easily be changed to NextSequenceSend which is already a well-known concept within ibc.

Conditional logic in recvPacket would change like so:

Spec:

- abortTransactionUnless(channel.state === OPEN || (channel.state === FLUSHING && packet.sequence <= counterpartyLastPacketSent))
+ abortTransactionUnless(channel.state === OPEN || (channel.state === FLUSHING && packet.sequence < counterpartyNextSequenceSend))

ibc-go example:

- if packet.GetSequence() > counterpartyUpgrade.LatestSequenceSend {
+ if packet.GetSequence() >= counterpartyUpgrade.NextSequenceSend {
    return errorsmod.Wrapf(
        types.ErrInvalidPacket,
        "failed to receive packet, cannot flush packet at sequence greater than counterparty last sequence send (%d) > (%d)", packet.GetSequence(), counterpartyUpgrade.LatestSequenceSend,
    )
}

I would consider this an improvement as we can reuse existing ibc concepts without introducing more concepts around send/recv sequencing.