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

chore: adding MsgChannelUpgradeTimeout fields and sdk.Msg interface impl #1830

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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
12 changes: 12 additions & 0 deletions docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -3141,6 +3141,18 @@ MsgChannelUpgradeInitResponse defines the MsgChannelUpgradeInit response type
MsgChannelUpgradeTimeout defines the request type for the ChannelUpgradeTimeout rpc


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `port_id` | [string](#string) | | |
| `channel_id` | [string](#string) | | |
| `counterparty_channel` | [Channel](#ibc.core.channel.v1.Channel) | | |
| `previous_error_receipt` | [ErrorReceipt](#ibc.core.channel.v1.ErrorReceipt) | | |
| `proof_channel` | [bytes](#bytes) | | |
| `proof_error_receipt` | [bytes](#bytes) | | |
| `proof_height` | [ibc.core.client.v1.Height](#ibc.core.client.v1.Height) | | |
| `signer` | [string](#string) | | |





Expand Down
54 changes: 50 additions & 4 deletions modules/core/04-channel/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,18 +571,64 @@ var _ sdk.Msg = &MsgChannelUpgradeTimeout{}

// NewMsgChannelUpgradeTimeout constructs a new MsgChannelUpgradeTimeout
// nolint:interfacer
func NewMsgChannelUpgradeTimeout() *MsgChannelUpgradeTimeout {
return &MsgChannelUpgradeTimeout{}
func NewMsgChannelUpgradeTimeout(
portID, channelID string,
counterpartyChannel Channel,
errorReceipt ErrorReceipt,
proofChannel, proofErrorReceipt []byte,
proofHeight clienttypes.Height,
signer string,
) *MsgChannelUpgradeTimeout {
return &MsgChannelUpgradeTimeout{
PortId: portID,
ChannelId: channelID,
CounterpartyChannel: counterpartyChannel,
PreviousErrorReceipt: errorReceipt,
ProofChannel: proofChannel,
ProofErrorReceipt: proofErrorReceipt,
ProofHeight: proofHeight,
Signer: signer,
}
}

// ValidateBasic implements sdk.Msg
func (msg MsgChannelUpgradeTimeout) ValidateBasic() error {
return errors.New("error method not implemented")
if err := host.PortIdentifierValidator(msg.PortId); err != nil {
return sdkerrors.Wrap(err, "invalid port ID")
}

if !IsValidChannelID(msg.ChannelId) {
return ErrInvalidChannelIdentifier
}

if len(msg.ProofChannel) == 0 {
return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof")
}

if msg.ProofHeight.IsZero() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "proof height must be non-zero")
}

if msg.CounterpartyChannel.State != OPEN {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could the counterparty channel state be in INITUPGRADE (crossing hellos?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know crossing hellos are no longer supported, and won't be for channel upgrades?
cc. @AdityaSripal

return sdkerrors.Wrapf(ErrInvalidChannelState, "expected: %s, got: %s", OPEN, msg.CounterpartyChannel.State)
}
Comment on lines +804 to +806
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AdityaSripal do you think there's any additional checks we need to perform on the counterparty channel?
Maybe check the channel version is not empty?


_, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err)
}

return nil
}

// GetSigners implements sdk.Msg
func (msg MsgChannelUpgradeTimeout) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{}
signer, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
panic(err)
}

return []sdk.AccAddress{signer}
}

var _ sdk.Msg = &MsgChannelUpgradeCancel{}
Expand Down
93 changes: 93 additions & 0 deletions modules/core/04-channel/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,99 @@ func (suite *TypesTestSuite) TestMsgAcknowledgementValidateBasic() {
}
}

func (suite *TypesTestSuite) TestMsgChannelUpgradeTimeoutValidateBasic() {
var msg *types.MsgChannelUpgradeTimeout

testCases := []struct {
name string
malleate func()
expPass bool
}{
{
"success",
func() {},
true,
},
{
"invalid port identifier",
func() {
msg.PortId = invalidPort
},
false,
},
{
"invalid channel identifier",
func() {
msg.ChannelId = invalidChannel
},
false,
},
{
"cannot submit an empty proof",
func() {
msg.ProofChannel = emptyProof
},
false,
},
{
"proof height must be > 0",
func() {
msg.ProofHeight = clienttypes.ZeroHeight()
},
false,
},
{
"invalid counterparty channel state",
func() {
msg.CounterpartyChannel.State = types.TRYUPGRADE
},
false,
},
{
"missing signer address",
func() {
msg.Signer = emptyAddr
},
false,
},
}

for _, tc := range testCases {
tc := tc
suite.Run(tc.name, func() {
msg = types.NewMsgChannelUpgradeTimeout(
ibctesting.MockPort, ibctesting.FirstChannelID,
types.Channel{State: types.OPEN}, types.ErrorReceipt{},
suite.proof, suite.proof,
height, addr,
)

tc.malleate()
err := msg.ValidateBasic()

if tc.expPass {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
}
})
}
}

func (suite *TypesTestSuite) TestMsgChannelUpgradeTimeoutGetSigners() {
expSigner, err := sdk.AccAddressFromBech32(addr)
suite.Require().NoError(err)

msg := types.NewMsgChannelUpgradeTimeout(
ibctesting.MockPort, ibctesting.FirstChannelID,
types.Channel{}, types.ErrorReceipt{},
suite.proof, suite.proof,
height, addr,
)

suite.Require().Equal([]sdk.AccAddress{expSigner}, msg.GetSigners())
}

func (suite *TypesTestSuite) TestMsgChannelUpgradeCancelValidateBasic() {
var msg *types.MsgChannelUpgradeCancel

Expand Down
Loading