Skip to content

Commit

Permalink
Bakes in iliad configuration and more sane data folder defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
leeren committed Aug 16, 2024
1 parent 820a852 commit a6e403a
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 5 deletions.
23 changes: 22 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,11 @@ var (
TakesFile: true,
Category: flags.MiscCategory,
}
IliadFlag = &cli.BoolFlag{
Name: "iliad",
Usage: "iliad test network: pre-configured proof-of-stake test network",
Category: flags.MiscCategory,
}

// RPC settings
IPCDisabledFlag = &cli.BoolFlag{
Expand Down Expand Up @@ -967,6 +972,7 @@ var (
GoerliFlag,
SepoliaFlag,
HoleskyFlag,
IliadFlag,
}
// NetworkFlags is the flag group of all built-in supported networks.
NetworkFlags = append([]cli.Flag{MainnetFlag}, TestnetFlags...)
Expand Down Expand Up @@ -996,6 +1002,9 @@ func MakeDataDir(ctx *cli.Context) string {
if ctx.Bool(HoleskyFlag.Name) {
return filepath.Join(path, "holesky")
}
if ctx.Bool(IliadFlag.Name) {
return filepath.Join(path, "iliad")
}
return path
}
Fatalf("Cannot determine default data directory, please set manually (--datadir)")
Expand Down Expand Up @@ -1058,6 +1067,8 @@ func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
urls = params.SepoliaBootnodes
case ctx.Bool(GoerliFlag.Name):
urls = params.GoerliBootnodes
case ctx.Bool(IliadFlag.Name):
urls = params.IliadBootnodes
}
}
cfg.BootstrapNodes = mustParseBootnodes(urls)
Expand Down Expand Up @@ -1489,6 +1500,8 @@ func SetDataDir(ctx *cli.Context, cfg *node.Config) {
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "sepolia")
case ctx.Bool(HoleskyFlag.Name) && cfg.DataDir == node.DefaultDataDir():
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "holesky")
case ctx.Bool(IliadFlag.Name) && cfg.DataDir == node.DefaultDataDir():
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "iliad")
}
}

Expand Down Expand Up @@ -1644,7 +1657,7 @@ func CheckExclusive(ctx *cli.Context, args ...interface{}) {
// SetEthConfig applies eth-related command line flags to the config.
func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
// Avoid conflicting network flags
CheckExclusive(ctx, MainnetFlag, DeveloperFlag, GoerliFlag, SepoliaFlag, HoleskyFlag)
CheckExclusive(ctx, MainnetFlag, DeveloperFlag, GoerliFlag, SepoliaFlag, HoleskyFlag, IliadFlag)
CheckExclusive(ctx, DeveloperFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer

// Set configurations from CLI flags
Expand Down Expand Up @@ -1819,6 +1832,12 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
}
cfg.Genesis = core.DefaultGoerliGenesisBlock()
SetDNSDiscoveryDefaults(cfg, params.GoerliGenesisHash)
case ctx.Bool(IliadFlag.Name):
if !ctx.IsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 1723217281
}
cfg.Genesis = core.DefaultIliadGenesisBlock()
SetDNSDiscoveryDefaults(cfg, params.IliadGenesisHash)
case ctx.Bool(DeveloperFlag.Name):
if !ctx.IsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 1337
Expand Down Expand Up @@ -2142,6 +2161,8 @@ func MakeGenesis(ctx *cli.Context) *core.Genesis {
genesis = core.DefaultSepoliaGenesisBlock()
case ctx.Bool(GoerliFlag.Name):
genesis = core.DefaultGoerliGenesisBlock()
case ctx.Bool(IliadFlag.Name):
genesis = core.DefaultIliadGenesisBlock()
case ctx.Bool(DeveloperFlag.Name):
Fatalf("Developer chains are ephemeral")
}
Expand Down
19 changes: 19 additions & 0 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ func getGenesisState(db ethdb.Database, blockhash common.Hash) (alloc types.Gene
genesis = DefaultSepoliaGenesisBlock()
case params.HoleskyGenesisHash:
genesis = DefaultHoleskyGenesisBlock()
case params.IliadGenesisHash:
genesis = DefaultIliadGenesisBlock()
}
if genesis != nil {
return genesis.Alloc, nil
Expand Down Expand Up @@ -294,6 +296,8 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *triedb.Database, g
if err != nil {
return genesis.Config, common.Hash{}, err
}
hash := genesis.ToBlock().Hash()
log.Info("Genesis Block Hash", "hash", hash.Hex())
return genesis.Config, block.Hash(), nil
}
// The genesis block is present(perhaps in ancient database) while the
Expand Down Expand Up @@ -409,6 +413,8 @@ func (g *Genesis) configOrDefault(ghash common.Hash) *params.ChainConfig {
return params.SepoliaChainConfig
case ghash == params.GoerliGenesisHash:
return params.GoerliChainConfig
case ghash == params.IliadGenesisHash:
return params.IliadChainConfig
default:
return params.AllEthashProtocolChanges
}
Expand Down Expand Up @@ -572,6 +578,18 @@ func DefaultHoleskyGenesisBlock() *Genesis {
}
}

