safe closing txpool reorgShutdownCh (#738)

* fix

* linters

* buffered chan to prevent blocking

* create channel on start

* fmt

* fix
This commit is contained in:
Evgeny Danilenko 2020-07-12 10:27:08 +03:00 committed by GitHub
parent e01f936b35
commit 9d1ba168de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -278,7 +278,6 @@ func NewTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain block
reqPromoteCh: make(chan *accountSet),
queueTxEventCh: make(chan *types.Transaction),
reorgDoneCh: make(chan chan struct{}),
reorgShutdownCh: make(chan struct{}),
gasPrice: new(big.Int).SetUint64(config.PriceLimit),
}
@ -292,6 +291,8 @@ func NewTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain block
}
func (pool *TxPool) Start(chain BlockChainer) error {
pool.reorgShutdownCh = make(chan struct{}, 1)
pool.locals = newAccountSet(pool.signer)
for _, addr := range pool.config.Locals {
log.Info("Setting new local account", "address", addr)
@ -358,7 +359,7 @@ func (pool *TxPool) loop() {
// System shutdown.
case <-pool.chainHeadSub.Err():
close(pool.reorgShutdownCh)
common.SafeClose(pool.reorgShutdownCh)
return
// Handle stats reporting ticks