@@ -34,7 +34,6 @@ import (
3434 "github.com/ethereum/go-ethereum/common"
3535 "github.com/ethereum/go-ethereum/core"
3636 "github.com/ethereum/go-ethereum/core/state"
37- "github.com/ethereum/go-ethereum/core/vm"
3837 "github.com/ethereum/go-ethereum/crypto"
3938 "github.com/ethereum/go-ethereum/eth"
4039 "github.com/ethereum/go-ethereum/ethdb"
@@ -173,6 +172,11 @@ var (
173172 Name : "minergpus" ,
174173 Usage : "List of GPUs to use for mining (e.g. '0,1' will use the first two GPUs found)" ,
175174 }
175+ TargetGasLimitFlag = cli.StringFlag {
176+ Name : "targetgaslimit" ,
177+ Usage : "Target gas limit sets the artificial target gas floor for the blocks to mine" ,
178+ Value : params .GenesisGasLimit .String (),
179+ }
176180 AutoDAGFlag = cli.BoolFlag {
177181 Name : "autodag" ,
178182 Usage : "Enable automatic DAG pregeneration" ,
@@ -656,6 +660,7 @@ func MakeSystemNode(name, version string, extra []byte, ctx *cli.Context) *node.
656660 accman := MakeAccountManager (ctx )
657661
658662 ethConf := & eth.Config {
663+ ChainConfig : MustMakeChainConfig (ctx ),
659664 Genesis : MakeGenesisBlock (ctx ),
660665 FastSync : ctx .GlobalBool (FastSyncFlag .Name ),
661666 BlockChainVersion : ctx .GlobalInt (BlockchainVersionFlag .Name ),
@@ -701,8 +706,6 @@ func MakeSystemNode(name, version string, extra []byte, ctx *cli.Context) *node.
701706 ethConf .Genesis = core .TestNetGenesisBlock ()
702707 }
703708 state .StartingNonce = 1048576 // (2**20)
704- // overwrite homestead block
705- params .HomesteadBlock = params .TestNetHomesteadBlock
706709
707710 case ctx .GlobalBool (DevModeFlag .Name ):
708711 // Override the base network stack configs
@@ -758,36 +761,67 @@ func SetupNetwork(ctx *cli.Context) {
758761 core .BlockReward = big .NewInt (1.5e+18 )
759762 core .ExpDiffPeriod = big .NewInt (math .MaxInt64 )
760763 }
764+ params .TargetGasLimit = common .String2Big (ctx .GlobalString (TargetGasLimitFlag .Name ))
761765}
762766
763- // SetupVM configured the VM package's global settings
764- func SetupVM (ctx * cli.Context ) {
765- vm .EnableJit = ctx .GlobalBool (VMEnableJitFlag .Name )
766- vm .ForceJit = ctx .GlobalBool (VMForceJitFlag .Name )
767- vm .SetJITCacheSize (ctx .GlobalInt (VMJitCacheFlag .Name ))
767+ // MustMakeChainConfig reads the chain configuration from the given database.
768+ func MustMakeChainConfig (ctx * cli.Context ) * core.ChainConfig {
769+ var (
770+ db = MakeChainDatabase (ctx )
771+ genesis = core .GetBlock (db , core .GetCanonicalHash (db , 0 ))
772+ )
773+ defer db .Close ()
774+
775+ chainConfig , err := core .GetChainConfig (db , genesis .Hash ())
776+ if err != nil {
777+ if err != core .ChainConfigNotFoundErr {
778+ Fatalf ("Could not make chain configuration: %v" , err )
779+ }
780+ var homesteadBlockNo * big.Int
781+ if ctx .GlobalBool (TestNetFlag .Name ) {
782+ homesteadBlockNo = params .TestNetHomesteadBlock
783+ } else {
784+ homesteadBlockNo = params .MainNetHomesteadBlock
785+ }
786+
787+ chainConfig = & core.ChainConfig {
788+ HomesteadBlock : homesteadBlockNo ,
789+ }
790+ }
791+ return chainConfig
768792}
769793
770- // MakeChain creates a chain manager from set command line flags.
771- func MakeChain (ctx * cli.Context ) (chain * core.BlockChain , chainDb ethdb.Database ) {
772- datadir := MustMakeDataDir (ctx )
773- cache := ctx .GlobalInt (CacheFlag .Name )
774- handles := MakeDatabaseHandles ()
794+ // MakeChainDatabase open an LevelDB using the flags passed to the client and will hard crash if it fails.
795+ func MakeChainDatabase (ctx * cli.Context ) ethdb.Database {
796+ var (
797+ datadir = MustMakeDataDir (ctx )
798+ cache = ctx .GlobalInt (CacheFlag .Name )
799+ handles = MakeDatabaseHandles ()
800+ )
775801
776- var err error
777- if chainDb , err = ethdb . NewLDBDatabase ( filepath . Join ( datadir , "chaindata" ), cache , handles ); err != nil {
802+ chainDb , err := ethdb . NewLDBDatabase ( filepath . Join ( datadir , "chaindata" ), cache , handles )
803+ if err != nil {
778804 Fatalf ("Could not open database: %v" , err )
779805 }
806+ return chainDb
807+ }
808+
809+ // MakeChain creates a chain manager from set command line flags.
810+ func MakeChain (ctx * cli.Context ) (chain * core.BlockChain , chainDb ethdb.Database ) {
811+ var err error
812+ chainDb = MakeChainDatabase (ctx )
813+
780814 if ctx .GlobalBool (OlympicFlag .Name ) {
781815 _ , err := core .WriteTestNetGenesisBlock (chainDb )
782816 if err != nil {
783817 glog .Fatalln (err )
784818 }
785819 }
786820
787- eventMux := new (event. TypeMux )
788- pow := ethash . New ()
789- //genesis := core.GenesisBlock(uint64(ctx.GlobalInt(GenesisNonceFlag.Name)), blockDB)
790- chain , err = core .NewBlockChain (chainDb , pow , eventMux )
821+ chainConfig := MustMakeChainConfig ( ctx )
822+
823+ var eventMux event. TypeMux
824+ chain , err = core .NewBlockChain (chainDb , chainConfig , ethash . New (), & eventMux )
791825 if err != nil {
792826 Fatalf ("Could not start chainmanager: %v" , err )
793827 }
0 commit comments