mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
validate development mode genesis configuration
This commit is contained in:
parent
a3be38127c
commit
ca2e9775ca
3 changed files with 46 additions and 6 deletions
|
|
@ -1646,6 +1646,43 @@ func CheckExclusive(ctx *cli.Context, args ...interface{}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func validateDeveloperGenesis(genesis *core.Genesis) error {
|
||||||
|
checkHFIsZero := func(forkName string, hfBlockNumber *big.Int) error {
|
||||||
|
if hfBlockNumber == nil {
|
||||||
|
return errors.New(fmt.Sprintf("%s: hard-fork not enabled", forkName))
|
||||||
|
} else if hfBlockNumber.Cmp(big.NewInt(0)) != 0 {
|
||||||
|
return errors.New(fmt.Sprintf("%s: hard-fork not activated in block 0", forkName))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
config := genesis.Config
|
||||||
|
if err := checkHFIsZero("Homestead", config.HomesteadBlock); err != nil {
|
||||||
|
return err
|
||||||
|
} else if config.DAOForkBlock != nil {
|
||||||
|
return errors.New("DAO hardfork cannot be enabled")
|
||||||
|
} else if err := checkHFIsZero("EIP150", config.EIP150Block); err != nil {
|
||||||
|
return err
|
||||||
|
} else if err := checkHFIsZero("EIP155", config.EIP155Block); err != nil {
|
||||||
|
return err
|
||||||
|
} else if err := checkHFIsZero("EIP158", config.EIP158Block); err != nil {
|
||||||
|
return err
|
||||||
|
} else if err := checkHFIsZero("Byzantium", config.ByzantiumBlock); err != nil {
|
||||||
|
return err
|
||||||
|
} else if err := checkHFIsZero("Constantinople", config.ConstantinopleBlock); err != nil {
|
||||||
|
return err
|
||||||
|
} else if err := checkHFIsZero("Istanbul", config.IstanbulBlock); err != nil {
|
||||||
|
return err
|
||||||
|
} else if err := checkHFIsZero("Berlin", config.BerlinBlock); err != nil {
|
||||||
|
return err
|
||||||
|
} else if err := checkHFIsZero("London", config.LondonBlock); err != nil {
|
||||||
|
return err
|
||||||
|
} else if config.TerminalTotalDifficultyPassed != true {
|
||||||
|
return errors.New("terminal total difficulty must be passed")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// SetEthConfig applies eth-related command line flags to the config.
|
// SetEthConfig applies eth-related command line flags to the config.
|
||||||
func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
|
func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
|
||||||
// Avoid conflicting network flags
|
// Avoid conflicting network flags
|
||||||
|
|
@ -1870,6 +1907,15 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
|
||||||
chaindb := tryMakeReadOnlyDatabase(ctx, stack)
|
chaindb := tryMakeReadOnlyDatabase(ctx, stack)
|
||||||
if rawdb.ReadCanonicalHash(chaindb, 0) != (common.Hash{}) {
|
if rawdb.ReadCanonicalHash(chaindb, 0) != (common.Hash{}) {
|
||||||
cfg.Genesis = nil // fallback to db content
|
cfg.Genesis = nil // fallback to db content
|
||||||
|
|
||||||
|
var genesis *core.Genesis
|
||||||
|
var err error
|
||||||
|
if genesis, err = core.ReadGenesis(chaindb); err != nil {
|
||||||
|
Fatalf("could not read genesis from database: %v", err)
|
||||||
|
}
|
||||||
|
if err = validateDeveloperGenesis(genesis); err != nil {
|
||||||
|
Fatalf("genesis configuration incompatible with development mode: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
chaindb.Close()
|
chaindb.Close()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,10 +82,6 @@ type SimulatedBeacon struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSimulatedBeacon(period uint64, eth *eth.Ethereum) (*SimulatedBeacon, error) {
|
func NewSimulatedBeacon(period uint64, eth *eth.Ethereum) (*SimulatedBeacon, error) {
|
||||||
chainConfig := eth.APIBackend.ChainConfig()
|
|
||||||
if !chainConfig.IsDevMode {
|
|
||||||
return nil, errors.New("incompatible pre-existing chain configuration")
|
|
||||||
}
|
|
||||||
block := eth.BlockChain().CurrentBlock()
|
block := eth.BlockChain().CurrentBlock()
|
||||||
current := engine.ForkchoiceStateV1{
|
current := engine.ForkchoiceStateV1{
|
||||||
HeadBlockHash: block.Hash(),
|
HeadBlockHash: block.Hash(),
|
||||||
|
|
|
||||||
|
|
@ -180,7 +180,6 @@ var (
|
||||||
ShanghaiTime: newUint64(0),
|
ShanghaiTime: newUint64(0),
|
||||||
TerminalTotalDifficulty: big.NewInt(0),
|
TerminalTotalDifficulty: big.NewInt(0),
|
||||||
TerminalTotalDifficultyPassed: true,
|
TerminalTotalDifficultyPassed: true,
|
||||||
IsDevMode: true,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AllCliqueProtocolChanges contains every protocol change (EIPs) introduced
|
// AllCliqueProtocolChanges contains every protocol change (EIPs) introduced
|
||||||
|
|
@ -331,7 +330,6 @@ type ChainConfig struct {
|
||||||
// Various consensus engines
|
// Various consensus engines
|
||||||
Ethash *EthashConfig `json:"ethash,omitempty"`
|
Ethash *EthashConfig `json:"ethash,omitempty"`
|
||||||
Clique *CliqueConfig `json:"clique,omitempty"`
|
Clique *CliqueConfig `json:"clique,omitempty"`
|
||||||
IsDevMode bool `json:"isDev,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// EthashConfig is the consensus engine configs for proof-of-work based sealing.
|
// EthashConfig is the consensus engine configs for proof-of-work based sealing.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue