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

trie: cleaner logic, one less func call #16803

Merged
merged 1 commit into from
May 24, 2018

Conversation

karalabe
Copy link
Member

This PR is a very tiny fix, that doesn't really have any impact other than code clarity. When hashing the account trie, whenever we reached a leaf node (account), we called onleaf. This onleaf method is used by statedb for trie pruning to link this leaf account to its storage trie.

There was a slight oversight I didn't realize while adding this logic: full trie nodes are often incomplete (i.e. some of its children are nil), but not flat out nil, rather valuenode(nil). This means that if child, ok := n.Children[i].(valueNode); ok { actually returns true and we call onleaf for dangling terminators. This is not an issue in our code, since onleaf tries to parse the leaf as an account, nil will fail parsing and returns, but this is an extra function call overhead we don't need.

Code clarity wise it took me 3 hours of debugging to realize why the path leading to such a "leaf" was invalid. Because it was not an actual leaf, just a dangling terminator. This is mostly what prompted this PR, so the next person touching this code won't waste 3 more hours ;P

@karalabe karalabe added this to the 1.8.9 milestone May 24, 2018
@karalabe karalabe merged commit 54294b4 into ethereum:master May 24, 2018
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.

3 participants