From 9d40dfa3903a3fa47e1b1def8d9d1c97892e4d44 Mon Sep 17 00:00:00 2001 From: romelukaku Date: Sun, 10 Jul 2022 14:54:03 +0700 Subject: [PATCH 1/3] mod getToDistributedCoinsFromGauges --- x/incentives/keeper/distribute.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/x/incentives/keeper/distribute.go b/x/incentives/keeper/distribute.go index 2442bfc4687..17a669aa938 100644 --- a/x/incentives/keeper/distribute.go +++ b/x/incentives/keeper/distribute.go @@ -21,9 +21,13 @@ 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 = coins.Add(gauge.DistributedCoins...) + } + return coins.Sub(distributed) } From 2f64584538afce9382cbfb889cd0833b1ed661e5 Mon Sep 17 00:00:00 2001 From: romelukaku Date: Sun, 10 Jul 2022 15:12:00 +0700 Subject: [PATCH 2/3] mod getToDistributedCoinsFromGauges --- x/incentives/keeper/distribute.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x/incentives/keeper/distribute.go b/x/incentives/keeper/distribute.go index 17a669aa938..1fcfe5215ed 100644 --- a/x/incentives/keeper/distribute.go +++ b/x/incentives/keeper/distribute.go @@ -23,9 +23,10 @@ func (k Keeper) getDistributedCoinsFromGauges(gauges []types.Gauge) sdk.Coins { func (k Keeper) getToDistributeCoinsFromGauges(gauges []types.Gauge) sdk.Coins { coins := sdk.Coins{} distributed := sdk.Coins{} + for _, gauge := range gauges { coins = coins.Add(gauge.Coins...) - distributed = coins.Add(gauge.DistributedCoins...) + distributed = distributed.Add(gauge.DistributedCoins...) } return coins.Sub(distributed) From c475b8582fb61e3cd226dee9f39ff7ff818b3cfe Mon Sep 17 00:00:00 2001 From: romelukaku Date: Sun, 10 Jul 2022 23:15:12 +0700 Subject: [PATCH 3/3] rm unused function --- x/incentives/keeper/gauge.go | 9 --------- 1 file changed, 9 deletions(-) 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)