chaincmd.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. // Copyright 2015 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. package main
  17. import (
  18. "encoding/json"
  19. "fmt"
  20. "os"
  21. "path/filepath"
  22. "runtime"
  23. "strconv"
  24. "sync/atomic"
  25. "time"
  26. "github.com/ethereum/go-ethereum/cmd/utils"
  27. "github.com/ethereum/go-ethereum/common"
  28. "github.com/ethereum/go-ethereum/console/prompt"
  29. "github.com/ethereum/go-ethereum/core"
  30. "github.com/ethereum/go-ethereum/core/rawdb"
  31. "github.com/ethereum/go-ethereum/core/state"
  32. "github.com/ethereum/go-ethereum/core/types"
  33. "github.com/ethereum/go-ethereum/eth/downloader"
  34. "github.com/ethereum/go-ethereum/event"
  35. "github.com/ethereum/go-ethereum/log"
  36. "github.com/ethereum/go-ethereum/metrics"
  37. "github.com/ethereum/go-ethereum/trie"
  38. "gopkg.in/urfave/cli.v1"
  39. )
  40. var (
  41. initCommand = cli.Command{
  42. Action: utils.MigrateFlags(initGenesis),
  43. Name: "init",
  44. Usage: "Bootstrap and initialize a new genesis block",
  45. ArgsUsage: "<genesisPath>",
  46. Flags: []cli.Flag{
  47. utils.DataDirFlag,
  48. },
  49. Category: "BLOCKCHAIN COMMANDS",
  50. Description: `
  51. The init command initializes a new genesis block and definition for the network.
  52. This is a destructive action and changes the network in which you will be
  53. participating.
  54. It expects the genesis file as argument.`,
  55. }
  56. dumpGenesisCommand = cli.Command{
  57. Action: utils.MigrateFlags(dumpGenesis),
  58. Name: "dumpgenesis",
  59. Usage: "Dumps genesis block JSON configuration to stdout",
  60. ArgsUsage: "",
  61. Flags: []cli.Flag{
  62. utils.DataDirFlag,
  63. },
  64. Category: "BLOCKCHAIN COMMANDS",
  65. Description: `
  66. The dumpgenesis command dumps the genesis block configuration in JSON format to stdout.`,
  67. }
  68. importCommand = cli.Command{
  69. Action: utils.MigrateFlags(importChain),
  70. Name: "import",
  71. Usage: "Import a blockchain file",
  72. ArgsUsage: "<filename> (<filename 2> ... <filename N>) ",
  73. Flags: []cli.Flag{
  74. utils.DataDirFlag,
  75. utils.CacheFlag,
  76. utils.SyncModeFlag,
  77. utils.GCModeFlag,
  78. utils.SnapshotFlag,
  79. utils.CacheDatabaseFlag,
  80. utils.CacheGCFlag,
  81. utils.MetricsEnabledFlag,
  82. utils.MetricsEnabledExpensiveFlag,
  83. utils.MetricsHTTPFlag,
  84. utils.MetricsPortFlag,
  85. utils.MetricsEnableInfluxDBFlag,
  86. utils.MetricsInfluxDBEndpointFlag,
  87. utils.MetricsInfluxDBDatabaseFlag,
  88. utils.MetricsInfluxDBUsernameFlag,
  89. utils.MetricsInfluxDBPasswordFlag,
  90. utils.MetricsInfluxDBTagsFlag,
  91. utils.TxLookupLimitFlag,
  92. },
  93. Category: "BLOCKCHAIN COMMANDS",
  94. Description: `
  95. The import command imports blocks from an RLP-encoded form. The form can be one file
  96. with several RLP-encoded blocks, or several files can be used.
  97. If only one file is used, import error will result in failure. If several files are used,
  98. processing will proceed even if an individual RLP-file import failure occurs.`,
  99. }
  100. exportCommand = cli.Command{
  101. Action: utils.MigrateFlags(exportChain),
  102. Name: "export",
  103. Usage: "Export blockchain into file",
  104. ArgsUsage: "<filename> [<blockNumFirst> <blockNumLast>]",
  105. Flags: []cli.Flag{
  106. utils.DataDirFlag,
  107. utils.CacheFlag,
  108. utils.SyncModeFlag,
  109. },
  110. Category: "BLOCKCHAIN COMMANDS",
  111. Description: `
  112. Requires a first argument of the file to write to.
  113. Optional second and third arguments control the first and
  114. last block to write. In this mode, the file will be appended
  115. if already existing. If the file ends with .gz, the output will
  116. be gzipped.`,
  117. }
  118. importPreimagesCommand = cli.Command{
  119. Action: utils.MigrateFlags(importPreimages),
  120. Name: "import-preimages",
  121. Usage: "Import the preimage database from an RLP stream",
  122. ArgsUsage: "<datafile>",
  123. Flags: []cli.Flag{
  124. utils.DataDirFlag,
  125. utils.CacheFlag,
  126. utils.SyncModeFlag,
  127. },
  128. Category: "BLOCKCHAIN COMMANDS",
  129. Description: `
  130. The import-preimages command imports hash preimages from an RLP encoded stream.`,
  131. }
  132. exportPreimagesCommand = cli.Command{
  133. Action: utils.MigrateFlags(exportPreimages),
  134. Name: "export-preimages",
  135. Usage: "Export the preimage database into an RLP stream",
  136. ArgsUsage: "<dumpfile>",
  137. Flags: []cli.Flag{
  138. utils.DataDirFlag,
  139. utils.CacheFlag,
  140. utils.SyncModeFlag,
  141. },
  142. Category: "BLOCKCHAIN COMMANDS",
  143. Description: `
  144. The export-preimages command export hash preimages to an RLP encoded stream`,
  145. }
  146. copydbCommand = cli.Command{
  147. Action: utils.MigrateFlags(copyDb),
  148. Name: "copydb",
  149. Usage: "Create a local chain from a target chaindata folder",
  150. ArgsUsage: "<sourceChaindataDir>",
  151. Flags: []cli.Flag{
  152. utils.DataDirFlag,
  153. utils.CacheFlag,
  154. utils.SyncModeFlag,
  155. utils.FakePoWFlag,
  156. utils.MainnetFlag,
  157. utils.RopstenFlag,
  158. utils.RinkebyFlag,
  159. utils.TxLookupLimitFlag,
  160. utils.GoerliFlag,
  161. utils.YoloV3Flag,
  162. utils.LegacyTestnetFlag,
  163. },
  164. Category: "BLOCKCHAIN COMMANDS",
  165. Description: `
  166. The first argument must be the directory containing the blockchain to download from`,
  167. }
  168. removedbCommand = cli.Command{
  169. Action: utils.MigrateFlags(removeDB),
  170. Name: "removedb",
  171. Usage: "Remove blockchain and state databases",
  172. ArgsUsage: " ",
  173. Flags: []cli.Flag{
  174. utils.DataDirFlag,
  175. },
  176. Category: "BLOCKCHAIN COMMANDS",
  177. Description: `
  178. Remove blockchain and state databases`,
  179. }
  180. dumpCommand = cli.Command{
  181. Action: utils.MigrateFlags(dump),
  182. Name: "dump",
  183. Usage: "Dump a specific block from storage",
  184. ArgsUsage: "[<blockHash> | <blockNum>]...",
  185. Flags: []cli.Flag{
  186. utils.DataDirFlag,
  187. utils.CacheFlag,
  188. utils.SyncModeFlag,
  189. utils.IterativeOutputFlag,
  190. utils.ExcludeCodeFlag,
  191. utils.ExcludeStorageFlag,
  192. utils.IncludeIncompletesFlag,
  193. },
  194. Category: "BLOCKCHAIN COMMANDS",
  195. Description: `
  196. The arguments are interpreted as block numbers or hashes.
  197. Use "ethereum dump 0" to dump the genesis block.`,
  198. }
  199. inspectCommand = cli.Command{
  200. Action: utils.MigrateFlags(inspect),
  201. Name: "inspect",
  202. Usage: "Inspect the storage size for each type of data in the database",
  203. ArgsUsage: " ",
  204. Flags: []cli.Flag{
  205. utils.DataDirFlag,
  206. utils.AncientFlag,
  207. utils.CacheFlag,
  208. utils.MainnetFlag,
  209. utils.RopstenFlag,
  210. utils.RinkebyFlag,
  211. utils.GoerliFlag,
  212. utils.YoloV3Flag,
  213. utils.LegacyTestnetFlag,
  214. utils.SyncModeFlag,
  215. },
  216. Category: "BLOCKCHAIN COMMANDS",
  217. }
  218. )
  219. // initGenesis will initialise the given JSON format genesis file and writes it as
  220. // the zero'd block (i.e. genesis) or will fail hard if it can't succeed.
  221. func initGenesis(ctx *cli.Context) error {
  222. // Make sure we have a valid genesis JSON
  223. genesisPath := ctx.Args().First()
  224. if len(genesisPath) == 0 {
  225. utils.Fatalf("Must supply path to genesis JSON file")
  226. }
  227. file, err := os.Open(genesisPath)
  228. if err != nil {
  229. utils.Fatalf("Failed to read genesis file: %v", err)
  230. }
  231. defer file.Close()
  232. genesis := new(core.Genesis)
  233. if err := json.NewDecoder(file).Decode(genesis); err != nil {
  234. utils.Fatalf("invalid genesis file: %v", err)
  235. }
  236. // Open and initialise both full and light databases
  237. stack, _ := makeConfigNode(ctx)
  238. defer stack.Close()
  239. for _, name := range []string{"chaindata", "lightchaindata"} {
  240. chaindb, err := stack.OpenDatabase(name, 0, 0, "")
  241. if err != nil {
  242. utils.Fatalf("Failed to open database: %v", err)
  243. }
  244. _, hash, err := core.SetupGenesisBlock(chaindb, genesis)
  245. if err != nil {
  246. utils.Fatalf("Failed to write genesis block: %v", err)
  247. }
  248. chaindb.Close()
  249. log.Info("Successfully wrote genesis state", "database", name, "hash", hash)
  250. }
  251. return nil
  252. }
  253. func dumpGenesis(ctx *cli.Context) error {
  254. genesis := utils.MakeGenesis(ctx)
  255. if genesis == nil {
  256. genesis = core.DefaultGenesisBlock()
  257. }
  258. if err := json.NewEncoder(os.Stdout).Encode(genesis); err != nil {
  259. utils.Fatalf("could not encode genesis")
  260. }
  261. return nil
  262. }
  263. func importChain(ctx *cli.Context) error {
  264. if len(ctx.Args()) < 1 {
  265. utils.Fatalf("This command requires an argument.")
  266. }
  267. // Start metrics export if enabled
  268. utils.SetupMetrics(ctx)
  269. // Start system runtime metrics collection
  270. go metrics.CollectProcessMetrics(3 * time.Second)
  271. stack, _ := makeConfigNode(ctx)
  272. defer stack.Close()
  273. chain, db := utils.MakeChain(ctx, stack, false)
  274. defer db.Close()
  275. // Start periodically gathering memory profiles
  276. var peakMemAlloc, peakMemSys uint64
  277. go func() {
  278. stats := new(runtime.MemStats)
  279. for {
  280. runtime.ReadMemStats(stats)
  281. if atomic.LoadUint64(&peakMemAlloc) < stats.Alloc {
  282. atomic.StoreUint64(&peakMemAlloc, stats.Alloc)
  283. }
  284. if atomic.LoadUint64(&peakMemSys) < stats.Sys {
  285. atomic.StoreUint64(&peakMemSys, stats.Sys)
  286. }
  287. time.Sleep(5 * time.Second)
  288. }
  289. }()
  290. // Import the chain
  291. start := time.Now()
  292. var importErr error
  293. if len(ctx.Args()) == 1 {
  294. if err := utils.ImportChain(chain, ctx.Args().First()); err != nil {
  295. importErr = err
  296. log.Error("Import error", "err", err)
  297. }
  298. } else {
  299. for _, arg := range ctx.Args() {
  300. if err := utils.ImportChain(chain, arg); err != nil {
  301. importErr = err
  302. log.Error("Import error", "file", arg, "err", err)
  303. }
  304. }
  305. }
  306. chain.Stop()
  307. fmt.Printf("Import done in %v.\n\n", time.Since(start))
  308. // Output pre-compaction stats mostly to see the import trashing
  309. stats, err := db.Stat("leveldb.stats")
  310. if err != nil {
  311. utils.Fatalf("Failed to read database stats: %v", err)
  312. }
  313. fmt.Println(stats)
  314. ioStats, err := db.Stat("leveldb.iostats")
  315. if err != nil {
  316. utils.Fatalf("Failed to read database iostats: %v", err)
  317. }
  318. fmt.Println(ioStats)
  319. // Print the memory statistics used by the importing
  320. mem := new(runtime.MemStats)
  321. runtime.ReadMemStats(mem)
  322. fmt.Printf("Object memory: %.3f MB current, %.3f MB peak\n", float64(mem.Alloc)/1024/1024, float64(atomic.LoadUint64(&peakMemAlloc))/1024/1024)
  323. fmt.Printf("System memory: %.3f MB current, %.3f MB peak\n", float64(mem.Sys)/1024/1024, float64(atomic.LoadUint64(&peakMemSys))/1024/1024)
  324. fmt.Printf("Allocations: %.3f million\n", float64(mem.Mallocs)/1000000)
  325. fmt.Printf("GC pause: %v\n\n", time.Duration(mem.PauseTotalNs))
  326. if ctx.GlobalBool(utils.NoCompactionFlag.Name) {
  327. return nil
  328. }
  329. // Compact the entire database to more accurately measure disk io and print the stats
  330. start = time.Now()
  331. fmt.Println("Compacting entire database...")
  332. if err = db.Compact(nil, nil); err != nil {
  333. utils.Fatalf("Compaction failed: %v", err)
  334. }
  335. fmt.Printf("Compaction done in %v.\n\n", time.Since(start))
  336. stats, err = db.Stat("leveldb.stats")
  337. if err != nil {
  338. utils.Fatalf("Failed to read database stats: %v", err)
  339. }
  340. fmt.Println(stats)
  341. ioStats, err = db.Stat("leveldb.iostats")
  342. if err != nil {
  343. utils.Fatalf("Failed to read database iostats: %v", err)
  344. }
  345. fmt.Println(ioStats)
  346. return importErr
  347. }
  348. func exportChain(ctx *cli.Context) error {
  349. if len(ctx.Args()) < 1 {
  350. utils.Fatalf("This command requires an argument.")
  351. }
  352. stack, _ := makeConfigNode(ctx)
  353. defer stack.Close()
  354. chain, _ := utils.MakeChain(ctx, stack, true)
  355. start := time.Now()
  356. var err error
  357. fp := ctx.Args().First()
  358. if len(ctx.Args()) < 3 {
  359. err = utils.ExportChain(chain, fp)
  360. } else {
  361. // This can be improved to allow for numbers larger than 9223372036854775807
  362. first, ferr := strconv.ParseInt(ctx.Args().Get(1), 10, 64)
  363. last, lerr := strconv.ParseInt(ctx.Args().Get(2), 10, 64)
  364. if ferr != nil || lerr != nil {
  365. utils.Fatalf("Export error in parsing parameters: block number not an integer\n")
  366. }
  367. if first < 0 || last < 0 {
  368. utils.Fatalf("Export error: block number must be greater than 0\n")
  369. }
  370. err = utils.ExportAppendChain(chain, fp, uint64(first), uint64(last))
  371. }
  372. if err != nil {
  373. utils.Fatalf("Export error: %v\n", err)
  374. }
  375. fmt.Printf("Export done in %v\n", time.Since(start))
  376. return nil
  377. }
  378. // importPreimages imports preimage data from the specified file.
  379. func importPreimages(ctx *cli.Context) error {
  380. if len(ctx.Args()) < 1 {
  381. utils.Fatalf("This command requires an argument.")
  382. }
  383. stack, _ := makeConfigNode(ctx)
  384. defer stack.Close()
  385. db := utils.MakeChainDatabase(ctx, stack)
  386. start := time.Now()
  387. if err := utils.ImportPreimages(db, ctx.Args().First()); err != nil {
  388. utils.Fatalf("Import error: %v\n", err)
  389. }
  390. fmt.Printf("Import done in %v\n", time.Since(start))
  391. return nil
  392. }
  393. // exportPreimages dumps the preimage data to specified json file in streaming way.
  394. func exportPreimages(ctx *cli.Context) error {
  395. if len(ctx.Args()) < 1 {
  396. utils.Fatalf("This command requires an argument.")
  397. }
  398. stack, _ := makeConfigNode(ctx)
  399. defer stack.Close()
  400. db := utils.MakeChainDatabase(ctx, stack)
  401. start := time.Now()
  402. if err := utils.ExportPreimages(db, ctx.Args().First()); err != nil {
  403. utils.Fatalf("Export error: %v\n", err)
  404. }
  405. fmt.Printf("Export done in %v\n", time.Since(start))
  406. return nil
  407. }
  408. func copyDb(ctx *cli.Context) error {
  409. // Ensure we have a source chain directory to copy
  410. if len(ctx.Args()) < 1 {
  411. utils.Fatalf("Source chaindata directory path argument missing")
  412. }
  413. if len(ctx.Args()) < 2 {
  414. utils.Fatalf("Source ancient chain directory path argument missing")
  415. }
  416. // Initialize a new chain for the running node to sync into
  417. stack, _ := makeConfigNode(ctx)
  418. defer stack.Close()
  419. chain, chainDb := utils.MakeChain(ctx, stack, false)
  420. syncMode := *utils.GlobalTextMarshaler(ctx, utils.SyncModeFlag.Name).(*downloader.SyncMode)
  421. var syncBloom *trie.SyncBloom
  422. if syncMode == downloader.FastSync {
  423. syncBloom = trie.NewSyncBloom(uint64(ctx.GlobalInt(utils.CacheFlag.Name)/2), chainDb)
  424. }
  425. dl := downloader.New(0, chainDb, syncBloom, new(event.TypeMux), chain, nil, nil)
  426. // Create a source peer to satisfy downloader requests from
  427. db, err := rawdb.NewLevelDBDatabaseWithFreezer(ctx.Args().First(), ctx.GlobalInt(utils.CacheFlag.Name)/2, 256, ctx.Args().Get(1), "")
  428. if err != nil {
  429. return err
  430. }
  431. hc, err := core.NewHeaderChain(db, chain.Config(), chain.Engine(), func() bool { return false })
  432. if err != nil {
  433. return err
  434. }
  435. peer := downloader.NewFakePeer("local", db, hc, dl)
  436. if err = dl.RegisterPeer("local", 63, peer); err != nil {
  437. return err
  438. }
  439. // Synchronise with the simulated peer
  440. start := time.Now()
  441. currentHeader := hc.CurrentHeader()
  442. if err = dl.Synchronise("local", currentHeader.Hash(), hc.GetTd(currentHeader.Hash(), currentHeader.Number.Uint64()), syncMode); err != nil {
  443. return err
  444. }
  445. for dl.Synchronising() {
  446. time.Sleep(10 * time.Millisecond)
  447. }
  448. fmt.Printf("Database copy done in %v\n", time.Since(start))
  449. // Compact the entire database to remove any sync overhead
  450. start = time.Now()
  451. fmt.Println("Compacting entire database...")
  452. if err = db.Compact(nil, nil); err != nil {
  453. utils.Fatalf("Compaction failed: %v", err)
  454. }
  455. fmt.Printf("Compaction done in %v.\n\n", time.Since(start))
  456. return nil
  457. }
  458. func removeDB(ctx *cli.Context) error {
  459. stack, config := makeConfigNode(ctx)
  460. // Remove the full node state database
  461. path := stack.ResolvePath("chaindata")
  462. if common.FileExist(path) {
  463. confirmAndRemoveDB(path, "full node state database")
  464. } else {
  465. log.Info("Full node state database missing", "path", path)
  466. }
  467. // Remove the full node ancient database
  468. path = config.Eth.DatabaseFreezer
  469. switch {
  470. case path == "":
  471. path = filepath.Join(stack.ResolvePath("chaindata"), "ancient")
  472. case !filepath.IsAbs(path):
  473. path = config.Node.ResolvePath(path)
  474. }
  475. if common.FileExist(path) {
  476. confirmAndRemoveDB(path, "full node ancient database")
  477. } else {
  478. log.Info("Full node ancient database missing", "path", path)
  479. }
  480. // Remove the light node database
  481. path = stack.ResolvePath("lightchaindata")
  482. if common.FileExist(path) {
  483. confirmAndRemoveDB(path, "light node database")
  484. } else {
  485. log.Info("Light node database missing", "path", path)
  486. }
  487. return nil
  488. }
  489. // confirmAndRemoveDB prompts the user for a last confirmation and removes the
  490. // folder if accepted.
  491. func confirmAndRemoveDB(database string, kind string) {
  492. confirm, err := prompt.Stdin.PromptConfirm(fmt.Sprintf("Remove %s (%s)?", kind, database))
  493. switch {
  494. case err != nil:
  495. utils.Fatalf("%v", err)
  496. case !confirm:
  497. log.Info("Database deletion skipped", "path", database)
  498. default:
  499. start := time.Now()
  500. filepath.Walk(database, func(path string, info os.FileInfo, err error) error {
  501. // If we're at the top level folder, recurse into
  502. if path == database {
  503. return nil
  504. }
  505. // Delete all the files, but not subfolders
  506. if !info.IsDir() {
  507. os.Remove(path)
  508. return nil
  509. }
  510. return filepath.SkipDir
  511. })
  512. log.Info("Database successfully deleted", "path", database, "elapsed", common.PrettyDuration(time.Since(start)))
  513. }
  514. }
  515. func dump(ctx *cli.Context) error {
  516. stack, _ := makeConfigNode(ctx)
  517. defer stack.Close()
  518. chain, chainDb := utils.MakeChain(ctx, stack, true)
  519. defer chainDb.Close()
  520. for _, arg := range ctx.Args() {
  521. var block *types.Block
  522. if hashish(arg) {
  523. block = chain.GetBlockByHash(common.HexToHash(arg))
  524. } else {
  525. num, _ := strconv.Atoi(arg)
  526. block = chain.GetBlockByNumber(uint64(num))
  527. }
  528. if block == nil {
  529. fmt.Println("{}")
  530. utils.Fatalf("block not found")
  531. } else {
  532. state, err := state.New(block.Root(), state.NewDatabase(chainDb), nil)
  533. if err != nil {
  534. utils.Fatalf("could not create new state: %v", err)
  535. }
  536. excludeCode := ctx.Bool(utils.ExcludeCodeFlag.Name)
  537. excludeStorage := ctx.Bool(utils.ExcludeStorageFlag.Name)
  538. includeMissing := ctx.Bool(utils.IncludeIncompletesFlag.Name)
  539. if ctx.Bool(utils.IterativeOutputFlag.Name) {
  540. state.IterativeDump(excludeCode, excludeStorage, !includeMissing, json.NewEncoder(os.Stdout))
  541. } else {
  542. if includeMissing {
  543. fmt.Printf("If you want to include accounts with missing preimages, you need iterative output, since" +
  544. " otherwise the accounts will overwrite each other in the resulting mapping.")
  545. }
  546. fmt.Printf("%v %s\n", includeMissing, state.Dump(excludeCode, excludeStorage, false))
  547. }
  548. }
  549. }
  550. return nil
  551. }
  552. func inspect(ctx *cli.Context) error {
  553. node, _ := makeConfigNode(ctx)
  554. defer node.Close()
  555. _, chainDb := utils.MakeChain(ctx, node, true)
  556. defer chainDb.Close()
  557. return rawdb.InspectDatabase(chainDb)
  558. }
  559. // hashish returns true for strings that look like hashes.
  560. func hashish(x string) bool {
  561. _, err := strconv.Atoi(x)
  562. return err != nil
  563. }