Skip to content

Commit 023670f

Browse files
karalabefjl
authored andcommitted
cmd, eth, les, node, pow: disk caching and progress reports
1 parent 567d41d commit 023670f

8 files changed

Lines changed: 216 additions & 55 deletions

File tree

‎cmd/geth/main.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ func init() {
9191
utils.BootnodesFlag,
9292
utils.DataDirFlag,
9393
utils.KeyStoreDirFlag,
94+
utils.EthashCacheDirFlag,
95+
utils.EthashCachesInMemoryFlag,
96+
utils.EthashCachesOnDiskFlag,
97+
utils.EthashDatasetDirFlag,
98+
utils.EthashDatasetsOnDiskFlag,
9499
utils.FastSyncFlag,
95100
utils.LightModeFlag,
96101
utils.LightServFlag,

‎cmd/geth/usage.go‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ var AppHelpFlagGroups = []flagGroup{
7777
utils.LightKDFFlag,
7878
},
7979
},
80+
{
81+
Name: "ETHASH",
82+
Flags: []cli.Flag{
83+
utils.EthashCacheDirFlag,
84+
utils.EthashCachesInMemoryFlag,
85+
utils.EthashCachesOnDiskFlag,
86+
utils.EthashDatasetDirFlag,
87+
utils.EthashDatasetsOnDiskFlag,
88+
},
89+
},
8090
{
8191
Name: "PERFORMANCE TUNING",
8292
Flags: []cli.Flag{

‎cmd/utils/flags.go‎

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.
436490
func 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 {

‎eth/backend.go‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ type Config struct {
8484
PowShared bool
8585
ExtraData []byte
8686

87+
EthashCacheDir string
88+
EthashCachesInMem int
89+
EthashCachesOnDisk int
90+
EthashDatasetDir string
91+
EthashDatasetsOnDisk int
92+
8793
Etherbase common.Address
8894
GasPrice *big.Int
8995
MinerThreads int
@@ -157,16 +163,11 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
157163
if err := SetupGenesisBlock(&chainDb, config); err != nil {
158164
return nil, err
159165
}
160-
pow, err := CreatePoW(config)
161-
if err != nil {
162-
return nil, err
163-
}
164-
165166
eth := &Ethereum{
166167
chainDb: chainDb,
167168
eventMux: ctx.EventMux,
168169
accountManager: ctx.AccountManager,
169-
pow: pow,
170+
pow: CreatePoW(ctx, config),
170171
shutdownChan: make(chan bool),
171172
stopDbUpgrade: stopDbUpgrade,
172173
netVersionId: config.NetworkId,
@@ -284,19 +285,20 @@ func SetupGenesisBlock(chainDb *ethdb.Database, config *Config) error {
284285
}
285286

286287
// CreatePoW creates the required type of PoW instance for an Ethereum service
287-
func CreatePoW(config *Config) (pow.PoW, error) {
288+
func CreatePoW(ctx *node.ServiceContext, config *Config) pow.PoW {
288289
switch {
289290
case config.PowFake:
290291
log.Warn("Ethash used in fake mode")
291-
return pow.FakePow{}, nil
292+
return pow.FakePow{}
292293
case config.PowTest:
293294
log.Warn("Ethash used in test mode")
294-
return pow.NewTestEthash(), nil
295+
return pow.NewTestEthash()
295296
case config.PowShared:
296297
log.Warn("Ethash used in shared mode")
297-
return pow.NewSharedEthash(), nil
298+
return pow.NewSharedEthash()
298299
default:
299-
return pow.NewFullEthash("", ""), nil
300+
return pow.NewFullEthash(ctx.ResolvePath(config.EthashCacheDir), config.EthashCachesInMem, config.EthashCachesOnDisk,
301+
config.EthashDatasetDir, config.EthashDatasetsOnDisk)
300302
}
301303
}
302304

‎les/backend.go‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,6 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
7777
if err := eth.SetupGenesisBlock(&chainDb, config); err != nil {
7878
return nil, err
7979
}
80-
pow, err := eth.CreatePoW(config)
81-
if err != nil {
82-
return nil, err
83-
}
84-
8580
odr := NewLesOdr(chainDb)
8681
relay := NewLesTxRelay()
8782
eth := &LightEthereum{
@@ -90,7 +85,7 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
9085
chainDb: chainDb,
9186
eventMux: ctx.EventMux,
9287
accountManager: ctx.AccountManager,
93-
pow: pow,
88+
pow: eth.CreatePoW(ctx, config),
9489
shutdownChan: make(chan bool),
9590
netVersionId: config.NetworkId,
9691
solcPath: config.SolcPath,

‎node/service.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ func (ctx *ServiceContext) OpenDatabase(name string, cache int, handles int) (et
4646
return ethdb.NewLDBDatabase(ctx.config.resolvePath(name), cache, handles)
4747
}
4848

49+
// ResolvePath resolves a user path into the data directory if that was relative
50+
// and if the user actually uses persistent storage. It will return an empty string
51+
// for emphemeral storage and the user's own input for absolute paths.
52+
func (ctx *ServiceContext) ResolvePath(path string) string {
53+
return ctx.config.resolvePath(path)
54+
}
55+
4956
// Service retrieves a currently running service registered of a specific type.
5057
func (ctx *ServiceContext) Service(service interface{}) error {
5158
element := reflect.ValueOf(service).Elem()

0 commit comments

Comments
 (0)