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

[CL Incentives]: Sync global uptime accumulators upon tick crossing #4399

Merged
merged 123 commits into from
Mar 3, 2023

Conversation

AlpinYukseloglu
Copy link
Contributor

Closes: #4278

What is the purpose of the change

This PR implements uptime-related logic for tick crossing. Specifically, it "flips" the tick-level uptime accum values upon crossing.

Brief Changelog

  • Implement logic for flipping uptime trackers when a tick is crossed

Testing and Verifying

  • New logic is relatively well tested in tick_test.go (including cases for technically undefined behavior such as crossing into non-adjacent ticks)

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes? (no)
  • Is a relevant changelog entry added to the Unreleased section in CHANGELOG.md? (no)
  • How is the feature or change documented? (not documented)

czarcas7ic and others added 30 commits January 25, 2023 21:01
* single fee accum

* lint
@AlpinYukseloglu AlpinYukseloglu added C:x/concentrated-liquidity F: concentrated-liquidity Tracking the development of concentrated liquidity feature to improve filtering on the project board labels Feb 23, 2023
Copy link
Contributor

@stackman27 stackman27 left a comment

Choose a reason for hiding this comment

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

left few comments

}

// Update global accums to now before uptime outside changes
if err := k.updateUptimeAccumulatorsToNow(ctx, poolId); err != nil {
Copy link
Member

@p0mvn p0mvn Feb 25, 2023

Choose a reason for hiding this comment

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

Why do we need to update uptime accumulators as we cross ticks?

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 be able to update them once per block?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My thinking was that the update logic for the target tick's uptime accumulators will involve the global accum values, so we need to ensure they are up to date. Are you suggesting this isn't necessary?

I do see a different issue though – we should be updating the accums prior to getting them instead of after, will fix.

Copy link
Member

Choose a reason for hiding this comment

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

So over a single swap, we might be crossing multiple ticks. From my understanding, we do not need to update the uptime accumulators every tick because that is idempotent within a swap. As a result, calling this update function as we cross every tick might be redundant.

Copy link
Member

Choose a reason for hiding this comment

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

Outside of the scope of this PR but - why do we also need to call updateUptimeAccumulatorsToNow in getTickInfo?

It feels that this update needs to happen at another level of abstraction or in another location

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So over a single swap, we might be crossing multiple ticks. From my understanding, we do not need to update the uptime accumulators every tick because that is idempotent within a swap. As a result, calling this update function as we cross every tick might be redundant.

Good point – we can add a check so it only updates if LastUpdateTime < current time. Made an issue here (#4422) to not block this PR (and because it could break some downstream PRs)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Outside of the scope of this PR but - why do we also need to call updateUptimeAccumulatorsToNow in getTickInfo?

It feels that this update needs to happen at another level of abstraction or in another location

We update there simply because getInitialUptimeGrowthOutsidesForTick uses global accum values (so they need to be up to date). The level of abstraction does seem a little off, but the function does include accumulator init logic more broadly so it might be worth discussing a small refactor or rename

additiveFee sdk.DecCoin
expectedLiquidityDelta sdk.Dec
expectedTickFeeGrowthOutside sdk.DecCoins
expectedErr bool
}{
{
name: "Get tick info on existing pool and existing tick",
name: "Get tick info on existing pool and existing tick below current tick (nonzero uptime trackers)",
Copy link
Member

@p0mvn p0mvn Feb 25, 2023

Choose a reason for hiding this comment

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

nit: let's remove "on existing pool" part from every test case name, please. It adds cognitive overhead while being unimportant context relative to other test case details because the pool existence check happens once at the top level

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, done

expectedTickFeeGrowthOutside: DefaultFeeAccumCoins.Add(defaultAdditiveFee),
},
{
name: "Get tick info on existing pool and existing tick below current tick (nonzero uptime trackers)",
Copy link
Member

Choose a reason for hiding this comment

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

Isn't it ("zero initial uptime") trackers. Should the test case name reflect that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm not sure I follow – the uptime trackers are nonzero in this test case no?

expectedTickFeeGrowthOutside: DefaultFeeAccumCoins.Add(defaultAdditiveFee),
},
{
name: "Get tick info on existing pool and existing tick above current tick (nil uptime trackers)",
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense also having a test case where non-zero initial uptime trackers and above current tick?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is already implicitly covered by case right below your comment, but I just added an explicit case for clarity anyway.

Copy link
Member

@p0mvn p0mvn left a comment

Choose a reason for hiding this comment

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

LGTM pending minor suggestions and the discussion on calling updateUptimeAccumulatorsToNow in crossTick and getTickInfo.

If that makes it easier for making progress, please feel free to merge this and move the discussion on Slack

Base automatically changed from alpo-cl-uptime-tick-init to main March 2, 2023 02:30
@AlpinYukseloglu AlpinYukseloglu added V:state/breaking State machine breaking PR and removed V:state/breaking State machine breaking PR labels Mar 2, 2023
@AlpinYukseloglu AlpinYukseloglu merged commit 981dcef into main Mar 3, 2023
@AlpinYukseloglu AlpinYukseloglu deleted the alpo-cl-uptime-cross branch March 3, 2023 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:x/concentrated-liquidity F: concentrated-liquidity Tracking the development of concentrated liquidity feature to improve filtering on the project board V:state/breaking State machine breaking PR
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[CL Incentives]: Sync global uptime accumulators upon tick crossing
4 participants