Skip to content

Commit

Permalink
Merge pull request #833 from lochjin/dev2.0_bug
Browse files Browse the repository at this point in the history
fix:stuck when exiting node
  • Loading branch information
dindinw authored Nov 23, 2024
2 parents e3fa239 + ac130ed commit 608208d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
18 changes: 15 additions & 3 deletions meerevm/meer/meerpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ func (m *MeerPool) handler() {
return
case msg := <-m.resetTemplate:
m.updateTemplate(true)
select {
case <-m.quit:
return
default:
}
msg.reply <- struct{}{}
case <-stallTicker.C:
m.handleStallSample()
Expand Down Expand Up @@ -311,10 +316,17 @@ func (m *MeerPool) ResetTemplate() error {
log.Warn(err.Error())
return err
}
log.Debug("Try to reset meer pool")
msg := &resetTemplateMsg{reply: make(chan struct{})}
m.resetTemplate <- msg
<-msg.reply
go func() {
log.Debug("Try to reset meer pool")
m.resetTemplate <- msg
}()
select {
case <-m.quit:
return errors.New("MeerPool is quit")
case <-msg.reply:

}
return nil
}

Expand Down
15 changes: 14 additions & 1 deletion services/miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"bytes"
"context"
ejson "encoding/json"
"errors"
"fmt"
"github.com/Qitmeer/qng/common/system"
"math/rand"
"net/http"
"sync"
Expand Down Expand Up @@ -463,6 +465,10 @@ out:
m.handleStallSample()

case <-m.quit:
log.Info("Miner.handler exit because of quit")
break out
case <-m.consensus.Interrupt():
log.Info("Miner.handler exit because of interrupt")
break out
}
}
Expand All @@ -485,6 +491,9 @@ cleanup:
}

func (m *Miner) updateBlockTemplate(force bool) error {
if system.InterruptRequested(m.consensus.Interrupt()) {
return errors.New("System Interruption")
}
m.Lock()
defer m.Unlock()

Expand Down Expand Up @@ -523,7 +532,11 @@ func (m *Miner) updateBlockTemplate(force bool) error {
m.stats.TotalGbts++ //gbt generates
start := time.Now().UnixMilli()
totalGbts.Update(m.stats.TotalGbts)
m.consensus.BlockChain().MeerChain().(*meer.MeerChain).MeerPool().ResetTemplate()
err := m.consensus.BlockChain().MeerChain().(*meer.MeerChain).MeerPool().ResetTemplate()
if err != nil {
log.Warn(err.Error())
return err
}
template, err := mining.NewBlockTemplate(m.policy, params.ActiveNetParams.Params, m.sigCache, m.txpool, m.timeSource, m.consensus, m.coinbaseAddress, nil, m.powType, m.coinbaseFlags)
if err != nil {
e := fmt.Errorf("Failed to create new block template: %s", err.Error())
Expand Down

0 comments on commit 608208d

Please sign in to comment.