Skip to content

Commit

Permalink
Don't send more commits upon second triggering of prepare quorum (#322)
Browse files Browse the repository at this point in the history
* hasQuorumBefore

* fix test

* tests.json
  • Loading branch information
GalRogozinski authored Dec 12, 2023
1 parent b83ee23 commit 375a276
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 30 deletions.
18 changes: 0 additions & 18 deletions qbft/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,6 @@ func aggregateCommitMsgs(msgs []*SignedMessage, fullData []byte) (*SignedMessage
return ret, nil
}

// didSendCommitForHeightAndRound returns true if sent commit msg for specific Height and round
/**
!exists m :: && m in current.messagesReceived
&& m.Commit?
&& var uPayload := m.commitPayload.unsignedPayload;
&& uPayload.Height == |current.blockchain|
&& uPayload.round == current.round
&& recoverSignedCommitAuthor(m.commitPayload) == current.id
*/
func didSendCommitForHeightAndRound(state *State, commitMsgContainer *MsgContainer) bool {
for _, msg := range commitMsgContainer.MessagesForRound(state.Round) {
if msg.MatchedSigners([]types.OperatorID{state.Share.OperatorID}) {
return true
}
}
return false
}

// CreateCommit
/**
Commit(
Expand Down
2 changes: 1 addition & 1 deletion qbft/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (i *Instance) ProcessMsg(msg *SignedMessage) (decided bool, decidedValue []
case ProposalMsgType:
return i.uponProposal(msg, i.State.ProposeContainer)
case PrepareMsgType:
return i.uponPrepare(msg, i.State.PrepareContainer, i.State.CommitContainer)
return i.uponPrepare(msg, i.State.PrepareContainer)
case CommitMsgType:
decided, decidedValue, aggregatedCommit, err = i.UponCommit(msg, i.State.CommitContainer)
if decided {
Expand Down
14 changes: 6 additions & 8 deletions qbft/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import (

// uponPrepare process prepare message
// Assumes prepare message is valid!
func (i *Instance) uponPrepare(
signedPrepare *SignedMessage,
prepareMsgContainer,
commitMsgContainer *MsgContainer) error {
func (i *Instance) uponPrepare(signedPrepare *SignedMessage, prepareMsgContainer *MsgContainer) error {
hasQuorumBefore := HasQuorum(i.State.Share, prepareMsgContainer.MessagesForRound(i.State.Round))

addedMsg, err := prepareMsgContainer.AddFirstMsgForSignerAndRound(signedPrepare)
if err != nil {
Expand All @@ -21,12 +19,12 @@ func (i *Instance) uponPrepare(
return nil // uponPrepare was already called
}

if !HasQuorum(i.State.Share, prepareMsgContainer.MessagesForRound(i.State.Round)) {
return nil // no quorum yet
if hasQuorumBefore {
return nil // already moved to commit stage
}

if didSendCommitForHeightAndRound(i.State, commitMsgContainer) {
return nil // already moved to commit stage
if !HasQuorum(i.State.Share, prepareMsgContainer.MessagesForRound(i.State.Round)) {
return nil // no quorum yet
}

proposedRoot := i.State.ProposalAcceptedForCurrentRound.Message.Root
Expand Down
2 changes: 1 addition & 1 deletion qbft/spectest/generate/tests.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ func PrepareQuorumTriggeredTwiceLateCommit() tests.SpecTest {
OutputMessages: []*qbft.SignedMessage{
testingutils.TestingPrepareMessage(ks.Shares[1], 1),
testingutils.TestingCommitMessage(ks.Shares[1], 1),
// ISSUE 214: we should have only commit broadcasted
testingutils.TestingCommitMessage(ks.Shares[1], 1),
},
}
}

0 comments on commit 375a276

Please sign in to comment.