diff --git a/modules/core/03-connection/keeper/verify_test.go b/modules/core/03-connection/keeper/verify_test.go index 77022015a74..f97bd12690c 100644 --- a/modules/core/03-connection/keeper/verify_test.go +++ b/modules/core/03-connection/keeper/verify_test.go @@ -890,6 +890,7 @@ func (suite *KeeperTestSuite) TestVerifyUpgrade() { upgrade = channeltypes.NewUpgrade( channeltypes.NewUpgradeFields(channeltypes.UNORDERED, []string{path.EndpointA.ConnectionID}, "v1.0.0"), channeltypes.NewTimeout(clienttypes.ZeroHeight(), 100000), + 0, ) suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.SetUpgrade(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, upgrade) diff --git a/modules/core/04-channel/keeper/grpc_query_test.go b/modules/core/04-channel/keeper/grpc_query_test.go index 39bb5e9c9cb..12ff1fbabbd 100644 --- a/modules/core/04-channel/keeper/grpc_query_test.go +++ b/modules/core/04-channel/keeper/grpc_query_test.go @@ -1863,6 +1863,7 @@ func (suite *KeeperTestSuite) TestQueryUpgrade() { expectedUpgrade = types.NewUpgrade( types.NewUpgradeFields(types.UNORDERED, []string{ibctesting.FirstConnectionID}, mock.Version), types.NewTimeout(clienttypes.ZeroHeight(), 1000000), + 0, ) suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.SetUpgrade(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, expectedUpgrade) diff --git a/modules/core/04-channel/keeper/packet.go b/modules/core/04-channel/keeper/packet.go index fd4107ee9db..087d0502d7a 100644 --- a/modules/core/04-channel/keeper/packet.go +++ b/modules/core/04-channel/keeper/packet.go @@ -250,7 +250,6 @@ func (k Keeper) RecvPacket( // incrementing nextSequenceRecv and storing under this chain's channelEnd identifiers // Since this is the receiving chain, our channelEnd is packet's destination port and channel k.SetNextSequenceRecv(ctx, packet.GetDestPort(), packet.GetDestChannel(), nextSequenceRecv) - } // log that a packet has been received & executed diff --git a/modules/core/04-channel/keeper/packet_test.go b/modules/core/04-channel/keeper/packet_test.go index fd5895771f3..b2af9329765 100644 --- a/modules/core/04-channel/keeper/packet_test.go +++ b/modules/core/04-channel/keeper/packet_test.go @@ -351,6 +351,30 @@ func (suite *KeeperTestSuite) TestRecvPacket() { channel := path.EndpointB.GetChannel() channel.State = types.FLUSHING path.EndpointB.SetChannel(channel) + + // set last packet sent sequence to sequence + 1 + counterpartyUpgrade := types.Upgrade{LatestSequenceSend: sequence + 1} + path.EndpointB.SetChannelCounterpartyUpgrade(counterpartyUpgrade) + }, + nil, + }, + { + "success with an counterparty latest sequence send set to 0", + func() { + suite.coordinator.Setup(path) + sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData) + suite.Require().NoError(err) + + packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) + channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) + + channel := path.EndpointB.GetChannel() + channel.State = types.FLUSHING + path.EndpointB.SetChannel(channel) + + // set last packet sent sequence to zero. + counterpartyUpgrade := types.Upgrade{LatestSequenceSend: 0} + path.EndpointB.SetChannelCounterpartyUpgrade(counterpartyUpgrade) }, nil, }, diff --git a/modules/core/04-channel/keeper/upgrade.go b/modules/core/04-channel/keeper/upgrade.go index e3b9cb77d31..975cdc83bec 100644 --- a/modules/core/04-channel/keeper/upgrade.go +++ b/modules/core/04-channel/keeper/upgrade.go @@ -174,7 +174,7 @@ func (k Keeper) ChanUpgradeTry( proofHeight, proofCounterpartyUpgrade, channel.Counterparty.PortId, channel.Counterparty.ChannelId, - types.NewUpgrade(counterpartyUpgradeFields, types.Timeout{}), + types.NewUpgrade(counterpartyUpgradeFields, types.Timeout{}, 0), ); err != nil { return types.Channel{}, types.Upgrade{}, errorsmod.Wrap(err, "failed to verify counterparty upgrade") } @@ -769,6 +769,12 @@ func (k Keeper) startFlushing(ctx sdk.Context, portID, channelID string, upgrade channel.State = types.FLUSHING k.SetChannel(ctx, portID, channelID, channel) + nextSequenceSend, found := k.GetNextSequenceSend(ctx, portID, channelID) + if !found { + return errorsmod.Wrapf(types.ErrSequenceSendNotFound, "port ID (%s) channel ID (%s)", portID, channelID) + } + + upgrade.LatestSequenceSend = nextSequenceSend - 1 upgrade.Timeout = k.getAbsoluteUpgradeTimeout(ctx) k.SetUpgrade(ctx, portID, channelID, *upgrade) diff --git a/modules/core/04-channel/keeper/upgrade_test.go b/modules/core/04-channel/keeper/upgrade_test.go index 1b6ec37821c..177629d568f 100644 --- a/modules/core/04-channel/keeper/upgrade_test.go +++ b/modules/core/04-channel/keeper/upgrade_test.go @@ -300,7 +300,10 @@ func (suite *KeeperTestSuite) TestChanUpgradeTry() { suite.Require().NoError(err) suite.Require().NotEmpty(upgrade) suite.Require().Equal(proposedUpgrade.Fields, upgrade.Fields) - suite.Require().Equal(path.EndpointA.GetChannel().UpgradeSequence, path.EndpointB.GetChannel().UpgradeSequence) + + nextSequenceSend, found := path.EndpointB.Chain.GetSimApp().IBCKeeper.ChannelKeeper.GetNextSequenceSend(path.EndpointB.Chain.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) + suite.Require().True(found) + suite.Require().Equal(nextSequenceSend-1, upgrade.LatestSequenceSend) } else { suite.assertUpgradeError(err, tc.expError) } @@ -482,6 +485,14 @@ func (suite *KeeperTestSuite) TestChanUpgradeAck() { }, commitmenttypes.ErrInvalidProof, }, + { + "fails due to proof verification failure, counterparty update has unexpected sequence", + func() { + // Decrementing LatestSequenceSend is sufficient to cause the proof to fail. + counterpartyUpgrade.LatestSequenceSend-- + }, + commitmenttypes.ErrInvalidProof, + }, { "fails due to mismatch in upgrade ordering", func() { @@ -1824,6 +1835,15 @@ func (suite *KeeperTestSuite) TestStartFlush() { }, connectiontypes.ErrInvalidConnectionState, }, + { + "next sequence send not found", + func() { + // Delete next sequence send key from store + store := suite.chainB.GetContext().KVStore(suite.chainB.GetSimApp().GetKey(exported.StoreKey)) + store.Delete(host.NextSequenceSendKey(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)) + }, + types.ErrSequenceSendNotFound, + }, } for _, tc := range testCases { @@ -1857,7 +1877,12 @@ func (suite *KeeperTestSuite) TestStartFlush() { suite.assertUpgradeError(err, tc.expError) } else { channel := path.EndpointB.GetChannel() + + nextSequenceSend, ok := suite.chainB.GetSimApp().IBCKeeper.ChannelKeeper.GetNextSequenceSend(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) + suite.Require().True(ok) + suite.Require().Equal(types.FLUSHING, channel.State) + suite.Require().Equal(nextSequenceSend-1, upgrade.LatestSequenceSend) expectedTimeoutTimestamp := types.DefaultTimeout.Timestamp + uint64(suite.chainB.GetContext().BlockTime().UnixNano()) suite.Require().Equal(expectedTimeoutTimestamp, upgrade.Timeout.Timestamp) diff --git a/modules/core/04-channel/types/msgs_test.go b/modules/core/04-channel/types/msgs_test.go index ae8faa5a11e..5a7bec0c889 100644 --- a/modules/core/04-channel/types/msgs_test.go +++ b/modules/core/04-channel/types/msgs_test.go @@ -808,6 +808,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeAckValidateBasic() { upgrade := types.NewUpgrade( types.NewUpgradeFields(types.ORDERED, []string{ibctesting.FirstConnectionID}, mock.Version), types.NewTimeout(clienttypes.NewHeight(1, 100), 0), + 0, ) msg = types.NewMsgChannelUpgradeAck( @@ -834,6 +835,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeAckGetSigners() { upgrade := types.NewUpgrade( types.NewUpgradeFields(types.ORDERED, []string{ibctesting.FirstConnectionID}, mock.Version), types.NewTimeout(clienttypes.NewHeight(1, 100), 0), + 0, ) msg := types.NewMsgChannelUpgradeAck( @@ -919,6 +921,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeConfirmValidateBasic() { counterpartyUpgrade := types.NewUpgrade( types.NewUpgradeFields(types.UNORDERED, []string{ibctesting.FirstConnectionID}, mock.Version), types.NewTimeout(clienttypes.NewHeight(0, 10000), timeoutTimestamp), + 0, ) msg = types.NewMsgChannelUpgradeConfirm( diff --git a/modules/core/04-channel/types/upgrade.go b/modules/core/04-channel/types/upgrade.go index c3a861e860b..e60fc3f624b 100644 --- a/modules/core/04-channel/types/upgrade.go +++ b/modules/core/04-channel/types/upgrade.go @@ -12,10 +12,11 @@ import ( ) // NewUpgrade creates a new Upgrade instance. -func NewUpgrade(upgradeFields UpgradeFields, timeout Timeout) Upgrade { +func NewUpgrade(upgradeFields UpgradeFields, timeout Timeout, latestPacketSent uint64) Upgrade { return Upgrade{ - Fields: upgradeFields, - Timeout: timeout, + Fields: upgradeFields, + Timeout: timeout, + LatestSequenceSend: latestPacketSent, } } diff --git a/modules/core/04-channel/types/upgrade.pb.go b/modules/core/04-channel/types/upgrade.pb.go index 5a8fca81909..7764b163ff7 100644 --- a/modules/core/04-channel/types/upgrade.pb.go +++ b/modules/core/04-channel/types/upgrade.pb.go @@ -25,10 +25,13 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Upgrade is a verifiable type which contains the relevant information // for an attempted upgrade. It provides the proposed changes to the channel -// end and the timeout for this upgrade attempt. +// end, the timeout for this upgrade attempt and the latest packet sequence sent +// which allows the counterparty to efficiently know the highest sequence it has received. +// The latest sequence send is used for pruning and upgrading from unordered to ordered channels. type Upgrade struct { - Fields UpgradeFields `protobuf:"bytes,1,opt,name=fields,proto3" json:"fields"` - Timeout Timeout `protobuf:"bytes,2,opt,name=timeout,proto3" json:"timeout"` + Fields UpgradeFields `protobuf:"bytes,1,opt,name=fields,proto3" json:"fields"` + Timeout Timeout `protobuf:"bytes,2,opt,name=timeout,proto3" json:"timeout"` + LatestSequenceSend uint64 `protobuf:"varint,3,opt,name=latest_sequence_send,json=latestSequenceSend,proto3" json:"latest_sequence_send,omitempty"` } func (m *Upgrade) Reset() { *m = Upgrade{} } @@ -157,31 +160,33 @@ func init() { func init() { proto.RegisterFile("ibc/core/channel/v1/upgrade.proto", fileDescriptor_fb1cef68588848b2) } var fileDescriptor_fb1cef68588848b2 = []byte{ - // 378 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0xcf, 0xaa, 0xd3, 0x40, - 0x14, 0x87, 0x33, 0x6d, 0xe9, 0x9f, 0x51, 0x2b, 0x44, 0x17, 0x21, 0x48, 0x5a, 0xbb, 0xb1, 0x9b, - 0x66, 0x6c, 0x15, 0x51, 0x71, 0x21, 0x05, 0x45, 0xdc, 0x08, 0x51, 0x37, 0x6e, 0xa4, 0x99, 0x1c, - 0xd3, 0x81, 0x66, 0x4e, 0x9c, 0x49, 0x02, 0xbe, 0x81, 0x3b, 0xfb, 0x08, 0x3e, 0x4e, 0x97, 0x5d, - 0xba, 0x92, 0x4b, 0xfb, 0x22, 0x97, 0x4c, 0x92, 0x5e, 0x2e, 0x64, 0x37, 0x67, 0xe6, 0xfb, 0x7d, - 0xe7, 0x30, 0x87, 0x3e, 0x16, 0x21, 0x67, 0x1c, 0x15, 0x30, 0xbe, 0xdd, 0x48, 0x09, 0x3b, 0x56, - 0x2c, 0x59, 0x9e, 0xc6, 0x6a, 0x13, 0x81, 0x9f, 0x2a, 0xcc, 0xd0, 0x7e, 0x20, 0x42, 0xee, 0x97, - 0x88, 0x5f, 0x23, 0x7e, 0xb1, 0x74, 0x1f, 0xc6, 0x18, 0xa3, 0x79, 0x67, 0xe5, 0xa9, 0x42, 0xdd, - 0x56, 0x5b, 0x93, 0x32, 0xc8, 0xec, 0x0f, 0xa1, 0x83, 0xaf, 0x95, 0xdf, 0x7e, 0x4b, 0xfb, 0x3f, - 0x04, 0xec, 0x22, 0xed, 0x90, 0x29, 0x99, 0xdf, 0x59, 0xcd, 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 0x44, 0xc8, 0x17, 0x31, 0xb2, 0xe2, 0x25, 0x4b, 0x30, 0xca, 0x77, 0xa0, 0xab, 0x6d, 0x3e, 0x7d, - 0xbe, 0x68, 0x16, 0x9a, 0xfd, 0x4a, 0x41, 0x87, 0x7d, 0xb3, 0xcc, 0x67, 0xd7, 0x01, 0x00, 0x00, - 0xff, 0xff, 0xf9, 0xfb, 0x1a, 0x65, 0x3f, 0x02, 0x00, 0x00, + // 407 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x92, 0xc1, 0x6e, 0xd4, 0x30, + 0x10, 0x86, 0xe3, 0x76, 0xd5, 0xed, 0x1a, 0x28, 0x92, 0xe9, 0x21, 0x5a, 0xa1, 0x74, 0xd9, 0x0b, + 0x7b, 0x69, 0xdc, 0x16, 0x84, 0x00, 0x71, 0x40, 0x95, 0x40, 0x88, 0x0b, 0x92, 0x17, 0x2e, 0x5c, + 0x56, 0x1b, 0x67, 0xc8, 0x5a, 0x4a, 0x3c, 0xc1, 0x76, 0x22, 0xf1, 0x06, 0x1c, 0xfb, 0x08, 0xbc, + 0x0a, 0xb7, 0x1e, 0x7b, 0xe4, 0x84, 0xd0, 0xee, 0x8b, 0xa0, 0x38, 0x49, 0x11, 0x52, 0x6e, 0x99, + 0xcc, 0xf7, 0xff, 0xfe, 0xc7, 0x63, 0xfa, 0x48, 0x25, 0x92, 0x4b, 0x34, 0xc0, 0xe5, 0x66, 0xad, + 0x35, 0xe4, 0xbc, 0x3e, 0xe7, 0x55, 0x99, 0x99, 0x75, 0x0a, 0x71, 0x69, 0xd0, 0x21, 0x7b, 0xa0, + 0x12, 0x19, 0x37, 0x48, 0xdc, 0x21, 0x71, 0x7d, 0x3e, 0x3d, 0xce, 0x30, 0x43, 0xdf, 0xe7, 0xcd, + 0x57, 0x8b, 0x4e, 0x07, 0xdd, 0x7a, 0x95, 0x47, 0xe6, 0x3f, 0x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0x6b, + 0xd7, 0x19, 0xf8, 0x4b, 0x9b, 0x88, 0xbe, 0x6c, 0xbd, 0x2e, 0x97, 0xd7, 0xdb, 0x88, 0xdc, 0x6c, + 0x23, 0xf2, 0x67, 0x1b, 0x91, 0xab, 0x5d, 0x14, 0xdc, 0xec, 0xa2, 0xe0, 0xd7, 0x2e, 0x0a, 0x3e, + 0xbf, 0xc8, 0x94, 0xdb, 0x54, 0x49, 0x2c, 0xb1, 0xe0, 0x12, 0x6d, 0x81, 0x96, 0xab, 0x44, 0x9e, + 0x66, 0xc8, 0xeb, 0xe7, 0xbc, 0xc0, 0xb4, 0xca, 0xc1, 0xb6, 0xfb, 0x3f, 0x7b, 0x7a, 0xda, 0x3f, + 0x01, 0xf7, 0xad, 0x04, 0x9b, 0x1c, 0xf8, 0xf5, 0x3f, 0xf9, 0x1b, 0x00, 0x00, 0xff, 0xff, 0xc0, + 0xc7, 0xee, 0x2b, 0x71, 0x02, 0x00, 0x00, } func (m *Upgrade) Marshal() (dAtA []byte, err error) { @@ -204,6 +209,11 @@ func (m *Upgrade) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.LatestSequenceSend != 0 { + i = encodeVarintUpgrade(dAtA, i, uint64(m.LatestSequenceSend)) + i-- + dAtA[i] = 0x18 + } { size, err := m.Timeout.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -327,6 +337,9 @@ func (m *Upgrade) Size() (n int) { n += 1 + l + sovUpgrade(uint64(l)) l = m.Timeout.Size() n += 1 + l + sovUpgrade(uint64(l)) + if m.LatestSequenceSend != 0 { + n += 1 + sovUpgrade(uint64(m.LatestSequenceSend)) + } return n } @@ -469,6 +482,25 @@ func (m *Upgrade) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field LatestSequenceSend", wireType) + } + m.LatestSequenceSend = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowUpgrade + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.LatestSequenceSend |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipUpgrade(dAtA[iNdEx:]) diff --git a/modules/core/04-channel/types/upgrade_test.go b/modules/core/04-channel/types/upgrade_test.go index 2f6ce80d0c4..3bf7cf67d54 100644 --- a/modules/core/04-channel/types/upgrade_test.go +++ b/modules/core/04-channel/types/upgrade_test.go @@ -61,6 +61,7 @@ func (suite *TypesTestSuite) TestUpgradeValidateBasic() { upgrade = types.NewUpgrade( types.NewUpgradeFields(types.ORDERED, []string{ibctesting.FirstConnectionID}, mock.Version), types.NewTimeout(clienttypes.NewHeight(0, 100), 0), + 0, ) tc.malleate() diff --git a/proto/ibc/core/channel/v1/upgrade.proto b/proto/ibc/core/channel/v1/upgrade.proto index 0b04b81eda6..294a8b8c21e 100644 --- a/proto/ibc/core/channel/v1/upgrade.proto +++ b/proto/ibc/core/channel/v1/upgrade.proto @@ -9,12 +9,15 @@ import "ibc/core/channel/v1/channel.proto"; // Upgrade is a verifiable type which contains the relevant information // for an attempted upgrade. It provides the proposed changes to the channel -// end and the timeout for this upgrade attempt. +// end, the timeout for this upgrade attempt and the latest packet sequence sent +// which allows the counterparty to efficiently know the highest sequence it has received. +// The latest sequence send is used for pruning and upgrading from unordered to ordered channels. message Upgrade { option (gogoproto.goproto_getters) = false; - UpgradeFields fields = 1 [(gogoproto.nullable) = false]; - Timeout timeout = 2 [(gogoproto.nullable) = false]; + UpgradeFields fields = 1 [(gogoproto.nullable) = false]; + Timeout timeout = 2 [(gogoproto.nullable) = false]; + uint64 latest_sequence_send = 3; } // UpgradeFields are the fields in a channel end which may be changed diff --git a/testing/endpoint.go b/testing/endpoint.go index 042fac27402..80e7c4dcda8 100644 --- a/testing/endpoint.go +++ b/testing/endpoint.go @@ -868,7 +868,8 @@ func (endpoint *Endpoint) GetProposedUpgrade() channeltypes.Upgrade { ConnectionHops: []string{endpoint.ConnectionID}, Version: endpoint.ChannelConfig.Version, }, - Timeout: channeltypes.NewTimeout(endpoint.Counterparty.Chain.GetTimeoutHeight(), 0), + Timeout: channeltypes.NewTimeout(endpoint.Counterparty.Chain.GetTimeoutHeight(), 0), + LatestSequenceSend: 0, } override := endpoint.ChannelConfig.ProposedUpgrade