Skip to content

Commit 4e075e4

Browse files
committed
Merge pull request #1773 from obscuren/dev-mode
cmd/geth, cmd/utils, eth: added dev mode flag
2 parents 62bbf8a + f04b3a6 commit 4e075e4

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

cmd/geth/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
308308
utils.IPCPathFlag,
309309
utils.ExecFlag,
310310
utils.WhisperEnabledFlag,
311+
utils.DevModeFlag,
311312
utils.VMDebugFlag,
312313
utils.VMForceJitFlag,
313314
utils.VMJitCacheFlag,

cmd/utils/flags.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ var (
121121
Name: "genesis",
122122
Usage: "Inserts/Overwrites the genesis block (json format)",
123123
}
124+
DevModeFlag = cli.BoolFlag{
125+
Name: "dev",
126+
Usage: "Developer mode. This mode creates a private network and sets several debugging flags",
127+
}
124128
IdentityFlag = cli.StringFlag{
125129
Name: "identity",
126130
Usage: "Custom node name",
@@ -410,7 +414,7 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
410414
glog.V(logger.Error).Infoln("WARNING: No etherbase set and no accounts found as default")
411415
}
412416

413-
return &eth.Config{
417+
cfg := &eth.Config{
414418
Name: common.MakeName(clientID, version),
415419
DataDir: ctx.GlobalString(DataDirFlag.Name),
416420
GenesisNonce: ctx.GlobalInt(GenesisNonceFlag.Name),
@@ -447,6 +451,33 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
447451
SolcPath: ctx.GlobalString(SolcPathFlag.Name),
448452
AutoDAG: ctx.GlobalBool(AutoDAGFlag.Name) || ctx.GlobalBool(MiningEnabledFlag.Name),
449453
}
454+
455+
if ctx.GlobalBool(DevModeFlag.Name) {
456+
if !ctx.GlobalIsSet(VMDebugFlag.Name) {
457+
cfg.VmDebug = true
458+
}
459+
if !ctx.GlobalIsSet(MaxPeersFlag.Name) {
460+
cfg.MaxPeers = 0
461+
}
462+
if !ctx.GlobalIsSet(GasPriceFlag.Name) {
463+
cfg.GasPrice = new(big.Int)
464+
}
465+
if !ctx.GlobalIsSet(ListenPortFlag.Name) {
466+
cfg.Port = "0" // auto port
467+
}
468+
if !ctx.GlobalIsSet(WhisperEnabledFlag.Name) {
469+
cfg.Shh = true
470+
}
471+
if !ctx.GlobalIsSet(DataDirFlag.Name) {
472+
cfg.DataDir = os.TempDir() + "/ethereum_dev_mode"
473+
}
474+
cfg.PowTest = true
475+
cfg.DevMode = true
476+
477+
glog.V(logger.Info).Infoln("dev mode enabled")
478+
}
479+
480+
return cfg
450481
}
451482

452483
// SetupLogger configures glog from the logging-related command line flags.

eth/backend.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ var (
7373
)
7474

7575
type Config struct {
76+
DevMode bool
77+
7678
Name string
7779
NetworkId int
7880
GenesisNonce int
@@ -303,16 +305,17 @@ func New(config *Config) (*Ethereum, error) {
303305
glog.V(logger.Info).Infof("Successfully wrote genesis block. New genesis hash = %x\n", block.Hash())
304306
}
305307

306-
if config.Olympic {
308+
// different modes
309+
switch {
310+
case config.Olympic:
311+
glog.V(logger.Error).Infoln("Starting Olympic network")
312+
fallthrough
313+
case config.DevMode:
307314
_, err := core.WriteTestNetGenesisBlock(chainDb, 42)
308315
if err != nil {
309316
return nil, err
310317
}
311-
glog.V(logger.Error).Infoln("Starting Olympic network")
312-
}
313-
314-
// This is for testing only.
315-
if config.GenesisBlock != nil {
318+
case config.GenesisBlock != nil: // This is for testing only.
316319
core.WriteBlock(chainDb, config.GenesisBlock)
317320
core.WriteHead(chainDb, config.GenesisBlock)
318321
}

0 commit comments

Comments
 (0)