referrerpolicy=no-referrer-when-downgrade

expected_siblings

Function expected_siblings 

Source
pub fn expected_siblings(width: u32, position: u32) -> usize
Expand description

Count sibling hashes needed to prove membership of the value at the position.

This is used to ensure that the right number of hashes was provided by the proof.

Unpaired nodes are promoted without a sibling, at any level. In the trees below, (n) is the proven leaf, [s] a sibling in the proof and | a promotion.

No promotion (width 4, position 1, siblings=2):

       root
      /    \
     .     [s]
    / \    / \
  [0] (1) 2   3
assert_eq!(cumulus_aura_authorizer_utils::expected_siblings(4, 1), 2);

Promoted at level 0 (width 7, position 6, siblings 2):

            root
        /          \
      [s]            .
     /   \         /   \
    .     .      [s]    |
   / \   / \     / \    |
  0   1 2   3   4   5  (6)
assert_eq!(cumulus_aura_authorizer_utils::expected_siblings(7, 6), 2);

Promoted twice at levels 0 and 1 (width 5, position 4, siblings 1):

          root
        /      \
      [s]       |
     /   \      |
    .     .     |
   / \   / \    |
  0   1 2   3  (4)
assert_eq!(cumulus_aura_authorizer_utils::expected_siblings(5, 4), 1);