8058 fix zero time checks (#8282)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
parent
5113effd24
commit
2c611b5706
|
@ -91,7 +91,7 @@ func (e Equivocation) Hash() tmbytes.HexBytes {
|
||||||
|
|
||||||
// ValidateBasic performs basic stateless validation checks on an Equivocation object.
|
// ValidateBasic performs basic stateless validation checks on an Equivocation object.
|
||||||
func (e Equivocation) ValidateBasic() error {
|
func (e Equivocation) ValidateBasic() error {
|
||||||
if e.Time.IsZero() {
|
if e.Time.Unix() <= 0 {
|
||||||
return fmt.Errorf("invalid equivocation time: %s", e.Time)
|
return fmt.Errorf("invalid equivocation time: %s", e.Time)
|
||||||
}
|
}
|
||||||
if e.Height < 1 {
|
if e.Height < 1 {
|
||||||
|
|
|
@ -43,7 +43,7 @@ func (e *Equivocation) Hash() tmbytes.HexBytes {
|
||||||
|
|
||||||
// ValidateBasic performs basic stateless validation checks on an Equivocation object.
|
// ValidateBasic performs basic stateless validation checks on an Equivocation object.
|
||||||
func (e *Equivocation) ValidateBasic() error {
|
func (e *Equivocation) ValidateBasic() error {
|
||||||
if e.Time.IsZero() {
|
if e.Time.Unix() <= 0 {
|
||||||
return fmt.Errorf("invalid equivocation time: %s", e.Time)
|
return fmt.Errorf("invalid equivocation time: %s", e.Time)
|
||||||
}
|
}
|
||||||
if e.Height < 1 {
|
if e.Height < 1 {
|
||||||
|
|
|
@ -48,11 +48,8 @@ func (cs ConsensusState) ValidateBasic() error {
|
||||||
if err := tmtypes.ValidateHash(cs.NextValidatorsHash); err != nil {
|
if err := tmtypes.ValidateHash(cs.NextValidatorsHash); err != nil {
|
||||||
return sdkerrors.Wrap(err, "next validators hash is invalid")
|
return sdkerrors.Wrap(err, "next validators hash is invalid")
|
||||||
}
|
}
|
||||||
if cs.Timestamp.IsZero() {
|
if cs.Timestamp.Unix() <= 0 {
|
||||||
return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "timestamp cannot be zero Unix time")
|
return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "timestamp must be a positive Unix time")
|
||||||
}
|
|
||||||
if cs.Timestamp.UnixNano() < 0 {
|
|
||||||
return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "timestamp cannot be negative Unix time")
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ func (k Keeper) ScheduleUpgrade(ctx sdk.Context, plan types.Plan) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !plan.Time.IsZero() {
|
if plan.Time.Unix() > 0 {
|
||||||
if !plan.Time.After(ctx.BlockHeader().Time) {
|
if !plan.Time.After(ctx.BlockHeader().Time) {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "upgrade cannot be scheduled in the past")
|
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "upgrade cannot be scheduled in the past")
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,10 +64,11 @@ func (p Plan) ValidateBasic() error {
|
||||||
if p.Height < 0 {
|
if p.Height < 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "height cannot be negative")
|
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "height cannot be negative")
|
||||||
}
|
}
|
||||||
if p.Time.IsZero() && p.Height == 0 {
|
isValidTime := p.Time.Unix() > 0
|
||||||
|
if !isValidTime && p.Height == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "must set either time or height")
|
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "must set either time or height")
|
||||||
}
|
}
|
||||||
if !p.Time.IsZero() && p.Height != 0 {
|
if isValidTime && p.Height != 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "cannot set both time and height")
|
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "cannot set both time and height")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +77,7 @@ func (p Plan) ValidateBasic() error {
|
||||||
|
|
||||||
// ShouldExecute returns true if the Plan is ready to execute given the current context
|
// ShouldExecute returns true if the Plan is ready to execute given the current context
|
||||||
func (p Plan) ShouldExecute(ctx sdk.Context) bool {
|
func (p Plan) ShouldExecute(ctx sdk.Context) bool {
|
||||||
if !p.Time.IsZero() {
|
if p.Time.Unix() > 0 {
|
||||||
return !ctx.BlockTime().Before(p.Time)
|
return !ctx.BlockTime().Before(p.Time)
|
||||||
}
|
}
|
||||||
if p.Height > 0 {
|
if p.Height > 0 {
|
||||||
|
@ -87,7 +88,7 @@ func (p Plan) ShouldExecute(ctx sdk.Context) bool {
|
||||||
|
|
||||||
// DueAt is a string representation of when this plan is due to be executed
|
// DueAt is a string representation of when this plan is due to be executed
|
||||||
func (p Plan) DueAt() string {
|
func (p Plan) DueAt() string {
|
||||||
if !p.Time.IsZero() {
|
if p.Time.Unix() > 0 {
|
||||||
return fmt.Sprintf("time: %s", p.Time.UTC().Format(time.RFC3339))
|
return fmt.Sprintf("time: %s", p.Time.UTC().Format(time.RFC3339))
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("height: %d", p.Height)
|
return fmt.Sprintf("height: %d", p.Height)
|
||||||
|
|
|
@ -39,13 +39,13 @@ func (p Plan) ValidateBasic() error {
|
||||||
if p.Height < 0 {
|
if p.Height < 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "height cannot be negative")
|
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "height cannot be negative")
|
||||||
}
|
}
|
||||||
if p.Time.IsZero() && p.Height == 0 {
|
if p.Time.Unix() <= 0 && p.Height == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "must set either time or height")
|
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "must set either time or height")
|
||||||
}
|
}
|
||||||
if !p.Time.IsZero() && p.Height != 0 {
|
if p.Time.Unix() > 0 && p.Height != 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "cannot set both time and height")
|
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "cannot set both time and height")
|
||||||
}
|
}
|
||||||
if !p.Time.IsZero() && p.UpgradedClientState != nil {
|
if p.Time.Unix() > 0 && p.UpgradedClientState != nil {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "IBC chain upgrades must only set height")
|
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "IBC chain upgrades must only set height")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ func (p Plan) ValidateBasic() error {
|
||||||
|
|
||||||
// ShouldExecute returns true if the Plan is ready to execute given the current context
|
// ShouldExecute returns true if the Plan is ready to execute given the current context
|
||||||
func (p Plan) ShouldExecute(ctx sdk.Context) bool {
|
func (p Plan) ShouldExecute(ctx sdk.Context) bool {
|
||||||
if !p.Time.IsZero() {
|
if p.Time.Unix() > 0 {
|
||||||
return !ctx.BlockTime().Before(p.Time)
|
return !ctx.BlockTime().Before(p.Time)
|
||||||
}
|
}
|
||||||
if p.Height > 0 {
|
if p.Height > 0 {
|
||||||
|
@ -65,7 +65,7 @@ func (p Plan) ShouldExecute(ctx sdk.Context) bool {
|
||||||
|
|
||||||
// DueAt is a string representation of when this plan is due to be executed
|
// DueAt is a string representation of when this plan is due to be executed
|
||||||
func (p Plan) DueAt() string {
|
func (p Plan) DueAt() string {
|
||||||
if !p.Time.IsZero() {
|
if p.Time.Unix() > 0 {
|
||||||
return fmt.Sprintf("time: %s", p.Time.UTC().Format(time.RFC3339))
|
return fmt.Sprintf("time: %s", p.Time.UTC().Format(time.RFC3339))
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("height: %d", p.Height)
|
return fmt.Sprintf("height: %d", p.Height)
|
||||||
|
|
Loading…
Reference in New Issue