@@ -23,6 +23,7 @@ import (
2323 "io/ioutil"
2424 "math/big"
2525 "os"
26+ "os/user"
2627 "path/filepath"
2728 "runtime"
2829 "strconv"
@@ -113,6 +114,29 @@ var (
113114 Name : "keystore" ,
114115 Usage : "Directory for the keystore (default = inside the datadir)" ,
115116 }
117+ EthashCacheDirFlag = DirectoryFlag {
118+ Name : "ethash.cachedir" ,
119+ Usage : "Directory to store the ethash verification caches (default = inside the datadir)" ,
120+ }
121+ EthashCachesInMemoryFlag = cli.IntFlag {
122+ Name : "ethash.cachesinmem" ,
123+ Usage : "Number of recent ethash caches to keep in memory (16MB each)" ,
124+ Value : 2 ,
125+ }
126+ EthashCachesOnDiskFlag = cli.IntFlag {
127+ Name : "ethash.cachesondisk" ,
128+ Usage : "Number of recent ethash caches to keep on disk (16MB each)" ,
129+ Value : 3 ,
130+ }
131+ EthashDatasetDirFlag = DirectoryFlag {
132+ Name : "ethash.dagdir" ,
133+ Usage : "Directory to store the ethash mining DAGs (default = inside home folder)" ,
134+ }
135+ EthashDatasetsOnDiskFlag = cli.IntFlag {
136+ Name : "ethash.dagsondisk" ,
137+ Usage : "Number of ethash mining DAGs to keep on disk (1+GB each)" ,
138+ Value : 2 ,
139+ }
116140 NetworkIdFlag = cli.IntFlag {
117141 Name : "networkid" ,
118142 Usage : "Network identifier (integer, 1=Frontier, 2=Morden (disused), 3=Ropsten)" ,
@@ -431,6 +455,36 @@ func MakeDataDir(ctx *cli.Context) string {
431455 return ""
432456}
433457
458+ // MakeEthashCacheDir returns the directory to use for storing the ethash cache
459+ // dumps.
460+ func MakeEthashCacheDir (ctx * cli.Context ) string {
461+ if ctx .GlobalIsSet (EthashCacheDirFlag .Name ) && ctx .GlobalString (EthashCacheDirFlag .Name ) == "" {
462+ return ""
463+ }
464+ if ! ctx .GlobalIsSet (EthashCacheDirFlag .Name ) {
465+ return "ethash"
466+ }
467+ return ctx .GlobalString (EthashCacheDirFlag .Name )
468+ }
469+
470+ // MakeEthashDatasetDir returns the directory to use for storing the full ethash
471+ // dataset dumps.
472+ func MakeEthashDatasetDir (ctx * cli.Context ) string {
473+ if ! ctx .GlobalIsSet (EthashDatasetDirFlag .Name ) {
474+ home := os .Getenv ("HOME" )
475+ if home == "" {
476+ if user , err := user .Current (); err == nil {
477+ home = user .HomeDir
478+ }
479+ }
480+ if runtime .GOOS == "windows" {
481+ return filepath .Join (home , "AppData" , "Ethash" )
482+ }
483+ return filepath .Join (home , ".ethash" )
484+ }
485+ return ctx .GlobalString (EthashDatasetDirFlag .Name )
486+ }
487+
434488// MakeIPCPath creates an IPC path configuration from the set command line flags,
435489// returning an empty string if IPC was explicitly disabled, or the set path.
436490func MakeIPCPath (ctx * cli.Context ) string {
@@ -751,6 +805,11 @@ func RegisterEthService(ctx *cli.Context, stack *node.Node, extra []byte) {
751805 GpobaseStepUp : ctx .GlobalInt (GpobaseStepUpFlag .Name ),
752806 GpobaseCorrectionFactor : ctx .GlobalInt (GpobaseCorrectionFactorFlag .Name ),
753807 SolcPath : ctx .GlobalString (SolcPathFlag .Name ),
808+ EthashCacheDir : MakeEthashCacheDir (ctx ),
809+ EthashCachesInMem : ctx .GlobalInt (EthashCachesInMemoryFlag .Name ),
810+ EthashCachesOnDisk : ctx .GlobalInt (EthashCachesOnDiskFlag .Name ),
811+ EthashDatasetDir : MakeEthashDatasetDir (ctx ),
812+ EthashDatasetsOnDisk : ctx .GlobalInt (EthashDatasetsOnDiskFlag .Name ),
754813 AutoDAG : ctx .GlobalBool (AutoDAGFlag .Name ) || ctx .GlobalBool (MiningEnabledFlag .Name ),
755814 EnablePreimageRecording : ctx .GlobalBool (VMEnableDebugFlag .Name ),
756815 }
@@ -923,7 +982,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai
923982
924983 seal := pow .PoW (pow.FakePow {})
925984 if ! ctx .GlobalBool (FakePoWFlag .Name ) {
926- seal = pow .NewFullEthash ("" , "" )
985+ seal = pow .NewFullEthash ("" , 1 , 0 , "" , 0 )
927986 }
928987 chain , err = core .NewBlockChain (chainDb , chainConfig , seal , new (event.TypeMux ), vm.Config {EnablePreimageRecording : ctx .GlobalBool (VMEnableDebugFlag .Name )})
929988 if err != nil {
0 commit comments