From e38a6df9cd836982a48854f59300459b91250e38 Mon Sep 17 00:00:00 2001 From: Emmanuel T Odeke Date: Tue, 8 Dec 2020 04:47:20 -0800 Subject: [PATCH] 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. --- x/ibc/light-clients/07-tendermint/types/misbehaviour.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/x/ibc/light-clients/07-tendermint/types/misbehaviour.go b/x/ibc/light-clients/07-tendermint/types/misbehaviour.go index 515876604..4e2fa9e81 100644 --- a/x/ibc/light-clients/07-tendermint/types/misbehaviour.go +++ b/x/ibc/light-clients/07-tendermint/types/misbehaviour.go @@ -2,7 +2,6 @@ package types import ( "bytes" - "math" "time" 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 // of the misbehaviour age range. func (misbehaviour Misbehaviour) GetTime() time.Time { - minTime := int64(math.Max(float64(misbehaviour.Header1.GetTime().UnixNano()), float64(misbehaviour.Header2.GetTime().UnixNano()))) - return time.Unix(0, minTime) + t1, t2 := misbehaviour.Header1.GetTime(), misbehaviour.Header2.GetTime() + if t1.After(t2) { + return t1 + } + return t2 } // ValidateBasic implements Misbehaviour interface