-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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(gov)!: use collections for deposit state management #16127
Merged
Merged
Changes from 14 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
dddd529
move constitution to collections
3d8306b
move params to collections
e559d41
chore: CHANGELOG.md
41d8e73
address PR reviews
6bb70e6
be consistent
c503920
more test fixes
9bf4d8c
Merge branch 'main' into tip/gov/coll-params-constitution
testinginprod 0cd34ed
use assert and not require
8fc50d7
Merge remote-tracking branch 'origin/tip/gov/coll-params-constitution…
915618b
fix prefixes numbers
d291e99
move deposit to collections1
6932323
move another part of deposits to use collections
0792749
Merge branch 'main' into tip/gov/coll-deposit
a9cc7ba
add panic in genesis
f29f12e
remove unused func
4e53600
more cleanups + format
99066f3
remove improt
b23e38d
change the collections API to error on walking
6af4aa9
chore: CHANGELOG.md
5191de7
lint bank
4f9bea7
remove unused error
3ee570e
remove unused errors
64bf12f
fix some minor thing
39c3c4a
Merge branch 'main' into tip/gov/coll-deposit
testinginprod a4fe45c
more minor things
66b7866
remove another method yet again
730116e
fmt
3a04628
Merge branch 'main' into tip/gov/coll-deposit
testinginprod 44906b0
chore: changelog
abbe962
Merge remote-tracking branch 'origin/tip/gov/coll-deposit' into tip/g…
a69ed21
supress lint
9aa0be4
fix lint maybe
21efcb5
fix lint 2
c295c8f
Merge branch 'main' into tip/gov/coll-deposit
testinginprod 7f8b066
go mod tidy all
667c4e3
Merge remote-tracking branch 'origin/tip/gov/coll-deposit' into tip/g…
2830f8a
Merge branch 'main' into tip/gov/coll-deposit
testinginprod 72dd01b
remove dependency on another error pkg
d400342
Merge remote-tracking branch 'origin/tip/gov/coll-deposit' into tip/g…
98195ea
tidy again
f5eb34c
try fix confix
b60262f
Merge branch 'main' into tip/gov/coll-deposit
testinginprod File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package keeper | |
|
||
import ( | ||
"context" | ||
"cosmossdk.io/collections" | ||
|
||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
|
@@ -91,9 +92,9 @@ func (q queryServer) Proposals(ctx context.Context, req *v1.QueryProposalsReques | |
if err != nil { | ||
return nil, err | ||
} | ||
_, err = q.k.GetDeposit(ctx, p.Id, depositor) | ||
has, err := q.k.Deposits.Has(ctx, collections.Join(p.Id, sdk.AccAddress(depositor))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. behavioural change, perf improvement: uses Has instead of Get in order to avoid getting the value from store and decoding it |
||
// if no error, deposit found, matchDepositor = true | ||
matchDepositor = err == nil | ||
matchDepositor = err == nil && has | ||
} | ||
|
||
if matchVoter && matchDepositor && matchStatus { | ||
|
@@ -225,7 +226,7 @@ func (q queryServer) Deposit(ctx context.Context, req *v1.QueryDepositRequest) ( | |
if err != nil { | ||
return nil, err | ||
} | ||
deposit, err := q.k.GetDeposit(ctx, req.ProposalId, depositor) | ||
deposit, err := q.k.Deposits.Get(ctx, collections.Join(req.ProposalId, sdk.AccAddress(depositor))) | ||
if err != nil { | ||
if errors.IsOf(err, types.ErrDepositNotFound) { | ||
return nil, status.Errorf(codes.InvalidArgument, | ||
|
@@ -248,19 +249,10 @@ func (q queryServer) Deposits(ctx context.Context, req *v1.QueryDepositsRequest) | |
} | ||
|
||
var deposits []*v1.Deposit | ||
|
||
store := q.k.storeService.OpenKVStore(ctx) | ||
depositStore := prefix.NewStore(runtime.KVStoreAdapter(store), types.DepositsKey(req.ProposalId)) | ||
|
||
pageRes, err := query.Paginate(depositStore, req.Pagination, func(key, value []byte) error { | ||
var deposit v1.Deposit | ||
if err := q.k.cdc.Unmarshal(value, &deposit); err != nil { | ||
return err | ||
} | ||
|
||
_, pageRes, err := query.CollectionFilteredPaginate(ctx, q.k.Deposits, req.Pagination, func(_ collections.Pair[uint64, sdk.AccAddress], deposit v1.Deposit) (bool, error) { | ||
deposits = append(deposits, &deposit) | ||
return nil | ||
}) | ||
return false, nil // we don't include results as they're being appended to the slice above. | ||
}, query.WithCollectionPaginationPairPrefix[uint64, sdk.AccAddress](req.ProposalId)) | ||
if err != nil { | ||
return nil, status.Error(codes.Internal, err.Error()) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a behavioural change, for which we compute the total amount of coins to burn and then we burn them all in a single batch