aboutsummaryrefslogtreecommitdiffstats
path: root/les/server.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/server.go
parentf44046a1c6889049dbf0f9448075a43f5b280b09 (diff)
downloadgo-tangerine-2695fa2213fe5010a80970bca1078834662d5972.tar
go-tangerine-2695fa2213fe5010a80970bca1078834662d5972.tar.gz
go-tangerine-2695fa2213fe5010a80970bca1078834662d5972.tar.bz2
go-tangerine-2695fa2213fe5010a80970bca1078834662d5972.tar.lz
go-tangerine-2695fa2213fe5010a80970bca1078834662d5972.tar.xz
go-tangerine-2695fa2213fe5010a80970bca1078834662d5972.tar.zst
go-tangerine-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/server.go')
-rw-r--r--les/server.go38
1 files changed, 20 insertions, 18 deletions
diff --git a/les/server.go b/les/server.go
index a934fbf26..df98d1e3a 100644
--- a/les/server.go
+++ b/les/server.go
@@ -38,21 +38,19 @@ import (
)
type LesServer struct {
- config *eth.Config
- protocolManager *ProtocolManager
- fcManager *flowcontrol.ClientManager // nil if our node is client only
- fcCostStats *requestCostStats
- defParams *flowcontrol.ServerParams
- lesTopics []discv5.Topic
- privateKey *ecdsa.PrivateKey
- quitSync chan struct{}
-
- chtIndexer, bloomTrieIndexer *core.ChainIndexer
+ lesCommons
+
+ fcManager *flowcontrol.ClientManager // nil if our node is client only
+ fcCostStats *requestCostStats
+ defParams *flowcontrol.ServerParams
+ lesTopics []discv5.Topic
+ privateKey *ecdsa.PrivateKey
+ quitSync chan struct{}
}
func NewLesServer(eth *eth.Ethereum, config *eth.Config) (*LesServer, error) {
quitSync := make(chan struct{})
- pm, err := NewProtocolManager(eth.BlockChain().Config(), false, ServerProtocolVersions, config.NetworkId, eth.EventMux(), eth.Engine(), newPeerSet(), eth.BlockChain(), eth.TxPool(), eth.ChainDb(), nil, nil, nil, quitSync, new(sync.WaitGroup))
+ pm, err := NewProtocolManager(eth.BlockChain().Config(), false, config.NetworkId, eth.EventMux(), eth.Engine(), newPeerSet(), eth.BlockChain(), eth.TxPool(), eth.ChainDb(), nil, nil, nil, quitSync, new(sync.WaitGroup))
if err != nil {
return nil, err
}
@@ -63,13 +61,17 @@ func NewLesServer(eth *eth.Ethereum, config *eth.Config) (*LesServer, error) {
}
srv := &LesServer{
- config: config,
- protocolManager: pm,
- quitSync: quitSync,
- lesTopics: lesTopics,
- chtIndexer: light.NewChtIndexer(eth.ChainDb(), false, nil),
- bloomTrieIndexer: light.NewBloomTrieIndexer(eth.ChainDb(), false, nil),
+ lesCommons: lesCommons{
+ config: config,
+ chainDb: eth.ChainDb(),
+ chtIndexer: light.NewChtIndexer(eth.ChainDb(), false, nil),
+ bloomTrieIndexer: light.NewBloomTrieIndexer(eth.ChainDb(), false, nil),
+ protocolManager: pm,
+ },
+ quitSync: quitSync,
+ lesTopics: lesTopics,
}
+
logger := log.New()
chtV1SectionCount, _, _ := srv.chtIndexer.Sections() // indexer still uses LES/1 4k section size for backwards server compatibility
@@ -104,7 +106,7 @@ func NewLesServer(eth *eth.Ethereum, config *eth.Config) (*LesServer, error) {
}
func (s *LesServer) Protocols() []p2p.Protocol {
- return s.protocolManager.SubProtocols
+ return s.makeProtocols(ServerProtocolVersions)
}
// Start starts the LES server