Skip to content

Commit 9ffc8c9

Browse files
authored
Merge pull request #176 from bane-labs/fix-sync
dbft: skip sealing task awaiting during node sync
2 parents d1804db + b48c9f8 commit 9ffc8c9

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

consensus/dbft/dbft.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ type DBFT struct {
183183
// various chain/mempool events and subscription management:
184184
chainHeadSub event.Subscription
185185
chainHeadEvents chan core.ChainHeadEvent
186+
// minerInterrupted is the callback indicating whether miner is temporary interrupted
187+
// due to the node sync.
188+
minerInterrupted func() bool
186189

187190
config *params.DBFTConfig // Consensus engine configuration parameters
188191

@@ -686,6 +689,12 @@ func (c *DBFT) WithRequestTxs(f func(hashed []common.Hash)) {
686689
c.requestTxs = f
687690
}
688691

692+
// WithMinerInterrupted sets callback to indicate whether miner is interrupted due
693+
// to the ongoing node sync process.
694+
func (c *DBFT) WithMinerInterrupted(f func() bool) {
695+
c.minerInterrupted = f
696+
}
697+
689698
// WithTxPool initializes transaction pool API for DBFT interactions with memory pool
690699
// (fetching unknown transactions).
691700
func (c *DBFT) WithTxPool(pool txPool) {
@@ -1412,6 +1421,13 @@ func (c *DBFT) newPayload(ctx *dbft.Context, t payload.MessageType, msg any) pay
14121421
}
14131422

14141423
func (c *DBFT) handleChainBlock(b *types.Block) error {
1424+
// A short path if miner is not active and the node is in the process of block
1425+
// sync. In this case dBFT can't react properly on the newcoming blocks since no
1426+
// sealing task is expected from miner.
1427+
if c.minerInterrupted() {
1428+
return nil
1429+
}
1430+
14151431
// We can get our own block here, so check for index.
14161432
if uint32(b.Number().Uint64()) >= c.dbft.BlockIndex {
14171433
log.Info("New block in the chain",

eth/backend.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
296296
bft.WithBroadcast(eth.dbftSrv.BroadcastMessage)
297297
bft.WithTxPool(eth.TxPool())
298298
bft.WithRequestTxs(eth.handler.BroadcastRequestTxs)
299+
bft.WithMinerInterrupted(eth.miner.Syncing)
299300
}
300301

301302
// Setup DNS discovery iterators.

miner/miner.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ func (miner *Miner) Mining() bool {
185185
return miner.worker.isRunning()
186186
}
187187

188+
// Syncing indicates whether mining is currently interrupted due to the node's Downloader work.
189+
func (miner *Miner) Syncing() bool {
190+
return miner.worker.isSyncing()
191+
}
192+
188193
func (miner *Miner) Hashrate() uint64 {
189194
if pow, ok := miner.engine.(consensus.PoW); ok {
190195
return uint64(pow.Hashrate())

miner/worker.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,12 @@ func (w *worker) isRunning() bool {
382382
return w.running.Load()
383383
}
384384

385+
// isSyncing returns an indicator whether the node is in the sync process
386+
// from the worker PoW.
387+
func (w *worker) isSyncing() bool {
388+
return w.syncing.Load()
389+
}
390+
385391
// close terminates all background threads maintained by the worker.
386392
// Note the worker does not support being closed multiple times.
387393
func (w *worker) close() {

0 commit comments

Comments
 (0)