Skip to content

Commit

Permalink
Remove redundant vote processing of piggybacked vote
Browse files Browse the repository at this point in the history
Votes from the block proposer are piggybacked by the block message.
The current code verifies them twice, so I removed the redundant processing.

Signed-off-by: Yacov Manevich <[email protected]>
  • Loading branch information
yacovm committed Jan 28, 2025
1 parent 6a0721b commit 66d34b2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 10 additions & 4 deletions epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,13 @@ func (e *Epoch) maybeCollectNotarization() error {
return nil
}

from := make([]NodeID, 0, voteCount)
for _, vote := range votesForCurrentRound {
from = append(from, vote.Signature.Signer)
}
e.Logger.Verbo("Counting votes", zap.Uint64("round", e.round),
zap.Int("votes", voteCount), zap.String("from", fmt.Sprintf("%s", from)))

// TODO: store votes before receiving the block

block := e.rounds[e.round].block
Expand Down Expand Up @@ -996,7 +1003,7 @@ func (e *Epoch) createBlockVerificationTask(block Block, from NodeID, vote Vote)
}
round.votes[string(vote.Signature.Signer)] = &vote

if err := e.doProposed(block, vote, from); err != nil {
if err := e.doProposed(block); err != nil {
e.Logger.Warn("Failed voting on block", zap.Error(err))
}

Expand Down Expand Up @@ -1237,7 +1244,7 @@ func (e *Epoch) startRound() error {
return e.handleBlockMessage(msgsForRound.proposal, leaderForCurrentRound)
}

func (e *Epoch) doProposed(block Block, voteFromLeader Vote, from NodeID) error {
func (e *Epoch) doProposed(block Block) error {
vote, err := e.voteOnBlock(block)
if err != nil {
return err
Expand All @@ -1260,8 +1267,7 @@ func (e *Epoch) doProposed(block Block, voteFromLeader Vote, from NodeID) error
if err := e.handleVoteMessage(&vote, e.ID); err != nil {
return err
}

return e.handleVoteMessage(&voteFromLeader, e.ID)
return nil
}

func (e *Epoch) voteOnBlock(block Block) (Vote, error) {
Expand Down
4 changes: 4 additions & 0 deletions epoch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ func notarizeAndFinalizeRound(t *testing.T, nodes []NodeID, round uint64, e *Epo

// start at one since our node has already voted
for i := 1; i < quorum; i++ {
// Skip the vote of the block proposer
if leader.Equals(nodes[i]) {
continue
}
injectTestVote(t, e, block, nodes[i])
}

Expand Down

0 comments on commit 66d34b2

Please sign in to comment.