Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal committed Apr 10, 2024
1 parent 5b8321a commit 183b66e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 5 additions & 3 deletions consensus/polybft/polybft.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,11 +629,13 @@ func (p *Polybft) startConsensusProtocol() {
stopSequence func()
)

// check every block time * 1.5, so we don't artificially close a sequence before the actual sequence has ended properly
// check every block time * 1.5, so we don't artificially close a sequence
// before the actual sequence has ended properly
checkOffset := p.config.BlockTime
if checkOffset > 1 {
checkOffset = checkOffset / 2
checkOffset /= 2
}

checkFrequency := time.Duration(p.config.BlockTime + checkOffset)
staleChecker := newStaleSequenceCheck(p.logger, p.blockchain.CurrentHeader, checkFrequency*time.Second)

Expand Down Expand Up @@ -679,7 +681,7 @@ func (p *Polybft) startConsensusProtocol() {
}
case <-sequenceCh:
case <-p.closeCh:
p.logger.Debug("[BRE] stoping sequence", "block number", latestHeader.Number+1)
p.logger.Debug("stoping sequence", "block number", latestHeader.Number+1)
if isValidator {
stopSequence()
staleChecker.stopChecking()
Expand Down
9 changes: 8 additions & 1 deletion consensus/polybft/stale_sequence_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ type staleSequenceCheck struct {
getHeader func() *types.Header
}

func newStaleSequenceCheck(logger hclog.Logger, getHeader func() *types.Header, checkDuration time.Duration) *staleSequenceCheck {
func newStaleSequenceCheck(logger hclog.Logger,
getHeader func() *types.Header,
checkDuration time.Duration,
) *staleSequenceCheck {
return &staleSequenceCheck{
logger: logger,
currentSequence: 0,
Expand All @@ -33,14 +36,18 @@ func (s *staleSequenceCheck) startChecking() {
s.sequenceShouldStop = make(chan struct{}, 1)
s.stop = make(chan struct{})
s.stopped = make(chan struct{})

ticker := time.NewTicker(s.checkFrequency)

go func() {
defer close(s.stopped)

for {
select {
case <-s.stop:
close(s.sequenceShouldStop)
ticker.Stop()

return
case <-ticker.C:
s.checkForStaleness()
Expand Down

0 comments on commit 183b66e

Please sign in to comment.