freecoding.school100% FREE · NO SIGNUP
Proof PeaksISSUE #34 of 38

avalanche · metastable consensus

ZeekaVSThe Collision
Zeeka saysAvalanche reaches consensus by repeated random sampling: each node polls a small committee, switches preference if a supermajority disagrees, and metastable convergence happens in milliseconds.

Avalanche is neither PoW nor classical BFT — it is metastable. Many nodes can hold different opinions briefly, but tiny biases get amplified exponentially under repeated random sampling. Each round, every node queries k random peers; if α of them agree on the opposite preference, it switches. With even a small initial bias, the network converges with high probability in roughly log(N) rounds.

The protocol gives sub-second finality across hundreds of nodes and underlies the Avalanche primary network and its subnets. The demo simulates 100 nodes starting 51/49 split, runs k-sampling rounds, and shows all converging to one opinion within twenty rounds — exactly the metastable amplification.

Power-ups you unlock

The Collision attacks — common mistakes

Boss battleSimulate 100 nodes starting 51/49 split and show all converge to one opinion within 20 sampling rounds.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>
// Avalanche metastable sampling: poll k peers, switch on α/k majority.
const N = 100, k = 10, alpha = 7;
const opinion = Array.from({length:N}, (_,i) => i < 51 ? 'red' : 'blue');
const tallyRed = (o) => o.filter(x => x === 'red').length;
const rows = ['round  0: ' + tallyRed(opinion) + ' red, ' + (N - tallyRed(opinion)) + ' blue'];
for(let r = 1; r <= 20; r++){
  const next = [...opinion];
  for(let i = 0; i < N; i++){
    let red = 0; for(let j = 0; j < k; j++) if(opinion[Math.floor(Math.random()*N)] === 'red') red++;
    if(red >= alpha) next[i] = 'red'; else if((k - red) >= alpha) next[i] = 'blue';
  }
  for(let i = 0; i < N; i++) opinion[i] = next[i];
  if(r % 4 === 0 || r === 20) rows.push('round ' + String(r).padStart(2) + ': ' + tallyRed(opinion) + ' red, ' + (N - tallyRed(opinion)) + ' blue');
  if(tallyRed(opinion) === N || tallyRed(opinion) === 0) break;
}
document.getElementById('o').textContent = [
  ...rows,
  'metastable convergence: tiny initial bias amplifies via random sampling'
].join('\n');
</script></body></html>
▶ Open the interactive comic issue
‹ Dag Consensus · Narwhal · BullsharkOuroboros · Provably Secure Pos ›