mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
all: ensure subscription is not nil
This commit is contained in:
parent
f5a68a40bf
commit
7a335ad5d1
8 changed files with 28 additions and 6 deletions
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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{})
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue