aboutsummaryrefslogtreecommitdiffstats
path: root/les/backend.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@users.noreply.github.com>2018-08-17 18:21:53 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-08-17 18:21:53 +0800
commit2695fa2213fe5010a80970bca1078834662d5972 (patch)
treec6bda44cc6c86c378f6717b3d896ac339360e9d3 /les/backend.go
parentf44046a1c6889049dbf0f9448075a43f5b280b09 (diff)
downloaddexon-2695fa2213fe5010a80970bca1078834662d5972.tar
dexon-2695fa2213fe5010a80970bca1078834662d5972.tar.gz
dexon-2695fa2213fe5010a80970bca1078834662d5972.tar.bz2
dexon-2695fa2213fe5010a80970bca1078834662d5972.tar.lz
dexon-2695fa2213fe5010a80970bca1078834662d5972.tar.xz
dexon-2695fa2213fe5010a80970bca1078834662d5972.tar.zst
dexon-2695fa2213fe5010a80970bca1078834662d5972.zip
les: fix crasher in NodeInfo when running as server (#17419)
* les: fix crasher in NodeInfo when running as server The ProtocolManager computes CHT and Bloom trie roots by asking the indexers for their current head. It tried to get the indexers from LesOdr, but no LesOdr instance is created in server mode. Attempt to fix this by moving the indexers, protocol creation and NodeInfo to a new lesCommons struct which is embedded into both server and client. All this setup code should really be cleaned up, but this is just a hotfix so we have to do that some other time. * les: fix commons protocol maker
Diffstat (limited to 'les/backend.go')
-rw-r--r--les/backend.go48
1 files changed, 23 insertions, 25 deletions
diff --git a/les/backend.go b/les/backend.go
index 9b8cc1828..d26c1470f 100644
--- a/les/backend.go
+++ b/les/backend.go
@@ -34,7 +34,6 @@ import (
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/filters"
"github.com/ethereum/go-ethereum/eth/gasprice"
- "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/ethereum/go-ethereum/light"
@@ -47,26 +46,24 @@ import (
)
type LightEthereum struct {
- config *eth.Config
+ lesCommons
odr *LesOdr
relay *LesTxRelay
chainConfig *params.ChainConfig
// Channel for shutting down the service
shutdownChan chan bool
+
// Handlers
- peers *peerSet
- txPool *light.TxPool
- blockchain *light.LightChain
- protocolManager *ProtocolManager
- serverPool *serverPool
- reqDist *requestDistributor
- retriever *retrieveManager
- // DB interfaces
- chainDb ethdb.Database // Block chain database
-
- bloomRequests chan chan *bloombits.Retrieval // Channel receiving bloom data retrieval requests
- bloomIndexer, chtIndexer, bloomTrieIndexer *core.ChainIndexer
+ peers *peerSet
+ txPool *light.TxPool
+ blockchain *light.LightChain
+ serverPool *serverPool
+ reqDist *requestDistributor
+ retriever *retrieveManager
+
+ bloomRequests chan chan *bloombits.Retrieval // Channel receiving bloom data retrieval requests
+ bloomIndexer *core.ChainIndexer
ApiBackend *LesApiBackend
@@ -95,9 +92,11 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
quitSync := make(chan struct{})
leth := &LightEthereum{
- config: config,
+ lesCommons: lesCommons{
+ chainDb: chainDb,
+ config: config,
+ },
chainConfig: chainConfig,
- chainDb: chainDb,
eventMux: ctx.EventMux,
peers: peers,
reqDist: newRequestDistributor(peers, quitSync),
@@ -112,10 +111,12 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
leth.relay = NewLesTxRelay(peers, leth.reqDist)
leth.serverPool = newServerPool(chainDb, quitSync, &leth.wg)
leth.retriever = newRetrieveManager(peers, leth.reqDist, leth.serverPool)
+
leth.odr = NewLesOdr(chainDb, leth.retriever)
leth.chtIndexer = light.NewChtIndexer(chainDb, true, leth.odr)
leth.bloomTrieIndexer = light.NewBloomTrieIndexer(chainDb, true, leth.odr)
leth.odr.SetIndexers(leth.chtIndexer, leth.bloomTrieIndexer, leth.bloomIndexer)
+
// Note: NewLightChain adds the trusted checkpoint so it needs an ODR with
// indexers already set but not started yet
if leth.blockchain, err = light.NewLightChain(leth.odr, leth.chainConfig, leth.engine); err != nil {
@@ -125,6 +126,7 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
leth.bloomIndexer.AddChildIndexer(leth.bloomTrieIndexer)
leth.chtIndexer.Start(leth.blockchain)
leth.bloomIndexer.Start(leth.blockchain)
+
// Rewind the chain in case of an incompatible config upgrade.
if compat, ok := genesisErr.(*params.ConfigCompatError); ok {
log.Warn("Rewinding chain to upgrade configuration", "err", compat)
@@ -133,7 +135,7 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
}
leth.txPool = light.NewTxPool(leth.chainConfig, leth.blockchain, leth.relay)
- if leth.protocolManager, err = NewProtocolManager(leth.chainConfig, true, ClientProtocolVersions, config.NetworkId, leth.eventMux, leth.engine, leth.peers, leth.blockchain, nil, chainDb, leth.odr, leth.relay, leth.serverPool, quitSync, &leth.wg); err != nil {
+ if leth.protocolManager, err = NewProtocolManager(leth.chainConfig, true, config.NetworkId, leth.eventMux, leth.engine, leth.peers, leth.blockchain, nil, chainDb, leth.odr, leth.relay, leth.serverPool, quitSync, &leth.wg); err != nil {
return nil, err
}
leth.ApiBackend = &LesApiBackend{leth, nil}
@@ -215,14 +217,14 @@ func (s *LightEthereum) ResetWithGenesisBlock(gb *types.Block) {
func (s *LightEthereum) BlockChain() *light.LightChain { return s.blockchain }
func (s *LightEthereum) TxPool() *light.TxPool { return s.txPool }
func (s *LightEthereum) Engine() consensus.Engine { return s.engine }
-func (s *LightEthereum) LesVersion() int { return int(s.protocolManager.SubProtocols[0].Version) }
+func (s *LightEthereum) LesVersion() int { return int(ClientProtocolVersions[0]) }
func (s *LightEthereum) Downloader() *downloader.Downloader { return s.protocolManager.downloader }
func (s *LightEthereum) EventMux() *event.TypeMux { return s.eventMux }
// Protocols implements node.Service, returning all the currently configured
// network protocols to start.
func (s *LightEthereum) Protocols() []p2p.Protocol {
- return s.protocolManager.SubProtocols
+ return s.makeProtocols(ClientProtocolVersions)
}
// Start implements node.Service, starting all internal goroutines needed by the
@@ -242,12 +244,8 @@ func (s *LightEthereum) Start(srvr *p2p.Server) error {
// Ethereum protocol.
func (s *LightEthereum) Stop() error {
s.odr.Stop()
- if s.bloomIndexer != nil {
- s.bloomIndexer.Close()
- }
- if s.chtIndexer != nil {
- s.chtIndexer.Close()
- }
+ s.bloomIndexer.Close()
+ s.chtIndexer.Close()
s.blockchain.Stop()
s.protocolManager.Stop()
s.txPool.Stop()