mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-14 12:06:40 +00:00
eth,core: terminate the downloader immediately when shutdown signal is received (#32062)
Closes https://github.com/ethereum/go-ethereum/issues/32058
This commit is contained in:
parent
0ce13346ce
commit
8219bfcadd
2 changed files with 8 additions and 5 deletions
|
|
@ -278,9 +278,8 @@ type BlockChain struct {
|
||||||
txLookupLock sync.RWMutex
|
txLookupLock sync.RWMutex
|
||||||
txLookupCache *lru.Cache[common.Hash, txLookup]
|
txLookupCache *lru.Cache[common.Hash, txLookup]
|
||||||
|
|
||||||
quit chan struct{} // shutdown signal, closed in Stop.
|
stopping atomic.Bool // false if chain is running, true when stopped
|
||||||
stopping atomic.Bool // false if chain is running, true when stopped
|
procInterrupt atomic.Bool // interrupt signaler for block processing
|
||||||
procInterrupt atomic.Bool // interrupt signaler for block processing
|
|
||||||
|
|
||||||
engine consensus.Engine
|
engine consensus.Engine
|
||||||
validator Validator // Block and state validator interface
|
validator Validator // Block and state validator interface
|
||||||
|
|
@ -328,7 +327,6 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
|
||||||
db: db,
|
db: db,
|
||||||
triedb: triedb,
|
triedb: triedb,
|
||||||
triegc: prque.New[int64, common.Hash](nil),
|
triegc: prque.New[int64, common.Hash](nil),
|
||||||
quit: make(chan struct{}),
|
|
||||||
chainmu: syncx.NewClosableMutex(),
|
chainmu: syncx.NewClosableMutex(),
|
||||||
bodyCache: lru.NewCache[common.Hash, *types.Body](bodyCacheLimit),
|
bodyCache: lru.NewCache[common.Hash, *types.Body](bodyCacheLimit),
|
||||||
bodyRLPCache: lru.NewCache[common.Hash, rlp.RawValue](bodyCacheLimit),
|
bodyRLPCache: lru.NewCache[common.Hash, rlp.RawValue](bodyCacheLimit),
|
||||||
|
|
@ -1206,7 +1204,6 @@ func (bc *BlockChain) stopWithoutSaving() {
|
||||||
bc.scope.Close()
|
bc.scope.Close()
|
||||||
|
|
||||||
// Signal shutdown to all goroutines.
|
// Signal shutdown to all goroutines.
|
||||||
close(bc.quit)
|
|
||||||
bc.StopInsert()
|
bc.StopInsert()
|
||||||
|
|
||||||
// Now wait for all chain modifications to end and persistent goroutines to exit.
|
// Now wait for all chain modifications to end and persistent goroutines to exit.
|
||||||
|
|
|
||||||
|
|
@ -199,6 +199,9 @@ type BlockChain interface {
|
||||||
// InsertChain inserts a batch of blocks into the local chain.
|
// InsertChain inserts a batch of blocks into the local chain.
|
||||||
InsertChain(types.Blocks) (int, error)
|
InsertChain(types.Blocks) (int, error)
|
||||||
|
|
||||||
|
// StopInsert interrupts the inserting process.
|
||||||
|
StopInsert()
|
||||||
|
|
||||||
// InsertReceiptChain inserts a batch of blocks along with their receipts
|
// InsertReceiptChain inserts a batch of blocks along with their receipts
|
||||||
// into the local chain. Blocks older than the specified `ancientLimit`
|
// into the local chain. Blocks older than the specified `ancientLimit`
|
||||||
// are stored directly in the ancient store, while newer blocks are stored
|
// are stored directly in the ancient store, while newer blocks are stored
|
||||||
|
|
@ -634,6 +637,9 @@ func (d *Downloader) Cancel() {
|
||||||
// Terminate interrupts the downloader, canceling all pending operations.
|
// Terminate interrupts the downloader, canceling all pending operations.
|
||||||
// The downloader cannot be reused after calling Terminate.
|
// The downloader cannot be reused after calling Terminate.
|
||||||
func (d *Downloader) Terminate() {
|
func (d *Downloader) Terminate() {
|
||||||
|
// Signal to stop inserting in-flight blocks
|
||||||
|
d.blockchain.StopInsert()
|
||||||
|
|
||||||
// Close the termination channel (make sure double close is allowed)
|
// Close the termination channel (make sure double close is allowed)
|
||||||
d.quitLock.Lock()
|
d.quitLock.Lock()
|
||||||
select {
|
select {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue