Skip to content

add DetectEquivocation rule#989

Open
HagarMeir wants to merge 2 commits into
hyperledger:mainfrom
HagarMeir:detect-equivocation
Open

add DetectEquivocation rule#989
HagarMeir wants to merge 2 commits into
hyperledger:mainfrom
HagarMeir:detect-equivocation

Conversation

@HagarMeir

Copy link
Copy Markdown
Contributor

#37

Copilot AI 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.

Pull request overview

This PR enables and reworks the DetectEquivocation consensus state rule to rotate primaries when conflicting batch digests are observed for the same <seq, shard, primary> tuple, and adds test coverage to exercise the new behavior.

Changes:

  • Enable DetectEquivocation in the state rules pipeline and implement a digest-based equivocation detection + shard term rotation.
  • Add a helper to summarize digest/signature distribution in logs when equivocation is detected.
  • Add unit/integration tests covering equivocation scenarios in both state and higher-level consensus flows.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
node/consensus/state/state.go Enables and implements digest-based equivocation detection and shard-term rotation logic (plus logging helper).
node/consensus/state/state_test.go Adds unit tests for equivocation detection and term-rotation behavior.
node/consensus/consensus_test.go Adds consensus-level test scenarios that introduce conflicting BAF digests and validate rotation behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread node/consensus/state/state.go Outdated
Comment on lines +739 to +745
term := s.Shards[i].Term
currentPrimary := types.PartyID(term % uint64(s.N))
if currentPrimary == vote.primary {
l.Warnf("Rotating primary %d (term %d -> %d) in shard %d due to equivocation at sequence %d",
vote.primary, s.Shards[i].Term, s.Shards[i].Term+1, s.Shards[i].Shard, vote.seq)
s.Shards[i].Term++
}
Comment on lines +628 to +631
types.NewSimpleBatchAttestationFragment(types.ShardID(1), types.PartyID(1), types.BatchSequence(10), []byte{1, 1, 1}, types.PartyID(2), 0, 0, nil),
types.NewSimpleBatchAttestationFragment(types.ShardID(1), types.PartyID(1), types.BatchSequence(10), []byte{2, 2, 2}, types.PartyID(3), 0, 0, nil),
types.NewSimpleBatchAttestationFragment(types.ShardID(1), types.PartyID(1), types.BatchSequence(10), []byte{3, 3, 3}, types.PartyID(0), 0, 0, nil),
},
Comment on lines +706 to +710
// For equivocation test, we need to set the initial term so that primary 1 is the current primary
shards := []state.ShardTerm{{Shard: 1}, {Shard: 2}}
if strings.Contains(tst.name, "equivocation") {
shards = []state.ShardTerm{{Shard: 1, Term: 1}, {Shard: 2}} // Term 1 % 4 = 1 (primary 1)
}
HagarMeir added 2 commits July 6, 2026 15:41
Signed-off-by: Hagar Meir <hagar.meir@ibm.com>
Signed-off-by: Hagar Meir <hagar.meir@ibm.com>
@HagarMeir HagarMeir force-pushed the detect-equivocation branch from 214476e to e03aa47 Compare July 6, 2026 12:53
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