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

[Uptime Incentives]: Use gauge duration as uptime with appropriate validation and fallback #7417

Merged
merged 5 commits into from
Feb 7, 2024

Conversation

AlpinYukseloglu
Copy link
Contributor

@AlpinYukseloglu AlpinYukseloglu commented Feb 6, 2024

Closes: #7369

What is the purpose of the change

This PR wires up gauge duration to be used as uptime for CL gauges. It also adds validation logic that checks the duration against authorized uptimes and falls back to the default authorized uptime of 1ns if it it invalid or unauthorized. Please see the linked issue for discussion on why this is necessary/important.

Testing and Verifying

All core changes are tested in distribute_test.go

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes?
  • Changelog entry added to Unreleased section of CHANGELOG.md?

Where is the change documented?

  • Specification (x/{module}/README.md)
  • Osmosis documentation site
  • Code comments?
  • N/A

@AlpinYukseloglu AlpinYukseloglu added the V:state/breaking State machine breaking PR label Feb 6, 2024
@@ -520,8 +534,24 @@ func (s *KeeperTestSuite) TestDistribute_ExternalIncentives_NoLock() {
"perpetual, 2 coins, paid over 1 epoch": withIsPerpetual(withGaugeCoins(defaultTest, defaultBothCoins), true),
"non-perpetual, 1 coin, paid over 2 epochs": withNumEpochs(defaultTest, 2),
"non-perpetual, 2 coins, paid over 3 epochs": withNumEpochs(withGaugeCoins(defaultTest, defaultBothCoins), 3),
"error: balancer pool id": withError(withPoolId(defaultTest, defaultBalancerPool)),
"error: inactive gauge": withError(withNumEpochs(defaultTest, 0)),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: diff seems to be rendering poorly – these are moved to the end of the block

"error: balancer pool id": withError(withPoolId(defaultTest, defaultBalancerPool)),
"error: inactive gauge": withError(withNumEpochs(defaultTest, 0)),

// We expect incentives with the set uptime to be created
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not a huge fan of this test format due to poor readability for more complex test cases, but opted to conform to it since refactoring would be higher overhead to discuss/implement/review

Comment on lines +609 to +613
// If uptime is not authorized, we expect to fall back to default
expectedUptime := types.DefaultConcentratedUptime
if tc.authorizedUptime {
expectedUptime = tc.distrTo.Duration
}
Copy link
Member

Choose a reason for hiding this comment

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

nit: suggest hardcoding the expected uptime in the test case struct as dynamically selecting the expected value in the test case logic is prone to test configuration bugs, especially, as the test case grows

@@ -602,6 +602,27 @@ func (k Keeper) distributeInternal(
// Get distribution epoch duration. This is used to calculate the emission rate.
currentEpoch := k.GetEpochInfo(ctx)

// Validate that the gauge's corresponding uptime is authorized.
authorizedUptimes := k.clk.GetParams(ctx).AuthorizedUptimes
Copy link
Member

Choose a reason for hiding this comment

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

I think we should pass authorized uptimes as a func input param instead of retrieving it for every single gauge, this could be expensive.

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 I agree that this might be expensive, but unfortunately distributeInternal is used for all gauges, not just CL gauges, so authorized uptimes as a func input would be super odd. Happy to continue discussion offline

Copy link
Member

@ValarDragon ValarDragon Feb 6, 2024

Choose a reason for hiding this comment

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

This is only in the noLock gauge (not superfluid) and can be altered state compatibly so i'm fine w/ filing this into a GH issue and doing later!

Copy link
Member

@czarcas7ic czarcas7ic left a comment

Choose a reason for hiding this comment

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

Nice work, I do think the change should be made to not pull module params for every single gauge though before merge.

Copy link
Member

@ValarDragon ValarDragon left a comment

Choose a reason for hiding this comment

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

This looks good to me! Would suggest breaking up this new code into its own function, but good to merge once doing that for me

@AlpinYukseloglu AlpinYukseloglu merged commit 29ed48f into main Feb 7, 2024
1 check passed
@AlpinYukseloglu AlpinYukseloglu deleted the alpo/use-uptime-duration branch February 7, 2024 04:52
p0mvn pushed a commit that referenced this pull request Feb 8, 2024
…lidation and fallback (#7417)

* implement validation, fallback, and wiring for using gauge duration as uptime

* add changelog

* extract uptime fetch into helper
@github-actions github-actions bot mentioned this pull request Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:x/incentives V:state/breaking State machine breaking PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Uptime Incentives]: Use gauge duration as uptime with appropriate validation and fallback
4 participants