-
Notifications
You must be signed in to change notification settings - Fork 107
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
go/common/keyformat: Ensure consensus and runtime prefixes are unique #5548
Conversation
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.
Could you maybe change this so that you can basically specify a namespace where it needs to be unique? Consensus looks fine, but runtime as it is currently doesn't make sense (e.g. history db keys and runtime transaction tree don't need to have unique prefixes -- those only need to be unique within that IO tree).
Wasn't sure about that and wanted to simplify. Will add namespaces. |
f572357
to
2a272aa
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #5548 +/- ##
==========================================
+ Coverage 66.26% 66.91% +0.64%
==========================================
Files 539 539
Lines 56877 56883 +6
==========================================
+ Hits 37691 38064 +373
+ Misses 14760 14379 -381
- Partials 4426 4440 +14 ☔ View full report in Codecov by Sentry. |
go/storage/mkvs/db/badger/badger.go
Outdated
@@ -32,37 +32,37 @@ var ( | |||
// nodeKeyFmt is the key format for nodes (node hash). | |||
// | |||
// Value is serialized node. | |||
nodeKeyFmt = keyformat.New(0x00, &hash.Hash{}) | |||
nodeKeyFmt = keyformat.Consensus(0x00, &hash.Hash{}) |
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.
This should not be consensus, this is another database for storing runtime and consensus state (both use the same but these keys here are internal). I don't think we should hardcode "runtime history" and all the database backend namespaces in the key format package though?
Could we have a notion of namespaces that are specified externally? E.g. something like:
// Somewhere we would define the namespace.
var Consensus = keyformat.NewNamespace()
// Then we can uset the namespace to create new key formats.
var fooFmt = Consensus.New(0x00, ...)
This (or similar) would make it more flexible to use in external packages without the need to change the keyformat
package.
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.
You are right. I reverted some changes and added namespace constructor (with a namespace name to have clearer panic message). Now there are 4 namespaces: consensus, runtime db, runtime tx, and badger. Key formats defined in tests and in migration don't belong to any namespace (duplicates are allowed).
824c64f
to
3d03828
Compare
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.
Looks good now, just two minor comment fixes.
3d03828
to
191d346
Compare
No description provided.