Closed zakir-code closed 1 week ago
This pull request introduces several modifications across multiple files to enhance logging, refine context management, and streamline migration processes. Key changes include the integration of a logging package, updates to context creation logic, the introduction of a new key removal function, and the removal of deprecated functions and variables in migration files.
File Path | Change Summary |
---|---|
app/upgrade_test.go | Added logging package import and initialized logger in buildApp . Updated context creation logic in newContext . Refactored checkKeysIsDelete function for key deletion verification. |
app/upgrades/v8/upgrade.go | Introduced removeStoreKeys function for deleting keys from a key-value store. Modified CreateUpgradeHandler to use this function. |
x/gov/migrations/v8/migrate.go | Removed DeleteOldParamsStore function and marked constants as deprecated. |
x/staking/migrations/v8/migrate.go | Removed deprecated variables (ValidatorOperatorKey , ConsensusPubKey , ConsensusProcessKey ) and the DeleteMigrationValidatorStore function. |
checkStakingMigrationDelete
function to utilize the checkKeysIsDelete
function, which is directly related to the main PR's refactor of the checkKeysIsDelete
function for key deletion verification.In the code where rabbits hop,
We clean the paths, we never stop.
With logs that shine and keys that flee,
Migrations dance, so wild and free!
Old things gone, new ways to play,
Hooray for changes, hip-hip-hooray! 🐇✨
app/upgrades/v8/upgrade.go (4)
`30-30`: **LGTM: Unified key removal implemented** The change successfully implements the unified method for deleting store keys as per the PR objective. The `removeStoreKeys` function is correctly used with appropriate arguments. --- `44-44`: **LGTM: Consistent use of unified key removal** The change in `migrationGovCustomParam` is consistent with the PR objective and the previous change in `CreateUpgradeHandler`. The `removeStoreKeys` function is correctly used with appropriate arguments. --- `5-5`: **LGTM: Necessary import added** The addition of the "encoding/hex" import is correct and necessary for its usage in the new `removeStoreKeys` function for logging purposes. --- `50-66`: _:warning: Potential issue_ **Potential resource leak in `removeStoreKeys` function** The implementation of the unified method for deleting store keys is good, but there's a potential issue with resource management: 1. The `defer iterator.Close()` is inside the `deleteFn` closure, which is called in a loop. This could lead to multiple open iterators if there are many keys to process, potentially causing resource exhaustion. 2. This issue was previously flagged in a review comment, but it hasn't been addressed in this version. To fix this, consider moving the `iterator.Close()` call to the end of the `for` loop in `deleteFn`, ensuring each iterator is closed after use. Here's a suggested fix: ```diff func removeStoreKeys(ctx sdk.Context, storeKey *storetypes.KVStoreKey, keys [][]byte) { store := ctx.KVStore(storeKey) deleteFn := func(key []byte) { iterator := storetypes.KVStorePrefixIterator(store, key) - defer iterator.Close() for ; iterator.Valid(); iterator.Next() { store.Delete(iterator.Key()) ctx.Logger().Info("remove store key", "kvStore", storeKey.Name(), "prefix", hex.EncodeToString(key), "key", string(iterator.Key())) } + iterator.Close() } for _, key := range keys { deleteFn(key) } } ```
Summary by CodeRabbit
New Features
Bug Fixes
Refactor