Files
consensus/engine/chain/proposer_resolicit_test.go
zeekayandHanzo Dev bba3234534 consensus: a quorum of zero is not a quorum
The chain engine decides on `acceptVotes() >= alpha`, so alpha=0 makes that
predicate hold over an EMPTY accept set. Any arriving vote — including one
AGAINST the block — then marks it accepted with zero accept votes, and Poll's
`rejectVotes() >= alpha` fires on nothing too, rejecting every fresh block and
dropping it from the tips. Two partitioned nodes could settle different blocks
at the same height with no quorum and no cert.

alpha=0 was reachable because Config.Validate had no callers — New,
NewWithConfig, NewWithParams and NewRuntime all reached NewChainConsensus
unchecked — and because Parameters.Valid gated its alpha checks behind
`AlphaPreference != 0`. The one value that destroys safety was the one value
that skipped validation.

Three independent layers close it, each judged by ONE definition of a safe
quorum:

  - config.Parameters.ValidQuorum, split out of Valid, judges K and the two
    integer alphas: 1 <= alpha <= K (unconditional now), AlphaConfidence >=
    AlphaPreference (never enforced before, so preference=15/confidence=1
    passed), and the Byzantine overlap floor, also unconditional. Valid calls
    it, so the two cannot drift. The split lets the engine demand SAFETY
    without also demanding the descriptive Alpha ratio and block timings,
    which have no bearing on whether a quorum can fork.

  - Transitive.Start refuses to run unsafe parameters. The check belongs here,
    not in the constructors: options are applied AFTER config, so WithParams
    can replace params a constructor already validated. Start is the one point
    every engine passes through with its final parameters.

  - NewChainConsensus, the single place the running predicate is armed, pins
    (k, alpha) into k >= 1, 1 <= alpha <= k. A path that skips both checks
    still cannot arm a predicate satisfiable by nothing.

Reclamp gains the safety floor as well. It installs a quorum on a LIVE engine
from a DERIVED validator count, and used to accept any well-formed alpha —
including k=4/alpha=2, where two disjoint quorums overlap in nothing. The
supermajority the committee sizer derives clears the floor at every k, so no
legitimate re-clamp is refused.

Fixtures that encoded unsafe quorums are corrected rather than exempted.
params5 was K=5/alpha=3: two 3-of-5 quorums overlap in a SINGLE node, so one
faulty validator (f=1 at K=5) can certify both sides of a fork. It is now
K=5/alpha=4 — the Byzantine floor, and what FeasibleParams(Local, 5) derives
for the live nets — which makes params5Prod an exact duplicate, so it goes.
Two config cases declared K and Beta with no integer alpha at all and expected
Valid to pass; that is a zero-vote quorum, not an unspecified one. Catch-up
certs carrying four signatures now declare the 4-of-5 threshold they are, and
the forged-signature case declares a real threshold so it still fails on the
forgery rather than on a stale bound.

The single-validator path is untouched: K=1/alpha=1 satisfies the floor, needs
no vote verifier, and bftCommittee still leaves a genuine K=1 preset unclamped.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-01 12:01:23 -07:00

