-
Notifications
You must be signed in to change notification settings - Fork 679
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: add ValidateBasic for MsgSendPacket #7468
Merged
bznein
merged 1 commit into
feat/ibc-eureka
from
bznein/7466/MsgSendPacketValidateBasic
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" | ||
channeltypesv1 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" | ||
commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" | ||
host "github.com/cosmos/ibc-go/v9/modules/core/24-host" | ||
ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" | ||
|
@@ -81,6 +82,34 @@ func NewMsgSendPacket(sourceChannel string, timeoutTimestamp uint64, signer stri | |
} | ||
} | ||
|
||
// ValidateBasic performs basic checks on a MsgSendPacket. | ||
func (msg *MsgSendPacket) ValidateBasic() error { | ||
if err := host.ChannelIdentifierValidator(msg.SourceChannel); err != nil { | ||
return err | ||
} | ||
|
||
if msg.TimeoutTimestamp == 0 { | ||
return errorsmod.Wrap(channeltypesv1.ErrInvalidTimeout, "timeout must not be 0") | ||
} | ||
|
||
if len(msg.PacketData) != 1 { | ||
return errorsmod.Wrapf(ErrInvalidPacketData, "packet data must be of length 1, got %d instead", len(msg.PacketData)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. partially also addreses #7390 (can close it after validation is done for all msgs) |
||
} | ||
|
||
for _, pd := range msg.PacketData { | ||
if err := pd.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
_, err := sdk.AccAddressFromBech32(msg.Signer) | ||
if err != nil { | ||
return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// NewMsgRecvPacket creates a new MsgRecvPacket instance. | ||
func NewMsgRecvPacket(packet Packet, proofCommitment []byte, proofHeight clienttypes.Height, signer string) *MsgRecvPacket { | ||
return &MsgRecvPacket{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feels weird mixing these personally? Would prefer if we just moved over all errors (i.e dunno what the error code for this error is? it might conflict with one we define in
errors.go
for chan/v2)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We were discussing this with @chatton and thought about importing for now and then having a cleanup issue about moving everything to v2. Though I'm with doing it now if we prefer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perfectly fine with me as long as there's an issue to track it 💪