-
Notifications
You must be signed in to change notification settings - Fork 14
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): migrate gov module to v8 #735
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package v8 | ||
|
||
import ( | ||
storetypes "cosmossdk.io/store/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
var ( | ||
// Deprecated: do not use, remove in v8 | ||
FxBaseParamsKeyPrefix = []byte("0x90") | ||
// Deprecated: do not use, remove in v8 | ||
FxEGFParamsKey = []byte("0x91") | ||
) | ||
Comment on lines
+8
to
+13
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. 🛠️ Refactor suggestion Refactor deprecated key declarations and clarify deprecation timeline.
Here's a suggested refactoring: const (
// FxBaseParamsKeyPrefix is the deprecated key prefix for base parameters.
// It will be removed in the next major version.
// The value 0x90 represents [explain significance].
FxBaseParamsKeyPrefix = []byte{0x90}
// FxEGFParamsKey is the deprecated key for EGF parameters.
// It will be removed in the next major version.
// The value 0x91 represents [explain significance].
FxEGFParamsKey = []byte{0x91}
) |
||
|
||
func GetRemovedStoreKeys() [][]byte { | ||
return [][]byte{FxBaseParamsKeyPrefix, FxEGFParamsKey} | ||
} | ||
|
||
func DeleteOldParamsStore( | ||
ctx sdk.Context, | ||
storeKey storetypes.StoreKey, | ||
) { | ||
store := ctx.KVStore(storeKey) | ||
removeKeys := GetRemovedStoreKeys() | ||
for _, key := range removeKeys { | ||
iterator := storetypes.KVStorePrefixIterator(store, key) | ||
for ; iterator.Valid(); iterator.Next() { | ||
store.Delete(iterator.Key()) | ||
} | ||
} | ||
} | ||
Comment on lines
+19
to
+31
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. Close iterator and consider minor optimization in DeleteOldParamsStore. The function correctly deletes deprecated entries, but there are two points to address:
Here's a suggested refactoring: func DeleteOldParamsStore(
ctx sdk.Context,
storeKey storetypes.StoreKey,
) {
removeKeys := GetRemovedStoreKeys()
for _, key := range removeKeys {
store := ctx.KVStore(storeKey)
iterator := storetypes.KVStorePrefixIterator(store, key)
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
store.Delete(iterator.Key())
}
}
} This change ensures that the iterator is properly closed and slightly optimizes the function by moving the store retrieval inside the loop, ensuring we always work with the most up-to-date store state. |
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.
Handle Potential Errors from
DeleteOldParamsStore
FunctionThe
fxgovv8.DeleteOldParamsStore(ctx, storeKey)
function might return an error that is currently not being handled. To enhance robustness, consider checking and handling any potential errors from this function.Apply this diff to handle the error:
📝 Committable suggestion