From dd1e4eeaf5370e9338a0eb38e6b5811ccd862341 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Wed, 13 Oct 2021 10:36:12 -0500 Subject: [PATCH] Linear time improvements to epoch time (#517) --- x/incentives/keeper/gauge.go | 3 ++- x/lockup/types/lock.go | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/x/incentives/keeper/gauge.go b/x/incentives/keeper/gauge.go index cbfb5ba58fb..b118ee7e51f 100644 --- a/x/incentives/keeper/gauge.go +++ b/x/incentives/keeper/gauge.go @@ -368,7 +368,8 @@ func (k Keeper) distributeInternal( denomLockAmt := lock.Coins.AmountOfNoDenomValidation(gauge.DistributeTo.Denom) amt := coin.Amount.Mul(denomLockAmt).Quo(lockSum.Mul(sdk.NewInt(int64(remainEpochs)))) if amt.IsPositive() { - distrCoins = distrCoins.Add(sdk.NewCoin(coin.Denom, amt)) + newlyDistributedCoin := sdk.Coin{Denom: coin.Denom, Amount: amt} + distrCoins = distrCoins.Add(newlyDistributedCoin) } } distrCoins = distrCoins.Sort() diff --git a/x/lockup/types/lock.go b/x/lockup/types/lock.go index bf28e16bfbe..5f318a5b2e8 100644 --- a/x/lockup/types/lock.go +++ b/x/lockup/types/lock.go @@ -1,6 +1,7 @@ package types import ( + "fmt" "time" sdk "github.com/cosmos/cosmos-sdk/types" @@ -24,8 +25,12 @@ func (p PeriodLock) IsUnlocking() bool { func SumLocksByDenom(locks []PeriodLock, denom string) sdk.Int { sum := sdk.NewInt(0) + err := sdk.ValidateDenom(denom) + if err != nil { + panic(fmt.Errorf("invalid denom used internally: %s, %v", denom, err)) + } for _, lock := range locks { - sum = sum.Add(lock.Coins.AmountOf(denom)) + sum = sum.Add(lock.Coins.AmountOfNoDenomValidation(denom)) } return sum }