Skip to content

Commit

Permalink
fix(lib/grandpa): ensure finalisationEngine exits when stop channel…
Browse files Browse the repository at this point in the history
… is triggered (#3141)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>
  • Loading branch information
EclesioMeloJunior and qdm12 authored Mar 10, 2023
1 parent e85c39a commit d7f7c06
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/grandpa/finalisation.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,15 @@ func (f *finalisationEngine) Stop() (err error) {
return nil
}

var errFinalisationEngineStopped = errors.New("finalisation engine stopped")

func (f *finalisationEngine) Run() (err error) {
defer close(f.engineDone)

err = f.defineRoundVotes()
if err != nil {
if errors.Is(err, errFinalisationEngineStopped) {
return nil
} else if err != nil {
return fmt.Errorf("defining round votes: %w", err)
}

Expand All @@ -360,7 +364,7 @@ func (f *finalisationEngine) Run() (err error) {
return nil
}

func (f *finalisationEngine) defineRoundVotes() error {
func (f *finalisationEngine) defineRoundVotes() (err error) {
gossipInterval := f.grandpaService.interval
determinePrevoteTimer := time.NewTimer(2 * gossipInterval)
determinePrecommitTimer := time.NewTimer(4 * gossipInterval)
Expand All @@ -372,7 +376,7 @@ func (f *finalisationEngine) defineRoundVotes() error {
case <-f.stopCh:
determinePrevoteTimer.Stop()
determinePrecommitTimer.Stop()
return nil
return fmt.Errorf("%w", errFinalisationEngineStopped)

case <-determinePrevoteTimer.C:
alreadyCompletable, err := f.grandpaService.checkRoundCompletable()
Expand Down

0 comments on commit d7f7c06

Please sign in to comment.