cmd/geth, cmd/utils, eth: added dev mode flag

Dev mode enabled some debugging flags such as:

* VM debugging mode
* Simpler proof of work
* Whisper enabled by default
* Datadir to a tmp datadir
* Maxpeers set to 0
* Gas price of 0
* Random listen port
This commit is contained in:
Jeffrey Wilcke 2015-09-06 15:46:54 +02:00
parent e2d7c1a523
commit f04b3a6f29
3 changed files with 42 additions and 7 deletions

View File

@ -308,6 +308,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
utils.IPCPathFlag, utils.IPCPathFlag,
utils.ExecFlag, utils.ExecFlag,
utils.WhisperEnabledFlag, utils.WhisperEnabledFlag,
utils.DevModeFlag,
utils.VMDebugFlag, utils.VMDebugFlag,
utils.VMForceJitFlag, utils.VMForceJitFlag,
utils.VMJitCacheFlag, utils.VMJitCacheFlag,

View File

@ -121,6 +121,10 @@ var (
Name: "genesis", Name: "genesis",
Usage: "Inserts/Overwrites the genesis block (json format)", Usage: "Inserts/Overwrites the genesis block (json format)",
} }
DevModeFlag = cli.BoolFlag{
Name: "dev",
Usage: "Developer mode. This mode creates a private network and sets several debugging flags",
}
IdentityFlag = cli.StringFlag{ IdentityFlag = cli.StringFlag{
Name: "identity", Name: "identity",
Usage: "Custom node name", Usage: "Custom node name",
@ -410,7 +414,7 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
glog.V(logger.Error).Infoln("WARNING: No etherbase set and no accounts found as default") glog.V(logger.Error).Infoln("WARNING: No etherbase set and no accounts found as default")
} }
return &eth.Config{ cfg := &eth.Config{
Name: common.MakeName(clientID, version), Name: common.MakeName(clientID, version),
DataDir: ctx.GlobalString(DataDirFlag.Name), DataDir: ctx.GlobalString(DataDirFlag.Name),
GenesisNonce: ctx.GlobalInt(GenesisNonceFlag.Name), GenesisNonce: ctx.GlobalInt(GenesisNonceFlag.Name),
@ -447,6 +451,33 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
SolcPath: ctx.GlobalString(SolcPathFlag.Name), SolcPath: ctx.GlobalString(SolcPathFlag.Name),
AutoDAG: ctx.GlobalBool(AutoDAGFlag.Name) || ctx.GlobalBool(MiningEnabledFlag.Name), AutoDAG: ctx.GlobalBool(AutoDAGFlag.Name) || ctx.GlobalBool(MiningEnabledFlag.Name),
} }
if ctx.GlobalBool(DevModeFlag.Name) {
if !ctx.GlobalIsSet(VMDebugFlag.Name) {
cfg.VmDebug = true
}
if !ctx.GlobalIsSet(MaxPeersFlag.Name) {
cfg.MaxPeers = 0
}
if !ctx.GlobalIsSet(GasPriceFlag.Name) {
cfg.GasPrice = new(big.Int)
}
if !ctx.GlobalIsSet(ListenPortFlag.Name) {
cfg.Port = "0" // auto port
}
if !ctx.GlobalIsSet(WhisperEnabledFlag.Name) {
cfg.Shh = true
}
if !ctx.GlobalIsSet(DataDirFlag.Name) {
cfg.DataDir = os.TempDir() + "/ethereum_dev_mode"
}
cfg.PowTest = true
cfg.DevMode = true
glog.V(logger.Info).Infoln("dev mode enabled")
}
return cfg
} }
// SetupLogger configures glog from the logging-related command line flags. // SetupLogger configures glog from the logging-related command line flags.

View File

@ -73,6 +73,8 @@ var (
) )
type Config struct { type Config struct {
DevMode bool
Name string Name string
NetworkId int NetworkId int
GenesisNonce int GenesisNonce int
@ -303,16 +305,17 @@ func New(config *Config) (*Ethereum, error) {
glog.V(logger.Info).Infof("Successfully wrote genesis block. New genesis hash = %x\n", block.Hash()) glog.V(logger.Info).Infof("Successfully wrote genesis block. New genesis hash = %x\n", block.Hash())
} }
if config.Olympic { // different modes
switch {
case config.Olympic:
glog.V(logger.Error).Infoln("Starting Olympic network")
fallthrough
case config.DevMode:
_, err := core.WriteTestNetGenesisBlock(chainDb, 42) _, err := core.WriteTestNetGenesisBlock(chainDb, 42)
if err != nil { if err != nil {
return nil, err return nil, err
} }
glog.V(logger.Error).Infoln("Starting Olympic network") case config.GenesisBlock != nil: // This is for testing only.
}
// This is for testing only.
if config.GenesisBlock != nil {
core.WriteBlock(chainDb, config.GenesisBlock) core.WriteBlock(chainDb, config.GenesisBlock)
core.WriteHead(chainDb, config.GenesisBlock) core.WriteHead(chainDb, config.GenesisBlock)
} }