Skip to content

Commit 8b84bd2

Browse files
authored
Merge pull request #14889 from karalabe/ethash-cache-on-import
cmd: add makecache cmd, use caches during import cmd
2 parents 4371367 + 4a260dc commit 8b84bd2

3 files changed

Lines changed: 42 additions & 27 deletions

File tree

‎cmd/geth/main.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ func init() {
157157
attachCommand,
158158
javascriptCommand,
159159
// See misccmd.go:
160+
makecacheCommand,
160161
makedagCommand,
161162
versionCommand,
162163
bugCommand,

‎cmd/geth/misccmd.go‎

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ package main
1818

1919
import (
2020
"fmt"
21-
"io/ioutil"
2221
"os"
23-
"path/filepath"
2422
"runtime"
2523
"strconv"
2624
"strings"
@@ -33,14 +31,27 @@ import (
3331
)
3432

3533
var (
34+
makecacheCommand = cli.Command{
35+
Action: utils.MigrateFlags(makecache),
36+
Name: "makecache",
37+
Usage: "Generate ethash verification cache (for testing)",
38+
ArgsUsage: "<blockNum> <outputDir>",
39+
Category: "MISCELLANEOUS COMMANDS",
40+
Description: `
41+
The makecache command generates an ethash cache in <outputDir>.
42+
43+
This command exists to support the system testing project.
44+
Regular users do not need to execute it.
45+
`,
46+
}
3647
makedagCommand = cli.Command{
3748
Action: utils.MigrateFlags(makedag),
3849
Name: "makedag",
39-
Usage: "Generate ethash DAG (for testing)",
50+
Usage: "Generate ethash mining DAG (for testing)",
4051
ArgsUsage: "<blockNum> <outputDir>",
4152
Category: "MISCELLANEOUS COMMANDS",
4253
Description: `
43-
The makedag command generates an ethash DAG in /tmp/dag.
54+
The makedag command generates an ethash DAG in <outputDir>.
4455
4556
This command exists to support the system testing project.
4657
Regular users do not need to execute it.
@@ -65,33 +76,33 @@ The output of this command is supposed to be machine-readable.
6576
}
6677
)
6778

79+
// makecache generates an ethash verification cache into the provided folder.
80+
func makecache(ctx *cli.Context) error {
81+
args := ctx.Args()
82+
if len(args) != 2 {
83+
utils.Fatalf(`Usage: geth makecache <block number> <outputdir>`)
84+
}
85+
block, err := strconv.ParseUint(args[0], 0, 64)
86+
if err != nil {
87+
utils.Fatalf("Invalid block number: %v", err)
88+
}
89+
ethash.MakeCache(block, args[1])
90+
91+
return nil
92+
}
93+
94+
// makedag generates an ethash mining DAG into the provided folder.
6895
func makedag(ctx *cli.Context) error {
6996
args := ctx.Args()
70-
wrongArgs := func() {
97+
if len(args) != 2 {
7198
utils.Fatalf(`Usage: geth makedag <block number> <outputdir>`)
7299
}
73-
switch {
74-
case len(args) == 2:
75-
blockNum, err := strconv.ParseUint(args[0], 0, 64)
76-
dir := args[1]
77-
if err != nil {
78-
wrongArgs()
79-
} else {
80-
dir = filepath.Clean(dir)
81-
// seems to require a trailing slash
82-
if !strings.HasSuffix(dir, "/") {
83-
dir = dir + "/"
84-
}
85-
_, err = ioutil.ReadDir(dir)
86-
if err != nil {
87-
utils.Fatalf("Can't find dir")
88-
}
89-
fmt.Println("making DAG, this could take awhile...")
90-
ethash.MakeDataset(blockNum, dir)
91-
}
92-
default:
93-
wrongArgs()
100+
block, err := strconv.ParseUint(args[0], 0, 64)
101+
if err != nil {
102+
utils.Fatalf("Invalid block number: %v", err)
94103
}
104+
ethash.MakeDataset(block, args[1])
105+
95106
return nil
96107
}
97108

‎cmd/utils/flags.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,10 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai
10931093

10941094
engine := ethash.NewFaker()
10951095
if !ctx.GlobalBool(FakePoWFlag.Name) {
1096-
engine = ethash.New("", 1, 0, "", 1, 0)
1096+
engine = ethash.New(
1097+
stack.ResolvePath(eth.DefaultConfig.EthashCacheDir), eth.DefaultConfig.EthashCachesInMem, eth.DefaultConfig.EthashCachesOnDisk,
1098+
stack.ResolvePath(eth.DefaultConfig.EthashDatasetDir), eth.DefaultConfig.EthashDatasetsInMem, eth.DefaultConfig.EthashDatasetsOnDisk,
1099+
)
10971100
}
10981101
config, _, err := core.SetupGenesisBlock(chainDb, MakeGenesis(ctx))
10991102
if err != nil {

0 commit comments

Comments
 (0)