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

refactor(x/accounts/defaults/lockup): Clean up some logic #20037

Merged
merged 33 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e24324d
use branch service
sontrinh16 Apr 11, 2024
d58b858
add withdraw reward
sontrinh16 Apr 11, 2024
e45a0d9
clean up
sontrinh16 Apr 14, 2024
bf22eff
seperate withdraw reward to another PR
sontrinh16 Apr 14, 2024
375b789
minor
sontrinh16 Apr 14, 2024
fd69fd3
minor
sontrinh16 Apr 14, 2024
4fe5ffd
minor
sontrinh16 Apr 14, 2024
0ad7f95
Merge branch 'main' into son/lockup_cleanup
sontrinh16 Apr 15, 2024
83eca87
add withdraw reward
sontrinh16 Apr 15, 2024
f49f4d0
Merge branch 'main' into son/lockup_cleanup
sontrinh16 Apr 15, 2024
89abdbf
remove loop
sontrinh16 Apr 18, 2024
f8b28ee
just need to initialize bondenom for del and undel trackin
sontrinh16 Apr 18, 2024
c323ee3
add withdraw reward
sontrinh16 Apr 18, 2024
99f1523
fix conflict
sontrinh16 Apr 18, 2024
51d0457
Merge branch 'main' into son/lockup_cleanup
sontrinh16 Apr 21, 2024
2bae4bc
addressing comment
sontrinh16 Apr 21, 2024
a75b91a
remove branch execute for send coins
sontrinh16 Apr 22, 2024
3e749ca
del free and del locking only track bond denom
sontrinh16 Apr 22, 2024
f85deb7
fix conflict
sontrinh16 Apr 24, 2024
5e5661d
fix test
sontrinh16 Apr 24, 2024
d8787f0
remove branch service
sontrinh16 Apr 24, 2024
e338a26
Merge branch 'main' into son/lockup_cleanup
sontrinh16 Apr 24, 2024
a67166c
add e2e test for withdraw reward
sontrinh16 Apr 24, 2024
d968fc7
add tracking check for del and undel
sontrinh16 Apr 24, 2024
6d26484
Merge branch 'son/lockup_cleanup' of https://github.com/cosmos/cosmos…
sontrinh16 Apr 24, 2024
74f856a
minor
sontrinh16 Apr 25, 2024
0bcfadd
remove print log
sontrinh16 Apr 25, 2024
28eb59a
fix test
sontrinh16 Apr 25, 2024
78a438d
Merge branch 'main' into son/lockup_cleanup
sontrinh16 Apr 28, 2024
ed55f56
Merge branch 'main' into son/lockup_cleanup
sontrinh16 Apr 29, 2024
bfb1e18
minor
sontrinh16 Apr 29, 2024
4a13043
minor
sontrinh16 Apr 29, 2024
b44fb4e
Merge branch 'main' into son/lockup_cleanup
sontrinh16 Apr 29, 2024
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
748 changes: 650 additions & 98 deletions api/cosmos/accounts/defaults/lockup/tx.pulsar.go

Large diffs are not rendered by default.

36 changes: 7 additions & 29 deletions x/accounts/defaults/lockup/continuous_locking_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (cva ContinuousLockingAccount) Init(ctx context.Context, msg *lockuptypes.M
return nil, sdkerrors.ErrInvalidRequest.Wrapf("invalid end time %s", msg.EndTime.String())
}

