miner, XDPoS, XDC: close chanels by owner, close XFN-41 (#1641)

This commit is contained in:
Daniel Liu 2025-11-03 17:22:31 +08:00 committed by benjamin202410
parent 013646403c
commit 5fa42ea2d0
3 changed files with 11 additions and 2 deletions

View file

@ -254,6 +254,9 @@ func XDC(ctx *cli.Context) error {
defer stack.Close()
startNode(ctx, stack, backend, cfg)
stack.Wait()
if engine, ok := backend.Engine().(*XDPoS.XDPoS); ok {
engine.Stop()
}
return nil
}

View file

@ -119,6 +119,14 @@ func New(chainConfig *params.ChainConfig, db ethdb.Database) *XDPoS {
}
}
// Stop stops the consensus engine:
// - close chanel MinePeriodCh
// - close chanel NewRoundCh
func (x *XDPoS) Stop() {
close(x.MinePeriodCh)
close(x.NewRoundCh)
}
// NewFullFaker creates an ethash consensus engine with a full fake scheme that
// accepts all blocks as valid, without checking any consensus rules whatsoever.
func NewFaker(db ethdb.Database, chainConfig *params.ChainConfig) *XDPoS {

View file

@ -277,9 +277,7 @@ func (w *worker) update() {
// timeout waiting for v1 inital value
minePeriod := 2
MinePeriodCh := w.engine.(*XDPoS.XDPoS).MinePeriodCh
defer close(MinePeriodCh)
NewRoundCh := w.engine.(*XDPoS.XDPoS).NewRoundCh
defer close(NewRoundCh)
timeout := time.NewTimer(time.Duration(minePeriod) * time.Second)
defer timeout.Stop()