Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Fast sync child trie support. #9239

Merged
merged 27 commits into from
Nov 7, 2021

Conversation

cheme
Copy link
Contributor

@cheme cheme commented Jun 30, 2021

This PR extend fast sync to support child trie.

When export reach a child root it includes it in the proof and switch to the child trie proof.
When child trie proof is added it resumes parent trie export.
Start key is now a list of nested trie storage key.

Currently only two level of trie are supported so it could also make sense to switch api from start_key: Vec<Vec<u8>> to child_storage_key: Option<Vec<u8>>, start_key: Vec<u8>.

0d08f53 switches to compact proof usage (can be revert if needed).

@cheme cheme added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. A3-in_progress Pull request is in progress. No review needed at this stage. and removed A0-please_review Pull request needs code review. labels Jun 30, 2021
@cheme cheme added A0-please_review Pull request needs code review. D2-notlive 💤 PR contains changes in a runtime directory that is not deployed to a chain that requires an audit. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Jul 1, 2021
@cheme cheme requested a review from arkpar July 1, 2021 12:51
#[derive(PartialEq, Eq, Clone)]
pub struct KeyValueState {
/// Storage key in parent states.
pub parent_storages: Vec<Vec<u8>>,
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to identify subtree by storage root instead of a key paths?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks doable: instead of removing root from parent trie on response, we would register their storage key and build a payload that work for client.
It is a bit more work but I think it is a good idea.

Copy link
Contributor Author

@cheme cheme Jul 5, 2021

Choose a reason for hiding this comment

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

4bd673f implements it, it also avoid adding two child trie with same root in export (only for a reply).

if let Some(e) = response.entries.last() {
self.last_key = e.key.clone();
let mut complete = true;
if self.last_key.len() == 2 && response.entries[0].entries.len() == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

response.entries could be empty here?
Also, why self.last_key.len() == 2? Could use some explaining in the comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is empty when the whole change set is into a child trie: then we do not have the parent key in parent payload (already define in previous payload). I will add comment.

@arkpar arkpar mentioned this pull request Jul 6, 2021
@arkpar
Copy link
Member

arkpar commented Jul 22, 2021

@bkchr @andresilva Would be good to get reviews on this one in for warp sync as well, as it contains changes to the protocol.
Pretty much all of the code touched here is only used for warp/fast sync proof collection and verification. So it should not break anything.

@arkpar arkpar requested review from bkchr and andresilva July 22, 2021 13:52
@stale
Copy link

stale bot commented Sep 15, 2021

Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Sep 15, 2021
@cheme
Copy link
Contributor Author

cheme commented Sep 15, 2021

Just need a second review. Note that it already contains the fix for #9715, wish it was merge 2 month ago and did not have to investigate an refix it.

@stale stale bot removed the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Sep 15, 2021
@arkpar
Copy link
Member

arkpar commented Oct 12, 2021

Now that the substrate/polkadot version with the warp sync protocol has been released, changes to the protocol would be incompatible. I guess we need to bump the protocol version.

@cheme
Copy link
Contributor Author

cheme commented Oct 13, 2021

Yes looks needed. I was also thinking of moving the state sync message in their own protobuf file, but there is not much use in doing it except it separates things.

@gavofyork
Copy link
Member

bot merge

@paritytech-processbot paritytech-processbot bot merged commit 702fd83 into paritytech:master Nov 7, 2021
grishasobol pushed a commit to gear-tech/substrate that referenced this pull request Mar 28, 2022
* state machine proofs.

* initial implementation

* Remove todo.

* Extend test and fix import.

* fix no proof, with proof ko.

* fix start at logic.

* Restore response size.

* Rework comments.

* Add explicit ref

* Use compact proof.

* ref change

* elaborato on empty change set condition.

* KeyValueState renaming.

* Do not add two time child trie with same root to sync reply.

* rust format

* Fix merge.

* fix warnings and fmt

* fmt

* update protocol id to V2
ark0f pushed a commit to gear-tech/substrate that referenced this pull request Feb 27, 2023
* state machine proofs.

* initial implementation

* Remove todo.

* Extend test and fix import.

* fix no proof, with proof ko.

* fix start at logic.

* Restore response size.

* Rework comments.

* Add explicit ref

* Use compact proof.

* ref change

* elaborato on empty change set condition.

* KeyValueState renaming.

* Do not add two time child trie with same root to sync reply.

* rust format

* Fix merge.

* fix warnings and fmt

* fmt

* update protocol id to V2
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D2-notlive 💤 PR contains changes in a runtime directory that is not deployed to a chain that requires an audit.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants