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

Add unlocking lock id to BeginUnlocking response #4489

Merged
merged 2 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### API Breaks

* [#4489](https://github.com/osmosis-labs/osmosis/pull/4489) Add unlockingLockId to BeginUnlocking response

## v15.0.0

This release containts the following new modules:
Expand Down
5 changes: 4 additions & 1 deletion proto/osmosis/lockup/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ message MsgBeginUnlocking {
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}
message MsgBeginUnlockingResponse { bool success = 1; }
message MsgBeginUnlockingResponse {
bool success = 1;
uint64 unlockingLockID = 2;
}

// MsgExtendLockup extends the existing lockup's duration.
// The new duration is longer than the original.
Expand Down
6 changes: 4 additions & 2 deletions proto/osmosis/protorev/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,10 @@ message QueryGetProtoRevPoolWeightsRequest {}
// Query/GetProtoRevPoolWeights RPC method.
message QueryGetProtoRevPoolWeightsResponse {
// pool_weights is a list of all of the pool weights
PoolWeights pool_weights = 1
[ (gogoproto.moretags) = "yaml:\"pool_weights\"", (gogoproto.nullable) = false ];
PoolWeights pool_weights = 1 [
(gogoproto.moretags) = "yaml:\"pool_weights\"",
(gogoproto.nullable) = false
];
}

// QueryGetProtoRevMaxPoolPointsPerBlockRequest is request type for the
Expand Down
2 changes: 1 addition & 1 deletion x/lockup/keeper/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (k Keeper) beginUnlockFromIterator(ctx sdk.Context, iterator db.Iterator) (

locks := k.getLocksFromIterator(ctx, iterator)
for _, lock := range locks {
err := k.BeginUnlock(ctx, lock.ID, nil)
_, err := k.BeginUnlock(ctx, lock.ID, nil)
if err != nil {
return locks, err
}
Expand Down
12 changes: 6 additions & 6 deletions x/lockup/keeper/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,19 @@ func (k Keeper) lock(ctx sdk.Context, lock types.PeriodLock, tokensToLock sdk.Co

// BeginUnlock is a utility to start unlocking coins from NotUnlocking queue.
// Returns an error if the lock has a synthetic lock.
func (k Keeper) BeginUnlock(ctx sdk.Context, lockID uint64, coins sdk.Coins) error {
func (k Keeper) BeginUnlock(ctx sdk.Context, lockID uint64, coins sdk.Coins) (uint64, error) {
// prohibit BeginUnlock if synthetic locks are referring to this
// TODO: In the future, make synthetic locks only get partial restrictions on the main lock.
lock, err := k.GetLockByID(ctx, lockID)
if err != nil {
return err
return 0, err
}
if k.HasAnySyntheticLockups(ctx, lock.ID) {
return fmt.Errorf("cannot BeginUnlocking a lock with synthetic lockup")
return 0, fmt.Errorf("cannot BeginUnlocking a lock with synthetic lockup")
}

_, err = k.beginUnlock(ctx, *lock, coins)
return err
unlockingLock, err := k.beginUnlock(ctx, *lock, coins)
return unlockingLock, err
}

// BeginForceUnlock begins force unlock of the given lock.
Expand Down Expand Up @@ -356,7 +356,7 @@ func (k Keeper) ForceUnlock(ctx sdk.Context, lock types.PeriodLock) error {
}

if !lock.IsUnlocking() {
err := k.BeginUnlock(ctx, lock.ID, nil)
_, err := k.BeginUnlock(ctx, lock.ID, nil)
if err != nil {
return err
}
Expand Down
10 changes: 8 additions & 2 deletions x/lockup/keeper/lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (suite *KeeperTestSuite) TestBeginForceUnlock() {
if tc.expectSameLockID {
suite.Require().Equal(lockID, lock.ID)
} else {
suite.Require().Equal(lockID, lock.ID + 1)
suite.Require().Equal(lockID, lock.ID+1)
}

// new or updated lock
Expand Down Expand Up @@ -139,6 +139,7 @@ func (suite *KeeperTestSuite) TestUnlock() {
passedTime time.Duration
expectedUnlockMaturedLockPass bool
balanceAfterUnlock sdk.Coins
isPartial bool
}{
{
name: "normal unlocking case",
Expand Down Expand Up @@ -177,6 +178,7 @@ func (suite *KeeperTestSuite) TestUnlock() {
passedTime: time.Second,
expectedUnlockMaturedLockPass: true,
balanceAfterUnlock: sdk.Coins{sdk.NewInt64Coin("stake", 5)},
isPartial: true,
},
{
name: "partial unlocking unknown tokens",
Expand Down Expand Up @@ -213,11 +215,15 @@ func (suite *KeeperTestSuite) TestUnlock() {
partialUnlocking := tc.unlockingCoins.IsAllLT(initialLockCoins) && tc.unlockingCoins != nil

// begin unlocking
err = lockupKeeper.BeginUnlock(ctx, lock.ID, tc.unlockingCoins)
unlockingLock, err := lockupKeeper.BeginUnlock(ctx, lock.ID, tc.unlockingCoins)

if tc.expectedBeginUnlockPass {
suite.Require().NoError(err)

if tc.isPartial {
suite.Require().Equal(unlockingLock, lock.ID+1)
}

// check unlocking coins. When a lock is a partial lock
// (i.e. tc.unlockingCoins is not nit and less than initialLockCoins),
// we only unlock the partial amount of tc.unlockingCoins
Expand Down
4 changes: 2 additions & 2 deletions x/lockup/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ func (server msgServer) BeginUnlocking(goCtx context.Context, msg *types.MsgBegi
return nil, sdkerrors.Wrap(types.ErrNotLockOwner, fmt.Sprintf("msg sender (%s) and lock owner (%s) does not match", msg.Owner, lock.Owner))
}

err = server.keeper.BeginUnlock(ctx, lock.ID, msg.Coins)
unlockingLock, err := server.keeper.BeginUnlock(ctx, lock.ID, msg.Coins)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
}

// N.B. begin unlock event is emitted downstream in the keeper method.

return &types.MsgBeginUnlockingResponse{}, nil
return &types.MsgBeginUnlockingResponse{Success: true, UnlockingLockID: unlockingLock}, nil
}

// BeginUnlockingAll begins unlocking for all the locks that the account has by iterating all the not-unlocking locks the account holds.
Expand Down
11 changes: 10 additions & 1 deletion x/lockup/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func (suite *KeeperTestSuite) TestMsgBeginUnlocking() {
name string
param param
expectPass bool
isPartial bool
}{
{
name: "unlock full amount of tokens via begin unlock",
Expand All @@ -138,6 +139,7 @@ func (suite *KeeperTestSuite) TestMsgBeginUnlocking() {
duration: time.Second,
coinsInOwnerAddress: sdk.Coins{sdk.NewInt64Coin("stake", 10)},
},
isPartial: true,
expectPass: true,
},
{
Expand All @@ -163,6 +165,7 @@ func (suite *KeeperTestSuite) TestMsgBeginUnlocking() {
coinsInOwnerAddress: sdk.Coins{sdk.NewInt64Coin("stake", 10)},
},
expectPass: false,
isPartial: true,
},
}

Expand All @@ -181,11 +184,17 @@ func (suite *KeeperTestSuite) TestMsgBeginUnlocking() {
suite.Require().NoError(err)
}

_, err = msgServer.BeginUnlocking(goCtx, types.NewMsgBeginUnlocking(test.param.lockOwner, resp.ID, test.param.coinsToUnlock))
unlockingResponse, err := msgServer.BeginUnlocking(goCtx, types.NewMsgBeginUnlocking(test.param.lockOwner, resp.ID, test.param.coinsToUnlock))

if test.expectPass {
suite.Require().NoError(err)
suite.AssertEventEmitted(suite.Ctx, types.TypeEvtBeginUnlock, 1)
suite.Require().True(unlockingResponse.Success)
if test.isPartial {
suite.Require().Equal(unlockingResponse.UnlockingLockID, resp.ID+1)
} else {
suite.Require().Equal(unlockingResponse.UnlockingLockID, resp.ID)
}
} else {
suite.Require().Error(err)
suite.AssertEventEmitted(suite.Ctx, types.TypeEvtBeginUnlock, 0)
Expand Down
118 changes: 77 additions & 41 deletions x/lockup/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/superfluid/keeper/edge_case_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (suite *KeeperTestSuite) TestTryUnbondingSuperfluidLockupDirectly() {
_, _, locks := suite.setupSuperfluidDelegations(valAddrs, tc.superDelegations, denoms)

for _, lock := range locks {
err := suite.App.LockupKeeper.BeginUnlock(suite.Ctx, lock.ID, sdk.Coins{})
_, err := suite.App.LockupKeeper.BeginUnlock(suite.Ctx, lock.ID, sdk.Coins{})
suite.Require().Error(err)
}
})
Expand Down
2 changes: 1 addition & 1 deletion x/superfluid/keeper/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (suite *KeeperTestSuite) TestUnlockAndMigrate() {
} else {
lock, err := lockupKeeper.GetLockByID(ctx, lockID)
suite.Require().NoError(err)
err = lockupKeeper.BeginUnlock(ctx, lockID, lock.Coins)
_, err = lockupKeeper.BeginUnlock(ctx, lockID, lock.Coins)
suite.Require().NoError(err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion x/superfluid/keeper/unpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (suite *KeeperTestSuite) TestUnpool() {
} else {
lock, err := lockupKeeper.GetLockByID(ctx, lockID)
suite.Require().NoError(err)
err = lockupKeeper.BeginUnlock(ctx, lockID, lock.Coins)
_, err = lockupKeeper.BeginUnlock(ctx, lockID, lock.Coins)
suite.Require().NoError(err)

// add time to current time to test lock end time
Expand Down
2 changes: 1 addition & 1 deletion x/valset-pref/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func (suite *KeeperTestSuite) SetupLocks(delegator sdk.AccAddress) []lockuptypes
unbondingLocks, err := suite.App.LockupKeeper.CreateLock(suite.Ctx, delegator, osmoToLock, twoWeekDuration)
suite.Require().NoError(err)

err = suite.App.LockupKeeper.BeginUnlock(suite.Ctx, unbondingLocks.ID, nil)
_, err = suite.App.LockupKeeper.BeginUnlock(suite.Ctx, unbondingLocks.ID, nil)
suite.Require().NoError(err)

locks = append(locks, unbondingLocks)
Expand Down
2 changes: 1 addition & 1 deletion x/valset-pref/types/expected_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ type LockupKeeper interface {
GetLockByID(ctx sdk.Context, lockID uint64) (*lockuptypes.PeriodLock, error)
GetAllSyntheticLockupsByLockup(ctx sdk.Context, lockID uint64) []lockuptypes.SyntheticLock
ForceUnlock(ctx sdk.Context, lock lockuptypes.PeriodLock) error
BeginUnlock(ctx sdk.Context, lockID uint64, coins sdk.Coins) error
BeginUnlock(ctx sdk.Context, lockID uint64, coins sdk.Coins) (uint64, error)
GetPeriodLocks(ctx sdk.Context) ([]lockuptypes.PeriodLock, error)
}