Skip to content

Commit b48c9f8

Browse files
committed
dbft: skip sealing task awaiting during node sync
If node is stale and far behind its peers, mining is aborted by the signal of Downloader. If mining is aborted, then sealing task won't be submitted to the consensus engine, and thus, dBFT awaiting for sealing task may hang forever in case of multiple block batch processing by Downloader. It may happen because dBFT's block notificaiton channel has buffer size of 2 and block notification processing is managed by the same eventLoop as sealing tasks awaiting. So dBFT blocks notifications processing by sealing task awaiting, and thus, blocks the whole chain from the further sync process: ``` 2024-04-18T10:26:44.856+0300 DEBUG [email protected]/dbft.go:229 caching message from future {"height": 6470, "view": 0, "cache": {}} 2024-04-18T10:26:45.264+0300 DEBUG [email protected]/dbft.go:214 received message {"type": "Commit", "from": 4, "height": 6470, "view": 0, "my_height": 1, "my_view": 0} 2024-04-18T10:26:45.265+0300 DEBUG [email protected]/dbft.go:229 caching message from future {"height": 6470, "view": 0, "cache": {}} INFO [04-18|10:26:50.148] Imported new chain segment number=192 hash=775270..7b8b06 blocks=192 txs=0 mgas=0.000 elapsed=562.005ms mgasps=0.000 age=19h32m52s triedirty=0.00B INFO [04-18|10:26:50.149] New block in the chain "dbft index"=1 "chain index"=192 hash=0x77527025ea64a0ceb26235efaf6ddc5430d0e2de15757869da2e90a1c57b8b06 "parent hash"=0xa9cde87fe65f34bf1f40982015e1a7e73b117a80fadf707b0deda67a34855092 primary=3 coinbase=0x1212000000000000000000000000000000000003 "mix digest"=0x23c10fa9c1fae49f6139db9c3ecff715de101c145e56e4d390a16e67d5c32e1b INFO [04-18|10:26:50.149] Fetching latest sealing proposal "desired number"=193 INFO [04-18|10:26:50.152] Indexed transactions blocks=193 txs=0 tail=0 elapsed=3.786ms INFO [04-18|10:26:50.770] Imported new chain segment number=384 hash=a5dac5..02375b blocks=192 txs=0 mgas=0.000 elapsed=472.546ms mgasps=0.000 age=18h57m12s triedirty=0.00B INFO [04-18|10:26:51.344] Imported new chain segment number=576 hash=1d8a8e..3e8def blocks=192 txs=0 mgas=0.000 elapsed=570.798ms mgasps=0.000 age=18h21m29s triedirty=0.00B INFO [04-18|10:26:52.221] Imported new chain segment number=960 hash=6fde0c..d75d78 blocks=384 txs=0 mgas=0.000 elapsed=868.154ms mgasps=0.000 age=17h10m6s triedirty=0.00B INFO [04-18|10:27:07.683] Looking for peers peercount=1 tried=1 static=0 ``` To fix this problem we have to omit block notifications processing until the node sync process end, i.e. util the moment miner resumes its work. Signed-off-by: Anna Shaleva <[email protected]>
1 parent 68e620e commit b48c9f8

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)