-
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
Conversation
…' into tip/gov/coll-params-constitution
# Conflicts: # x/gov/keeper/keeper.go
return nil | ||
coinsToBurn := sdk.NewCoins() | ||
err := keeper.IterateDeposits(ctx, proposalID, func(key collections.Pair[uint64, sdk.AccAddress], deposit v1.Deposit) bool { | ||
coinsToBurn = coinsToBurn.Add(deposit.Amount...) |
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
@@ -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 comment
The 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
@@ -353,7 +353,7 @@ func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.Weight | |||
|
|||
// RegisterStoreDecoder registers a decoder for gov module's types | |||
func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) { | |||
sdr[govtypes.StoreKey] = simulation.NewDecodeStore(am.cdc) | |||
sdr[govtypes.StoreKey] = simtypes.NewStoreDecoderFuncFromCollectionsSchema(am.keeper.Schema) |
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 does not support all gov states object currently because we haven't migrated all states objects to use collections
@@ -127,7 +127,7 @@ func (m Map[K, V]) Iterate(ctx context.Context, ranger Ranger[K]) (Iterator[K, V | |||
// walk function with the decoded key and value. If the callback function | |||
// returns true then the walking is stopped. | |||
// A nil ranger equals to walking over the entire key and value set. | |||
func (m Map[K, V]) Walk(ctx context.Context, ranger Ranger[K], walkFunc func(K, V) bool) error { | |||
func (m Map[K, V]) Walk(ctx context.Context, ranger Ranger[K], walkFunc func(key K, value V) (stop bool, err error)) error { |
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.
added the possibility to make walkFunc error, this plays well with gov and generally is better to allow for a straightforward way to error during iterations and propagate errors back.
@@ -256,9 +258,12 @@ func (k BaseKeeper) GetAllDenomMetaData(ctx context.Context) []types.Metadata { | |||
// provides the metadata to a callback. If true is returned from the | |||
// callback, iteration is halted. | |||
func (k BaseKeeper) IterateAllDenomMetaData(ctx context.Context, cb func(types.Metadata) bool) { | |||
_ = k.BaseViewKeeper.DenomMetadata.Walk(ctx, nil, func(_ string, metadata types.Metadata) bool { | |||
return cb(metadata) | |||
err := k.BaseViewKeeper.DenomMetadata.Walk(ctx, nil, func(_ string, metadata types.Metadata) (stop bool, err error) { |
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.
adjusts to match the collections API breaking change.
@@ -474,7 +479,10 @@ func (k BaseKeeper) trackUndelegation(ctx context.Context, addr sdk.AccAddress, | |||
// with the balance of each coin. | |||
// The iteration stops if the callback returns true. | |||
func (k BaseViewKeeper) IterateTotalSupply(ctx context.Context, cb func(sdk.Coin) bool) { | |||
_ = k.Supply.Walk(ctx, nil, func(s string, m math.Int) bool { | |||
return cb(sdk.NewCoin(s, m)) | |||
err := k.Supply.Walk(ctx, nil, func(s string, m math.Int) (bool, error) { |
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.
adjusts to match the collections API breaking change.
@@ -376,7 +377,12 @@ func (k BaseSendKeeper) DeleteSendEnabled(ctx context.Context, denoms ...string) | |||
|
|||
// IterateSendEnabledEntries iterates over all the SendEnabled entries. | |||
func (k BaseSendKeeper) IterateSendEnabledEntries(ctx context.Context, cb func(denom string, sendEnabled bool) bool) { |
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.
adjusts to match the collections API breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should add a couple changelog entries for the public functions that were removed
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.
lgtm!
Description
Closes: #16126
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change