diff --git a/core/chain_indexer.go b/core/chain_indexer.go index c0c2c4f7f9..f959c4d1e8 100644 --- a/core/chain_indexer.go +++ b/core/chain_indexer.go @@ -145,7 +145,9 @@ func (c *ChainIndexer) AddCheckpoint(section uint64, shead common.Hash) { func (c *ChainIndexer) Start(chain ChainIndexerChain) { events := make(chan ChainHeadEvent, 10) sub := chain.SubscribeChainHeadEvent(events) - + if sub == nil { + log.Crit("Failed to create chain head subscription") + } go c.eventLoop(chain.CurrentHeader(), events, sub) } diff --git a/core/tx_pool.go b/core/tx_pool.go index f7032dbd1e..6974428017 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -297,6 +297,9 @@ func NewTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain block // Subscribe events from blockchain and start the main event loop. pool.chainHeadSub = pool.chain.SubscribeChainHeadEvent(pool.chainHeadCh) + if pool.chainHeadSub == nil { + log.Crit("Failed to create chain head subscription") + } pool.wg.Add(1) go pool.loop() diff --git a/eth/enr_entry.go b/eth/enr_entry.go index d9e7b95784..6e74b83c4b 100644 --- a/eth/enr_entry.go +++ b/eth/enr_entry.go @@ -19,6 +19,7 @@ package eth import ( "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/forkid" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/rlp" ) @@ -40,7 +41,9 @@ func (e ethEntry) ENRKey() string { func (eth *Ethereum) startEthEntryUpdate(ln *enode.LocalNode) { var newHead = make(chan core.ChainHeadEvent, 10) sub := eth.blockchain.SubscribeChainHeadEvent(newHead) - + if sub == nil { + log.Crit("Failed to create chain head subscription") + } go func() { defer sub.Unsubscribe() for { diff --git a/ethstats/ethstats.go b/ethstats/ethstats.go index f9284722cf..83992df4e1 100644 --- a/ethstats/ethstats.go +++ b/ethstats/ethstats.go @@ -145,15 +145,18 @@ func (s *Service) loop() { blockchain = s.les.BlockChain() txpool = s.les.TxPool() } - chainHeadCh := make(chan core.ChainHeadEvent, chainHeadChanSize) headSub := blockchain.SubscribeChainHeadEvent(chainHeadCh) + if headSub == nil { + log.Crit("Failed to create chain head subscription") + } defer headSub.Unsubscribe() - txEventCh := make(chan core.NewTxsEvent, txChanSize) txSub := txpool.SubscribeNewTxsEvent(txEventCh) + if txSub == nil { + log.Crit("Failed to create new tx subscription") + } defer txSub.Unsubscribe() - // Start a goroutine that exhausts the subsciptions to avoid events piling up var ( quitCh = make(chan struct{}) diff --git a/les/server.go b/les/server.go index e68903dd81..fa94ace2b2 100644 --- a/les/server.go +++ b/les/server.go @@ -227,6 +227,9 @@ func (s *LesServer) capacityManagement() { processCh := make(chan bool, 100) sub := s.handler.blockchain.SubscribeBlockProcessingEvent(processCh) + if sub == nil { + log.Crit("Failed to create block processing subscription") + } defer sub.Unsubscribe() totalRechargeCh := make(chan uint64, 100) diff --git a/les/server_handler.go b/les/server_handler.go index 16249ef1ba..a7309daa00 100644 --- a/les/server_handler.go +++ b/les/server_handler.go @@ -898,6 +898,9 @@ func (h *serverHandler) broadcastHeaders() { headCh := make(chan core.ChainHeadEvent, 10) headSub := h.blockchain.SubscribeChainHeadEvent(headCh) + if headSub == nil { + log.Crit("Failed to create chain head subscription") + } defer headSub.Unsubscribe() var ( diff --git a/light/txpool.go b/light/txpool.go index 11a0e76ae0..19c90918dc 100644 --- a/light/txpool.go +++ b/light/txpool.go @@ -105,6 +105,9 @@ func NewTxPool(config *params.ChainConfig, chain *LightChain, relay TxRelayBacke } // Subscribe events from blockchain pool.chainHeadSub = pool.chain.SubscribeChainHeadEvent(pool.chainHeadCh) + if pool.chainHeadSub == nil { + log.Crit("Failed to create chain head subscription") + } go pool.eventLoop() return pool diff --git a/miner/worker.go b/miner/worker.go index 52f8919f0d..a21206d925 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -205,7 +205,9 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus // Subscribe events for blockchain worker.chainHeadSub = eth.BlockChain().SubscribeChainHeadEvent(worker.chainHeadCh) worker.chainSideSub = eth.BlockChain().SubscribeChainSideEvent(worker.chainSideCh) - + if worker.txsSub == nil || worker.chainHeadSub == nil || worker.chainSideSub == nil { + log.Crit("Failed to create subscriptions") + } // Sanitize recommit interval if the user-specified one is too short. recommit := worker.config.Recommit if recommit < minRecommitInterval {