backend.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. // Copyright 2014 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. // Package eth implements the Ethereum protocol.
  17. package eth
  18. import (
  19. "errors"
  20. "fmt"
  21. "math/big"
  22. "runtime"
  23. "sync"
  24. "sync/atomic"
  25. "github.com/ethereum/go-ethereum/accounts"
  26. "github.com/ethereum/go-ethereum/accounts/abi/bind"
  27. "github.com/ethereum/go-ethereum/common"
  28. "github.com/ethereum/go-ethereum/common/hexutil"
  29. "github.com/ethereum/go-ethereum/consensus"
  30. "github.com/ethereum/go-ethereum/consensus/clique"
  31. "github.com/ethereum/go-ethereum/consensus/ethash"
  32. "github.com/ethereum/go-ethereum/core"
  33. "github.com/ethereum/go-ethereum/core/bloombits"
  34. "github.com/ethereum/go-ethereum/core/rawdb"
  35. "github.com/ethereum/go-ethereum/core/types"
  36. "github.com/ethereum/go-ethereum/core/vm"
  37. "github.com/ethereum/go-ethereum/eth/downloader"
  38. "github.com/ethereum/go-ethereum/eth/filters"
  39. "github.com/ethereum/go-ethereum/eth/gasprice"
  40. "github.com/ethereum/go-ethereum/ethdb"
  41. "github.com/ethereum/go-ethereum/event"
  42. "github.com/ethereum/go-ethereum/internal/ethapi"
  43. "github.com/ethereum/go-ethereum/log"
  44. "github.com/ethereum/go-ethereum/miner"
  45. "github.com/ethereum/go-ethereum/node"
  46. "github.com/ethereum/go-ethereum/p2p"
  47. "github.com/ethereum/go-ethereum/params"
  48. "github.com/ethereum/go-ethereum/rlp"
  49. "github.com/ethereum/go-ethereum/rpc"
  50. )
  51. type LesServer interface {
  52. Start(srvr *p2p.Server)
  53. Stop()
  54. APIs() []rpc.API
  55. Protocols() []p2p.Protocol
  56. SetBloomBitsIndexer(bbIndexer *core.ChainIndexer)
  57. SetContractBackend(bind.ContractBackend)
  58. }
  59. // Ethereum implements the Ethereum full node service.
  60. type Ethereum struct {
  61. config *Config
  62. // Channel for shutting down the service
  63. shutdownChan chan bool // Channel for shutting down the Ethereum
  64. // Handlers
  65. txPool *core.TxPool
  66. blockchain *core.BlockChain
  67. protocolManager *ProtocolManager
  68. lesServer LesServer
  69. // DB interfaces
  70. chainDb ethdb.Database // Block chain database
  71. eventMux *event.TypeMux
  72. engine consensus.Engine
  73. accountManager *accounts.Manager
  74. bloomRequests chan chan *bloombits.Retrieval // Channel receiving bloom data retrieval requests
  75. bloomIndexer *core.ChainIndexer // Bloom indexer operating during block imports
  76. APIBackend *EthAPIBackend
  77. miner *miner.Miner
  78. gasPrice *big.Int
  79. etherbase common.Address
  80. networkID uint64
  81. netRPCService *ethapi.PublicNetAPI
  82. lock sync.RWMutex // Protects the variadic fields (e.g. gas price and etherbase)
  83. }
  84. func (s *Ethereum) AddLesServer(ls LesServer) {
  85. s.lesServer = ls
  86. ls.SetBloomBitsIndexer(s.bloomIndexer)
  87. }
  88. // SetClient sets a rpc client which connecting to our local node.
  89. func (s *Ethereum) SetContractBackend(backend bind.ContractBackend) {
  90. // Pass the rpc client to les server if it is enabled.
  91. if s.lesServer != nil {
  92. s.lesServer.SetContractBackend(backend)
  93. }
  94. }
  95. // New creates a new Ethereum object (including the
  96. // initialisation of the common Ethereum object)
  97. func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
  98. // Ensure configuration values are compatible and sane
  99. if config.SyncMode == downloader.LightSync {
  100. return nil, errors.New("can't run eth.Ethereum in light sync mode, use les.LightEthereum")
  101. }
  102. if !config.SyncMode.IsValid() {
  103. return nil, fmt.Errorf("invalid sync mode %d", config.SyncMode)
  104. }
  105. if config.Miner.GasPrice == nil || config.Miner.GasPrice.Cmp(common.Big0) <= 0 {
  106. log.Warn("Sanitizing invalid miner gas price", "provided", config.Miner.GasPrice, "updated", DefaultConfig.Miner.GasPrice)
  107. config.Miner.GasPrice = new(big.Int).Set(DefaultConfig.Miner.GasPrice)
  108. }
  109. if config.NoPruning && config.TrieDirtyCache > 0 {
  110. config.TrieCleanCache += config.TrieDirtyCache
  111. config.TrieDirtyCache = 0
  112. }
  113. log.Info("Allocated trie memory caches", "clean", common.StorageSize(config.TrieCleanCache)*1024*1024, "dirty", common.StorageSize(config.TrieDirtyCache)*1024*1024)
  114. // Assemble the Ethereum object
  115. chainDb, err := ctx.OpenDatabaseWithFreezer("chaindata", config.DatabaseCache, config.DatabaseHandles, config.DatabaseFreezer, "eth/db/chaindata/")
  116. if err != nil {
  117. return nil, err
  118. }
  119. chainConfig, genesisHash, genesisErr := core.SetupGenesisBlockWithOverride(chainDb, config.Genesis, config.ConstantinopleOverride)
  120. if _, ok := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !ok {
  121. return nil, genesisErr
  122. }
  123. log.Info("Initialised chain configuration", "config", chainConfig)
  124. eth := &Ethereum{
  125. config: config,
  126. chainDb: chainDb,
  127. eventMux: ctx.EventMux,
  128. accountManager: ctx.AccountManager,
  129. engine: CreateConsensusEngine(ctx, chainConfig, &config.Ethash, config.Miner.Notify, config.Miner.Noverify, chainDb),
  130. shutdownChan: make(chan bool),
  131. networkID: config.NetworkId,
  132. gasPrice: config.Miner.GasPrice,
  133. etherbase: config.Miner.Etherbase,
  134. bloomRequests: make(chan chan *bloombits.Retrieval),
  135. bloomIndexer: NewBloomIndexer(chainDb, params.BloomBitsBlocks, params.BloomConfirms),
  136. }
  137. bcVersion := rawdb.ReadDatabaseVersion(chainDb)
  138. var dbVer = "<nil>"
  139. if bcVersion != nil {
  140. dbVer = fmt.Sprintf("%d", *bcVersion)
  141. }
  142. log.Info("Initialising Ethereum protocol", "versions", ProtocolVersions, "network", config.NetworkId, "dbversion", dbVer)
  143. if !config.SkipBcVersionCheck {
  144. if bcVersion != nil && *bcVersion > core.BlockChainVersion {
  145. return nil, fmt.Errorf("database version is v%d, Geth %s only supports v%d", *bcVersion, params.VersionWithMeta, core.BlockChainVersion)
  146. } else if bcVersion == nil || *bcVersion < core.BlockChainVersion {
  147. log.Warn("Upgrade blockchain database version", "from", dbVer, "to", core.BlockChainVersion)
  148. rawdb.WriteDatabaseVersion(chainDb, core.BlockChainVersion)
  149. }
  150. }
  151. var (
  152. vmConfig = vm.Config{
  153. EnablePreimageRecording: config.EnablePreimageRecording,
  154. EWASMInterpreter: config.EWASMInterpreter,
  155. EVMInterpreter: config.EVMInterpreter,
  156. }
  157. cacheConfig = &core.CacheConfig{
  158. TrieCleanLimit: config.TrieCleanCache,
  159. TrieCleanNoPrefetch: config.NoPrefetch,
  160. TrieDirtyLimit: config.TrieDirtyCache,
  161. TrieDirtyDisabled: config.NoPruning,
  162. TrieTimeLimit: config.TrieTimeout,
  163. }
  164. )
  165. eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, chainConfig, eth.engine, vmConfig, eth.shouldPreserve)
  166. if err != nil {
  167. return nil, err
  168. }
  169. // Rewind the chain in case of an incompatible config upgrade.
  170. if compat, ok := genesisErr.(*params.ConfigCompatError); ok {
  171. log.Warn("Rewinding chain to upgrade configuration", "err", compat)
  172. eth.blockchain.SetHead(compat.RewindTo)
  173. rawdb.WriteChainConfig(chainDb, genesisHash, chainConfig)
  174. }
  175. eth.bloomIndexer.Start(eth.blockchain)
  176. if config.TxPool.Journal != "" {
  177. config.TxPool.Journal = ctx.ResolvePath(config.TxPool.Journal)
  178. }
  179. eth.txPool = core.NewTxPool(config.TxPool, chainConfig, eth.blockchain)
  180. // Permit the downloader to use the trie cache allowance during fast sync
  181. cacheLimit := cacheConfig.TrieCleanLimit + cacheConfig.TrieDirtyLimit
  182. checkpoint := config.Checkpoint
  183. if checkpoint == nil {
  184. checkpoint = params.TrustedCheckpoints[genesisHash]
  185. }
  186. if eth.protocolManager, err = NewProtocolManager(chainConfig, checkpoint, config.SyncMode, config.NetworkId, eth.eventMux, eth.txPool, eth.engine, eth.blockchain, chainDb, cacheLimit, config.Whitelist); err != nil {
  187. return nil, err
  188. }
  189. eth.miner = miner.New(eth, &config.Miner, chainConfig, eth.EventMux(), eth.engine, eth.isLocalBlock)
  190. eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))
  191. eth.APIBackend = &EthAPIBackend{ctx.ExtRPCEnabled(), eth, nil}
  192. gpoParams := config.GPO
  193. if gpoParams.Default == nil {
  194. gpoParams.Default = config.Miner.GasPrice
  195. }
  196. eth.APIBackend.gpo = gasprice.NewOracle(eth.APIBackend, gpoParams)
  197. return eth, nil
  198. }
  199. func makeExtraData(extra []byte) []byte {
  200. if len(extra) == 0 {
  201. // create default extradata
  202. extra, _ = rlp.EncodeToBytes([]interface{}{
  203. uint(params.VersionMajor<<16 | params.VersionMinor<<8 | params.VersionPatch),
  204. "geth",
  205. runtime.Version(),
  206. runtime.GOOS,
  207. })
  208. }
  209. if uint64(len(extra)) > params.MaximumExtraDataSize {
  210. log.Warn("Miner extra data exceed limit", "extra", hexutil.Bytes(extra), "limit", params.MaximumExtraDataSize)
  211. extra = nil
  212. }
  213. return extra
  214. }
  215. // CreateConsensusEngine creates the required type of consensus engine instance for an Ethereum service
  216. func CreateConsensusEngine(ctx *node.ServiceContext, chainConfig *params.ChainConfig, config *ethash.Config, notify []string, noverify bool, db ethdb.Database) consensus.Engine {
  217. // If proof-of-authority is requested, set it up
  218. if chainConfig.Clique != nil {
  219. return clique.New(chainConfig.Clique, db)
  220. }
  221. // Otherwise assume proof-of-work
  222. switch config.PowMode {
  223. case ethash.ModeFake:
  224. log.Warn("Ethash used in fake mode")
  225. return ethash.NewFaker()
  226. case ethash.ModeTest:
  227. log.Warn("Ethash used in test mode")
  228. return ethash.NewTester(nil, noverify)
  229. case ethash.ModeShared:
  230. log.Warn("Ethash used in shared mode")
  231. return ethash.NewShared()
  232. default:
  233. engine := ethash.New(ethash.Config{
  234. CacheDir: ctx.ResolvePath(config.CacheDir),
  235. CachesInMem: config.CachesInMem,
  236. CachesOnDisk: config.CachesOnDisk,
  237. DatasetDir: config.DatasetDir,
  238. DatasetsInMem: config.DatasetsInMem,
  239. DatasetsOnDisk: config.DatasetsOnDisk,
  240. }, notify, noverify)
  241. engine.SetThreads(-1) // Disable CPU mining
  242. return engine
  243. }
  244. }
  245. // APIs return the collection of RPC services the ethereum package offers.
  246. // NOTE, some of these services probably need to be moved to somewhere else.
  247. func (s *Ethereum) APIs() []rpc.API {
  248. apis := ethapi.GetAPIs(s.APIBackend)
  249. // Append any APIs exposed explicitly by the les server
  250. if s.lesServer != nil {
  251. apis = append(apis, s.lesServer.APIs()...)
  252. }
  253. // Append any APIs exposed explicitly by the consensus engine
  254. apis = append(apis, s.engine.APIs(s.BlockChain())...)
  255. // Append any APIs exposed explicitly by the les server
  256. if s.lesServer != nil {
  257. apis = append(apis, s.lesServer.APIs()...)
  258. }
  259. // Append all the local APIs and return
  260. return append(apis, []rpc.API{
  261. {
  262. Namespace: "eth",
  263. Version: "1.0",
  264. Service: NewPublicEthereumAPI(s),
  265. Public: true,
  266. }, {
  267. Namespace: "eth",
  268. Version: "1.0",
  269. Service: NewPublicMinerAPI(s),
  270. Public: true,
  271. }, {
  272. Namespace: "eth",
  273. Version: "1.0",
  274. Service: downloader.NewPublicDownloaderAPI(s.protocolManager.downloader, s.eventMux),
  275. Public: true,
  276. }, {
  277. Namespace: "miner",
  278. Version: "1.0",
  279. Service: NewPrivateMinerAPI(s),
  280. Public: false,
  281. }, {
  282. Namespace: "eth",
  283. Version: "1.0",
  284. Service: filters.NewPublicFilterAPI(s.APIBackend, false),
  285. Public: true,
  286. }, {
  287. Namespace: "admin",
  288. Version: "1.0",
  289. Service: NewPrivateAdminAPI(s),
  290. }, {
  291. Namespace: "debug",
  292. Version: "1.0",
  293. Service: NewPublicDebugAPI(s),
  294. Public: true,
  295. }, {
  296. Namespace: "debug",
  297. Version: "1.0",
  298. Service: NewPrivateDebugAPI(s),
  299. }, {
  300. Namespace: "net",
  301. Version: "1.0",
  302. Service: s.netRPCService,
  303. Public: true,
  304. },
  305. }...)
  306. }
  307. func (s *Ethereum) ResetWithGenesisBlock(gb *types.Block) {
  308. s.blockchain.ResetWithGenesisBlock(gb)
  309. }
  310. func (s *Ethereum) Etherbase() (eb common.Address, err error) {
  311. s.lock.RLock()
  312. etherbase := s.etherbase
  313. s.lock.RUnlock()
  314. if etherbase != (common.Address{}) {
  315. return etherbase, nil
  316. }
  317. if wallets := s.AccountManager().Wallets(); len(wallets) > 0 {
  318. if accounts := wallets[0].Accounts(); len(accounts) > 0 {
  319. etherbase := accounts[0].Address
  320. s.lock.Lock()
  321. s.etherbase = etherbase
  322. s.lock.Unlock()
  323. log.Info("Etherbase automatically configured", "address", etherbase)
  324. return etherbase, nil
  325. }
  326. }
  327. return common.Address{}, fmt.Errorf("etherbase must be explicitly specified")
  328. }
  329. // isLocalBlock checks whether the specified block is mined
  330. // by local miner accounts.
  331. //
  332. // We regard two types of accounts as local miner account: etherbase
  333. // and accounts specified via `txpool.locals` flag.
  334. func (s *Ethereum) isLocalBlock(block *types.Block) bool {
  335. author, err := s.engine.Author(block.Header())
  336. if err != nil {
  337. log.Warn("Failed to retrieve block author", "number", block.NumberU64(), "hash", block.Hash(), "err", err)
  338. return false
  339. }
  340. // Check whether the given address is etherbase.
  341. s.lock.RLock()
  342. etherbase := s.etherbase
  343. s.lock.RUnlock()
  344. if author == etherbase {
  345. return true
  346. }
  347. // Check whether the given address is specified by `txpool.local`
  348. // CLI flag.
  349. for _, account := range s.config.TxPool.Locals {
  350. if account == author {
  351. return true
  352. }
  353. }
  354. return false
  355. }
  356. // shouldPreserve checks whether we should preserve the given block
  357. // during the chain reorg depending on whether the author of block
  358. // is a local account.
  359. func (s *Ethereum) shouldPreserve(block *types.Block) bool {
  360. // The reason we need to disable the self-reorg preserving for clique
  361. // is it can be probable to introduce a deadlock.
  362. //
  363. // e.g. If there are 7 available signers
  364. //
  365. // r1 A
  366. // r2 B
  367. // r3 C
  368. // r4 D
  369. // r5 A [X] F G
  370. // r6 [X]
  371. //
  372. // In the round5, the inturn signer E is offline, so the worst case
  373. // is A, F and G sign the block of round5 and reject the block of opponents
  374. // and in the round6, the last available signer B is offline, the whole
  375. // network is stuck.
  376. if _, ok := s.engine.(*clique.Clique); ok {
  377. return false
  378. }
  379. return s.isLocalBlock(block)
  380. }
  381. // SetEtherbase sets the mining reward address.
  382. func (s *Ethereum) SetEtherbase(etherbase common.Address) {
  383. s.lock.Lock()
  384. s.etherbase = etherbase
  385. s.lock.Unlock()
  386. s.miner.SetEtherbase(etherbase)
  387. }
  388. // StartMining starts the miner with the given number of CPU threads. If mining
  389. // is already running, this method adjust the number of threads allowed to use
  390. // and updates the minimum price required by the transaction pool.
  391. func (s *Ethereum) StartMining(threads int) error {
  392. // Update the thread count within the consensus engine
  393. type threaded interface {
  394. SetThreads(threads int)
  395. }
  396. if th, ok := s.engine.(threaded); ok {
  397. log.Info("Updated mining threads", "threads", threads)
  398. if threads == 0 {
  399. threads = -1 // Disable the miner from within
  400. }
  401. th.SetThreads(threads)
  402. }
  403. // If the miner was not running, initialize it
  404. if !s.IsMining() {
  405. // Propagate the initial price point to the transaction pool
  406. s.lock.RLock()
  407. price := s.gasPrice
  408. s.lock.RUnlock()
  409. s.txPool.SetGasPrice(price)
  410. // Configure the local mining address
  411. eb, err := s.Etherbase()
  412. if err != nil {
  413. log.Error("Cannot start mining without etherbase", "err", err)
  414. return fmt.Errorf("etherbase missing: %v", err)
  415. }
  416. if clique, ok := s.engine.(*clique.Clique); ok {
  417. wallet, err := s.accountManager.Find(accounts.Account{Address: eb})
  418. if wallet == nil || err != nil {
  419. log.Error("Etherbase account unavailable locally", "err", err)
  420. return fmt.Errorf("signer missing: %v", err)
  421. }
  422. clique.Authorize(eb, wallet.SignData)
  423. }
  424. // If mining is started, we can disable the transaction rejection mechanism
  425. // introduced to speed sync times.
  426. atomic.StoreUint32(&s.protocolManager.acceptTxs, 1)
  427. go s.miner.Start(eb)
  428. }
  429. return nil
  430. }
  431. // StopMining terminates the miner, both at the consensus engine level as well as
  432. // at the block creation level.
  433. func (s *Ethereum) StopMining() {
  434. // Update the thread count within the consensus engine
  435. type threaded interface {
  436. SetThreads(threads int)
  437. }
  438. if th, ok := s.engine.(threaded); ok {
  439. th.SetThreads(-1)
  440. }
  441. // Stop the block creating itself
  442. s.miner.Stop()
  443. }
  444. func (s *Ethereum) IsMining() bool { return s.miner.Mining() }
  445. func (s *Ethereum) Miner() *miner.Miner { return s.miner }
  446. func (s *Ethereum) AccountManager() *accounts.Manager { return s.accountManager }
  447. func (s *Ethereum) BlockChain() *core.BlockChain { return s.blockchain }
  448. func (s *Ethereum) TxPool() *core.TxPool { return s.txPool }
  449. func (s *Ethereum) EventMux() *event.TypeMux { return s.eventMux }
  450. func (s *Ethereum) Engine() consensus.Engine { return s.engine }
  451. func (s *Ethereum) ChainDb() ethdb.Database { return s.chainDb }
  452. func (s *Ethereum) IsListening() bool { return true } // Always listening
  453. func (s *Ethereum) EthVersion() int { return int(s.protocolManager.SubProtocols[0].Version) }
  454. func (s *Ethereum) NetVersion() uint64 { return s.networkID }
  455. func (s *Ethereum) Downloader() *downloader.Downloader { return s.protocolManager.downloader }
  456. func (s *Ethereum) Synced() bool { return atomic.LoadUint32(&s.protocolManager.acceptTxs) == 1 }
  457. func (s *Ethereum) ArchiveMode() bool { return s.config.NoPruning }
  458. // Protocols implements node.Service, returning all the currently configured
  459. // network protocols to start.
  460. func (s *Ethereum) Protocols() []p2p.Protocol {
  461. if s.lesServer == nil {
  462. return s.protocolManager.SubProtocols
  463. }
  464. return append(s.protocolManager.SubProtocols, s.lesServer.Protocols()...)
  465. }
  466. // Start implements node.Service, starting all internal goroutines needed by the
  467. // Ethereum protocol implementation.
  468. func (s *Ethereum) Start(srvr *p2p.Server) error {
  469. // Start the bloom bits servicing goroutines
  470. s.startBloomHandlers(params.BloomBitsBlocks)
  471. // Start the RPC service
  472. s.netRPCService = ethapi.NewPublicNetAPI(srvr, s.NetVersion())
  473. // Figure out a max peers count based on the server limits
  474. maxPeers := srvr.MaxPeers
  475. if s.config.LightServ > 0 {
  476. if s.config.LightPeers >= srvr.MaxPeers {
  477. return fmt.Errorf("invalid peer config: light peer count (%d) >= total peer count (%d)", s.config.LightPeers, srvr.MaxPeers)
  478. }
  479. maxPeers -= s.config.LightPeers
  480. }
  481. // Start the networking layer and the light server if requested
  482. s.protocolManager.Start(maxPeers)
  483. if s.lesServer != nil {
  484. s.lesServer.Start(srvr)
  485. }
  486. return nil
  487. }
  488. // Stop implements node.Service, terminating all internal goroutines used by the
  489. // Ethereum protocol.
  490. func (s *Ethereum) Stop() error {
  491. s.bloomIndexer.Close()
  492. s.blockchain.Stop()
  493. s.engine.Close()
  494. s.protocolManager.Stop()
  495. if s.lesServer != nil {
  496. s.lesServer.Stop()
  497. }
  498. s.txPool.Stop()
  499. s.miner.Stop()
  500. s.eventMux.Stop()
  501. s.chainDb.Close()
  502. close(s.shutdownChan)
  503. return nil
  504. }