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) {
|
func (c *ChainIndexer) Start(chain ChainIndexerChain) {
|
||||||
events := make(chan ChainHeadEvent, 10)
|
events := make(chan ChainHeadEvent, 10)
|
||||||
sub := chain.SubscribeChainHeadEvent(events)
|
sub := chain.SubscribeChainHeadEvent(events)
|
||||||
|
if sub == nil {
|
||||||
|
log.Crit("Failed to create chain head subscription")
|
||||||
|
}
|
||||||
go c.eventLoop(chain.CurrentHeader(), events, sub)
|
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.
|
// Subscribe events from blockchain and start the main event loop.
|
||||||
pool.chainHeadSub = pool.chain.SubscribeChainHeadEvent(pool.chainHeadCh)
|
pool.chainHeadSub = pool.chain.SubscribeChainHeadEvent(pool.chainHeadCh)
|
||||||
|
if pool.chainHeadSub == nil {
|
||||||
|
log.Crit("Failed to create chain head subscription")
|
||||||
|
}
|
||||||
pool.wg.Add(1)
|
pool.wg.Add(1)
|
||||||
go pool.loop()
|
go pool.loop()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ package eth
|
||||||
import (
|
import (
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/forkid"
|
"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/p2p/enode"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
)
|
)
|
||||||
|
|
@ -40,7 +41,9 @@ func (e ethEntry) ENRKey() string {
|
||||||
func (eth *Ethereum) startEthEntryUpdate(ln *enode.LocalNode) {
|
func (eth *Ethereum) startEthEntryUpdate(ln *enode.LocalNode) {
|
||||||
var newHead = make(chan core.ChainHeadEvent, 10)
|
var newHead = make(chan core.ChainHeadEvent, 10)
|
||||||
sub := eth.blockchain.SubscribeChainHeadEvent(newHead)
|
sub := eth.blockchain.SubscribeChainHeadEvent(newHead)
|
||||||
|
if sub == nil {
|
||||||
|
log.Crit("Failed to create chain head subscription")
|
||||||
|
}
|
||||||
go func() {
|
go func() {
|
||||||
defer sub.Unsubscribe()
|
defer sub.Unsubscribe()
|
||||||
for {
|
for {
|
||||||
|
|
|
||||||
|
|
@ -145,15 +145,18 @@ func (s *Service) loop() {
|
||||||
blockchain = s.les.BlockChain()
|
blockchain = s.les.BlockChain()
|
||||||
txpool = s.les.TxPool()
|
txpool = s.les.TxPool()
|
||||||
}
|
}
|
||||||
|
|
||||||
chainHeadCh := make(chan core.ChainHeadEvent, chainHeadChanSize)
|
chainHeadCh := make(chan core.ChainHeadEvent, chainHeadChanSize)
|
||||||
headSub := blockchain.SubscribeChainHeadEvent(chainHeadCh)
|
headSub := blockchain.SubscribeChainHeadEvent(chainHeadCh)
|
||||||
|
if headSub == nil {
|
||||||
|
log.Crit("Failed to create chain head subscription")
|
||||||
|
}
|
||||||
defer headSub.Unsubscribe()
|
defer headSub.Unsubscribe()
|
||||||
|
|
||||||
txEventCh := make(chan core.NewTxsEvent, txChanSize)
|
txEventCh := make(chan core.NewTxsEvent, txChanSize)
|
||||||
txSub := txpool.SubscribeNewTxsEvent(txEventCh)
|
txSub := txpool.SubscribeNewTxsEvent(txEventCh)
|
||||||
|
if txSub == nil {
|
||||||
|
log.Crit("Failed to create new tx subscription")
|
||||||
|
}
|
||||||
defer txSub.Unsubscribe()
|
defer txSub.Unsubscribe()
|
||||||
|
|
||||||
// Start a goroutine that exhausts the subsciptions to avoid events piling up
|
// Start a goroutine that exhausts the subsciptions to avoid events piling up
|
||||||
var (
|
var (
|
||||||
quitCh = make(chan struct{})
|
quitCh = make(chan struct{})
|
||||||
|
|
|
||||||
|
|
@ -227,6 +227,9 @@ func (s *LesServer) capacityManagement() {
|
||||||
|
|
||||||
processCh := make(chan bool, 100)
|
processCh := make(chan bool, 100)
|
||||||
sub := s.handler.blockchain.SubscribeBlockProcessingEvent(processCh)
|
sub := s.handler.blockchain.SubscribeBlockProcessingEvent(processCh)
|
||||||
|
if sub == nil {
|
||||||
|
log.Crit("Failed to create block processing subscription")
|
||||||
|
}
|
||||||
defer sub.Unsubscribe()
|
defer sub.Unsubscribe()
|
||||||
|
|
||||||
totalRechargeCh := make(chan uint64, 100)
|
totalRechargeCh := make(chan uint64, 100)
|
||||||
|
|
|
||||||
|
|
@ -898,6 +898,9 @@ func (h *serverHandler) broadcastHeaders() {
|
||||||
|
|
||||||
headCh := make(chan core.ChainHeadEvent, 10)
|
headCh := make(chan core.ChainHeadEvent, 10)
|
||||||
headSub := h.blockchain.SubscribeChainHeadEvent(headCh)
|
headSub := h.blockchain.SubscribeChainHeadEvent(headCh)
|
||||||
|
if headSub == nil {
|
||||||
|
log.Crit("Failed to create chain head subscription")
|
||||||
|
}
|
||||||
defer headSub.Unsubscribe()
|
defer headSub.Unsubscribe()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,9 @@ func NewTxPool(config *params.ChainConfig, chain *LightChain, relay TxRelayBacke
|
||||||
}
|
}
|
||||||
// Subscribe events from blockchain
|
// Subscribe events from blockchain
|
||||||
pool.chainHeadSub = pool.chain.SubscribeChainHeadEvent(pool.chainHeadCh)
|
pool.chainHeadSub = pool.chain.SubscribeChainHeadEvent(pool.chainHeadCh)
|
||||||
|
if pool.chainHeadSub == nil {
|
||||||
|
log.Crit("Failed to create chain head subscription")
|
||||||
|
}
|
||||||
go pool.eventLoop()
|
go pool.eventLoop()
|
||||||
|
|
||||||
return pool
|
return pool
|
||||||
|
|
|
||||||
|
|
@ -205,7 +205,9 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus
|
||||||
// Subscribe events for blockchain
|
// Subscribe events for blockchain
|
||||||
worker.chainHeadSub = eth.BlockChain().SubscribeChainHeadEvent(worker.chainHeadCh)
|
worker.chainHeadSub = eth.BlockChain().SubscribeChainHeadEvent(worker.chainHeadCh)
|
||||||
worker.chainSideSub = eth.BlockChain().SubscribeChainSideEvent(worker.chainSideCh)
|
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.
|
// Sanitize recommit interval if the user-specified one is too short.
|
||||||
recommit := worker.config.Recommit
|
recommit := worker.config.Recommit
|
||||||
if recommit < minRecommitInterval {
|
if recommit < minRecommitInterval {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue