@@ -18,9 +18,7 @@ package main
1818
1919import (
2020 "fmt"
21- "io/ioutil"
2221 "os"
23- "path/filepath"
2422 "runtime"
2523 "strconv"
2624 "strings"
@@ -33,14 +31,27 @@ import (
3331)
3432
3533var (
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
4556This command exists to support the system testing project.
4657Regular 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.
6895func 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
0 commit comments