cbergoon / merkletree

A Merkle Tree implementation written in Go.
MIT License
491 stars 126 forks source link

Serialization support? #13

Open adamcypher opened 5 years ago

adamcypher commented 5 years ago

Is there a good way to serialize and deserialize the merkle tree?

encoding/gob seems to fail

cbergoon commented 5 years ago

@adamgering do you have the specific error?

I see a couple potential problems. There is a circular reference between the node and the tree structs that might be causing a problem. We can probably get around this with custom encode/decode functions.

The second likely issue is that the hash function is stored on the MerkleTree type to allow it to be configurable. Since we cannot serialize a function in Go maybe this should be handled at the application level.

Cam

pocockn commented 4 years ago

@cbergoon Did you get any further with this issue? I'm trying to serialize and deserialize the tree but I'm getting the circular reference error you mentioned. Great library!

cbergoon commented 4 years ago

@pocockn unfortunately I haven't looked into it much more. I will try to spend some time on it this weekend - if the reference can't be removed I'm thinking maybe an intermediate form that would omit the reference and be recalculated. As for the hash function being dynamic we could potentially change this to only support the std lib hash types; this way we do not need the function but just an indicator of which to use.

Haven't thought it all the way through yet so if you have suggestions feel free to share.

Cam