Skip to main content

select_subtree_path

Function select_subtree_path 

Source
pub fn select_subtree_path(
    nonce: &[u8; 32],
    key_count: u32,
) -> Option<SubtreePath>
Expand description

Deterministically select one contiguous subtree from (nonce, key_count).

Walks the nonce bits from the root, descending into the child the bit picks, and stops at the smallest branch whose real-leaf count is still ≥ ceil(sqrt(key_count)). Because an all-padding child has zero real leaves (< the floor), the walk never descends into one — so the selection always covers ≥ sqrt real leaves and is never empty (ADR dead-block fix).

For key_count <= SMALL_TREE_FULL_AUDIT_FLOOR the whole tree is selected.

Returns None only for an out-of-protocol key_count (caller rejects).