main.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. // Copyright 2014 The go-ethereum Authors
  2. // This file is part of go-ethereum.
  3. //
  4. // go-ethereum is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU 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. // go-ethereum 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 General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
  16. // geth is the official command-line client for Ethereum.
  17. package main
  18. import (
  19. "fmt"
  20. "os"
  21. "sort"
  22. "strconv"
  23. "strings"
  24. "time"
  25. "github.com/ethereum/go-ethereum/accounts"
  26. "github.com/ethereum/go-ethereum/accounts/keystore"
  27. "github.com/ethereum/go-ethereum/accounts/pluggable"
  28. "github.com/ethereum/go-ethereum/cmd/utils"
  29. "github.com/ethereum/go-ethereum/common"
  30. "github.com/ethereum/go-ethereum/console/prompt"
  31. "github.com/ethereum/go-ethereum/eth"
  32. "github.com/ethereum/go-ethereum/eth/downloader"
  33. "github.com/ethereum/go-ethereum/ethclient"
  34. "github.com/ethereum/go-ethereum/internal/debug"
  35. "github.com/ethereum/go-ethereum/internal/ethapi"
  36. "github.com/ethereum/go-ethereum/internal/flags"
  37. "github.com/ethereum/go-ethereum/log"
  38. "github.com/ethereum/go-ethereum/metrics"
  39. "github.com/ethereum/go-ethereum/node"
  40. "github.com/ethereum/go-ethereum/permission"
  41. "github.com/ethereum/go-ethereum/plugin"
  42. "gopkg.in/urfave/cli.v1"
  43. )
  44. const (
  45. clientIdentifier = "geth" // Client identifier to advertise over the network
  46. )
  47. var (
  48. // Git SHA1 commit hash of the release (set via linker flags)
  49. gitCommit = ""
  50. gitDate = ""
  51. // The app that holds all commands and flags.
  52. app = flags.NewApp(gitCommit, gitDate, "the go-ethereum command line interface")
  53. // flags that configure the node
  54. nodeFlags = []cli.Flag{
  55. utils.IdentityFlag,
  56. utils.UnlockedAccountFlag,
  57. utils.PasswordFileFlag,
  58. utils.BootnodesFlag,
  59. utils.DataDirFlag,
  60. utils.AncientFlag,
  61. utils.MinFreeDiskSpaceFlag,
  62. utils.KeyStoreDirFlag,
  63. utils.ExternalSignerFlag,
  64. utils.NoUSBFlag,
  65. utils.USBFlag,
  66. utils.SmartCardDaemonPathFlag,
  67. utils.OverrideBerlinFlag,
  68. utils.EthashCacheDirFlag,
  69. utils.EthashCachesInMemoryFlag,
  70. utils.EthashCachesOnDiskFlag,
  71. utils.EthashCachesLockMmapFlag,
  72. utils.EthashDatasetDirFlag,
  73. utils.EthashDatasetsInMemoryFlag,
  74. utils.EthashDatasetsOnDiskFlag,
  75. utils.EthashDatasetsLockMmapFlag,
  76. utils.TxPoolLocalsFlag,
  77. utils.TxPoolNoLocalsFlag,
  78. utils.TxPoolJournalFlag,
  79. utils.TxPoolRejournalFlag,
  80. utils.TxPoolPriceLimitFlag,
  81. utils.TxPoolPriceBumpFlag,
  82. utils.TxPoolAccountSlotsFlag,
  83. utils.TxPoolGlobalSlotsFlag,
  84. utils.TxPoolAccountQueueFlag,
  85. utils.TxPoolGlobalQueueFlag,
  86. utils.TxPoolLifetimeFlag,
  87. utils.SyncModeFlag,
  88. utils.ExitWhenSyncedFlag,
  89. utils.GCModeFlag,
  90. utils.SnapshotFlag,
  91. utils.TxLookupLimitFlag,
  92. utils.LightServeFlag,
  93. utils.LightIngressFlag,
  94. utils.LightEgressFlag,
  95. utils.LightMaxPeersFlag,
  96. utils.LightNoPruneFlag,
  97. utils.LightKDFFlag,
  98. utils.UltraLightServersFlag,
  99. utils.UltraLightFractionFlag,
  100. utils.UltraLightOnlyAnnounceFlag,
  101. utils.LightNoSyncServeFlag,
  102. utils.AuthorizationListFlag,
  103. utils.BloomFilterSizeFlag,
  104. utils.CacheFlag,
  105. utils.CacheDatabaseFlag,
  106. utils.CacheTrieFlag,
  107. utils.CacheTrieJournalFlag,
  108. utils.CacheTrieRejournalFlag,
  109. utils.CacheGCFlag,
  110. utils.CacheSnapshotFlag,
  111. utils.CacheNoPrefetchFlag,
  112. utils.CachePreimagesFlag,
  113. utils.ListenPortFlag,
  114. utils.MaxPeersFlag,
  115. utils.MaxPendingPeersFlag,
  116. utils.MiningEnabledFlag,
  117. utils.MinerThreadsFlag,
  118. utils.MinerNotifyFlag,
  119. utils.MinerGasTargetFlag,
  120. utils.MinerGasLimitFlag,
  121. utils.MinerGasPriceFlag,
  122. utils.MinerEtherbaseFlag,
  123. utils.MinerExtraDataFlag,
  124. utils.MinerRecommitIntervalFlag,
  125. utils.MinerNoVerfiyFlag,
  126. utils.NATFlag,
  127. utils.NoDiscoverFlag,
  128. utils.DiscoveryV5Flag,
  129. utils.NetrestrictFlag,
  130. utils.NodeKeyFileFlag,
  131. utils.NodeKeyHexFlag,
  132. utils.DNSDiscoveryFlag,
  133. utils.MainnetFlag,
  134. utils.DeveloperFlag,
  135. utils.DeveloperPeriodFlag,
  136. utils.RopstenFlag,
  137. utils.RinkebyFlag,
  138. utils.GoerliFlag,
  139. utils.YoloV3Flag,
  140. utils.VMEnableDebugFlag,
  141. utils.NetworkIdFlag,
  142. utils.EthStatsURLFlag,
  143. utils.FakePoWFlag,
  144. utils.NoCompactionFlag,
  145. utils.GpoBlocksFlag,
  146. utils.GpoPercentileFlag,
  147. utils.GpoMaxGasPriceFlag,
  148. utils.EWASMInterpreterFlag,
  149. utils.EVMInterpreterFlag,
  150. utils.MinerNotifyFullFlag,
  151. configFileFlag,
  152. utils.CatalystFlag,
  153. // Quorum
  154. utils.QuorumImmutabilityThreshold,
  155. utils.EnableNodePermissionFlag,
  156. utils.RaftLogDirFlag,
  157. utils.RaftModeFlag,
  158. utils.RaftBlockTimeFlag,
  159. utils.RaftJoinExistingFlag,
  160. utils.RaftPortFlag,
  161. utils.RaftDNSEnabledFlag,
  162. utils.EmitCheckpointsFlag,
  163. utils.IstanbulRequestTimeoutFlag,
  164. utils.IstanbulBlockPeriodFlag,
  165. utils.PluginSettingsFlag,
  166. utils.PluginSkipVerifyFlag,
  167. utils.PluginLocalVerifyFlag,
  168. utils.PluginPublicKeyFlag,
  169. utils.AllowedFutureBlockTimeFlag,
  170. utils.EVMCallTimeOutFlag,
  171. utils.MultitenancyFlag,
  172. utils.RevertReasonFlag,
  173. utils.QuorumEnablePrivateTrieCache,
  174. utils.QuorumEnablePrivacyMarker,
  175. utils.QuorumPTMUnixSocketFlag,
  176. utils.QuorumPTMUrlFlag,
  177. utils.QuorumPTMTimeoutFlag,
  178. utils.QuorumPTMDialTimeoutFlag,
  179. utils.QuorumPTMHttpIdleTimeoutFlag,
  180. utils.QuorumPTMHttpWriteBufferSizeFlag,
  181. utils.QuorumPTMHttpReadBufferSizeFlag,
  182. utils.QuorumPTMTlsModeFlag,
  183. utils.QuorumPTMTlsRootCaFlag,
  184. utils.QuorumPTMTlsClientCertFlag,
  185. utils.QuorumPTMTlsClientKeyFlag,
  186. utils.QuorumPTMTlsInsecureSkipVerify,
  187. utils.QuorumLightServerFlag,
  188. utils.QuorumLightServerP2PListenPortFlag,
  189. utils.QuorumLightServerP2PMaxPeersFlag,
  190. utils.QuorumLightServerP2PNetrestrictFlag,
  191. utils.QuorumLightServerP2PPermissioningFlag,
  192. utils.QuorumLightServerP2PPermissioningPrefixFlag,
  193. utils.QuorumLightClientFlag,
  194. utils.QuorumLightClientPSIFlag,
  195. utils.QuorumLightClientTokenEnabledFlag,
  196. utils.QuorumLightClientTokenValueFlag,
  197. utils.QuorumLightClientTokenManagementFlag,
  198. utils.QuorumLightClientRPCTLSFlag,
  199. utils.QuorumLightClientRPCTLSInsecureSkipVerifyFlag,
  200. utils.QuorumLightClientRPCTLSCACertFlag,
  201. utils.QuorumLightClientRPCTLSCertFlag,
  202. utils.QuorumLightClientRPCTLSKeyFlag,
  203. utils.QuorumLightClientServerNodeFlag,
  204. utils.QuorumLightClientServerNodeRPCFlag,
  205. utils.QuorumLightTLSFlag,
  206. utils.QuorumLightTLSCertFlag,
  207. utils.QuorumLightTLSKeyFlag,
  208. utils.QuorumLightTLSCACertsFlag,
  209. utils.QuorumLightTLSClientAuthFlag,
  210. utils.QuorumLightTLSCipherSuitesFlag,
  211. // End-Quorum
  212. }
  213. rpcFlags = []cli.Flag{
  214. utils.HTTPEnabledFlag,
  215. utils.HTTPListenAddrFlag,
  216. utils.HTTPPortFlag,
  217. utils.HTTPCORSDomainFlag,
  218. utils.HTTPVirtualHostsFlag,
  219. utils.LegacyRPCEnabledFlag,
  220. utils.LegacyRPCListenAddrFlag,
  221. utils.LegacyRPCPortFlag,
  222. utils.LegacyRPCCORSDomainFlag,
  223. utils.LegacyRPCVirtualHostsFlag,
  224. utils.LegacyRPCApiFlag,
  225. utils.GraphQLEnabledFlag,
  226. utils.GraphQLCORSDomainFlag,
  227. utils.GraphQLVirtualHostsFlag,
  228. utils.HTTPApiFlag,
  229. utils.HTTPPathPrefixFlag,
  230. utils.WSEnabledFlag,
  231. utils.WSListenAddrFlag,
  232. utils.WSPortFlag,
  233. utils.WSApiFlag,
  234. utils.WSAllowedOriginsFlag,
  235. utils.WSPathPrefixFlag,
  236. utils.IPCDisabledFlag,
  237. utils.IPCPathFlag,
  238. utils.InsecureUnlockAllowedFlag,
  239. utils.RPCGlobalGasCapFlag,
  240. utils.RPCGlobalTxFeeCapFlag,
  241. utils.AllowUnprotectedTxs,
  242. }
  243. metricsFlags = []cli.Flag{
  244. utils.MetricsEnabledFlag,
  245. utils.MetricsEnabledExpensiveFlag,
  246. utils.MetricsHTTPFlag,
  247. utils.MetricsPortFlag,
  248. utils.MetricsEnableInfluxDBFlag,
  249. utils.MetricsInfluxDBEndpointFlag,
  250. utils.MetricsInfluxDBDatabaseFlag,
  251. utils.MetricsInfluxDBUsernameFlag,
  252. utils.MetricsInfluxDBPasswordFlag,
  253. utils.MetricsInfluxDBTagsFlag,
  254. }
  255. )
  256. func init() {
  257. // Initialize the CLI app and start Geth
  258. app.Action = geth
  259. app.HideVersion = true // we have a command to print the version
  260. app.Copyright = "Copyright 2013-2021 The go-ethereum Authors"
  261. app.Commands = []cli.Command{
  262. // See chaincmd.go:
  263. initCommand,
  264. mpsdbUpgradeCommand,
  265. importCommand,
  266. exportCommand,
  267. importPreimagesCommand,
  268. exportPreimagesCommand,
  269. removedbCommand,
  270. dumpCommand,
  271. dumpGenesisCommand,
  272. // See accountcmd.go:
  273. accountCommand,
  274. walletCommand,
  275. // See consolecmd.go:
  276. consoleCommand,
  277. attachCommand,
  278. javascriptCommand,
  279. // See misccmd.go:
  280. makecacheCommand,
  281. makedagCommand,
  282. versionCommand,
  283. versionCheckCommand,
  284. licenseCommand,
  285. // See config.go
  286. dumpConfigCommand,
  287. // see dbcmd.go
  288. dbCommand,
  289. // See cmd/utils/flags_legacy.go
  290. utils.ShowDeprecated,
  291. // See snapshot.go
  292. snapshotCommand,
  293. }
  294. sort.Sort(cli.CommandsByName(app.Commands))
  295. app.Flags = append(app.Flags, nodeFlags...)
  296. app.Flags = append(app.Flags, rpcFlags...)
  297. app.Flags = append(app.Flags, consoleFlags...)
  298. app.Flags = append(app.Flags, debug.Flags...)
  299. app.Flags = append(app.Flags, metricsFlags...)
  300. app.Before = func(ctx *cli.Context) error {
  301. return debug.Setup(ctx)
  302. }
  303. app.After = func(ctx *cli.Context) error {
  304. debug.Exit()
  305. prompt.Stdin.Close() // Resets terminal mode.
  306. return nil
  307. }
  308. }
  309. func main() {
  310. if err := app.Run(os.Args); err != nil {
  311. fmt.Fprintln(os.Stderr, err)
  312. os.Exit(1)
  313. }
  314. }
  315. // prepare manipulates memory cache allowance and setups metric system.
  316. // This function should be called before launching devp2p stack.
  317. func prepare(ctx *cli.Context) {
  318. // If we're running a known preset, log it for convenience.
  319. switch {
  320. case ctx.GlobalIsSet(utils.RopstenFlag.Name):
  321. log.Info("Starting Geth on Ropsten testnet...")
  322. case ctx.GlobalIsSet(utils.RinkebyFlag.Name):
  323. log.Info("Starting Geth on Rinkeby testnet...")
  324. case ctx.GlobalIsSet(utils.GoerliFlag.Name):
  325. log.Info("Starting Geth on Görli testnet...")
  326. case ctx.GlobalIsSet(utils.YoloV3Flag.Name):
  327. log.Info("Starting Geth on YOLOv3 testnet...")
  328. case ctx.GlobalIsSet(utils.DeveloperFlag.Name):
  329. log.Info("Starting Geth in ephemeral dev mode...")
  330. case !ctx.GlobalIsSet(utils.NetworkIdFlag.Name):
  331. log.Info("Starting Geth on Ethereum mainnet...")
  332. }
  333. // If we're a full node on mainnet without --cache specified, bump default cache allowance
  334. if ctx.GlobalString(utils.SyncModeFlag.Name) != "light" && !ctx.GlobalIsSet(utils.CacheFlag.Name) && !ctx.GlobalIsSet(utils.NetworkIdFlag.Name) {
  335. // Make sure we're not on any supported preconfigured testnet either
  336. if !ctx.GlobalIsSet(utils.RopstenFlag.Name) && !ctx.GlobalIsSet(utils.RinkebyFlag.Name) && !ctx.GlobalIsSet(utils.GoerliFlag.Name) && !ctx.GlobalIsSet(utils.DeveloperFlag.Name) {
  337. // Nope, we're really on mainnet. Bump that cache up!
  338. log.Info("Bumping default cache on mainnet", "provided", ctx.GlobalInt(utils.CacheFlag.Name), "updated", 4096)
  339. ctx.GlobalSet(utils.CacheFlag.Name, strconv.Itoa(4096))
  340. }
  341. }
  342. // If we're running a light client on any network, drop the cache to some meaningfully low amount
  343. if ctx.GlobalString(utils.SyncModeFlag.Name) == "light" && !ctx.GlobalIsSet(utils.CacheFlag.Name) {
  344. log.Info("Dropping default light client cache", "provided", ctx.GlobalInt(utils.CacheFlag.Name), "updated", 128)
  345. ctx.GlobalSet(utils.CacheFlag.Name, strconv.Itoa(128))
  346. }
  347. // Start metrics export if enabled
  348. utils.SetupMetrics(ctx)
  349. // Start system runtime metrics collection
  350. go metrics.CollectProcessMetrics(3 * time.Second)
  351. }
  352. // geth is the main entry point into the system if no special subcommand is ran.
  353. // It creates a default node based on the command line arguments and runs it in
  354. // blocking mode, waiting for it to be shut down.
  355. func geth(ctx *cli.Context) error {
  356. if args := ctx.Args(); len(args) > 0 {
  357. return fmt.Errorf("invalid command: %q", args[0])
  358. }
  359. prepare(ctx)
  360. stack, backend := makeFullNode(ctx)
  361. defer stack.Close()
  362. startNode(ctx, stack, backend)
  363. stack.Wait()
  364. return nil
  365. }
  366. // startNode boots up the system node and all registered protocols, after which
  367. // it unlocks any requested accounts, and starts the RPC/IPC interfaces and the
  368. // miner.
  369. func startNode(ctx *cli.Context, stack *node.Node, backend ethapi.Backend) {
  370. log.DoEmitCheckpoints = ctx.GlobalBool(utils.EmitCheckpointsFlag.Name)
  371. debug.Memsize.Add("node", stack)
  372. // raft mode does not support --exitwhensynced
  373. if ctx.GlobalBool(utils.ExitWhenSyncedFlag.Name) && ctx.GlobalBool(utils.RaftModeFlag.Name) {
  374. utils.Fatalf("raft consensus does not support --exitwhensynced")
  375. }
  376. // Start up the node itself
  377. utils.StartNode(ctx, stack)
  378. // Now that the plugin manager has been started we register the account plugin with the corresponding account backend. All other account management is disabled when using External Signer
  379. if !ctx.IsSet(utils.ExternalSignerFlag.Name) && stack.PluginManager().IsEnabled(plugin.AccountPluginInterfaceName) {
  380. b := stack.AccountManager().Backends(pluggable.BackendType)[0].(*pluggable.Backend)
  381. if err := stack.PluginManager().AddAccountPluginToBackend(b); err != nil {
  382. log.Error("failed to setup account plugin", "err", err)
  383. }
  384. }
  385. // Unlock any account specifically requested
  386. unlockAccounts(ctx, stack)
  387. // Register wallet event handlers to open and auto-derive wallets
  388. events := make(chan accounts.WalletEvent, 16)
  389. stack.AccountManager().Subscribe(events)
  390. // Create a client to interact with local geth node.
  391. rpcClient, err := stack.Attach()
  392. if err != nil {
  393. utils.Fatalf("Failed to attach to self: %v", err)
  394. }
  395. ethClient := ethclient.NewClient(rpcClient)
  396. // Quorum
  397. if ctx.GlobalBool(utils.MultitenancyFlag.Name) && !stack.PluginManager().IsEnabled(plugin.SecurityPluginInterfaceName) {
  398. utils.Fatalf("multitenancy requires RPC Security Plugin to be configured")
  399. }
  400. // End Quorum
  401. go func() {
  402. // Open any wallets already attached
  403. for _, wallet := range stack.AccountManager().Wallets() {
  404. if err := wallet.Open(""); err != nil {
  405. log.Warn("Failed to open wallet", "url", wallet.URL(), "err", err)
  406. }
  407. }
  408. // Listen for wallet event till termination
  409. for event := range events {
  410. switch event.Kind {
  411. case accounts.WalletArrived:
  412. if err := event.Wallet.Open(""); err != nil {
  413. log.Warn("New wallet appeared, failed to open", "url", event.Wallet.URL(), "err", err)
  414. }
  415. case accounts.WalletOpened:
  416. status, _ := event.Wallet.Status()
  417. log.Info("New wallet appeared", "url", event.Wallet.URL(), "status", status)
  418. var derivationPaths []accounts.DerivationPath
  419. if event.Wallet.URL().Scheme == "ledger" {
  420. derivationPaths = append(derivationPaths, accounts.LegacyLedgerBaseDerivationPath)
  421. }
  422. derivationPaths = append(derivationPaths, accounts.DefaultBaseDerivationPath)
  423. event.Wallet.SelfDerive(derivationPaths, ethClient)
  424. case accounts.WalletDropped:
  425. log.Info("Old wallet dropped", "url", event.Wallet.URL())
  426. event.Wallet.Close()
  427. }
  428. }
  429. }()
  430. // Spawn a standalone goroutine for status synchronization monitoring,
  431. // close the node when synchronization is complete if user required.
  432. if ctx.GlobalBool(utils.ExitWhenSyncedFlag.Name) {
  433. go func() {
  434. sub := stack.EventMux().Subscribe(downloader.DoneEvent{})
  435. defer sub.Unsubscribe()
  436. for {
  437. event := <-sub.Chan()
  438. if event == nil {
  439. continue
  440. }
  441. done, ok := event.Data.(downloader.DoneEvent)
  442. if !ok {
  443. continue
  444. }
  445. if timestamp := time.Unix(int64(done.Latest.Time), 0); time.Since(timestamp) < 10*time.Minute {
  446. log.Info("Synchronisation completed", "latestnum", done.Latest.Number, "latesthash", done.Latest.Hash(),
  447. "age", common.PrettyAge(timestamp))
  448. stack.Close()
  449. }
  450. }
  451. }()
  452. }
  453. // Quorum
  454. //
  455. // checking if permissions is enabled and staring the permissions service
  456. if stack.Config().EnableNodePermission {
  457. stack.Server().SetIsNodePermissioned(permission.IsNodePermissioned)
  458. if stack.IsPermissionEnabled() {
  459. var permissionService *permission.PermissionCtrl
  460. if err := stack.Lifecycle(&permissionService); err != nil {
  461. utils.Fatalf("Permission service not runnning: %v", err)
  462. }
  463. if err := permissionService.AfterStart(); err != nil {
  464. utils.Fatalf("Permission service post construct failure: %v", err)
  465. }
  466. }
  467. }
  468. // Start auxiliary services if enabled
  469. if ctx.GlobalBool(utils.MiningEnabledFlag.Name) || ctx.GlobalBool(utils.DeveloperFlag.Name) {
  470. // Mining only makes sense if a full Ethereum node is running
  471. if ctx.GlobalString(utils.SyncModeFlag.Name) == "light" {
  472. utils.Fatalf("Light clients do not support mining")
  473. }
  474. ethBackend, ok := backend.(*eth.EthAPIBackend)
  475. if !ok {
  476. utils.Fatalf("Ethereum service not running: %v", err)
  477. }
  478. // Set the gas price to the limits from the CLI and start mining
  479. gasprice := utils.GlobalBig(ctx, utils.MinerGasPriceFlag.Name)
  480. ethBackend.TxPool().SetGasPrice(gasprice)
  481. // start mining
  482. threads := ctx.GlobalInt(utils.MinerThreadsFlag.Name)
  483. if err := ethBackend.StartMining(threads); err != nil {
  484. utils.Fatalf("Failed to start mining: %v", err)
  485. }
  486. }
  487. // checks quorum features that depend on the ethereum service
  488. quorumValidateEthService(stack, ctx.GlobalBool(utils.RaftModeFlag.Name))
  489. }
  490. // unlockAccounts unlocks any account specifically requested.
  491. func unlockAccounts(ctx *cli.Context, stack *node.Node) {
  492. var unlocks []string
  493. inputs := strings.Split(ctx.GlobalString(utils.UnlockedAccountFlag.Name), ",")
  494. for _, input := range inputs {
  495. if trimmed := strings.TrimSpace(input); trimmed != "" {
  496. unlocks = append(unlocks, trimmed)
  497. }
  498. }
  499. // Short circuit if there is no account to unlock.
  500. if len(unlocks) == 0 {
  501. return
  502. }
  503. // If insecure account unlocking is not allowed if node's APIs are exposed to external.
  504. // Print warning log to user and skip unlocking.
  505. if !stack.Config().InsecureUnlockAllowed && stack.Config().ExtRPCEnabled() {
  506. utils.Fatalf("Account unlock with HTTP access is forbidden!")
  507. }
  508. ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
  509. passwords := utils.MakePasswordList(ctx)
  510. for i, account := range unlocks {
  511. unlockAccount(ks, account, i, passwords)
  512. }
  513. }