Skip to content

Commit d51a9fd

Browse files
committed
cmd, core, params: add --rinkeby flag for fast connectivity
1 parent e1dc7ec commit d51a9fd

File tree

7 files changed

+80
-16
lines changed

7 files changed

+80
-16
lines changed

cmd/geth/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ func init() {
133133
utils.PreloadJSFlag,
134134
utils.WhisperEnabledFlag,
135135
utils.DevModeFlag,
136-
utils.TestNetFlag,
136+
utils.TestnetFlag,
137+
utils.RinkebyFlag,
137138
utils.VMEnableDebugFlag,
138139
utils.NetworkIdFlag,
139140
utils.RPCCORSDomainFlag,

cmd/geth/usage.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ var AppHelpFlagGroups = []flagGroup{
6969
utils.KeyStoreDirFlag,
7070
utils.NoUSBFlag,
7171
utils.NetworkIdFlag,
72-
utils.TestNetFlag,
72+
utils.TestnetFlag,
73+
utils.RinkebyFlag,
7374
utils.DevModeFlag,
7475
utils.SyncModeFlag,
7576
utils.EthStatsURLFlag,

cmd/utils/flags.go

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,17 @@ var (
150150
}
151151
NetworkIdFlag = cli.Uint64Flag{
152152
Name: "networkid",
153-
Usage: "Network identifier (integer, 1=Frontier, 2=Morden (disused), 3=Ropsten)",
153+
Usage: "Network identifier (integer, 1=Frontier, 2=Morden (disused), 3=Ropsten, 4=Rinkeby)",
154154
Value: eth.DefaultConfig.NetworkId,
155155
}
156-
TestNetFlag = cli.BoolFlag{
156+
TestnetFlag = cli.BoolFlag{
157157
Name: "testnet",
158158
Usage: "Ropsten network: pre-configured proof-of-work test network",
159159
}
160+
RinkebyFlag = cli.BoolFlag{
161+
Name: "rinkeby",
162+
Usage: "Rinkeby network: pre-configured proof-of-authority test network",
163+
}
160164
DevModeFlag = cli.BoolFlag{
161165
Name: "dev",
162166
Usage: "Developer mode: pre-configured private network with several debugging flags",
@@ -415,10 +419,12 @@ var (
415419
// the a subdirectory of the specified datadir will be used.
416420
func MakeDataDir(ctx *cli.Context) string {
417421
if path := ctx.GlobalString(DataDirFlag.Name); path != "" {
418-
// TODO: choose a different location outside of the regular datadir.
419-
if ctx.GlobalBool(TestNetFlag.Name) {
422+
if ctx.GlobalBool(TestnetFlag.Name) {
420423
return filepath.Join(path, "testnet")
421424
}
425+
if ctx.GlobalBool(RinkebyFlag.Name) {
426+
return filepath.Join(path, "rinkeby")
427+
}
422428
return path
423429
}
424430
Fatalf("Cannot determine default data directory, please set manually (--datadir)")
@@ -462,10 +468,13 @@ func setNodeUserIdent(ctx *cli.Context, cfg *node.Config) {
462468
// flags, reverting to pre-configured ones if none have been specified.
463469
func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
464470
urls := params.MainnetBootnodes
465-
if ctx.GlobalIsSet(BootnodesFlag.Name) {
471+
switch {
472+
case ctx.GlobalIsSet(BootnodesFlag.Name):
466473
urls = strings.Split(ctx.GlobalString(BootnodesFlag.Name), ",")
467-
} else if ctx.GlobalBool(TestNetFlag.Name) {
474+
case ctx.GlobalBool(TestnetFlag.Name):
468475
urls = params.TestnetBootnodes
476+
case ctx.GlobalBool(RinkebyFlag.Name):
477+
urls = params.RinkebyBootnodes
469478
}
470479

471480
cfg.BootstrapNodes = make([]*discover.Node, 0, len(urls))
@@ -483,9 +492,12 @@ func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
483492
// flags, reverting to pre-configured ones if none have been specified.
484493
func setBootstrapNodesV5(ctx *cli.Context, cfg *p2p.Config) {
485494
urls := params.DiscoveryV5Bootnodes
486-
if ctx.GlobalIsSet(BootnodesFlag.Name) {
495+
switch {
496+
case ctx.GlobalIsSet(BootnodesFlag.Name):
487497
urls = strings.Split(ctx.GlobalString(BootnodesFlag.Name), ",")
488-
} else if cfg.BootstrapNodesV5 == nil {
498+
case ctx.GlobalBool(RinkebyFlag.Name):
499+
urls = params.RinkebyV5Bootnodes
500+
case cfg.BootstrapNodesV5 != nil:
489501
return // already set, don't apply defaults.
490502
}
491503

@@ -723,8 +735,10 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
723735
cfg.DataDir = ctx.GlobalString(DataDirFlag.Name)
724736
case ctx.GlobalBool(DevModeFlag.Name):
725737
cfg.DataDir = filepath.Join(os.TempDir(), "ethereum_dev_mode")
726-
case ctx.GlobalBool(TestNetFlag.Name):
738+
case ctx.GlobalBool(TestnetFlag.Name):
727739
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "testnet")
740+
case ctx.GlobalBool(RinkebyFlag.Name):
741+
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "rinkeby")
728742
}
729743

730744
if ctx.GlobalIsSet(KeyStoreDirFlag.Name) {
@@ -783,7 +797,7 @@ func checkExclusive(ctx *cli.Context, flags ...cli.Flag) {
783797
// SetEthConfig applies eth-related command line flags to the config.
784798
func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
785799
// Avoid conflicting network flags
786-
checkExclusive(ctx, DevModeFlag, TestNetFlag)
800+
checkExclusive(ctx, DevModeFlag, TestnetFlag, RinkebyFlag)
787801
checkExclusive(ctx, FastSyncFlag, LightModeFlag, SyncModeFlag)
788802

789803
ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
@@ -835,13 +849,18 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
835849
cfg.EnablePreimageRecording = ctx.GlobalBool(VMEnableDebugFlag.Name)
836850
}
837851

838-
// Override any default configs for --dev and --testnet.
852+
// Override any default configs for hard coded networks.
839853
switch {
840-
case ctx.GlobalBool(TestNetFlag.Name):
854+
case ctx.GlobalBool(TestnetFlag.Name):
841855
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
842856
cfg.NetworkId = 3
843857
}
844858
cfg.Genesis = core.DefaultTestnetGenesisBlock()
859+
case ctx.GlobalBool(RinkebyFlag.Name):
860+
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
861+
cfg.NetworkId = 4
862+
}
863+
cfg.Genesis = core.DefaultRinkebyGenesisBlock()
845864
case ctx.GlobalBool(DevModeFlag.Name):
846865
cfg.Genesis = core.DevGenesisBlock()
847866
if !ctx.GlobalIsSet(GasPriceFlag.Name) {
@@ -928,8 +947,10 @@ func MakeChainDatabase(ctx *cli.Context, stack *node.Node) ethdb.Database {
928947
func MakeGenesis(ctx *cli.Context) *core.Genesis {
929948
var genesis *core.Genesis
930949
switch {
931-
case ctx.GlobalBool(TestNetFlag.Name):
950+
case ctx.GlobalBool(TestnetFlag.Name):
932951
genesis = core.DefaultTestnetGenesisBlock()
952+
case ctx.GlobalBool(RinkebyFlag.Name):
953+
genesis = core.DefaultRinkebyGenesisBlock()
933954
case ctx.GlobalBool(DevModeFlag.Name):
934955
genesis = core.DevGenesisBlock()
935956
}

core/genesis.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,18 @@ func DefaultTestnetGenesisBlock() *Genesis {
278278
}
279279
}
280280

281+
// DefaultRinkebyGenesisBlock returns the Rinkeby network genesis block.
282+
func DefaultRinkebyGenesisBlock() *Genesis {
283+
return &Genesis{
284+
Config: params.RinkebyChainConfig,
285+
Timestamp: 1492009146,
286+
ExtraData: hexutil.MustDecode("0x52657370656374206d7920617574686f7269746168207e452e436172746d616e42eb768f2244c8811c63729a21a3569731535f067ffc57839b00206d1ad20c69a1981b489f772031b279182d99e65703f0076e4812653aab85fca0f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
287+
GasLimit: 4700000,
288+
Difficulty: big.NewInt(1),
289+
Alloc: decodePrealloc(rinkebyAllocData),
290+
}
291+
}
292+
281293
// DevGenesisBlock returns the 'geth --dev' genesis block.
282294
func DevGenesisBlock() *Genesis {
283295
return &Genesis{

core/genesis_alloc.go

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

params/bootnodes.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ var TestnetBootnodes = []string{
3939
"enode://20c9ad97c081d63397d7b685a412227a40e23c8bdc6688c6f37e97cfbc22d2b4d1db1510d8f61e6a8866ad7f0e17c02b14182d37ea7c3c8b9c2683aeb6b733a1@52.169.14.227:30303", // IE
4040
}
4141

42+
// RinkebyBootnodes are the enode URLs of the P2P bootstrap nodes running on the
43+
// Rinkeby test network.
44+
var RinkebyBootnodes = []string{
45+
"enode://a24ac7c5484ef4ed0c5eb2d36620ba4e4aa13b8c84684e1b4aab0cebea2ae45cb4d375b77eab56516d34bfbd3c1a833fc51296ff084b770b94fb9028c4d25ccf@52.169.42.101:30303", // IE
46+
}
47+
48+
// RinkebyV5Bootnodes are the enode URLs of the P2P bootstrap nodes running on the
49+
// Rinkeby test network for the experimental RLPx v5 topic-discovery network.
50+
var RinkebyV5Bootnodes = []string{
51+
"enode://a24ac7c5484ef4ed0c5eb2d36620ba4e4aa13b8c84684e1b4aab0cebea2ae45cb4d375b77eab56516d34bfbd3c1a833fc51296ff084b770b94fb9028c4d25ccf@52.169.42.101:30303?discport=30304", // IE
52+
}
53+
4254
// DiscoveryV5Bootnodes are the enode URLs of the P2P bootstrap nodes for the
4355
// experimental RLPx v5 topic-discovery network.
4456
var DiscoveryV5Bootnodes = []string{

params/config.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var (
3737
Ethash: new(EthashConfig),
3838
}
3939

40-
// TestnetChainConfig contains the chain parameters to run a node on the ropsten test network.
40+
// TestnetChainConfig contains the chain parameters to run a node on the Ropsten test network.
4141
TestnetChainConfig = &ChainConfig{
4242
ChainId: big.NewInt(3),
4343
HomesteadBlock: big.NewInt(0),
@@ -50,6 +50,22 @@ var (
5050
Ethash: new(EthashConfig),
5151
}
5252

53+
// RinkebyChainConfig contains the chain parameters to run a node on the Rinkeby test network.
54+
RinkebyChainConfig = &ChainConfig{
55+
ChainId: big.NewInt(4),
56+
HomesteadBlock: big.NewInt(1),
57+
DAOForkBlock: nil,
58+
DAOForkSupport: true,
59+
EIP150Block: big.NewInt(2),
60+
EIP150Hash: common.HexToHash("0x9b095b36c15eaf13044373aef8ee0bd3a382a5abb92e402afa44b8249c3a90e9"),
61+
EIP155Block: big.NewInt(3),
62+
EIP158Block: big.NewInt(3),
63+
Clique: &CliqueConfig{
64+
Period: 15,
65+
Epoch: 30000,
66+
},
67+
}
68+
5369
// AllProtocolChanges contains every protocol change (EIPs)
5470
// introduced and accepted by the Ethereum core developers.
5571
// TestChainConfig is like AllProtocolChanges but has chain ID 1.

0 commit comments

Comments
 (0)