-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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(mint)!: migrate state management to collections #16329
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
44e510d
decouple keeper from query server
cb7b7ab
start migrating params
f8ccb03
remove GetParams
374952a
remove SetParams
18dbf63
start migrating minter
f548ef7
remove GetMinter
fb1887c
remove SetMinter
0b3d4b8
replace simulation store decoder with collections
0e5c431
error
f5812e5
Merge branch 'main' into tip/mint/collections
testinginprod 78b735c
chore: CHANGELOG.md
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
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"context" | ||
"fmt" | ||
|
||
"cosmossdk.io/collections" | ||
"cosmossdk.io/log" | ||
"cosmossdk.io/math" | ||
|
||
|
@@ -25,6 +26,10 @@ type Keeper struct { | |
// the address capable of executing a MsgUpdateParams message. Typically, this | ||
// should be the x/gov module account. | ||
authority string | ||
|
||
Schema collections.Schema | ||
Params collections.Item[types.Params] | ||
Minter collections.Item[types.Minter] | ||
} | ||
|
||
// NewKeeper creates a new mint Keeper instance | ||
|
@@ -42,14 +47,24 @@ func NewKeeper( | |
panic(fmt.Sprintf("the x/%s module account has not been set", types.ModuleName)) | ||
} | ||
|
||
return Keeper{ | ||
sb := collections.NewSchemaBuilder(storeService) | ||
k := Keeper{ | ||
cdc: cdc, | ||
storeService: storeService, | ||
stakingKeeper: sk, | ||
bankKeeper: bk, | ||
feeCollectorName: feeCollectorName, | ||
authority: authority, | ||
Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)), | ||
Minter: collections.NewItem(sb, types.MinterKey, "minter", codec.CollValue[types.Minter](cdc)), | ||
} | ||
|
||
schema, err := sb.Build() | ||
if err != nil { | ||
panic(err) | ||
} | ||
k.Schema = schema | ||
return k | ||
} | ||
|
||
// GetAuthority returns the x/mint module's authority. | ||
|
@@ -63,59 +78,6 @@ func (k Keeper) Logger(ctx context.Context) log.Logger { | |
return sdkCtx.Logger().With("module", "x/"+types.ModuleName) | ||
} | ||
|
||
// GetMinter returns the minter. | ||
func (k Keeper) GetMinter(ctx context.Context) (types.Minter, error) { | ||
testinginprod marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var minter types.Minter | ||
store := k.storeService.OpenKVStore(ctx) | ||
bz, err := store.Get(types.MinterKey) | ||
if err != nil { | ||
return minter, err | ||
} | ||
|
||
if bz == nil { | ||
return minter, fmt.Errorf("stored minter should not have been nil") | ||
} | ||
|
||
err = k.cdc.Unmarshal(bz, &minter) | ||
return minter, err | ||
} | ||
|
||
// SetMinter sets the minter. | ||
func (k Keeper) SetMinter(ctx context.Context, minter types.Minter) error { | ||
store := k.storeService.OpenKVStore(ctx) | ||
bz, err := k.cdc.Marshal(&minter) | ||
if err != nil { | ||
return err | ||
} | ||
return store.Set(types.MinterKey, bz) | ||
} | ||
|
||
// SetParams sets the x/mint module parameters. | ||
func (k Keeper) SetParams(ctx context.Context, params types.Params) error { | ||
store := k.storeService.OpenKVStore(ctx) | ||
bz, err := k.cdc.Marshal(¶ms) | ||
if err != nil { | ||
return err | ||
} | ||
return store.Set(types.ParamsKey, bz) | ||
} | ||
|
||
// GetParams returns the current x/mint module parameters. | ||
func (k Keeper) GetParams(ctx context.Context) (p types.Params, err error) { | ||
store := k.storeService.OpenKVStore(ctx) | ||
bz, err := store.Get(types.ParamsKey) | ||
if err != nil { | ||
return p, err | ||
} | ||
|
||
if bz == nil { | ||
return p, nil | ||
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. returning empty params should be an error, because of invalid decs, I think that the fact it did not create issues was by "luck". Right now the behavioural change is that we'll error if params are missing. |
||
} | ||
|
||
err = k.cdc.Unmarshal(bz, &p) | ||
return p, err | ||
} | ||
|
||
// StakingTokenSupply implements an alias call to the underlying staking keeper's | ||
// StakingTokenSupply to be used in BeginBlocker. | ||
func (k Keeper) StakingTokenSupply(ctx context.Context) math.Int { | ||
|
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
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.
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods