merkletree icon indicating copy to clipboard operation
merkletree copied to clipboard

Serialization support?

Open adamcypher opened this issue 4 years ago • 3 comments

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

encoding/gob seems to fail

adamcypher avatar Aug 22 '19 23:08 adamcypher

@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

cbergoon avatar Aug 25 '19 17:08 cbergoon

@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!

pocockn avatar Jun 17 '20 16:06 pocockn

@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

cbergoon avatar Jun 24 '20 20:06 cbergoon