MCPcopy Create free account
hub / github.com/base/base / find_differing_leaf_pairs

Function find_differing_leaf_pairs

etc/tools/witness-diff/src/diff.rs:121–137  ·  view source on GitHub ↗

Find leaf nodes that share the same trie path but carry different values. A well-formed trie has at most one leaf per path, so duplicate prefixes within a single witness are not expected. If the input is malformed the `HashMap::collect()` below will silently retain only the last entry for any duplicate path; this is acceptable for a diagnostic tool where correctness of the trie structure is a pre

(
    local_leaves: &[DecodedLeaf],
    rpc_leaves: &[DecodedLeaf],
)

Source from the content-addressed store, hash-verified

119/// duplicate path; this is acceptable for a diagnostic tool where correctness
120/// of the trie structure is a precondition.
121pub fn find_differing_leaf_pairs(
122 local_leaves: &[DecodedLeaf],
123 rpc_leaves: &[DecodedLeaf],
124) -> Vec<(Nibbles, Bytes, Bytes)> {
125 let rpc_by_prefix: HashMap<&Nibbles, &Bytes> =
126 rpc_leaves.iter().map(|l| (&l.prefix, &l.value)).collect();
127
128 let mut pairs = Vec::new();
129 for local_leaf in local_leaves {
130 if let Some(rpc_value) = rpc_by_prefix.get(&local_leaf.prefix)
131 && local_leaf.value != **rpc_value
132 {
133 pairs.push((local_leaf.prefix, local_leaf.value.clone(), (*rpc_value).clone()));
134 }
135 }
136 pairs
137}
138
139/// Compare two sets of bytes and print a compact diff summary.
140///

Callers 1

runFunction · 0.85

Calls 4

iterMethod · 0.45
getMethod · 0.45
pushMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected