trie: cleaner logic, one less func call #16803
Merged
+2
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
. Thisonleaf
method is used bystatedb
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
, rathervaluenode(nil)
. This means thatif child, ok := n.Children[i].(valueNode); ok {
actually returns true and we callonleaf
for dangling terminators. This is not an issue in our code, sinceonleaf
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