From 143abbab2a675df8d97c1ba284f597c2f9df9cb2 Mon Sep 17 00:00:00 2001 From: mconcat Date: Thu, 14 Apr 2022 23:22:08 +0900 Subject: [PATCH 01/17] add EditLockup remove gw file fdsa --- proto/osmosis/lockup/tx.proto | 19 ++ x/lockup/keeper/lock.go | 34 ++ x/lockup/keeper/lock_test.go | 55 +++ x/lockup/keeper/msg_server.go | 29 ++ x/lockup/keeper/msg_server_test.go | 75 ++++ x/lockup/types/msgs.go | 23 ++ x/lockup/types/tx.pb.go | 528 +++++++++++++++++++++++++++-- 7 files changed, 728 insertions(+), 35 deletions(-) diff --git a/proto/osmosis/lockup/tx.proto b/proto/osmosis/lockup/tx.proto index 5746ed5edab..25941d643ee 100644 --- a/proto/osmosis/lockup/tx.proto +++ b/proto/osmosis/lockup/tx.proto @@ -17,6 +17,8 @@ service Msg { returns (MsgBeginUnlockingAllResponse); // MsgBeginUnlocking begins unlocking tokens by lock ID rpc BeginUnlocking(MsgBeginUnlocking) returns (MsgBeginUnlockingResponse); + // MsgEditLockup edits the existing lockups by lock ID + rpc EditLockup(MsgEditLockup) returns (MsgEditLockupResponse); } message MsgLockTokens { @@ -49,3 +51,20 @@ message MsgBeginUnlocking { ]; } message MsgBeginUnlockingResponse { bool success = 1; } + +message MsgEditLockup { + string owner = 1 [ (gogoproto.moretags) = "yaml:\"owner\"" ]; + uint64 ID = 2; + + // duration to be set. fails if lower than the current duration, or is unlocking + google.protobuf.Duration duration = 3 [ + (gogoproto.nullable) = false, + (gogoproto.stdduration) = true, + (gogoproto.jsontag) = "duration,omitempty", + (gogoproto.moretags) = "yaml:\"duration\"" + ]; + + // extend for other edit, e.g. cancel unlocking +} + +message MsgEditLockupResponse { bool success = 1; } diff --git a/x/lockup/keeper/lock.go b/x/lockup/keeper/lock.go index 61f32eeb43d..d8e8a827991 100644 --- a/x/lockup/keeper/lock.go +++ b/x/lockup/keeper/lock.go @@ -536,3 +536,37 @@ func (k Keeper) unlockInternalLogic(ctx sdk.Context, lock types.PeriodLock) erro k.hooks.OnTokenUnlocked(ctx, owner, lock.ID, lock.Coins, lock.Duration, lock.EndTime) return nil } + +func (k Keeper) EditLockup(ctx sdk.Context, lock types.PeriodLock, newDuration time.Duration) error { + // sanity check + + // check unlocking + if lock.IsUnlocking() { + return fmt.Errorf("cannot edit unlocking lockup") + } + + // check synthetic lockup exists + if k.HasAnySyntheticLockups(ctx, lock.ID) { + return fmt.Errorf("cannot edit lockup with synthetic lock") + } + + if newDuration != 0 { + // check newDuration > duration + if !(newDuration > lock.Duration) { + return fmt.Errorf("new duration should be greater than the original") + } + + // update accumulation store + for _, coin := range lock.Coins { + k.accumulationStore(ctx, coin.Denom).Decrease(accumulationKey(lock.Duration), coin.Amount) + k.accumulationStore(ctx, coin.Denom).Increase(accumulationKey(newDuration), coin.Amount) + } + + lock.Duration = newDuration + } + + // update lockup + k.setLockAndResetLockRefs(ctx, lock) + + return nil +} \ No newline at end of file diff --git a/x/lockup/keeper/lock_test.go b/x/lockup/keeper/lock_test.go index 523d0b6d52f..744437e3426 100644 --- a/x/lockup/keeper/lock_test.go +++ b/x/lockup/keeper/lock_test.go @@ -648,3 +648,58 @@ func (suite *KeeperTestSuite) TestSlashTokensFromLockByID() { _, err = suite.app.LockupKeeper.SlashTokensFromLockByID(suite.ctx, 1, sdk.Coins{sdk.NewInt64Coin("stake1", 1)}) suite.Require().Error(err) } + +func (suite *KeeperTestSuite) TestEditLockup() { + suite.SetupTest() + + // initial check + locks, err := suite.app.LockupKeeper.GetPeriodLocks(suite.ctx) + suite.Require().NoError(err) + suite.Require().Len(locks, 0) + + // lock coins + addr := sdk.AccAddress([]byte("addr1---------------")) + + // 1 * time.Second: 10 + coins := sdk.Coins{sdk.NewInt64Coin("stake", 10)} + suite.LockTokens(addr, coins, time.Second) + + // check accumulations + acc := suite.app.LockupKeeper.GetPeriodLocksAccumulation(suite.ctx, types.QueryCondition{ + Denom: "stake", + Duration: time.Second, + }) + suite.Require().Equal(int64(10), acc.Int64()) + + lock, _ := suite.app.LockupKeeper.GetLockByID(suite.ctx, 1) + + // duration decrease should fail + err = suite.app.LockupKeeper.EditLockup(suite.ctx, *lock, time.Second/2) + suite.Require().Error(err) + + // duration increase should success + err = suite.app.LockupKeeper.EditLockup(suite.ctx, *lock, time.Second*2) + suite.Require().NoError(err) + + // check queries + lock, _ = suite.app.LockupKeeper.GetLockByID(suite.ctx, lock.ID) + suite.Require().Equal(lock.Duration, time.Second*2) + + locks = suite.app.LockupKeeper.GetLocksLongerThanDurationDenom(suite.ctx, "stake", time.Second) + suite.Require().Equal(len(locks), 1) + + locks = suite.app.LockupKeeper.GetLocksLongerThanDurationDenom(suite.ctx, "stake", time.Second*2) + suite.Require().Equal(len(locks), 1) + + // check accumulations + acc = suite.app.LockupKeeper.GetPeriodLocksAccumulation(suite.ctx, types.QueryCondition{ + Denom: "stake", + Duration: time.Second, + }) + suite.Require().Equal(int64(0), acc.Int64()) + acc = suite.app.LockupKeeper.GetPeriodLocksAccumulation(suite.ctx, types.QueryCondition{ + Denom: "stake", + Duration: time.Second * 2, + }) + suite.Require().Equal(int64(10), acc.Int64()) +} diff --git a/x/lockup/keeper/msg_server.go b/x/lockup/keeper/msg_server.go index f051aafe043..f0c21704e21 100644 --- a/x/lockup/keeper/msg_server.go +++ b/x/lockup/keeper/msg_server.go @@ -155,3 +155,32 @@ func createBeginUnlockEvent(lock *types.PeriodLock) sdk.Event { sdk.NewAttribute(types.AttributePeriodLockUnlockTime, lock.EndTime.String()), ) } + +func (server msgServer) EditLockup(goCtx context.Context, msg *types.MsgEditLockup) (*types.MsgEditLockupResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + lock, err := server.keeper.GetLockByID(ctx, msg.ID) + if err != nil { + return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error()) + } + + if msg.Owner != lock.Owner { + 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.EditLockup(ctx, lock, lock.Duration) + if err != nil { + return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error()) + } + + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.TypeEvtLockTokens, + sdk.NewAttribute(types.AttributePeriodLockID, utils.Uint64ToString(lock.ID)), + sdk.NewAttribute(types.AttributePeriodLockOwner, lock.Owner), + sdk.NewAttribute(types.AttributePeriodLockDuration, lock.Duration.String()), + ), + }) + + return &types.MsgEditLockupResponse{}, nil +} diff --git a/x/lockup/keeper/msg_server_test.go b/x/lockup/keeper/msg_server_test.go index 042156cc4d6..ce1179ecab2 100644 --- a/x/lockup/keeper/msg_server_test.go +++ b/x/lockup/keeper/msg_server_test.go @@ -266,3 +266,78 @@ func (suite *KeeperTestSuite) TestMsgBeginUnlockingAll() { } } } + +func (suite *KeeperTestSuite) TestMsgEditLockup() { + type param struct { + coinsToLock sdk.Coins + isSyntheticLockup bool + lockOwner sdk.AccAddress + duration time.Duration + newDuration time.Duration + } + + tests := []struct { + name string + param param + expectPass bool + }{ + { + name: "edit lockups by duration", + param: param{ + coinsToLock: sdk.Coins{sdk.NewInt64Coin("stake", 10)}, // setup wallet + isSyntheticLockup: false, + lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet + duration: time.Second, + newDuration: time.Second * 2, + }, + expectPass: true, + }, + { + name: "edit lockups by lesser duration", + param: param{ + coinsToLock: sdk.Coins{sdk.NewInt64Coin("stake", 10)}, // setup wallet + isSyntheticLockup: false, + lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet + duration: time.Second, + newDuration: time.Second / 2, + }, + expectPass: false, + }, + { + name: "disallow edit when synthetic lockup exists", + param: param{ + coinsToLock: sdk.Coins{sdk.NewInt64Coin("stake", 10)}, // setup wallet + isSyntheticLockup: true, + lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet + duration: time.Second, + newDuration: time.Second * 2, + }, + expectPass: false, + }, + } + + for _, test := range tests { + suite.SetupTest() + + err := simapp.FundAccount(suite.app.BankKeeper, suite.ctx, test.param.lockOwner, test.param.coinsToLock) + suite.Require().NoError(err) + + msgServer := keeper.NewMsgServerImpl(suite.app.LockupKeeper) + c := sdk.WrapSDKContext(suite.ctx) + resp, err := msgServer.LockTokens(c, types.NewMsgLockTokens(test.param.lockOwner, test.param.duration, test.param.coinsToLock)) + suite.Require().NoError(err) + + if test.param.isSyntheticLockup { + err = suite.app.LockupKeeper.CreateSyntheticLockup(suite.ctx, resp.ID, "synthetic", time.Second, false) + suite.Require().NoError(err) + } + + _, err = msgServer.EditLockup(c, types.NewMsgEditLockup(param.lockOwner, resp.ID, param.newDuration)) + + if test.expectPass { + suite.Require().NoError(err) + } else { + suite.Require().Error(err) + } + } +} diff --git a/x/lockup/types/msgs.go b/x/lockup/types/msgs.go index 17eaf0974bb..bb6f8fe0810 100644 --- a/x/lockup/types/msgs.go +++ b/x/lockup/types/msgs.go @@ -12,6 +12,7 @@ const ( TypeMsgLockTokens = "lock_tokens" TypeMsgBeginUnlockingAll = "begin_unlocking_all" TypeMsgBeginUnlocking = "begin_unlocking" + TypeMsgEditLockup = "edit_lockup" ) var _ sdk.Msg = &MsgLockTokens{} @@ -92,3 +93,25 @@ func (m MsgBeginUnlocking) GetSigners() []sdk.AccAddress { owner, _ := sdk.AccAddressFromBech32(m.Owner) return []sdk.AccAddress{owner} } + +// NewMsgEditLockup creates a message to edit the properties of existing locks +func NewMsgEditLockup(owner sdk.AccAddress, id uint64, duration time.Duration) *MsgEditLockup { + return &MsgEditLockup{ + Owner: owner.String(), + ID: id, + Duration: duration, + } +} + +func (m MsgEditLockup) Route() string { return RouterKey } +func (m MsgEditLockup) Type() string { return TypeMsgEditLockup } +func (m MsgEditLockup) ValidateBasic() error { + return nil +} +func (m MsgEditLockup) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON((&m))) +} +func (m MsgEditLockup) GetSigners() []sdk.AccAddress { + owner, _ := sdk.AccAddressFromBech32(m.Owner) + return []sdk.AccAddress{owner} +} diff --git a/x/lockup/types/tx.pb.go b/x/lockup/types/tx.pb.go index 8e87af6464a..5cbc11c75d1 100644 --- a/x/lockup/types/tx.pb.go +++ b/x/lockup/types/tx.pb.go @@ -331,6 +331,111 @@ func (m *MsgBeginUnlockingResponse) GetSuccess() bool { return false } +type MsgEditLockup struct { + Owner string `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty" yaml:"owner"` + ID uint64 `protobuf:"varint,2,opt,name=ID,proto3" json:"ID,omitempty"` + // duration to be set. fails if lower than the current duration, or is unlocking + Duration time.Duration `protobuf:"bytes,3,opt,name=duration,proto3,stdduration" json:"duration,omitempty" yaml:"duration"` +} + +func (m *MsgEditLockup) Reset() { *m = MsgEditLockup{} } +func (m *MsgEditLockup) String() string { return proto.CompactTextString(m) } +func (*MsgEditLockup) ProtoMessage() {} +func (*MsgEditLockup) Descriptor() ([]byte, []int) { + return fileDescriptor_bcdad5af0d24735f, []int{6} +} +func (m *MsgEditLockup) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgEditLockup) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgEditLockup.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgEditLockup) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgEditLockup.Merge(m, src) +} +func (m *MsgEditLockup) XXX_Size() int { + return m.Size() +} +func (m *MsgEditLockup) XXX_DiscardUnknown() { + xxx_messageInfo_MsgEditLockup.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgEditLockup proto.InternalMessageInfo + +func (m *MsgEditLockup) GetOwner() string { + if m != nil { + return m.Owner + } + return "" +} + +func (m *MsgEditLockup) GetID() uint64 { + if m != nil { + return m.ID + } + return 0 +} + +func (m *MsgEditLockup) GetDuration() time.Duration { + if m != nil { + return m.Duration + } + return 0 +} + +type MsgEditLockupResponse struct { + Success bool `protobuf:"varint,1,opt,name=success,proto3" json:"success,omitempty"` +} + +func (m *MsgEditLockupResponse) Reset() { *m = MsgEditLockupResponse{} } +func (m *MsgEditLockupResponse) String() string { return proto.CompactTextString(m) } +func (*MsgEditLockupResponse) ProtoMessage() {} +func (*MsgEditLockupResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_bcdad5af0d24735f, []int{7} +} +func (m *MsgEditLockupResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgEditLockupResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgEditLockupResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgEditLockupResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgEditLockupResponse.Merge(m, src) +} +func (m *MsgEditLockupResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgEditLockupResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgEditLockupResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgEditLockupResponse proto.InternalMessageInfo + +func (m *MsgEditLockupResponse) GetSuccess() bool { + if m != nil { + return m.Success + } + return false +} + func init() { proto.RegisterType((*MsgLockTokens)(nil), "osmosis.lockup.MsgLockTokens") proto.RegisterType((*MsgLockTokensResponse)(nil), "osmosis.lockup.MsgLockTokensResponse") @@ -338,46 +443,51 @@ func init() { proto.RegisterType((*MsgBeginUnlockingAllResponse)(nil), "osmosis.lockup.MsgBeginUnlockingAllResponse") proto.RegisterType((*MsgBeginUnlocking)(nil), "osmosis.lockup.MsgBeginUnlocking") proto.RegisterType((*MsgBeginUnlockingResponse)(nil), "osmosis.lockup.MsgBeginUnlockingResponse") + proto.RegisterType((*MsgEditLockup)(nil), "osmosis.lockup.MsgEditLockup") + proto.RegisterType((*MsgEditLockupResponse)(nil), "osmosis.lockup.MsgEditLockupResponse") } func init() { proto.RegisterFile("osmosis/lockup/tx.proto", fileDescriptor_bcdad5af0d24735f) } var fileDescriptor_bcdad5af0d24735f = []byte{ - // 538 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x54, 0xbf, 0x6f, 0xd3, 0x40, - 0x14, 0x8e, 0x1d, 0x4a, 0xcb, 0x01, 0x81, 0x5a, 0x45, 0x38, 0x16, 0xd8, 0xc1, 0xe2, 0x47, 0x90, - 0xda, 0x3b, 0x52, 0x40, 0x48, 0x0c, 0x48, 0x98, 0x2c, 0x15, 0x44, 0x42, 0x56, 0x59, 0x18, 0x90, - 0x6c, 0xe7, 0xb8, 0x5a, 0xb1, 0x7d, 0x56, 0xce, 0x2e, 0xcd, 0xce, 0x1f, 0xc0, 0xc8, 0xcc, 0xc8, - 0xc0, 0xdf, 0xd1, 0xb1, 0x23, 0x53, 0x8a, 0x92, 0x8d, 0xb1, 0x7f, 0x01, 0xf2, 0x9d, 0xcf, 0x6a, - 0x92, 0x8a, 0x66, 0xea, 0x74, 0x79, 0xf7, 0xbd, 0xf7, 0xbd, 0xf7, 0x7d, 0xef, 0x62, 0x70, 0x9b, - 0xb2, 0x98, 0xb2, 0x90, 0xa1, 0x88, 0x06, 0x83, 0x3c, 0x45, 0xd9, 0x01, 0x4c, 0x87, 0x34, 0xa3, - 0x5a, 0xa3, 0x04, 0xa0, 0x00, 0x8c, 0x0d, 0x42, 0x09, 0xe5, 0x10, 0x2a, 0x7e, 0x89, 0x2c, 0xc3, - 0x24, 0x94, 0x92, 0x08, 0x23, 0x1e, 0xf9, 0xf9, 0x67, 0xd4, 0xcf, 0x87, 0x5e, 0x16, 0xd2, 0x44, - 0xe2, 0x01, 0xa7, 0x41, 0xbe, 0xc7, 0x30, 0xda, 0xef, 0xf8, 0x38, 0xf3, 0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0xff, 0x2f, 0x3f, 0xfd, 0x17, 0x00, 0x00, - 0xff, 0xff, 0x84, 0x9e, 0x53, 0xa5, 0xc2, 0x04, 0x00, 0x00, + // 582 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x54, 0x3f, 0x6f, 0xd3, 0x40, + 0x1c, 0x8d, 0x1d, 0x4a, 0xcb, 0x0f, 0x08, 0xd4, 0x2a, 0x22, 0xb1, 0xc0, 0x0e, 0x16, 0x7f, 0x82, + 0xd4, 0xde, 0x91, 0x02, 0x42, 0x62, 0x40, 0x22, 0x84, 0xa1, 0xa2, 0x91, 0x90, 0x55, 0x16, 0x06, + 0x24, 0xdb, 0x39, 0xae, 0x56, 0x1c, 0x5f, 0x94, 0xb3, 0x4b, 0xb3, 0xf3, 0x01, 0x18, 0xf9, 0x0c, + 0x0c, 0x48, 0x7c, 0x8b, 0x8e, 0x1d, 0x99, 0x52, 0x94, 0x6c, 0x8c, 0x1d, 0x98, 0x91, 0xcf, 0x39, + 0x37, 0xff, 0x44, 0x22, 0x24, 0x98, 0x9c, 0xf3, 0xfb, 0xfd, 0x79, 0xef, 0xdd, 0x8b, 0xe1, 0x3a, + 0xe3, 0x6d, 0xc6, 0x7d, 0x8e, 0x03, 0xe6, 0xb5, 0xe2, 0x0e, 0x8e, 0x0e, 0x51, 0xa7, 0xcb, 0x22, + 0xa6, 0x15, 0x46, 0x00, 0x4a, 0x01, 0x7d, 0x83, 0x32, 0xca, 0x04, 0x84, 0x93, 0x5f, 0x69, 0x95, + 0x6e, 0x50, 0xc6, 0x68, 0x40, 0xb0, 0x38, 0xb9, 0xf1, 0x7b, 0xdc, 0x8c, 0xbb, 0x4e, 0xe4, 0xb3, + 0x50, 0xe2, 0x9e, 0x18, 0x83, 0x5d, 0x87, 0x13, 0x7c, 0x50, 0x75, 0x49, 0xe4, 0x54, 0xb1, 0xc7, + 0x7c, 0x89, 0x97,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 0x18, 0xca, + 0x8f, 0x81, 0xa1, 0x7c, 0x1a, 0x1a, 0xb9, 0xe3, 0xa1, 0x91, 0xfb, 0x3e, 0x34, 0x72, 0x6f, 0xab, + 0x63, 0x09, 0x1f, 0x8d, 0xda, 0x0a, 0x1c, 0x97, 0xcb, 0x03, 0x3e, 0x78, 0x82, 0x0f, 0xb3, 0xcf, + 0x7b, 0x12, 0x78, 0xf7, 0xbc, 0x08, 0xd2, 0xc3, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x1e, 0x0b, + 0x41, 0xba, 0xfd, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -398,6 +508,8 @@ type MsgClient interface { BeginUnlockingAll(ctx context.Context, in *MsgBeginUnlockingAll, opts ...grpc.CallOption) (*MsgBeginUnlockingAllResponse, error) // MsgBeginUnlocking begins unlocking tokens by lock ID BeginUnlocking(ctx context.Context, in *MsgBeginUnlocking, opts ...grpc.CallOption) (*MsgBeginUnlockingResponse, error) + // MsgEditLockup edits the existing lockups by lock ID + EditLockup(ctx context.Context, in *MsgEditLockup, opts ...grpc.CallOption) (*MsgEditLockupResponse, error) } type msgClient struct { @@ -435,6 +547,15 @@ func (c *msgClient) BeginUnlocking(ctx context.Context, in *MsgBeginUnlocking, o return out, nil } +func (c *msgClient) EditLockup(ctx context.Context, in *MsgEditLockup, opts ...grpc.CallOption) (*MsgEditLockupResponse, error) { + out := new(MsgEditLockupResponse) + err := c.cc.Invoke(ctx, "/osmosis.lockup.Msg/EditLockup", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // LockTokens lock tokens @@ -443,6 +564,8 @@ type MsgServer interface { BeginUnlockingAll(context.Context, *MsgBeginUnlockingAll) (*MsgBeginUnlockingAllResponse, error) // MsgBeginUnlocking begins unlocking tokens by lock ID BeginUnlocking(context.Context, *MsgBeginUnlocking) (*MsgBeginUnlockingResponse, error) + // MsgEditLockup edits the existing lockups by lock ID + EditLockup(context.Context, *MsgEditLockup) (*MsgEditLockupResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -458,6 +581,9 @@ func (*UnimplementedMsgServer) BeginUnlockingAll(ctx context.Context, req *MsgBe func (*UnimplementedMsgServer) BeginUnlocking(ctx context.Context, req *MsgBeginUnlocking) (*MsgBeginUnlockingResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method BeginUnlocking not implemented") } +func (*UnimplementedMsgServer) EditLockup(ctx context.Context, req *MsgEditLockup) (*MsgEditLockupResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method EditLockup not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -517,6 +643,24 @@ func _Msg_BeginUnlocking_Handler(srv interface{}, ctx context.Context, dec func( return interceptor(ctx, in, info, handler) } +func _Msg_EditLockup_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgEditLockup) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).EditLockup(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/osmosis.lockup.Msg/EditLockup", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).EditLockup(ctx, req.(*MsgEditLockup)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "osmosis.lockup.Msg", HandlerType: (*MsgServer)(nil), @@ -533,6 +677,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "BeginUnlocking", Handler: _Msg_BeginUnlocking_Handler, }, + { + MethodName: "EditLockup", + Handler: _Msg_EditLockup_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "osmosis/lockup/tx.proto", @@ -767,6 +915,82 @@ func (m *MsgBeginUnlockingResponse) MarshalToSizedBuffer(dAtA []byte) (int, erro return len(dAtA) - i, nil } +func (m *MsgEditLockup) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgEditLockup) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgEditLockup) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + n2, err2 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.Duration, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.Duration):]) + if err2 != nil { + return 0, err2 + } + i -= n2 + i = encodeVarintTx(dAtA, i, uint64(n2)) + i-- + dAtA[i] = 0x1a + if m.ID != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.ID)) + i-- + dAtA[i] = 0x10 + } + if len(m.Owner) > 0 { + i -= len(m.Owner) + copy(dAtA[i:], m.Owner) + i = encodeVarintTx(dAtA, i, uint64(len(m.Owner))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgEditLockupResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgEditLockupResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgEditLockupResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Success { + i-- + if m.Success { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -873,6 +1097,36 @@ func (m *MsgBeginUnlockingResponse) Size() (n int) { return n } +func (m *MsgEditLockup) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Owner) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.ID != 0 { + n += 1 + sovTx(uint64(m.ID)) + } + l = github_com_gogo_protobuf_types.SizeOfStdDuration(m.Duration) + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgEditLockupResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Success { + n += 2 + } + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1468,6 +1722,210 @@ func (m *MsgBeginUnlockingResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgEditLockup) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgEditLockup: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgEditLockup: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Owner", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Owner = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) + } + m.ID = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ID |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Duration", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdDurationUnmarshal(&m.Duration, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgEditLockupResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgEditLockupResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgEditLockupResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Success", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Success = bool(v != 0) + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 From e60fb3b9445021e87ec6375243b7be2a005c401a Mon Sep 17 00:00:00 2001 From: mconcat Date: Thu, 14 Apr 2022 23:44:00 +0900 Subject: [PATCH 02/17] fix syntax --- x/lockup/keeper/msg_server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/lockup/keeper/msg_server.go b/x/lockup/keeper/msg_server.go index f0c21704e21..6e531e23f60 100644 --- a/x/lockup/keeper/msg_server.go +++ b/x/lockup/keeper/msg_server.go @@ -168,7 +168,7 @@ func (server msgServer) EditLockup(goCtx context.Context, msg *types.MsgEditLock 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.EditLockup(ctx, lock, lock.Duration) + err = server.keeper.EditLockup(ctx, *lock, lock.Duration) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error()) } From b2025719ca2857aec133b37e63b915024286fa01 Mon Sep 17 00:00:00 2001 From: mconcat Date: Thu, 14 Apr 2022 23:44:29 +0900 Subject: [PATCH 03/17] gofmt --- x/lockup/keeper/lock.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/lockup/keeper/lock.go b/x/lockup/keeper/lock.go index d8e8a827991..b357fec5e15 100644 --- a/x/lockup/keeper/lock.go +++ b/x/lockup/keeper/lock.go @@ -555,7 +555,7 @@ func (k Keeper) EditLockup(ctx sdk.Context, lock types.PeriodLock, newDuration t if !(newDuration > lock.Duration) { return fmt.Errorf("new duration should be greater than the original") } - + // update accumulation store for _, coin := range lock.Coins { k.accumulationStore(ctx, coin.Denom).Decrease(accumulationKey(lock.Duration), coin.Amount) @@ -569,4 +569,4 @@ func (k Keeper) EditLockup(ctx sdk.Context, lock types.PeriodLock, newDuration t k.setLockAndResetLockRefs(ctx, lock) return nil -} \ No newline at end of file +} From 520f40b13e6a8d10226c656415efdc722fb02d1b Mon Sep 17 00:00:00 2001 From: mconcat Date: Thu, 14 Apr 2022 23:51:16 +0900 Subject: [PATCH 04/17] fix --- x/lockup/keeper/lock.go | 6 +++++- x/lockup/keeper/msg_server_test.go | 2 +- x/lockup/types/msgs.go | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/x/lockup/keeper/lock.go b/x/lockup/keeper/lock.go index b357fec5e15..1e0dab208ee 100644 --- a/x/lockup/keeper/lock.go +++ b/x/lockup/keeper/lock.go @@ -6,6 +6,7 @@ import ( "time" "github.com/gogo/protobuf/proto" + "github.com/osmosis-labs/osmosis/v7/store" "github.com/osmosis-labs/osmosis/v7/x/lockup/types" @@ -566,7 +567,10 @@ func (k Keeper) EditLockup(ctx sdk.Context, lock types.PeriodLock, newDuration t } // update lockup - k.setLockAndResetLockRefs(ctx, lock) + err := k.setLockAndResetLockRefs(ctx, lock) + if err != nil { + return err + } return nil } diff --git a/x/lockup/keeper/msg_server_test.go b/x/lockup/keeper/msg_server_test.go index ce1179ecab2..ab01f9c54a2 100644 --- a/x/lockup/keeper/msg_server_test.go +++ b/x/lockup/keeper/msg_server_test.go @@ -332,7 +332,7 @@ func (suite *KeeperTestSuite) TestMsgEditLockup() { suite.Require().NoError(err) } - _, err = msgServer.EditLockup(c, types.NewMsgEditLockup(param.lockOwner, resp.ID, param.newDuration)) + _, err = msgServer.EditLockup(c, types.NewMsgEditLockup(test.param.lockOwner, resp.ID, test.param.newDuration)) if test.expectPass { suite.Require().NoError(err) diff --git a/x/lockup/types/msgs.go b/x/lockup/types/msgs.go index bb6f8fe0810..91dcc65e31e 100644 --- a/x/lockup/types/msgs.go +++ b/x/lockup/types/msgs.go @@ -108,9 +108,11 @@ func (m MsgEditLockup) Type() string { return TypeMsgEditLockup } func (m MsgEditLockup) ValidateBasic() error { return nil } + func (m MsgEditLockup) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON((&m))) } + func (m MsgEditLockup) GetSigners() []sdk.AccAddress { owner, _ := sdk.AccAddressFromBech32(m.Owner) return []sdk.AccAddress{owner} From ba815a5a9b1776c0bc5ad1c38952ed3bc10126b2 Mon Sep 17 00:00:00 2001 From: mconcat Date: Mon, 18 Apr 2022 23:15:34 +0900 Subject: [PATCH 05/17] Apply suggestions from code review Co-authored-by: Aleksandr Bezobchuk --- x/lockup/keeper/lock.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/x/lockup/keeper/lock.go b/x/lockup/keeper/lock.go index 1e0dab208ee..1aa16355849 100644 --- a/x/lockup/keeper/lock.go +++ b/x/lockup/keeper/lock.go @@ -539,9 +539,7 @@ func (k Keeper) unlockInternalLogic(ctx sdk.Context, lock types.PeriodLock) erro } func (k Keeper) EditLockup(ctx sdk.Context, lock types.PeriodLock, newDuration time.Duration) error { - // sanity check - // check unlocking if lock.IsUnlocking() { return fmt.Errorf("cannot edit unlocking lockup") } @@ -552,7 +550,6 @@ func (k Keeper) EditLockup(ctx sdk.Context, lock types.PeriodLock, newDuration t } if newDuration != 0 { - // check newDuration > duration if !(newDuration > lock.Duration) { return fmt.Errorf("new duration should be greater than the original") } From 54eff0f4eadc7f470e584df71c63292338f27e41 Mon Sep 17 00:00:00 2001 From: mconcat Date: Mon, 18 Apr 2022 23:20:37 +0900 Subject: [PATCH 06/17] EditLockup -> ExtendLockup, use Wrapf --- proto/osmosis/lockup/tx.proto | 6 +- x/lockup/keeper/lock.go | 2 +- x/lockup/keeper/lock_test.go | 4 +- x/lockup/keeper/msg_server.go | 12 +- x/lockup/types/tx.pb.go | 200 +++++++++++++++++----------------- 5 files changed, 112 insertions(+), 112 deletions(-) diff --git a/proto/osmosis/lockup/tx.proto b/proto/osmosis/lockup/tx.proto index 25941d643ee..d39ec6a4831 100644 --- a/proto/osmosis/lockup/tx.proto +++ b/proto/osmosis/lockup/tx.proto @@ -18,7 +18,7 @@ service Msg { // MsgBeginUnlocking begins unlocking tokens by lock ID rpc BeginUnlocking(MsgBeginUnlocking) returns (MsgBeginUnlockingResponse); // MsgEditLockup edits the existing lockups by lock ID - rpc EditLockup(MsgEditLockup) returns (MsgEditLockupResponse); + rpc ExtendLockup(MsgExtendLockup) returns (MsgExtendLockupResponse); } message MsgLockTokens { @@ -52,7 +52,7 @@ message MsgBeginUnlocking { } message MsgBeginUnlockingResponse { bool success = 1; } -message MsgEditLockup { +message MsgExtendLockup { string owner = 1 [ (gogoproto.moretags) = "yaml:\"owner\"" ]; uint64 ID = 2; @@ -67,4 +67,4 @@ message MsgEditLockup { // extend for other edit, e.g. cancel unlocking } -message MsgEditLockupResponse { bool success = 1; } +message MsgExtendLockupResponse { bool success = 1; } diff --git a/x/lockup/keeper/lock.go b/x/lockup/keeper/lock.go index 1aa16355849..77e0b19edcf 100644 --- a/x/lockup/keeper/lock.go +++ b/x/lockup/keeper/lock.go @@ -538,7 +538,7 @@ func (k Keeper) unlockInternalLogic(ctx sdk.Context, lock types.PeriodLock) erro return nil } -func (k Keeper) EditLockup(ctx sdk.Context, lock types.PeriodLock, newDuration time.Duration) error { +func (k Keeper) ExtendLockup(ctx sdk.Context, lock types.PeriodLock, newDuration time.Duration) error { if lock.IsUnlocking() { return fmt.Errorf("cannot edit unlocking lockup") diff --git a/x/lockup/keeper/lock_test.go b/x/lockup/keeper/lock_test.go index 744437e3426..4d950507e41 100644 --- a/x/lockup/keeper/lock_test.go +++ b/x/lockup/keeper/lock_test.go @@ -674,11 +674,11 @@ func (suite *KeeperTestSuite) TestEditLockup() { lock, _ := suite.app.LockupKeeper.GetLockByID(suite.ctx, 1) // duration decrease should fail - err = suite.app.LockupKeeper.EditLockup(suite.ctx, *lock, time.Second/2) + err = suite.app.LockupKeeper.ExtendLockup(suite.ctx, *lock, time.Second/2) suite.Require().Error(err) // duration increase should success - err = suite.app.LockupKeeper.EditLockup(suite.ctx, *lock, time.Second*2) + err = suite.app.LockupKeeper.ExtendLockup(suite.ctx, *lock, time.Second*2) suite.Require().NoError(err) // check queries diff --git a/x/lockup/keeper/msg_server.go b/x/lockup/keeper/msg_server.go index 6e531e23f60..19d993ce2ee 100644 --- a/x/lockup/keeper/msg_server.go +++ b/x/lockup/keeper/msg_server.go @@ -156,21 +156,21 @@ func createBeginUnlockEvent(lock *types.PeriodLock) sdk.Event { ) } -func (server msgServer) EditLockup(goCtx context.Context, msg *types.MsgEditLockup) (*types.MsgEditLockupResponse, error) { +func (server msgServer) ExtendLockup(goCtx context.Context, msg *types.MsgExtendLockup) (*types.MsgExtendLockupResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) lock, err := server.keeper.GetLockByID(ctx, msg.ID) if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error()) + return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, err.Error()) } if msg.Owner != lock.Owner { - return nil, sdkerrors.Wrap(types.ErrNotLockOwner, fmt.Sprintf("msg sender (%s) and lock owner (%s) does not match", msg.Owner, lock.Owner)) + return nil, sdkerrors.Wrapf(types.ErrNotLockOwner, fmt.Sprintf("msg sender (%s) and lock owner (%s) does not match", msg.Owner, lock.Owner)) } - err = server.keeper.EditLockup(ctx, *lock, lock.Duration) + err = server.keeper.ExtendLockup(ctx, *lock, lock.Duration) if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error()) + return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, err.Error()) } ctx.EventManager().EmitEvents(sdk.Events{ @@ -182,5 +182,5 @@ func (server msgServer) EditLockup(goCtx context.Context, msg *types.MsgEditLock ), }) - return &types.MsgEditLockupResponse{}, nil + return &types.MsgExtendLockupResponse{}, nil } diff --git a/x/lockup/types/tx.pb.go b/x/lockup/types/tx.pb.go index 5cbc11c75d1..d6c8a25b78d 100644 --- a/x/lockup/types/tx.pb.go +++ b/x/lockup/types/tx.pb.go @@ -331,25 +331,25 @@ func (m *MsgBeginUnlockingResponse) GetSuccess() bool { return false } -type MsgEditLockup struct { +type MsgExtendLockup struct { Owner string `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty" yaml:"owner"` ID uint64 `protobuf:"varint,2,opt,name=ID,proto3" json:"ID,omitempty"` // duration to be set. fails if lower than the current duration, or is unlocking Duration time.Duration `protobuf:"bytes,3,opt,name=duration,proto3,stdduration" json:"duration,omitempty" yaml:"duration"` } -func (m *MsgEditLockup) Reset() { *m = MsgEditLockup{} } -func (m *MsgEditLockup) String() string { return proto.CompactTextString(m) } -func (*MsgEditLockup) ProtoMessage() {} -func (*MsgEditLockup) Descriptor() ([]byte, []int) { +func (m *MsgExtendLockup) Reset() { *m = MsgExtendLockup{} } +func (m *MsgExtendLockup) String() string { return proto.CompactTextString(m) } +func (*MsgExtendLockup) ProtoMessage() {} +func (*MsgExtendLockup) Descriptor() ([]byte, []int) { return fileDescriptor_bcdad5af0d24735f, []int{6} } -func (m *MsgEditLockup) XXX_Unmarshal(b []byte) error { +func (m *MsgExtendLockup) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgEditLockup) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgExtendLockup) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgEditLockup.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgExtendLockup.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -359,55 +359,55 @@ func (m *MsgEditLockup) XXX_Marshal(b []byte, deterministic bool) ([]byte, error return b[:n], nil } } -func (m *MsgEditLockup) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgEditLockup.Merge(m, src) +func (m *MsgExtendLockup) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgExtendLockup.Merge(m, src) } -func (m *MsgEditLockup) XXX_Size() int { +func (m *MsgExtendLockup) XXX_Size() int { return m.Size() } -func (m *MsgEditLockup) XXX_DiscardUnknown() { - xxx_messageInfo_MsgEditLockup.DiscardUnknown(m) +func (m *MsgExtendLockup) XXX_DiscardUnknown() { + xxx_messageInfo_MsgExtendLockup.DiscardUnknown(m) } -var xxx_messageInfo_MsgEditLockup proto.InternalMessageInfo +var xxx_messageInfo_MsgExtendLockup proto.InternalMessageInfo -func (m *MsgEditLockup) GetOwner() string { +func (m *MsgExtendLockup) GetOwner() string { if m != nil { return m.Owner } return "" } -func (m *MsgEditLockup) GetID() uint64 { +func (m *MsgExtendLockup) GetID() uint64 { if m != nil { return m.ID } return 0 } -func (m *MsgEditLockup) GetDuration() time.Duration { +func (m *MsgExtendLockup) GetDuration() time.Duration { if m != nil { return m.Duration } return 0 } -type MsgEditLockupResponse struct { +type MsgExtendLockupResponse struct { Success bool `protobuf:"varint,1,opt,name=success,proto3" json:"success,omitempty"` } -func (m *MsgEditLockupResponse) Reset() { *m = MsgEditLockupResponse{} } -func (m *MsgEditLockupResponse) String() string { return proto.CompactTextString(m) } -func (*MsgEditLockupResponse) ProtoMessage() {} -func (*MsgEditLockupResponse) Descriptor() ([]byte, []int) { +func (m *MsgExtendLockupResponse) Reset() { *m = MsgExtendLockupResponse{} } +func (m *MsgExtendLockupResponse) String() string { return proto.CompactTextString(m) } +func (*MsgExtendLockupResponse) ProtoMessage() {} +func (*MsgExtendLockupResponse) Descriptor() ([]byte, []int) { return fileDescriptor_bcdad5af0d24735f, []int{7} } -func (m *MsgEditLockupResponse) XXX_Unmarshal(b []byte) error { +func (m *MsgExtendLockupResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgEditLockupResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgExtendLockupResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgEditLockupResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgExtendLockupResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -417,19 +417,19 @@ func (m *MsgEditLockupResponse) XXX_Marshal(b []byte, deterministic bool) ([]byt return b[:n], nil } } -func (m *MsgEditLockupResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgEditLockupResponse.Merge(m, src) +func (m *MsgExtendLockupResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgExtendLockupResponse.Merge(m, src) } -func (m *MsgEditLockupResponse) XXX_Size() int { +func (m *MsgExtendLockupResponse) XXX_Size() int { return m.Size() } -func (m *MsgEditLockupResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgEditLockupResponse.DiscardUnknown(m) +func (m *MsgExtendLockupResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgExtendLockupResponse.DiscardUnknown(m) } -var xxx_messageInfo_MsgEditLockupResponse proto.InternalMessageInfo +var xxx_messageInfo_MsgExtendLockupResponse proto.InternalMessageInfo -func (m *MsgEditLockupResponse) GetSuccess() bool { +func (m *MsgExtendLockupResponse) GetSuccess() bool { if m != nil { return m.Success } @@ -443,51 +443,51 @@ func init() { proto.RegisterType((*MsgBeginUnlockingAllResponse)(nil), "osmosis.lockup.MsgBeginUnlockingAllResponse") proto.RegisterType((*MsgBeginUnlocking)(nil), "osmosis.lockup.MsgBeginUnlocking") proto.RegisterType((*MsgBeginUnlockingResponse)(nil), "osmosis.lockup.MsgBeginUnlockingResponse") - proto.RegisterType((*MsgEditLockup)(nil), "osmosis.lockup.MsgEditLockup") - proto.RegisterType((*MsgEditLockupResponse)(nil), "osmosis.lockup.MsgEditLockupResponse") + proto.RegisterType((*MsgExtendLockup)(nil), "osmosis.lockup.MsgExtendLockup") + proto.RegisterType((*MsgExtendLockupResponse)(nil), "osmosis.lockup.MsgExtendLockupResponse") } func init() { proto.RegisterFile("osmosis/lockup/tx.proto", fileDescriptor_bcdad5af0d24735f) } var fileDescriptor_bcdad5af0d24735f = []byte{ - // 582 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x54, 0x3f, 0x6f, 0xd3, 0x40, - 0x1c, 0x8d, 0x1d, 0x4a, 0xcb, 0x0f, 0x08, 0xd4, 0x2a, 0x22, 0xb1, 0xc0, 0x0e, 0x16, 0x7f, 0x82, - 0xd4, 0xde, 0x91, 0x02, 0x42, 0x62, 0x40, 0x22, 0x84, 0xa1, 0xa2, 0x91, 0x90, 0x55, 0x16, 0x06, - 0x24, 0xdb, 0x39, 0xae, 0x56, 0x1c, 0x5f, 0x94, 0xb3, 0x4b, 0xb3, 0xf3, 0x01, 0x18, 0xf9, 0x0c, - 0x0c, 0x48, 0x7c, 0x8b, 0x8e, 0x1d, 0x99, 0x52, 0x94, 0x6c, 0x8c, 0x1d, 0x98, 0x91, 0xcf, 0x39, - 0x37, 0xff, 0x44, 0x22, 0x24, 0x98, 0x9c, 0xf3, 0xfb, 0xfd, 0x79, 0xef, 0xdd, 0x8b, 0xe1, 0x3a, - 0xe3, 0x6d, 0xc6, 0x7d, 0x8e, 0x03, 0xe6, 0xb5, 0xe2, 0x0e, 0x8e, 0x0e, 0x51, 0xa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0xfc, 0x11, 0xce, 0xb6, 0x52, 0x58, 0x9f, 0x4d, - 0xef, 0xed, 0x39, 0xbd, 0x33, 0x55, 0xfa, 0xe6, 0x32, 0x55, 0xd9, 0xa2, 0x77, 0x50, 0x98, 0xca, - 0xe3, 0xad, 0x85, 0xfd, 0xfa, 0xfd, 0x85, 0x25, 0xd9, 0x7c, 0x1b, 0x60, 0x2c, 0x07, 0xf3, 0xcc, - 0x39, 0x83, 0xe7, 0x9a, 0x33, 0x7b, 0x25, 0xb5, 0x57, 0x47, 0x03, 0x43, 0x39, 0x1e, 0x18, 0xca, - 0x8f, 0x81, 0xa1, 0x7c, 0x1a, 0x1a, 0xb9, 0xe3, 0xa1, 0x91, 0xfb, 0x3e, 0x34, 0x72, 0x6f, 0xab, - 0x63, 0x09, 0x1f, 0x8d, 0xda, 0x0a, 0x1c, 0x97, 0xcb, 0x03, 0x3e, 0x78, 0x82, 0x0f, 0xb3, 0xcf, - 0x7b, 0x12, 0x78, 0xf7, 0xbc, 0x08, 0xd2, 0xc3, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x1e, 0x0b, - 0x41, 0xba, 0xfd, 0x05, 0x00, 0x00, + // 590 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x54, 0xcd, 0x6e, 0xd3, 0x4c, + 0x14, 0x8d, 0x9d, 0xaf, 0x5f, 0xcb, 0xa5, 0xa4, 0xd4, 0x2a, 0x6a, 0x62, 0x81, 0x1d, 0x2c, 0xa0, + 0x41, 0x6a, 0x3d, 0xa4, 0x05, 0x21, 0xb1, 0x40, 0x22, 0x84, 0x45, 0x05, 0x91, 0x90, 0x55, 0x24, + 0xc4, 0x02, 0xc9, 0x76, 0x86, 0xa9, 0x15, 0xc7, 0x63, 0x65, 0xec, 0x92, 0xec, 0x79, 0x00, 0x96, + 0x3c, 0x03, 0x0b, 0x36, 0xbc, 0x44, 0x97, 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 0xb3, 0x6e, 0x84, 0x03, 0x6e, 0x41, 0x1c, 0xfe, 0xb1, 0xca, 0xf1, 0xfc, 0xe6, + 0xff, 0x66, 0x7e, 0x8d, 0x03, 0xd8, 0x9e, 0x5a, 0x7a, 0xb1, 0xd4, 0xfd, 0x9f, 0x32, 0xe4, 0x1b, + 0x8c, 0x28, 0x16, 0xc0, 0xd8, 0x8f, 0xf3, 0xc6, 0x74, 0x1a, 0x26, 0x52, 0xab, 0xde, 0xfe, 0x2d, + 0x9c, 0x4d, 0x25, 0xb0, 0x39, 0x9b, 0xe0, 0x5b, 0x73, 0x7a, 0x67, 0xaa, 0xd4, 0xdd, 0x65, 0xaa, + 0xb2, 0x41, 0x6f, 0xa1, 0x30, 0x95, 0xc9, 0x9b, 0x0b, 0xfb, 0xd5, 0xbb, 0x0b, 0x4b, 0x32, 0xfe, + 0xd7, 0xb0, 0x3e, 0x91, 0x05, 0x7d, 0x4e, 0xeb, 0x78, 0x81, 0xba, 0xb3, 0xa0, 0x40, 0x30, 0xd7, + 0x9e, 0x9f, 0x0e, 0x34, 0xe9, 0x6c, 0xa0, 0x49, 0xdf, 0x07, 0x9a, 0xf4, 0x71, 0xa8, 0xe5, 0xce, + 0x86, 0x5a, 0xee, 0xdb, 0x50, 0xcb, 0xbd, 0xa9, 0x8e, 0x65, 0x7d, 0x44, 0xb6, 0xe7, 0xdb, 0x0e, + 0x13, 0x17, 0x74, 0xf2, 0x10, 0x75, 0xb3, 0x3f, 0xfa, 0x24, 0xfa, 0xce, 0xff, 0x3c, 0x50, 0x07, + 0xbf, 0x02, 0x00, 0x00, 0xff, 0xff, 0xba, 0x65, 0x88, 0x8d, 0x07, 0x06, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -509,7 +509,7 @@ type MsgClient interface { // MsgBeginUnlocking begins unlocking tokens by lock ID BeginUnlocking(ctx context.Context, in *MsgBeginUnlocking, opts ...grpc.CallOption) (*MsgBeginUnlockingResponse, error) // MsgEditLockup edits the existing lockups by lock ID - EditLockup(ctx context.Context, in *MsgEditLockup, opts ...grpc.CallOption) (*MsgEditLockupResponse, error) + ExtendLockup(ctx context.Context, in *MsgExtendLockup, opts ...grpc.CallOption) (*MsgExtendLockupResponse, error) } type msgClient struct { @@ -547,9 +547,9 @@ func (c *msgClient) BeginUnlocking(ctx context.Context, in *MsgBeginUnlocking, o return out, nil } -func (c *msgClient) EditLockup(ctx context.Context, in *MsgEditLockup, opts ...grpc.CallOption) (*MsgEditLockupResponse, error) { - out := new(MsgEditLockupResponse) - err := c.cc.Invoke(ctx, "/osmosis.lockup.Msg/EditLockup", in, out, opts...) +func (c *msgClient) ExtendLockup(ctx context.Context, in *MsgExtendLockup, opts ...grpc.CallOption) (*MsgExtendLockupResponse, error) { + out := new(MsgExtendLockupResponse) + err := c.cc.Invoke(ctx, "/osmosis.lockup.Msg/ExtendLockup", in, out, opts...) if err != nil { return nil, err } @@ -565,7 +565,7 @@ type MsgServer interface { // MsgBeginUnlocking begins unlocking tokens by lock ID BeginUnlocking(context.Context, *MsgBeginUnlocking) (*MsgBeginUnlockingResponse, error) // MsgEditLockup edits the existing lockups by lock ID - EditLockup(context.Context, *MsgEditLockup) (*MsgEditLockupResponse, error) + ExtendLockup(context.Context, *MsgExtendLockup) (*MsgExtendLockupResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -581,8 +581,8 @@ func (*UnimplementedMsgServer) BeginUnlockingAll(ctx context.Context, req *MsgBe func (*UnimplementedMsgServer) BeginUnlocking(ctx context.Context, req *MsgBeginUnlocking) (*MsgBeginUnlockingResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method BeginUnlocking not implemented") } -func (*UnimplementedMsgServer) EditLockup(ctx context.Context, req *MsgEditLockup) (*MsgEditLockupResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method EditLockup not implemented") +func (*UnimplementedMsgServer) ExtendLockup(ctx context.Context, req *MsgExtendLockup) (*MsgExtendLockupResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ExtendLockup not implemented") } func RegisterMsgServer(s grpc1.Server, srv MsgServer) { @@ -643,20 +643,20 @@ func _Msg_BeginUnlocking_Handler(srv interface{}, ctx context.Context, dec func( return interceptor(ctx, in, info, handler) } -func _Msg_EditLockup_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgEditLockup) +func _Msg_ExtendLockup_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgExtendLockup) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MsgServer).EditLockup(ctx, in) + return srv.(MsgServer).ExtendLockup(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/osmosis.lockup.Msg/EditLockup", + FullMethod: "/osmosis.lockup.Msg/ExtendLockup", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).EditLockup(ctx, req.(*MsgEditLockup)) + return srv.(MsgServer).ExtendLockup(ctx, req.(*MsgExtendLockup)) } return interceptor(ctx, in, info, handler) } @@ -678,8 +678,8 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ Handler: _Msg_BeginUnlocking_Handler, }, { - MethodName: "EditLockup", - Handler: _Msg_EditLockup_Handler, + MethodName: "ExtendLockup", + Handler: _Msg_ExtendLockup_Handler, }, }, Streams: []grpc.StreamDesc{}, @@ -915,7 +915,7 @@ func (m *MsgBeginUnlockingResponse) MarshalToSizedBuffer(dAtA []byte) (int, erro return len(dAtA) - i, nil } -func (m *MsgEditLockup) Marshal() (dAtA []byte, err error) { +func (m *MsgExtendLockup) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -925,12 +925,12 @@ func (m *MsgEditLockup) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgEditLockup) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgExtendLockup) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgEditLockup) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgExtendLockup) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -958,7 +958,7 @@ func (m *MsgEditLockup) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MsgEditLockupResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgExtendLockupResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -968,12 +968,12 @@ func (m *MsgEditLockupResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgEditLockupResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgExtendLockupResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgEditLockupResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgExtendLockupResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -1097,7 +1097,7 @@ func (m *MsgBeginUnlockingResponse) Size() (n int) { return n } -func (m *MsgEditLockup) Size() (n int) { +func (m *MsgExtendLockup) Size() (n int) { if m == nil { return 0 } @@ -1115,7 +1115,7 @@ func (m *MsgEditLockup) Size() (n int) { return n } -func (m *MsgEditLockupResponse) Size() (n int) { +func (m *MsgExtendLockupResponse) Size() (n int) { if m == nil { return 0 } @@ -1722,7 +1722,7 @@ func (m *MsgBeginUnlockingResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgEditLockup) Unmarshal(dAtA []byte) error { +func (m *MsgExtendLockup) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1745,10 +1745,10 @@ func (m *MsgEditLockup) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgEditLockup: wiretype end group for non-group") + return fmt.Errorf("proto: MsgExtendLockup: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgEditLockup: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgExtendLockup: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -1856,7 +1856,7 @@ func (m *MsgEditLockup) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgEditLockupResponse) Unmarshal(dAtA []byte) error { +func (m *MsgExtendLockupResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1879,10 +1879,10 @@ func (m *MsgEditLockupResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgEditLockupResponse: wiretype end group for non-group") + return fmt.Errorf("proto: MsgExtendLockupResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgEditLockupResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgExtendLockupResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: From a79cbdac3a5437c7eeb66750e5af97947877b394 Mon Sep 17 00:00:00 2001 From: mconcat Date: Mon, 18 Apr 2022 23:46:07 +0900 Subject: [PATCH 07/17] fix test --- x/lockup/keeper/lock.go | 13 +++++++++---- x/lockup/keeper/lock_test.go | 7 ++++++- x/lockup/keeper/msg_server.go | 2 +- x/lockup/keeper/msg_server_test.go | 6 +++--- x/lockup/types/msgs.go | 18 +++++++++--------- 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/x/lockup/keeper/lock.go b/x/lockup/keeper/lock.go index 77e0b19edcf..dd095579478 100644 --- a/x/lockup/keeper/lock.go +++ b/x/lockup/keeper/lock.go @@ -539,7 +539,6 @@ func (k Keeper) unlockInternalLogic(ctx sdk.Context, lock types.PeriodLock) erro } func (k Keeper) ExtendLockup(ctx sdk.Context, lock types.PeriodLock, newDuration time.Duration) error { - if lock.IsUnlocking() { return fmt.Errorf("cannot edit unlocking lockup") } @@ -549,7 +548,10 @@ func (k Keeper) ExtendLockup(ctx sdk.Context, lock types.PeriodLock, newDuration return fmt.Errorf("cannot edit lockup with synthetic lock") } + oldLock := lock + if newDuration != 0 { + fmt.Println(newDuration, lock.Duration) if !(newDuration > lock.Duration) { return fmt.Errorf("new duration should be greater than the original") } @@ -564,10 +566,13 @@ func (k Keeper) ExtendLockup(ctx sdk.Context, lock types.PeriodLock, newDuration } // update lockup - err := k.setLockAndResetLockRefs(ctx, lock) + err := k.deleteLockRefs(ctx, unlockingPrefix(oldLock.IsUnlocking()), oldLock) if err != nil { return err } - - return nil + err = k.addLockRefs(ctx, lock) + if err != nil { + return err + } + return k.setLock(ctx, lock) } diff --git a/x/lockup/keeper/lock_test.go b/x/lockup/keeper/lock_test.go index 4d950507e41..65372c43b92 100644 --- a/x/lockup/keeper/lock_test.go +++ b/x/lockup/keeper/lock_test.go @@ -696,10 +696,15 @@ func (suite *KeeperTestSuite) TestEditLockup() { Denom: "stake", Duration: time.Second, }) - suite.Require().Equal(int64(0), acc.Int64()) + suite.Require().Equal(int64(10), acc.Int64()) acc = suite.app.LockupKeeper.GetPeriodLocksAccumulation(suite.ctx, types.QueryCondition{ Denom: "stake", Duration: time.Second * 2, }) suite.Require().Equal(int64(10), acc.Int64()) + acc = suite.app.LockupKeeper.GetPeriodLocksAccumulation(suite.ctx, types.QueryCondition{ + Denom: "stake", + Duration: time.Second * 3, + }) + suite.Require().Equal(int64(0), acc.Int64()) } diff --git a/x/lockup/keeper/msg_server.go b/x/lockup/keeper/msg_server.go index 19d993ce2ee..393e16aba3e 100644 --- a/x/lockup/keeper/msg_server.go +++ b/x/lockup/keeper/msg_server.go @@ -168,7 +168,7 @@ func (server msgServer) ExtendLockup(goCtx context.Context, msg *types.MsgExtend return nil, sdkerrors.Wrapf(types.ErrNotLockOwner, fmt.Sprintf("msg sender (%s) and lock owner (%s) does not match", msg.Owner, lock.Owner)) } - err = server.keeper.ExtendLockup(ctx, *lock, lock.Duration) + err = server.keeper.ExtendLockup(ctx, *lock, msg.Duration) if err != nil { return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, err.Error()) } diff --git a/x/lockup/keeper/msg_server_test.go b/x/lockup/keeper/msg_server_test.go index ab01f9c54a2..6546c0b2aa1 100644 --- a/x/lockup/keeper/msg_server_test.go +++ b/x/lockup/keeper/msg_server_test.go @@ -332,12 +332,12 @@ func (suite *KeeperTestSuite) TestMsgEditLockup() { suite.Require().NoError(err) } - _, err = msgServer.EditLockup(c, types.NewMsgEditLockup(test.param.lockOwner, resp.ID, test.param.newDuration)) + _, err = msgServer.ExtendLockup(c, types.NewMsgExtendLockup(test.param.lockOwner, resp.ID, test.param.newDuration)) if test.expectPass { - suite.Require().NoError(err) + suite.Require().NoError(err, test.name) } else { - suite.Require().Error(err) + suite.Require().Error(err, test.name) } } } diff --git a/x/lockup/types/msgs.go b/x/lockup/types/msgs.go index 91dcc65e31e..9d7f5184353 100644 --- a/x/lockup/types/msgs.go +++ b/x/lockup/types/msgs.go @@ -12,7 +12,7 @@ const ( TypeMsgLockTokens = "lock_tokens" TypeMsgBeginUnlockingAll = "begin_unlocking_all" TypeMsgBeginUnlocking = "begin_unlocking" - TypeMsgEditLockup = "edit_lockup" + TypeMsgExtendLockup = "edit_lockup" ) var _ sdk.Msg = &MsgLockTokens{} @@ -94,26 +94,26 @@ func (m MsgBeginUnlocking) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{owner} } -// NewMsgEditLockup creates a message to edit the properties of existing locks -func NewMsgEditLockup(owner sdk.AccAddress, id uint64, duration time.Duration) *MsgEditLockup { - return &MsgEditLockup{ +// NewMsgExtendLockup creates a message to edit the properties of existing locks +func NewMsgExtendLockup(owner sdk.AccAddress, id uint64, duration time.Duration) *MsgExtendLockup { + return &MsgExtendLockup{ Owner: owner.String(), ID: id, Duration: duration, } } -func (m MsgEditLockup) Route() string { return RouterKey } -func (m MsgEditLockup) Type() string { return TypeMsgEditLockup } -func (m MsgEditLockup) ValidateBasic() error { +func (m MsgExtendLockup) Route() string { return RouterKey } +func (m MsgExtendLockup) Type() string { return TypeMsgExtendLockup } +func (m MsgExtendLockup) ValidateBasic() error { return nil } -func (m MsgEditLockup) GetSignBytes() []byte { +func (m MsgExtendLockup) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON((&m))) } -func (m MsgEditLockup) GetSigners() []sdk.AccAddress { +func (m MsgExtendLockup) GetSigners() []sdk.AccAddress { owner, _ := sdk.AccAddressFromBech32(m.Owner) return []sdk.AccAddress{owner} } From f61fed4b4b2103c4bf455077a370792a2aac7582 Mon Sep 17 00:00:00 2001 From: mconcat Date: Tue, 19 Apr 2022 00:06:27 +0900 Subject: [PATCH 08/17] add duration check on MsgExtendLockup --- x/lockup/types/msgs.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/x/lockup/types/msgs.go b/x/lockup/types/msgs.go index 9d7f5184353..b96c0c91882 100644 --- a/x/lockup/types/msgs.go +++ b/x/lockup/types/msgs.go @@ -106,6 +106,9 @@ func NewMsgExtendLockup(owner sdk.AccAddress, id uint64, duration time.Duration) func (m MsgExtendLockup) Route() string { return RouterKey } func (m MsgExtendLockup) Type() string { return TypeMsgExtendLockup } func (m MsgExtendLockup) ValidateBasic() error { + if m.Duration <= 0 { + return fmt.Errorf("duration should be positive: %d < 0", m.Duration) + } return nil } From 5c45211953df8ab80cf640382089b437bdfee09f Mon Sep 17 00:00:00 2001 From: mconcat Date: Mon, 25 Apr 2022 21:52:54 +0900 Subject: [PATCH 09/17] Apply suggestions from code review Co-authored-by: Aleksandr Bezobchuk --- x/lockup/keeper/lock.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/x/lockup/keeper/lock.go b/x/lockup/keeper/lock.go index dd095579478..12d72125b75 100644 --- a/x/lockup/keeper/lock.go +++ b/x/lockup/keeper/lock.go @@ -545,14 +545,13 @@ func (k Keeper) ExtendLockup(ctx sdk.Context, lock types.PeriodLock, newDuration // check synthetic lockup exists if k.HasAnySyntheticLockups(ctx, lock.ID) { - return fmt.Errorf("cannot edit lockup with synthetic lock") + return fmt.Errorf("cannot edit lockup with synthetic lock %d", lock.ID) } oldLock := lock if newDuration != 0 { - fmt.Println(newDuration, lock.Duration) - if !(newDuration > lock.Duration) { + if newDuration < lock.Duration { return fmt.Errorf("new duration should be greater than the original") } @@ -570,9 +569,11 @@ func (k Keeper) ExtendLockup(ctx sdk.Context, lock types.PeriodLock, newDuration if err != nil { return err } + err = k.addLockRefs(ctx, lock) if err != nil { return err } + return k.setLock(ctx, lock) } From b6e31c9949efa2f4fc1ec3c7b005c5a9f816c824 Mon Sep 17 00:00:00 2001 From: mconcat Date: Mon, 25 Apr 2022 22:02:51 +0900 Subject: [PATCH 10/17] Update x/lockup/keeper/lock.go Co-authored-by: Aleksandr Bezobchuk --- x/lockup/keeper/lock.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/lockup/keeper/lock.go b/x/lockup/keeper/lock.go index 12d72125b75..ed71827979e 100644 --- a/x/lockup/keeper/lock.go +++ b/x/lockup/keeper/lock.go @@ -540,7 +540,7 @@ func (k Keeper) unlockInternalLogic(ctx sdk.Context, lock types.PeriodLock) erro func (k Keeper) ExtendLockup(ctx sdk.Context, lock types.PeriodLock, newDuration time.Duration) error { if lock.IsUnlocking() { - return fmt.Errorf("cannot edit unlocking lockup") + return fmt.Errorf("cannot edit unlocking lockup for lock %d", lock.ID) } // check synthetic lockup exists From 5999bd23d96d6cfdf0e59cb7ce3ff7335bfd966b Mon Sep 17 00:00:00 2001 From: mconcat Date: Mon, 25 Apr 2022 22:09:07 +0900 Subject: [PATCH 11/17] fix msg validation --- x/lockup/types/msgs.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/x/lockup/types/msgs.go b/x/lockup/types/msgs.go index b96c0c91882..b0e0c7d7dab 100644 --- a/x/lockup/types/msgs.go +++ b/x/lockup/types/msgs.go @@ -106,6 +106,12 @@ func NewMsgExtendLockup(owner sdk.AccAddress, id uint64, duration time.Duration) func (m MsgExtendLockup) Route() string { return RouterKey } func (m MsgExtendLockup) Type() string { return TypeMsgExtendLockup } func (m MsgExtendLockup) ValidateBasic() error { + if len(m.Owner) == 0 { + return fmt.Errorf("owner is empty") + } + if m.ID == 0 { + return fmt.Errorf("id is empty") + } if m.Duration <= 0 { return fmt.Errorf("duration should be positive: %d < 0", m.Duration) } From 32b2a274edca48dd0ed7d8221ef3d8771727eef8 Mon Sep 17 00:00:00 2001 From: mconcat Date: Tue, 26 Apr 2022 00:48:47 +0900 Subject: [PATCH 12/17] protodoc for MsgExtendLockup --- proto/osmosis/lockup/tx.proto | 2 ++ 1 file changed, 2 insertions(+) diff --git a/proto/osmosis/lockup/tx.proto b/proto/osmosis/lockup/tx.proto index d39ec6a4831..279278fd869 100644 --- a/proto/osmosis/lockup/tx.proto +++ b/proto/osmosis/lockup/tx.proto @@ -52,6 +52,8 @@ message MsgBeginUnlocking { } message MsgBeginUnlockingResponse { bool success = 1; } +// MsgExtendLockup extends the existing lockup's duration. +// The new duration is longer than the original. message MsgExtendLockup { string owner = 1 [ (gogoproto.moretags) = "yaml:\"owner\"" ]; uint64 ID = 2; From 5d9d2761abfa730d91b81921ecaa374ddecbbcf3 Mon Sep 17 00:00:00 2001 From: mconcat Date: Thu, 28 Apr 2022 03:03:58 +0900 Subject: [PATCH 13/17] fix lock lint --- x/lockup/keeper/lock_test.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/x/lockup/keeper/lock_test.go b/x/lockup/keeper/lock_test.go index 445bed40c08..204bbe8c27d 100644 --- a/x/lockup/keeper/lock_test.go +++ b/x/lockup/keeper/lock_test.go @@ -645,7 +645,7 @@ func (suite *KeeperTestSuite) TestEditLockup() { suite.SetupTest() // initial check - locks, err := suite.app.LockupKeeper.GetPeriodLocks(suite.ctx) + locks, err := suite.App.LockupKeeper.GetPeriodLocks(suite.Ctx) suite.Require().NoError(err) suite.Require().Len(locks, 0) @@ -657,44 +657,44 @@ func (suite *KeeperTestSuite) TestEditLockup() { suite.LockTokens(addr, coins, time.Second) // check accumulations - acc := suite.app.LockupKeeper.GetPeriodLocksAccumulation(suite.ctx, types.QueryCondition{ + acc := suite.App.LockupKeeper.GetPeriodLocksAccumulation(suite.Ctx, types.QueryCondition{ Denom: "stake", Duration: time.Second, }) suite.Require().Equal(int64(10), acc.Int64()) - lock, _ := suite.app.LockupKeeper.GetLockByID(suite.ctx, 1) + lock, _ := suite.App.LockupKeeper.GetLockByID(suite.Ctx, 1) // duration decrease should fail - err = suite.app.LockupKeeper.ExtendLockup(suite.ctx, *lock, time.Second/2) + err = suite.App.LockupKeeper.ExtendLockup(suite.Ctx, *lock, time.Second/2) suite.Require().Error(err) // duration increase should success - err = suite.app.LockupKeeper.ExtendLockup(suite.ctx, *lock, time.Second*2) + err = suite.App.LockupKeeper.ExtendLockup(suite.Ctx, *lock, time.Second*2) suite.Require().NoError(err) // check queries - lock, _ = suite.app.LockupKeeper.GetLockByID(suite.ctx, lock.ID) + lock, _ = suite.App.LockupKeeper.GetLockByID(suite.Ctx, lock.ID) suite.Require().Equal(lock.Duration, time.Second*2) - locks = suite.app.LockupKeeper.GetLocksLongerThanDurationDenom(suite.ctx, "stake", time.Second) + locks = suite.App.LockupKeeper.GetLocksLongerThanDurationDenom(suite.Ctx, "stake", time.Second) suite.Require().Equal(len(locks), 1) - locks = suite.app.LockupKeeper.GetLocksLongerThanDurationDenom(suite.ctx, "stake", time.Second*2) + locks = suite.App.LockupKeeper.GetLocksLongerThanDurationDenom(suite.Ctx, "stake", time.Second*2) suite.Require().Equal(len(locks), 1) // check accumulations - acc = suite.app.LockupKeeper.GetPeriodLocksAccumulation(suite.ctx, types.QueryCondition{ + acc = suite.App.LockupKeeper.GetPeriodLocksAccumulation(suite.Ctx, types.QueryCondition{ Denom: "stake", Duration: time.Second, }) suite.Require().Equal(int64(10), acc.Int64()) - acc = suite.app.LockupKeeper.GetPeriodLocksAccumulation(suite.ctx, types.QueryCondition{ + acc = suite.App.LockupKeeper.GetPeriodLocksAccumulation(suite.Ctx, types.QueryCondition{ Denom: "stake", Duration: time.Second * 2, }) suite.Require().Equal(int64(10), acc.Int64()) - acc = suite.app.LockupKeeper.GetPeriodLocksAccumulation(suite.ctx, types.QueryCondition{ + acc = suite.App.LockupKeeper.GetPeriodLocksAccumulation(suite.Ctx, types.QueryCondition{ Denom: "stake", Duration: time.Second * 3, }) From 5d1c61d1b44d77812f8b31d131633bdd96e0f372 Mon Sep 17 00:00:00 2001 From: mconcat Date: Thu, 28 Apr 2022 06:13:40 +0900 Subject: [PATCH 14/17] typo --- x/lockup/keeper/msg_server_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/x/lockup/keeper/msg_server_test.go b/x/lockup/keeper/msg_server_test.go index 8cfbe1692d9..1c0aab1a004 100644 --- a/x/lockup/keeper/msg_server_test.go +++ b/x/lockup/keeper/msg_server_test.go @@ -6,6 +6,7 @@ import ( "github.com/osmosis-labs/osmosis/v7/x/lockup/keeper" "github.com/osmosis-labs/osmosis/v7/x/lockup/types" + "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -314,16 +315,16 @@ func (suite *KeeperTestSuite) TestMsgEditLockup() { for _, test := range tests { suite.SetupTest() - err := simapp.FundAccount(suite.app.BankKeeper, suite.ctx, test.param.lockOwner, test.param.coinsToLock) + err := simapp.FundAccount(suite.App.BankKeeper, suite.Ctx, test.param.lockOwner, test.param.coinsToLock) suite.Require().NoError(err) - msgServer := keeper.NewMsgServerImpl(suite.app.LockupKeeper) - c := sdk.WrapSDKContext(suite.ctx) + msgServer := keeper.NewMsgServerImpl(suite.App.LockupKeeper) + c := sdk.WrapSDKContext(suite.Ctx) resp, err := msgServer.LockTokens(c, types.NewMsgLockTokens(test.param.lockOwner, test.param.duration, test.param.coinsToLock)) suite.Require().NoError(err) if test.param.isSyntheticLockup { - err = suite.app.LockupKeeper.CreateSyntheticLockup(suite.ctx, resp.ID, "synthetic", time.Second, false) + err = suite.App.LockupKeeper.CreateSyntheticLockup(suite.Ctx, resp.ID, "synthetic", time.Second, false) suite.Require().NoError(err) } From 78c555c82aeda744f793aa8ee9e06245ca4c87a2 Mon Sep 17 00:00:00 2001 From: mconcat Date: Tue, 3 May 2022 00:07:54 +0900 Subject: [PATCH 15/17] Apply suggestions from code review Co-authored-by: Matt, Park <45252226+mattverse@users.noreply.github.com> --- x/lockup/keeper/lock_test.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/x/lockup/keeper/lock_test.go b/x/lockup/keeper/lock_test.go index 204bbe8c27d..86c79c112f5 100644 --- a/x/lockup/keeper/lock_test.go +++ b/x/lockup/keeper/lock_test.go @@ -668,7 +668,10 @@ func (suite *KeeperTestSuite) TestEditLockup() { // duration decrease should fail err = suite.App.LockupKeeper.ExtendLockup(suite.Ctx, *lock, time.Second/2) suite.Require().Error(err) - + // extending lock with same duration should fail + err = suite.App.LockupKeeper.ExtendLockup(suite.Ctx, *lock, time.Second) + suite.Require().Error(err) + // duration increase should success err = suite.App.LockupKeeper.ExtendLockup(suite.Ctx, *lock, time.Second*2) suite.Require().NoError(err) @@ -676,7 +679,9 @@ func (suite *KeeperTestSuite) TestEditLockup() { // check queries lock, _ = suite.App.LockupKeeper.GetLockByID(suite.Ctx, lock.ID) suite.Require().Equal(lock.Duration, time.Second*2) - + suite.Require().Equal(1, lock.ID) + suite.Require().Equal(coins, lock.Coins) + locks = suite.App.LockupKeeper.GetLocksLongerThanDurationDenom(suite.Ctx, "stake", time.Second) suite.Require().Equal(len(locks), 1) From 0ebe1ef2c9068de0a3d57f997bae0aa2c020493b Mon Sep 17 00:00:00 2001 From: mconcat Date: Tue, 3 May 2022 00:21:36 +0900 Subject: [PATCH 16/17] add hook call in extendlock --- x/lockup/keeper/lock.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/x/lockup/keeper/lock.go b/x/lockup/keeper/lock.go index ed71827979e..717d8dfdba5 100644 --- a/x/lockup/keeper/lock.go +++ b/x/lockup/keeper/lock.go @@ -575,5 +575,13 @@ func (k Keeper) ExtendLockup(ctx sdk.Context, lock types.PeriodLock, newDuration return err } - return k.setLock(ctx, lock) + err = k.setLock(ctx, lock) + if err != nil { + return err + } + + k.hooks.OnTokenUnlocked(ctx, lock.OwnerAddress(), lock.ID, lock.Coins, oldLock.Duration, lock.EndTime) + k.hooks.OnTokenLocked(ctx, lock.OwnerAddress(), lock.ID, lock.Coins, lock.Duration, lock.EndTime) + + return nil } From dba0383209de198041df5dd7699b19951b927bfc Mon Sep 17 00:00:00 2001 From: mconcat Date: Tue, 3 May 2022 00:24:49 +0900 Subject: [PATCH 17/17] fix test --- x/lockup/keeper/lock.go | 2 +- x/lockup/keeper/lock_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/x/lockup/keeper/lock.go b/x/lockup/keeper/lock.go index 717d8dfdba5..0d031e28427 100644 --- a/x/lockup/keeper/lock.go +++ b/x/lockup/keeper/lock.go @@ -551,7 +551,7 @@ func (k Keeper) ExtendLockup(ctx sdk.Context, lock types.PeriodLock, newDuration oldLock := lock if newDuration != 0 { - if newDuration < lock.Duration { + if newDuration <= lock.Duration { return fmt.Errorf("new duration should be greater than the original") } diff --git a/x/lockup/keeper/lock_test.go b/x/lockup/keeper/lock_test.go index 86c79c112f5..621571317e5 100644 --- a/x/lockup/keeper/lock_test.go +++ b/x/lockup/keeper/lock_test.go @@ -671,7 +671,7 @@ func (suite *KeeperTestSuite) TestEditLockup() { // extending lock with same duration should fail err = suite.App.LockupKeeper.ExtendLockup(suite.Ctx, *lock, time.Second) suite.Require().Error(err) - + // duration increase should success err = suite.App.LockupKeeper.ExtendLockup(suite.Ctx, *lock, time.Second*2) suite.Require().NoError(err) @@ -679,9 +679,9 @@ func (suite *KeeperTestSuite) TestEditLockup() { // check queries lock, _ = suite.App.LockupKeeper.GetLockByID(suite.Ctx, lock.ID) suite.Require().Equal(lock.Duration, time.Second*2) - suite.Require().Equal(1, lock.ID) + suite.Require().Equal(uint64(1), lock.ID) suite.Require().Equal(coins, lock.Coins) - + locks = suite.App.LockupKeeper.GetLocksLongerThanDurationDenom(suite.Ctx, "stake", time.Second) suite.Require().Equal(len(locks), 1)