more changes

Signed-off-by: Stefan <stefan.pingel@consensys.net>
TransactionValidatorService
Stefan 1 year ago
parent 8dd80a781a
commit e609f5b370
  1. 19
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java
  2. 1
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeFactory.java
  3. 21
      besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
  4. 8
      besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java
  5. 4
      besu/src/main/java/org/hyperledger/besu/services/PluginTransactionValidatorServiceImpl.java
  6. 6
      besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java
  7. 2
      plugin-api/build.gradle
  8. 2
      plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PluginTransactionValidatorService.java
  9. 1
      plugin-api/src/main/java/org/hyperledger/besu/plugin/services/txvalidator/PluginTransactionValidator.java

@ -43,22 +43,23 @@ import org.hyperledger.besu.plugin.data.EnodeURL;
import org.hyperledger.besu.plugin.services.BesuConfiguration; import org.hyperledger.besu.plugin.services.BesuConfiguration;
import org.hyperledger.besu.plugin.services.BesuEvents; import org.hyperledger.besu.plugin.services.BesuEvents;
import org.hyperledger.besu.plugin.services.PicoCLIOptions; import org.hyperledger.besu.plugin.services.PicoCLIOptions;
import org.hyperledger.besu.plugin.services.PluginTransactionValidatorService;
import org.hyperledger.besu.plugin.services.SecurityModuleService; import org.hyperledger.besu.plugin.services.SecurityModuleService;
import org.hyperledger.besu.plugin.services.StorageService; import org.hyperledger.besu.plugin.services.StorageService;
import org.hyperledger.besu.plugin.services.TransactionSelectionService; import org.hyperledger.besu.plugin.services.TransactionSelectionService;
import org.hyperledger.besu.plugin.services.TransactionValidatorService;
import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBPlugin; import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBPlugin;
import org.hyperledger.besu.plugin.services.txselection.TransactionSelectorFactory; import org.hyperledger.besu.plugin.services.txselection.TransactionSelectorFactory;
import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionValidatorFactory;
import org.hyperledger.besu.services.BesuConfigurationImpl; import org.hyperledger.besu.services.BesuConfigurationImpl;
import org.hyperledger.besu.services.BesuEventsImpl; import org.hyperledger.besu.services.BesuEventsImpl;
import org.hyperledger.besu.services.BesuPluginContextImpl; import org.hyperledger.besu.services.BesuPluginContextImpl;
import org.hyperledger.besu.services.PermissioningServiceImpl; import org.hyperledger.besu.services.PermissioningServiceImpl;
import org.hyperledger.besu.services.PicoCLIOptionsImpl; import org.hyperledger.besu.services.PicoCLIOptionsImpl;
import org.hyperledger.besu.services.PluginTransactionValidatorServiceImpl;
import org.hyperledger.besu.services.RpcEndpointServiceImpl; import org.hyperledger.besu.services.RpcEndpointServiceImpl;
import org.hyperledger.besu.services.SecurityModuleServiceImpl; import org.hyperledger.besu.services.SecurityModuleServiceImpl;
import org.hyperledger.besu.services.StorageServiceImpl; import org.hyperledger.besu.services.StorageServiceImpl;
import org.hyperledger.besu.services.TransactionSelectionServiceImpl; import org.hyperledger.besu.services.TransactionSelectionServiceImpl;
import org.hyperledger.besu.services.TransactionValidatorServiceImpl;
import java.io.File; import java.io.File;
import java.nio.file.Path; import java.nio.file.Path;
@ -100,7 +101,7 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner {
besuPluginContext.addService( besuPluginContext.addService(
TransactionSelectionService.class, new TransactionSelectionServiceImpl()); TransactionSelectionService.class, new TransactionSelectionServiceImpl());
besuPluginContext.addService( besuPluginContext.addService(
TransactionValidatorService.class, new TransactionValidatorServiceImpl()); PluginTransactionValidatorService.class, new PluginTransactionValidatorServiceImpl());
final Path pluginsPath; final Path pluginsPath;
final String pluginDir = System.getProperty("besu.plugins.dir"); final String pluginDir = System.getProperty("besu.plugins.dir");
if (pluginDir == null || pluginDir.isEmpty()) { if (pluginDir == null || pluginDir.isEmpty()) {
@ -187,6 +188,8 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner {
final Optional<TransactionSelectorFactory> transactionSelectorFactory = final Optional<TransactionSelectorFactory> transactionSelectorFactory =
getTransactionSelectorFactory(besuPluginContext); getTransactionSelectorFactory(besuPluginContext);
final PluginTransactionValidatorFactory pluginTransactionValidatorFactory =
getPluginTransactionValidatorFactory(besuPluginContext);
builder builder
.synchronizerConfiguration(new SynchronizerConfiguration.Builder().build()) .synchronizerConfiguration(new SynchronizerConfiguration.Builder().build())
.dataDirectory(node.homeDirectory()) .dataDirectory(node.homeDirectory())
@ -209,7 +212,8 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner {
.maxRemotelyInitiatedPeers(15) .maxRemotelyInitiatedPeers(15)
.networkConfiguration(node.getNetworkingConfiguration()) .networkConfiguration(node.getNetworkingConfiguration())
.randomPeerPriority(false) .randomPeerPriority(false)
.transactionSelectorFactory(transactionSelectorFactory); .transactionSelectorFactory(transactionSelectorFactory)
.pluginTransactionValidatorFactory(pluginTransactionValidatorFactory);
node.getGenesisConfig() node.getGenesisConfig()
.map(GenesisConfigFile::fromConfig) .map(GenesisConfigFile::fromConfig)
@ -325,4 +329,11 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner {
besuPluginContext.getService(TransactionSelectionService.class); besuPluginContext.getService(TransactionSelectionService.class);
return txSelectionService.isPresent() ? txSelectionService.get().get() : Optional.empty(); return txSelectionService.isPresent() ? txSelectionService.get().get() : Optional.empty();
} }
private PluginTransactionValidatorFactory getPluginTransactionValidatorFactory(
final BesuPluginContextImpl besuPluginContext) {
final Optional<PluginTransactionValidatorService> txValidatorService =
besuPluginContext.getService(PluginTransactionValidatorService.class);
return txValidatorService.map(PluginTransactionValidatorService::get).orElse(null);
}
} }

@ -117,6 +117,7 @@ public class BesuNodeFactory {
.name(name) .name(name)
.miningEnabled() .miningEnabled()
.jsonRpcEnabled() .jsonRpcEnabled()
.jsonRpcTxPool()
.webSocketEnabled() .webSocketEnabled()
.extraCLIOptions(extraCliOptions); .extraCLIOptions(extraCliOptions);
builder = configModifier.apply(builder); builder = configModifier.apply(builder);

@ -164,13 +164,13 @@ import org.hyperledger.besu.plugin.services.BlockchainService;
import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.PermissioningService; import org.hyperledger.besu.plugin.services.PermissioningService;
import org.hyperledger.besu.plugin.services.PicoCLIOptions; import org.hyperledger.besu.plugin.services.PicoCLIOptions;
import org.hyperledger.besu.plugin.services.PluginTransactionValidatorService;
import org.hyperledger.besu.plugin.services.PrivacyPluginService; import org.hyperledger.besu.plugin.services.PrivacyPluginService;
import org.hyperledger.besu.plugin.services.RpcEndpointService; import org.hyperledger.besu.plugin.services.RpcEndpointService;
import org.hyperledger.besu.plugin.services.SecurityModuleService; import org.hyperledger.besu.plugin.services.SecurityModuleService;
import org.hyperledger.besu.plugin.services.StorageService; import org.hyperledger.besu.plugin.services.StorageService;
import org.hyperledger.besu.plugin.services.TraceService; import org.hyperledger.besu.plugin.services.TraceService;
import org.hyperledger.besu.plugin.services.TransactionSelectionService; import org.hyperledger.besu.plugin.services.TransactionSelectionService;
import org.hyperledger.besu.plugin.services.TransactionValidatorService;
import org.hyperledger.besu.plugin.services.exception.StorageException; import org.hyperledger.besu.plugin.services.exception.StorageException;
import org.hyperledger.besu.plugin.services.metrics.MetricCategory; import org.hyperledger.besu.plugin.services.metrics.MetricCategory;
import org.hyperledger.besu.plugin.services.metrics.MetricCategoryRegistry; import org.hyperledger.besu.plugin.services.metrics.MetricCategoryRegistry;
@ -184,13 +184,13 @@ import org.hyperledger.besu.services.BesuPluginContextImpl;
import org.hyperledger.besu.services.BlockchainServiceImpl; import org.hyperledger.besu.services.BlockchainServiceImpl;
import org.hyperledger.besu.services.PermissioningServiceImpl; import org.hyperledger.besu.services.PermissioningServiceImpl;
import org.hyperledger.besu.services.PicoCLIOptionsImpl; import org.hyperledger.besu.services.PicoCLIOptionsImpl;
import org.hyperledger.besu.services.PluginTransactionValidatorServiceImpl;
import org.hyperledger.besu.services.PrivacyPluginServiceImpl; import org.hyperledger.besu.services.PrivacyPluginServiceImpl;
import org.hyperledger.besu.services.RpcEndpointServiceImpl; import org.hyperledger.besu.services.RpcEndpointServiceImpl;
import org.hyperledger.besu.services.SecurityModuleServiceImpl; import org.hyperledger.besu.services.SecurityModuleServiceImpl;
import org.hyperledger.besu.services.StorageServiceImpl; import org.hyperledger.besu.services.StorageServiceImpl;
import org.hyperledger.besu.services.TraceServiceImpl; import org.hyperledger.besu.services.TraceServiceImpl;
import org.hyperledger.besu.services.TransactionSelectionServiceImpl; import org.hyperledger.besu.services.TransactionSelectionServiceImpl;
import org.hyperledger.besu.services.TransactionValidatorServiceImpl;
import org.hyperledger.besu.services.kvstore.InMemoryStoragePlugin; import org.hyperledger.besu.services.kvstore.InMemoryStoragePlugin;
import org.hyperledger.besu.util.InvalidConfigurationException; import org.hyperledger.besu.util.InvalidConfigurationException;
import org.hyperledger.besu.util.LogConfigurator; import org.hyperledger.besu.util.LogConfigurator;
@ -375,7 +375,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
P2PDiscoveryOptionGroup p2PDiscoveryOptionGroup = new P2PDiscoveryOptionGroup(); P2PDiscoveryOptionGroup p2PDiscoveryOptionGroup = new P2PDiscoveryOptionGroup();
private final TransactionSelectionServiceImpl transactionSelectionServiceImpl; private final TransactionSelectionServiceImpl transactionSelectionServiceImpl;
private final TransactionValidatorServiceImpl transactionValidatorServiceImpl; private final PluginTransactionValidatorServiceImpl transactionValidatorServiceImpl;
static class P2PDiscoveryOptionGroup { static class P2PDiscoveryOptionGroup {
@ -1360,7 +1360,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
new PkiBlockCreationConfigurationProvider(), new PkiBlockCreationConfigurationProvider(),
new RpcEndpointServiceImpl(), new RpcEndpointServiceImpl(),
new TransactionSelectionServiceImpl(), new TransactionSelectionServiceImpl(),
new TransactionValidatorServiceImpl()); new PluginTransactionValidatorServiceImpl());
} }
/** /**
@ -1400,7 +1400,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
final PkiBlockCreationConfigurationProvider pkiBlockCreationConfigProvider, final PkiBlockCreationConfigurationProvider pkiBlockCreationConfigProvider,
final RpcEndpointServiceImpl rpcEndpointServiceImpl, final RpcEndpointServiceImpl rpcEndpointServiceImpl,
final TransactionSelectionServiceImpl transactionSelectionServiceImpl, final TransactionSelectionServiceImpl transactionSelectionServiceImpl,
final TransactionValidatorServiceImpl transactionValidatorServiceImpl) { final PluginTransactionValidatorServiceImpl transactionValidatorServiceImpl) {
this.besuComponent = besuComponent; this.besuComponent = besuComponent;
this.logger = besuComponent.getBesuCommandLogger(); this.logger = besuComponent.getBesuCommandLogger();
this.rlpBlockImporter = rlpBlockImporter; this.rlpBlockImporter = rlpBlockImporter;
@ -1602,7 +1602,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
besuPluginContext.addService( besuPluginContext.addService(
TransactionSelectionService.class, transactionSelectionServiceImpl); TransactionSelectionService.class, transactionSelectionServiceImpl);
besuPluginContext.addService( besuPluginContext.addService(
TransactionValidatorService.class, transactionValidatorServiceImpl); PluginTransactionValidatorService.class, transactionValidatorServiceImpl);
// register built-in plugins // register built-in plugins
rocksDBPlugin = new RocksDBPlugin(); rocksDBPlugin = new RocksDBPlugin();
@ -2243,7 +2243,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
.ethProtocolConfiguration(unstableEthProtocolOptions.toDomainObject()) .ethProtocolConfiguration(unstableEthProtocolOptions.toDomainObject())
.networkConfiguration(unstableNetworkingOptions.toDomainObject()) .networkConfiguration(unstableNetworkingOptions.toDomainObject())
.transactionSelectorFactory(getTransactionSelectorFactory()) .transactionSelectorFactory(getTransactionSelectorFactory())
.pluginTransactionSelectorFactory(getPluginTransactionValidatorFactory()) .pluginTransactionValidatorFactory(getPluginTransactionValidatorFactory())
.dataDirectory(dataDir()) .dataDirectory(dataDir())
.miningParameters( .miningParameters(
new MiningParameters.Builder() new MiningParameters.Builder()
@ -2301,9 +2301,9 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
} }
private PluginTransactionValidatorFactory getPluginTransactionValidatorFactory() { private PluginTransactionValidatorFactory getPluginTransactionValidatorFactory() {
final Optional<TransactionValidatorService> txSValidatorService = final Optional<PluginTransactionValidatorService> txSValidatorService =
besuPluginContext.getService(TransactionValidatorService.class); besuPluginContext.getService(PluginTransactionValidatorService.class);
return txSValidatorService.map(TransactionValidatorService::get).orElse(null); return txSValidatorService.map(PluginTransactionValidatorService::get).orElse(null);
} }
private GraphQLConfiguration graphQLConfiguration() { private GraphQLConfiguration graphQLConfiguration() {
@ -2935,7 +2935,6 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
} }
private TransactionPoolConfiguration buildTransactionPoolConfiguration() { private TransactionPoolConfiguration buildTransactionPoolConfiguration() {
final var stableTxPoolOption = stableTransactionPoolOptions.toDomainObject(); final var stableTxPoolOption = stableTransactionPoolOptions.toDomainObject();
return ImmutableTransactionPoolConfiguration.builder() return ImmutableTransactionPoolConfiguration.builder()
.from(stableTxPoolOption) .from(stableTxPoolOption)

@ -540,7 +540,13 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides
return this; return this;
} }
public BesuControllerBuilder pluginTransactionSelectorFactory( /**
* sets the pluginTransactionValidatorFactory
*
* @param pluginTransactionValidatorFactory factory that creates plugin transaction Validators
* @return the besu controller builder
*/
public BesuControllerBuilder pluginTransactionValidatorFactory(
final PluginTransactionValidatorFactory pluginTransactionValidatorFactory) { final PluginTransactionValidatorFactory pluginTransactionValidatorFactory) {
this.pluginTransactionValidatorFactory = pluginTransactionValidatorFactory; this.pluginTransactionValidatorFactory = pluginTransactionValidatorFactory;
return this; return this;

@ -14,11 +14,11 @@
*/ */
package org.hyperledger.besu.services; package org.hyperledger.besu.services;
import org.hyperledger.besu.plugin.services.TransactionValidatorService; import org.hyperledger.besu.plugin.services.PluginTransactionValidatorService;
import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionValidatorFactory; import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionValidatorFactory;
/** The Transaction Selection service implementation. */ /** The Transaction Selection service implementation. */
public class TransactionValidatorServiceImpl implements TransactionValidatorService { public class PluginTransactionValidatorServiceImpl implements PluginTransactionValidatorService {
private PluginTransactionValidatorFactory factory; private PluginTransactionValidatorFactory factory;

@ -76,12 +76,12 @@ import org.hyperledger.besu.plugin.services.storage.PrivacyKeyValueStorageFactor
import org.hyperledger.besu.plugin.services.storage.SegmentIdentifier; import org.hyperledger.besu.plugin.services.storage.SegmentIdentifier;
import org.hyperledger.besu.services.BesuPluginContextImpl; import org.hyperledger.besu.services.BesuPluginContextImpl;
import org.hyperledger.besu.services.PermissioningServiceImpl; import org.hyperledger.besu.services.PermissioningServiceImpl;
import org.hyperledger.besu.services.PluginTransactionValidatorServiceImpl;
import org.hyperledger.besu.services.PrivacyPluginServiceImpl; import org.hyperledger.besu.services.PrivacyPluginServiceImpl;
import org.hyperledger.besu.services.RpcEndpointServiceImpl; import org.hyperledger.besu.services.RpcEndpointServiceImpl;
import org.hyperledger.besu.services.SecurityModuleServiceImpl; import org.hyperledger.besu.services.SecurityModuleServiceImpl;
import org.hyperledger.besu.services.StorageServiceImpl; import org.hyperledger.besu.services.StorageServiceImpl;
import org.hyperledger.besu.services.TransactionSelectionServiceImpl; import org.hyperledger.besu.services.TransactionSelectionServiceImpl;
import org.hyperledger.besu.services.TransactionValidatorServiceImpl;
import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage; import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -241,7 +241,7 @@ public abstract class CommandTestAbstract {
when(mockControllerBuilder.maxRemotelyInitiatedPeers(anyInt())) when(mockControllerBuilder.maxRemotelyInitiatedPeers(anyInt()))
.thenReturn(mockControllerBuilder); .thenReturn(mockControllerBuilder);
when(mockControllerBuilder.transactionSelectorFactory(any())).thenReturn(mockControllerBuilder); when(mockControllerBuilder.transactionSelectorFactory(any())).thenReturn(mockControllerBuilder);
when(mockControllerBuilder.pluginTransactionSelectorFactory(any())) when(mockControllerBuilder.pluginTransactionValidatorFactory(any()))
.thenReturn(mockControllerBuilder); .thenReturn(mockControllerBuilder);
when(mockControllerBuilder.besuComponent(any(BesuComponent.class))) when(mockControllerBuilder.besuComponent(any(BesuComponent.class)))
.thenReturn(mockControllerBuilder); .thenReturn(mockControllerBuilder);
@ -493,7 +493,7 @@ public abstract class CommandTestAbstract {
pkiBlockCreationConfigProvider, pkiBlockCreationConfigProvider,
rpcEndpointServiceImpl, rpcEndpointServiceImpl,
new TransactionSelectionServiceImpl(), new TransactionSelectionServiceImpl(),
new TransactionValidatorServiceImpl()); new PluginTransactionValidatorServiceImpl());
} }
@Override @Override

@ -69,7 +69,7 @@ Calculated : ${currentHash}
tasks.register('checkAPIChanges', FileStateChecker) { tasks.register('checkAPIChanges', FileStateChecker) {
description = "Checks that the API for the Plugin-API project does not change without deliberate thought" description = "Checks that the API for the Plugin-API project does not change without deliberate thought"
files = sourceSets.main.allJava.files files = sourceSets.main.allJava.files
knownHash = 'efyGMh6uDklK9YBP8cAbXujTu4adsr/hG5Y6RUkj3P8=' knownHash = 'Hk2/Iqa74WbVIJ/EWqb00iqxBN9lMi/A20eTIf1GoZE='
} }
check.dependsOn('checkAPIChanges') check.dependsOn('checkAPIChanges')

@ -20,7 +20,7 @@ import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionValidat
/** Transaction validator for addition of transactions to the transaction pool */ /** Transaction validator for addition of transactions to the transaction pool */
@Unstable @Unstable
public interface TransactionValidatorService extends BesuService { public interface PluginTransactionValidatorService extends BesuService {
/** /**
* Returns the transaction validator factory * Returns the transaction validator factory

@ -29,5 +29,4 @@ public interface PluginTransactionValidator {
* @return true if the transaction can be added, false otherwise * @return true if the transaction can be added, false otherwise
*/ */
boolean validateTransaction(final Transaction transaction); boolean validateTransaction(final Transaction transaction);
;
} }

Loading…
Cancel
Save