Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test/feat: incentive accumulator truncation #7395

Merged
merged 2 commits into from
Feb 1, 2024

Conversation

p0mvn
Copy link
Member

@p0mvn p0mvn commented Feb 1, 2024

Closes: #XXX

What is the purpose of the change

This PR shows that there is a chance of incentives being truncated due to large liquidity value.
We observed this in pool 1423 where both tokens have 18 decimal precision.

In such a case, the incentive record is updated correctly, not the global pool accumulator. The reason the pool accumulator is not updated is that it is a per unit of liquidity value (divided by liquidity). This division leads to truncation to zero.

It has been determined that no funds are at risk. The incentives are eventually distributed if either:
a) A long time without an update to the pool state occurs (at least 51 minutes with the current pool setup configuration)
b) Current tick liquidity becomes smaller

We confirmed that other pools are highly unlikely to be affected by setting a breakpoint with a debugger in-place of where the new event is emitted.

Going forward, we will have event, metric and log emitted if truncation happens.

Possible Solutions

To prevent this from happening again, we will evaluate the following approaches:

  • Restrict min uptime options for certain pairs, requiring users to stay longer.
  • Implement scaling factor for pool per-unit of liquidity accumulator

@p0mvn p0mvn added A:no-changelog A:backport/v22.x backport patches to v22.x branch labels Feb 1, 2024
@p0mvn p0mvn marked this pull request as ready for review February 1, 2024 03:54
@p0mvn p0mvn marked this pull request as draft February 1, 2024 03:54
@p0mvn p0mvn added the V:state/compatible/backport State machine compatible PR, should be backported label Feb 1, 2024
@p0mvn p0mvn marked this pull request as ready for review February 1, 2024 04:12
Comment on lines +251 to +260
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.IncentiveTruncationPlaceholderName,
sdk.NewAttribute("pool_id", strconv.FormatUint(poolID, 10)),
sdk.NewAttribute("total_liq", liquidityInAccum.String()),
sdk.NewAttribute("per_unit_liq", incentivesPerLiquidity.String()),
sdk.NewAttribute("total_amt", totalEmittedAmount.String()),
))

telemetry.IncrCounter(1, types.IncentiveTruncationPlaceholderName)
ctx.Logger().Error(types.IncentiveTruncationPlaceholderName, "pool_id", poolID, "total_liq", liquidityInAccum, "per_unit_liq", incentivesPerLiquidity, "total_amt", totalEmittedAmount)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should create an alert for these and a Grafana dashboard cc: @niccoloraspa @alessandrolomanto

// Reset events
s.Ctx = s.Ctx.WithEventManager(sdk.NewEventManager())

s.Ctx = s.Ctx.WithBlockTime(s.Ctx.BlockTime().Add(time.Minute * 51))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we only need to add 1 minute here? Since we already went ahead 50 minutes above?

@@ -48,4 +48,6 @@ const (
AttributeKeySpreadRewardGrowthOppositeDirectionOfLastTraversal = "spread_reward_growth"
AttributeKeyUptimeGrowthOppositeDirectionOfLastTraversal = "uptime_growth"
AttributeNewOwner = "new_owner"

IncentiveTruncationPlaceholderName = "concentrated_liquidity_incentive_truncation"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove placeholder name?

@czarcas7ic czarcas7ic merged commit 8eaaae9 into main Feb 1, 2024
1 check passed
@czarcas7ic czarcas7ic deleted the roman/incentive-truncation-alert branch February 1, 2024 06:17
mergify bot pushed a commit that referenced this pull request Feb 1, 2024
* test/feat: incentive accumulator truncation

* updates

(cherry picked from commit 8eaaae9)
p0mvn added a commit that referenced this pull request Feb 1, 2024
* test/feat: incentive accumulator truncation

* updates

(cherry picked from commit 8eaaae9)

Co-authored-by: Roman <[email protected]>
@github-actions github-actions bot mentioned this pull request Mar 15, 2024
@github-actions github-actions bot mentioned this pull request May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:backport/v22.x backport patches to v22.x branch A:no-changelog C:x/concentrated-liquidity V:state/compatible/backport State machine compatible PR, should be backported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants