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

feat(osmoutils): custom accumulator position updates #3903

Merged
merged 15 commits into from
Jan 5, 2023

Conversation

p0mvn
Copy link
Member

@p0mvn p0mvn commented Jan 2, 2023

Closes: #XXX

What is the purpose of the change

This PR implements the ability to provide custom position accumulators for NewPositionCustomAcc, AddToPositionCustomAcc, and RemoveFromPositionCustomAcc accumulator methods.

It also implements a convenience method called UpdateAccumulator and its custom version UpdatePositionCustomAcc. If numShares is positive, it acts as AddToPosition, if negative, it acts as RemoveFromPosition. If zero, it fails.

Testing and Verifying

This change added tests.

The tests for "custom accumulator" APIs only focus on test cases around the custom accumulator updates since their default versions go over all internal edge cases in-depth.

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 applicable

@p0mvn p0mvn added the V:state/compatible/no_backport State machine compatible PR, depends on prior breaks label Jan 2, 2023
@p0mvn p0mvn marked this pull request as ready for review January 3, 2023 03:22
Copy link
Member

@mattverse mattverse left a comment

Choose a reason for hiding this comment

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

Left some minor reviews, please take a look. Otherwise lgtm!

Comment on lines +128 to +132
//
// An alternative approach is to simply generate an additional position every time an
// address adds to its position. We do not pursue this path because we want to ensure
// that withdrawal and claiming functions remain constant time and do not scale with the
// number of times a user has added to their position.
Copy link
Member

Choose a reason for hiding this comment

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

What do you think of removing this part?

Suggested change
//
// An alternative approach is to simply generate an additional position every time an
// address adds to its position. We do not pursue this path because we want to ensure
// that withdrawal and claiming functions remain constant time and do not scale with the
// number of times a user has added to their position.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is useful context

@@ -35,8 +39,24 @@ func getPosition(accum AccumulatorObject, name string) (Record, error) {
func getTotalRewards(accum AccumulatorObject, position Record) sdk.DecCoins {
totalRewards := position.UnclaimedRewards

// TODO: add a check that accum.value is greater than position.InitAccumValue
Copy link
Member

Choose a reason for hiding this comment

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

I reckon this is small enough to be included in this PR, was there a separate reason or further investigation you wanted to do before adding this check?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is non-blocking for fees. I don't want to get too wrapped up in the details to block further fee work.

We have a bunch of TODOs in this package since we still are iterating and prototyping the final design. I think it would make sense to come back and address all the details once we finalize the accum package and finish its integration into fees and incentives.

Let me know if that doesn't convince you to keep this as todo for now

oldPositionAccumulatorValue: initialCoinsDenomOne.Add(sdk.NewDecCoin(initialCoinDenomOne.Denom, sdk.OneInt())),
expectError: accum.NegativeAccDifferenceError{sdk.NewDecCoins(sdk.NewDecCoin(initialCoinDenomOne.Denom, sdk.OneInt()))},
},
"old accumulator coins are a superset of new - error": {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"old accumulator coins are a superset of new - error": {
"old accumulator coins are not a superset of new - error": {

Copy link
Member Author

Choose a reason for hiding this comment

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

but they are in this test case. old coins contain coins from customAccumulatorValue plus other coins

// All custom accumulator values must be non-negative.
// The position is initialized with empty unclaimed rewards
// If there is an existing position for the given address, it is overwritten.
func (accum AccumulatorObject) NewPositionCustomAcc(name string, numShareUnits sdk.Dec, customAccumulatorValue sdk.DecCoins, options *Options) error {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: consider changing method name to NewPositionCustomizedAcc it was after reading through all other codes that I understood what this method meant. (Just a personal opinion tho so please feel free to resolve this issue if you think the current method name is more intuitive)

Suggested change
func (accum AccumulatorObject) NewPositionCustomAcc(name string, numShareUnits sdk.Dec, customAccumulatorValue sdk.DecCoins, options *Options) error {
func (accum AccumulatorObject) NewPositionCustomizedAcc(name string, numShareUnits sdk.Dec, customAccumulatorValue sdk.DecCoins, options *Options) error {

Copy link
Member Author

Choose a reason for hiding this comment

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

I've considered this but tbh I prefer the original NewPositionCustomAcc better because it is shorter. To me, there is no semantical difference between Custom and Customized.

If you don't mind, I will keep the old name for shortness but lmk if any concerns

Comment on lines 238 to 242
func (accum AccumulatorObject) UpdatePositionCustomAcc(name string, numShares sdk.Dec, customAccumulatorValue sdk.DecCoins) error {
return accum.updatePosition(name, numShares, customAccumulatorValue)
}

func (accum AccumulatorObject) updatePosition(name string, numShares sdk.Dec, positionAccumulatorUpdate sdk.DecCoins) error {
Copy link
Member

Choose a reason for hiding this comment

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

why not directly expose updatePosition if this is the case?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. Refactored APIs here to reduce boilerplate: 54042ac

@p0mvn
Copy link
Member Author

p0mvn commented Jan 5, 2023

Addressed all comments, thanks @mattverse

@p0mvn
Copy link
Member Author

p0mvn commented Jan 5, 2023

Discussed offline - merging to unblock fees work

@p0mvn p0mvn merged commit 95dc42d into main Jan 5, 2023
@p0mvn p0mvn deleted the roman/custom-acc-updates branch January 5, 2023 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
V:state/compatible/no_backport State machine compatible PR, depends on prior breaks
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants