diff --git a/x/evidence/legacy/v038/types.go b/x/evidence/legacy/v038/types.go index f438e2bec562..994f718ca5fd 100644 --- a/x/evidence/legacy/v038/types.go +++ b/x/evidence/legacy/v038/types.go @@ -91,7 +91,7 @@ func (e Equivocation) Hash() tmbytes.HexBytes { // ValidateBasic performs basic stateless validation checks on an Equivocation object. func (e Equivocation) ValidateBasic() error { - if e.Time.IsZero() { + if e.Time.Unix() <= 0 { return fmt.Errorf("invalid equivocation time: %s", e.Time) } if e.Height < 1 { diff --git a/x/evidence/types/evidence.go b/x/evidence/types/evidence.go index 8558623baa67..95705cc5b937 100644 --- a/x/evidence/types/evidence.go +++ b/x/evidence/types/evidence.go @@ -43,7 +43,7 @@ func (e *Equivocation) Hash() tmbytes.HexBytes { // ValidateBasic performs basic stateless validation checks on an Equivocation object. func (e *Equivocation) ValidateBasic() error { - if e.Time.IsZero() { + if e.Time.Unix() <= 0 { return fmt.Errorf("invalid equivocation time: %s", e.Time) } if e.Height < 1 { diff --git a/x/ibc/light-clients/07-tendermint/types/consensus_state.go b/x/ibc/light-clients/07-tendermint/types/consensus_state.go index b581983944fd..adb469a3d108 100644 --- a/x/ibc/light-clients/07-tendermint/types/consensus_state.go +++ b/x/ibc/light-clients/07-tendermint/types/consensus_state.go @@ -48,11 +48,8 @@ func (cs ConsensusState) ValidateBasic() error { if err := tmtypes.ValidateHash(cs.NextValidatorsHash); err != nil { return sdkerrors.Wrap(err, "next validators hash is invalid") } - if cs.Timestamp.IsZero() { - return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "timestamp cannot be zero Unix time") - } - if cs.Timestamp.UnixNano() < 0 { - return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "timestamp cannot be negative Unix time") + if cs.Timestamp.Unix() <= 0 { + return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "timestamp must be a positive Unix time") } return nil } diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index 0cf619cf36fe..1092885bcb3f 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -60,7 +60,7 @@ func (k Keeper) ScheduleUpgrade(ctx sdk.Context, plan types.Plan) error { return err } - if !plan.Time.IsZero() { + if plan.Time.Unix() > 0 { if !plan.Time.After(ctx.BlockHeader().Time) { return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "upgrade cannot be scheduled in the past") } diff --git a/x/upgrade/legacy/v038/types.go b/x/upgrade/legacy/v038/types.go index fb06a6dc5a1c..db833477bf23 100644 --- a/x/upgrade/legacy/v038/types.go +++ b/x/upgrade/legacy/v038/types.go @@ -64,10 +64,11 @@ func (p Plan) ValidateBasic() error { if p.Height < 0 { 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") } - if !p.Time.IsZero() && p.Height != 0 { + if isValidTime && p.Height != 0 { 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 func (p Plan) ShouldExecute(ctx sdk.Context) bool { - if !p.Time.IsZero() { + if p.Time.Unix() > 0 { return !ctx.BlockTime().Before(p.Time) } 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 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("height: %d", p.Height) diff --git a/x/upgrade/types/plan.go b/x/upgrade/types/plan.go index 2cbacd60b0be..aa1a0601ffca 100644 --- a/x/upgrade/types/plan.go +++ b/x/upgrade/types/plan.go @@ -39,13 +39,13 @@ func (p Plan) ValidateBasic() error { if p.Height < 0 { 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") } - 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") } - 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") } @@ -54,7 +54,7 @@ func (p Plan) ValidateBasic() error { // ShouldExecute returns true if the Plan is ready to execute given the current context func (p Plan) ShouldExecute(ctx sdk.Context) bool { - if !p.Time.IsZero() { + if p.Time.Unix() > 0 { return !ctx.BlockTime().Before(p.Time) } 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 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("height: %d", p.Height)