-
Notifications
You must be signed in to change notification settings - Fork 122
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
Made StoreKey singleton #2018
Made StoreKey singleton #2018
Conversation
WalkthroughThe changes involve the declaration of the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Files selected for processing (1)
- mod/node-core/pkg/components/depinject.go (1 hunks)
Additional comments not posted (2)
mod/node-core/pkg/components/depinject.go (2)
Line range hint
1-124
: Overall, the changes look good and address the PR objectives.The implementation of the singleton pattern for
StoreKey
should effectively resolve the issues mentioned in the PR objectives. The changes are minimal and focused, which reduces the risk of introducing new problems.A few points to consider for future improvements:
- Document the rationale behind the singleton pattern in a comment, as suggested earlier.
- Consider adding unit tests to verify the singleton behavior of
StoreKey
.- If not already done, update any documentation that might reference the old
StoreKey
implementation.
34-36
: LGTM! Verify usage across the codebase.The modification to
ProvideKVStoreKey
function effectively implements the singleton pattern forStoreKey
. This change addresses the issue mentioned in the PR objectives where multiple calls to this function were causing problems.To ensure this change doesn't introduce any unexpected behavior, let's verify the usage of
ProvideKVStoreKey
across the codebase:This script will help us ensure that:
- All usages of
ProvideKVStoreKey
are still valid with the new implementation.- There are no remaining direct instantiations of
storetypes.NewKVStoreKey
that should be replaced withProvideKVStoreKey
.Verification successful
Verified! All usages of
ProvideKVStoreKey
are correctly updated, and there are no direct instantiations ofstoretypes.NewKVStoreKey
remaining in the active codebase.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check usage of ProvideKVStoreKey across the codebase # Search for function calls to ProvideKVStoreKey echo "Searching for ProvideKVStoreKey usage:" rg --type go "ProvideKVStoreKey\(\)" -C 3 # Search for any direct usage of storetypes.NewKVStoreKey echo "\nChecking for any remaining direct usage of storetypes.NewKVStoreKey:" rg --type go "storetypes\.NewKVStoreKey\(" -C 3Length of output: 1792
//nolint:gochecknoglobals // storeKey is a singleton. | ||
var storeKey = storetypes.NewKVStoreKey("beacon") |
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! Consider adding a brief comment explaining the singleton pattern.
The introduction of a global storeKey
variable aligns well with the PR objective of making StoreKey
a singleton. This change should effectively prevent issues arising from multiple instantiations of the key.
Consider adding a brief comment explaining why the singleton pattern is used here. This can help future maintainers understand the rationale behind this design decision. For example:
//nolint:gochecknoglobals // storeKey is a singleton.
+// Using a singleton pattern ensures that only one instance of the StoreKey is used
+// throughout the application, preventing issues with multiple instantiations.
var storeKey = storetypes.NewKVStoreKey("beacon")
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
//nolint:gochecknoglobals // storeKey is a singleton. | |
var storeKey = storetypes.NewKVStoreKey("beacon") | |
//nolint:gochecknoglobals // storeKey is a singleton. | |
// Using a singleton pattern ensures that only one instance of the StoreKey is used | |
// throughout the application, preventing issues with multiple instantiations. | |
var storeKey = storetypes.NewKVStoreKey("beacon") |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2018 +/- ##
=======================================
Coverage 22.37% 22.37%
=======================================
Files 358 358
Lines 16066 16065 -1
Branches 13 13
=======================================
Hits 3594 3594
+ Misses 12323 12322 -1
Partials 149 149
|
StoreKey
is used as index in cosmos sdk DB code. Notably the whole struct is used as index, not its content; this means that if we callProvideKVStoreKey
twice (thus currently re-instantiating a key with the same content), the lookup by storeKey fails and its store may not be found, even if the store key content is the very same.This is hardly an issue in beaconKit but it costed me some debugging time while trying wiring miniAvalanche in.
The change I propose here makes the storeKey a singleton and guards against nasty issue which would happen if
ProveideKVStore
is called multiple times.Summary by CodeRabbit
Bug Fixes
storeKey
variable to ensure consistent access throughout the application.Refactor
storeKey
with a global instance, enhancing efficiency.