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

go/common/keyformat: Ensure consensus and runtime prefixes are unique #5548

Merged
merged 2 commits into from
Feb 5, 2024

Conversation

peternose
Copy link
Contributor

No description provided.

Copy link
Member

@kostko kostko left a 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).

@peternose
Copy link
Contributor Author

history db keys and runtime transaction tree don't need to have unique prefixes

Wasn't sure about that and wanted to simplify. Will add namespaces.

@peternose peternose force-pushed the peternose/feature/keyformat-uniqueness branch from f572357 to 2a272aa Compare January 31, 2024 12:32
Copy link

codecov bot commented Jan 31, 2024

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (bfff729) 66.26% compared to head (191d346) 66.91%.
Report is 1 commits behind head on master.

Files Patch % Lines
go/common/grpc/service.go 0.00% 0 Missing and 1 partial ⚠️
go/consensus/api/transaction/transaction.go 0.00% 0 Missing and 1 partial ⚠️
go/upgrade/migrations/migrations.go 0.00% 0 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

@peternose peternose marked this pull request as ready for review January 31, 2024 13:44
@peternose peternose requested a review from kostko February 1, 2024 10:38
@@ -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{})
Copy link
Member

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.

Copy link
Contributor Author

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).

@peternose peternose force-pushed the peternose/feature/keyformat-uniqueness branch 5 times, most recently from 824c64f to 3d03828 Compare February 5, 2024 11:17
Copy link
Member

@kostko kostko left a 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.

go/storage/mkvs/db/badger/badger.go Outdated Show resolved Hide resolved
go/consensus/api/api.go Outdated Show resolved Hide resolved
@peternose peternose force-pushed the peternose/feature/keyformat-uniqueness branch from 3d03828 to 191d346 Compare February 5, 2024 12:50
@peternose peternose merged commit cd75e3b into master Feb 5, 2024
6 checks passed
@peternose peternose deleted the peternose/feature/keyformat-uniqueness branch February 5, 2024 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants