5

According to the example here, I see one could use the srml_support::storage::child API to create a merkle sub trie out of arbitrary data. But how can we get the merkle root or a proof for a particular leaf using this? I see the API doesn't provide any functions named as such.

vim
  • 1,098
  • 9
  • 21
  • You tagged your question with `substrate`, would you be interested in a dedicated Stack Exchange Q&A site for Substrate, Polkadot, et al. -- check out the [Area51 Substrate Proposal](https://area51.stackexchange.com/proposals/122626/substrate?referrer=NTUwMTkxYjJjOTJiNjE0YzMxYjgwMGNkZmFlYzdhZTczYjk1ZWY3ZGI4NzJmODUwN2RlYTQ2MTNjZTdkOTZhMAzuL-zybtPN9CHzwE-WUdvBC8WxvPG46b4ayadke6kG0) – q9f Jul 28 '19 at 10:57
  • Hey VIM, we are trying again to open a dedicated Substrate StackExchange. Can you take a look and support the proposal? https://area51.stackexchange.com/proposals/126136 – Shawn Tabrizi Dec 16 '21 at 13:05

2 Answers2

4

The srml_support::storage::child API make use of sr_io API.

sr_io provides more functionality, for example sr_io::child_storage_root which is the function you are looking for.

Shawn Tabrizi
  • 12,206
  • 1
  • 38
  • 69
thiolliere
  • 516
  • 2
  • 3
  • how do I obtain a proof for a leaf of a child trie? I see the above API do not have such a function. – vim Jul 26 '19 at 12:24
2

An alternative is to directly query the parent trie node containing the root. For the linked exemple it will be something like this (child_storage_root is doing calculation of ongoing change whereas querying directly the root get the state at the start of the block processing or the latest stored state calculation):

let id = Self::id_from_index(index);
let child_root = storage::unhashed::get_raw(id.as_ref());
cheme
  • 378
  • 3
  • 10