paritytech / trie

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

trie-db: Fetch the closest merkle value #199

Closed lexnv closed 12 months ago

lexnv commented 1 year ago

This PR adds support for fetching the merkle value directly from the trie-db.

We could build on this PR to have support for recorded Merkel Value in the cache.

Would love to get your thoughts on this @cheme @arkpar 🙏 (For reference @tomaka to ensure we don't break anything wrt to compatibilities between smoldot and substrate)

Part of https://github.com/paritytech/substrate/issues/14550.

// @paritytech/subxt-team

arkpar commented 1 year ago

After reading the spec more carefully, I think the logic here requires some changes. We need to return the descendant of the provided key, not just the lower bound. Basically this means traversing the tree as usual, but for Leaf, Extension and NibbledBranch nodes if you run out of key, just check if the current node key slice extends the remainder.

if slice.starts_with(&partial) {
  return Ok(Some(hash)))
else
  return Ok(None)
}