-
Notifications
You must be signed in to change notification settings - Fork 150
chore(l1): fast validate #5713
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
chore(l1): fast validate #5713
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -528,6 +528,38 @@ impl Trie { | |
| trie.root = root; | ||
| trie | ||
| } | ||
|
|
||
| /// Validates that the Trie isn't missing any nodes expected in the branches | ||
| /// | ||
| /// This is used internally with debug assertions to check the status of the trie | ||
| /// after syncing operations. | ||
| /// Note: this operation validates the hashes because the iterator uses | ||
| /// get_node_checked. We shouldn't downgrade that to the unchecked version | ||
| pub fn validate(self) -> Result<(), TrieError> { | ||
| let mut expected_count = if self.root.is_valid() { 1 } else { 0 }; | ||
| for (_, node) in self.into_iter() { | ||
| expected_count -= 1; | ||
| match node { | ||
| Node::Branch(branch_node) => { | ||
| expected_count += branch_node | ||
| .choices | ||
| .iter() | ||
| .filter(|child| child.is_valid()) | ||
| .count(); | ||
| } | ||
| Node::Extension(_) => { | ||
| expected_count += 1; | ||
| } | ||
| Node::Leaf(_) => {} | ||
| } | ||
| } | ||
fedacking marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if expected_count != 0 { | ||
| return Err(TrieError::Verify(format!( | ||
| "Node count mismatch, expected {expected_count} more" | ||
| ))); | ||
|
Comment on lines
+556
to
+559
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We lost context here, maybe for a follow-up but we might want better info for this error (like node/path) to understand where to look instead of just the difference? Not sure if right now that info is useful or not, i didn't debugged these cases before, if it is indeed useful we can create a small issue for later. |
||
| } | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| impl IntoIterator for Trie { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.