Skip to content

A node that decided the carried proposal votes for it in the new view - #811

Merged
pfi79 merged 3 commits into
hyperledger:mainfrom
HagarMeir:decided-node-votes-for-carried
Dec 3, 2026
Merged

pfi79 merged 3 commits into
hyperledger:mainfrom
HagarMeir:decided-node-votes-for-carried

Conversation

@HagarMeir

@HagarMeir HagarMeir commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #807. Part of #780.

A node that already decided the in flight proposal now carries it into the new view like the others, and votes for it there, as in PBFT:

  • The view changer starts the new view at the carried proposal's sequence also when the node decided it, and writes no new view record.
  • The view doesn't verify a proposal it already decided a second time.
  • The controller doesn't deliver a decision it already has, but still removes its requests from the pool.
  • A sync that brings the decided proposal doesn't stop the view while the others are still at that sequence in it. It also keeps the in flight data that the view's votes are saved with.
  • A node that decided past the carried proposal, or decided another proposal at its sequence, doesn't carry it, and starts after its decisions. The controller never restarts the same view at an earlier sequence, but a new view can start at the carried sequence even if the old view ran past it.

Not in this PR:

Written by Claude for @HagarMeir.

🤖 Generated with Claude Code

A node that already decided the in flight proposal now carries it into
the new view like the others, and votes for it there. The controller
doesn't deliver a decision it already has, but still removes its
requests from the pool, and a sync doesn't stop the view while the
others are still at that sequence in it.

Fixes hyperledger#807.

Written by Claude for @HagarMeir.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Hagar Meir <hagar.meir@ibm.com>
@HagarMeir
HagarMeir force-pushed the decided-node-votes-for-carried branch from 4156513 to f1e206a Compare December 2, 2026 11:22
return nil, true // I already decided on the in flight proposal
v.Logger.Debugf("Node %d already decided the in flight proposal at sequence %d, and carries it to vote for it", v.SelfID, lastDecisionMD.GetLatestSequence())
decided := proposalFromProto(proposal)
return &decided, true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important: a node that carries a proposal it already decided loses that vote if it restarts. It writes no new view record, and the pre-prepare it saves at seq S is at or below its checkpoint, so PersistedState.recoverProposed treats it as committed (v.ProposalSequence > seq) and the node comes back in the new view at S+1. That is the case this PR is for: the others are still at S in the new view and need this node's vote. A restart drops the vote, and the forced nothingNew in sync doesn't apply, because startSeq is now S+1.

Scenario: node 3 decides S in view 0, carries it into view 1 and saves the pre-prepare, then crashes before it commits again. It restarts in view 1 at S+1, and nodes 1, 2 and 4 are left waiting for a quorum at S.

Fix: restore a view whose last pre-prepare is a carried proposal equal to the checkpoint at that sequence with the carried proposal, or document that the vote is best effort. Add a restart test for this case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. It's listed under "Not in this PR" in the description. I opened #812 for it, with your suggested fix.

Written by Claude for @HagarMeir.

Comment thread internal/bft/controller.go Outdated

// A node that already decided a carried proposal, in the view it was proposed in or by a sync, votes for it again in
// the view it was carried into, but doesn't deliver it twice.
if md.GetLatestSequence() < c.latestSeq() || c.decided(&d.proposal) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important: a stale decision no longer goes through MutuallyExclusiveDeliver, which used to run Synchronizer.Sync(), reset the checkpoint to the sync result and return its reconfig. It now skips delivery outright and never looks at reconfig.InLatestDecision. If the checkpoint moved past this decision (sequence below latestSeq()) and the decisions in between hold a reconfiguration that the other path didn't act on, the controller no longer closes for it.

Fix: check that every path that advances the checkpoint past a decision already handles its reconfig. If one doesn't, keep the old sync for the md.GetLatestSequence() < c.latestSeq() case, and skip only for the c.decided(&d.proposal) case, where nothing is new.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Only a decision that is the node's last decision is skipped now. A decision behind the checkpoint goes to MutuallyExclusiveDeliver as before. TestDecidedProposalIsNotDeliveredAgain covers both.

Written by Claude for @HagarMeir.

Comment thread internal/bft/view.go
func (v *View) verifyCarriedProposal(proposal types.Proposal, md *protos.ViewMetadata) ([]types.RequestInfo, error) {
// A node that already decided the carried proposal verified it then, and the application may not accept it again, for
// example because it already appended it. The node votes for it, but doesn't deliver it again (Controller.decide).
if decided, _ := v.RetrieveCheckpoint(); isLastDecision(decided, proposal) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit (optional): this early return skips more than VerifyProposal. It also skips the md.GetViewId() > v.Number check and the verification sequence check below it. Say the decided proposal changed the verification sequence (a config update). This node then accepts and votes for it again with its new verification sequence, while a node that hasn't decided it checks it against the old one.

Fix: return early only around the VerifyProposal call (use RequestsFromProposal in its place) and keep the view check after it. If skipping the verification sequence check is deliberate, say so in the comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Only VerifyProposal is skipped now, and the view and verification sequence checks still run. A new case in TestViewComplainsAboutABadCarriedProposal covers a decided proposal with another verification sequence.

Written by Claude for @HagarMeir.

Comment thread internal/bft/controller.go Outdated

// A node that already decided a carried proposal, in the view it was proposed in or by a sync, votes for it again in
// the view it was carried into, but doesn't deliver it twice.
if md.GetLatestSequence() < c.latestSeq() || c.decided(&d.proposal) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pre-existing (not from this change, not blocking): when a decision is skipped as stale (md.GetLatestSequence() < c.latestSeq()) and d.view == currView and the view isn't stopped, decide still does the view bookkeeping. It counts the decision (incrementCurrentDecisionsInView) and, on rotation, calls changeView(curr, md.GetLatestSequence()+1, ...). That restarts the view at a sequence at or below the checkpoint, so the decisions in view are over-counted and the view goes back.

Fix: return after close(d.delivered) when the decision is stale. Keep the bookkeeping only for the c.decided case of a carried proposal, where countsInView is false.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, this predates the PR, and with the fix above the stale case behaves as on main. I opened #813 for it, together with pfi79's equal-sequence case.

Written by Claude for @HagarMeir.

@pfi79 pfi79 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Additional review comments are in the inline threads.

Comment thread internal/bft/controller.go Resolved
Comment thread internal/bft/controller.go Resolved
Comment thread internal/bft/controller.go Resolved
Comment thread internal/bft/controller_carry_test.go Resolved
Comment thread internal/bft/controller_carry_test.go Resolved
Comment thread internal/bft/controller.go Resolved
Comment thread internal/bft/viewchanger.go Resolved
Skip delivery only for the node's last decision, so a decision behind
the checkpoint goes to MutuallyExclusiveDeliver as before. Keep the
carried proposal in a view that is still at its sequence, read the
checkpoint once when deciding whether to carry it, and keep the view
and verification sequence checks for a decided carried proposal.

Written by Claude for @HagarMeir.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Hagar Meir <hagar.meir@ibm.com>

@pfi79 pfi79 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review comments on the carried-proposal changes. The findings are in the inline threads.

Comment thread internal/bft/controller.go Resolved
Comment thread internal/bft/controller.go Resolved
Comment thread internal/bft/controller.go Resolved
Comment thread internal/bft/controller.go Resolved
A view that votes for its decided carried proposal is kept by a sync
only while the others are still at its sequence with that proposal.
Otherwise the node moves on to the next sequence, also when it decided
the proposal before the sync and the synchronizer has nothing newer.

Written by Claude for @HagarMeir.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Hagar Meir <hagar.meir@ibm.com>
@pfi79

pfi79 commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Major: restart loses the vote for a decided carried proposal

A node that already decided the carried proposal can carry and vote for it in the new view, but it loses that vote after restart. This is the scenario described in the unresolved review thread #811 (comment) and tracked by #812; the PR description also lists it as out of scope.

Location: internal/bft/viewchanger.go (inFlightToCarry), internal/bft/view.go / carried-proposal recovery, internal/bft/state.go (recoverProposed).

Scenario:

  1. Node 3 decides sequence S in view 0 and carries it into view 1.
  2. Node 3 saves the pre-prepare for the carried proposal in view 1, but crashes before deciding it again.
  3. After restart, the checkpoint is at S while the persisted proposed record is also at S. PersistedState.recoverProposed treats it as safely committed (v.ProposalSequence > seq, with v.ProposalSequence == S+1) and does not restore the in-flight carried proposal.
  4. Node 3 comes back in view 1 at S+1. Nodes 1,2,4 are still at S in view 1 and need node 3's vote, so the view can stall.

Why it matters: This is a liveness gap in the exact case PR #811 is fixing. The live-process vote is preserved, but a crash/restart during that window loses it.

How to verify / fix: Add a restart integration test that covers this case. A possible fix is to restore a proposed record at the checkpoint sequence as the carried in-flight proposal when it is equal to the checkpoint and valid for the current/new view, instead of treating it as safely committed.

Below is a reproducing integration test (it compiles; on current PR #811 behavior it is expected to time out before the fix):

// Copyright IBM Corp. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

package test

import (
	"strings"
	"sync"
	"sync/atomic"
	"testing"
	"time"

	"github.com/hyperledger/SmartBFT/smartbftprotos"
	"github.com/stretchr/testify/require"
	"go.uber.org/zap"
	"go.uber.org/zap/zapcore"
)

// TestRestartDecidedCarriedProposalKeepsVote reproduces the liveness gap reported in the review of PR #811
// (issue #812, unresolved review thread): a node that already decided the carried proposal in an earlier view,
// carried it into the next view and started voting for it, loses that vote on restart. After restart it comes
// back past the carried sequence, so the other nodes, which still need its vote at that sequence, wait forever.
//
// Scenario:
// node 3 decides sequence 1 in view 0; nodes 1,2,4 do not. The view changes to view 1 and all four carry the
// proposal. Node 4 is disconnected so the remaining quorum needs node 3's vote. Node 3 loses commits in view 1,
// restarts before it can decide again, and should still vote for the carried proposal after restart. Nodes 1,2,3
// should then deliver the same proposal that node 3 delivered in view 0.
func TestRestartDecidedCarriedProposalKeepsVote(t *testing.T) {
	t.Parallel()
	network := NewNetwork()
	defer network.Shutdown()

	testDir := t.TempDir()

	numberOfNodes := 4
	nodes := make([]*App, 0, numberOfNodes)
	var carried sync.WaitGroup
	carried.Add(3) // nodes 1,2,4 start view 1 with the carried proposal
	var node3Carried sync.WaitGroup
	node3Carried.Add(1)
	var restarted atomic.Bool

	for i := 1; i <= numberOfNodes; i++ {
		n := newNode(uint64(i), network, t.Name(), testDir, false, 0)
		n.Consensus.Config.SyncOnStart = false
		n.Consensus.Config.LeaderHeartbeatTimeout = 5 * time.Second
		nodes = append(nodes, n)

		id := n.ID
		var carriedOnce, node3CarriedOnce sync.Once
		n.Consensus.Logger = n.logger.Desugar().WithOptions(zap.Hooks(func(entry zapcore.Entry) error {
			if !strings.Contains(entry.Message, "starts view 1 at sequence 1 with a carried proposal") {
				return nil
			}
			if id == 3 {
				if !restarted.Load() {
					node3CarriedOnce.Do(node3Carried.Done)
				}
				return nil
			}
			carriedOnce.Do(carried.Done)
			return nil
		})).Sugar()

		switch id {
		case 3:
			// Node 3 decides in view 0, but must not decide again in view 1 before restart.
			n.LoseMessages(func(msg *smartbftprotos.Message) bool {
				return msg.GetCommit() != nil && msg.GetCommit().GetView() == 1
			})
		default:
			// Nodes 1,2,4 do not decide in view 0.
			n.LoseMessages(func(msg *smartbftprotos.Message) bool {
				return msg.GetCommit() != nil && msg.GetCommit().GetView() == 0
			})
		}
	}

	// The view data of node 3 doesn't reach the next leader, so others carry the proposal.
	nodes[2].DisconnectFrom(2)
	startNodes(nodes, network)

	nodes[0].Submit(Request{ID: "1", ClientID: "alice"})
	decidedInView0 := delivered(t, nodes[2])

	carried.Wait()
	node3Carried.Wait()

	// Keep node 4 out of the quorum: nodes 1,2 need node 3's vote in view 1.
	nodes[3].Disconnect()
	nodes[2].ConnectTo(2)

	restarted.Store(true)
	nodes[2].RestartSync(false)

	for _, n := range []*App{nodes[0], nodes[1], nodes[2]} {
		require.Equal(t, decidedInView0, delivered(t, n), "node %d decided another proposal than node 3 decided in view 0", n.ID)
	}
}

@HagarMeir

Copy link
Copy Markdown
Contributor Author

Thanks, and thanks for the test. This is tracked in #812, which is listed under "Not in this PR", and it will be the next PR, starting from your test. The fix is in the WAL restore and the controller's start, which this PR doesn't touch otherwise, so I'd like to keep it separate and keep this PR reviewable.

Written by Claude for @HagarMeir.

@pfi79
pfi79 merged commit fb0b944 into hyperledger:main Dec 3, 2026
6 checks passed
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.

A node that already decided a carried proposal doesn't vote for it in the new view

3 participants