Skip to content

Commit 2c611b5

Browse files
8058 fix zero time checks (#8282)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 5113eff commit 2c611b5

File tree

6 files changed

+15
-17
lines changed

6 files changed

+15
-17
lines changed

x/evidence/legacy/v038/types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (e Equivocation) Hash() tmbytes.HexBytes {
9191

9292
// ValidateBasic performs basic stateless validation checks on an Equivocation object.
9393
func (e Equivocation) ValidateBasic() error {
94-
if e.Time.IsZero() {
94+
if e.Time.Unix() <= 0 {
9595
return fmt.Errorf("invalid equivocation time: %s", e.Time)
9696
}
9797
if e.Height < 1 {

x/evidence/types/evidence.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (e *Equivocation) Hash() tmbytes.HexBytes {
4343

4444
// ValidateBasic performs basic stateless validation checks on an Equivocation object.
4545
func (e *Equivocation) ValidateBasic() error {
46-
if e.Time.IsZero() {
46+
if e.Time.Unix() <= 0 {
4747
return fmt.Errorf("invalid equivocation time: %s", e.Time)
4848
}
4949
if e.Height < 1 {

x/ibc/light-clients/07-tendermint/types/consensus_state.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,8 @@ func (cs ConsensusState) ValidateBasic() error {
4848
if err := tmtypes.ValidateHash(cs.NextValidatorsHash); err != nil {
4949
return sdkerrors.Wrap(err, "next validators hash is invalid")
5050
}
51-
if cs.Timestamp.IsZero() {
52-
return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "timestamp cannot be zero Unix time")
53-
}
54-
if cs.Timestamp.UnixNano() < 0 {
55-
return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "timestamp cannot be negative Unix time")
51+
if cs.Timestamp.Unix() <= 0 {
52+
return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "timestamp must be a positive Unix time")
5653
}
5754
return nil
5855
}

x/upgrade/keeper/keeper.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (k Keeper) ScheduleUpgrade(ctx sdk.Context, plan types.Plan) error {
6060
return err
6161
}
6262

63-
if !plan.Time.IsZero() {
63+
if plan.Time.Unix() > 0 {
6464
if !plan.Time.After(ctx.BlockHeader().Time) {
6565
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "upgrade cannot be scheduled in the past")
6666
}

x/upgrade/legacy/v038/types.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ func (p Plan) ValidateBasic() error {
6464
if p.Height < 0 {
6565
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "height cannot be negative")
6666
}
67-
if p.Time.IsZero() && p.Height == 0 {
67+
isValidTime := p.Time.Unix() > 0
68+
if !isValidTime && p.Height == 0 {
6869
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "must set either time or height")
6970
}
70-
if !p.Time.IsZero() && p.Height != 0 {
71+
if isValidTime && p.Height != 0 {
7172
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "cannot set both time and height")
7273
}
7374

@@ -76,7 +77,7 @@ func (p Plan) ValidateBasic() error {
7677

7778
// ShouldExecute returns true if the Plan is ready to execute given the current context
7879
func (p Plan) ShouldExecute(ctx sdk.Context) bool {
79-
if !p.Time.IsZero() {
80+
if p.Time.Unix() > 0 {
8081
return !ctx.BlockTime().Before(p.Time)
8182
}
8283
if p.Height > 0 {
@@ -87,7 +88,7 @@ func (p Plan) ShouldExecute(ctx sdk.Context) bool {
8788

8889
// DueAt is a string representation of when this plan is due to be executed
8990
func (p Plan) DueAt() string {
90-
if !p.Time.IsZero() {
91+
if p.Time.Unix() > 0 {
9192
return fmt.Sprintf("time: %s", p.Time.UTC().Format(time.RFC3339))
9293
}
9394
return fmt.Sprintf("height: %d", p.Height)

x/upgrade/types/plan.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ func (p Plan) ValidateBasic() error {
3939
if p.Height < 0 {
4040
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "height cannot be negative")
4141
}
42-
if p.Time.IsZero() && p.Height == 0 {
42+
if p.Time.Unix() <= 0 && p.Height == 0 {
4343
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "must set either time or height")
4444
}
45-
if !p.Time.IsZero() && p.Height != 0 {
45+
if p.Time.Unix() > 0 && p.Height != 0 {
4646
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "cannot set both time and height")
4747
}
48-
if !p.Time.IsZero() && p.UpgradedClientState != nil {
48+
if p.Time.Unix() > 0 && p.UpgradedClientState != nil {
4949
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "IBC chain upgrades must only set height")
5050
}
5151

@@ -54,7 +54,7 @@ func (p Plan) ValidateBasic() error {
5454

5555
// ShouldExecute returns true if the Plan is ready to execute given the current context
5656
func (p Plan) ShouldExecute(ctx sdk.Context) bool {
57-
if !p.Time.IsZero() {
57+
if p.Time.Unix() > 0 {
5858
return !ctx.BlockTime().Before(p.Time)
5959
}
6060
if p.Height > 0 {
@@ -65,7 +65,7 @@ func (p Plan) ShouldExecute(ctx sdk.Context) bool {
6565

6666
// DueAt is a string representation of when this plan is due to be executed
6767
func (p Plan) DueAt() string {
68-
if !p.Time.IsZero() {
68+
if p.Time.Unix() > 0 {
6969
return fmt.Sprintf("time: %s", p.Time.UTC().Format(time.RFC3339))
7070
}
7171
return fmt.Sprintf("height: %d", p.Height)

0 commit comments

Comments
 (0)