Skip to content

Commit

Permalink
Linear time improvements to epoch time (#517)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValarDragon authored Oct 13, 2021
1 parent fdaca2b commit dd1e4ee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion x/incentives/keeper/gauge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 6 additions & 1 deletion x/lockup/types/lock.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
"fmt"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -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
}

0 comments on commit dd1e4ee

Please sign in to comment.