Skip to content

Commit

Permalink
Add suport for --plugins option in acceptance tests (hyperledger#7713)
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio Di Fabio <[email protected]>
  • Loading branch information
fab-10 authored Oct 2, 2024
1 parent 9310e10 commit 94099d1
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public class BesuNode implements NodeConfiguration, RunnableNode, AutoCloseable
private boolean useWsForJsonRpc = false;
private String token = null;
private final List<String> plugins = new ArrayList<>();
private final List<String> requestedPlugins;
private final List<String> extraCLIOptions;
private final List<String> staticNodes;
private boolean isDnsEnabled = false;
Expand Down Expand Up @@ -163,6 +164,7 @@ public BesuNode(
final boolean secp256k1Native,
final boolean altbn128Native,
final List<String> plugins,
final List<String> requestedPlugins,
final List<String> extraCLIOptions,
final List<String> staticNodes,
final boolean isDnsEnabled,
Expand Down Expand Up @@ -224,6 +226,7 @@ public BesuNode(
LOG.error("Could not find plugin \"{}\" in resources", pluginName);
}
});
this.requestedPlugins = requestedPlugins;
engineRpcConfiguration.ifPresent(
config -> MergeConfigOptions.setMergeEnabled(config.isEnabled()));
this.extraCLIOptions = extraCLIOptions;
Expand Down Expand Up @@ -738,6 +741,10 @@ public List<String> getPlugins() {
return plugins;
}

public List<String> getRequestedPlugins() {
return requestedPlugins;
}

@Override
public List<String> getExtraCLIOptions() {
return extraCLIOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,11 @@ private List<String> commandlineArgs(final BesuNode node, final Path dataDir) {
params.add("--logging=" + level);
}

if (!node.getRequestedPlugins().isEmpty()) {
params.add(
"--plugins=" + node.getRequestedPlugins().stream().collect(Collectors.joining(",")));
}

params.addAll(node.getRunCommand());
return params;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.plugins.PluginConfiguration;
import org.hyperledger.besu.ethereum.core.plugins.PluginInfo;
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration;
import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration;
import org.hyperledger.besu.ethereum.eth.transactions.BlobCacheModule;
Expand Down Expand Up @@ -302,6 +303,12 @@ public List<String> provideExtraCLIOptions() {
return toProvide.getExtraCLIOptions();
}

@Provides
@Named("RequestedPlugins")
public List<String> provideRequestedPlugins() {
return toProvide.getRequestedPlugins();
}

@Provides
Path provideDataDir() {
return toProvide.homeDirectory();
Expand Down Expand Up @@ -469,7 +476,8 @@ public BesuPluginContextImpl providePluginContext(
final RpcEndpointServiceImpl rpcEndpointServiceImpl,
final BesuConfiguration commonPluginConfiguration,
final PermissioningServiceImpl permissioningService,
final @Named("ExtraCLIOptions") List<String> extraCLIOptions) {
final @Named("ExtraCLIOptions") List<String> extraCLIOptions,
final @Named("RequestedPlugins") List<String> requestedPlugins) {
final CommandLine commandLine = new CommandLine(CommandSpec.create());
final BesuPluginContextImpl besuPluginContext = new BesuPluginContextImpl();
besuPluginContext.addService(StorageService.class, storageService);
Expand Down Expand Up @@ -504,7 +512,10 @@ public BesuPluginContextImpl providePluginContext(
besuPluginContext.addService(PrivacyPluginService.class, new PrivacyPluginServiceImpl());

besuPluginContext.initialize(
new PluginConfiguration.Builder().pluginsDir(pluginsPath).build());
new PluginConfiguration.Builder()
.pluginsDir(pluginsPath)
.requestedPlugins(requestedPlugins.stream().map(PluginInfo::new).toList())
.build());
besuPluginContext.registerPlugins();
commandLine.parseArgs(extraCLIOptions.toArray(new String[0]));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class BesuNodeConfiguration {
private final boolean secp256k1Native;
private final boolean altbn128Native;
private final List<String> plugins;
private final List<String> requestedPlugins;
private final List<String> extraCLIOptions;
private final List<String> staticNodes;
private final boolean isDnsEnabled;
Expand Down Expand Up @@ -102,6 +103,7 @@ public class BesuNodeConfiguration {
final boolean secp256k1Native,
final boolean altbn128Native,
final List<String> plugins,
final List<String> requestedPlugins,
final List<String> extraCLIOptions,
final List<String> staticNodes,
final boolean isDnsEnabled,
Expand Down Expand Up @@ -137,6 +139,7 @@ public class BesuNodeConfiguration {
this.secp256k1Native = secp256k1Native;
this.altbn128Native = altbn128Native;
this.plugins = plugins;
this.requestedPlugins = requestedPlugins;
this.extraCLIOptions = extraCLIOptions;
this.staticNodes = staticNodes;
this.isDnsEnabled = isDnsEnabled;
Expand Down Expand Up @@ -239,6 +242,10 @@ public List<String> getPlugins() {
return plugins;
}

public List<String> getRequestedPlugins() {
return requestedPlugins;
}

public List<String> getExtraCLIOptions() {
return extraCLIOptions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public class BesuNodeConfigurationBuilder {
private boolean secp256K1Native = true;
private boolean altbn128Native = true;
private final List<String> plugins = new ArrayList<>();
private final List<String> requestedPlugins = new ArrayList<>();
private final List<String> extraCLIOptions = new ArrayList<>();
private List<String> staticNodes = new ArrayList<>();
private boolean isDnsEnabled = false;
Expand Down Expand Up @@ -448,6 +449,12 @@ public BesuNodeConfigurationBuilder plugins(final List<String> plugins) {
return this;
}

public BesuNodeConfigurationBuilder requestedPlugins(final List<String> requestedPlugins) {
this.requestedPlugins.clear();
this.requestedPlugins.addAll(requestedPlugins);
return this;
}

public BesuNodeConfigurationBuilder extraCLIOptions(final List<String> extraCLIOptions) {
this.extraCLIOptions.clear();
this.extraCLIOptions.addAll(extraCLIOptions);
Expand Down Expand Up @@ -545,6 +552,7 @@ public BesuNodeConfiguration build() {
secp256K1Native,
altbn128Native,
plugins,
requestedPlugins,
extraCLIOptions,
staticNodes,
isDnsEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public BesuNode create(final BesuNodeConfiguration config) throws IOException {
config.isSecp256k1Native(),
config.isAltbn128Native(),
config.getPlugins(),
config.getRequestedPlugins(),
config.getExtraCLIOptions(),
config.getStaticNodes(),
config.isDnsEnabled(),
Expand Down

0 comments on commit 94099d1

Please sign in to comment.