Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove api breaks on backport for channel upgradability #5484

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion modules/core/04-channel/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
3 changes: 0 additions & 3 deletions modules/core/04-channel/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func TestValidateGenesis(t *testing.T) {
types.NewPacketSequence(testPort2, testChannel2, 1),
},
2,
types.Params{UpgradeTimeout: types.DefaultTimeout},
),
expPass: true,
},
Expand Down Expand Up @@ -172,7 +171,6 @@ func TestValidateGenesis(t *testing.T) {
types.NewPacketSequence(testPort2, testChannel2, 1),
},
0,
types.Params{UpgradeTimeout: types.DefaultTimeout},
),
expPass: false,
},
Expand Down Expand Up @@ -210,7 +208,6 @@ func TestValidateGenesis(t *testing.T) {
types.NewPacketSequence(testPort2, testChannel2, 1),
},
0,
types.Params{UpgradeTimeout: types.DefaultTimeout},
),
expPass: false,
},
Expand Down
43 changes: 42 additions & 1 deletion modules/core/04-channel/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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{
Expand Down
36 changes: 18 additions & 18 deletions modules/core/04-channel/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion modules/core/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions modules/core/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ func (suite *IBCTestSuite) TestValidateGenesis() {
channeltypes.NewPacketSequence(port2, channel2, 1),
},
0,
channeltypes.Params{UpgradeTimeout: channeltypes.DefaultTimeout},
),
},
expPass: true,
Expand Down Expand Up @@ -301,7 +300,6 @@ func (suite *IBCTestSuite) TestInitGenesis() {
channeltypes.NewPacketSequence(port2, channel2, 1),
},
0,
channeltypes.Params{UpgradeTimeout: channeltypes.DefaultTimeout},
),
},
},
Expand Down
2 changes: 1 addition & 1 deletion modules/core/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion testing/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions testing/solomachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading