@@ -95,29 +95,35 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
9595 quitSync := make (chan struct {})
9696
9797 leth := & LightEthereum {
98- config : config ,
99- chainConfig : chainConfig ,
100- chainDb : chainDb ,
101- eventMux : ctx .EventMux ,
102- peers : peers ,
103- reqDist : newRequestDistributor (peers , quitSync ),
104- accountManager : ctx .AccountManager ,
105- engine : eth .CreateConsensusEngine (ctx , chainConfig , & config .Ethash , nil , chainDb ),
106- shutdownChan : make (chan bool ),
107- networkId : config .NetworkId ,
108- bloomRequests : make (chan chan * bloombits.Retrieval ),
109- bloomIndexer : eth .NewBloomIndexer (chainDb , light .BloomTrieFrequency ),
110- chtIndexer : light .NewChtIndexer (chainDb , true ),
111- bloomTrieIndexer : light .NewBloomTrieIndexer (chainDb , true ),
98+ config : config ,
99+ chainConfig : chainConfig ,
100+ chainDb : chainDb ,
101+ eventMux : ctx .EventMux ,
102+ peers : peers ,
103+ reqDist : newRequestDistributor (peers , quitSync ),
104+ accountManager : ctx .AccountManager ,
105+ engine : eth .CreateConsensusEngine (ctx , chainConfig , & config .Ethash , nil , chainDb ),
106+ shutdownChan : make (chan bool ),
107+ networkId : config .NetworkId ,
108+ bloomRequests : make (chan chan * bloombits.Retrieval ),
109+ bloomIndexer : eth .NewBloomIndexer (chainDb , light .BloomTrieFrequency , light .HelperTrieConfirmations ),
112110 }
113111
114112 leth .relay = NewLesTxRelay (peers , leth .reqDist )
115113 leth .serverPool = newServerPool (chainDb , quitSync , & leth .wg )
116114 leth .retriever = newRetrieveManager (peers , leth .reqDist , leth .serverPool )
117- leth .odr = NewLesOdr (chainDb , leth .chtIndexer , leth .bloomTrieIndexer , leth .bloomIndexer , leth .retriever )
115+ leth .odr = NewLesOdr (chainDb , leth .retriever )
116+ leth .chtIndexer = light .NewChtIndexer (chainDb , true , leth .odr )
117+ leth .bloomTrieIndexer = light .NewBloomTrieIndexer (chainDb , true , leth .odr )
118+ leth .odr .SetIndexers (leth .chtIndexer , leth .bloomTrieIndexer , leth .bloomIndexer )
119+ // Note: NewLightChain adds the trusted checkpoint so it needs an ODR with
120+ // indexers already set but not started yet
118121 if leth .blockchain , err = light .NewLightChain (leth .odr , leth .chainConfig , leth .engine ); err != nil {
119122 return nil , err
120123 }
124+ // Note: AddChildIndexer starts the update process for the child
125+ leth .bloomIndexer .AddChildIndexer (leth .bloomTrieIndexer )
126+ leth .chtIndexer .Start (leth .blockchain )
121127 leth .bloomIndexer .Start (leth .blockchain )
122128 // Rewind the chain in case of an incompatible config upgrade.
123129 if compat , ok := genesisErr .(* params.ConfigCompatError ); ok {
@@ -242,9 +248,6 @@ func (s *LightEthereum) Stop() error {
242248 if s .chtIndexer != nil {
243249 s .chtIndexer .Close ()
244250 }
245- if s .bloomTrieIndexer != nil {
246- s .bloomTrieIndexer .Close ()
247- }
248251 s .blockchain .Stop ()
249252 s .protocolManager .Stop ()
250253 s .txPool .Stop ()
0 commit comments