Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
import org.hyperledger.besu.metrics.ObservableMetricsSystem;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
import org.hyperledger.besu.plugin.data.EnodeURL;
import org.hyperledger.besu.plugin.services.BesuConfiguration;
import org.hyperledger.besu.plugin.services.BesuEvents;
import org.hyperledger.besu.plugin.services.BlockchainService;
Expand Down Expand Up @@ -164,11 +163,11 @@ public void startNode(final BesuNode node) {
GlobalOpenTelemetry.resetForTest();
final ObservableMetricsSystem metricsSystem =
(ObservableMetricsSystem) component.getMetricsSystem();
final List<EnodeURL> bootnodes =
final List<EnodeURLImpl> bootnodes =
node.getConfiguration().getBootnodes().stream().map(EnodeURLImpl::fromURI).toList();

final EthNetworkConfig.Builder networkConfigBuilder = component.ethNetworkConfigBuilder();
networkConfigBuilder.setBootNodes(bootnodes);
networkConfigBuilder.setEnodeBootNodes(bootnodes);
node.getConfiguration()
.getGenesisConfig()
.map(GenesisConfig::fromConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private LocalPermissioningConfiguration localConfigPermissioningConfiguration()
localConfigNodesPermissioningFile = createTemporaryPermissionsFile();
}

final List<EnodeURL> nodeAllowList =
final List<EnodeURLImpl> nodeAllowList =
localConfigPermittedNodes.stream()
.map(EnodeURLImpl::fromURI)
.collect(Collectors.toList());
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/hyperledger/besu/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolEvictionService;
import org.hyperledger.besu.ethereum.p2p.network.NetworkRunner;
import org.hyperledger.besu.ethereum.p2p.network.P2PNetwork;
import org.hyperledger.besu.ethereum.p2p.peers.EnodeURLImpl;
import org.hyperledger.besu.ethstats.EthStatsService;
import org.hyperledger.besu.metrics.MetricsService;
import org.hyperledger.besu.nat.NatService;
import org.hyperledger.besu.plugin.data.EnodeURL;

import java.io.File;
import java.io.FileOutputStream;
Expand Down Expand Up @@ -542,7 +542,7 @@ public Map<String, JsonRpcMethod> getInProcessRpcMethods() {
* @return the local enode
*/
@VisibleForTesting
Optional<EnodeURL> getLocalEnode() {
Optional<EnodeURLImpl> getLocalEnode() {
return networkRunner.getNetwork().getLocalEnode();
}

Expand Down
44 changes: 28 additions & 16 deletions app/src/main/java/org/hyperledger/besu/RunnerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import org.hyperledger.besu.ethereum.p2p.config.SubProtocolConfiguration;
import org.hyperledger.besu.ethereum.p2p.discovery.DefaultPeerDiscoveryAgentFactory;
import org.hyperledger.besu.ethereum.p2p.discovery.DefaultRlpxAgentFactory;
import org.hyperledger.besu.ethereum.p2p.discovery.NodeIdentifier;
import org.hyperledger.besu.ethereum.p2p.discovery.PeerDiscoveryAgentFactory;
import org.hyperledger.besu.ethereum.p2p.discovery.RlpxAgentFactory;
import org.hyperledger.besu.ethereum.p2p.network.DefaultP2PNetwork;
Expand Down Expand Up @@ -186,7 +187,7 @@ public class RunnerBuilder {
private ObservableMetricsSystem metricsSystem;
private PermissioningServiceImpl permissioningService;
private Optional<PermissioningConfiguration> permissioningConfiguration = Optional.empty();
private Collection<EnodeURL> staticNodes = Collections.emptyList();
private Collection<EnodeURLImpl> staticNodes = Collections.emptyList();
private Optional<String> identityString = Optional.empty();
private BesuPluginContextImpl besuPluginContext;
private boolean autoLogBloomCaching = true;
Expand Down Expand Up @@ -520,7 +521,7 @@ public RunnerBuilder permissioningService(final PermissioningServiceImpl permiss
* @param staticNodes the static nodes
* @return the runner builder
*/
public RunnerBuilder staticNodes(final Collection<EnodeURL> staticNodes) {
public RunnerBuilder staticNodes(final Collection<EnodeURLImpl> staticNodes) {
this.staticNodes = staticNodes;
return this;
}
Expand Down Expand Up @@ -671,16 +672,24 @@ public Runner build() {
});
discoveryConfiguration.setPreferIpv6Outbound(preferIpv6Outbound);
if (discoveryEnabled) {
final List<EnodeURL> bootstrap;
if (ethNetworkConfig.bootNodes() == null) {
bootstrap = EthNetworkConfig.getNetworkConfig(NetworkDefinition.MAINNET).bootNodes();
final List<EnodeURLImpl> bootstrap;
if (ethNetworkConfig.enodeBootNodes() == null) {
bootstrap = EthNetworkConfig.getNetworkConfig(NetworkDefinition.MAINNET).enodeBootNodes();
} else {
bootstrap = ethNetworkConfig.bootNodes();
bootstrap = ethNetworkConfig.enodeBootNodes();
}
discoveryConfiguration.setBootnodes(bootstrap);
discoveryConfiguration.setEnodeBootnodes(bootstrap);
discoveryConfiguration.setEnrBootnodes(
ethNetworkConfig.enrBootNodes() == null
? EthNetworkConfig.getNetworkConfig(NetworkDefinition.MAINNET).enrBootNodes()
: ethNetworkConfig.enrBootNodes());

discoveryConfiguration.setIncludeBootnodesOnPeerRefresh(
besuController.getGenesisConfigOptions().isPoa() && poaDiscoveryRetryBootnodes);
LOG.info("Resolved {} bootnodes.", bootstrap.size());
LOG.info(
"Resolved {} bootnodes.",
discoveryConfiguration.getEnodeBootnodes().size()
+ discoveryConfiguration.getEnrBootnodes().size());
LOG.debug("Bootnodes = {}", bootstrap);
discoveryConfiguration.setDnsDiscoveryURL(ethNetworkConfig.dnsDiscoveryUrl());
discoveryConfiguration.setDiscoveryV5Enabled(
Expand Down Expand Up @@ -726,7 +735,8 @@ public Runner build() {
final PeerPermissions defaultPeerPermissions =
PeerPermissions.combine(peerPermissionSubnet, bannedNodes);

final List<EnodeURL> bootnodes = discoveryConfiguration.getBootnodes();
final List<? extends NodeIdentifier> bootnodes =
discoveryConfiguration.getBootnodeIdentifiers();

final Synchronizer synchronizer = besuController.getSynchronizer();

Expand Down Expand Up @@ -1180,8 +1190,8 @@ private boolean isEthStatsEnabled() {
return ethstatsOptions != null && !Strings.isNullOrEmpty(ethstatsOptions.getEthstatsUrl());
}

private Stream<EnodeURL> sanitizePeers(
final P2PNetwork network, final Collection<EnodeURL> enodeURLS) {
private Stream<EnodeURLImpl> sanitizePeers(
final P2PNetwork network, final Collection<EnodeURLImpl> enodeURLS) {
if (network.getLocalEnode().isEmpty()) {
return enodeURLS.stream();
}
Expand All @@ -1191,12 +1201,12 @@ private Stream<EnodeURL> sanitizePeers(
}

private Optional<NodePermissioningController> buildNodePermissioningController(
final List<EnodeURL> bootnodesAsEnodeURLs,
final List<? extends NodeIdentifier> bootnodesIdentifiers,
final Synchronizer synchronizer,
final TransactionSimulator transactionSimulator,
final Bytes localNodeId,
final Blockchain blockchain) {
final Collection<EnodeURL> fixedNodes = getFixedNodes(bootnodesAsEnodeURLs, staticNodes);
final Collection<NodeIdentifier> fixedNodes = getFixedNodes(bootnodesIdentifiers, staticNodes);

if (permissioningConfiguration.isPresent()) {
final PermissioningConfiguration configuration = this.permissioningConfiguration.get();
Expand Down Expand Up @@ -1285,9 +1295,11 @@ private Optional<NatManager> buildNatManager(final NatMethod natMethod) {
* @return the fixed and more nodes combined
*/
@VisibleForTesting
public static Collection<EnodeURL> getFixedNodes(
final Collection<EnodeURL> someFixedNodes, final Collection<EnodeURL> moreFixedNodes) {
final Collection<EnodeURL> fixedNodes = new ArrayList<>(someFixedNodes);
public static Collection<NodeIdentifier> getFixedNodes(
final Collection<? extends NodeIdentifier> someFixedNodes,
final Collection<EnodeURLImpl> moreFixedNodes) {
final Collection<NodeIdentifier> fixedNodes = new ArrayList<>();
fixedNodes.addAll(someFixedNodes);
fixedNodes.addAll(moreFixedNodes);
return fixedNodes;
}
Expand Down
37 changes: 23 additions & 14 deletions app/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration;
import org.hyperledger.besu.ethereum.mainnet.BalConfiguration;
import org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration;
import org.hyperledger.besu.ethereum.p2p.discovery.NodeIdentifier;
import org.hyperledger.besu.ethereum.p2p.discovery.P2PDiscoveryConfiguration;
import org.hyperledger.besu.ethereum.p2p.discovery.dns.EthereumNodeRecord;
import org.hyperledger.besu.ethereum.p2p.peers.EnodeDnsConfiguration;
import org.hyperledger.besu.ethereum.p2p.peers.EnodeURLImpl;
import org.hyperledger.besu.ethereum.p2p.peers.StaticNodesParser;
Expand Down Expand Up @@ -155,7 +157,6 @@
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
import org.hyperledger.besu.metrics.vertx.VertxMetricsAdapterFactory;
import org.hyperledger.besu.nat.NatMethod;
import org.hyperledger.besu.plugin.data.EnodeURL;
import org.hyperledger.besu.plugin.services.BesuConfiguration;
import org.hyperledger.besu.plugin.services.BesuEvents;
import org.hyperledger.besu.plugin.services.BlockSimulationService;
Expand Down Expand Up @@ -689,7 +690,7 @@ void setNetwork(final String inputNetwork) {
private MetricsConfiguration metricsConfiguration;
private Optional<PermissioningConfiguration> permissioningConfiguration;
private DataStorageConfiguration dataStorageConfiguration;
private Collection<EnodeURL> staticNodes;
private Collection<EnodeURLImpl> staticNodes;
private BesuController besuController;
private BesuConfigurationImpl pluginCommonConfiguration;

Expand Down Expand Up @@ -2030,10 +2031,13 @@ private void configure() throws Exception {
permissioningConfiguration = permissioningConfiguration();
staticNodes = loadStaticNodes();

final List<EnodeURL> enodeURIs = ethNetworkConfig.bootNodes();
permissioningConfiguration
.flatMap(PermissioningConfiguration::getLocalConfig)
.ifPresent(p -> ensureAllNodesAreInAllowlist(enodeURIs, p));
.ifPresent(p -> ensureAllNodesAreInAllowlist(ethNetworkConfig.enodeBootNodes(), p));

permissioningConfiguration
.flatMap(PermissioningConfiguration::getLocalConfig)
.ifPresent(p -> ensureAllNodesAreInAllowlist(ethNetworkConfig.enrBootNodes(), p));

permissioningConfiguration
.flatMap(PermissioningConfiguration::getLocalConfig)
Expand Down Expand Up @@ -2081,11 +2085,11 @@ private JsonRpcIpcConfiguration jsonRpcIpcConfiguration(
}

private void ensureAllNodesAreInAllowlist(
final Collection<EnodeURL> enodeAddresses,
final Collection<? extends NodeIdentifier> nodeIdentifiers,
final LocalPermissioningConfiguration permissioningConfiguration) {
try {
PermissioningConfigurationValidator.areAllNodesInAllowlist(
enodeAddresses, permissioningConfiguration);
nodeIdentifiers, permissioningConfiguration);
} catch (final Exception e) {
throw new ParameterException(this.commandLine, e.getMessage());
}
Expand Down Expand Up @@ -2403,7 +2407,7 @@ private Runner synchronize(
final ApiConfiguration apiConfiguration,
final MetricsConfiguration metricsConfiguration,
final Optional<PermissioningConfiguration> permissioningConfiguration,
final Collection<EnodeURL> staticNodes,
final Collection<EnodeURLImpl> staticNodes,
final Path pidPath) {

checkNotNull(runnerBuilder);
Expand Down Expand Up @@ -2518,7 +2522,7 @@ private EthNetworkConfig updateNetworkConfig(final NetworkDefinition network) {
}

if (p2PDiscoveryOptions.bootNodes == null) {
builder.setBootNodes(new ArrayList<>());
builder.setEnodeBootNodes(new ArrayList<>());
}
builder.setDnsDiscoveryUrl(null);
}
Expand All @@ -2541,7 +2545,7 @@ private EthNetworkConfig updateNetworkConfig(final NetworkDefinition network) {
discoveryDnsUrlFromGenesis.ifPresent(builder::setDnsDiscoveryUrl);
}

List<EnodeURL> listBootNodes = null;
List<EnodeURLImpl> listBootNodes = null;
if (p2PDiscoveryOptions.bootNodes != null) {
try {
final List<String> resolvedBootNodeArgs =
Expand All @@ -2558,15 +2562,20 @@ private EthNetworkConfig updateNetworkConfig(final NetworkDefinition network) {
final Optional<List<String>> bootNodesFromGenesis =
genesisConfigOptionsSupplier.get().getDiscoveryOptions().getBootNodes();
if (bootNodesFromGenesis.isPresent()) {
listBootNodes = buildEnodes(bootNodesFromGenesis.get(), getEnodeDnsConfiguration());
if (bootNodesFromGenesis.get().getFirst().startsWith("enr:")) {
builder.setEnrBootNodes(
bootNodesFromGenesis.get().stream().map(EthereumNodeRecord::fromEnr).toList());
} else {
listBootNodes = buildEnodes(bootNodesFromGenesis.get(), getEnodeDnsConfiguration());
}
}
}
if (listBootNodes != null) {
if (!p2PDiscoveryOptions.peerDiscoveryEnabled) {
logger.warn("Discovery disabled: bootnodes will be ignored.");
}
DiscoveryConfiguration.assertValidBootnodes(listBootNodes);
builder.setBootNodes(listBootNodes);
builder.setEnodeBootNodes(listBootNodes);
}
return builder.build();
}
Expand Down Expand Up @@ -2601,7 +2610,7 @@ public MetricsSystem getMetricsSystem() {
return besuComponent.getMetricsSystem();
}

private Set<EnodeURL> loadStaticNodes() throws IOException {
private Set<EnodeURLImpl> loadStaticNodes() throws IOException {
final Path staticNodesPath;
if (staticNodesFile != null) {
staticNodesPath = staticNodesFile.toAbsolutePath();
Expand All @@ -2614,14 +2623,14 @@ private Set<EnodeURL> loadStaticNodes() throws IOException {
staticNodesPath = dataDir().resolve(staticNodesFilename);
}
logger.debug("Static Nodes file: {}", staticNodesPath);
final Set<EnodeURL> staticNodes =
final Set<EnodeURLImpl> staticNodes =
StaticNodesParser.fromPath(staticNodesPath, getEnodeDnsConfiguration());
logger.info("Connecting to {} static nodes.", staticNodes.size());
logger.debug("Static Nodes = {}", staticNodes);
return staticNodes;
}

private List<EnodeURL> buildEnodes(
private List<EnodeURLImpl> buildEnodes(
final List<String> bootNodes, final EnodeDnsConfiguration enodeDnsConfiguration) {
return bootNodes.stream()
.filter(bootNode -> !bootNode.isEmpty())
Expand Down
Loading
Loading