diff --git a/x/incentives/keeper/distribute.go b/x/incentives/keeper/distribute.go index 2442bfc4687..1fcfe5215ed 100644 --- a/x/incentives/keeper/distribute.go +++ b/x/incentives/keeper/distribute.go @@ -21,9 +21,14 @@ func (k Keeper) getDistributedCoinsFromGauges(gauges []types.Gauge) sdk.Coins { } func (k Keeper) getToDistributeCoinsFromGauges(gauges []types.Gauge) sdk.Coins { - // TODO: Consider optimizing this in the future to only require one iteration over all gauges. - coins := k.getCoinsFromGauges(gauges) - distributed := k.getDistributedCoinsFromGauges(gauges) + coins := sdk.Coins{} + distributed := sdk.Coins{} + + for _, gauge := range gauges { + coins = coins.Add(gauge.Coins...) + distributed = distributed.Add(gauge.DistributedCoins...) + } + return coins.Sub(distributed) } diff --git a/x/incentives/keeper/gauge.go b/x/incentives/keeper/gauge.go index 59bc7436dc2..8dfe12d1ac7 100644 --- a/x/incentives/keeper/gauge.go +++ b/x/incentives/keeper/gauge.go @@ -38,15 +38,6 @@ func (k Keeper) getGaugesFromIterator(ctx sdk.Context, iterator db.Iterator) []t return gauges } -// Compute the total amount of coins in all the gauges. -func (k Keeper) getCoinsFromGauges(gauges []types.Gauge) sdk.Coins { - coins := sdk.Coins{} - for _, gauge := range gauges { - coins = coins.Add(gauge.Coins...) - } - return coins -} - // setGauge set the gauge inside store. func (k Keeper) setGauge(ctx sdk.Context, gauge *types.Gauge) error { store := ctx.KVStore(k.storeKey)