cmd/utils: configure DNS names for testnets

This commit is contained in:
Felix Lange 2020-02-09 22:57:23 +01:00
parent c2db1d8a12
commit 5715db6ba7
2 changed files with 27 additions and 3 deletions

View file

@ -1481,9 +1481,8 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
if ctx.GlobalIsSet(RPCGlobalGasCap.Name) {
cfg.RPCGasCap = new(big.Int).SetUint64(ctx.GlobalUint64(RPCGlobalGasCap.Name))
}
if ctx.GlobalIsSet(DisableDNSFlag.Name) {
cfg.DisableDNSDiscovery = ctx.GlobalBool(DisableDNSFlag.Name)
}
// if ctx.GlobalIsSet(DiscoveryURLFlag.Name) {
// }
// Override any default configs for hard coded networks.
switch {
@ -1492,16 +1491,19 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
cfg.NetworkId = 3
}
cfg.Genesis = core.DefaultTestnetGenesisBlock()
setDNSDiscoveryDefaults(ctx, cfg, params.KnownDNSNetworks[params.TestnetGenesisHash])
case ctx.GlobalBool(RinkebyFlag.Name):
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 4
}
cfg.Genesis = core.DefaultRinkebyGenesisBlock()
setDNSDiscoveryDefaults(ctx, cfg, params.KnownDNSNetworks[params.RinkebyGenesisHash])
case ctx.GlobalBool(GoerliFlag.Name):
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 5
}
cfg.Genesis = core.DefaultGoerliGenesisBlock()
setDNSDiscoveryDefaults(ctx, cfg, params.KnownDNSNetworks[params.GoerliGenesisHash])
case ctx.GlobalBool(DeveloperFlag.Name):
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 1337
@ -1531,6 +1533,15 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
}
}
// setDNSDiscoveryDefaults configures DNS discovery with the given URL if
// no URL is set.
func setDNSDiscoveryDefaults(ctx *cli.Context, cfg *eth.Config, url string) {
if len(cfg.DiscoveryURLs) > 0 || ctx.GlobalIsSet(DisableDNSFlag.Name) {
return
}
cfg.DiscoveryURLs = []string{url}
}
// RegisterEthService adds an Ethereum client to the stack.
func RegisterEthService(stack *node.Node, cfg *eth.Config) {
var err error

View file

@ -16,6 +16,8 @@
package params
import "github.com/ethereum/go-ethereum/common"
// MainnetBootnodes are the enode URLs of the P2P bootstrap nodes running on
// the main Ethereum network.
var MainnetBootnodes = []string{
@ -69,3 +71,14 @@ var DiscoveryV5Bootnodes = []string{
"enode://1c7a64d76c0334b0418c004af2f67c50e36a3be60b5e4790bdac0439d21603469a85fad36f2473c9a80eb043ae60936df905fa28f1ff614c3e5dc34f15dcd2dc@40.118.3.223:30306",
"enode://85c85d7143ae8bb96924f2b54f1b3e70d8c4d367af305325d30a61385a432f247d2c75c45c6b4a60335060d072d7f5b35dd1d4c45f76941f62a4f83b6e75daaf@40.118.3.223:30307",
}
const dnsPrefix = "enrtree://AKA3AM6LPBYEUDMVNU3BSVQJ5AD45Y7YPOHJLEF6W26QOE4VTUDPE@"
// These DNS names provide bootstrap connectivity for public testnets and the mainnet.
// See https://github.com/ethereum/discv4-dns-lists for more information.
var KnownDNSNetworks = map[common.Hash]string{
MainnetGenesisHash: dnsPrefix + "all.mainnet.nodes.ethflare.xyz",
TestnetGenesisHash: dnsPrefix + "all.ropsten.nodes.ethflare.xyz",
RinkebyGenesisHash: dnsPrefix + "all.rinkeby.nodes.ethflare.xyz",
GoerliGenesisHash: dnsPrefix + "all.goerli.nodes.ethflare.xyz",
}