Liking cljdoc? Tell your friends :D

urd.consensus.algorithms.snowflake

Snowflake and Snowball: the repeated-sampling core of the Avalanche family.

These are pure functions over a small map. They are separated from the Snowman node deliberately -- they are total, they have real invariants, and they are the natural first target for machine-checked verification.

The family

Slush keeps only a preference. Snowflake adds a CONSECUTIVE-success confidence counter and an absorbing finalized flag. Snowball adds a CUMULATIVE preference-strength tally and returns the argmax of that instead of the last successful poll's choice. Each is a strict superset of the previous.

Ported from avalanchego/snow/consensus/snowball (Aug 2026).

Which of these avalanchego actually deploys

Snowflake. Not Snowball. chains/manager.go:933 and :1358 both build &smcon.Topological{Factory: snowball.SnowflakeFactory}, and git log -S SnowflakeFactory -- chains/manager.go returns exactly one commit: db3b57a96f -- make snowman use snowflake directly instead of snowball (#3403). SnowballFactory is exported, exercised by the package's own tests, and wired into no chain.

So Snowball below -- the cumulative :strength tally, the argmax preference, the finalized-versus-argmax asymmetry that accept-weird-color pins -- is reference material rather than production behaviour. It is kept because it is the published algorithm, because the papers are stated in its terms, and because a library covering the family should be able to express it. It is not kept under the impression that it is what the network runs.

Two further notes on drift from the papers, both verified against that tree:

  • betaVirtuous / betaRogue are GONE. They were replaced by a single beta plus a list of (alpha-confidence, beta) termination conditions. Production always uses exactly one pair; the multi-condition path ("early termination": a stronger quorum finalizes in fewer rounds) is exercised only by tests. We model the list, since it costs nothing and the single-condition case is just a list of one. termination-conditions is public and overridable so the multi-condition path can actually be CONSTRUCTED: while the pairs were derived from params inside a private function, no caller could build an instance with more than one counter, the partial-clear semantics that are the vector's whole reason for existing were unobservable, and the claim above was not true of the code.

  • The Avalanche DAG protocol has been DELETED from avalanchego entirely (the X-Chain moved to Snowman in Cortina). Only Snowman remains, so the papers are the sole source for the DAG variant.

Parameters

k                sample size per poll
alpha-preference votes needed to move the preference
alpha-confidence votes needed to increment confidence
beta             consecutive successes needed to finalize

Validity (parameters.go:93-116):

k/2 < alpha-preference <= alpha-confidence <= k

The first conjunct forces a strict majority of the sample, so two conflicting choices cannot both clear alpha-preference in one poll of one honest node. The second guarantees that any poll which increments confidence also moved the preference -- which is what makes the beta-run characterisation below hold.

Snowflake and Snowball: the repeated-sampling core of the Avalanche family.

These are pure functions over a small map. They are separated from the
Snowman node deliberately -- they are total, they have real invariants, and
they are the natural first target for machine-checked verification.

## The family

Slush keeps only a preference. Snowflake adds a CONSECUTIVE-success
confidence counter and an absorbing `finalized` flag. Snowball adds a
CUMULATIVE preference-strength tally and returns the argmax of that instead of
the last successful poll's choice. Each is a strict superset of the previous.

Ported from `avalanchego/snow/consensus/snowball` (Aug 2026).

## Which of these avalanchego actually deploys

**Snowflake.** Not Snowball. `chains/manager.go:933` and `:1358` both build
`&smcon.Topological{Factory: snowball.SnowflakeFactory}`, and
`git log -S SnowflakeFactory -- chains/manager.go` returns exactly one commit:
`db3b57a96f` -- make snowman use snowflake directly instead of snowball
(#3403). `SnowballFactory` is exported, exercised by the package's own tests,
and wired into no chain.

So Snowball below -- the cumulative `:strength` tally, the argmax preference,
the finalized-versus-argmax asymmetry that `accept-weird-color` pins -- is
reference material rather than production behaviour. It is kept because it is
the published algorithm, because the papers are stated in its terms, and
because a library covering the family should be able to express it. It is not
kept under the impression that it is what the network runs.

Two further notes on drift from the papers, both verified against that tree:

- `betaVirtuous` / `betaRogue` are GONE. They were replaced by a single
  `beta` plus a list of (alpha-confidence, beta) termination conditions.
  Production always uses exactly one pair; the multi-condition path ("early
  termination": a stronger quorum finalizes in fewer rounds) is exercised
  only by tests. We model the list, since it costs nothing and the
  single-condition case is just a list of one. `termination-conditions` is
  public and overridable so the multi-condition path can actually be
  CONSTRUCTED: while the pairs were derived from `params` inside a private
  function, no caller could build an instance with more than one counter, the
  partial-clear semantics that are the vector's whole reason for existing were
  unobservable, and the claim above was not true of the code.

- The Avalanche DAG protocol has been DELETED from avalanchego entirely
  (the X-Chain moved to Snowman in Cortina). Only Snowman remains, so the
  papers are the sole source for the DAG variant.

## Parameters

    k                sample size per poll
    alpha-preference votes needed to move the preference
    alpha-confidence votes needed to increment confidence
    beta             consecutive successes needed to finalize

Validity (`parameters.go:93-116`):

    k/2 < alpha-preference <= alpha-confidence <= k

The first conjunct forces a strict majority of the sample, so two conflicting
choices cannot both clear `alpha-preference` in one poll of one honest node.
The second guarantees that any poll which increments confidence also moved the
preference -- which is what makes the beta-run characterisation below hold.
raw docstring

binary-record-pollclj/s

(binary-record-poll sf votes bit)

binary_snowflake.go:47-80. bit is 0 or 1.

Unlike the unary form this DOES guard finalized? and DOES check alpha-preference itself, and a flip clears confidence before the run -- the same consecutive-poll rule as the n-ary instance, over two choices.

`binary_snowflake.go:47-80`. `bit` is 0 or 1.

Unlike the unary form this DOES guard `finalized?` and DOES check
alpha-preference itself, and a flip clears confidence before the run --
the same consecutive-poll rule as the n-ary instance, over two choices.
sourceraw docstring

binary-record-unsuccessful-pollclj/s

(binary-record-unsuccessful-poll sf)
source

binary-snowflakeclj/s

(binary-snowflake params bit)

A binary instance: which of two branches, 0 or 1, at one bit.

A binary instance: which of two branches, 0 or 1, at one bit.
sourceraw docstring

confidenceclj/s

(confidence sb)
source

default-paramsclj/s

source

finalized?clj/s

(finalized? sb)
source

instance-finalized?clj/s

(instance-finalized? sf)

Works for a unary or a binary instance -- both keep the flag at the top.

Works for a unary or a binary instance -- both keep the flag at the top.
sourceraw docstring

snowballclj/s

(snowball params choice)

A fresh Snowball instance preferring choice.

A fresh Snowball instance preferring `choice`.
sourceraw docstring

snowball-preferenceclj/s

(snowball-preference sb)

The current preference.

Note the asymmetry, which is NOT cosmetic: once finalized, Snowball returns the SNOWFLAKE's preference, not its own argmax. The two can disagree at the instant of finalization, and the snowflake's choice wins. avalanchego pins this with TestBinarySnowballAcceptWeirdColor; reproduce it or diverge.

The current preference.

Note the asymmetry, which is NOT cosmetic: once finalized, Snowball returns
the SNOWFLAKE's preference, not its own argmax. The two can disagree at the
instant of finalization, and the snowflake's choice wins. avalanchego pins
this with `TestBinarySnowballAcceptWeirdColor`; reproduce it or diverge.
sourceraw docstring

snowball-record-pollclj/s

(snowball-record-poll sb votes choice)

Apply a poll result.

Snowball's only delta from Snowflake is the preference rule: it tracks a CUMULATIVE tally per choice and prefers the argmax, where Snowflake prefers whatever won the last successful poll. Flips only on STRICT improvement, so ties are broken lazily in favour of the incumbent (nnary_snowball.go:50-61).

Apply a poll result.

Snowball's only delta from Snowflake is the preference rule: it tracks a
CUMULATIVE tally per choice and prefers the argmax, where Snowflake prefers
whatever won the last successful poll. Flips only on STRICT improvement, so
ties are broken lazily in favour of the incumbent (`nnary_snowball.go:50-61`).
sourceraw docstring

snowflakeclj/s

(snowflake params choice)

A fresh Snowflake instance preferring choice.

A fresh Snowflake instance preferring `choice`.
sourceraw docstring

snowflake-record-pollclj/s

(snowflake-record-poll sf votes choice)

Apply a poll result: votes for choice out of k.

Total. Mirrors nnary_snowflake.go:54-88 exactly:

  • finalized is ABSORBING -- a finalized instance ignores everything;
  • below alpha-preference is indistinguishable from an unsuccessful poll;
  • a preference FLIP zeroes confidence first, which is why preference churn can never accumulate toward finalization;
  • confidence increments by at most one per poll.
Apply a poll result: `votes` for `choice` out of k.

Total. Mirrors `nnary_snowflake.go:54-88` exactly:

  - finalized is ABSORBING -- a finalized instance ignores everything;
  - below alpha-preference is indistinguishable from an unsuccessful poll;
  - a preference FLIP zeroes confidence first, which is why preference churn
    can never accumulate toward finalization;
  - confidence increments by at most one per poll.
sourceraw docstring

snowflake-record-unsuccessful-pollclj/s

(snowflake-record-unsuccessful-poll sf)

A poll that failed to reach alpha-preference. Clears confidence; finalized? is untouched, since it is absorbing.

A poll that failed to reach alpha-preference. Clears confidence; `finalized?`
is untouched, since it is absorbing.
sourceraw docstring

termination-conditionsclj/s

(termination-conditions params)

The (alpha-confidence, beta) pairs this instance finalizes on.

:termination-conditions supplied explicitly wins; otherwise the single condition built from :alpha-confidence/:beta, which is newSingleTerminationCondition (parameters.go:131-138) and is what avalanchego actually deploys.

This is public and overridable so the multi-condition path is REACHABLE. It was not: the pairs were derived from params inside a private function, so no caller could construct an instance with more than one counter, and the partial-clear semantics of the confidence vector -- the only reason the vector is a vector -- could never be observed. snowflake_test.go:10-23 drives every one of its four generators off a three-element table.

The (alpha-confidence, beta) pairs this instance finalizes on.

`:termination-conditions` supplied explicitly wins; otherwise the single
condition built from `:alpha-confidence`/`:beta`, which is
`newSingleTerminationCondition` (`parameters.go:131-138`) and is what
avalanchego actually deploys.

This is public and overridable so the multi-condition path is REACHABLE.
It was not: the pairs were derived from `params` inside a private function,
so no caller could construct an instance with more than one counter, and the
partial-clear semantics of the confidence vector -- the only reason the vector
is a vector -- could never be observed. `snowflake_test.go:10-23` drives every
one of its four generators off a three-element table.
sourceraw docstring

unary-extendclj/s

(unary-extend sf bit)

Extend(bit): become a binary instance preferring bit.

The accumulated confidence CARRIES OVER. That is the point of the Tree: a run of bits that has been polled into agreement does not start again from zero when a new choice forces the run to split.

`Extend(bit)`: become a binary instance preferring `bit`.

The accumulated confidence CARRIES OVER. That is the point of the Tree: a run
of bits that has been polled into agreement does not start again from zero
when a new choice forces the run to split.
sourceraw docstring

unary-record-pollclj/s

(unary-record-poll sf votes)

unary_snowflake.go:45-64.

Note what is NOT here: no finalized? guard, and no alpha-preference check. Both live in the caller -- unaryNode.RecordPoll tests alpha before calling -- so this is asymmetric with binary-record-poll, which has both. The asymmetry is avalanchego's and is reproduced rather than tidied, because tidying it would silently move where an alpha threshold is enforced.

`unary_snowflake.go:45-64`.

Note what is NOT here: no `finalized?` guard, and no alpha-preference check.
Both live in the caller -- `unaryNode.RecordPoll` tests alpha before calling
-- so this is asymmetric with `binary-record-poll`, which has both. The
asymmetry is avalanchego's and is reproduced rather than tidied, because
tidying it would silently move where an alpha threshold is enforced.
sourceraw docstring

unary-record-unsuccessful-pollclj/s

(unary-record-unsuccessful-poll sf)
source

unary-snowflakeclj/s

(unary-snowflake params)

A unary instance: no choice at all, only confidence that the bits it covers are settled.

A unary instance: no choice at all, only confidence that the bits it covers
are settled.
sourceraw docstring

valid-params?clj/s

(valid-params? {:keys [k alpha-preference alpha-confidence beta] :as params})

Are these parameters self-consistent?

A total predicate; the natural first thing to machine-check.

Are these parameters self-consistent?

A total predicate; the natural first thing to machine-check.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close