if msg.EndTime.Before(msg.StartTime) {
if msg.EndTime.Before(msg.StartTime) || msg.EndTime.Equal(msg.StartTime) {
sontrinh16 marked this conversation as resolved.
Show resolved Hide resolved
return nil, sdkerrors.ErrInvalidRequest.Wrap("invalid start and end time (must be start before end)")
}

Expand All @@ -66,12 +66,6 @@ func (cva *ContinuousLockingAccount) Delegate(ctx context.Context, msg *lockupty
return cva.BaseLockup.Delegate(ctx, msg, cva.GetLockedCoinsWithDenoms)
}

func (cva *ContinuousLockingAccount) Undelegate(ctx context.Context, msg *lockuptypes.MsgUndelegate) (
*lockuptypes.MsgExecuteMessagesResponse, error,
) {
return cva.BaseLockup.Undelegate(ctx, msg)
}

sontrinh16 marked this conversation as resolved.
Show resolved Hide resolved
func (cva *ContinuousLockingAccount) SendCoins(ctx context.Context, msg *lockuptypes.MsgSend) (
*lockuptypes.MsgExecuteMessagesResponse, error,
) {
Expand All @@ -89,36 +83,20 @@ func (cva ContinuousLockingAccount) GetLockCoinsInfo(ctx context.Context, blockT
unlockedCoins = sdk.Coins{}
lockedCoins = sdk.Coins{}

// We must handle the case where the start time for a lockup account has
// been set into the future or when the start of the chain is not exactly
// known.
startTime, err := cva.StartTime.Get(ctx)
if err != nil {
return nil, nil, err
}
endTime, err := cva.EndTime.Get(ctx)
if err != nil {
return nil, nil, err
}
var originalVesting sdk.Coins
var originalLocking sdk.Coins
err = cva.IterateCoinEntries(ctx, cva.OriginalLocking, func(key string, value math.Int) (stop bool, err error) {
originalVesting = append(originalVesting, sdk.NewCoin(key, value))
vestedCoin, vestingCoin, err := cva.GetLockCoinInfoWithDenom(ctx, blockTime, key)
originalLocking = append(originalLocking, sdk.NewCoin(key, value))
unlockedCoin, lockedCoin, err := cva.GetLockCoinInfoWithDenom(ctx, blockTime, key)
if err != nil {
return true, err
}
unlockedCoins = append(unlockedCoins, *vestedCoin)
lockedCoins = append(lockedCoins, *vestingCoin)
unlockedCoins = append(unlockedCoins, *unlockedCoin)
lockedCoins = append(lockedCoins, *lockedCoin)
return false, nil
})
if err != nil {
return nil, nil, err
}
if startTime.After(blockTime) {
return unlockedCoins, originalVesting, nil
} else if endTime.Before(blockTime) {
return originalVesting, lockedCoins, nil
}

return unlockedCoins, lockedCoins, nil
}
Expand Down Expand Up @@ -215,9 +193,9 @@ func (cva ContinuousLockingAccount) RegisterInitHandler(builder *accountstd.Init

func (cva ContinuousLockingAccount) RegisterExecuteHandlers(builder *accountstd.ExecuteBuilder) {
accountstd.RegisterExecuteHandler(builder, cva.Delegate)
accountstd.RegisterExecuteHandler(builder, cva.Undelegate)
accountstd.RegisterExecuteHandler(builder, cva.SendCoins)
accountstd.RegisterExecuteHandler(builder, cva.WithdrawUnlockedCoins)
cva.BaseLockup.RegisterExecuteHandlers(builder)
}

func (cva ContinuousLockingAccount) RegisterQueryHandlers(builder *accountstd.QueryBuilder) {
Expand Down
8 changes: 1 addition & 7 deletions x/accounts/defaults/lockup/delayed_locking_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ func (dva *DelayedLockingAccount) Delegate(ctx context.Context, msg *lockuptypes
return dva.BaseLockup.Delegate(ctx, msg, dva.GetLockedCoinsWithDenoms)
}

func (dva *DelayedLockingAccount) Undelegate(ctx context.Context, msg *lockuptypes.MsgUndelegate) (
*lockuptypes.MsgExecuteMessagesResponse, error,
) {
return dva.BaseLockup.Undelegate(ctx, msg)
}

func (dva *DelayedLockingAccount) SendCoins(ctx context.Context, msg *lockuptypes.MsgSend) (
*lockuptypes.MsgExecuteMessagesResponse, error,
) {
Expand Down Expand Up @@ -148,9 +142,9 @@ func (dva DelayedLockingAccount) RegisterInitHandler(builder *accountstd.InitBui

func (dva DelayedLockingAccount) RegisterExecuteHandlers(builder *accountstd.ExecuteBuilder) {
accountstd.RegisterExecuteHandler(builder, dva.Delegate)
accountstd.RegisterExecuteHandler(builder, dva.Undelegate)
accountstd.RegisterExecuteHandler(builder, dva.SendCoins)
accountstd.RegisterExecuteHandler(builder, dva.WithdrawUnlockedCoins)
dva.BaseLockup.RegisterExecuteHandlers(builder)
}

func (dva DelayedLockingAccount) RegisterQueryHandlers(builder *accountstd.QueryBuilder) {
Expand Down
14 changes: 13 additions & 1 deletion x/accounts/defaults/lockup/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,27 @@ require (
github.com/cosmos/gogoproto v1.4.12
)

require cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect

require (

cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/google/orderedcode v0.0.1 // indirect
github.com/lib/pq v1.10.7 // indirect
github.com/minio/highwayhash v1.0.2 // indirect
)

require (
buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.32.0-20240130113600-88ef6483f90f.1 // indirect
buf.build/gen/go/tendermint/tendermint/protocolbuffers/go v1.32.0-20231117195010-33ed361a9051.1 // indirect
cosmossdk.io/api v0.7.4
cosmossdk.io/api v0.7.4 // indirect
cosmossdk.io/errors v1.0.1
cosmossdk.io/log v1.3.1 // indirect
cosmossdk.io/math v1.3.0
cosmossdk.io/store v1.0.2 // indirect
cosmossdk.io/x/auth v0.0.0-00010101000000-000000000000 // indirect
cosmossdk.io/x/distribution v0.0.0-00010101000000-000000000000
cosmossdk.io/x/tx v0.13.2 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
Expand Down
5 changes: 5 additions & 0 deletions x/accounts/defaults/lockup/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/zondax/hid v0.9.2 h1:WCJFnEDMiqGF64nlZz28E9qLVZ0KSJ7xpc5DLEyma2U=
github.com/zondax/hid v0.9.2/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM=
github.com/zondax/ledger-go v0.14.3 h1:wEpJt2CEcBJ428md/5MgSLsXLBos98sBOyxNmCjfUCw=
Expand Down Expand Up @@ -720,6 +721,7 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB
golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -761,6 +763,7 @@ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand All @@ -772,6 +775,7 @@ golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -852,6 +856,7 @@ golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapK
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ=
golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
Loading
Loading