105 lines
4.3 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Copyright (C) 2019-2026, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// proposer_resolicit_test.go — the direct fails-before/passes-after proof of the
// build-path re-solicit alignment (engine.go buildBlocksLocked). avalanchego never
// silently drops a rebuild of a still-processing preferred block: its repoll keeps
// re-querying it until it decides. Lux's `continue` on an already-tracked block
// dropped the build signal, so a peer that missed the first PushQuery was only
// re-asked on the slower rePollAllPending backoff. This test parks the re-poll
// ticker and proves the BUILD path itself re-solicits an undecided own proposal.
package chain
import (
"context"
"testing"
"time"
"github.com/luxfi/ids"
)
// TestProposerRebuild_ReSolicitsOwnUndecidedProposal drives two build passes for
// the SAME own block while it is still undecided (only the self-vote; α=4 not
// reached). The re-poll ticker is parked (RoundTO huge), so the ONLY thing that
// can re-solicit votes is the build path. With the fix the second build re-issues
// RequestVotes; the pre-fix bare `continue` leaves the count flat.
//
// PRE-FIX (revert the re-solicit block in buildBlocksLocked back to a bare
// `continue`): second == first → RED.
// POST-FIX: second > first → GREEN.
func TestProposerRebuild_ReSolicitsOwnUndecidedProposal(t *testing.T) {
vs := newTestValidatorSet(5)
params := params5()
params.RoundTO = 30 * time.Second // park the re-poll ticker: only the BUILD path may re-solicit
rec := &recordingGossiper{}
e, _ := newQuorumEngine(t, params, vs, 0, rec)
cp := newReSolicitProbe()
e.SetProposer(cp)
blk := newTestBlock(1, ids.Empty, "rebuilt-own")
vm := &prefRecordingVM{build: blk}
e.SetVM(vm)
// First build: tracks the own proposal and solicits its votes once.
if err := e.Notify(context.Background(), Message{Type: PendingTxs}); err != nil {
t.Fatalf("Notify #1: %v", err)
}
first := cp.requestCount(blk.id)
if first == 0 {
t.Fatalf("first build must solicit votes at least once (got %d)", first)
}
// The block is still undecided (self-vote only, below α=4). The VM re-offers the
// SAME block (mempool still non-empty). Only the build-path re-solicit can fire.
if err := e.Notify(context.Background(), Message{Type: PendingTxs}); err != nil {
t.Fatalf("Notify #2: %v", err)
}
second := cp.requestCount(blk.id)
if second <= first {
t.Fatalf("REBUILD DROPPED: a rebuild of the UNDECIDED own proposal did not re-solicit votes "+
"(RequestVotes stayed at %d). avalanchego re-queries a still-processing preferred block until it "+
"decides; the bare `continue` on already-tracked silently drops the build signal, so a peer that "+
"missed the first PushQuery is never re-asked on the build path.", second)
}
}
// TestProposerRebuild_DoesNotReSolicitDecidedProposal proves the re-solicit is
// scoped: once a block is DECIDED, a spurious rebuild does NOT re-solicit (no
// wasted gossip for a finalized height). It also guards against re-soliciting a
// non-own block (the build path only ever handles own proposals, but the Decided
// gate is the belt-and-suspenders that keeps a finalized own block quiet).
func TestProposerRebuild_DoesNotReSolicitDecidedProposal(t *testing.T) {
vs := newTestValidatorSet(5)
params := params5()
params.RoundTO = 30 * time.Second
rec := &recordingGossiper{}
e, chainID := newQuorumEngine(t, params, vs, 0, rec)
cp := newReSolicitProbe()
e.SetProposer(cp)
blk := newTestBlock(1, ids.Empty, "decided-own")
vm := &prefRecordingVM{build: blk}
e.SetVM(vm)
// Track + finalize the block with a full α-of-K quorum so it is Decided.
pos := trackProposal(e, chainID, blk, 0) // self = 1
e.ReceiveVote(vs.signedVote(1, pos))
e.ReceiveVote(vs.signedVote(2, pos))
e.ReceiveVote(vs.signedVote(3, pos)) // 4 of 5 → finalizes
if !waitFor(2*time.Second, func() bool { return e.IsAccepted(blk.id) }) {
t.Fatal("setup: block must finalize with its α-of-K quorum")
}
before := cp.requestCount(blk.id)
// A rebuild of the now-DECIDED block must not re-solicit.
if err := e.Notify(context.Background(), Message{Type: PendingTxs}); err != nil {
t.Fatalf("Notify: %v", err)
}
if after := cp.requestCount(blk.id); after != before {
t.Fatalf("a DECIDED block must not be re-solicited on rebuild (RequestVotes went %d -> %d)", before, after)
}
}