Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel-Trintinalia <[email protected]>
  • Loading branch information
Gabriel-Trintinalia committed Jun 20, 2024
1 parent 8c78b6a commit 9a5ca85
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ public void startNode(final BesuNode node) {
.storageProvider(storageProvider)
.gasLimitCalculator(GasLimitCalculator.constant())
.evmConfiguration(EvmConfiguration.DEFAULT)
.p2PConfiguration(P2PConfiguration.createDefault())
.networkConfiguration(node.getNetworkingConfiguration());
.networkConfiguration(node.getNetworkingConfiguration())
.p2PConfiguration(P2PConfiguration.createDefault());

node.getGenesisConfig()
.map(GenesisConfigFile::fromConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public BesuNodeConfigurationBuilder jsonRpcAuthenticationUsingECDSA() throws URI
return this;
}

public BesuNodeConfigurationBuilder p2pConfiguration(final P2PConfiguration p2pConfiguration) {
public BesuNodeConfigurationBuilder p2PConfiguration(final P2PConfiguration p2pConfiguration) {
this.p2pConfiguration = p2pConfiguration;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public class BesuNodeFactory {

private final NodeConfigurationFactory node = new NodeConfigurationFactory();

private final P2PConfiguration P2P_DISABLED =
P2PConfiguration.builder().p2pEnabled(false).build();
private final P2PConfiguration DISCOVERY_DISABLED =
P2PConfiguration.builder().discoveryEnabled(false).build();

public BesuNode create(final BesuNodeConfiguration config) throws IOException {
return new BesuNode(
config.getName(),
Expand Down Expand Up @@ -182,7 +187,7 @@ public BesuNode createArchiveNodeWithDiscoveryDisabledAndAdmin(final String name
.name(name)
.jsonRpcConfiguration(node.jsonRpcConfigWithAdmin())
.webSocketEnabled()
.p2pConfiguration(P2PConfiguration.builder().peerDiscoveryEnabled(false).build())
.p2PConfiguration(DISCOVERY_DISABLED)
.build());
}

Expand All @@ -197,7 +202,6 @@ public BesuNode createArchiveNodeNetServicesEnabled(final String name) throws IO
// .setMetricsConfiguration(metricsConfiguration)
.jsonRpcConfiguration(node.jsonRpcConfigWithAdmin())
.webSocketEnabled()
.p2pConfiguration(P2PConfiguration.builder().p2pEnabled(true).build())
.build());
}

Expand All @@ -206,7 +210,7 @@ public BesuNode createArchiveNodeNetServicesDisabled(final String name) throws I
new BesuNodeConfigurationBuilder()
.name(name)
.jsonRpcConfiguration(node.jsonRpcConfigWithAdmin())
.p2pConfiguration(P2PConfiguration.builder().p2pEnabled(false).build())
.p2PConfiguration(P2P_DISABLED)
.build());
}

Expand Down Expand Up @@ -276,7 +280,7 @@ public BesuNode createNodeWithP2pDisabled(final String name) throws IOException
return create(
new BesuNodeConfigurationBuilder()
.name(name)
.p2pConfiguration(P2PConfiguration.builder().p2pEnabled(false).build())
.p2PConfiguration(P2P_DISABLED)
.jsonRpcConfiguration(node.createJsonRpcEnabledConfig())
.build());
}
Expand Down Expand Up @@ -358,7 +362,7 @@ public BesuNode createNodeWithNoDiscovery(final String name) throws IOException
return create(
new BesuNodeConfigurationBuilder()
.name(name)
.p2pConfiguration(P2PConfiguration.builder().peerDiscoveryEnabled(false).build())
.p2PConfiguration(DISCOVERY_DISABLED)
.engineRpcEnabled(false)
.build());
}
Expand Down Expand Up @@ -477,12 +481,12 @@ public BesuNode createIbft2Node(final String name, final boolean fixedPort) thro
.devMode(false)
.genesisConfigProvider(GenesisConfigurationFactory::createIbft2GenesisConfig);
if (fixedPort) {
var port =
int port =
Math.abs(name.hashCode() % 60000)
+ 1024
+ 500; // Generate a consistent port for p2p based on node name (+ 500 to avoid
// clashing with RPC port or other nodes with a similar name)
builder.p2pConfiguration(P2PConfiguration.builder().p2pPort(port).build());
builder.p2PConfiguration(P2PConfiguration.builder().port(port).build());
}
return create(builder.build());
}
Expand Down Expand Up @@ -530,12 +534,12 @@ public BesuNode createQbftNode(final String name, final boolean fixedPort) throw
.devMode(false)
.genesisConfigProvider(GenesisConfigurationFactory::createQbftGenesisConfig);
if (fixedPort) {
var port =
int port =
Math.abs(name.hashCode() % 60000)
+ 1024
+ 500; // Generate a consistent port for p2p based on node name (+ 500 to avoid
// clashing with RPC port or other nodes with a similar name)
builder.p2pConfiguration(P2PConfiguration.builder().p2pPort(port).build());
builder.p2PConfiguration(P2PConfiguration.builder().port(port).build());
}
return create(builder.build());
}
Expand Down Expand Up @@ -718,7 +722,7 @@ private BesuNodeConfigurationBuilder createConfigurationBuilderWithStaticNodes(
.name(name)
.jsonRpcEnabled()
.webSocketEnabled()
.p2pConfiguration(P2PConfiguration.builder().peerDiscoveryEnabled(false).build())
.p2PConfiguration(DISCOVERY_DISABLED)
.staticNodes(staticNodesUrls)
.bootnodeEligible(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private BesuNodeConfigurationBuilder configureNode(
return nodeBuilder
.devMode(false)
.keyPair(keyPair)
.p2pConfiguration(P2PConfiguration.builder().p2pPort(p2pBindingPort).build())
.p2PConfiguration(P2PConfiguration.builder().port(p2pBindingPort).build())
.genesisConfigProvider(
(nodes) ->
Optional.of(
Expand Down
4 changes: 2 additions & 2 deletions besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ public RunnerBuilder besuController(final BesuController besuController) {
}

/**
* TLSConfiguration p2pTLSConfiguration.
* P2P Configuration Configuration.
*
* @param p2PConfiguration the TLSConfiguration p2pTLSConfiguration
* @param p2PConfiguration the p2pConfiguration
* @return the runner builder
*/
public RunnerBuilder p2PConfiguration(final P2PConfiguration p2PConfiguration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2095,6 +2095,7 @@ private Runner synchronize(
runnerBuilder
.vertx(vertx)
.besuController(controller)
.p2PConfiguration(p2pConfiguration)
.natMethod(natMethod)
.natManagerServiceName(unstableNatOptions.getNatManagerServiceName())
.natMethodFallbackEnabled(unstableNatOptions.getNatMethodFallbackEnabled())
Expand All @@ -2121,7 +2122,6 @@ private Runner synchronize(
.storageProvider(keyValueStorageProvider(keyValueStorageName))
.rpcEndpointService(rpcEndpointServiceImpl)
.enodeDnsConfiguration(getEnodeDnsConfiguration())
.p2PConfiguration(p2pConfiguration)
.build();

addShutdownHook(runner);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,11 @@ private void checkP2pOptionsDependencies(final CommandLine commandLine, final Lo
public P2PConfiguration toDomainObject() {
return new P2PConfiguration.Builder()
.p2pEnabled(p2pEnabled)
.peerDiscoveryEnabled(peerDiscoveryEnabled)
.discoveryEnabled(peerDiscoveryEnabled)
.bootNodes(bootNodes)
.p2pHost(p2pHost)
.host(p2pHost)
.p2pInterface(p2pInterface)
.p2pPort(p2pPort)
.port(p2pPort)
.maxPeers(maxPeers)
.isLimitRemoteWireConnectionsEnabled(isLimitRemoteWireConnectionsEnabled)
.maxRemoteConnectionsPercentage(maxRemoteConnectionsPercentage)
Expand Down
36 changes: 18 additions & 18 deletions besu/src/test/java/org/hyperledger/besu/RunnerBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ public void enodeUrlShouldHaveAdvertisedHostWhenDiscoveryDisabled() {
.p2PConfiguration(
P2PConfiguration.builder()
.p2pInterface("0.0.0.0")
.p2pPort(p2pListenPort)
.p2pHost(p2pAdvertisedHost)
.port(p2pListenPort)
.host(p2pAdvertisedHost)
.p2pEnabled(true)
.peerDiscoveryEnabled(false)
.discoveryEnabled(false)
.build())
.besuController(besuController)
.ethNetworkConfig(mock(EthNetworkConfig.class))
Expand Down Expand Up @@ -201,10 +201,10 @@ public void movingAcrossProtocolSpecsUpdatesNodeRecord() {
.p2PConfiguration(
P2PConfiguration.builder()
.p2pInterface("0.0.0.0")
.p2pPort(p2pListenPort)
.p2pHost(p2pAdvertisedHost)
.port(p2pListenPort)
.host(p2pAdvertisedHost)
.p2pEnabled(true)
.peerDiscoveryEnabled(true)
.discoveryEnabled(true)
.build())
.natMethod(NatMethod.NONE)
.besuController(besuController)
Expand Down Expand Up @@ -262,10 +262,10 @@ public void whenEngineApiAddedListensOnDefaultPort() {
.p2PConfiguration(
P2PConfiguration.builder()
.p2pInterface("0.0.0.0")
.p2pPort(30303)
.p2pHost("127.0.0.1")
.port(30303)
.host("127.0.0.1")
.p2pEnabled(true)
.peerDiscoveryEnabled(true)
.discoveryEnabled(true)
.build())
.natMethod(NatMethod.NONE)
.besuController(besuController)
Expand Down Expand Up @@ -308,10 +308,10 @@ public void whenEngineApiAddedWebSocketReadyOnSamePort() {
.p2PConfiguration(
P2PConfiguration.builder()
.p2pInterface("0.0.0.0")
.p2pPort(30303)
.p2pHost("127.0.0.1")
.port(30303)
.host("127.0.0.1")
.p2pEnabled(true)
.peerDiscoveryEnabled(true)
.discoveryEnabled(true)
.build())
.natMethod(NatMethod.NONE)
.besuController(besuController)
Expand Down Expand Up @@ -353,10 +353,10 @@ public void whenEngineApiAddedEthSubscribeAvailable() {
.p2PConfiguration(
P2PConfiguration.builder()
.p2pInterface("0.0.0.0")
.p2pPort(30303)
.p2pHost("127.0.0.1")
.port(30303)
.host("127.0.0.1")
.p2pEnabled(true)
.peerDiscoveryEnabled(true)
.discoveryEnabled(true)
.build())
.natMethod(NatMethod.NONE)
.besuController(besuController)
Expand Down Expand Up @@ -400,10 +400,10 @@ public void noEngineApiNoServiceForMethods() {
.p2PConfiguration(
P2PConfiguration.builder()
.p2pInterface("0.0.0.0")
.p2pPort(30303)
.p2pHost("127.0.0.1")
.port(30303)
.host("127.0.0.1")
.p2pEnabled(true)
.peerDiscoveryEnabled(true)
.discoveryEnabled(true)
.build())
.natMethod(NatMethod.NONE)
.besuController(besuController)
Expand Down
2 changes: 1 addition & 1 deletion besu/src/test/java/org/hyperledger/besu/RunnerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private void syncFromGenesis(final SyncMode mode, final GenesisConfigFile genesi
final RunnerBuilder runnerBuilder =
new RunnerBuilder()
.vertx(vertx)
.p2PConfiguration(P2PConfiguration.builder().p2pHost(listenHost).p2pPort(0).build())
.p2PConfiguration(P2PConfiguration.builder().host(listenHost).port(0).build())
.metricsSystem(noOpMetricsSystem)
.permissioningService(new PermissioningServiceImpl())
.staticNodes(emptySet())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ public int getMaxRemoteInitiatedPeers() {
public static P2PConfiguration createDefault() {
return new Builder()
.p2pEnabled(true)
.peerDiscoveryEnabled(true)
.p2pHost(autoDiscoverDefaultIP().getHostAddress())
.discoveryEnabled(true)
.host(autoDiscoverDefaultIP().getHostAddress())
.p2pInterface(NetworkUtility.INADDR_ANY)
.p2pPort(EnodeURLImpl.DEFAULT_LISTENING_PORT)
.port(EnodeURLImpl.DEFAULT_LISTENING_PORT)
.maxPeers(25)
.maxRemoteConnectionsPercentage(
Fraction.fromFloat(DEFAULT_FRACTION_REMOTE_CONNECTIONS_ALLOWED).toPercentage())
Expand All @@ -145,9 +145,9 @@ public static P2PConfiguration.Builder builder() {

public static class Builder {
private boolean p2pEnabled = true;
private boolean peerDiscoveryEnabled = true;
private boolean discoveryEnabled = true;
private List<String> bootNodes;
private String p2pHost;
private String host;
private String p2pInterface = NetworkUtility.INADDR_ANY;
private int p2pPort = EnodeURLImpl.DEFAULT_LISTENING_PORT;
private int maxPeers;
Expand All @@ -164,8 +164,8 @@ public Builder p2pEnabled(final boolean p2pEnabled) {
return this;
}

public Builder peerDiscoveryEnabled(final boolean peerDiscoveryEnabled) {
this.peerDiscoveryEnabled = peerDiscoveryEnabled;
public Builder discoveryEnabled(final boolean discoveryEnabled) {
this.discoveryEnabled = discoveryEnabled;
return this;
}

Expand All @@ -174,8 +174,8 @@ public Builder bootNodes(final List<String> bootNodes) {
return this;
}

public Builder p2pHost(final String p2pHost) {
this.p2pHost = p2pHost;
public Builder host(final String host) {
this.host = host;
return this;
}

Expand All @@ -184,8 +184,8 @@ public Builder p2pInterface(final String p2pInterface) {
return this;
}

public Builder p2pPort(final int p2pPort) {
this.p2pPort = p2pPort;
public Builder port(final int listeningPort) {
this.p2pPort = listeningPort;
return this;
}

Expand Down Expand Up @@ -228,9 +228,9 @@ public Builder allowedSubnets(final List<SubnetInfo> allowedSubnets) {
public P2PConfiguration build() {
return new P2PConfiguration(
p2pEnabled,
peerDiscoveryEnabled,
discoveryEnabled,
bootNodes,
p2pHost,
host,
p2pInterface,
p2pPort,
maxPeers,
Expand Down

0 comments on commit 9a5ca85

Please sign in to comment.