Skip to content

Commit

Permalink
QBFT: fix chain fork when emptyblockperiodseconds is enabled (#1669)
Browse files Browse the repository at this point in the history
Authored-by: H.HSEL <26063868+hhsel@users.noreply.github.com>
  • Loading branch information
antonydenyer authored Aug 21, 2023
1 parent 57fa403 commit 65de7ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions consensus/istanbul/qbft/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ type core struct {
backlogs map[common.Address]*prque.Prque
backlogsMu *sync.Mutex

current *roundState
handlerWg *sync.WaitGroup
current *roundState
currentMutex sync.Mutex
handlerWg *sync.WaitGroup

roundChangeSet *roundChangeSet
roundChangeTimer *time.Timer
Expand Down Expand Up @@ -116,6 +117,9 @@ func (c *core) IsCurrentProposal(blockHash common.Hash) bool {

// startNewRound starts a new round. if round equals to 0, it means to starts a new sequence
func (c *core) startNewRound(round *big.Int) {
c.currentMutex.Lock()
defer c.currentMutex.Unlock()

var logger log.Logger
if c.current == nil {
logger = c.logger.New("old.round", -1, "old.seq", 0)
Expand Down
5 changes: 5 additions & 0 deletions consensus/istanbul/qbft/core/preprepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ import (
// - extends PRE-PREPARE message with ROUND-CHANGE and PREPARE justification
// - broadcast PRE-PREPARE message to other validators
func (c *core) sendPreprepareMsg(request *Request) {
// c.current and c.valSet (checked in IsProposer()) is updated asynchronously in startNewRound(),
// need to prevent race condition with mutex
c.currentMutex.Lock()
defer c.currentMutex.Unlock()

logger := c.currentLogger(true, nil)

// If I'm the proposer and I have the same sequence with the proposal
Expand Down

0 comments on commit 65de7ae

Please sign in to comment.