Skip to content

Commit

Permalink
Add DNS discovery (hyperledger#1595)
Browse files Browse the repository at this point in the history
* Add DNS discovery for goerli, rinkeby and mainnet to help speed up discovery of peers

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* Add final to constant fields

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

Co-authored-by: David Mechler <david.mechler@consensys.net>
  • Loading branch information
atoulme and David Mechler authored Nov 25, 2020
1 parent a4a8723 commit f41fb97
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 27 deletions.
1 change: 1 addition & 0 deletions besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ public Runner build() {
bootstrap = ethNetworkConfig.getBootNodes();
}
discoveryConfiguration.setBootnodes(bootstrap);
discoveryConfiguration.setDnsDiscoveryURL(ethNetworkConfig.getDnsDiscoveryUrl());
} else {
discoveryConfiguration.setActive(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration.CLASSIC_BOOTSTRAP_NODES;
import static org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration.GOERLI_BOOTSTRAP_NODES;
import static org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration.GOERLI_DISCOVERY_URL;
import static org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration.KOTTI_BOOTSTRAP_NODES;
import static org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration.MAINNET_BOOTSTRAP_NODES;
import static org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration.MAINNET_DISCOVERY_URL;
import static org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration.MORDOR_BOOTSTRAP_NODES;
import static org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration.RINKEBY_BOOTSTRAP_NODES;
import static org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration.RINKEBY_DISCOVERY_URL;
import static org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration.ROPSTEN_BOOTSTRAP_NODES;
import static org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration.YOLO_V2_BOOTSTRAP_NODES;

Expand Down Expand Up @@ -59,14 +62,19 @@ public class EthNetworkConfig {
private final String genesisConfig;
private final BigInteger networkId;
private final List<EnodeURL> bootNodes;
private final String dnsDiscoveryUrl;

public EthNetworkConfig(
final String genesisConfig, final BigInteger networkId, final List<EnodeURL> bootNodes) {
final String genesisConfig,
final BigInteger networkId,
final List<EnodeURL> bootNodes,
final String dnsDiscoveryUrl) {
Preconditions.checkNotNull(genesisConfig);
Preconditions.checkNotNull(bootNodes);
this.genesisConfig = genesisConfig;
this.networkId = networkId;
this.bootNodes = bootNodes;
this.dnsDiscoveryUrl = dnsDiscoveryUrl;
}

public String getGenesisConfig() {
Expand All @@ -81,6 +89,10 @@ public List<EnodeURL> getBootNodes() {
return bootNodes;
}

public String getDnsDiscoveryUrl() {
return dnsDiscoveryUrl;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
Expand All @@ -92,12 +104,13 @@ public boolean equals(final Object o) {
final EthNetworkConfig that = (EthNetworkConfig) o;
return networkId.equals(that.networkId)
&& Objects.equals(genesisConfig, that.genesisConfig)
&& Objects.equals(bootNodes, that.bootNodes);
&& Objects.equals(bootNodes, that.bootNodes)
&& Objects.equals(dnsDiscoveryUrl, that.dnsDiscoveryUrl);
}

@Override
public int hashCode() {
return Objects.hash(genesisConfig, networkId, bootNodes);
return Objects.hash(genesisConfig, networkId, bootNodes, dnsDiscoveryUrl);
}

@Override
Expand All @@ -109,38 +122,50 @@ public String toString() {
+ networkId
+ ", bootNodes="
+ bootNodes
+ ", dnsDiscoveryUrl="
+ dnsDiscoveryUrl
+ '}';
}

public static EthNetworkConfig getNetworkConfig(final NetworkName networkName) {
switch (networkName) {
case ROPSTEN:
return new EthNetworkConfig(
jsonConfig(ROPSTEN_GENESIS), ROPSTEN_NETWORK_ID, ROPSTEN_BOOTSTRAP_NODES);
jsonConfig(ROPSTEN_GENESIS), ROPSTEN_NETWORK_ID, ROPSTEN_BOOTSTRAP_NODES, null);
case RINKEBY:
return new EthNetworkConfig(
jsonConfig(RINKEBY_GENESIS), RINKEBY_NETWORK_ID, RINKEBY_BOOTSTRAP_NODES);
jsonConfig(RINKEBY_GENESIS),
RINKEBY_NETWORK_ID,
RINKEBY_BOOTSTRAP_NODES,
RINKEBY_DISCOVERY_URL);
case GOERLI:
return new EthNetworkConfig(
jsonConfig(GOERLI_GENESIS), GOERLI_NETWORK_ID, GOERLI_BOOTSTRAP_NODES);
jsonConfig(GOERLI_GENESIS),
GOERLI_NETWORK_ID,
GOERLI_BOOTSTRAP_NODES,
GOERLI_DISCOVERY_URL);
case DEV:
return new EthNetworkConfig(jsonConfig(DEV_GENESIS), DEV_NETWORK_ID, new ArrayList<>());
return new EthNetworkConfig(
jsonConfig(DEV_GENESIS), DEV_NETWORK_ID, new ArrayList<>(), null);
case CLASSIC:
return new EthNetworkConfig(
jsonConfig(CLASSIC_GENESIS), CLASSIC_NETWORK_ID, CLASSIC_BOOTSTRAP_NODES);
jsonConfig(CLASSIC_GENESIS), CLASSIC_NETWORK_ID, CLASSIC_BOOTSTRAP_NODES, null);
case KOTTI:
return new EthNetworkConfig(
jsonConfig(KOTTI_GENESIS), KOTTI_NETWORK_ID, KOTTI_BOOTSTRAP_NODES);
jsonConfig(KOTTI_GENESIS), KOTTI_NETWORK_ID, KOTTI_BOOTSTRAP_NODES, null);
case MORDOR:
return new EthNetworkConfig(
jsonConfig(MORDOR_GENESIS), MORDOR_NETWORK_ID, MORDOR_BOOTSTRAP_NODES);
jsonConfig(MORDOR_GENESIS), MORDOR_NETWORK_ID, MORDOR_BOOTSTRAP_NODES, null);
case YOLO_V2:
return new EthNetworkConfig(
jsonConfig(YOLO_GENESIS), YOLO_V2_NETWORK_ID, YOLO_V2_BOOTSTRAP_NODES);
jsonConfig(YOLO_GENESIS), YOLO_V2_NETWORK_ID, YOLO_V2_BOOTSTRAP_NODES, null);
case MAINNET:
default:
return new EthNetworkConfig(
jsonConfig(MAINNET_GENESIS), MAINNET_NETWORK_ID, MAINNET_BOOTSTRAP_NODES);
jsonConfig(MAINNET_GENESIS),
MAINNET_NETWORK_ID,
MAINNET_BOOTSTRAP_NODES,
MAINNET_DISCOVERY_URL);
}
}

