Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow consuming iterator when decoding compact proof. #135

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cheme
Copy link
Contributor

@cheme cheme commented Jun 18, 2021

In cumulus, decoding involve *2 size of proof memory usage from pvf during decoding.

This PR switch trie_codec to allow consuming iterator : see decode_compact_from_iter_owned that will allow
us to do iteraton on storage proof in a consuming way with cumulus.

Something like

let mut nodes = storage_proof.encoded_nodes;
nodes.reverse();
let root = match sp_trie::decode_compact_owned::<sp_trie::Layout<HashFor<B>>, _, _>(
		&mut db,
		sp_std::iter::from_fn(move|| nodes.pop()),
		Some(parent_head.state_root()),
	) {

Note that there will always be a time when we got twice the memory of a single node, but that is the same for any storage read.

cc\ @bkchr

Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized this will probably not bring that much, but yeah looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants