aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/utils
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-07-07 21:04:34 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-07-15 21:52:55 +0800
commit6060e098c929792f455d7f580ed91e914d28cf3b (patch)
tree1518c9572c5c5609069e6d6c8d03fdf261fd4ad8 /cmd/utils
parentaa1e052cb41c39363a9930added46dac5b6db832 (diff)
downloaddexon-6060e098c929792f455d7f580ed91e914d28cf3b.tar
dexon-6060e098c929792f455d7f580ed91e914d28cf3b.tar.gz
dexon-6060e098c929792f455d7f580ed91e914d28cf3b.tar.bz2
dexon-6060e098c929792f455d7f580ed91e914d28cf3b.tar.lz
dexon-6060e098c929792f455d7f580ed91e914d28cf3b.tar.xz
dexon-6060e098c929792f455d7f580ed91e914d28cf3b.tar.zst
dexon-6060e098c929792f455d7f580ed91e914d28cf3b.zip
cmd, core, eth, params: implement flags to control dao fork blocks
Diffstat (limited to 'cmd/utils')
-rw-r--r--cmd/utils/flags.go76
1 files changed, 40 insertions, 36 deletions
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index 38ba3a9ba..b95f5159c 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -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.