Skip to content

Commit

Permalink
x/incentives: Lower Epoch allocation overhead (backport #7100) (#7103)
Browse files Browse the repository at this point in the history
* x/incentives: Lower Epoch allocation overhead (#7100)

* Lower allocation overhead

* Add changelog

(cherry picked from commit 63d2551)

# Conflicts:
#	CHANGELOG.md

* Fix changelog conflict

* Revert "Fix changelog conflict"

This reverts commit 6235a69.

* Fix Changelog.md

* try Alessandro's fix

---------

Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
Co-authored-by: Dev Ojha <dojha@berkeley.edu>
  • Loading branch information
3 people authored Dec 13, 2023
1 parent 79adb8f commit f7c9600
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/check-state-compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,17 @@ jobs:
run: |
REPO_MAJOR_VERSION=$(echo ${{ github.base_ref }} | sed 's/\.x//')
SNAPSHOT_INFO_URL=${{ env.SNAPSHOT_BUCKET }}/$REPO_MAJOR_VERSION/snapshots.json
# Get the latest pre-epoch snapshot information from bucket
SNAPSHOT_INFO=$(curl -sL --retry 5 --retry-delay 5 --connect-timeout 30 -H "Accept: application/json" $SNAPSHOT_INFO_URL)
SNAPSHOT_URL=$(echo $SNAPSHOT_INFO | jq -r '.[] | select(.type == "pre-epoch").url')
SNAPSHOT_ID=$(echo $SNAPSHOT_INFO | jq -r '.[] | select(.type == "pre-epoch").filename' | cut -f 1 -d '.')
# Download snapshot if not already present
mkdir -p /mnt/data/snapshots/$REPO_MAJOR_VERSION/
if [ ! -d "/mnt/data/snapshots/$REPO_MAJOR_VERSION/$SNAPSHOT_ID" ]; then
rm -rf /mnt/data/snapshots/$REPO_MAJOR_VERSION/*
mkdir /mnt/data/snapshots/$REPO_MAJOR_VERSION/$SNAPSHOT_ID
wget -q -O - $SNAPSHOT_URL | lz4 -d | tar -C /mnt/data/snapshots/$REPO_MAJOR_VERSION/$SNAPSHOT_ID -xvf -
fi
# Copy snapshot in Data folder
cp -R /mnt/data/snapshots/$REPO_MAJOR_VERSION/$SNAPSHOT_ID/* $HOME/.osmosisd/
-
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Misc Improvements

* [#7093](https://github.com/osmosis-labs/osmosis/pull/7093),[#7100](https://github.com/osmosis-labs/osmosis/pull/7100) Lower CPU overheads of the Osmosis epoch.

## v20.5.1

### API
Expand Down
5 changes: 3 additions & 2 deletions x/incentives/keeper/distribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,13 +652,14 @@ func (k Keeper) distributeInternal(
if lockSum.IsZero() {
return nil, nil
}
remainingEpochsAsInt := osmomath.NewInt(int64(remainEpochs))
// total_denom_lock_amount * remain_epochs
lockSumTimesRemainingEpochs := lockSum.Mul(remainingEpochsAsInt)
lockSumTimesRemainingEpochs := lockSum.MulRaw(int64(remainEpochs))

for _, lock := range locks {
distrCoins := sdk.Coins{}
// too expensive + verbose even in debug mode.
// ctx.Logger().Debug("distributeInternal, distribute to lock", "module", types.ModuleName, "gaugeId", gauge.Id, "lockId", lock.ID, "remainCons", remainCoins, "height", ctx.BlockHeight())

for _, coin := range remainCoins {
// distribution amount = gauge_size * denom_lock_amount / (total_denom_lock_amount * remain_epochs)
denomLockAmt := lock.Coins.AmountOfNoDenomValidation(denom)
Expand Down
2 changes: 1 addition & 1 deletion x/incentives/keeper/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (k Keeper) FinishedGaugesIterator(ctx sdk.Context) sdk.Iterator {

// FilterLocksByMinDuration returns locks whose lock duration is greater than the provided minimum duration.
func FilterLocksByMinDuration(locks []lockuptypes.PeriodLock, minDuration time.Duration) []lockuptypes.PeriodLock {
filteredLocks := make([]lockuptypes.PeriodLock, 0, len(locks)/2)
filteredLocks := make([]lockuptypes.PeriodLock, 0, len(locks))
for _, lock := range locks {
if lock.Duration >= minDuration {
filteredLocks = append(filteredLocks, lock)
Expand Down

0 comments on commit f7c9600

Please sign in to comment.