x/ibc/light-clients: simplify max time comparison (#8089)
The prior code that tried to get the newest/larger time between the too performed: * 2 time.Time.UnixNano() retrievals: 2 multiplications, 2 additions * 1 math.Max comparison * 1 time.Unix(0, minTime) creation but really this code could just use native operations on: time.Time.After() simply. This now becomes a single operation, single comparison for the same effect.
This commit is contained in:
parent
b219c54c2d
commit
e38a6df9cd
|
@ -2,7 +2,6 @@ package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"math"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||||
|
@ -48,8 +47,11 @@ func (misbehaviour Misbehaviour) GetHeight() exported.Height {
|
||||||
// maximum value from both headers to prevent producing an invalid header outside
|
// maximum value from both headers to prevent producing an invalid header outside
|
||||||
// of the misbehaviour age range.
|
// of the misbehaviour age range.
|
||||||
func (misbehaviour Misbehaviour) GetTime() time.Time {
|
func (misbehaviour Misbehaviour) GetTime() time.Time {
|
||||||
minTime := int64(math.Max(float64(misbehaviour.Header1.GetTime().UnixNano()), float64(misbehaviour.Header2.GetTime().UnixNano())))
|
t1, t2 := misbehaviour.Header1.GetTime(), misbehaviour.Header2.GetTime()
|
||||||
return time.Unix(0, minTime)
|
if t1.After(t2) {
|
||||||
|
return t1
|
||||||
|
}
|
||||||
|
return t2
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateBasic implements Misbehaviour interface
|
// ValidateBasic implements Misbehaviour interface
|
||||||
|
|
Loading…
Reference in New Issue