Skip to content

fix(consensus): select a proposer after rotating to a single validator - #1654

Draft
lklimek wants to merge 2 commits into
fix/ws-error-resubscribe-hangfrom
fix/consensus-single-validator-proposer
Draft

lklimek wants to merge 2 commits into
fix/ws-error-resubscribe-hangfrom
fix/consensus-single-validator-proposer

Conversation

@lklimek

@lklimek lklimek commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

TL;DR: A network whose validator set shrinks to a single validator keeps producing blocks instead of crashing every node.

User story

As a Dash Platform node operator, I want my node to keep running when the validator quorum rotates to a single member, so a small or test network does not halt.

Scenario

Base flow

  1. A network rotates its validator quorum.
  2. The new quorum has only one validator.
  3. Each node selects the proposer for the next height.

Actual behavior

Every node crashes with CONSENSUS FAILURE!!! ... nil pointer dereference and the network halts.

Expected behavior

The only validator becomes the proposer and the network continues.

Detailed discussion

What was done

  • heightProposerSelector.proposerFromStore (internal/consensus/versioned/selectproposer/height_proposer.go): after a quorum rotation it picks the validator at index 1, deliberately preserving historical behaviour for consensus compatibility. A one-member set has no index 1, so GetByIndex(1) returned nil and the node crashed.
    • A one-member set now uses index 0. Sets of two or more keep index 1, so proposer selection is unchanged for every deployed network (all consensus versions 0–2).
    • An empty set returns an error instead of panicking.
  • New test TestProposerSelectionQuorumRotation: quorum rotation into sets of 1 and 2 validators, consensus versions 0–2, and the following heights and rounds. It reproduced the panic before the fix.

Evidence: a local e2e run (dev at 831bbeaf6 and 1871893d0) rotated to [validator_update.1010] validator05 = 100 and every node crashed in proposerFromStore.

Stacked on #1642; the stacked PR above it removes the unused ci e2e network.

Out of scope: ValidatorSet.proposerIndex is not clamped when a set shrinks in place with the same quorum hash (types/validator_set.go, updateWithChangeSet). This is pre-existing and found in review; it is a separate follow-up.

Known limitations: None.

Testing

  • go test -race -p 2 -count=1 ./internal/consensus/versioned/...: pass. The new test failed (panic) before the fix.
  • go vet on the package: pass. make lint LINT_BASE=3382eff1a reports only the local libpcap typecheck (the gosec G115 finding from review is fixed).
  • Cross-provider review: one HIGH (lint) and one LOW finding, both fixed; one pre-existing MEDIUM moved out of scope (above).

Breaking changes

None.

🤖 Co-authored by Claudius the Magnificent AI Agent

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@lklimek
lklimek added this pull request to stack #1650 November 26, 2026 14:18
@lklimek lklimek added this to the v2.1 milestone Nov 26, 2026
@thepastaclaw

thepastaclaw commented Nov 26, 2026 •

Copy link
Copy Markdown

🕓 Review not started yet because this PR is a draft.

  • Request normal review — click when the PR is ready for review.
  • Request priority review — click to move this review to the front of the queue.

Commit d306401. Normal review starts when eligible; priority review starts as soon as a slot is available.

@lklimek
lklimek removed this pull request from stack #1650 November 26, 2026 16:19
@lklimek
lklimek added this pull request to stack #1658 November 26, 2026 16:19

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final validation — Phase 1 + Phase 2

Consensus version 0 now selects the sole validator after a quorum rotation instead of dereferencing a missing second validator. Larger sets and consensus versions 1 and 2 keep their existing selection rules. All six test shards, both end-to-end jobs, the Linux build, vet, and lint passed on this head; the PastaClaw review check is still pending.

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: tenderdash-consensus-security); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.2-sol (effort low) — The change is a small, contained fix in proposerFromStore that handles empty and single-validator sets while preserving the existing selection rule for larger sets.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort high); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (zai below 15% reserve: 5h 100% left, weekly 0% left)
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.2-sol — tenderdash-consensus-security (completed, effort medium); agent phase2-reviewer
Out-of-scope follow-up suggestions (1)

These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.

  • In-place validator removals can prevent consensus from advancing — When an ABCI update retains the quorum hash, UpdateWithChangeSet preserves the old proposer index. If the set shrinks past that index, ValidateBasic rejects the update before proposer selection. Even if the index stays in bounds, an otherwise valid update that retains the quorum hash and threshold key leaves ValidatorSet.Hash() unchanged. If the update removed the previous block's proposer, the selector tries to restore a validator who is no longer in the set, and consensus initialization fails. Both paths predate this PR.
    • Follow-up: Track this in a separate issue and follow-up PR. Define how to update the proposer index after an in-place membership change and how to select the next proposer deterministically when the previous proposer was removed. Cover live transitions and restart.

@lklimek
lklimek marked this pull request as ready for review November 27, 2026 12:41
@lklimek
lklimek marked this pull request as draft November 27, 2026 12:41
lklimek and others added 2 commits December 3, 2026 01:07
After a quorum rotation, heightProposerSelector.proposerFromStore picks
the validator at index 1, preserving historical behaviour. A validator
set with one member has no index 1, so GetByIndex returned nil and the
node crashed with a nil pointer dereference (CONSENSUS FAILURE).

Wrap the index to the set size, so a one-member set selects its only
validator and larger sets keep index 1. An empty set returns an error
instead of panicking.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Choose the proposer index by validator set size directly, so gosec
G115 has no narrowing conversion to flag.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lklimek
lklimek force-pushed the fix/consensus-single-validator-proposer branch from 18c25f2 to d306401 Compare December 3, 2026 00:07

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants