Repository navigation
A node that decided the carried proposal votes for it in the new view - #811
Conversation
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>
4156513 to
f1e206a
Compare
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
|
||
| // 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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| 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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
|
||
| // 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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
Additional review comments are in the inline threads.
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
left a comment
There was a problem hiding this comment.
Review comments on the carried-proposal changes. The findings are in the inline threads.
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>
Major: restart loses the vote for a decided carried proposalA 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: Scenario:
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)
}
} |
|
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. |
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:
Not in this PR:
decidedoes the view bookkeeping for a decision it doesn't deliver (decidedoes the view bookkeeping for a decision it doesn't deliver #813). This predates this PR.Written by Claude for @HagarMeir.
🤖 Generated with Claude Code