-
Notifications
You must be signed in to change notification settings - Fork 30
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
Key-value DB using gob
for encoding/decoding
#88
base: master
Are you sure you want to change the base?
Conversation
84fc324
to
0203249
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.
Looking good. I added a few questions. Hope to do a more detailed review before our hangouts session later.
storage/kv/merkletreekv/storage.go
Outdated
STRIdentifier = 'S' | ||
PoliciesIdentifier = 'P' | ||
EpochIdentifier = 'O' | ||
TreeNonceIdentifier = 'T' |
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.
Arent' those constants the same as in https://github.com/coniks-sys/coniks-go/blob/84fc324bc27fee50c0619a9538c0d91421b804d1/merkletree/storage.go ?
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.
Oh, this is a old commit that has been deleted.
Key string | ||
Value []byte | ||
Index []byte | ||
Commitment *crypto.Commit |
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.
I guess all this values need to public to correctly encode now?
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.
Yes, since we didn't export the structs so I think it still ensures our preservation, i.e., there's no way to change or read the node's fields.
Btw, the reason is (mostly) because I didn't want to implement the GobEncode/GobDecode interface manually.
ecf430d
to
28a53ac
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.
Some suggestions/questions.
merkletree/policy.go
Outdated
@@ -30,8 +33,6 @@ func NewPolicies(epDeadline TimeStamp, vrfPrivKey vrf.PrivateKey) *Policies { | |||
} | |||
} | |||
|
|||
// Serialize encodes the policy to a byte array with the following format: | |||
// [lib version, cryptographic algorithm in use, epoch deadline, vrf public key] |
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.
Why is the comment not relevant anymore?
merkletree/merkletree.go
Outdated
EmptyBranchIdentifier = 'E' | ||
LeafIdentifier = 'L' | ||
EmptyNodeKey = 'E' | ||
LeafNodeKey = 'L' |
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.
Nitpicking: We would need this naming to be consistent. I liked the identifier (we already have so many different "keys" ;-) Here, we still stick with identifier: https://github.com/coniks-sys/coniks-go/pull/88/files#diff-7e689735c327b0bd737cd6e956e20b4aR4
Anyways, choose what you prefer. I just think it should be consistent.
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.
Oops, it must be my mistake. I have no intention to change this! Thanks!
storage/kv/merkletreekv/strkv.go
Outdated
return merkletree.DecodeSTR(buff) | ||
} | ||
|
||
func STRKey(epoch uint64) []byte { |
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 could be unexported or not? If this should stay exported it would need a more speaking name.
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.
Do you have any suggestion for this? :D
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.
If it is unexported the name is OK.
storage/kv/merkletreekv/strkv.go
Outdated
"github.com/coniks-sys/coniks-go/utils" | ||
) | ||
|
||
func StoreSTR(wb kv.Batch, str *merkletree.SignedTreeRoot) error { |
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 and LoadSTR
currently aren't used. I guess this will change?
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.
They would be used to load the old STRs which were deleted from the pad.snapshot
.
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.
Cool, thanks. Can we have a test for that?
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.
Yup!
From my point of view this PR looks very good (just a few questions and nitpicks). |
Thanks! |
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.
The encoding, decoding and reconstruction functions aren't part of the core data structure, they are only relevant to the DB, and they are ultimately only used in EncodePAD
, which is really only used by StorePAD
in padkv.go. As such, all gob encoding and decoding functions related to the DB should be part of the storage/kv/merkletreekv
package, not the core merkletree
package.
I agree that the encoding format is an implementation detail we should hide from the developer, but I don't see the reason why these functions need to be part of the core data structure if they are used only for a separate feature (the DB) of coniks-go.
PTAL. I need to use this in extensions implementation ;) |
74739cb
to
91590e5
Compare
- Export fields of nodes struct for gob encoding - Add gob encoding/decoding for PAD, STR, MerkleTree, Policies (use internally)
I have made an improvement in commit 84fc324bc27fee50c0619a9538c0d91421b804d1. This implementation's performance is better than #37 now.
Update (description below)
This pull uses
encoding/gob
to encode/decode the merkletree structs to/from a buffer, and it implements the db backend hook for the merkletree package.The package
merkletree
is now exporting some functions for encoding/decoding the PAD, STR, Merkletree and Policies from a buffer (any types that implement theio.Writer
andio.Reader
interface). This way, I think we can hide the detail implementations of the encoding/decoding from the developers.Move to the hook implementation, there are two cases when we want to use a persistent storage:
This hook exports APIs for store/load the PAD, STR to/from the db.