Conversation
|
There're some issues with this db hooks implementation:
I would like to have your advices @masomel @arlolra @liamsi ! |
|
Looking through the ac93761 code, I don't quite understand why the policies need to be passed into But coming back to your second point, could we give the developer the option to store the policy type itself in the DB? Looking at the code, I'm also wondering if all of the |
It's much more clear. Thanks!
Because the
Yes. I already did it in af4ea71051d25191b555d96820b3fe9d964fd219, but it doesn't belong to this branch. Hmm, I guess we should review and merge #35 first.
Yes. I'm just waiting for you to say that. I would like to do it, too. |
Ok, so how the
Ok, I'll go take a look. Agreed, let's get that done first.
Cool! Feel free to just suggest it next time if you would like to make changes like these :) |
# Conflicts: # merkletree/policy.go
25a6925 to
2f704cf
Compare
I've been thinking more about this, and maybe we should move all |
Yup, totally agree. I'm doing it :) |
I spent last few days to work on this. But it seems not to be feasible. If we want to go this way, we have to export fields that we really don't want to do. (e.g., see https://github.com/coniks-sys/coniks-go/blob/cc8b74db472f53a621ac89c05d41ba4121b891a1/merkletree/nodekv.go). What do you think? |
Hmm, this is a good point. At least for |
But |
|
@c633 Is there anything I can help with here to get this moving again? |
|
@masomel I'm working on this. I'm trying to implement it in several ways and do benchmark to compare them. Code will be pushed today. |
|
I saw your email, I didn't realize you were benchmarking the various implementations. I don't want to rush you. But I have some time this week to help with coding, so if there was any task that you haven't gotten to yet and would want help on, I'd be available work on it. |
Thanks! Maybe we can start reviewing this pull. I tried to implement the encoding/decoding using So I think I will stick with this implementation and start re-organizing the source code (I still have no idea how to put |
| - ``client``: Client-side protocol cgo hooks | ||
| - ``crypto``: Cryptographic algorithms and operations | ||
| - ``merkletree``: Merkle prefix tree and related data structures | ||
| - ``storage``: DB hooks for storage backend (currently the library supports key-value db only) |
There was a problem hiding this comment.
Seems like this is duplicate (see L27)
| return m, nil | ||
| } | ||
|
|
||
| func (m *MerkleTree) reconstructTree(db kv.DB, parent MerkleNode, epoch uint64, prefixBits []bool) (MerkleNode, error) { |
There was a problem hiding this comment.
Is there a reason why reconstructTree needs to be a method of MerkleTree? None of m's fields are used in this function.
| } else { | ||
| parent.(*interiorNode).leftChild = n | ||
| } | ||
| switch n.(type) { |
There was a problem hiding this comment.
I think this switch needs a default case to throw an error in case we encounter some malformed data.
|
|
||
| wb := db.NewBatch() | ||
| m1.StoreToKV(1, wb) | ||
| err = db.Write(wb) |
There was a problem hiding this comment.
Is there a reason why db.Write(wb) isn't called from within m.StoreToKV()?
|
|
||
| wb := db.NewBatch() | ||
| m1.StoreToKV(1, wb) | ||
| err = db.Write(wb) |
| } | ||
|
|
||
| ap := m2.Get(index1) | ||
| if ap.Leaf.Value() == nil { |
There was a problem hiding this comment.
Is this the only condition that indicates that key1 cannot be found in the tree? I'm wondering if we should also be checking the leaf node type and the leaf's index here.
There was a problem hiding this comment.
Same goes for L58, L105, and L120.
| } | ||
|
|
||
| func (n *userLeafNode) isEmpty() bool { | ||
| func (n *interiorNode) isEmpty() bool { |
There was a problem hiding this comment.
Any reason the node types were flipped between here and L156?
|
|
||
| func deserializeNode(buf []byte) MerkleNode { | ||
| switch buf[0] { | ||
| case InteriorNodeIdentifier: |
There was a problem hiding this comment.
This is a modularity comment: Might be worth moving each of these cases into a helper function to clean this function up.
| wb := db.NewBatch() | ||
| enWant.storeToKV(1, []bool{false}, wb) | ||
| inWant.storeToKV(1, []bool{true}, wb) | ||
| lnWant.storeToKV(1, util.ToBits(lnWant.index)[:lnWant.level], wb) |
There was a problem hiding this comment.
Is util.ToBits(lnWant.index)[:lnWant.level] how the developer is going to have to call ln.storeToKV()? If so, I think the interface should abstract this detail away.
There was a problem hiding this comment.
Same goes for loadNode() below in L94.
masomel
left a comment
There was a problem hiding this comment.
This is looking pretty good, though some of my comments do require changes. Should we also add db hooks for the TB?
| // return nil | ||
| // } | ||
| // return str | ||
| return nil // util we have a better way to construct the tree partially based on the lookup index. |
There was a problem hiding this comment.
Is this comment still relevant? It seems like str.LoadFromKV() doesn't do anything tree-related.
The differences between the two benchmarks aren't huge, but I agree that the current implementation works fine.
I'm thinking it might make sense to structure the db hooks in a similar fashion to how we've structured our library: server calls protocol calls merkletree. So one possible solution would be to move all of the *kv.go files to a I also think that the hooks should only be for deserializing/loading and serializing/storing. If we don't make the serialization functions etc methods of the corresponding types, we also shouldn't have to add new interface methods (e.g. in policy), right? If this is possible, this should allow us to de-tangle the DB hooks from the actual data structure. Addditionally, if we remove the hooks in functions like |
I'm trying to optimize the
Maybe I got your idea. Thanks for your suggestions! It totally makes sense!
Yeah, it's right! It makes things clearer. Let's see if I can make this work. |
|
Close and move to #88. |
PAD,STR,Policies,MerkleTree. The storing data is formatted as the comments ofStoreToKVmethods.kvPADfrom the latestSTRfrom the db (e.g., when the key server restarts), and to reconstruct a part of tree when looking through the db for specific epoch in lookup function.