Skip to content
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

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion mod/node-core/pkg/components/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

//nolint:gochecknoglobals // storeKey is a singleton.
var storeKey = storetypes.NewKVStoreKey("beacon")
Comment on lines +31 to +32
Copy link
Contributor

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.

Suggested change
//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")


func ProvideKVStoreKey() **storetypes.KVStoreKey {
storeKey := storetypes.NewKVStoreKey("beacon")
return &storeKey
}

Expand Down
Loading