-
Notifications
You must be signed in to change notification settings - Fork 662
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add verifiable upgrade type and validate basic functions (#3451)
- Loading branch information
Showing
8 changed files
with
759 additions
and
27 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package types | ||
|
||
import ( | ||
"strings" | ||
|
||
errorsmod "cosmossdk.io/errors" | ||
|
||
"github.com/cosmos/ibc-go/v7/internal/collections" | ||
) | ||
|
||
// ValidateBasic performs a basic validation of the upgrade fields | ||
func (u Upgrade) ValidateBasic() error { | ||
if err := u.Fields.ValidateBasic(); err != nil { | ||
return errorsmod.Wrap(err, "proposed upgrade fields are invalid") | ||
} | ||
|
||
if !u.Timeout.IsValid() { | ||
return errorsmod.Wrap(ErrInvalidUpgrade, "upgrade timeout cannot be empty") | ||
} | ||
|
||
// TODO: determine if last packet sequence sent can be 0? | ||
return nil | ||
} | ||
|
||
// ValidateBasic performs a basic validation of the proposed upgrade fields | ||
func (uf UpgradeFields) ValidateBasic() error { | ||
if !collections.Contains(uf.Ordering, []Order{ORDERED, UNORDERED}) { | ||
return errorsmod.Wrap(ErrInvalidChannelOrdering, uf.Ordering.String()) | ||
} | ||
|
||
if len(uf.ConnectionHops) != 1 { | ||
return errorsmod.Wrap(ErrTooManyConnectionHops, "current IBC version only supports one connection hop") | ||
} | ||
|
||
if strings.TrimSpace(uf.Version) == "" { | ||
return errorsmod.Wrap(ErrInvalidChannelVersion, "version cannot be empty") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// IsValid returns true if either the height or timestamp is non-zero | ||
func (ut UpgradeTimeout) IsValid() bool { | ||
return !ut.TimeoutHeight.IsZero() || ut.TimeoutTimestamp != 0 | ||
} |
Oops, something went wrong.