vulcanize / go-codec-dagcosmos

A Go implementation of the DAG interface for Tendermint and Cosmos types
Other
8 stars 2 forks source link

Marshaller, unmarshaller, and multicodec reg for different tree types #19

Closed i-norden closed 3 years ago

i-norden commented 3 years ago

Currently this doesn't decode the leaf values of a header tree or part tree. I still need to figure out the best way to handle trees composed of header fields and arbitrarily fragmented blocks.

A header tree is a merkle tree with 14 leaf nodes, these nodes store the 14 protobuf encoded fields of a header in order. As such we only know how to handle decoding of a leaf value if we know its position in the tree, and therefore it's type (since the types otherwise cannot be distinguished e.g. can't tell apart a merkle root for a CommitTree vs a TxTree).

A part tree is a tree composed of the fragments of a protobuf encoded Block. The block bytes are split based on an arbitrary index size, meaning individual fields of the Block will be split across separate leaf nodes (it is not possible to map a leaf node value to a type). As such it is impossible to decode the values without collecting them all, concatenating the bytes in the order they appear in the leaf nodes, and unmarshalling the restored byte array into the Tendermint Block protobuf type.

Towards #3

i-norden commented 3 years ago

Close this to get the many finished trees in but still need to do #20