diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-08-04 00:40:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-04 00:40:21 +0800 |
commit | 8b84bd283fe94a7c921fd404156e25160ac918dc (patch) | |
tree | a08303fab47af1568abf4ebbf222baee8c399160 | |
parent | 4371367cd18cf5b03c90e35630b61586071c8724 (diff) | |
parent | 4a260dc1f28719be860937a2b0c9574d59e51ab9 (diff) | |
download | dexon-8b84bd283fe94a7c921fd404156e25160ac918dc.tar dexon-8b84bd283fe94a7c921fd404156e25160ac918dc.tar.gz dexon-8b84bd283fe94a7c921fd404156e25160ac918dc.tar.bz2 dexon-8b84bd283fe94a7c921fd404156e25160ac918dc.tar.lz dexon-8b84bd283fe94a7c921fd404156e25160ac918dc.tar.xz dexon-8b84bd283fe94a7c921fd404156e25160ac918dc.tar.zst dexon-8b84bd283fe94a7c921fd404156e25160ac918dc.zip |
Merge pull request #14889 from karalabe/ethash-cache-on-import
cmd: add makecache cmd, use caches during import cmd
-rw-r--r-- | cmd/geth/main.go | 1 | ||||
-rw-r--r-- | cmd/geth/misccmd.go | 63 | ||||
-rw-r--r-- | cmd/utils/flags.go | 5 |
3 files changed, 42 insertions, 27 deletions
diff --git a/cmd/geth/main.go b/cmd/geth/main.go index e89f88ec9..58e949806 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -157,6 +157,7 @@ func init() { attachCommand, javascriptCommand, // See misccmd.go: + makecacheCommand, makedagCommand, versionCommand, bugCommand, diff --git a/cmd/geth/misccmd.go b/cmd/geth/misccmd.go index 62b93d65a..2e68dcda3 100644 --- a/cmd/geth/misccmd.go +++ b/cmd/geth/misccmd.go @@ -18,9 +18,7 @@ package main import ( "fmt" - "io/ioutil" "os" - "path/filepath" "runtime" "strconv" "strings" @@ -33,14 +31,27 @@ import ( ) var ( + makecacheCommand = cli.Command{ + Action: utils.MigrateFlags(makecache), + Name: "makecache", + Usage: "Generate ethash verification cache (for testing)", + ArgsUsage: "<blockNum> <outputDir>", + Category: "MISCELLANEOUS COMMANDS", + Description: ` +The makecache command generates an ethash cache in <outputDir>. + +This command exists to support the system testing project. +Regular users do not need to execute it. +`, + } makedagCommand = cli.Command{ Action: utils.MigrateFlags(makedag), Name: "makedag", - Usage: "Generate ethash DAG (for testing)", + Usage: "Generate ethash mining DAG (for testing)", ArgsUsage: "<blockNum> <outputDir>", Category: "MISCELLANEOUS COMMANDS", Description: ` -The makedag command generates an ethash DAG in /tmp/dag. +The makedag command generates an ethash DAG in <outputDir>. This command exists to support the system testing project. Regular users do not need to execute it. @@ -65,33 +76,33 @@ The output of this command is supposed to be machine-readable. } ) +// makecache generates an ethash verification cache into the provided folder. +func makecache(ctx *cli.Context) error { + args := ctx.Args() + if len(args) != 2 { + utils.Fatalf(`Usage: geth makecache <block number> <outputdir>`) + } + block, err := strconv.ParseUint(args[0], 0, 64) + if err != nil { + utils.Fatalf("Invalid block number: %v", err) + } + ethash.MakeCache(block, args[1]) + + return nil +} + +// makedag generates an ethash mining DAG into the provided folder. func makedag(ctx *cli.Context) error { args := ctx.Args() - wrongArgs := func() { + if len(args) != 2 { utils.Fatalf(`Usage: geth makedag <block number> <outputdir>`) } - switch { - case len(args) == 2: - blockNum, err := strconv.ParseUint(args[0], 0, 64) - dir := args[1] - if err != nil { - wrongArgs() - } else { - dir = filepath.Clean(dir) - // seems to require a trailing slash - if !strings.HasSuffix(dir, "/") { - dir = dir + "/" - } - _, err = ioutil.ReadDir(dir) - if err != nil { - utils.Fatalf("Can't find dir") - } - fmt.Println("making DAG, this could take awhile...") - ethash.MakeDataset(blockNum, dir) - } - default: - wrongArgs() + block, err := strconv.ParseUint(args[0], 0, 64) + if err != nil { + utils.Fatalf("Invalid block number: %v", err) } + ethash.MakeDataset(block, args[1]) + return nil } diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 9f7b76c12..04728b5c6 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1093,7 +1093,10 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai engine := ethash.NewFaker() if !ctx.GlobalBool(FakePoWFlag.Name) { - engine = ethash.New("", 1, 0, "", 1, 0) + engine = ethash.New( + stack.ResolvePath(eth.DefaultConfig.EthashCacheDir), eth.DefaultConfig.EthashCachesInMem, eth.DefaultConfig.EthashCachesOnDisk, + stack.ResolvePath(eth.DefaultConfig.EthashDatasetDir), eth.DefaultConfig.EthashDatasetsInMem, eth.DefaultConfig.EthashDatasetsOnDisk, + ) } config, _, err := core.SetupGenesisBlock(chainDb, MakeGenesis(ctx)) if err != nil { |