From 928dca829fbdcd9c3fdfd8291ad8c7ca4d4f94dc Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Fri, 22 Jul 2022 20:39:58 -0500 Subject: [PATCH 1/3] Speedup epoch distribution, superfluid component --- x/incentives/keeper/distribute.go | 35 +++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/x/incentives/keeper/distribute.go b/x/incentives/keeper/distribute.go index f25b233426c..fdfe9144690 100644 --- a/x/incentives/keeper/distribute.go +++ b/x/incentives/keeper/distribute.go @@ -225,20 +225,37 @@ func (k Keeper) doDistributionSends(ctx sdk.Context, distrs *distributionInfo) e func (k Keeper) distributeSyntheticInternal( ctx sdk.Context, gauge types.Gauge, locks []lockuptypes.PeriodLock, distrInfo *distributionInfo, ) (sdk.Coins, error) { - denom := gauge.DistributeTo.Denom - - qualifiedLocks := make([]lockuptypes.PeriodLock, 0, len(locks)) + qualifiedLocks := k.lk.GetLocksLongerThanDurationDenom(ctx, gauge.DistributeTo.Denom, gauge.DistributeTo.Duration) + + // map from lockID to present index in resultant list + // to be state compatible with what we had before, we iterate over locks, to get qualified locks + // to be in the same order as what is present in locks. + // in a future release, we can just use qualified locks directly. + type lockIndexPair struct { + lock lockuptypes.PeriodLock + index int + } + qualifiedLocksMap := make(map[uint64]lockIndexPair, len(qualifiedLocks)) + for _, lock := range qualifiedLocks { + qualifiedLocksMap[lock.ID] = lockIndexPair{lock, -1} + } + curIndex := 0 for _, lock := range locks { - // see if this lock has a synthetic lockup. If so, err == nil, and we add to qualifiedLocks. - // otherwise it does not, and we continue. - _, err := k.lk.GetSyntheticLockup(ctx, lock.ID, denom) - if err != nil { + if v, ok := qualifiedLocksMap[lock.ID]; ok { + qualifiedLocksMap[lock.ID] = lockIndexPair{v.lock, curIndex} + curIndex += 1 + } + } + + sortedAndTrimmedQualifiedLocks := make([]lockuptypes.PeriodLock, curIndex, curIndex) + for _, v := range qualifiedLocksMap { + if v.index < 0 { continue } - qualifiedLocks = append(qualifiedLocks, lock) + sortedAndTrimmedQualifiedLocks[v.index] = v.lock } - return k.distributeInternal(ctx, gauge, qualifiedLocks, distrInfo) + return k.distributeInternal(ctx, gauge, sortedAndTrimmedQualifiedLocks, distrInfo) } // distributeInternal runs the distribution logic for a gauge, and adds the sends to From 77f62e0682ab7ee54b47a91452e7c526289b2085 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Sat, 23 Jul 2022 12:11:29 -0500 Subject: [PATCH 2/3] changelog entries --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2687f58418..70f47dada78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,7 +44,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Breaking Changes - * [#1889](https://github.com/osmosis-labs/osmosis/pull/1825) Add proto responses to gamm LP messages: * MsgJoinPoolResponse: share_out_amount and token_in fields * MsgExitPoolResponse: token_out field @@ -85,6 +84,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [1931](https://github.com/osmosis-labs/osmosis/pull/1931) Add explicit check for input denoms to `CalcJoinPoolShares` * [2011](https://github.com/osmosis-labs/osmosis/pull/2011) Fix bug in TokenFactory initGenesis, relating to denom creation fee param. +### Improvements +* [#2214](https://github.com/osmosis-labs/osmosis/pull/2214) Speedup epoch distribution, superfluid component ## [v9.0.0 - Nitrogen](https://github.com/osmosis-labs/osmosis/releases/tag/v9.0.0) From 037c5464f76c44491c71a14480315baccb56f522 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Sat, 23 Jul 2022 12:15:05 -0500 Subject: [PATCH 3/3] lint --- x/incentives/keeper/distribute.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/incentives/keeper/distribute.go b/x/incentives/keeper/distribute.go index fdfe9144690..c6921364441 100644 --- a/x/incentives/keeper/distribute.go +++ b/x/incentives/keeper/distribute.go @@ -247,7 +247,7 @@ func (k Keeper) distributeSyntheticInternal( } } - sortedAndTrimmedQualifiedLocks := make([]lockuptypes.PeriodLock, curIndex, curIndex) + sortedAndTrimmedQualifiedLocks := make([]lockuptypes.PeriodLock, curIndex) for _, v := range qualifiedLocksMap { if v.index < 0 { continue