Skip to content

Commit

Permalink
Make fixed port optional when creating a BFT node
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
  • Loading branch information
matthew1001 committed May 21, 2024
1 parent 89e7738 commit 6ec0eeb
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -461,26 +461,30 @@ public BesuNode createIbft2Node(final String name, final String genesisFile) thr
.build());
}

public BesuNode createIbft2Node(final String name) throws IOException {
public BesuNode createIbft2Node(final String name, final boolean fixedPort) throws IOException {
JsonRpcConfiguration rpcConfig = node.createJsonRpcWithIbft2EnabledConfig(false);
rpcConfig.setPort(
Math.abs(name.hashCode() % 60000)
+ 1024); // Generate a consistent port for p2p based on node name
rpcConfig.addRpcApi("ADMIN,TXPOOL");
return create(
if (fixedPort) {
rpcConfig.setPort(
Math.abs(name.hashCode() % 60000)
+ 1024); // Generate a consistent port for p2p based on node name
}
BesuNodeConfigurationBuilder builder =
new BesuNodeConfigurationBuilder()
.name(name)
.miningEnabled()
.jsonRpcConfiguration(rpcConfig)
.webSocketConfiguration(node.createWebSocketEnabledConfig())
.devMode(false)
.genesisConfigProvider(GenesisConfigurationFactory::createIbft2GenesisConfig)
.p2pPort(
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)
.build());
.genesisConfigProvider(GenesisConfigurationFactory::createIbft2GenesisConfig);
if (fixedPort) {
builder.p2pPort(
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)
}
return create(builder.build());
}

public BesuNode createQbftNodeWithTLS(final String name, final String type) throws IOException {
Expand Down Expand Up @@ -508,26 +512,31 @@ public BesuNode createQbftNodeWithTLSPKCS11(final String name) throws IOExceptio
return createQbftNodeWithTLS(name, KeyStoreWrapper.KEYSTORE_TYPE_PKCS11);
}

public BesuNode createQbftNode(final String name) throws IOException {
public BesuNode createQbftNode(final String name, final boolean fixedPort) throws IOException {
JsonRpcConfiguration rpcConfig = node.createJsonRpcWithQbftEnabledConfig(false);
rpcConfig.setPort(
Math.abs(name.hashCode() % 60000)
+ 1024); // Generate a consistent port for p2p based on node name
rpcConfig.addRpcApi("ADMIN,TXPOOL");
return create(
if (fixedPort) {
rpcConfig.setPort(
Math.abs(name.hashCode() % 60000)
+ 1024); // Generate a consistent port for p2p based on node name
}

BesuNodeConfigurationBuilder builder =
new BesuNodeConfigurationBuilder()
.name(name)
.miningEnabled()
.jsonRpcConfiguration(rpcConfig)
.webSocketConfiguration(node.createWebSocketEnabledConfig())
.devMode(false)
.genesisConfigProvider(GenesisConfigurationFactory::createQbftGenesisConfig)
.p2pPort(
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)
.build());
.genesisConfigProvider(GenesisConfigurationFactory::createQbftGenesisConfig);
if (fixedPort) {
builder.p2pPort(
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)
}
return create(builder.build());
}

public BesuNode createCustomGenesisNode(
Expand Down
6 changes: 4 additions & 2 deletions acceptance-tests/tests/shanghai/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ plugins {
id 'org.web3j.solidity' version '0.4.1'
}

jar { enabled = false }
jar { enabled = true }

web3j { generatedPackageName = 'org.hyperledger.besu.tests.web3j.generated' }
web3j {
generatedPackageName = 'org.hyperledger.besu.tests.web3j.generated'
}

sourceSets.main.solidity.srcDirs = [
"$projectDir/shanghaicontracts"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ public static Stream<Arguments> getFactories() {
@FunctionalInterface
public interface NodeCreator {

BesuNode create(BesuNodeFactory factory, String name) throws Exception;
BesuNode create(BesuNodeFactory factory, String name, boolean fixedPort) throws Exception;
}

@FunctionalInterface
public interface FixedPortNodeCreator {

BesuNode createFixedPort(BesuNodeFactory factory, String name, boolean fixedPort)
throws Exception;
}

@FunctionalInterface
Expand All @@ -57,7 +64,11 @@ public BftAcceptanceTestParameterization(
}

public BesuNode createNode(BesuNodeFactory factory, String name) throws Exception {
return creatorFn.create(factory, name);
return creatorFn.create(factory, name, false);
}

public BesuNode createNodeFixedPort(BesuNodeFactory factory, String name) throws Exception {
return creatorFn.create(factory, name, true);
}

public BesuNode createNodeWithValidators(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ public void shouldBeStableDuringLongTest(
// in between certain steps. There should be no upper-limit to how long the test is run for
assertThat(getTestDurationMins()).isGreaterThanOrEqualTo(MIN_TEST_TIME_MINS);

final BesuNode minerNode1 = nodeFactory.createNode(besu, "miner1");
final BesuNode minerNode2 = nodeFactory.createNode(besu, "miner2");
final BesuNode minerNode3 = nodeFactory.createNode(besu, "miner3");
final BesuNode minerNode4 = nodeFactory.createNode(besu, "miner4");
final BesuNode minerNode1 = nodeFactory.createNodeFixedPort(besu, "miner1");
final BesuNode minerNode2 = nodeFactory.createNodeFixedPort(besu, "miner2");
final BesuNode minerNode3 = nodeFactory.createNodeFixedPort(besu, "miner3");
final BesuNode minerNode4 = nodeFactory.createNodeFixedPort(besu, "miner4");

// Each step should be given a minimum of 3 minutes to complete successfully. If the time
// give to run the soak test results in a time-per-step lower than this then the time
Expand Down

0 comments on commit 6ec0eeb

Please sign in to comment.