Expand Down Expand Up @@ -180,6 +205,7 @@ public static String jsonConfig(final NetworkName network) {

public static class Builder {

private final String dnsDiscoveryUrl;
private String genesisConfig;
private BigInteger networkId;
private List<EnodeURL> bootNodes;
Expand All @@ -188,6 +214,7 @@ public Builder(final EthNetworkConfig ethNetworkConfig) {
this.genesisConfig = ethNetworkConfig.genesisConfig;
this.networkId = ethNetworkConfig.networkId;
this.bootNodes = ethNetworkConfig.bootNodes;
this.dnsDiscoveryUrl = ethNetworkConfig.dnsDiscoveryUrl;
}

public Builder setGenesisConfig(final String genesisConfig) {
Expand All @@ -206,7 +233,7 @@ public Builder setBootNodes(final List<EnodeURL> bootNodes) {
}

public EthNetworkConfig build() {
return new EthNetworkConfig(genesisConfig, networkId, bootNodes);
return new EthNetworkConfig(genesisConfig, networkId, bootNodes, dnsDiscoveryUrl);
}
}
}
5 changes: 4 additions & 1 deletion besu/src/test/java/org/hyperledger/besu/RunnerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,10 @@ private void syncFromGenesis(final SyncMode mode, final GenesisConfigFile genesi
final EnodeURL enode = runnerAhead.getLocalEnode().get();
final EthNetworkConfig behindEthNetworkConfiguration =
new EthNetworkConfig(
EthNetworkConfig.jsonConfig(DEV), DEV_NETWORK_ID, Collections.singletonList(enode));
EthNetworkConfig.jsonConfig(DEV),
DEV_NETWORK_ID,
Collections.singletonList(enode),
null);
runnerBehind =
runnerBuilder
.besuController(controllerBehind)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.PERM;
import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.WEB3;
import static org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration.MAINNET_BOOTSTRAP_NODES;
import static org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration.MAINNET_DISCOVERY_URL;
import static org.hyperledger.besu.nat.kubernetes.KubernetesNatManager.DEFAULT_BESU_SERVICE_NAME_FILTER;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
Expand Down Expand Up @@ -173,7 +174,8 @@ public void callingBesuCommandWithoutOptionsMustSyncWithDefaultValues() throws E
new EthNetworkConfig(
EthNetworkConfig.jsonConfig(MAINNET),
EthNetworkConfig.MAINNET_NETWORK_ID,
MAINNET_BOOTSTRAP_NODES));
MAINNET_BOOTSTRAP_NODES,
MAINNET_DISCOVERY_URL));
verify(mockRunnerBuilder).p2pAdvertisedHost(eq("127.0.0.1"));
verify(mockRunnerBuilder).p2pListenPort(eq(30303));
verify(mockRunnerBuilder).maxPeers(eq(25));
Expand Down Expand Up @@ -784,7 +786,8 @@ public void noOverrideDefaultValuesIfKeyIsNotPresentInConfigFile() throws IOExce
new EthNetworkConfig(
EthNetworkConfig.jsonConfig(MAINNET),
EthNetworkConfig.MAINNET_NETWORK_ID,
MAINNET_BOOTSTRAP_NODES));
MAINNET_BOOTSTRAP_NODES,
MAINNET_DISCOVERY_URL));
verify(mockRunnerBuilder).p2pAdvertisedHost(eq("127.0.0.1"));
verify(mockRunnerBuilder).p2pListenPort(eq(30303));
verify(mockRunnerBuilder).maxPeers(eq(25));
Expand Down
7 changes: 7 additions & 0 deletions ethereum/p2p/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,18 @@ dependencies {
implementation project(':nat')

implementation 'com.google.guava:guava'
implementation 'dnsjava:dnsjava'
implementation 'io.prometheus:simpleclient'
implementation 'io.vertx:vertx-core'
implementation 'org.apache.logging.log4j:log4j-api'
implementation 'org.apache.tuweni:bytes'
implementation 'org.apache.tuweni:crypto'
implementation 'org.apache.tuweni:devp2p'
implementation 'org.apache.tuweni:dns-discovery'
implementation 'org.apache.tuweni:io'
implementation 'org.apache.tuweni:rlp'
implementation 'org.apache.tuweni:units'
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
implementation 'org.xerial.snappy:snappy-java'

annotationProcessor "org.immutables:value"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@
import java.util.stream.Stream;

public class DiscoveryConfiguration {
public static List<EnodeURL> MAINNET_BOOTSTRAP_NODES =
public static final String GOERLI_DISCOVERY_URL =
"enrtree://AKA3AM6LPBYEUDMVNU3BSVQJ5AD45Y7YPOHJLEF6W26QOE4VTUDPE@all.goerli.ethdisco.net";
public static final String MAINNET_DISCOVERY_URL =
"enrtree://AKA3AM6LPBYEUDMVNU3BSVQJ5AD45Y7YPOHJLEF6W26QOE4VTUDPE@all.mainnet.ethdisco.net";
public static final String RINKEBY_DISCOVERY_URL =
"enrtree://AKA3AM6LPBYEUDMVNU3BSVQJ5AD45Y7YPOHJLEF6W26QOE4VTUDPE@all.rinkeby.ethdisco.net";

public static final List<EnodeURL> MAINNET_BOOTSTRAP_NODES =
Collections.unmodifiableList(
Stream.of(
// Ethereum Foundation Bootnodes
Expand All @@ -52,15 +59,15 @@ public class DiscoveryConfiguration {
)
.map(EnodeURL::fromString)
.collect(toList()));
public static List<EnodeURL> RINKEBY_BOOTSTRAP_NODES =
public static final List<EnodeURL> RINKEBY_BOOTSTRAP_NODES =
Collections.unmodifiableList(
Stream.of(
"enode://a24ac7c5484ef4ed0c5eb2d36620ba4e4aa13b8c84684e1b4aab0cebea2ae45cb4d375b77eab56516d34bfbd3c1a833fc51296ff084b770b94fb9028c4d25ccf@52.169.42.101:30303",
"enode://343149e4feefa15d882d9fe4ac7d88f885bd05ebb735e547f12e12080a9fa07c8014ca6fd7f373123488102fe5e34111f8509cf0b7de3f5b44339c9f25e87cb8@52.3.158.184:30303",
"enode://b6b28890b006743680c52e64e0d16db57f28124885595fa03a562be1d2bf0f3a1da297d56b13da25fb992888fd556d4c1a27b1f39d531bde7de1921c90061cc6@159.89.28.211:30303")
.map(EnodeURL::fromString)
.collect(toList()));
public static List<EnodeURL> ROPSTEN_BOOTSTRAP_NODES =
public static final List<EnodeURL> ROPSTEN_BOOTSTRAP_NODES =
Collections.unmodifiableList(
Stream.of(
"enode://6332792c4a00e3e4ee0926ed89e0d27ef985424d97b6a45bf0f23e51f0dcb5e66b875777506458aea7af6f9e4ffb69f43f3778ee73c81ed9d34c51c4b16b0b0f@52.232.243.152:30303",
Expand All @@ -70,7 +77,7 @@ public class DiscoveryConfiguration {
.map(EnodeURL::fromString)
.collect(toList()));

public static List<EnodeURL> GOERLI_BOOTSTRAP_NODES =
public static final List<EnodeURL> GOERLI_BOOTSTRAP_NODES =
Collections.unmodifiableList(
Stream.of(
"enode://011f758e6552d105183b1761c5e2dea0111bc20fd5f6422bc7f91e0fabbec9a6595caf6239b37feb773dddd3f87240d99d859431891e4a642cf2a0a9e6cbb98a@51.141.78.53:30303",
Expand All @@ -89,7 +96,7 @@ public class DiscoveryConfiguration {
.map(EnodeURL::fromString)
.collect(toList()));

public static List<EnodeURL> CLASSIC_BOOTSTRAP_NODES =
public static final List<EnodeURL> CLASSIC_BOOTSTRAP_NODES =
Collections.unmodifiableList(
Stream.of(
"enode://158ac5a4817265d0d8b977660b3dbe9abee5694ed212f7091cbf784ddf47623ed015e1cb54594d10c1c46118747ddabe86ebf569cf24ae91f2daa0f1adaae390@159.203.56.33:30303",
Expand All @@ -114,7 +121,7 @@ public class DiscoveryConfiguration {
.map(EnodeURL::fromString)
.collect(toList()));

public static List<EnodeURL> KOTTI_BOOTSTRAP_NODES =
public static final List<EnodeURL> KOTTI_BOOTSTRAP_NODES =
Collections.unmodifiableList(
Stream.of(
// Authority Nodes
Expand All @@ -134,7 +141,7 @@ public class DiscoveryConfiguration {
.map(EnodeURL::fromString)
.collect(toList()));

public static List<EnodeURL> MORDOR_BOOTSTRAP_NODES =
public static final List<EnodeURL> MORDOR_BOOTSTRAP_NODES =
Collections.unmodifiableList(
Stream.of(
"enode://642cf9650dd8869d42525dbf6858012e3b4d64f475e733847ab6f7742341a4397414865d953874e8f5ed91b0e4e1c533dee14ad1d6bb276a5459b2471460ff0d@157.230.152.87:30303", // @meowbits Mordor
Expand Down Expand Up @@ -169,7 +176,7 @@ public class DiscoveryConfiguration {
.map(EnodeURL::fromString)
.collect(toList()));

public static List<EnodeURL> YOLO_V2_BOOTSTRAP_NODES =
public static final List<EnodeURL> YOLO_V2_BOOTSTRAP_NODES =
Collections.unmodifiableList(
Stream.<String>of(
"enode://9e1096aa59862a6f164994cb5cb16f5124d6c992cdbf4535ff7dea43ea1512afe5448dca9df1b7ab0726129603f1a3336b631e4d7a1a44c94daddd03241587f9@3.9.20.133:30303")
Expand All @@ -182,6 +189,7 @@ public class DiscoveryConfiguration {
private String advertisedHost = "127.0.0.1";
private int bucketSize = 16;
private List<EnodeURL> bootnodes = new ArrayList<>();
private String dnsDiscoveryURL;

public static DiscoveryConfiguration create() {
return new DiscoveryConfiguration();
Expand Down Expand Up @@ -255,6 +263,14 @@ public DiscoveryConfiguration setBucketSize(final int bucketSize) {
return this;
}

public String getDNSDiscoveryURL() {
return dnsDiscoveryURL;
}

public void setDnsDiscoveryURL(final String dnsDiscoveryURL) {
this.dnsDiscoveryURL = dnsDiscoveryURL;
}

@Override
public boolean equals(final Object o) {
if (o == this) {
Expand All @@ -269,12 +285,14 @@ public boolean equals(final Object o) {
&& bucketSize == that.bucketSize
&& Objects.equals(bindHost, that.bindHost)
&& Objects.equals(advertisedHost, that.advertisedHost)
&& Objects.equals(bootnodes, that.bootnodes);
&& Objects.equals(bootnodes, that.bootnodes)
&& Objects.equals(dnsDiscoveryURL, that.dnsDiscoveryURL);
}

@Override
public int hashCode() {
return Objects.hash(active, bindHost, bindPort, advertisedHost, bucketSize, bootnodes);
return Objects.hash(
active, bindHost, bindPort, advertisedHost, bucketSize, bootnodes, dnsDiscoveryURL);
}

@Override
Expand All @@ -294,6 +312,8 @@ public String toString() {
+ bucketSize
+ ", bootnodes="
+ bootnodes
+ ", dnsDiscoveryURL="
+ dnsDiscoveryURL
+ '}';
}
}
Loading

0 comments on commit f41fb97

Please sign in to comment.