Skip to content

Commit

Permalink
Revert "Add plugin API to select Transactions (hyperledger#5396)" (hy…
Browse files Browse the repository at this point in the history
…perledger#5499)

* Revert "Add plugin API to select Transactions (hyperledger#5396)"

This reverts commit 65bcc55.

Signed-off-by: Simon Dudley <simon.dudley@consensys.net>
  • Loading branch information
siladu authored May 26, 2023
1 parent 128f95e commit a0c6052
Show file tree
Hide file tree
Showing 68 changed files with 144 additions and 534 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public String getHostName() {
return LOCALHOST;
}

public NodeRequests nodeRequests() {
private NodeRequests nodeRequests() {
Optional<WebSocketService> websocketService = Optional.empty();
if (nodeRequests == null) {
final Web3jService web3jService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@
import org.hyperledger.besu.plugin.services.PicoCLIOptions;
import org.hyperledger.besu.plugin.services.SecurityModuleService;
import org.hyperledger.besu.plugin.services.StorageService;
import org.hyperledger.besu.plugin.services.TransactionSelectionService;
import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBPlugin;
import org.hyperledger.besu.plugin.services.txselection.TransactionSelectorFactory;
import org.hyperledger.besu.services.BesuConfigurationImpl;
import org.hyperledger.besu.services.BesuEventsImpl;
import org.hyperledger.besu.services.BesuPluginContextImpl;
Expand All @@ -56,7 +54,6 @@
import org.hyperledger.besu.services.RpcEndpointServiceImpl;
import org.hyperledger.besu.services.SecurityModuleServiceImpl;
import org.hyperledger.besu.services.StorageServiceImpl;
import org.hyperledger.besu.services.TransactionSelectionServiceImpl;

import java.io.File;
import java.nio.file.Path;
Expand All @@ -66,7 +63,6 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -95,22 +91,14 @@ private BesuPluginContextImpl buildPluginContext(
besuPluginContext.addService(StorageService.class, storageService);
besuPluginContext.addService(SecurityModuleService.class, securityModuleService);
besuPluginContext.addService(PicoCLIOptions.class, new PicoCLIOptionsImpl(commandLine));
besuPluginContext.addService(
TransactionSelectionService.class, new TransactionSelectionServiceImpl());

final Path pluginsPath;
final String pluginDirEnv = System.getenv("besu.plugins.dir");
if (pluginDirEnv == null || pluginDirEnv.isEmpty()) {
pluginsPath = node.homeDirectory().resolve("plugins");
final File pluginsDirFile = pluginsPath.toFile();
if (!pluginsDirFile.isDirectory()) {
pluginsDirFile.mkdirs();
pluginsDirFile.deleteOnExit();
}
} else {
pluginsPath = Path.of(pluginDirEnv);
System.setProperty("besu.plugins.dir", pluginsPath.toString());

final Path pluginsPath = node.homeDirectory().resolve("plugins");
final File pluginsDirFile = pluginsPath.toFile();
if (!pluginsDirFile.isDirectory()) {
pluginsDirFile.mkdirs();
pluginsDirFile.deleteOnExit();
}
System.setProperty("besu.plugins.dir", pluginsPath.toString());
besuPluginContext.registerPlugins(pluginsPath);

commandLine.parseArgs(node.getConfiguration().getExtraCLIOptions().toArray(new String[0]));
Expand Down Expand Up @@ -181,9 +169,6 @@ public void startNode(final BesuNode node) {

final int maxPeers = 25;

final Optional<TransactionSelectorFactory> transactionSelectorFactory =
getTransactionSelectorFactory(besuPluginContext);

builder
.synchronizerConfiguration(new SynchronizerConfiguration.Builder().build())
.dataDirectory(node.homeDirectory())
Expand All @@ -205,8 +190,7 @@ public void startNode(final BesuNode node) {
.lowerBoundPeers(maxPeers)
.maxRemotelyInitiatedPeers(15)
.networkConfiguration(node.getNetworkingConfiguration())
.randomPeerPriority(false)
.transactionSelectorFactory(transactionSelectorFactory);
.randomPeerPriority(false);

node.getGenesisConfig()
.map(GenesisConfigFile::fromConfig)
Expand Down Expand Up @@ -315,11 +299,4 @@ public void startConsoleCapture() {
public String getConsoleContents() {
throw new RuntimeException("Console contents can only be captured in process execution");
}

private Optional<TransactionSelectorFactory> getTransactionSelectorFactory(
final BesuPluginContextImpl besuPluginContext) {
final Optional<TransactionSelectionService> txSelectionService =
besuPluginContext.getService(TransactionSelectionService.class);
return txSelectionService.isPresent() ? txSelectionService.get().get() : Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,33 +107,10 @@ public BesuNode createMinerNode(
return create(config);
}

public BesuNode createMinerNodeWithExtraCliOptions(
final String name,
final UnaryOperator<BesuNodeConfigurationBuilder> configModifier,
final List<String> extraCliOptions)
throws IOException {
BesuNodeConfigurationBuilder builder =
new BesuNodeConfigurationBuilder()
.name(name)
.miningEnabled()
.jsonRpcEnabled()
.webSocketEnabled()
.extraCLIOptions(extraCliOptions);
builder = configModifier.apply(builder);
final BesuNodeConfiguration config = builder.build();

return create(config);
}

public BesuNode createMinerNode(final String name) throws IOException {
return createMinerNode(name, UnaryOperator.identity());
}

public BesuNode createMinerNodeWithExtraCliOptions(
final String name, final List<String> extraCliOptions) throws IOException {
return createMinerNodeWithExtraCliOptions(name, UnaryOperator.identity(), extraCliOptions);
}

public BesuNode createMinerNodeWithRevertReasonEnabled(final String name) throws IOException {
return createMinerNode(name, BesuNodeConfigurationBuilder::revertReasonEnabled);
}
Expand Down
29 changes: 2 additions & 27 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,12 @@
import org.hyperledger.besu.plugin.services.SecurityModuleService;
import org.hyperledger.besu.plugin.services.StorageService;
import org.hyperledger.besu.plugin.services.TraceService;
import org.hyperledger.besu.plugin.services.TransactionSelectionService;
import org.hyperledger.besu.plugin.services.exception.StorageException;
import org.hyperledger.besu.plugin.services.metrics.MetricCategory;
import org.hyperledger.besu.plugin.services.metrics.MetricCategoryRegistry;
import org.hyperledger.besu.plugin.services.securitymodule.SecurityModule;
import org.hyperledger.besu.plugin.services.storage.PrivacyKeyValueStorageFactory;
import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBPlugin;
import org.hyperledger.besu.plugin.services.txselection.TransactionSelectorFactory;
import org.hyperledger.besu.services.BesuEventsImpl;
import org.hyperledger.besu.services.BesuPluginContextImpl;
import org.hyperledger.besu.services.BlockchainServiceImpl;
Expand All @@ -185,7 +183,6 @@
import org.hyperledger.besu.services.SecurityModuleServiceImpl;
import org.hyperledger.besu.services.StorageServiceImpl;
import org.hyperledger.besu.services.TraceServiceImpl;
import org.hyperledger.besu.services.TransactionSelectionServiceImpl;
import org.hyperledger.besu.services.kvstore.InMemoryStoragePlugin;
import org.hyperledger.besu.util.InvalidConfigurationException;
import org.hyperledger.besu.util.LogConfigurator;
Expand Down Expand Up @@ -237,7 +234,6 @@
import io.vertx.core.metrics.MetricsOptions;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.units.bigints.UInt256;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import picocli.AutoComplete;
import picocli.CommandLine;
Expand Down Expand Up @@ -364,8 +360,6 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
@CommandLine.ArgGroup(validate = false, heading = "@|bold P2P Discovery Options|@%n")
P2PDiscoveryOptionGroup p2PDiscoveryOptionGroup = new P2PDiscoveryOptionGroup();

private final TransactionSelectionServiceImpl transactionSelectionServiceImpl;

static class P2PDiscoveryOptionGroup {

// Public IP stored to prevent having to research it each time we need it.
Expand Down Expand Up @@ -1386,8 +1380,7 @@ public BesuCommand(
new PermissioningServiceImpl(),
new PrivacyPluginServiceImpl(),
new PkiBlockCreationConfigurationProvider(),
new RpcEndpointServiceImpl(),
new TransactionSelectionServiceImpl());
new RpcEndpointServiceImpl());
}

/**
Expand All @@ -1407,7 +1400,6 @@ public BesuCommand(
* @param privacyPluginService instance of PrivacyPluginServiceImpl
* @param pkiBlockCreationConfigProvider instance of PkiBlockCreationConfigurationProvider
* @param rpcEndpointServiceImpl instance of RpcEndpointServiceImpl
* @param transactionSelectionServiceImpl instance of TransactionSelectionServiceImpl
*/
@VisibleForTesting
protected BesuCommand(
Expand All @@ -1424,8 +1416,7 @@ protected BesuCommand(
final PermissioningServiceImpl permissioningService,
final PrivacyPluginServiceImpl privacyPluginService,
final PkiBlockCreationConfigurationProvider pkiBlockCreationConfigProvider,
final RpcEndpointServiceImpl rpcEndpointServiceImpl,
final TransactionSelectionServiceImpl transactionSelectionServiceImpl) {
final RpcEndpointServiceImpl rpcEndpointServiceImpl) {
this.besuComponent = besuComponent;
this.logger = besuComponent.getBesuCommandLogger();
this.rlpBlockImporter = rlpBlockImporter;
Expand All @@ -1443,7 +1434,6 @@ protected BesuCommand(
besuPluginContext.addService(BesuConfiguration.class, pluginCommonConfiguration);
this.pkiBlockCreationConfigProvider = pkiBlockCreationConfigProvider;
this.rpcEndpointServiceImpl = rpcEndpointServiceImpl;
this.transactionSelectionServiceImpl = transactionSelectionServiceImpl;
}

/**
Expand Down Expand Up @@ -1624,8 +1614,6 @@ private void preparePlugins() {
besuPluginContext.addService(PermissioningService.class, permissioningService);
besuPluginContext.addService(PrivacyPluginService.class, privacyPluginService);
besuPluginContext.addService(RpcEndpointService.class, rpcEndpointServiceImpl);
besuPluginContext.addService(
TransactionSelectionService.class, transactionSelectionServiceImpl);

// register built-in plugins
rocksDBPlugin = new RocksDBPlugin();
Expand Down Expand Up @@ -1727,9 +1715,6 @@ private void startPlugins() {
besuController.getProtocolContext().getWorldStateArchive()),
besuController.getProtocolSchedule()));

besuPluginContext.addService(
TransactionSelectionService.class, new TransactionSelectionServiceImpl());

besuController.getAdditionalPluginServices().appendPluginServices(besuPluginContext);
besuPluginContext.startPlugins();
}
Expand Down Expand Up @@ -2256,15 +2241,12 @@ public BesuController buildController() {
*/
public BesuControllerBuilder getControllerBuilder() {
final KeyValueStorageProvider storageProvider = keyValueStorageProvider(keyValueStorageName);
final Optional<TransactionSelectorFactory> transactionSelectorFactory =
getTransactionSelectorFactory();
return controllerBuilderFactory
.fromEthNetworkConfig(
updateNetworkConfig(network), genesisConfigOverrides, getDefaultSyncModeIfNotSet())
.synchronizerConfiguration(buildSyncConfig())
.ethProtocolConfiguration(unstableEthProtocolOptions.toDomainObject())
.networkConfiguration(unstableNetworkingOptions.toDomainObject())
.transactionSelectorFactory(transactionSelectorFactory)
.dataDirectory(dataDir())
.miningParameters(
new MiningParameters.Builder()
Expand Down Expand Up @@ -2314,13 +2296,6 @@ public BesuControllerBuilder getControllerBuilder() {
.chainPruningConfiguration(unstableChainPruningOptions.toDomainObject());
}

@NotNull
private Optional<TransactionSelectorFactory> getTransactionSelectorFactory() {
final Optional<TransactionSelectionService> txSelectionService =
besuPluginContext.getService(TransactionSelectionService.class);
return txSelectionService.isPresent() ? txSelectionService.get().get() : Optional.empty();
}

private GraphQLConfiguration graphQLConfiguration() {

CommandLineUtils.checkOptionDependencies(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
import org.hyperledger.besu.metrics.ObservableMetricsSystem;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.permissioning.NodeMessagePermissioningProvider;
import org.hyperledger.besu.plugin.services.txselection.TransactionSelectorFactory;

import java.io.Closeable;
import java.math.BigInteger;
Expand Down Expand Up @@ -180,7 +179,6 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides

private NetworkingConfiguration networkingConfiguration;
private Boolean randomPeerPriority;
private Optional<TransactionSelectorFactory> transactionSelectorFactory = Optional.empty();
/** the Dagger configured context that can provide dependencies */
protected Optional<BesuComponent> besuComponent = Optional.empty();

Expand Down Expand Up @@ -524,18 +522,6 @@ public BesuControllerBuilder randomPeerPriority(final Boolean randomPeerPriority
return this;
}

/**
* sets the transactionSelectorFactory in the builder
*
* @param transactionSelectorFactory the optional transaction selector factory
* @return the besu controller builder
*/
public BesuControllerBuilder transactionSelectorFactory(
final Optional<TransactionSelectorFactory> transactionSelectorFactory) {
this.transactionSelectorFactory = transactionSelectorFactory;
return this;
}

/**
* Build besu controller.
*
Expand Down Expand Up @@ -589,11 +575,7 @@ public BesuController build() {

final ProtocolContext protocolContext =
createProtocolContext(
blockchain,
worldStateArchive,
protocolSchedule,
this::createConsensusContext,
transactionSelectorFactory);
blockchain, worldStateArchive, protocolSchedule, this::createConsensusContext);
validateContext(protocolContext);

if (chainPrunerConfiguration.getChainPruningEnabled()) {
Expand Down Expand Up @@ -1009,21 +991,15 @@ protected EthProtocolManager createEthProtocolManager(
* @param worldStateArchive the world state archive
* @param protocolSchedule the protocol schedule
* @param consensusContextFactory the consensus context factory
* @param transactionSelectorFactory optional transaction selector factory
* @return the protocol context
*/
protected ProtocolContext createProtocolContext(
final MutableBlockchain blockchain,
final WorldStateArchive worldStateArchive,
final ProtocolSchedule protocolSchedule,
final ConsensusContextFactory consensusContextFactory,
final Optional<TransactionSelectorFactory> transactionSelectorFactory) {
final ConsensusContextFactory consensusContextFactory) {
return ProtocolContext.init(
blockchain,
worldStateArchive,
protocolSchedule,
consensusContextFactory,
transactionSelectorFactory);
blockchain, worldStateArchive, protocolSchedule, consensusContextFactory);
}

private Optional<SnapProtocolManager> createSnapProtocolManager(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
import org.hyperledger.besu.evm.internal.EvmConfiguration;
import org.hyperledger.besu.metrics.ObservableMetricsSystem;
import org.hyperledger.besu.plugin.services.permissioning.NodeMessagePermissioningProvider;
import org.hyperledger.besu.plugin.services.txselection.TransactionSelectorFactory;

import java.math.BigInteger;
import java.nio.file.Path;
Expand Down Expand Up @@ -175,14 +174,9 @@ protected ProtocolContext createProtocolContext(
final MutableBlockchain blockchain,
final WorldStateArchive worldStateArchive,
final ProtocolSchedule protocolSchedule,
final ConsensusContextFactory consensusContextFactory,
final Optional<TransactionSelectorFactory> transactionSelectorFactory) {
final ConsensusContextFactory consensusContextFactory) {
return MigratingProtocolContext.init(
blockchain,
worldStateArchive,
protocolSchedule,
consensusContextFactory,
transactionSelectorFactory);
blockchain, worldStateArchive, protocolSchedule, consensusContextFactory);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import org.hyperledger.besu.evm.internal.EvmConfiguration;
import org.hyperledger.besu.metrics.ObservableMetricsSystem;
import org.hyperledger.besu.plugin.services.permissioning.NodeMessagePermissioningProvider;
import org.hyperledger.besu.plugin.services.txselection.TransactionSelectorFactory;

import java.math.BigInteger;
import java.nio.file.Path;
Expand Down Expand Up @@ -189,15 +188,10 @@ protected ProtocolContext createProtocolContext(
final MutableBlockchain blockchain,
final WorldStateArchive worldStateArchive,
final ProtocolSchedule protocolSchedule,
final ConsensusContextFactory consensusContextFactory,
final Optional<TransactionSelectorFactory> transactionSelectorFactory) {
final ConsensusContextFactory consensusContextFactory) {
final ProtocolContext protocolContext =
super.createProtocolContext(
blockchain,
worldStateArchive,
protocolSchedule,
consensusContextFactory,
transactionSelectorFactory);
blockchain, worldStateArchive, protocolSchedule, consensusContextFactory);
transitionProtocolSchedule.setProtocolContext(protocolContext);
return protocolContext;
}
Expand Down
Loading

0 comments on commit a0c6052

Please sign in to comment.