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

@ -265,21 +265,20 @@ func NewTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain block
// Create the transaction pool with its initial settings
pool := &TxPool{
config: config,
chainconfig: chainconfig,
chain: chain,
signer: types.NewEIP155Signer(chainconfig.ChainID),
pending: make(map[common.Address]*txList),
queue: make(map[common.Address]*txList),
beats: make(map[common.Address]time.Time),
all: newTxLookup(),
chainHeadCh: make(chan ChainHeadEvent, chainHeadChanSize),
reqResetCh: make(chan *txpoolResetRequest),
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),
config: config,
chainconfig: chainconfig,
chain: chain,
signer: types.NewEIP155Signer(chainconfig.ChainID),
pending: make(map[common.Address]*txList),
queue: make(map[common.Address]*txList),
beats: make(map[common.Address]time.Time),
all: newTxLookup(),
chainHeadCh: make(chan ChainHeadEvent, chainHeadChanSize),
reqResetCh: make(chan *txpoolResetRequest),
reqPromoteCh: make(chan *accountSet),
queueTxEventCh: make(chan *types.Transaction),
reorgDoneCh: make(chan chan struct{}),
gasPrice: new(big.Int).SetUint64(config.PriceLimit),
}
if config.StartOnInit {
@ -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