Skip to content

Commit

Permalink
ibft: add round number to timeout event
Browse files Browse the repository at this point in the history
This prevents unjustified pre-prepare messages from block proposer when
it receives F+1 round-change messages before timeout.
  • Loading branch information
andrepatta committed Nov 7, 2024
1 parent 5aabcba commit 6a57978
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
5 changes: 1 addition & 4 deletions consensus/istanbul/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ func (c *core) startNewRound(round *big.Int) {
defer c.currentMutex.Unlock()
defer c.newRoundChangeTimer()

// Stop running timers
c.stopTimer()

var logger log.Logger
if c.current == nil {
logger = c.logger.New("old.round", -1, "old.seq", 0)
Expand Down Expand Up @@ -296,7 +293,7 @@ func (c *core) newRoundChangeTimer() {
c.currentLogger(true, nil).Trace("IBFT: start new ROUND-CHANGE timer", "timeout", timeout.Seconds())
c.cleanLogger.Info("[Consensus]: Start new ROUND-CHANGE timer", "timeout", timeout.Seconds())
c.roundChangeTimer = time.AfterFunc(timeout, func() {
c.sendEvent(timeoutEvent{})
c.sendEvent(timeoutEvent{round: round})
})
}

Expand Down
4 changes: 3 additions & 1 deletion consensus/istanbul/core/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ type backlogEvent struct {
msg qbfttypes.QBFTMessage
}

type timeoutEvent struct{}
type timeoutEvent struct {
round uint64
}
9 changes: 7 additions & 2 deletions consensus/istanbul/core/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,17 @@ func (c *core) handleEvents() {
// if successfully processed, we gossip message to other validators
c.backend.Gossip(c.valSet, ev.msg.Code(), data)
}
case _, ok := <-c.timeoutSub.Chan():
case event, ok := <-c.timeoutSub.Chan():
// we received a round change timeout
if !ok {
return
}
c.handleTimeoutMsg()
switch ev := event.Data.(type) {
case timeoutEvent:
if c.current != nil && c.current.Round().Uint64() == ev.round {
c.handleTimeoutMsg()
}
}
case event, ok := <-c.finalCommittedSub.Chan():
// our block proposal got committed
if !ok {
Expand Down

0 comments on commit 6a57978

Please sign in to comment.