Skip to content

Commit

Permalink
Updated ATs DSL to create PKI QBFT node configuration (hyperledger#2670)
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas Saldanha <lucascrsaldanha@gmail.com>
  • Loading branch information
lucassaldanha authored Aug 25, 2021
1 parent 9d91136 commit 68f222b
Show file tree
Hide file tree
Showing 14 changed files with 319 additions and 38 deletions.
1 change: 1 addition & 0 deletions acceptance-tests/dsl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies {
implementation project(':ethereum:eth')
implementation project(':ethereum:p2p')
implementation project(':pki')
implementation project(path: ':pki', configuration: 'testArtifacts')
implementation project(':ethereum:permissioning')
implementation project(':ethereum:rlp')
implementation project(':metrics:core')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.hyperledger.besu.ethereum.p2p.rlpx.connections.netty.TLSConfiguration;
import org.hyperledger.besu.ethereum.permissioning.PermissioningConfiguration;
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
import org.hyperledger.besu.pki.config.PkiKeyStoreConfiguration;
import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition;
import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.NodeConfiguration;
import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.genesis.GenesisConfigurationProvider;
Expand Down Expand Up @@ -118,6 +119,7 @@ public class BesuNode implements NodeConfiguration, RunnableNode, AutoCloseable
private final List<String> staticNodes;
private boolean isDnsEnabled = false;
private Optional<Integer> exitCode = Optional.empty();
private Optional<PkiKeyStoreConfiguration> pkiKeyStoreConfiguration = Optional.empty();

public BesuNode(
final String name,
Expand Down Expand Up @@ -145,7 +147,8 @@ public BesuNode(
final boolean isDnsEnabled,
final Optional<PrivacyParameters> privacyParameters,
final List<String> runCommand,
final Optional<KeyPair> keyPair)
final Optional<KeyPair> keyPair,
final Optional<PkiKeyStoreConfiguration> pkiKeyStoreConfiguration)
throws IOException {
this.homeDirectory = dataPath.orElseGet(BesuNode::createTmpDataDirectory);
keyfilePath.ifPresent(
Expand Down Expand Up @@ -195,6 +198,7 @@ public BesuNode(
this.staticNodes = staticNodes;
this.isDnsEnabled = isDnsEnabled;
privacyParameters.ifPresent(this::setPrivacyParameters);
this.pkiKeyStoreConfiguration = pkiKeyStoreConfiguration;
LOG.info("Created BesuNode {}", this.toString());
}

Expand Down Expand Up @@ -656,6 +660,10 @@ public List<String> getRunCommand() {
return runCommand;
}

public Optional<PkiKeyStoreConfiguration> getPkiKeyStoreConfiguration() {
return pkiKeyStoreConfiguration;
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,34 @@ public void startNode(final BesuNode node) {
String.valueOf(
permissioningConfiguration.getNodeSmartContractInterfaceVersion()));
});

node.getPkiKeyStoreConfiguration()
.ifPresent(
pkiConfig -> {
params.add("--Xpki-block-creation-enabled");

params.add("--Xpki-block-creation-keystore-certificate-alias");
params.add(pkiConfig.getCertificateAlias());

params.add("--Xpki-block-creation-keystore-type");
params.add(pkiConfig.getKeyStoreType());

params.add("--Xpki-block-creation-keystore-file");
params.add(pkiConfig.getKeyStorePath().toAbsolutePath().toString());

params.add("--Xpki-block-creation-keystore-password-file");
params.add(pkiConfig.getKeyStorePasswordPath().toAbsolutePath().toString());

params.add("--Xpki-block-creation-truststore-type");
params.add(pkiConfig.getTrustStoreType());

params.add("--Xpki-block-creation-truststore-file");
params.add(pkiConfig.getTrustStorePath().toAbsolutePath().toString());

params.add("--Xpki-block-creation-truststore-password-file");
params.add(pkiConfig.getTrustStorePasswordPath().toAbsolutePath().toString());
});

params.addAll(node.getExtraCLIOptions());

params.add("--key-value-storage");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.hyperledger.besu.Runner;
import org.hyperledger.besu.RunnerBuilder;
import org.hyperledger.besu.cli.config.EthNetworkConfig;
import org.hyperledger.besu.consensus.qbft.pki.PkiBlockCreationConfigurationProvider;
import org.hyperledger.besu.controller.BesuController;
import org.hyperledger.besu.controller.BesuControllerBuilder;
import org.hyperledger.besu.crypto.KeyPairSecurityModule;
Expand Down Expand Up @@ -163,6 +164,10 @@ public void startNode(final BesuNode node) {
.isRevertReasonEnabled(node.isRevertReasonEnabled())
.storageProvider(storageProvider)
.gasLimitCalculator(GasLimitCalculator.constant())
.pkiBlockCreationConfiguration(
node.getPkiKeyStoreConfiguration()
.map(
(pkiConfig) -> new PkiBlockCreationConfigurationProvider().load(pkiConfig)))
.build();

final RunnerBuilder runnerBuilder = new RunnerBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.hyperledger.besu.ethereum.p2p.rlpx.connections.netty.TLSConfiguration;
import org.hyperledger.besu.ethereum.permissioning.PermissioningConfiguration;
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
import org.hyperledger.besu.pki.config.PkiKeyStoreConfiguration;
import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.genesis.GenesisConfigurationProvider;

import java.nio.file.Path;
Expand Down Expand Up @@ -58,6 +59,7 @@ public class BesuNodeConfiguration {
private final List<String> runCommand;
private final NetworkName network;
private final Optional<KeyPair> keyPair;
private final Optional<PkiKeyStoreConfiguration> pkiKeyStoreConfiguration;

BesuNodeConfiguration(
final String name,
Expand Down Expand Up @@ -85,7 +87,8 @@ public class BesuNodeConfiguration {
final boolean isDnsEnabled,
final Optional<PrivacyParameters> privacyParameters,
final List<String> runCommand,
final Optional<KeyPair> keyPair) {
final Optional<KeyPair> keyPair,
final Optional<PkiKeyStoreConfiguration> pkiKeyStoreConfiguration) {
this.name = name;
this.miningParameters = miningParameters;
this.jsonRpcConfiguration = jsonRpcConfiguration;
Expand All @@ -112,6 +115,7 @@ public class BesuNodeConfiguration {
this.privacyParameters = privacyParameters;
this.runCommand = runCommand;
this.keyPair = keyPair;
this.pkiKeyStoreConfiguration = pkiKeyStoreConfiguration;
}

public String getName() {
Expand Down Expand Up @@ -217,4 +221,8 @@ public NetworkName getNetwork() {
public Optional<KeyPair> getKeyPair() {
return keyPair;
}

public Optional<PkiKeyStoreConfiguration> getPkiKeyStoreConfiguration() {
return pkiKeyStoreConfiguration;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.hyperledger.besu.ethereum.p2p.rlpx.connections.netty.TLSConfiguration;
import org.hyperledger.besu.ethereum.permissioning.PermissioningConfiguration;
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
import org.hyperledger.besu.pki.config.PkiKeyStoreConfiguration;
import org.hyperledger.besu.pki.keystore.KeyStoreWrapper;
import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.genesis.GenesisConfigurationProvider;

Expand Down Expand Up @@ -80,6 +81,7 @@ public class BesuNodeConfigurationBuilder {
private Optional<PrivacyParameters> privacyParameters = Optional.empty();
private List<String> runCommand = new ArrayList<>();
private Optional<KeyPair> keyPair = Optional.empty();
private Optional<PkiKeyStoreConfiguration> pkiKeyStoreConfiguration = Optional.empty();

public BesuNodeConfigurationBuilder() {
// Check connections more frequently during acceptance tests to cut down on
Expand Down Expand Up @@ -349,6 +351,13 @@ private Path createTemporaryFile(final String suffix) {
return tempFile.toPath();
}

public BesuNodeConfigurationBuilder pkiBlockCreationEnabled(
final PkiKeyStoreConfiguration pkiKeyStoreConfiguration) {
this.pkiKeyStoreConfiguration = Optional.of(pkiKeyStoreConfiguration);

return this;
}

public BesuNodeConfigurationBuilder discoveryEnabled(final boolean discoveryEnabled) {
this.discoveryEnabled = discoveryEnabled;
return this;
Expand Down Expand Up @@ -433,6 +442,7 @@ public BesuNodeConfiguration build() {
isDnsEnabled,
privacyParameters,
runCommand,
keyPair);
keyPair,
pkiKeyStoreConfiguration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.hyperledger.besu.tests.acceptance.dsl.node.Node;
import org.hyperledger.besu.tests.acceptance.dsl.node.RunnableNode;
import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.genesis.GenesisConfigurationFactory;
import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.pki.PkiKeystoreConfigurationFactory;

import java.io.File;
import java.io.IOException;
Expand All @@ -54,6 +55,8 @@ public class BesuNodeFactory {

private final GenesisConfigurationFactory genesis = new GenesisConfigurationFactory();
private final NodeConfigurationFactory node = new NodeConfigurationFactory();
private final PkiKeystoreConfigurationFactory pkiKeystoreConfigurationFactory =
new PkiKeystoreConfigurationFactory();

public BesuNode create(final BesuNodeConfiguration config) throws IOException {
return new BesuNode(
Expand Down Expand Up @@ -82,7 +85,8 @@ public BesuNode create(final BesuNodeConfiguration config) throws IOException {
config.isDnsEnabled(),
config.getPrivacyParameters(),
config.getRunCommand(),
config.getKeyPair());
config.getKeyPair(),
config.getPkiKeyStoreConfiguration());
}

public BesuNode createMinerNode(final String name) throws IOException {
Expand Down Expand Up @@ -392,6 +396,19 @@ public BesuNode createQbftNode(final String name) throws IOException {
.build());
}

public BesuNode createPkiQbftNode(final String name) throws IOException {
return create(
new BesuNodeConfigurationBuilder()
.name(name)
.miningEnabled()
.jsonRpcConfiguration(node.createJsonRpcWithQbftEnabledConfig(false))
.webSocketConfiguration(node.createWebSocketEnabledConfig())
.devMode(false)
.genesisConfigProvider(genesis::createQbftGenesisConfig)
.pkiBlockCreationEnabled(pkiKeystoreConfigurationFactory.createPkiConfig())
.build());
}

public BesuNode createCustomGenesisNode(
final String name, final String genesisPath, final boolean canBeBootnode) throws IOException {
return createCustomGenesisNode(name, genesisPath, canBeBootnode, false);
Expand Down Expand Up @@ -504,6 +521,24 @@ public BesuNode createQbftNodeWithValidators(final String name, final String...
.build());
}

public BesuNode createPkiQbftNodeWithValidators(final String name, final String... validators)
throws IOException {

return create(
new BesuNodeConfigurationBuilder()
.name(name)
.miningEnabled()
.jsonRpcConfiguration(node.createJsonRpcWithQbftEnabledConfig(false))
.webSocketConfiguration(node.createWebSocketEnabledConfig())
.devMode(false)
.pkiBlockCreationEnabled(pkiKeystoreConfigurationFactory.createPkiConfig())
.genesisConfigProvider(
nodes ->
node.createGenesisConfigForValidators(
asList(validators), nodes, genesis::createQbftGenesisConfig))
.build());
}

public BesuNode createNodeWithStaticNodes(final String name, final List<Node> staticNodes)
throws IOException {

Expand Down
Loading

0 comments on commit 68f222b

Please sign in to comment.