cmd, core, params: add support for the Ephemery testnet

This commit is contained in:
atkinsonholly 2024-07-23 07:31:31 +01:00
parent ef583e9d18
commit 1fc0e579e6
6 changed files with 136 additions and 11 deletions

View file

@ -298,6 +298,9 @@ func prepare(ctx *cli.Context) {
case ctx.IsSet(utils.HoleskyFlag.Name): case ctx.IsSet(utils.HoleskyFlag.Name):
log.Info("Starting Geth on Holesky testnet...") log.Info("Starting Geth on Holesky testnet...")
case ctx.IsSet(utils.EphemeryFlag.Name):
log.Info("Starting Geth on Ephemery testnet...")
case ctx.IsSet(utils.DeveloperFlag.Name): case ctx.IsSet(utils.DeveloperFlag.Name):
log.Info("Starting Geth in ephemeral dev mode...") log.Info("Starting Geth in ephemeral dev mode...")
log.Warn(`You are running Geth in --dev mode. Please note the following: log.Warn(`You are running Geth in --dev mode. Please note the following:
@ -322,7 +325,8 @@ func prepare(ctx *cli.Context) {
// If we're a full node on mainnet without --cache specified, bump default cache allowance // If we're a full node on mainnet without --cache specified, bump default cache allowance
if !ctx.IsSet(utils.CacheFlag.Name) && !ctx.IsSet(utils.NetworkIdFlag.Name) { if !ctx.IsSet(utils.CacheFlag.Name) && !ctx.IsSet(utils.NetworkIdFlag.Name) {
// Make sure we're not on any supported preconfigured testnet either // Make sure we're not on any supported preconfigured testnet either
if !ctx.IsSet(utils.HoleskyFlag.Name) && if !ctx.IsSet(utils.EphemeryFlag.Name) &&
!ctx.IsSet(utils.HoleskyFlag.Name) &&
!ctx.IsSet(utils.SepoliaFlag.Name) && !ctx.IsSet(utils.SepoliaFlag.Name) &&
!ctx.IsSet(utils.GoerliFlag.Name) && !ctx.IsSet(utils.GoerliFlag.Name) &&
!ctx.IsSet(utils.DeveloperFlag.Name) { !ctx.IsSet(utils.DeveloperFlag.Name) {

View file

@ -133,7 +133,7 @@ var (
} }
NetworkIdFlag = &cli.Uint64Flag{ NetworkIdFlag = &cli.Uint64Flag{
Name: "networkid", Name: "networkid",
Usage: "Explicitly set network id (integer)(For testnets: use --goerli, --sepolia, --holesky instead)", Usage: "Explicitly set network id (integer)(For testnets: use --goerli, --sepolia, --holesky, --ephemery instead)",
Value: ethconfig.Defaults.NetworkId, Value: ethconfig.Defaults.NetworkId,
Category: flags.EthCategory, Category: flags.EthCategory,
} }
@ -157,6 +157,11 @@ var (
Usage: "Holesky network: pre-configured proof-of-stake test network", Usage: "Holesky network: pre-configured proof-of-stake test network",
Category: flags.EthCategory, Category: flags.EthCategory,
} }
EphemeryFlag = &cli.BoolFlag{
Name: "ephemery",
Usage: "Ephemery network: pre-configured proof-of-stake test network",
Category: flags.EthCategory,
}
// Dev mode // Dev mode
DeveloperFlag = &cli.BoolFlag{ DeveloperFlag = &cli.BoolFlag{
Name: "dev", Name: "dev",
@ -967,6 +972,7 @@ var (
GoerliFlag, GoerliFlag,
SepoliaFlag, SepoliaFlag,
HoleskyFlag, HoleskyFlag,
EphemeryFlag,
} }
// NetworkFlags is the flag group of all built-in supported networks. // NetworkFlags is the flag group of all built-in supported networks.
NetworkFlags = append([]cli.Flag{MainnetFlag}, TestnetFlags...) NetworkFlags = append([]cli.Flag{MainnetFlag}, TestnetFlags...)
@ -996,6 +1002,9 @@ func MakeDataDir(ctx *cli.Context) string {
if ctx.Bool(HoleskyFlag.Name) { if ctx.Bool(HoleskyFlag.Name) {
return filepath.Join(path, "holesky") return filepath.Join(path, "holesky")
} }
if ctx.Bool(EphemeryFlag.Name) {
return filepath.Join(path, "ephemery")
}
return path return path
} }
Fatalf("Cannot determine default data directory, please set manually (--datadir)") Fatalf("Cannot determine default data directory, please set manually (--datadir)")
@ -1052,6 +1061,8 @@ func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
return // Already set by config file, don't apply defaults. return // Already set by config file, don't apply defaults.
} }
switch { switch {
case ctx.Bool(EphemeryFlag.Name):
urls = params.EphemeryBootnodes
case ctx.Bool(HoleskyFlag.Name): case ctx.Bool(HoleskyFlag.Name):
urls = params.HoleskyBootnodes urls = params.HoleskyBootnodes
case ctx.Bool(SepoliaFlag.Name): case ctx.Bool(SepoliaFlag.Name):
@ -1489,6 +1500,8 @@ func SetDataDir(ctx *cli.Context, cfg *node.Config) {
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "sepolia") cfg.DataDir = filepath.Join(node.DefaultDataDir(), "sepolia")
case ctx.Bool(HoleskyFlag.Name) && cfg.DataDir == node.DefaultDataDir(): case ctx.Bool(HoleskyFlag.Name) && cfg.DataDir == node.DefaultDataDir():
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "holesky") cfg.DataDir = filepath.Join(node.DefaultDataDir(), "holesky")
case ctx.Bool(EphemeryFlag.Name) && cfg.DataDir == node.DefaultDataDir():
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "ephemery")
} }
} }
@ -1644,7 +1657,7 @@ func CheckExclusive(ctx *cli.Context, args ...interface{}) {
// 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
CheckExclusive(ctx, MainnetFlag, DeveloperFlag, GoerliFlag, SepoliaFlag, HoleskyFlag) CheckExclusive(ctx, MainnetFlag, DeveloperFlag, GoerliFlag, SepoliaFlag, HoleskyFlag, EphemeryFlag)
CheckExclusive(ctx, DeveloperFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer CheckExclusive(ctx, DeveloperFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer
// Set configurations from CLI flags // Set configurations from CLI flags
@ -1801,6 +1814,12 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
} }
cfg.Genesis = core.DefaultGenesisBlock() cfg.Genesis = core.DefaultGenesisBlock()
SetDNSDiscoveryDefaults(cfg, params.MainnetGenesisHash) SetDNSDiscoveryDefaults(cfg, params.MainnetGenesisHash)
case ctx.Bool(EphemeryFlag.Name):
cfg.Genesis = core.DefaultEphemeryGenesisBlock()
if !ctx.IsSet(NetworkIdFlag.Name) {
cfg.NetworkId = cfg.Genesis.Config.ChainID.Uint64()
}
SetDNSDiscoveryDefaults(cfg, params.EphemeryGenesisHash)
case ctx.Bool(HoleskyFlag.Name): case ctx.Bool(HoleskyFlag.Name):
if !ctx.IsSet(NetworkIdFlag.Name) { if !ctx.IsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 17000 cfg.NetworkId = 17000
@ -2136,6 +2155,8 @@ func MakeGenesis(ctx *cli.Context) *core.Genesis {
switch { switch {
case ctx.Bool(MainnetFlag.Name): case ctx.Bool(MainnetFlag.Name):
genesis = core.DefaultGenesisBlock() genesis = core.DefaultGenesisBlock()
case ctx.Bool(EphemeryFlag.Name):
genesis = core.DefaultEphemeryGenesisBlock()
case ctx.Bool(HoleskyFlag.Name): case ctx.Bool(HoleskyFlag.Name):
genesis = core.DefaultHoleskyGenesisBlock() genesis = core.DefaultHoleskyGenesisBlock()
case ctx.Bool(SepoliaFlag.Name): case ctx.Bool(SepoliaFlag.Name):

View file

@ -23,6 +23,7 @@ import (
"fmt" "fmt"
"math/big" "math/big"
"strings" "strings"
"time"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
@ -209,6 +210,8 @@ func getGenesisState(db ethdb.Database, blockhash common.Hash) (alloc types.Gene
genesis = DefaultSepoliaGenesisBlock() genesis = DefaultSepoliaGenesisBlock()
case params.HoleskyGenesisHash: case params.HoleskyGenesisHash:
genesis = DefaultHoleskyGenesisBlock() genesis = DefaultHoleskyGenesisBlock()
case params.EphemeryGenesisHash:
genesis = DefaultEphemeryGenesisBlock()
} }
if genesis != nil { if genesis != nil {
return genesis.Alloc, nil return genesis.Alloc, nil
@ -403,6 +406,8 @@ func (g *Genesis) configOrDefault(ghash common.Hash) *params.ChainConfig {
return g.Config return g.Config
case ghash == params.MainnetGenesisHash: case ghash == params.MainnetGenesisHash:
return params.MainnetChainConfig return params.MainnetChainConfig
case ghash == params.EphemeryGenesisHash:
return params.EphemeryChainConfig
case ghash == params.HoleskyGenesisHash: case ghash == params.HoleskyGenesisHash:
return params.HoleskyChainConfig return params.HoleskyChainConfig
case ghash == params.SepoliaGenesisHash: case ghash == params.SepoliaGenesisHash:
@ -572,6 +577,35 @@ func DefaultHoleskyGenesisBlock() *Genesis {
} }
} }
// DefaultEphemeryGenesisBlock returns the Ephemery network genesis block.
func DefaultEphemeryGenesisBlock() *Genesis {
// Calculate the number of ephemery iterations that have elapsed since minGenesisTime to get the latest ChainID
now := time.Now()
minGenesisTimestamp := int64(1638471600)
genesisDelay := uint64(300)
timestamp := time.Unix(minGenesisTimestamp, 0)
difference := now.Sub(timestamp)
differenceInSeconds := difference.Seconds() * float64(time.Nanosecond)
iteration := int64(differenceInSeconds) / int64(params.EphemeryChainConfig.EphemeralTime)
i := big.NewInt(iteration)
params.EphemeryChainConfig.ChainID = new(big.Int).Add(i, params.EphemeryChainConfig.ChainID)
log.Debug("1", "EphemeralTime", params.EphemeryChainConfig.EphemeralTime)
log.Debug("2", "iteration", uint64(iteration))
log.Debug("3", "minGenesisTimestamp", uint64(minGenesisTimestamp))
log.Debug("4", "timestamp", params.EphemeryChainConfig.EphemeralTime*uint64(iteration)+uint64(minGenesisTimestamp)+genesisDelay)
return &Genesis{
Config: params.EphemeryChainConfig,
Nonce: 0x1234,
GasLimit: 0x400000,
Difficulty: big.NewInt(0x01),
Timestamp: (params.EphemeryChainConfig.EphemeralTime * uint64(iteration)) + uint64(minGenesisTimestamp) + genesisDelay,
ExtraData: []byte(""),
Alloc: decodePrealloc(ephemeryAllocData),
}
}
// DeveloperGenesisBlock returns the 'geth --dev' genesis block. // DeveloperGenesisBlock returns the 'geth --dev' genesis block.
func DeveloperGenesisBlock(gasLimit uint64, faucet *common.Address) *Genesis { func DeveloperGenesisBlock(gasLimit uint64, faucet *common.Address) *Genesis {
// Override the default period to the user requested one // Override the default period to the user requested one

File diff suppressed because one or more lines are too long

View file

@ -28,6 +28,14 @@ var MainnetBootnodes = []string{
"enode://4aeb4ab6c14b23e2c4cfdce879c04b0748a20d8e9b59e25ded2a08143e265c6c25936e74cbc8e641e3312ca288673d91f2f93f8e277de3cfa444ecdaaf982052@157.90.35.166:30303", // bootnode-hetzner-fsn "enode://4aeb4ab6c14b23e2c4cfdce879c04b0748a20d8e9b59e25ded2a08143e265c6c25936e74cbc8e641e3312ca288673d91f2f93f8e277de3cfa444ecdaaf982052@157.90.35.166:30303", // bootnode-hetzner-fsn
} }
// EphemeryBootnodes are the enode URLs of the P2P bootstrap nodes running on the
// Ephemery test network.
var EphemeryBootnodes = []string{
// ephemery.dev bootnodes
"enode://50a54ecbd2175497640bcf46a25bbe9bb4fae51d7cc2a29ef4947a7ee17496cf39a699b7fe6b703ed0feb9dbaae7e44fc3827fcb7435ca9ac6de4daa4d983b3d@137.74.203.240:30303",
"enode://0f2c301a9a3f9fa2ccfa362b79552c052905d8c2982f707f46cd29ece5a9e1c14ecd06f4ac951b228f059a43c6284a1a14fce709e8976cac93b50345218bf2e9@135.181.140.168:30343",
}
// HoleskyBootnodes are the enode URLs of the P2P bootstrap nodes running on the // HoleskyBootnodes are the enode URLs of the P2P bootstrap nodes running on the
// Holesky test network. // Holesky test network.
var HoleskyBootnodes = []string{ var HoleskyBootnodes = []string{

View file

@ -27,6 +27,7 @@ import (
// Genesis hashes to enforce below configs on. // Genesis hashes to enforce below configs on.
var ( var (
MainnetGenesisHash = common.HexToHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3") MainnetGenesisHash = common.HexToHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3")
EphemeryGenesisHash = common.HexToHash("0xb62368598318c23ba82921969086f7ab078cad039d84f5cf557812a921535c46")
HoleskyGenesisHash = common.HexToHash("0xb5f7f912443c940f21fd611f12828d75b534364ed9e95ca4e307729a4661bde4") HoleskyGenesisHash = common.HexToHash("0xb5f7f912443c940f21fd611f12828d75b534364ed9e95ca4e307729a4661bde4")
SepoliaGenesisHash = common.HexToHash("0x25a5cc106eea7138acab33231d7160d69cb777ee0c2c553fcddf5138993e6dd9") SepoliaGenesisHash = common.HexToHash("0x25a5cc106eea7138acab33231d7160d69cb777ee0c2c553fcddf5138993e6dd9")
GoerliGenesisHash = common.HexToHash("0xbf7e331f7f7c1dd2e05159666b3bf8bc7a8a3a9eb1d518969eab529dd9b88c1a") GoerliGenesisHash = common.HexToHash("0xbf7e331f7f7c1dd2e05159666b3bf8bc7a8a3a9eb1d518969eab529dd9b88c1a")
@ -61,6 +62,57 @@ var (
CancunTime: newUint64(1710338135), CancunTime: newUint64(1710338135),
Ethash: new(EthashConfig), Ethash: new(EthashConfig),
} }
// EphemeryChainConfig contains the chain parameters to run a node on the Ephemery test network.
EphemeryChainConfig = &ChainConfig{
// TODO: review params
// "config": {
// "chainId": 1337498,
// "homesteadBlock": 0,
// "eip150Block": 0,
// "eip155Block": 0,
// "eip158Block": 0,
// "byzantiumBlock": 0,
// "constantinopleBlock": 0,
// "petersburgBlock": 0,
// "istanbulBlock": 0,
// "berlinBlock": 0,
// "londonBlock": 0,
// "mergeForkBlock": 0,
// "terminalTotalDifficulty": 0,
// "coinbase": "0x0000000000000000000000000000000000000000",
// "difficulty": "0x01",
// "extraData": "",
// "gasLimit": "0x400000",
// "nonce": "0x1234",
// "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
// "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
// "timestamp": "1665428400",
// "ephemeral": 172800
// },
ChainID: big.NewInt(39438000),
HomesteadBlock: big.NewInt(0),
DAOForkBlock: nil,
DAOForkSupport: true,
EIP150Block: big.NewInt(0),
EIP155Block: big.NewInt(0),
EIP158Block: big.NewInt(0),
ByzantiumBlock: big.NewInt(0),
ConstantinopleBlock: big.NewInt(0),
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: nil,
BerlinBlock: big.NewInt(0),
LondonBlock: big.NewInt(0),
ArrowGlacierBlock: nil,
GrayGlacierBlock: nil,
TerminalTotalDifficulty: big.NewInt(0),
TerminalTotalDifficultyPassed: true,
MergeNetsplitBlock: nil,
ShanghaiTime: newUint64(1696000704),
CancunTime: newUint64(1707305664),
Ethash: new(EthashConfig),
EphemeralTime: uint64(604800), // 7 days in seconds TODO: rename as reset
}
// HoleskyChainConfig contains the chain parameters to run a node on the Holesky test network. // HoleskyChainConfig contains the chain parameters to run a node on the Holesky test network.
HoleskyChainConfig = &ChainConfig{ HoleskyChainConfig = &ChainConfig{
ChainID: big.NewInt(17000), ChainID: big.NewInt(17000),
@ -316,6 +368,7 @@ var NetworkNames = map[string]string{
GoerliChainConfig.ChainID.String(): "goerli", GoerliChainConfig.ChainID.String(): "goerli",
SepoliaChainConfig.ChainID.String(): "sepolia", SepoliaChainConfig.ChainID.String(): "sepolia",
HoleskyChainConfig.ChainID.String(): "holesky", HoleskyChainConfig.ChainID.String(): "holesky",
EphemeryChainConfig.ChainID.String(): "ephemery",
} }
// ChainConfig is the core config which determines the blockchain settings. // ChainConfig is the core config which determines the blockchain settings.
@ -368,6 +421,10 @@ 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"`
// EphemeralTime is a flag that is added to support the Ephemery network
// EIP-6916 implements the Ephemery testnet (https://github.com/ethereum/EIPs/blob/master/EIPS/eip-6916.md)
EphemeralTime uint64 `json:"ephemeral"`
} }
// EthashConfig is the consensus engine configs for proof-of-work based sealing. // EthashConfig is the consensus engine configs for proof-of-work based sealing.