paritytech / trie

Base-16 Modified Patricia Merkle Tree (aka Trie)
Apache License 2.0
251 stars 67 forks source link

Is there any docs or words to explain way pr#142 change the leaf node from storing normal value to a hashed node? #152

Open atenjin opened 2 years ago

atenjin commented 2 years ago

relate to #142 and substrate pr https://github.com/paritytech/substrate/pull/9732 I don't know why you design this feature, to change the leaf node from storing a normal value to a hashed node related to threshold. This change causes a migration for substrate node, but I do not understand this feature is necessary.

It seems that this feature uses one more hash to bring less cause for calculating state root? or something else?

I do not find any discuss for this. Can you explain more reason for this feature?

bkchr commented 2 years ago

CC @cheme

cheme commented 2 years ago

It is only to reduce proof size.

Gist of it is, if value is behind same merkle hash as the partial key of its node, then every access to the partial key will add the value in the proof and for three use case it is better to be able to only add hash of the value.

I have no trace of original discussion (on riot a long time ago), but https://github.com/paritytech/substrate/discussions/11607 goes into more details about the implementation details.

Edit: forgot to mention, but also when updating a value without reading it, this allow not having the old value in proof.