Commit 6060e098 authored by Péter Szilágyi's avatar Péter Szilágyi

cmd, core, eth, params: implement flags to control dao fork blocks

parent aa1e052c
This diff is collapsed.
...@@ -150,7 +150,6 @@ participating. ...@@ -150,7 +150,6 @@ participating.
utils.IdentityFlag, utils.IdentityFlag,
utils.UnlockedAccountFlag, utils.UnlockedAccountFlag,
utils.PasswordFileFlag, utils.PasswordFileFlag,
utils.GenesisFileFlag,
utils.BootnodesFlag, utils.BootnodesFlag,
utils.DataDirFlag, utils.DataDirFlag,
utils.KeyStoreDirFlag, utils.KeyStoreDirFlag,
...@@ -165,6 +164,8 @@ participating. ...@@ -165,6 +164,8 @@ participating.
utils.MaxPendingPeersFlag, utils.MaxPendingPeersFlag,
utils.EtherbaseFlag, utils.EtherbaseFlag,
utils.GasPriceFlag, utils.GasPriceFlag,
utils.SupportDAOFork,
utils.OpposeDAOFork,
utils.MinerThreadsFlag, utils.MinerThreadsFlag,
utils.MiningEnabledFlag, utils.MiningEnabledFlag,
utils.MiningGPUFlag, utils.MiningGPUFlag,
...@@ -225,12 +226,6 @@ participating. ...@@ -225,12 +226,6 @@ participating.
eth.EnableBadBlockReporting = true eth.EnableBadBlockReporting = true
utils.SetupNetwork(ctx) utils.SetupNetwork(ctx)
// Deprecation warning.
if ctx.GlobalIsSet(utils.GenesisFileFlag.Name) {
common.PrintDepricationWarning("--genesis is deprecated. Switch to use 'geth init /path/to/file'")
}
return nil return nil
} }
......
...@@ -68,7 +68,6 @@ var AppHelpFlagGroups = []flagGroup{ ...@@ -68,7 +68,6 @@ var AppHelpFlagGroups = []flagGroup{
utils.OlympicFlag, utils.OlympicFlag,
utils.TestNetFlag, utils.TestNetFlag,
utils.DevModeFlag, utils.DevModeFlag,
utils.GenesisFileFlag,
utils.IdentityFlag, utils.IdentityFlag,
utils.FastSyncFlag, utils.FastSyncFlag,
utils.LightKDFFlag, utils.LightKDFFlag,
......
...@@ -126,10 +126,6 @@ var ( ...@@ -126,10 +126,6 @@ var (
Name: "dev", Name: "dev",
Usage: "Developer mode: pre-configured private network with several debugging flags", Usage: "Developer mode: pre-configured private network with several debugging flags",
} }
GenesisFileFlag = cli.StringFlag{
Name: "genesis",
Usage: "Insert/overwrite the genesis block (JSON format)",
}
IdentityFlag = cli.StringFlag{ IdentityFlag = cli.StringFlag{
Name: "identity", Name: "identity",
Usage: "Custom node name", Usage: "Custom node name",
...@@ -161,6 +157,15 @@ var ( ...@@ -161,6 +157,15 @@ var (
Name: "lightkdf", Name: "lightkdf",
Usage: "Reduce key-derivation RAM & CPU usage at some expense of KDF strength", Usage: "Reduce key-derivation RAM & CPU usage at some expense of KDF strength",
} }
// Fork settings
SupportDAOFork = cli.BoolFlag{
Name: "support-dao-fork",
Usage: "Updates the chain rules to support the DAO hard-fork",
}
OpposeDAOFork = cli.BoolFlag{
Name: "oppose-dao-fork",
Usage: "Updates the chain rules to oppose the DAO hard-fork",
}
// Miner settings // Miner settings
// TODO: refactor CPU vs GPU mining flags // TODO: refactor CPU vs GPU mining flags
MiningEnabledFlag = cli.BoolFlag{ MiningEnabledFlag = cli.BoolFlag{
...@@ -534,20 +539,6 @@ func MakeWSRpcHost(ctx *cli.Context) string { ...@@ -534,20 +539,6 @@ func MakeWSRpcHost(ctx *cli.Context) string {
return ctx.GlobalString(WSListenAddrFlag.Name) return ctx.GlobalString(WSListenAddrFlag.Name)
} }
// MakeGenesisBlock loads up a genesis block from an input file specified in the
// command line, or returns the empty string if none set.
func MakeGenesisBlock(ctx *cli.Context) string {
genesis := ctx.GlobalString(GenesisFileFlag.Name)
if genesis == "" {
return ""
}
data, err := ioutil.ReadFile(genesis)
if err != nil {
Fatalf("Failed to load custom genesis file: %v", err)
}
return string(data)
}
// MakeDatabaseHandles raises out the number of allowed file handles per process // MakeDatabaseHandles raises out the number of allowed file handles per process
// for Geth and returns half of the allowance to assign to the database. // for Geth and returns half of the allowance to assign to the database.
func MakeDatabaseHandles() int { func MakeDatabaseHandles() int {
...@@ -689,7 +680,6 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte, ...@@ -689,7 +680,6 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte,
ethConf := &eth.Config{ ethConf := &eth.Config{
ChainConfig: MustMakeChainConfig(ctx), ChainConfig: MustMakeChainConfig(ctx),
Genesis: MakeGenesisBlock(ctx),
FastSync: ctx.GlobalBool(FastSyncFlag.Name), FastSync: ctx.GlobalBool(FastSyncFlag.Name),
BlockChainVersion: ctx.GlobalInt(BlockchainVersionFlag.Name), BlockChainVersion: ctx.GlobalInt(BlockchainVersionFlag.Name),
DatabaseCache: ctx.GlobalInt(CacheFlag.Name), DatabaseCache: ctx.GlobalInt(CacheFlag.Name),
...@@ -722,17 +712,13 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte, ...@@ -722,17 +712,13 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte,
if !ctx.GlobalIsSet(NetworkIdFlag.Name) { if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
ethConf.NetworkId = 1 ethConf.NetworkId = 1
} }
if !ctx.GlobalIsSet(GenesisFileFlag.Name) {
ethConf.Genesis = core.OlympicGenesisBlock() ethConf.Genesis = core.OlympicGenesisBlock()
}
case ctx.GlobalBool(TestNetFlag.Name): case ctx.GlobalBool(TestNetFlag.Name):
if !ctx.GlobalIsSet(NetworkIdFlag.Name) { if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
ethConf.NetworkId = 2 ethConf.NetworkId = 2
} }
if !ctx.GlobalIsSet(GenesisFileFlag.Name) {
ethConf.Genesis = core.TestNetGenesisBlock() ethConf.Genesis = core.TestNetGenesisBlock()
}
state.StartingNonce = 1048576 // (2**20) state.StartingNonce = 1048576 // (2**20)
case ctx.GlobalBool(DevModeFlag.Name): case ctx.GlobalBool(DevModeFlag.Name):
...@@ -747,9 +733,7 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte, ...@@ -747,9 +733,7 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte,
stackConf.ListenAddr = ":0" stackConf.ListenAddr = ":0"
} }
// Override the Ethereum protocol configs // Override the Ethereum protocol configs
if !ctx.GlobalIsSet(GenesisFileFlag.Name) {
ethConf.Genesis = core.OlympicGenesisBlock() ethConf.Genesis = core.OlympicGenesisBlock()
}
if !ctx.GlobalIsSet(GasPriceFlag.Name) { if !ctx.GlobalIsSet(GasPriceFlag.Name) {
ethConf.GasPrice = new(big.Int) ethConf.GasPrice = new(big.Int)
} }
...@@ -813,24 +797,44 @@ func MustMakeChainConfig(ctx *cli.Context) *core.ChainConfig { ...@@ -813,24 +797,44 @@ func MustMakeChainConfig(ctx *cli.Context) *core.ChainConfig {
// MustMakeChainConfigFromDb reads the chain configuration from the given database. // MustMakeChainConfigFromDb reads the chain configuration from the given database.
func MustMakeChainConfigFromDb(ctx *cli.Context, db ethdb.Database) *core.ChainConfig { func MustMakeChainConfigFromDb(ctx *cli.Context, db ethdb.Database) *core.ChainConfig {
genesis := core.GetBlock(db, core.GetCanonicalHash(db, 0), 0) // If the chain is already initialized, use any existing chain configs
if genesis := core.GetBlock(db, core.GetCanonicalHash(db, 0), 0); genesis != nil {
if genesis != nil {
// Existing genesis block, use stored config if available.
storedConfig, err := core.GetChainConfig(db, genesis.Hash()) storedConfig, err := core.GetChainConfig(db, genesis.Hash())
if err == nil { if err == nil {
// Force override any existing configs if explicitly requested
switch {
case storedConfig.DAOForkBlock == nil && ctx.GlobalBool(SupportDAOFork.Name) && ctx.GlobalBool(TestNetFlag.Name):
storedConfig.DAOForkBlock = params.TestNetDAOForkBlock
case storedConfig.DAOForkBlock == nil && ctx.GlobalBool(SupportDAOFork.Name):
storedConfig.DAOForkBlock = params.MainNetDAOForkBlock
case ctx.GlobalBool(OpposeDAOFork.Name):
storedConfig.DAOForkBlock = nil
}
return storedConfig return storedConfig
} else if err != core.ChainConfigNotFoundErr { } else if err != core.ChainConfigNotFoundErr {
Fatalf("Could not make chain configuration: %v", err) Fatalf("Could not make chain configuration: %v", err)
} }
} }
var homesteadBlockNo *big.Int // If the chain is uninitialized nor no configs are present, create one
var homesteadBlock *big.Int
if ctx.GlobalBool(TestNetFlag.Name) { if ctx.GlobalBool(TestNetFlag.Name) {
homesteadBlockNo = params.TestNetHomesteadBlock homesteadBlock = params.TestNetHomesteadBlock
} else { } else {
homesteadBlockNo = params.MainNetHomesteadBlock homesteadBlock = params.MainNetHomesteadBlock
}
var daoForkBlock *big.Int
switch {
case ctx.GlobalBool(SupportDAOFork.Name) && ctx.GlobalBool(TestNetFlag.Name):
daoForkBlock = params.TestNetDAOForkBlock
case ctx.GlobalBool(SupportDAOFork.Name):
daoForkBlock = params.MainNetDAOForkBlock
case ctx.GlobalBool(OpposeDAOFork.Name):
daoForkBlock = nil
}
return &core.ChainConfig{
HomesteadBlock: homesteadBlock,
DAOForkBlock: daoForkBlock,
} }
return &core.ChainConfig{HomesteadBlock: homesteadBlockNo}
} }
// MakeChainDatabase open an LevelDB using the flags passed to the client and will hard crash if it fails. // MakeChainDatabase open an LevelDB using the flags passed to the client and will hard crash if it fails.
......
...@@ -31,7 +31,8 @@ var ChainConfigNotFoundErr = errors.New("ChainConfig not found") // general conf ...@@ -31,7 +31,8 @@ var ChainConfigNotFoundErr = errors.New("ChainConfig not found") // general conf
// that any network, identified by its genesis block, can have its own // that any network, identified by its genesis block, can have its own
// set of configuration options. // set of configuration options.
type ChainConfig struct { type ChainConfig struct {
HomesteadBlock *big.Int // homestead switch block HomesteadBlock *big.Int `json:"homesteadBlock"` // homestead switch block (0 = already homestead)
DAOForkBlock *big.Int `json:"daoForkBlock"` // TheDAO hard-fork block (nil = no fork)
VmConfig vm.Config `json:"-"` VmConfig vm.Config `json:"-"`
} }
...@@ -41,6 +42,5 @@ func (c *ChainConfig) IsHomestead(num *big.Int) bool { ...@@ -41,6 +42,5 @@ func (c *ChainConfig) IsHomestead(num *big.Int) bool {
if num == nil { if num == nil {
return false return false
} }
return num.Cmp(c.HomesteadBlock) >= 0 return num.Cmp(c.HomesteadBlock) >= 0
} }
...@@ -205,6 +205,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { ...@@ -205,6 +205,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
if config.ChainConfig == nil { if config.ChainConfig == nil {
return nil, errors.New("missing chain config") return nil, errors.New("missing chain config")
} }
core.WriteChainConfig(chainDb, genesis.Hash(), config.ChainConfig)
eth.chainConfig = config.ChainConfig eth.chainConfig = config.ChainConfig
eth.chainConfig.VmConfig = vm.Config{ eth.chainConfig.VmConfig = vm.Config{
EnableJit: config.EnableJit, EnableJit: config.EnableJit,
......
...@@ -21,4 +21,6 @@ import "math/big" ...@@ -21,4 +21,6 @@ import "math/big"
var ( var (
TestNetHomesteadBlock = big.NewInt(494000) // testnet homestead block TestNetHomesteadBlock = big.NewInt(494000) // testnet homestead block
MainNetHomesteadBlock = big.NewInt(1150000) // mainnet homestead block MainNetHomesteadBlock = big.NewInt(1150000) // mainnet homestead block
TestNetDAOForkBlock = big.NewInt(8888888) // testnet dao hard-fork block
MainNetDAOForkBlock = big.NewInt(9999999) // mainnet dao hard-fork block
) )
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment