add DetectEquivocation rule#989
Open
HagarMeir wants to merge 2 commits into
Open
Conversation
c95fe18 to
214476e
Compare
Contributor
There was a problem hiding this comment.
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
DetectEquivocationin 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
stateand 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 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) | ||
| } |
Signed-off-by: Hagar Meir <hagar.meir@ibm.com>
Signed-off-by: Hagar Meir <hagar.meir@ibm.com>
214476e to
e03aa47
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#37