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.
utils.IdentityFlag,
utils.UnlockedAccountFlag,
utils.PasswordFileFlag,
utils.GenesisFileFlag,
utils.BootnodesFlag,
utils.DataDirFlag,
utils.KeyStoreDirFlag,
......@@ -165,6 +164,8 @@ participating.
utils.MaxPendingPeersFlag,
utils.EtherbaseFlag,
utils.GasPriceFlag,
utils.SupportDAOFork,
utils.OpposeDAOFork,
utils.MinerThreadsFlag,
utils.MiningEnabledFlag,
utils.MiningGPUFlag,
......@@ -225,12 +226,6 @@ participating.
eth.EnableBadBlockReporting = true
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
}
......
......@@ -68,7 +68,6 @@ var AppHelpFlagGroups = []flagGroup{
utils.OlympicFlag,
utils.TestNetFlag,
utils.DevModeFlag,
utils.GenesisFileFlag,
utils.IdentityFlag,
utils.FastSyncFlag,
utils.LightKDFFlag,
......
......@@ -126,10 +126,6 @@ var (
Name: "dev",
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{
Name: "identity",
Usage: "Custom node name",
......@@ -161,6 +157,15 @@ var (
Name: "lightkdf",
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
// TODO: refactor CPU vs GPU mining flags
MiningEnabledFlag = cli.BoolFlag{
......@@ -534,20 +539,6 @@ func MakeWSRpcHost(ctx *cli.Context) string {
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
// for Geth and returns half of the allowance to assign to the database.
func MakeDatabaseHandles() int {
......@@ -689,7 +680,6 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte,
ethConf := &eth.Config{
ChainConfig: MustMakeChainConfig(ctx),
Genesis: MakeGenesisBlock(ctx),
FastSync: ctx.GlobalBool(FastSyncFlag.Name),
BlockChainVersion: ctx.GlobalInt(BlockchainVersionFlag.Name),
DatabaseCache: ctx.GlobalInt(CacheFlag.Name),
......@@ -722,17 +712,13 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte,
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
ethConf.NetworkId = 1
}
if !ctx.GlobalIsSet(GenesisFileFlag.Name) {
ethConf.Genesis = core.OlympicGenesisBlock()
}
ethConf.Genesis = core.OlympicGenesisBlock()
case ctx.GlobalBool(TestNetFlag.Name):
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
ethConf.NetworkId = 2
}
if !ctx.GlobalIsSet(GenesisFileFlag.Name) {
ethConf.Genesis = core.TestNetGenesisBlock()
}
ethConf.Genesis = core.TestNetGenesisBlock()
state.StartingNonce = 1048576 // (2**20)
case ctx.GlobalBool(DevModeFlag.Name):
......@@ -747,9 +733,7 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte,
stackConf.ListenAddr = ":0"
}
// Override the Ethereum protocol configs
if !ctx.GlobalIsSet(GenesisFileFlag.Name) {
ethConf.Genesis = core.OlympicGenesisBlock()
}
ethConf.Genesis = core.OlympicGenesisBlock()
if !ctx.GlobalIsSet(GasPriceFlag.Name) {
ethConf.GasPrice = new(big.Int)
}
......@@ -813,24 +797,44 @@ func MustMakeChainConfig(ctx *cli.Context) *core.ChainConfig {
// MustMakeChainConfigFromDb reads the chain configuration from the given database.
func MustMakeChainConfigFromDb(ctx *cli.Context, db ethdb.Database) *core.ChainConfig {
genesis := core.GetBlock(db, core.GetCanonicalHash(db, 0), 0)
if genesis != nil {
// Existing genesis block, use stored config if available.
// If the chain is already initialized, use any existing chain configs
if genesis := core.GetBlock(db, core.GetCanonicalHash(db, 0), 0); genesis != nil {
storedConfig, err := core.GetChainConfig(db, genesis.Hash())
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
} else if err != core.ChainConfigNotFoundErr {
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) {
homesteadBlockNo = params.TestNetHomesteadBlock
homesteadBlock = params.TestNetHomesteadBlock
} 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.
......
......@@ -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
// set of configuration options.
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:"-"`
}
......@@ -41,6 +42,5 @@ func (c *ChainConfig) IsHomestead(num *big.Int) bool {
if num == nil {
return false
}
return num.Cmp(c.HomesteadBlock) >= 0
}
......@@ -205,6 +205,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
if config.ChainConfig == nil {
return nil, errors.New("missing chain config")
}
core.WriteChainConfig(chainDb, genesis.Hash(), config.ChainConfig)
eth.chainConfig = config.ChainConfig
eth.chainConfig.VmConfig = vm.Config{
EnableJit: config.EnableJit,
......
......@@ -21,4 +21,6 @@ import "math/big"
var (
TestNetHomesteadBlock = big.NewInt(494000) // testnet 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