Skip to main content

migration_wave_for

Function migration_wave_for 

Source
pub fn migration_wave_for(
    self_id: Option<&PeerId>,
    close_group_size: usize,
) -> u64
Expand description

Which wave this node belongs to, derived from its own ID.

Deterministic and needs no coordination, which is the point: a node cannot ask its close group “are you migrating?” without a protocol change, and the answer would be stale by the time it arrived. Hashing the peer ID spreads the members of any group across the waves without anybody agreeing on anything.

It is a stagger, not a guarantee. Seven IDs hashed into four waves will not always land two, two, two, one. What makes it safe rather than merely tidy is that it composes with the possession gate: a node whose turn has come still cannot give a chunk up until its neighbours have proven they hold it, so an unlucky wave waits instead of over-shedding.