From 1d783a282147c037a9bc1606c60e5f4a711cdd6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 21 Dec 2023 19:29:41 +0100 Subject: [PATCH] fix: remove api breaks on backport --- modules/core/04-channel/types/genesis.go | 21 ++++++++- modules/core/04-channel/types/genesis_test.go | 3 -- modules/core/04-channel/types/msgs.go | 43 ++++++++++++++++++- modules/core/04-channel/types/msgs_test.go | 36 ++++++++-------- modules/core/ante/ante_test.go | 2 +- modules/core/genesis_test.go | 2 - modules/core/keeper/msg_server_test.go | 2 +- testing/endpoint.go | 2 +- testing/solomachine.go | 2 - 9 files changed, 83 insertions(+), 30 deletions(-) diff --git a/modules/core/04-channel/types/genesis.go b/modules/core/04-channel/types/genesis.go index 371b55563fd..d95f24c35e6 100644 --- a/modules/core/04-channel/types/genesis.go +++ b/modules/core/04-channel/types/genesis.go @@ -41,10 +41,29 @@ func (ps PacketSequence) Validate() error { return validateGenFields(ps.PortId, ps.ChannelId, ps.Sequence) } -// NewGenesisState creates a GenesisState instance. +// NewGenesisState creates a GenesisState instance. It uses the default params. +// Breakage in v9.0.0 will allow the params to be provided. Please use +// NewGenesisStateWithParams in this version if you want to provide custom params. func NewGenesisState( channels []IdentifiedChannel, acks, receipts, commitments []PacketState, sendSeqs, recvSeqs, ackSeqs []PacketSequence, nextChannelSequence uint64, +) GenesisState { + return GenesisState{ + Channels: channels, + Acknowledgements: acks, + Commitments: commitments, + SendSequences: sendSeqs, + RecvSequences: recvSeqs, + AckSequences: ackSeqs, + NextChannelSequence: nextChannelSequence, + Params: DefaultParams(), + } +} + +// NewGenesisStateWithParams creates a GenesisState instance. +func NewGenesisStateWithParams( + channels []IdentifiedChannel, acks, receipts, commitments []PacketState, + sendSeqs, recvSeqs, ackSeqs []PacketSequence, nextChannelSequence uint64, params Params, ) GenesisState { return GenesisState{ diff --git a/modules/core/04-channel/types/genesis_test.go b/modules/core/04-channel/types/genesis_test.go index 957c79725a7..973f06b6b0c 100644 --- a/modules/core/04-channel/types/genesis_test.go +++ b/modules/core/04-channel/types/genesis_test.go @@ -67,7 +67,6 @@ func TestValidateGenesis(t *testing.T) { types.NewPacketSequence(testPort2, testChannel2, 1), }, 2, - types.Params{UpgradeTimeout: types.DefaultTimeout}, ), expPass: true, }, @@ -172,7 +171,6 @@ func TestValidateGenesis(t *testing.T) { types.NewPacketSequence(testPort2, testChannel2, 1), }, 0, - types.Params{UpgradeTimeout: types.DefaultTimeout}, ), expPass: false, }, @@ -210,7 +208,6 @@ func TestValidateGenesis(t *testing.T) { types.NewPacketSequence(testPort2, testChannel2, 1), }, 0, - types.Params{UpgradeTimeout: types.DefaultTimeout}, ), expPass: false, }, diff --git a/modules/core/04-channel/types/msgs.go b/modules/core/04-channel/types/msgs.go index ebb211b3d72..cbbfec4dc66 100644 --- a/modules/core/04-channel/types/msgs.go +++ b/modules/core/04-channel/types/msgs.go @@ -270,7 +270,26 @@ func (msg MsgChannelCloseInit) GetSigners() []sdk.AccAddress { } // NewMsgChannelCloseConfirm creates a new MsgChannelCloseConfirm instance +// Breakage in v9.0.0 will allow for the counterparty upgrade sequence to be provided. +// Please use NewMsgChannelCloseConfirmWithCounterpartyUpgradeSequence to provide the +// counterparty upgrade sequence in this version. func NewMsgChannelCloseConfirm( + portID, channelID string, proofInit []byte, proofHeight clienttypes.Height, + signer string, +) *MsgChannelCloseConfirm { + return &MsgChannelCloseConfirm{ + PortId: portID, + ChannelId: channelID, + ProofInit: proofInit, + ProofHeight: proofHeight, + Signer: signer, + CounterpartyUpgradeSequence: 0, + } +} + +// NewMsgChannelCloseConfirmWithCounterpartyUpgradeSequence creates a new MsgChannelCloseConfirm instance +// with a non-zero counterparty upgrade sequence. +func NewMsgChannelCloseConfirmWithCounterpartyUpgradeSequence( portID, channelID string, proofInit []byte, proofHeight clienttypes.Height, signer string, counterpartyUpgradeSequence uint64, ) *MsgChannelCloseConfirm { @@ -390,11 +409,33 @@ func (msg MsgTimeout) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{signer} } -// NewMsgTimeoutOnClose constructs new MsgTimeoutOnClose +// NewMsgTimeoutOnClose constructs a new MsgTimeoutOnClose. +// The counterparty upgrade sequence is set to 0. Breakage in +// v9.0.0 will allow the counterparty upgrade sequence to be provided. +// Please use NewMsgTimeoutOnCloseWithCounterpartyUpgradeSequence in this version +// to provide the counterparty upgrade sequence. func NewMsgTimeoutOnClose( packet Packet, nextSequenceRecv uint64, proofUnreceived, proofClose []byte, proofHeight clienttypes.Height, signer string, +) *MsgTimeoutOnClose { + return &MsgTimeoutOnClose{ + Packet: packet, + NextSequenceRecv: nextSequenceRecv, + ProofUnreceived: proofUnreceived, + ProofClose: proofClose, + ProofHeight: proofHeight, + Signer: signer, + CounterpartyUpgradeSequence: 0, + } +} + +// NewMsgTimeoutOnCloseWithCounterpartyUpgradeSequence constructs a new MsgTimeoutOnClose +// with the provided counterparty upgrade sequence. +func NewMsgTimeoutOnCloseWithCounterpartyUpgradeSequence( + packet Packet, nextSequenceRecv uint64, + proofUnreceived, proofClose []byte, + proofHeight clienttypes.Height, signer string, counterpartyUpgradeSequence uint64, ) *MsgTimeoutOnClose { return &MsgTimeoutOnClose{ diff --git a/modules/core/04-channel/types/msgs_test.go b/modules/core/04-channel/types/msgs_test.go index 5a7bec0c889..f0dc4e46d99 100644 --- a/modules/core/04-channel/types/msgs_test.go +++ b/modules/core/04-channel/types/msgs_test.go @@ -353,15 +353,15 @@ func (suite *TypesTestSuite) TestMsgChannelCloseConfirmValidateBasic() { msg *types.MsgChannelCloseConfirm expPass bool }{ - {"success", types.NewMsgChannelCloseConfirm(portid, chanid, suite.proof, height, addr, 0), true}, - {"success, positive counterparty upgrade sequence", types.NewMsgChannelCloseConfirm(portid, chanid, suite.proof, height, addr, 1), true}, - {"too short port id", types.NewMsgChannelCloseConfirm(invalidShortPort, chanid, suite.proof, height, addr, 0), false}, - {"too long port id", types.NewMsgChannelCloseConfirm(invalidLongPort, chanid, suite.proof, height, addr, 0), false}, - {"port id contains non-alpha", types.NewMsgChannelCloseConfirm(invalidPort, chanid, suite.proof, height, addr, 0), false}, - {"too short channel id", types.NewMsgChannelCloseConfirm(portid, invalidShortChannel, suite.proof, height, addr, 0), false}, - {"too long channel id", types.NewMsgChannelCloseConfirm(portid, invalidLongChannel, suite.proof, height, addr, 0), false}, - {"channel id contains non-alpha", types.NewMsgChannelCloseConfirm(portid, invalidChannel, suite.proof, height, addr, 0), false}, - {"empty proof", types.NewMsgChannelCloseConfirm(portid, chanid, emptyProof, height, addr, 0), false}, + {"success", types.NewMsgChannelCloseConfirm(portid, chanid, suite.proof, height, addr), true}, + {"success, positive counterparty upgrade sequence", types.NewMsgChannelCloseConfirmWithCounterpartyUpgradeSequence(portid, chanid, suite.proof, height, addr, 1), true}, + {"too short port id", types.NewMsgChannelCloseConfirm(invalidShortPort, chanid, suite.proof, height, addr), false}, + {"too long port id", types.NewMsgChannelCloseConfirm(invalidLongPort, chanid, suite.proof, height, addr), false}, + {"port id contains non-alpha", types.NewMsgChannelCloseConfirm(invalidPort, chanid, suite.proof, height, addr), false}, + {"too short channel id", types.NewMsgChannelCloseConfirm(portid, invalidShortChannel, suite.proof, height, addr), false}, + {"too long channel id", types.NewMsgChannelCloseConfirm(portid, invalidLongChannel, suite.proof, height, addr), false}, + {"channel id contains non-alpha", types.NewMsgChannelCloseConfirm(portid, invalidChannel, suite.proof, height, addr), false}, + {"empty proof", types.NewMsgChannelCloseConfirm(portid, chanid, emptyProof, height, addr), false}, } for _, tc := range testCases { @@ -382,7 +382,7 @@ func (suite *TypesTestSuite) TestMsgChannelCloseConfirmValidateBasic() { func (suite *TypesTestSuite) TestMsgChannelCloseConfirmGetSigners() { expSigner, err := sdk.AccAddressFromBech32(addr) suite.Require().NoError(err) - msg := types.NewMsgChannelCloseConfirm(portid, chanid, suite.proof, height, addr, counterpartyUpgradeSequence) + msg := types.NewMsgChannelCloseConfirm(portid, chanid, suite.proof, height, addr) encodingCfg := moduletestutil.MakeTestEncodingConfig(ibc.AppModuleBasic{}) signers, _, err := encodingCfg.Codec.GetMsgV1Signers(msg) @@ -476,13 +476,13 @@ func (suite *TypesTestSuite) TestMsgTimeoutOnCloseValidateBasic() { msg *types.MsgTimeoutOnClose expPass bool }{ - {"success", types.NewMsgTimeoutOnClose(packet, 1, suite.proof, suite.proof, height, addr, 0), true}, - {"success, positive counterparty upgrade sequence", types.NewMsgTimeoutOnClose(packet, 1, suite.proof, suite.proof, height, addr, 1), true}, - {"seq 0", types.NewMsgTimeoutOnClose(packet, 0, suite.proof, suite.proof, height, addr, 0), false}, - {"signer address is empty", types.NewMsgTimeoutOnClose(packet, 1, suite.proof, suite.proof, height, emptyAddr, 0), false}, - {"empty proof", types.NewMsgTimeoutOnClose(packet, 1, emptyProof, suite.proof, height, addr, 0), false}, - {"empty proof close", types.NewMsgTimeoutOnClose(packet, 1, suite.proof, emptyProof, height, addr, 0), false}, - {"invalid packet", types.NewMsgTimeoutOnClose(invalidPacket, 1, suite.proof, suite.proof, height, addr, 0), false}, + {"success", types.NewMsgTimeoutOnClose(packet, 1, suite.proof, suite.proof, height, addr), true}, + {"success, positive counterparty upgrade sequence", types.NewMsgTimeoutOnCloseWithCounterpartyUpgradeSequence(packet, 1, suite.proof, suite.proof, height, addr, 1), true}, + {"seq 0", types.NewMsgTimeoutOnClose(packet, 0, suite.proof, suite.proof, height, addr), false}, + {"signer address is empty", types.NewMsgTimeoutOnClose(packet, 1, suite.proof, suite.proof, height, emptyAddr), false}, + {"empty proof", types.NewMsgTimeoutOnClose(packet, 1, emptyProof, suite.proof, height, addr), false}, + {"empty proof close", types.NewMsgTimeoutOnClose(packet, 1, suite.proof, emptyProof, height, addr), false}, + {"invalid packet", types.NewMsgTimeoutOnClose(invalidPacket, 1, suite.proof, suite.proof, height, addr), false}, } for _, tc := range testCases { @@ -503,7 +503,7 @@ func (suite *TypesTestSuite) TestMsgTimeoutOnCloseValidateBasic() { func (suite *TypesTestSuite) TestMsgTimeoutOnCloseGetSigners() { expSigner, err := sdk.AccAddressFromBech32(addr) suite.Require().NoError(err) - msg := types.NewMsgTimeoutOnClose(packet, 1, suite.proof, suite.proof, height, addr, counterpartyUpgradeSequence) + msg := types.NewMsgTimeoutOnClose(packet, 1, suite.proof, suite.proof, height, addr) encodingCfg := moduletestutil.MakeTestEncodingConfig(ibc.AppModuleBasic{}) signers, _, err := encodingCfg.Codec.GetMsgV1Signers(msg) diff --git a/modules/core/ante/ante_test.go b/modules/core/ante/ante_test.go index 734d71cc290..1b9a8c15c64 100644 --- a/modules/core/ante/ante_test.go +++ b/modules/core/ante/ante_test.go @@ -147,7 +147,7 @@ func (suite *AnteTestSuite) createTimeoutOnCloseMessage(isRedundant bool) sdk.Ms channelKey := host.ChannelKey(packet.GetDestPort(), packet.GetDestChannel()) proofClosed, _ := suite.chainA.QueryProof(channelKey) - return channeltypes.NewMsgTimeoutOnClose(packet, 1, proof, proofClosed, proofHeight, suite.path.EndpointA.Chain.SenderAccount.GetAddress().String(), 0) + return channeltypes.NewMsgTimeoutOnClose(packet, 1, proof, proofClosed, proofHeight, suite.path.EndpointA.Chain.SenderAccount.GetAddress().String()) } func (suite *AnteTestSuite) createUpdateClientMessage() sdk.Msg { diff --git a/modules/core/genesis_test.go b/modules/core/genesis_test.go index be1eb909678..3f6515573c7 100644 --- a/modules/core/genesis_test.go +++ b/modules/core/genesis_test.go @@ -142,7 +142,6 @@ func (suite *IBCTestSuite) TestValidateGenesis() { channeltypes.NewPacketSequence(port2, channel2, 1), }, 0, - channeltypes.Params{UpgradeTimeout: channeltypes.DefaultTimeout}, ), }, expPass: true, @@ -301,7 +300,6 @@ func (suite *IBCTestSuite) TestInitGenesis() { channeltypes.NewPacketSequence(port2, channel2, 1), }, 0, - channeltypes.Params{UpgradeTimeout: channeltypes.DefaultTimeout}, ), }, }, diff --git a/modules/core/keeper/msg_server_test.go b/modules/core/keeper/msg_server_test.go index ee8444514e5..6ae1f45af1a 100644 --- a/modules/core/keeper/msg_server_test.go +++ b/modules/core/keeper/msg_server_test.go @@ -718,7 +718,7 @@ func (suite *KeeperTestSuite) TestHandleTimeoutOnClosePacket() { channelKey := host.ChannelKey(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) proofClosed, _ := suite.chainB.QueryProof(channelKey) - msg := channeltypes.NewMsgTimeoutOnClose(packet, 1, proof, proofClosed, proofHeight, suite.chainA.SenderAccount.GetAddress().String(), counterpartyUpgradeSequence) + msg := channeltypes.NewMsgTimeoutOnCloseWithCounterpartyUpgradeSequence(packet, 1, proof, proofClosed, proofHeight, suite.chainA.SenderAccount.GetAddress().String(), counterpartyUpgradeSequence) _, err := keeper.Keeper.TimeoutOnClose(*suite.chainA.App.GetIBCKeeper(), suite.chainA.GetContext(), msg) diff --git a/testing/endpoint.go b/testing/endpoint.go index 3c73c9c162b..f84e5ae70f6 100644 --- a/testing/endpoint.go +++ b/testing/endpoint.go @@ -561,7 +561,7 @@ func (endpoint *Endpoint) TimeoutOnClose(packet channeltypes.Packet) error { nextSeqRecv, found := endpoint.Counterparty.Chain.App.GetIBCKeeper().ChannelKeeper.GetNextSequenceRecv(endpoint.Counterparty.Chain.GetContext(), endpoint.ChannelConfig.PortID, endpoint.ChannelID) require.True(endpoint.Chain.TB, found) - timeoutOnCloseMsg := channeltypes.NewMsgTimeoutOnClose( + timeoutOnCloseMsg := channeltypes.NewMsgTimeoutOnCloseWithCounterpartyUpgradeSequence( packet, nextSeqRecv, proof, proofClosed, proofHeight, endpoint.Chain.SenderAccount.GetAddress().String(), endpoint.Counterparty.GetChannel().UpgradeSequence, diff --git a/testing/solomachine.go b/testing/solomachine.go index 81eb087f6bc..2293f285bec 100644 --- a/testing/solomachine.go +++ b/testing/solomachine.go @@ -358,7 +358,6 @@ func (solo *Solomachine) ChanCloseConfirm(chain *TestChain, portID, channelID st proofInit, clienttypes.ZeroHeight(), chain.SenderAccount.GetAddress().String(), - 0, // use default value for channel that hasn't undergone an upgrade ) res, err := chain.SendMsgs(msgChanCloseConfirm) @@ -450,7 +449,6 @@ func (solo *Solomachine) TimeoutPacketOnClose(chain *TestChain, packet channelty proofClosed, clienttypes.ZeroHeight(), chain.SenderAccount.GetAddress().String(), - 0, // use default value for channel that hasn't undergone an upgrade ) res, err := chain.SendMsgs(msgTimeout)