// DefaultIliadGenesisBlock returns the iliad network genesis block.
func DefaultIliadGenesisBlock() *Genesis {
return &Genesis{
Config: params.IliadChainConfig,
Difficulty: big.NewInt(0x20000),
GasLimit: 0x7A1200,
Nonce: 0x42,
Timestamp: 0,
Alloc: decodePrealloc(iliadAllocData),
}
}

// DeveloperGenesisBlock returns the 'geth --dev' genesis block.
func DeveloperGenesisBlock(gasLimit uint64, faucet *common.Address) *Genesis {
// Override the default period to the user requested one
Expand All @@ -593,6 +611,7 @@ func DeveloperGenesisBlock(gasLimit uint64, faucet *common.Address) *Genesis {
common.BytesToAddress([]byte{7}): {Balance: big.NewInt(1)}, // ECScalarMul
common.BytesToAddress([]byte{8}): {Balance: big.NewInt(1)}, // ECPairing
common.BytesToAddress([]byte{9}): {Balance: big.NewInt(1)}, // BLAKE2b

// Pre-deploy EIP-4788 system contract
params.BeaconRootsAddress: {Nonce: 1, Code: params.BeaconRootsCode, Balance: common.Big0},
},
Expand Down
1 change: 1 addition & 0 deletions core/genesis_alloc.go

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions core/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ func testSetupGenesis(t *testing.T, scheme string) {
wantHash: params.GoerliGenesisHash,
wantConfig: params.GoerliChainConfig,
},
{
name: "custom block in DB, genesis == iliad",
fn: func(db ethdb.Database) (*params.ChainConfig, common.Hash, error) {
tdb := triedb.NewDatabase(db, newDbConfig(scheme))
customg.Commit(db, tdb)
return SetupGenesisBlock(db, tdb, DefaultIliadGenesisBlock())
},
wantErr: &GenesisMismatchError{Stored: customghash, New: params.IliadGenesisHash},
wantHash: params.IliadGenesisHash,
wantConfig: params.IliadChainConfig,
},
{
name: "compatible config in DB",
fn: func(db ethdb.Database) (*params.ChainConfig, common.Hash, error) {
Expand Down Expand Up @@ -186,6 +197,7 @@ func TestGenesisHashes(t *testing.T) {
{DefaultGenesisBlock(), params.MainnetGenesisHash},
{DefaultGoerliGenesisBlock(), params.GoerliGenesisHash},
{DefaultSepoliaGenesisBlock(), params.SepoliaGenesisHash},
{DefaultIliadGenesisBlock(), params.IliadGenesisHash},
} {
// Test via MustCommit
db := rawdb.NewMemoryDatabase()
Expand Down
8 changes: 4 additions & 4 deletions node/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,19 @@ func DefaultDataDir() string {
if home != "" {
switch runtime.GOOS {
case "darwin":
return filepath.Join(home, "Library", "Ethereum")
return filepath.Join(home, "Library", "Story", "geth")
case "windows":
// We used to put everything in %HOME%\AppData\Roaming, but this caused
// problems with non-typical setups. If this fallback location exists and
// is non-empty, use it, otherwise DTRT and check %LOCALAPPDATA%.
fallback := filepath.Join(home, "AppData", "Roaming", "Ethereum")
fallback := filepath.Join(home, "AppData", "Roaming", "Story", "geth")
appdata := windowsAppData()
if appdata == "" || isNonEmptyDir(fallback) {
return fallback
}
return filepath.Join(appdata, "Ethereum")
return filepath.Join(appdata, "Story", "geth")
default:
return filepath.Join(home, ".ethereum")
return filepath.Join(home, ".story", "geth")
}
}
// As we cannot guess a stable location, return empty and handle later
Expand Down
9 changes: 9 additions & 0 deletions params/bootnodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ var SepoliaBootnodes = []string{
"enode://9e9492e2e8836114cc75f5b929784f4f46c324ad01daf87d956f98b3b6c5fcba95524d6e5cf9861dc96a2c8a171ea7105bb554a197455058de185fa870970c7c@138.68.123.152:30303", // sepolia-bootnode-1-ams3
}

// IliadBootnodes are the enode URLs of the P2P bootstrap nodes running on the
// Iliad test network.
var IliadBootnodes = []string{
// Upstream bootnodes
"enode://5e7587609f641724d5ba7de6da94c4c95ccd22219c79e6c7b68b7779fc7e3ef0d02d59d7237cb3f524b432edde5d14d6251afb313d153391cc9bcf6cf4b0e146@44.214.162.88:30303",

"enode://42a60e0f30de311f9e38351901848bb78956f68131569cc1ff460113c948eb67df812da4998aab6c2ac0e10ef365648fd968996e68953df29e10370607a51d9e@50.18.191.26:30303",
}

// GoerliBootnodes are the enode URLs of the P2P bootstrap nodes running on the
// Görli test network.
var GoerliBootnodes = []string{
Expand Down
23 changes: 23 additions & 0 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var (
HoleskyGenesisHash = common.HexToHash("0xb5f7f912443c940f21fd611f12828d75b534364ed9e95ca4e307729a4661bde4")
SepoliaGenesisHash = common.HexToHash("0x25a5cc106eea7138acab33231d7160d69cb777ee0c2c553fcddf5138993e6dd9")
GoerliGenesisHash = common.HexToHash("0xbf7e331f7f7c1dd2e05159666b3bf8bc7a8a3a9eb1d518969eab529dd9b88c1a")
IliadGenesisHash = common.HexToHash("0x47ca9ec3d82d73a707260c984b948b5f163dc78fd27c0703ca5541cbc218873d")
)

func newUint64(val uint64) *uint64 { return &val }
Expand Down Expand Up @@ -137,6 +138,27 @@ var (
Epoch: 30000,
},
}

IliadChainConfig = &ChainConfig{
ChainID: big.NewInt(1513),
HomesteadBlock: big.NewInt(0),
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),
BerlinBlock: big.NewInt(0),
LondonBlock: big.NewInt(0),
ArrowGlacierBlock: big.NewInt(0),
GrayGlacierBlock: big.NewInt(0),
TerminalTotalDifficulty: big.NewInt(0),
TerminalTotalDifficultyPassed: true,
ShanghaiTime: newUint64(0),
CancunTime: newUint64(0),
}

// AllEthashProtocolChanges contains every protocol change (EIPs) introduced
// and accepted by the Ethereum core developers into the Ethash consensus.
AllEthashProtocolChanges = &ChainConfig{
Expand Down Expand Up @@ -316,6 +338,7 @@ var NetworkNames = map[string]string{
GoerliChainConfig.ChainID.String(): "goerli",
SepoliaChainConfig.ChainID.String(): "sepolia",
HoleskyChainConfig.ChainID.String(): "holesky",
IliadChainConfig.ChainID.String(): "iliad",
}

// ChainConfig is the core config which determines the blockchain settings.
Expand Down

0 comments on commit a6e403a

Please sign in to comment.