-
Notifications
You must be signed in to change notification settings - Fork 608
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
Refactor lock
method
#1936
Refactor lock
method
#1936
Conversation
err = k.addTokenToLock(ctx, lock, coin) | ||
if err != nil { | ||
return nil, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks wrong? addTokenToLock did more, e.g. handling of the main accumulation store? Why was this deleted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh the claim is that all functionality is there between the synth lock line, and lock.
Why not keep addTokenToLock
and just have that function as a subcomponent call lock
? (But retain the synth lock functionality)
That would be maintaining the standard in this package of having the exported method be doing validation logic & hook / return type logic, and the private method doing the state change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't fully follow the logic here. There are two calls that addTokenToLock
makes that are not related to the synth lock related accumulation store update, which are:
setLock
to update state with the new lock instance:
osmosis/x/lockup/keeper/lock.go
Line 100 in 8f018a6
err := k.setLock(ctx, *lock) - Update to
accumulationStore
:
osmosis/x/lockup/keeper/lock.go
Line 106 in 8f018a6
k.accumulationStore(ctx, coin.Denom).Increase(accumulationKey(lock.Duration), coin.Amount)
How/where are these being accounted for in the new implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I see the lock
call above now. The change that adds an addition parameter to lock
also makes sense now. Clever refactor :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ValarDragon wdym by ? Are you referring to synth lock accumulation store part?
(But retain the synth lock functionality)
@@ -144,47 +144,17 @@ func (suite *KeeperTestSuite) TestUnlockPeriodLockByID() { | |||
suite.Require().Len(locks, 0) | |||
} | |||
|
|||
func (suite *KeeperTestSuite) TestLock() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to do either or both:
- have additional tests for
CreateLock
that would cover the removed logic - use the
export_test.go
trick that will allow us to- export
lock
for tests only and - keep testing the now unexported
lock
method
- export
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah missed the tests! thanks for catching this! Just added this in the most recent commit!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few clarifying questions but overall LGTM! Love this refactor, cleans things up quite a bit :)
err = k.addTokenToLock(ctx, lock, coin) | ||
if err != nil { | ||
return nil, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't fully follow the logic here. There are two calls that addTokenToLock
makes that are not related to the synth lock related accumulation store update, which are:
setLock
to update state with the new lock instance:
osmosis/x/lockup/keeper/lock.go
Line 100 in 8f018a6
err := k.setLock(ctx, *lock) - Update to
accumulationStore
:
osmosis/x/lockup/keeper/lock.go
Line 106 in 8f018a6
k.accumulationStore(ctx, coin.Denom).Increase(accumulationKey(lock.Duration), coin.Amount)
How/where are these being accounted for in the new implementation?
err = k.addTokenToLock(ctx, lock, coin) | ||
if err != nil { | ||
return nil, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I see the lock
call above now. The change that adds an addition parameter to lock
also makes sense now. Clever refactor :)
Co-authored-by: Aleksandr Bezobchuk <[email protected]>
…labs/osmosis into mattverse/refactor-lock
merging this upon being blocker for future work for adding testing for lockup! |
I'm a bit concerned about this change / haven't convinced myself they are at functionality parity |
Apologies if I went ahead and rushed into merging this, I supposed there weren't extra reviews. Is there something you're concerned about or would like to give a review on? We can either revert this commit or create a new PR depending on the review |
A Note to reviewers to clarify no logic has been removed / changed per this PR Previous logic for
Refactored Logic for
Previous logic for
Refactored Logic for
|
* Add lock method refactor * Delete duplciated testing * Update x/lockup/keeper/lock.go Co-authored-by: Aleksandr Bezobchuk <[email protected]> * Add tests implement feedback from code review * Add test cases Co-authored-by: Aleksandr Bezobchuk <[email protected]> (cherry picked from commit c115593) # Conflicts: # x/lockup/keeper/admin_keeper_test.go # x/lockup/keeper/lock.go
* Refactor `lock` method (#1936) * Add lock method refactor * Delete duplciated testing * Update x/lockup/keeper/lock.go Co-authored-by: Aleksandr Bezobchuk <[email protected]> * Add tests implement feedback from code review * Add test cases Co-authored-by: Aleksandr Bezobchuk <[email protected]> (cherry picked from commit c115593) # Conflicts: # x/lockup/keeper/admin_keeper_test.go # x/lockup/keeper/lock.go * Fix merge conflict * Merge Co-authored-by: Matt, Park <[email protected]> Co-authored-by: mattverse <[email protected]>
This reverts commit d733f64.
Sub component of: #1838
What is the purpose of the change
The lock method in the lockup module was a public method before current change, which was an imo dangerous design, as it is and should be only called by either of the two methods
CreateLock
AddTokensToLockByID
That being said, there shouldn't be any cases where the
Lock
method is called directly, but called only through the two entrypoints mentioned above, not to mention the code duplication that we had for the two methods above.This PR changes the Lock method into a private method and refactors code duplication logic as well.
Brief Changelog
Lock
method in x/lockup module.Documentation and Release Note
Unreleased
section inCHANGELOG.md
? no