mirror of
https://github.com/vacp2p/status-linea-besu.git
synced 2026-01-09 13:58:02 -05:00
Merge branch 'main' into zkbesu
# Conflicts: # CHANGELOG.md # acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java # ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/execution/TracedJsonRpcProcessor.java # ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java # ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToAllowlist.java # ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromAllowlist.java # ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/response/RpcErrorType.java # ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToAllowlistTest.java # ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromAllowlistTest.java # ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AuthorityProcessor.java # ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java # ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java # ethereum/evmtool/src/test/resources/org/hyperledger/besu/evmtool/code-validate/initcode.json # evm/src/main/java/org/hyperledger/besu/evm/code/EOFLayout.java # plugin-api/build.gradle
This commit is contained in:
@@ -15,8 +15,14 @@
|
||||
### Additions and Improvements
|
||||
- Expose set finalized/safe block in plugin api BlockchainService. These method can be used by plugins to set finalized/safe block for a PoA network (such as QBFT, IBFT and Clique).[#7382](https://github.com/hyperledger/besu/pull/7382)
|
||||
- In process RPC service [#7395](https://github.com/hyperledger/besu/pull/7395)
|
||||
- Added support for tracing private transactions using `priv_traceTransaction` API. [#6161](https://github.com/hyperledger/besu/pull/6161)
|
||||
- Wrap WorldUpdater into EVMWorldupdater [#7434](https://github.com/hyperledger/besu/pull/7434)
|
||||
|
||||
|
||||
### Bug fixes
|
||||
- Correct entrypoint in Docker evmtool [#7430](https://github.com/hyperledger/besu/pull/7430)
|
||||
- Fix protocol schedule check for devnets [#7429](https://github.com/hyperledger/besu/pull/7429)
|
||||
- Fix behaviour when starting in a pre-merge network [#7431](https://github.com/hyperledger/besu/pull/7431)
|
||||
|
||||
## 24.7.1
|
||||
|
||||
|
||||
@@ -24,11 +24,16 @@ import org.hyperledger.besu.tests.acceptance.dsl.node.Node;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class AllowListContainsKeyAndValue implements Condition {
|
||||
private final ALLOWLIST_TYPE allowlistType;
|
||||
private final Collection<String> allowlistValues;
|
||||
private final Path configFilePath;
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AllowListContainsKeyAndValue.class);
|
||||
|
||||
public AllowListContainsKeyAndValue(
|
||||
final ALLOWLIST_TYPE allowlistType,
|
||||
final Collection<String> allowlistValues,
|
||||
@@ -47,6 +52,7 @@ public class AllowListContainsKeyAndValue implements Condition {
|
||||
allowlistType, allowlistValues, configFilePath);
|
||||
} catch (final Exception e) {
|
||||
result = false;
|
||||
LOG.error("Error verifying allowlist contains key and value", e);
|
||||
}
|
||||
assertThat(result).isTrue();
|
||||
}
|
||||
|
||||
@@ -18,8 +18,13 @@ import static org.hyperledger.besu.controller.BesuController.DATABASE_PATH;
|
||||
|
||||
import org.hyperledger.besu.Runner;
|
||||
import org.hyperledger.besu.RunnerBuilder;
|
||||
import org.hyperledger.besu.chainexport.RlpBlockExporter;
|
||||
import org.hyperledger.besu.chainimport.JsonBlockImporter;
|
||||
import org.hyperledger.besu.chainimport.RlpBlockImporter;
|
||||
import org.hyperledger.besu.cli.BesuCommand;
|
||||
import org.hyperledger.besu.cli.config.EthNetworkConfig;
|
||||
import org.hyperledger.besu.cli.config.NetworkName;
|
||||
import org.hyperledger.besu.components.BesuComponent;
|
||||
import org.hyperledger.besu.config.GenesisConfigFile;
|
||||
import org.hyperledger.besu.controller.BesuController;
|
||||
import org.hyperledger.besu.controller.BesuControllerBuilder;
|
||||
@@ -31,23 +36,28 @@ import org.hyperledger.besu.ethereum.api.ApiConfiguration;
|
||||
import org.hyperledger.besu.ethereum.api.graphql.GraphQLConfiguration;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.InProcessRpcConfiguration;
|
||||
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.eth.EthProtocolConfiguration;
|
||||
import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration;
|
||||
import org.hyperledger.besu.ethereum.eth.transactions.BlobCacheModule;
|
||||
import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration;
|
||||
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration;
|
||||
import org.hyperledger.besu.ethereum.p2p.peers.EnodeURLImpl;
|
||||
import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProvider;
|
||||
import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProviderBuilder;
|
||||
import org.hyperledger.besu.ethereum.transaction.TransactionSimulator;
|
||||
import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.cache.BonsaiCachedMerkleTrieLoaderModule;
|
||||
import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration;
|
||||
import org.hyperledger.besu.evm.internal.EvmConfiguration;
|
||||
import org.hyperledger.besu.metrics.MetricsSystemFactory;
|
||||
import org.hyperledger.besu.metrics.MetricsSystemModule;
|
||||
import org.hyperledger.besu.metrics.ObservableMetricsSystem;
|
||||
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
|
||||
import org.hyperledger.besu.plugin.data.EnodeURL;
|
||||
import org.hyperledger.besu.plugin.services.BesuConfiguration;
|
||||
import org.hyperledger.besu.plugin.services.BesuEvents;
|
||||
import org.hyperledger.besu.plugin.services.BlockchainService;
|
||||
import org.hyperledger.besu.plugin.services.MetricsSystem;
|
||||
import org.hyperledger.besu.plugin.services.PermissioningService;
|
||||
import org.hyperledger.besu.plugin.services.PicoCLIOptions;
|
||||
import org.hyperledger.besu.plugin.services.PrivacyPluginService;
|
||||
@@ -71,17 +81,27 @@ import org.hyperledger.besu.services.StorageServiceImpl;
|
||||
import org.hyperledger.besu.services.TransactionPoolValidatorServiceImpl;
|
||||
import org.hyperledger.besu.services.TransactionSelectionServiceImpl;
|
||||
import org.hyperledger.besu.services.TransactionSimulationServiceImpl;
|
||||
import org.hyperledger.besu.services.kvstore.InMemoryStoragePlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Clock;
|
||||
import java.util.HashMap;
|
||||
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;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Component;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import io.opentelemetry.api.GlobalOpenTelemetry;
|
||||
import io.vertx.core.Vertx;
|
||||
import org.slf4j.Logger;
|
||||
@@ -97,59 +117,6 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner {
|
||||
|
||||
private final Map<Node, BesuPluginContextImpl> besuPluginContextMap = new ConcurrentHashMap<>();
|
||||
|
||||
private BesuPluginContextImpl buildPluginContext(
|
||||
final BesuNode node,
|
||||
final StorageServiceImpl storageService,
|
||||
final SecurityModuleServiceImpl securityModuleService,
|
||||
final TransactionSimulationServiceImpl transactionSimulationServiceImpl,
|
||||
final TransactionSelectionServiceImpl transactionSelectionServiceImpl,
|
||||
final TransactionPoolValidatorServiceImpl transactionPoolValidatorServiceImpl,
|
||||
final BlockchainServiceImpl blockchainServiceImpl,
|
||||
final RpcEndpointServiceImpl rpcEndpointServiceImpl,
|
||||
final BesuConfiguration commonPluginConfiguration,
|
||||
final PermissioningServiceImpl permissioningService) {
|
||||
final CommandLine commandLine = new CommandLine(CommandSpec.create());
|
||||
final BesuPluginContextImpl besuPluginContext = new BesuPluginContextImpl();
|
||||
besuPluginContext.addService(StorageService.class, storageService);
|
||||
besuPluginContext.addService(SecurityModuleService.class, securityModuleService);
|
||||
besuPluginContext.addService(PicoCLIOptions.class, new PicoCLIOptionsImpl(commandLine));
|
||||
besuPluginContext.addService(RpcEndpointService.class, rpcEndpointServiceImpl);
|
||||
besuPluginContext.addService(
|
||||
TransactionSelectionService.class, transactionSelectionServiceImpl);
|
||||
besuPluginContext.addService(
|
||||
TransactionPoolValidatorService.class, transactionPoolValidatorServiceImpl);
|
||||
besuPluginContext.addService(
|
||||
TransactionSimulationService.class, transactionSimulationServiceImpl);
|
||||
besuPluginContext.addService(BlockchainService.class, blockchainServiceImpl);
|
||||
besuPluginContext.addService(BesuConfiguration.class, commonPluginConfiguration);
|
||||
|
||||
final Path pluginsPath;
|
||||
final String pluginDir = System.getProperty("besu.plugins.dir");
|
||||
if (pluginDir == null || pluginDir.isEmpty()) {
|
||||
pluginsPath = node.homeDirectory().resolve("plugins");
|
||||
final File pluginsDirFile = pluginsPath.toFile();
|
||||
if (!pluginsDirFile.isDirectory()) {
|
||||
pluginsDirFile.mkdirs();
|
||||
pluginsDirFile.deleteOnExit();
|
||||
}
|
||||
System.setProperty("besu.plugins.dir", pluginsPath.toString());
|
||||
} else {
|
||||
pluginsPath = Path.of(pluginDir);
|
||||
}
|
||||
|
||||
besuPluginContext.addService(BesuConfiguration.class, commonPluginConfiguration);
|
||||
besuPluginContext.addService(PermissioningService.class, permissioningService);
|
||||
besuPluginContext.addService(PrivacyPluginService.class, new PrivacyPluginServiceImpl());
|
||||
|
||||
besuPluginContext.registerPlugins(new PluginConfiguration(pluginsPath));
|
||||
|
||||
commandLine.parseArgs(node.getConfiguration().getExtraCLIOptions().toArray(new String[0]));
|
||||
|
||||
// register built-in plugins
|
||||
new RocksDBPlugin().register(besuPluginContext);
|
||||
return besuPluginContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startNode(final BesuNode node) {
|
||||
|
||||
@@ -162,8 +129,9 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner {
|
||||
throw new UnsupportedOperationException("commands are not supported with thread runner");
|
||||
}
|
||||
|
||||
final StorageServiceImpl storageService = new StorageServiceImpl();
|
||||
final SecurityModuleServiceImpl securityModuleService = new SecurityModuleServiceImpl();
|
||||
AcceptanceTestBesuComponent component =
|
||||
DaggerThreadBesuNodeRunner_AcceptanceTestBesuComponent.create();
|
||||
|
||||
final TransactionSimulationServiceImpl transactionSimulationServiceImpl =
|
||||
new TransactionSimulationServiceImpl();
|
||||
final TransactionSelectionServiceImpl transactionSelectionServiceImpl =
|
||||
@@ -186,49 +154,22 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner {
|
||||
.withMiningParameters(miningParameters);
|
||||
|
||||
final BesuPluginContextImpl besuPluginContext =
|
||||
besuPluginContextMap.computeIfAbsent(
|
||||
node,
|
||||
n ->
|
||||
buildPluginContext(
|
||||
node,
|
||||
storageService,
|
||||
securityModuleService,
|
||||
transactionSimulationServiceImpl,
|
||||
transactionSelectionServiceImpl,
|
||||
transactionPoolValidatorServiceImpl,
|
||||
blockchainServiceImpl,
|
||||
rpcEndpointServiceImpl,
|
||||
commonPluginConfiguration,
|
||||
permissioningService));
|
||||
besuPluginContextMap.computeIfAbsent(node, n -> component.getBesuPluginContext());
|
||||
|
||||
GlobalOpenTelemetry.resetForTest();
|
||||
final ObservableMetricsSystem metricsSystem =
|
||||
MetricsSystemFactory.create(node.getMetricsConfiguration());
|
||||
final ObservableMetricsSystem metricsSystem = component.getObservableMetricsSystem();
|
||||
final List<EnodeURL> bootnodes =
|
||||
node.getConfiguration().getBootnodes().stream()
|
||||
.map(EnodeURLImpl::fromURI)
|
||||
.collect(Collectors.toList());
|
||||
final NetworkName network = node.getNetwork() == null ? NetworkName.DEV : node.getNetwork();
|
||||
final EthNetworkConfig.Builder networkConfigBuilder =
|
||||
new EthNetworkConfig.Builder(EthNetworkConfig.getNetworkConfig(network))
|
||||
.setBootNodes(bootnodes);
|
||||
|
||||
final EthNetworkConfig.Builder networkConfigBuilder = component.ethNetworkConfigBuilder();
|
||||
networkConfigBuilder.setBootNodes(bootnodes);
|
||||
node.getConfiguration()
|
||||
.getGenesisConfig()
|
||||
.map(GenesisConfigFile::fromConfig)
|
||||
.ifPresent(networkConfigBuilder::setGenesisConfigFile);
|
||||
final EthNetworkConfig ethNetworkConfig = networkConfigBuilder.build();
|
||||
final SynchronizerConfiguration synchronizerConfiguration =
|
||||
new SynchronizerConfiguration.Builder().build();
|
||||
final BesuControllerBuilder builder =
|
||||
new BesuController.Builder()
|
||||
.fromEthNetworkConfig(ethNetworkConfig, synchronizerConfiguration.getSyncMode());
|
||||
|
||||
final KeyValueStorageProvider storageProvider =
|
||||
new KeyValueStorageProviderBuilder()
|
||||
.withStorageFactory(storageService.getByName("rocksdb").get())
|
||||
.withCommonConfiguration(commonPluginConfiguration)
|
||||
.withMetricsSystem(metricsSystem)
|
||||
.build();
|
||||
|
||||
final TransactionPoolConfiguration txPoolConfig =
|
||||
ImmutableTransactionPoolConfiguration.builder()
|
||||
@@ -237,35 +178,20 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner {
|
||||
.transactionPoolValidatorService(transactionPoolValidatorServiceImpl)
|
||||
.build();
|
||||
|
||||
final BesuControllerBuilder builder = component.besuControllerBuilder();
|
||||
builder.isRevertReasonEnabled(node.isRevertReasonEnabled());
|
||||
builder.networkConfiguration(node.getNetworkingConfiguration());
|
||||
builder.transactionPoolConfiguration(txPoolConfig);
|
||||
builder.dataDirectory(dataDir);
|
||||
builder.nodeKey(new NodeKey(new KeyPairSecurityModule(KeyPairUtil.loadKeyPair(dataDir))));
|
||||
builder.privacyParameters(node.getPrivacyParameters());
|
||||
final InProcessRpcConfiguration inProcessRpcConfiguration = node.inProcessRpcConfiguration();
|
||||
|
||||
final int maxPeers = 25;
|
||||
|
||||
builder
|
||||
.synchronizerConfiguration(new SynchronizerConfiguration.Builder().build())
|
||||
.dataDirectory(node.homeDirectory())
|
||||
.miningParameters(miningParameters)
|
||||
.privacyParameters(node.getPrivacyParameters())
|
||||
.nodeKey(new NodeKey(new KeyPairSecurityModule(KeyPairUtil.loadKeyPair(dataDir))))
|
||||
.metricsSystem(metricsSystem)
|
||||
.transactionPoolConfiguration(txPoolConfig)
|
||||
.dataStorageConfiguration(DataStorageConfiguration.DEFAULT_FOREST_CONFIG)
|
||||
.ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
|
||||
.clock(Clock.systemUTC())
|
||||
.isRevertReasonEnabled(node.isRevertReasonEnabled())
|
||||
.storageProvider(storageProvider)
|
||||
.gasLimitCalculator(GasLimitCalculator.constant())
|
||||
.evmConfiguration(EvmConfiguration.DEFAULT)
|
||||
.maxPeers(maxPeers)
|
||||
.maxRemotelyInitiatedPeers(15)
|
||||
.networkConfiguration(node.getNetworkingConfiguration())
|
||||
.randomPeerPriority(false);
|
||||
|
||||
node.getGenesisConfig()
|
||||
.map(GenesisConfigFile::fromConfig)
|
||||
.ifPresent(builder::genesisConfigFile);
|
||||
|
||||
final BesuController besuController = builder.build();
|
||||
final BesuController besuController = component.besuController();
|
||||
|
||||
initTransactionSimulationService(
|
||||
transactionSimulationServiceImpl, besuController, node.getApiConfiguration());
|
||||
@@ -299,11 +225,10 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner {
|
||||
.collect(Collectors.toList()))
|
||||
.besuPluginContext(besuPluginContext)
|
||||
.autoLogBloomCaching(false)
|
||||
.storageProvider(storageProvider)
|
||||
.storageProvider(besuController.getStorageProvider())
|
||||
.rpcEndpointService(rpcEndpointServiceImpl)
|
||||
.inProcessRpcConfiguration(inProcessRpcConfiguration);
|
||||
node.engineRpcConfiguration().ifPresent(runnerBuilder::engineJsonRpcConfiguration);
|
||||
|
||||
besuPluginContext.beforeExternalServices();
|
||||
final Runner runner = runnerBuilder.build();
|
||||
|
||||
@@ -396,4 +321,229 @@ public class ThreadBesuNodeRunner implements BesuNodeRunner {
|
||||
public String getConsoleContents() {
|
||||
throw new RuntimeException("Console contents can only be captured in process execution");
|
||||
}
|
||||
|
||||
@Module
|
||||
@SuppressWarnings("CloseableProvides")
|
||||
static class BesuControllerModule {
|
||||
@Provides
|
||||
@Singleton
|
||||
public SynchronizerConfiguration provideSynchronizationConfiguration() {
|
||||
final SynchronizerConfiguration synchronizerConfiguration =
|
||||
SynchronizerConfiguration.builder().build();
|
||||
return synchronizerConfiguration;
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
public BesuControllerBuilder provideBesuControllerBuilder(
|
||||
final EthNetworkConfig ethNetworkConfig,
|
||||
final SynchronizerConfiguration synchronizerConfiguration) {
|
||||
|
||||
final BesuControllerBuilder builder =
|
||||
new BesuController.Builder()
|
||||
.fromEthNetworkConfig(ethNetworkConfig, synchronizerConfiguration.getSyncMode());
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Provides
|
||||
public BesuController provideBesuController(
|
||||
final SynchronizerConfiguration synchronizerConfiguration,
|
||||
final BesuControllerBuilder builder,
|
||||
final ObservableMetricsSystem metricsSystem,
|
||||
final KeyValueStorageProvider storageProvider,
|
||||
final MiningParameters miningParameters) {
|
||||
|
||||
builder
|
||||
.synchronizerConfiguration(synchronizerConfiguration)
|
||||
.metricsSystem(metricsSystem)
|
||||
.dataStorageConfiguration(DataStorageConfiguration.DEFAULT_FOREST_CONFIG)
|
||||
.ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
|
||||
.clock(Clock.systemUTC())
|
||||
.storageProvider(storageProvider)
|
||||
.gasLimitCalculator(GasLimitCalculator.constant())
|
||||
.evmConfiguration(EvmConfiguration.DEFAULT)
|
||||
.maxPeers(25)
|
||||
.maxRemotelyInitiatedPeers(15)
|
||||
.miningParameters(miningParameters)
|
||||
.randomPeerPriority(false)
|
||||
.besuComponent(null);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public EthNetworkConfig.Builder provideEthNetworkConfigBuilder() {
|
||||
final EthNetworkConfig.Builder networkConfigBuilder =
|
||||
new EthNetworkConfig.Builder(EthNetworkConfig.getNetworkConfig(NetworkName.DEV));
|
||||
return networkConfigBuilder;
|
||||
}
|
||||
|
||||
@Provides
|
||||
public EthNetworkConfig provideEthNetworkConfig(
|
||||
final EthNetworkConfig.Builder networkConfigBuilder) {
|
||||
|
||||
final EthNetworkConfig ethNetworkConfig = networkConfigBuilder.build();
|
||||
return ethNetworkConfig;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("besuPluginContext")
|
||||
public BesuPluginContextImpl providePluginContext(
|
||||
final StorageServiceImpl storageService,
|
||||
final SecurityModuleServiceImpl securityModuleService,
|
||||
final TransactionSimulationServiceImpl transactionSimulationServiceImpl,
|
||||
final TransactionSelectionServiceImpl transactionSelectionServiceImpl,
|
||||
final TransactionPoolValidatorServiceImpl transactionPoolValidatorServiceImpl,
|
||||
final BlockchainServiceImpl blockchainServiceImpl,
|
||||
final RpcEndpointServiceImpl rpcEndpointServiceImpl,
|
||||
final BesuConfiguration commonPluginConfiguration,
|
||||
final PermissioningServiceImpl permissioningService) {
|
||||
final CommandLine commandLine = new CommandLine(CommandSpec.create());
|
||||
final BesuPluginContextImpl besuPluginContext = new BesuPluginContextImpl();
|
||||
besuPluginContext.addService(StorageService.class, storageService);
|
||||
besuPluginContext.addService(SecurityModuleService.class, securityModuleService);
|
||||
besuPluginContext.addService(PicoCLIOptions.class, new PicoCLIOptionsImpl(commandLine));
|
||||
besuPluginContext.addService(RpcEndpointService.class, rpcEndpointServiceImpl);
|
||||
besuPluginContext.addService(
|
||||
TransactionSelectionService.class, transactionSelectionServiceImpl);
|
||||
besuPluginContext.addService(
|
||||
TransactionPoolValidatorService.class, transactionPoolValidatorServiceImpl);
|
||||
besuPluginContext.addService(
|
||||
TransactionSimulationService.class, transactionSimulationServiceImpl);
|
||||
besuPluginContext.addService(BlockchainService.class, blockchainServiceImpl);
|
||||
besuPluginContext.addService(BesuConfiguration.class, commonPluginConfiguration);
|
||||
|
||||
final Path pluginsPath;
|
||||
final String pluginDir = System.getProperty("besu.plugins.dir");
|
||||
if (pluginDir == null || pluginDir.isEmpty()) {
|
||||
// pluginsPath = node.homeDirectory().resolve("plugins");
|
||||
pluginsPath = commonPluginConfiguration.getDataPath().resolve("plugins");
|
||||
final File pluginsDirFile = pluginsPath.toFile();
|
||||
if (!pluginsDirFile.isDirectory()) {
|
||||
pluginsDirFile.mkdirs();
|
||||
pluginsDirFile.deleteOnExit();
|
||||
}
|
||||
System.setProperty("besu.plugins.dir", pluginsPath.toString());
|
||||
} else {
|
||||
pluginsPath = Path.of(pluginDir);
|
||||
}
|
||||
|
||||
besuPluginContext.addService(BesuConfiguration.class, commonPluginConfiguration);
|
||||
besuPluginContext.addService(PermissioningService.class, permissioningService);
|
||||
besuPluginContext.addService(PrivacyPluginService.class, new PrivacyPluginServiceImpl());
|
||||
|
||||
besuPluginContext.registerPlugins(new PluginConfiguration(pluginsPath));
|
||||
|
||||
// register built-in plugins
|
||||
new RocksDBPlugin().register(besuPluginContext);
|
||||
return besuPluginContext;
|
||||
}
|
||||
|
||||
@Provides
|
||||
public KeyValueStorageProvider provideKeyValueStorageProvider(
|
||||
final BesuConfiguration commonPluginConfiguration, final MetricsSystem metricsSystem) {
|
||||
|
||||
final StorageServiceImpl storageService = new StorageServiceImpl();
|
||||
storageService.registerKeyValueStorage(
|
||||
new InMemoryStoragePlugin.InMemoryKeyValueStorageFactory("memory"));
|
||||
final KeyValueStorageProvider storageProvider =
|
||||
new KeyValueStorageProviderBuilder()
|
||||
.withStorageFactory(storageService.getByName("memory").get())
|
||||
.withCommonConfiguration(commonPluginConfiguration)
|
||||
.withMetricsSystem(metricsSystem)
|
||||
.build();
|
||||
|
||||
return storageProvider;
|
||||
}
|
||||
|
||||
@Provides
|
||||
public MiningParameters provideMiningParameters(
|
||||
final TransactionSelectionServiceImpl transactionSelectionServiceImpl) {
|
||||
final var miningParameters =
|
||||
ImmutableMiningParameters.builder()
|
||||
.transactionSelectionService(transactionSelectionServiceImpl)
|
||||
.build();
|
||||
|
||||
return miningParameters;
|
||||
}
|
||||
|
||||
@Provides
|
||||
Path provideDataDir() {
|
||||
try {
|
||||
return Files.createTempDirectory("acctest");
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException("Unable to create temporary data directory", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Inject
|
||||
BesuConfiguration provideBesuConfiguration(final Path dataDir) {
|
||||
final BesuConfigurationImpl commonPluginConfiguration = new BesuConfigurationImpl();
|
||||
commonPluginConfiguration.init(
|
||||
dataDir, dataDir.resolve(DATABASE_PATH), DataStorageConfiguration.DEFAULT_FOREST_CONFIG);
|
||||
return commonPluginConfiguration;
|
||||
}
|
||||
|
||||
@Provides
|
||||
TransactionPoolConfiguration provideTransactionPoolConfiguration(
|
||||
final BesuNode node,
|
||||
final TransactionPoolValidatorServiceImpl transactionPoolValidatorServiceImpl) {
|
||||
return ImmutableTransactionPoolConfiguration.builder()
|
||||
.from(node.getTransactionPoolConfiguration())
|
||||
.strictTransactionReplayProtectionEnabled(node.isStrictTxReplayProtectionEnabled())
|
||||
.transactionPoolValidatorService(transactionPoolValidatorServiceImpl)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@Module
|
||||
static class MockBesuCommandModule {
|
||||
|
||||
@Provides
|
||||
BesuCommand provideBesuCommand(final AcceptanceTestBesuComponent component) {
|
||||
final BesuCommand besuCommand =
|
||||
new BesuCommand(
|
||||
component,
|
||||
RlpBlockImporter::new,
|
||||
JsonBlockImporter::new,
|
||||
RlpBlockExporter::new,
|
||||
new RunnerBuilder(),
|
||||
new BesuController.Builder(),
|
||||
Optional.ofNullable(component.getBesuPluginContext()).orElse(null),
|
||||
System.getenv());
|
||||
besuCommand.toCommandLine();
|
||||
return besuCommand;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
MetricsConfiguration provideMetricsConfiguration() {
|
||||
return MetricsConfiguration.builder().build();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("besuCommandLogger")
|
||||
@Singleton
|
||||
Logger provideBesuCommandLogger() {
|
||||
return LoggerFactory.getLogger(MockBesuCommandModule.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Component(
|
||||
modules = {
|
||||
ThreadBesuNodeRunner.BesuControllerModule.class,
|
||||
ThreadBesuNodeRunner.MockBesuCommandModule.class,
|
||||
BonsaiCachedMerkleTrieLoaderModule.class,
|
||||
MetricsSystemModule.class,
|
||||
BlobCacheModule.class
|
||||
})
|
||||
public interface AcceptanceTestBesuComponent extends BesuComponent {
|
||||
BesuController besuController();
|
||||
|
||||
BesuControllerBuilder besuControllerBuilder(); // TODO: needing this sucks
|
||||
|
||||
EthNetworkConfig.Builder ethNetworkConfigBuilder();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,7 +276,7 @@ public class PrivacyNode implements AutoCloseable {
|
||||
final Path dataLocation, final Path dbLocation) {
|
||||
final var besuConfiguration = new BesuConfigurationImpl();
|
||||
besuConfiguration
|
||||
.init(dataLocation, dbLocation, null)
|
||||
.init(dataLocation, dbLocation, besuConfig.getDataStorageConfiguration())
|
||||
.withMiningParameters(besuConfig.getMiningParameters());
|
||||
return new PrivacyKeyValueStorageProviderBuilder()
|
||||
.withStorageFactory(
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package org.hyperledger.besu.tests.acceptance.dsl.privacy.transaction;
|
||||
|
||||
import org.hyperledger.besu.datatypes.Address;
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.ethereum.privacy.PrivacyGroupUtil;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.privacy.PrivacyNode;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.privacy.condition.PrivGetTransactionReceiptTransaction;
|
||||
@@ -25,6 +26,7 @@ import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivDebugGe
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivGetCodeTransaction;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivGetLogsTransaction;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivGetTransaction;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivTraceTransaction;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.filter.PrivGetFilterChangesTransaction;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.filter.PrivGetFilterLogsTransaction;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.filter.PrivNewFilterTransaction;
|
||||
@@ -115,6 +117,11 @@ public class PrivacyTransactions {
|
||||
return new PrivGetLogsTransaction(privacyGroupId, filterParameter);
|
||||
}
|
||||
|
||||
public PrivTraceTransaction privTraceTransaction(
|
||||
final String privacyGroupId, final Hash transactionHash) {
|
||||
return new PrivTraceTransaction(privacyGroupId, transactionHash);
|
||||
}
|
||||
|
||||
public RemoveFromFlexiblePrivacyGroupTransaction removeFromPrivacyGroup(
|
||||
final String privacyGroupId,
|
||||
final String remover,
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright contributors to Hyperledger Besu.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
package org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class PrivTraceTransaction implements Transaction<String> {
|
||||
|
||||
private final String privacyGroupId;
|
||||
private final Hash transactionHash;
|
||||
|
||||
public PrivTraceTransaction(final String privacyGroupId, final Hash transactionHash) {
|
||||
this.privacyGroupId = privacyGroupId;
|
||||
this.transactionHash = transactionHash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute(final NodeRequests node) {
|
||||
try {
|
||||
final PrivacyRequestFactory.PrivTraceTransaction response =
|
||||
node.privacy().privTraceTransaction(privacyGroupId, transactionHash).send();
|
||||
|
||||
assertThat(response).as("check response is not null").isNotNull();
|
||||
assertThat(response.getResult()).as("check result in response is not null").isNotNull();
|
||||
|
||||
return response.getResult();
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,6 +109,8 @@ public class PrivacyRequestFactory {
|
||||
public static class GetPrivateTransactionResponse
|
||||
extends Response<PrivateTransactionGroupResponse> {}
|
||||
|
||||
public static class PrivTraceTransaction extends Response<String> {}
|
||||
|
||||
public static class CreatePrivacyGroupResponse extends Response<String> {}
|
||||
|
||||
public static class DeletePrivacyGroupResponse extends Response<String> {}
|
||||
@@ -455,6 +457,16 @@ public class PrivacyRequestFactory {
|
||||
"priv_getLogs", Arrays.asList(privacyGroupId, filterParameter), web3jService, EthLog.class);
|
||||
}
|
||||
|
||||
public Request<?, PrivTraceTransaction> privTraceTransaction(
|
||||
final String privacyGroupId, final Hash transactionHash) {
|
||||
|
||||
return new Request<>(
|
||||
"priv_traceTransaction",
|
||||
Arrays.asList(privacyGroupId, transactionHash),
|
||||
web3jService,
|
||||
PrivTraceTransaction.class);
|
||||
}
|
||||
|
||||
public Request<?, EthFilter> privNewFilter(
|
||||
final String privacyGroupId, final LogFilterJsonParameter filterParameter) {
|
||||
return new Request<>(
|
||||
|
||||
@@ -18,7 +18,7 @@ cd acceptance-tests/simple-permissioning-smart-contract
|
||||
* Also this truffle.js uses address and private key generated by Ganache with default mnemonic "candy maple cake sugar pudding cream honey rich smooth crumble sweet treat"
|
||||
|
||||
* To run the Truffle example with Besu, you need Besu running
|
||||
* [check out and build Besu](../../README.md)
|
||||
* [check out and build Besu](../../../README.md)
|
||||
* run Besu (either in IDE or via command line), with mining and RPC enabled.
|
||||
|
||||
* Run Truffle migrate against Ganache
|
||||
|
||||
@@ -38,7 +38,7 @@ public class ClusterThreadNodeRunnerAcceptanceTest extends AcceptanceTestBase {
|
||||
final BesuNodeRunner besuNodeRunner = new ThreadBesuNodeRunner();
|
||||
noDiscoveryCluster = new Cluster(clusterConfiguration, net, besuNodeRunner);
|
||||
final BesuNode noDiscoveryNode = besu.createNodeWithNoDiscovery("noDiscovery");
|
||||
fullNode = besu.createArchiveNode("node2");
|
||||
fullNode = besu.createArchiveNode("archive");
|
||||
noDiscoveryCluster.start(noDiscoveryNode, fullNode);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* Copyright contributors to Hyperledger Besu.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
package org.hyperledger.besu.tests.acceptance.privacy;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.web3j.utils.Restriction.UNRESTRICTED;
|
||||
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.privacy.ParameterizedEnclaveTestBase;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.privacy.PrivacyNode;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.privacy.account.PrivacyAccountResolver;
|
||||
import org.hyperledger.besu.tests.web3j.generated.SimpleStorage;
|
||||
import org.hyperledger.enclave.testutil.EnclaveEncryptorType;
|
||||
import org.hyperledger.enclave.testutil.EnclaveType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Test;
|
||||
import org.web3j.utils.Restriction;
|
||||
|
||||
public class PrivTraceTransactionAcceptanceTest extends ParameterizedEnclaveTestBase {
|
||||
|
||||
private final PrivacyNode node;
|
||||
|
||||
private final PrivacyNode wrongNode;
|
||||
|
||||
public PrivTraceTransactionAcceptanceTest(
|
||||
final Restriction restriction,
|
||||
final EnclaveType enclaveType,
|
||||
final EnclaveEncryptorType enclaveEncryptorType)
|
||||
throws IOException {
|
||||
|
||||
super(restriction, enclaveType, enclaveEncryptorType);
|
||||
|
||||
node =
|
||||
privacyBesu.createPrivateTransactionEnabledMinerNode(
|
||||
restriction + "-node",
|
||||
PrivacyAccountResolver.ALICE.resolve(enclaveEncryptorType),
|
||||
enclaveType,
|
||||
Optional.empty(),
|
||||
false,
|
||||
false,
|
||||
restriction == UNRESTRICTED);
|
||||
|
||||
wrongNode =
|
||||
privacyBesu.createPrivateTransactionEnabledMinerNode(
|
||||
restriction + "-node",
|
||||
PrivacyAccountResolver.BOB.resolve(enclaveEncryptorType),
|
||||
enclaveType,
|
||||
Optional.empty(),
|
||||
false,
|
||||
false,
|
||||
restriction == UNRESTRICTED);
|
||||
|
||||
privacyCluster.start(node);
|
||||
privacyCluster.start(wrongNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTransactionTrace() throws JsonProcessingException {
|
||||
final String privacyGroupId = createPrivacyGroup();
|
||||
final SimpleStorage simpleStorageContract = deploySimpleStorageContract(privacyGroupId);
|
||||
|
||||
Hash transactionHash =
|
||||
Hash.fromHexString(doTransaction(privacyGroupId, simpleStorageContract, 0));
|
||||
|
||||
final String result =
|
||||
node.execute(privacyTransactions.privTraceTransaction(privacyGroupId, transactionHash));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
JsonNode rootNode = mapper.readTree(result);
|
||||
JsonNode resultNode = rootNode.get("result");
|
||||
|
||||
assertThat(resultNode).isNotNull();
|
||||
assertThat(resultNode.isArray()).isTrue();
|
||||
assertThat(resultNode.size()).isGreaterThan(0);
|
||||
|
||||
JsonNode trace = resultNode.get(0);
|
||||
assertThat(trace.get("action").get("callType").asText()).isEqualTo("call");
|
||||
assertThat(trace.get("action").get("from").asText()).isEqualTo(node.getAddress().toString());
|
||||
assertThat(trace.get("action").get("input").asText()).startsWith("0x60fe47b1");
|
||||
assertThat(trace.get("action").get("to").asText())
|
||||
.isEqualTo(simpleStorageContract.getContractAddress());
|
||||
assertThat(trace.get("action").get("value").asText()).isEqualTo("0x0");
|
||||
assertThat(trace.get("blockHash").asText()).isNotEmpty();
|
||||
assertThat(trace.get("blockNumber").asInt()).isGreaterThan(0);
|
||||
assertThat(trace.get("transactionHash").asText()).isEqualTo(transactionHash.toString());
|
||||
assertThat(trace.get("type").asText()).isEqualTo("call");
|
||||
|
||||
final String wrongPrivacyGroupId = createWrongPrivacyGroup();
|
||||
|
||||
final String resultEmpty =
|
||||
wrongNode.execute(
|
||||
privacyTransactions.privTraceTransaction(wrongPrivacyGroupId, transactionHash));
|
||||
|
||||
ObjectMapper mapperEmpty = new ObjectMapper();
|
||||
|
||||
JsonNode rootNodeEmpty = mapperEmpty.readTree(resultEmpty);
|
||||
JsonNode resultNodeEmpty = rootNodeEmpty.get("result");
|
||||
|
||||
assertThat(resultNodeEmpty).isNotNull();
|
||||
assertThat(resultNodeEmpty.isArray()).isTrue();
|
||||
assertThat(resultNodeEmpty.isEmpty()).isTrue();
|
||||
|
||||
final String resultWrongHash =
|
||||
wrongNode.execute(privacyTransactions.privTraceTransaction(privacyGroupId, Hash.EMPTY));
|
||||
|
||||
ObjectMapper mapperWrongHash = new ObjectMapper();
|
||||
|
||||
JsonNode rootNodeWrongHash = mapperWrongHash.readTree(resultWrongHash);
|
||||
JsonNode resultNodeWrongHash = rootNodeWrongHash.get("result");
|
||||
|
||||
assertThat(resultNodeWrongHash).isNotNull();
|
||||
assertThat(resultNodeWrongHash.isArray()).isTrue();
|
||||
assertThat(resultNodeWrongHash.isEmpty()).isTrue();
|
||||
}
|
||||
|
||||
private String createPrivacyGroup() {
|
||||
return node.execute(createPrivacyGroup("myGroupName", "my group description", node));
|
||||
}
|
||||
|
||||
private String createWrongPrivacyGroup() {
|
||||
return wrongNode.execute(createPrivacyGroup("myGroupName", "my group description", wrongNode));
|
||||
}
|
||||
|
||||
private SimpleStorage deploySimpleStorageContract(final String privacyGroupId) {
|
||||
final SimpleStorage simpleStorage =
|
||||
node.execute(
|
||||
privateContractTransactions.createSmartContractWithPrivacyGroupId(
|
||||
SimpleStorage.class,
|
||||
node.getTransactionSigningKey(),
|
||||
restriction,
|
||||
node.getEnclaveKey(),
|
||||
privacyGroupId));
|
||||
|
||||
privateContractVerifier
|
||||
.validPrivateContractDeployed(
|
||||
simpleStorage.getContractAddress(), node.getAddress().toString())
|
||||
.verify(simpleStorage);
|
||||
|
||||
return simpleStorage;
|
||||
}
|
||||
|
||||
private String doTransaction(
|
||||
final String privacyGroupId, final SimpleStorage simpleStorageContract, final int value) {
|
||||
return node.execute(
|
||||
privateContractTransactions.callSmartContractWithPrivacyGroupId(
|
||||
simpleStorageContract.getContractAddress(),
|
||||
simpleStorageContract.set(BigInteger.valueOf(value)).encodeFunctionCall(),
|
||||
node.getTransactionSigningKey(),
|
||||
restriction,
|
||||
node.getEnclaveKey(),
|
||||
privacyGroupId));
|
||||
}
|
||||
}
|
||||
@@ -104,6 +104,8 @@ dependencies {
|
||||
testImplementation 'org.mockito:mockito-core'
|
||||
testImplementation 'org.testcontainers:testcontainers'
|
||||
testImplementation 'tech.pegasys.discovery:discovery'
|
||||
testImplementation 'com.google.dagger:dagger'
|
||||
|
||||
annotationProcessor 'com.google.dagger:dagger-compiler'
|
||||
testAnnotationProcessor 'com.google.dagger:dagger-compiler'
|
||||
}
|
||||
|
||||
@@ -69,20 +69,26 @@ public class DataStorageOptions implements CLIOptions<DataStorageConfiguration>
|
||||
public static final String BONSAI_TRIE_LOG_PRUNING_WINDOW_SIZE =
|
||||
"--bonsai-trie-logs-pruning-window-size";
|
||||
|
||||
// TODO --Xbonsai-limit-trie-logs-enabled and --Xbonsai-trie-log-pruning-enabled are deprecated,
|
||||
// remove in a future release
|
||||
@SuppressWarnings("ExperimentalCliOptionMustBeCorrectlyDisplayed")
|
||||
@CommandLine.Option(
|
||||
names = {
|
||||
BONSAI_LIMIT_TRIE_LOGS_ENABLED,
|
||||
"--Xbonsai-limit-trie-logs-enabled",
|
||||
"--Xbonsai-trie-log-pruning-enabled"
|
||||
"--Xbonsai-limit-trie-logs-enabled", // deprecated
|
||||
"--Xbonsai-trie-log-pruning-enabled" // deprecated
|
||||
},
|
||||
fallbackValue = "true",
|
||||
description = "Limit the number of trie logs that are retained. (default: ${DEFAULT-VALUE})")
|
||||
private Boolean bonsaiLimitTrieLogsEnabled = DEFAULT_BONSAI_LIMIT_TRIE_LOGS_ENABLED;
|
||||
|
||||
// TODO --Xbonsai-trie-logs-pruning-window-size is deprecated, remove in a future release
|
||||
@SuppressWarnings("ExperimentalCliOptionMustBeCorrectlyDisplayed")
|
||||
@CommandLine.Option(
|
||||
names = {BONSAI_TRIE_LOG_PRUNING_WINDOW_SIZE, "--Xbonsai-trie-logs-pruning-window-size"},
|
||||
names = {
|
||||
BONSAI_TRIE_LOG_PRUNING_WINDOW_SIZE,
|
||||
"--Xbonsai-trie-logs-pruning-window-size" // deprecated
|
||||
},
|
||||
description =
|
||||
"The max number of blocks to load and prune trie logs for at startup. (default: ${DEFAULT-VALUE})")
|
||||
private Integer bonsaiTrieLogPruningWindowSize = DEFAULT_BONSAI_TRIE_LOG_PRUNING_WINDOW_SIZE;
|
||||
|
||||
@@ -552,6 +552,7 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides
|
||||
checkNotNull(evmConfiguration, "Missing evm config");
|
||||
checkNotNull(networkingConfiguration, "Missing network configuration");
|
||||
checkNotNull(dataStorageConfiguration, "Missing data storage configuration");
|
||||
|
||||
prepForBuild();
|
||||
|
||||
final ProtocolSchedule protocolSchedule = createProtocolSchedule();
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext;
|
||||
import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator;
|
||||
import org.hyperledger.besu.ethereum.chain.Blockchain;
|
||||
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
|
||||
import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters;
|
||||
import org.hyperledger.besu.ethereum.core.MiningParameters;
|
||||
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
|
||||
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration;
|
||||
@@ -129,7 +130,13 @@ public class TransitionBesuControllerBuilder extends BesuControllerBuilder {
|
||||
transitionProtocolSchedule.getPreMergeSchedule(),
|
||||
protocolContext,
|
||||
transactionPool,
|
||||
MiningParameters.MINING_DISABLED,
|
||||
ImmutableMiningParameters.builder()
|
||||
.from(miningParameters)
|
||||
.mutableInitValues(
|
||||
ImmutableMiningParameters.MutableInitValues.builder()
|
||||
.isMiningEnabled(false)
|
||||
.build())
|
||||
.build(),
|
||||
syncState,
|
||||
ethProtocolManager),
|
||||
mergeBesuControllerBuilder.createTransitionMiningCoordinator(
|
||||
@@ -406,9 +413,9 @@ public class TransitionBesuControllerBuilder extends BesuControllerBuilder {
|
||||
return propagateConfig(z -> z.dataStorageConfiguration(dataStorageConfiguration));
|
||||
}
|
||||
|
||||
private BesuControllerBuilder propagateConfig(final Consumer<BesuControllerBuilder> toPropogate) {
|
||||
toPropogate.accept(preMergeBesuControllerBuilder);
|
||||
toPropogate.accept(mergeBesuControllerBuilder);
|
||||
private BesuControllerBuilder propagateConfig(final Consumer<BesuControllerBuilder> toPropagate) {
|
||||
toPropagate.accept(preMergeBesuControllerBuilder);
|
||||
toPropagate.accept(mergeBesuControllerBuilder);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/** The Blockchain service implementation. */
|
||||
@Unstable
|
||||
@@ -44,6 +45,7 @@ public class BlockchainServiceImpl implements BlockchainService {
|
||||
private MutableBlockchain blockchain;
|
||||
|
||||
/** Instantiates a new Blockchain service implementation. */
|
||||
@Inject
|
||||
public BlockchainServiceImpl() {}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.hyperledger.besu.plugin.services.permissioning.NodeConnectionPermissi
|
||||
import org.hyperledger.besu.plugin.services.permissioning.NodeMessagePermissioningProvider;
|
||||
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@@ -29,6 +30,7 @@ public class PermissioningServiceImpl implements PermissioningService {
|
||||
Lists.newArrayList();
|
||||
|
||||
/** Default Constructor. */
|
||||
@Inject
|
||||
public PermissioningServiceImpl() {}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.hyperledger.besu.plugin.services.rlp.RlpConverterService;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
/** RLP Serialiaztion/Deserialization service. */
|
||||
/** RLP Serialization/Deserialization service. */
|
||||
public class RlpConverterServiceImpl implements RlpConverterService {
|
||||
|
||||
private final BlockHeaderFunctions blockHeaderFunctions;
|
||||
|
||||
@@ -36,6 +36,7 @@ import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -48,6 +49,7 @@ public class RpcEndpointServiceImpl implements RpcEndpointService {
|
||||
private Map<String, JsonRpcMethod> inProcessRpcMethods;
|
||||
|
||||
/** Default Constructor. */
|
||||
@Inject
|
||||
public RpcEndpointServiceImpl() {}
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,15 +21,18 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Supplier;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/** The Security module service implementation. */
|
||||
public class SecurityModuleServiceImpl implements SecurityModuleService {
|
||||
private final Map<String, Supplier<SecurityModule>> securityModuleSuppliers =
|
||||
new ConcurrentHashMap<>();
|
||||
|
||||
/** Default Constructor. */
|
||||
@Inject
|
||||
public SecurityModuleServiceImpl() {}
|
||||
|
||||
private final Map<String, Supplier<SecurityModule>> securityModuleSuppliers =
|
||||
new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public void register(final String name, final Supplier<SecurityModule> securityModuleSupplier) {
|
||||
securityModuleSuppliers.put(name, securityModuleSupplier);
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/** The Storage service implementation. */
|
||||
public class StorageServiceImpl implements StorageService {
|
||||
@@ -31,6 +32,7 @@ public class StorageServiceImpl implements StorageService {
|
||||
private final Map<String, KeyValueStorageFactory> factories;
|
||||
|
||||
/** Instantiates a new Storage service. */
|
||||
@Inject
|
||||
public StorageServiceImpl() {
|
||||
this.segments = List.of(KeyValueSegmentIdentifier.values());
|
||||
this.factories = new ConcurrentHashMap<>();
|
||||
|
||||
@@ -19,15 +19,17 @@ import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionPoolVal
|
||||
import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionPoolValidatorFactory;
|
||||
|
||||
import java.util.Optional;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/** The Transaction pool validator service implementation. */
|
||||
public class TransactionPoolValidatorServiceImpl implements TransactionPoolValidatorService {
|
||||
|
||||
private Optional<PluginTransactionPoolValidatorFactory> factory = Optional.empty();
|
||||
|
||||
/** Default Constructor. */
|
||||
@Inject
|
||||
public TransactionPoolValidatorServiceImpl() {}
|
||||
|
||||
private Optional<PluginTransactionPoolValidatorFactory> factory = Optional.empty();
|
||||
|
||||
@Override
|
||||
public PluginTransactionPoolValidator createTransactionValidator() {
|
||||
return factory
|
||||
|
||||
@@ -19,15 +19,17 @@ import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelecto
|
||||
import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelectorFactory;
|
||||
|
||||
import java.util.Optional;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/** The Transaction Selection service implementation. */
|
||||
public class TransactionSelectionServiceImpl implements TransactionSelectionService {
|
||||
|
||||
private Optional<PluginTransactionSelectorFactory> factory = Optional.empty();
|
||||
|
||||
/** Default Constructor. */
|
||||
@Inject
|
||||
public TransactionSelectionServiceImpl() {}
|
||||
|
||||
private Optional<PluginTransactionSelectorFactory> factory = Optional.empty();
|
||||
|
||||
@Override
|
||||
public PluginTransactionSelector createPluginTransactionSelector() {
|
||||
return factory
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.hyperledger.besu.plugin.data.TransactionSimulationResult;
|
||||
import org.hyperledger.besu.plugin.services.TransactionSimulationService;
|
||||
|
||||
import java.util.Optional;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/** TransactionSimulationServiceImpl */
|
||||
@Unstable
|
||||
@@ -43,6 +44,7 @@ public class TransactionSimulationServiceImpl implements TransactionSimulationSe
|
||||
private TransactionSimulator transactionSimulator;
|
||||
|
||||
/** Create an instance to be configured */
|
||||
@Inject
|
||||
public TransactionSimulationServiceImpl() {}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Copyright contributors to Hyperledger Besu.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
package org.hyperledger.besu;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hyperledger.besu.ethereum.core.PrivacyParameters.FLEXIBLE_PRIVACY;
|
||||
|
||||
import org.hyperledger.besu.components.BesuComponent;
|
||||
import org.hyperledger.besu.components.BesuPluginContextModule;
|
||||
import org.hyperledger.besu.components.MockBesuCommandModule;
|
||||
import org.hyperledger.besu.components.NoOpMetricsSystemModule;
|
||||
import org.hyperledger.besu.components.PrivacyTestModule;
|
||||
import org.hyperledger.besu.config.GenesisConfigFile;
|
||||
import org.hyperledger.besu.controller.BesuController;
|
||||
import org.hyperledger.besu.cryptoservices.NodeKeyUtils;
|
||||
import org.hyperledger.besu.datatypes.Address;
|
||||
import org.hyperledger.besu.enclave.EnclaveFactory;
|
||||
import org.hyperledger.besu.ethereum.GasLimitCalculator;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
|
||||
import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider;
|
||||
import org.hyperledger.besu.ethereum.core.MiningParameters;
|
||||
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
|
||||
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration;
|
||||
import org.hyperledger.besu.ethereum.eth.sync.SyncMode;
|
||||
import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration;
|
||||
import org.hyperledger.besu.ethereum.eth.transactions.BlobCacheModule;
|
||||
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration;
|
||||
import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration;
|
||||
import org.hyperledger.besu.ethereum.privacy.storage.PrivacyStorageProvider;
|
||||
import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.cache.BonsaiCachedMerkleTrieLoaderModule;
|
||||
import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration;
|
||||
import org.hyperledger.besu.evm.internal.EvmConfiguration;
|
||||
import org.hyperledger.besu.evm.precompile.PrecompiledContract;
|
||||
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
|
||||
import org.hyperledger.besu.testutil.TestClock;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Path;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Component;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import io.vertx.core.Vertx;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class FlexGroupPrivacyTest {
|
||||
|
||||
private final Vertx vertx = Vertx.vertx();
|
||||
|
||||
@AfterEach
|
||||
public void cleanUp() {
|
||||
vertx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void flexibleEnabledPrivacy() {
|
||||
final BesuController besuController =
|
||||
DaggerFlexGroupPrivacyTest_FlexGroupPrivacyTestComponent.builder()
|
||||
.build()
|
||||
.getBesuController();
|
||||
|
||||
final PrecompiledContract flexiblePrecompiledContract =
|
||||
getPrecompile(besuController, FLEXIBLE_PRIVACY);
|
||||
|
||||
assertThat(flexiblePrecompiledContract.getName()).isEqualTo("FlexiblePrivacy");
|
||||
}
|
||||
|
||||
private PrecompiledContract getPrecompile(
|
||||
final BesuController besuController, final Address defaultPrivacy) {
|
||||
return besuController
|
||||
.getProtocolSchedule()
|
||||
.getByBlockHeader(blockHeader(0))
|
||||
.getPrecompileContractRegistry()
|
||||
.get(defaultPrivacy);
|
||||
}
|
||||
|
||||
private BlockHeader blockHeader(final long number) {
|
||||
return new BlockHeaderTestFixture().number(number).buildHeader();
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Component(
|
||||
modules = {
|
||||
FlexGroupPrivacyParametersModule.class,
|
||||
FlexGroupPrivacyTest.PrivacyTestBesuControllerModule.class,
|
||||
PrivacyTestModule.class,
|
||||
MockBesuCommandModule.class,
|
||||
BonsaiCachedMerkleTrieLoaderModule.class,
|
||||
NoOpMetricsSystemModule.class,
|
||||
BesuPluginContextModule.class,
|
||||
BlobCacheModule.class
|
||||
})
|
||||
interface FlexGroupPrivacyTestComponent extends BesuComponent {
|
||||
BesuController getBesuController();
|
||||
}
|
||||
|
||||
@Module
|
||||
static class FlexGroupPrivacyParametersModule {
|
||||
|
||||
@Provides
|
||||
PrivacyParameters providePrivacyParameters(
|
||||
final PrivacyStorageProvider storageProvider, final Vertx vertx) {
|
||||
try {
|
||||
return new PrivacyParameters.Builder()
|
||||
.setEnabled(true)
|
||||
.setEnclaveUrl(new URI("http://127.0.0.1:8000"))
|
||||
.setStorageProvider(storageProvider)
|
||||
.setEnclaveFactory(new EnclaveFactory(vertx))
|
||||
.setFlexiblePrivacyGroupsEnabled(true)
|
||||
.build();
|
||||
} catch (URISyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Module
|
||||
static class PrivacyTestBesuControllerModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@SuppressWarnings("CloseableProvides")
|
||||
BesuController provideBesuController(
|
||||
final PrivacyParameters privacyParameters,
|
||||
final DataStorageConfiguration dataStorageConfiguration,
|
||||
final FlexGroupPrivacyTestComponent context,
|
||||
@Named("dataDir") final Path dataDir) {
|
||||
|
||||
return new BesuController.Builder()
|
||||
.fromGenesisFile(GenesisConfigFile.mainnet(), SyncMode.FULL)
|
||||
.synchronizerConfiguration(SynchronizerConfiguration.builder().build())
|
||||
.ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
|
||||
.storageProvider(new InMemoryKeyValueStorageProvider())
|
||||
.networkId(BigInteger.ONE)
|
||||
.miningParameters(MiningParameters.newDefault())
|
||||
.dataStorageConfiguration(dataStorageConfiguration)
|
||||
.nodeKey(NodeKeyUtils.generate())
|
||||
.metricsSystem(new NoOpMetricsSystem())
|
||||
.dataDirectory(dataDir)
|
||||
.clock(TestClock.fixed())
|
||||
.privacyParameters(privacyParameters)
|
||||
.transactionPoolConfiguration(TransactionPoolConfiguration.DEFAULT)
|
||||
.gasLimitCalculator(GasLimitCalculator.constant())
|
||||
.evmConfiguration(EvmConfiguration.DEFAULT)
|
||||
.networkConfiguration(NetworkingConfiguration.create())
|
||||
.besuComponent(context)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,12 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.hyperledger.besu.components.BesuComponent;
|
||||
import org.hyperledger.besu.components.BesuPluginContextModule;
|
||||
import org.hyperledger.besu.components.EnclaveModule;
|
||||
import org.hyperledger.besu.components.MockBesuCommandModule;
|
||||
import org.hyperledger.besu.components.NoOpMetricsSystemModule;
|
||||
import org.hyperledger.besu.components.PrivacyTestModule;
|
||||
import org.hyperledger.besu.config.GenesisConfigFile;
|
||||
import org.hyperledger.besu.controller.BesuController;
|
||||
import org.hyperledger.besu.crypto.KeyPair;
|
||||
@@ -47,7 +53,9 @@ import org.hyperledger.besu.ethereum.core.Transaction;
|
||||
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration;
|
||||
import org.hyperledger.besu.ethereum.eth.sync.SyncMode;
|
||||
import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration;
|
||||
import org.hyperledger.besu.ethereum.eth.transactions.BlobCacheModule;
|
||||
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration;
|
||||
import org.hyperledger.besu.ethereum.mainnet.BlockImportResult;
|
||||
import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode;
|
||||
import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration;
|
||||
import org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver;
|
||||
@@ -56,6 +64,7 @@ import org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap;
|
||||
import org.hyperledger.besu.ethereum.privacy.storage.PrivacyStorageProvider;
|
||||
import org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage;
|
||||
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
|
||||
import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.cache.BonsaiCachedMerkleTrieLoaderModule;
|
||||
import org.hyperledger.besu.evm.internal.EvmConfiguration;
|
||||
import org.hyperledger.besu.evm.log.LogsBloomFilter;
|
||||
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
|
||||
@@ -70,19 +79,21 @@ import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
import dagger.Component;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.apache.tuweni.bytes.Bytes32;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class PrivacyReorgTest {
|
||||
|
||||
@TempDir private Path folder;
|
||||
|
||||
private static final Supplier<SignatureAlgorithm> SIGNATURE_ALGORITHM =
|
||||
Suppliers.memoize(SignatureAlgorithmFactory::getInstance);
|
||||
|
||||
@@ -130,11 +141,15 @@ public class PrivacyReorgTest {
|
||||
.signAndBuild(KEY_PAIR);
|
||||
|
||||
private final BlockDataGenerator gen = new BlockDataGenerator();
|
||||
private BesuController besuController;
|
||||
private PrivateStateRootResolver privateStateRootResolver;
|
||||
private PrivacyParameters privacyParameters;
|
||||
private Enclave mockEnclave;
|
||||
private Transaction privacyMarkerTransaction;
|
||||
private final PrivacyReorgTestComponent component =
|
||||
DaggerPrivacyReorgTest_PrivacyReorgTestComponent.create();
|
||||
|
||||
private final BesuController besuController = component.getBesuController();
|
||||
private final PrivateStateRootResolver privateStateRootResolver =
|
||||
component.getPrivacyParameters().getPrivateStateRootResolver();
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws IOException {
|
||||
@@ -174,29 +189,6 @@ public class PrivacyReorgTest {
|
||||
.build();
|
||||
|
||||
privacyParameters.setPrivacyUserId(ENCLAVE_PUBLIC_KEY.toBase64String());
|
||||
|
||||
privateStateRootResolver =
|
||||
new PrivateStateRootResolver(privacyParameters.getPrivateStateStorage());
|
||||
|
||||
besuController =
|
||||
new BesuController.Builder()
|
||||
.fromGenesisFile(
|
||||
GenesisConfigFile.fromResource("/privacy_reorg_genesis.json"), SyncMode.FULL)
|
||||
.synchronizerConfiguration(SynchronizerConfiguration.builder().build())
|
||||
.ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
|
||||
.storageProvider(new InMemoryKeyValueStorageProvider())
|
||||
.networkId(BigInteger.ONE)
|
||||
.miningParameters(MiningParameters.newDefault())
|
||||
.nodeKey(NodeKeyUtils.generate())
|
||||
.metricsSystem(new NoOpMetricsSystem())
|
||||
.dataDirectory(folder)
|
||||
.clock(TestClock.fixed())
|
||||
.privacyParameters(privacyParameters)
|
||||
.transactionPoolConfiguration(TransactionPoolConfiguration.DEFAULT)
|
||||
.gasLimitCalculator(GasLimitCalculator.constant())
|
||||
.evmConfiguration(EvmConfiguration.DEFAULT)
|
||||
.networkConfiguration(NetworkingConfiguration.create())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -204,7 +196,8 @@ public class PrivacyReorgTest {
|
||||
// Setup an initial blockchain with one private transaction
|
||||
final ProtocolContext protocolContext = besuController.getProtocolContext();
|
||||
final DefaultBlockchain blockchain = (DefaultBlockchain) protocolContext.getBlockchain();
|
||||
final PrivateStateStorage privateStateStorage = privacyParameters.getPrivateStateStorage();
|
||||
final PrivateStateStorage privateStateStorage =
|
||||
component.getPrivacyParameters().getPrivateStateStorage();
|
||||
|
||||
final Block firstBlock =
|
||||
gen.block(
|
||||
@@ -244,7 +237,7 @@ public class PrivacyReorgTest {
|
||||
// Setup an initial blockchain with one private transaction
|
||||
final ProtocolContext protocolContext = besuController.getProtocolContext();
|
||||
final DefaultBlockchain blockchain = (DefaultBlockchain) protocolContext.getBlockchain();
|
||||
|
||||
assertThat(blockchain.getChainHeadBlockNumber()).isEqualTo(0);
|
||||
final Block firstBlock =
|
||||
gen.block(
|
||||
getBlockOptionsWithTransaction(
|
||||
@@ -252,8 +245,9 @@ public class PrivacyReorgTest {
|
||||
privacyMarkerTransaction,
|
||||
FIRST_BLOCK_WITH_SINGLE_TRANSACTION_STATE_ROOT));
|
||||
|
||||
appendBlock(besuController, blockchain, protocolContext, firstBlock);
|
||||
|
||||
var importResult = appendBlock(besuController, blockchain, protocolContext, firstBlock);
|
||||
assertThat(importResult.isImported()).isTrue();
|
||||
assertThat(blockchain.getChainHeadBlockNumber()).isEqualTo(1);
|
||||
// Check that the private state root is not the empty state
|
||||
assertPrivateStateRoot(
|
||||
privateStateRootResolver, blockchain, STATE_ROOT_AFTER_TRANSACTION_APPENDED_TO_EMPTY_STATE);
|
||||
@@ -394,12 +388,12 @@ public class PrivacyReorgTest {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void appendBlock(
|
||||
private BlockImportResult appendBlock(
|
||||
final BesuController besuController,
|
||||
final DefaultBlockchain blockchain,
|
||||
final ProtocolContext protocolContext,
|
||||
final Block block) {
|
||||
besuController
|
||||
return besuController
|
||||
.getProtocolSchedule()
|
||||
.getByBlockHeader(blockchain.getChainHeadHeader())
|
||||
.getBlockImporter()
|
||||
@@ -487,4 +481,93 @@ public class PrivacyReorgTest {
|
||||
.hasOmmers(false)
|
||||
.setLogsBloom(LogsBloomFilter.empty());
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Component(
|
||||
modules = {
|
||||
PrivacyReorgTest.PrivacyReorgParametersModule.class,
|
||||
PrivacyReorgTest.PrivacyReorgTestBesuControllerModule.class,
|
||||
PrivacyReorgTest.PrivacyReorgTestGenesisConfigModule.class,
|
||||
EnclaveModule.class,
|
||||
PrivacyTestModule.class,
|
||||
MockBesuCommandModule.class,
|
||||
NoOpMetricsSystemModule.class,
|
||||
BonsaiCachedMerkleTrieLoaderModule.class,
|
||||
BlobCacheModule.class,
|
||||
BesuPluginContextModule.class
|
||||
})
|
||||
interface PrivacyReorgTestComponent extends BesuComponent {
|
||||
|
||||
BesuController getBesuController();
|
||||
|
||||
PrivacyParameters getPrivacyParameters();
|
||||
}
|
||||
|
||||
@Module
|
||||
static class PrivacyReorgParametersModule {
|
||||
|
||||
// TODO: copypasta, get this from the enclave factory
|
||||
private static final Bytes ENCLAVE_PUBLIC_KEY =
|
||||
Bytes.fromBase64String("A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=");
|
||||
|
||||
@Provides
|
||||
PrivacyParameters providePrivacyReorgParameters(
|
||||
final PrivacyStorageProvider storageProvider, final EnclaveFactory enclaveFactory) {
|
||||
|
||||
PrivacyParameters retval =
|
||||
new PrivacyParameters.Builder()
|
||||
.setEnabled(true)
|
||||
.setStorageProvider(storageProvider)
|
||||
.setEnclaveUrl(URI.create("http//1.1.1.1:1234"))
|
||||
.setEnclaveFactory(enclaveFactory)
|
||||
.build();
|
||||
retval.setPrivacyUserId(ENCLAVE_PUBLIC_KEY.toBase64String());
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
|
||||
@Module
|
||||
static class PrivacyReorgTestBesuControllerModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@SuppressWarnings("CloseableProvides")
|
||||
BesuController provideBesuController(
|
||||
final PrivacyParameters privacyParameters,
|
||||
final GenesisConfigFile genesisConfigFile,
|
||||
final PrivacyReorgTestComponent context,
|
||||
final @Named("dataDir") Path dataDir) {
|
||||
|
||||
// dataStorageConfiguration default
|
||||
// named privacyReorgParams
|
||||
BesuController retval =
|
||||
new BesuController.Builder()
|
||||
.fromGenesisFile(genesisConfigFile, SyncMode.FULL)
|
||||
.synchronizerConfiguration(SynchronizerConfiguration.builder().build())
|
||||
.ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
|
||||
.storageProvider(new InMemoryKeyValueStorageProvider())
|
||||
.networkId(BigInteger.ONE)
|
||||
.miningParameters(MiningParameters.newDefault())
|
||||
.nodeKey(NodeKeyUtils.generate())
|
||||
.metricsSystem(new NoOpMetricsSystem())
|
||||
.dataDirectory(dataDir)
|
||||
.clock(TestClock.fixed())
|
||||
.privacyParameters(privacyParameters)
|
||||
.transactionPoolConfiguration(TransactionPoolConfiguration.DEFAULT)
|
||||
.gasLimitCalculator(GasLimitCalculator.constant())
|
||||
.evmConfiguration(EvmConfiguration.DEFAULT)
|
||||
.networkConfiguration(NetworkingConfiguration.create())
|
||||
.besuComponent(context)
|
||||
.build();
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
|
||||
@Module
|
||||
static class PrivacyReorgTestGenesisConfigModule {
|
||||
@Provides
|
||||
GenesisConfigFile providePrivacyReorgGenesisConfigFile() {
|
||||
return GenesisConfigFile.fromResource("/privacy_reorg_genesis.json");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright ConsenSys AG.
|
||||
* Copyright contributors to Hyperledger Besu.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
@@ -16,18 +16,17 @@ package org.hyperledger.besu;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hyperledger.besu.ethereum.core.PrivacyParameters.DEFAULT_PRIVACY;
|
||||
import static org.hyperledger.besu.ethereum.core.PrivacyParameters.FLEXIBLE_PRIVACY;
|
||||
import static org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBCLIOptions.DEFAULT_BACKGROUND_THREAD_COUNT;
|
||||
import static org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBCLIOptions.DEFAULT_CACHE_CAPACITY;
|
||||
import static org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBCLIOptions.DEFAULT_IS_HIGH_SPEC;
|
||||
import static org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBCLIOptions.DEFAULT_MAX_OPEN_FILES;
|
||||
|
||||
import org.hyperledger.besu.cli.config.EthNetworkConfig;
|
||||
import org.hyperledger.besu.cli.config.NetworkName;
|
||||
import org.hyperledger.besu.components.BesuComponent;
|
||||
import org.hyperledger.besu.components.BesuPluginContextModule;
|
||||
import org.hyperledger.besu.components.MockBesuCommandModule;
|
||||
import org.hyperledger.besu.components.NoOpMetricsSystemModule;
|
||||
import org.hyperledger.besu.components.PrivacyParametersModule;
|
||||
import org.hyperledger.besu.components.PrivacyTestModule;
|
||||
import org.hyperledger.besu.config.GenesisConfigFile;
|
||||
import org.hyperledger.besu.controller.BesuController;
|
||||
import org.hyperledger.besu.cryptoservices.NodeKeyUtils;
|
||||
import org.hyperledger.besu.datatypes.Address;
|
||||
import org.hyperledger.besu.enclave.EnclaveFactory;
|
||||
import org.hyperledger.besu.ethereum.GasLimitCalculator;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
|
||||
@@ -37,126 +36,47 @@ import org.hyperledger.besu.ethereum.core.PrivacyParameters;
|
||||
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration;
|
||||
import org.hyperledger.besu.ethereum.eth.sync.SyncMode;
|
||||
import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration;
|
||||
import org.hyperledger.besu.ethereum.eth.transactions.BlobCacheModule;
|
||||
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration;
|
||||
import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration;
|
||||
import org.hyperledger.besu.ethereum.privacy.storage.PrivacyStorageProvider;
|
||||
import org.hyperledger.besu.ethereum.privacy.storage.keyvalue.PrivacyKeyValueStorageProviderBuilder;
|
||||
import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier;
|
||||
import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.cache.BonsaiCachedMerkleTrieLoaderModule;
|
||||
import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration;
|
||||
import org.hyperledger.besu.evm.internal.EvmConfiguration;
|
||||
import org.hyperledger.besu.evm.precompile.PrecompiledContract;
|
||||
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
|
||||
import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBKeyValuePrivacyStorageFactory;
|
||||
import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBKeyValueStorageFactory;
|
||||
import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBMetricsFactory;
|
||||
import org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBFactoryConfiguration;
|
||||
import org.hyperledger.besu.services.BesuConfigurationImpl;
|
||||
import org.hyperledger.besu.testutil.TestClock;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Component;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import io.vertx.core.Vertx;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
public class PrivacyTest {
|
||||
class PrivacyTest {
|
||||
|
||||
private final Vertx vertx = Vertx.vertx();
|
||||
|
||||
@TempDir private Path dataDir;
|
||||
|
||||
@AfterEach
|
||||
public void cleanUp() {
|
||||
vertx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultPrivacy() throws IOException, URISyntaxException {
|
||||
final BesuController besuController = setUpControllerWithPrivacyEnabled(false);
|
||||
void defaultPrivacy() {
|
||||
final BesuController besuController =
|
||||
DaggerPrivacyTest_PrivacyTestComponent.builder().build().getBesuController();
|
||||
|
||||
final PrecompiledContract precompiledContract = getPrecompile(besuController, DEFAULT_PRIVACY);
|
||||
|
||||
assertThat(precompiledContract.getName()).isEqualTo("Privacy");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void flexibleEnabledPrivacy() throws IOException, URISyntaxException {
|
||||
final BesuController besuController = setUpControllerWithPrivacyEnabled(true);
|
||||
|
||||
final PrecompiledContract flexiblePrecompiledContract =
|
||||
getPrecompile(besuController, FLEXIBLE_PRIVACY);
|
||||
|
||||
assertThat(flexiblePrecompiledContract.getName()).isEqualTo("FlexiblePrivacy");
|
||||
}
|
||||
|
||||
private BesuController setUpControllerWithPrivacyEnabled(final boolean flexibleEnabled)
|
||||
throws IOException, URISyntaxException {
|
||||
final Path dbDir = Files.createTempDirectory(dataDir, "database");
|
||||
final var miningParameters = MiningParameters.newDefault();
|
||||
final var dataStorageConfiguration = DataStorageConfiguration.DEFAULT_FOREST_CONFIG;
|
||||
final PrivacyParameters privacyParameters =
|
||||
new PrivacyParameters.Builder()
|
||||
.setEnabled(true)
|
||||
.setEnclaveUrl(new URI("http://127.0.0.1:8000"))
|
||||
.setStorageProvider(
|
||||
createKeyValueStorageProvider(
|
||||
dataDir, dbDir, dataStorageConfiguration, miningParameters))
|
||||
.setEnclaveFactory(new EnclaveFactory(vertx))
|
||||
.setFlexiblePrivacyGroupsEnabled(flexibleEnabled)
|
||||
.build();
|
||||
return new BesuController.Builder()
|
||||
.fromEthNetworkConfig(EthNetworkConfig.getNetworkConfig(NetworkName.MAINNET), SyncMode.FULL)
|
||||
.synchronizerConfiguration(SynchronizerConfiguration.builder().build())
|
||||
.ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
|
||||
.storageProvider(new InMemoryKeyValueStorageProvider())
|
||||
.networkId(BigInteger.ONE)
|
||||
.miningParameters(miningParameters)
|
||||
.dataStorageConfiguration(dataStorageConfiguration)
|
||||
.nodeKey(NodeKeyUtils.generate())
|
||||
.metricsSystem(new NoOpMetricsSystem())
|
||||
.dataDirectory(dataDir)
|
||||
.clock(TestClock.fixed())
|
||||
.privacyParameters(privacyParameters)
|
||||
.transactionPoolConfiguration(TransactionPoolConfiguration.DEFAULT)
|
||||
.gasLimitCalculator(GasLimitCalculator.constant())
|
||||
.evmConfiguration(EvmConfiguration.DEFAULT)
|
||||
.networkConfiguration(NetworkingConfiguration.create())
|
||||
.build();
|
||||
}
|
||||
|
||||
private PrivacyStorageProvider createKeyValueStorageProvider(
|
||||
final Path dataDir,
|
||||
final Path dbDir,
|
||||
final DataStorageConfiguration dataStorageConfiguration,
|
||||
final MiningParameters miningParameters) {
|
||||
final var besuConfiguration = new BesuConfigurationImpl();
|
||||
besuConfiguration
|
||||
.init(dataDir, dbDir, dataStorageConfiguration)
|
||||
.withMiningParameters(miningParameters);
|
||||
return new PrivacyKeyValueStorageProviderBuilder()
|
||||
.withStorageFactory(
|
||||
new RocksDBKeyValuePrivacyStorageFactory(
|
||||
new RocksDBKeyValueStorageFactory(
|
||||
() ->
|
||||
new RocksDBFactoryConfiguration(
|
||||
DEFAULT_MAX_OPEN_FILES,
|
||||
DEFAULT_BACKGROUND_THREAD_COUNT,
|
||||
DEFAULT_CACHE_CAPACITY,
|
||||
DEFAULT_IS_HIGH_SPEC),
|
||||
Arrays.asList(KeyValueSegmentIdentifier.values()),
|
||||
RocksDBMetricsFactory.PRIVATE_ROCKS_DB_METRICS)))
|
||||
.withCommonConfiguration(besuConfiguration)
|
||||
.withMetricsSystem(new NoOpMetricsSystem())
|
||||
.build();
|
||||
}
|
||||
|
||||
private PrecompiledContract getPrecompile(
|
||||
final BesuController besuController, final Address defaultPrivacy) {
|
||||
return besuController
|
||||
@@ -169,4 +89,55 @@ public class PrivacyTest {
|
||||
private BlockHeader blockHeader(final long number) {
|
||||
return new BlockHeaderTestFixture().number(number).buildHeader();
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Component(
|
||||
modules = {
|
||||
PrivacyParametersModule.class,
|
||||
PrivacyTest.PrivacyTestBesuControllerModule.class,
|
||||
PrivacyTestModule.class,
|
||||
MockBesuCommandModule.class,
|
||||
BonsaiCachedMerkleTrieLoaderModule.class,
|
||||
NoOpMetricsSystemModule.class,
|
||||
BesuPluginContextModule.class,
|
||||
BlobCacheModule.class
|
||||
})
|
||||
interface PrivacyTestComponent extends BesuComponent {
|
||||
|
||||
BesuController getBesuController();
|
||||
}
|
||||
|
||||
@Module
|
||||
static class PrivacyTestBesuControllerModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@SuppressWarnings("CloseableProvides")
|
||||
BesuController provideBesuController(
|
||||
final PrivacyParameters privacyParameters,
|
||||
final DataStorageConfiguration dataStorageConfiguration,
|
||||
final PrivacyTestComponent context,
|
||||
@Named("dataDir") final Path dataDir) {
|
||||
|
||||
return new BesuController.Builder()
|
||||
.fromGenesisFile(GenesisConfigFile.mainnet(), SyncMode.FULL)
|
||||
.synchronizerConfiguration(SynchronizerConfiguration.builder().build())
|
||||
.ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
|
||||
.storageProvider(new InMemoryKeyValueStorageProvider())
|
||||
.networkId(BigInteger.ONE)
|
||||
.miningParameters(MiningParameters.newDefault())
|
||||
.dataStorageConfiguration(dataStorageConfiguration)
|
||||
.nodeKey(NodeKeyUtils.generate())
|
||||
.metricsSystem(new NoOpMetricsSystem())
|
||||
.dataDirectory(dataDir)
|
||||
.clock(TestClock.fixed())
|
||||
.privacyParameters(privacyParameters)
|
||||
.transactionPoolConfiguration(TransactionPoolConfiguration.DEFAULT)
|
||||
.gasLimitCalculator(GasLimitCalculator.constant())
|
||||
.evmConfiguration(EvmConfiguration.DEFAULT)
|
||||
.networkConfiguration(NetworkingConfiguration.create())
|
||||
.besuComponent(context)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,10 @@ import static org.hyperledger.besu.plugin.services.storage.rocksdb.configuration
|
||||
import static org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBCLIOptions.DEFAULT_CACHE_CAPACITY;
|
||||
import static org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBCLIOptions.DEFAULT_IS_HIGH_SPEC;
|
||||
import static org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBCLIOptions.DEFAULT_MAX_OPEN_FILES;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.hyperledger.besu.cli.config.EthNetworkConfig;
|
||||
import org.hyperledger.besu.components.BesuComponent;
|
||||
import org.hyperledger.besu.config.GenesisConfigFile;
|
||||
import org.hyperledger.besu.config.JsonUtil;
|
||||
import org.hyperledger.besu.config.MergeConfigOptions;
|
||||
@@ -483,6 +485,7 @@ public final class RunnerTest {
|
||||
.evmConfiguration(EvmConfiguration.DEFAULT)
|
||||
.networkConfiguration(NetworkingConfiguration.create())
|
||||
.randomPeerPriority(Boolean.FALSE)
|
||||
.besuComponent(mock(BesuComponent.class))
|
||||
.maxPeers(25)
|
||||
.maxRemotelyInitiatedPeers(15)
|
||||
.build();
|
||||
|
||||
@@ -16,10 +16,12 @@ package org.hyperledger.besu.chainexport;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.hyperledger.besu.chainimport.RlpBlockImporter;
|
||||
import org.hyperledger.besu.cli.config.EthNetworkConfig;
|
||||
import org.hyperledger.besu.cli.config.NetworkName;
|
||||
import org.hyperledger.besu.components.BesuComponent;
|
||||
import org.hyperledger.besu.controller.BesuController;
|
||||
import org.hyperledger.besu.cryptoservices.NodeKeyUtils;
|
||||
import org.hyperledger.besu.ethereum.GasLimitCalculator;
|
||||
@@ -102,6 +104,7 @@ public final class RlpBlockExporterTest {
|
||||
.gasLimitCalculator(GasLimitCalculator.constant())
|
||||
.evmConfiguration(EvmConfiguration.DEFAULT)
|
||||
.networkConfiguration(NetworkingConfiguration.create())
|
||||
.besuComponent(mock(BesuComponent.class))
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,9 @@ package org.hyperledger.besu.chainimport;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.hyperledger.besu.components.BesuComponent;
|
||||
import org.hyperledger.besu.config.GenesisConfigFile;
|
||||
import org.hyperledger.besu.config.JsonUtil;
|
||||
import org.hyperledger.besu.controller.BesuController;
|
||||
@@ -463,6 +465,7 @@ public abstract class JsonBlockImporterTest {
|
||||
.gasLimitCalculator(GasLimitCalculator.constant())
|
||||
.evmConfiguration(EvmConfiguration.DEFAULT)
|
||||
.networkConfiguration(NetworkingConfiguration.create())
|
||||
.besuComponent(mock(BesuComponent.class))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,11 @@ package org.hyperledger.besu.chainimport;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.hyperledger.besu.cli.config.EthNetworkConfig;
|
||||
import org.hyperledger.besu.cli.config.NetworkName;
|
||||
import org.hyperledger.besu.components.BesuComponent;
|
||||
import org.hyperledger.besu.config.MergeConfigOptions;
|
||||
import org.hyperledger.besu.controller.BesuController;
|
||||
import org.hyperledger.besu.cryptoservices.NodeKeyUtils;
|
||||
@@ -77,6 +79,7 @@ public final class RlpBlockImporterTest {
|
||||
.gasLimitCalculator(GasLimitCalculator.constant())
|
||||
.evmConfiguration(EvmConfiguration.DEFAULT)
|
||||
.networkConfiguration(NetworkingConfiguration.create())
|
||||
.besuComponent(mock(BesuComponent.class))
|
||||
.build();
|
||||
final RlpBlockImporter.ImportResult result =
|
||||
rlpBlockImporter.importBlockchain(source, targetController, false);
|
||||
@@ -110,6 +113,7 @@ public final class RlpBlockImporterTest {
|
||||
.gasLimitCalculator(GasLimitCalculator.constant())
|
||||
.evmConfiguration(EvmConfiguration.DEFAULT)
|
||||
.networkConfiguration(NetworkingConfiguration.create())
|
||||
.besuComponent(mock(BesuComponent.class))
|
||||
.build();
|
||||
|
||||
assertThatThrownBy(
|
||||
@@ -140,6 +144,7 @@ public final class RlpBlockImporterTest {
|
||||
.gasLimitCalculator(GasLimitCalculator.constant())
|
||||
.evmConfiguration(EvmConfiguration.DEFAULT)
|
||||
.networkConfiguration(NetworkingConfiguration.create())
|
||||
.besuComponent(mock(BesuComponent.class))
|
||||
.build();
|
||||
|
||||
final RlpBlockImporter.ImportResult result =
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class TxPoolOptionsTest extends CommandTestAbstract {
|
||||
@@ -97,6 +98,7 @@ public class TxPoolOptionsTest extends CommandTestAbstract {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // Failing in CI, but not locally
|
||||
public void txpoolForcePriceBumpToZeroWhenZeroBaseFeeMarket() throws IOException {
|
||||
final Path genesisFile = createFakeGenesisFile(GENESIS_WITH_ZERO_BASE_FEE_MARKET);
|
||||
parseCommand("--genesis-file", genesisFile.toString());
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright contributors to Hyperledger Besu.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
package org.hyperledger.besu.components;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.hyperledger.besu.crypto.KeyPair;
|
||||
import org.hyperledger.besu.crypto.SignatureAlgorithm;
|
||||
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;
|
||||
import org.hyperledger.besu.datatypes.Wei;
|
||||
import org.hyperledger.besu.enclave.Enclave;
|
||||
import org.hyperledger.besu.enclave.EnclaveFactory;
|
||||
import org.hyperledger.besu.enclave.types.ReceiveResponse;
|
||||
import org.hyperledger.besu.ethereum.privacy.PrivateTransaction;
|
||||
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
|
||||
import org.hyperledger.besu.plugin.data.Restriction;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.apache.tuweni.bytes.Bytes32;
|
||||
|
||||
@Module
|
||||
public class EnclaveModule {
|
||||
|
||||
private static final Supplier<SignatureAlgorithm> SIGNATURE_ALGORITHM =
|
||||
Suppliers.memoize(SignatureAlgorithmFactory::getInstance);
|
||||
|
||||
private static final Bytes ENCLAVE_PUBLIC_KEY =
|
||||
Bytes.fromBase64String("A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=");
|
||||
|
||||
private static final Bytes32 PRIVACY_GROUP_BYTES32 =
|
||||
Bytes32.fromHexString("0xf250d523ae9164722b06ca25cfa2a7f3c45df96b09e215236f886c876f715bfa");
|
||||
|
||||
private static final Bytes MOCK_PAYLOAD =
|
||||
Bytes.fromHexString(
|
||||
"0x608060405234801561001057600080fd5b5060008054600160a060020a03191633179055610199806100326000396000f3fe6080604052600436106100565763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416633fa4f245811461005b5780636057361d1461008257806367e404ce146100ae575b600080fd5b34801561006757600080fd5b506100706100ec565b60408051918252519081900360200190f35b34801561008e57600080fd5b506100ac600480360360208110156100a557600080fd5b50356100f2565b005b3480156100ba57600080fd5b506100c3610151565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b60025490565b604080513381526020810183905281517fc9db20adedc6cf2b5d25252b101ab03e124902a73fcb12b753f3d1aaa2d8f9f5929181900390910190a16002556001805473ffffffffffffffffffffffffffffffffffffffff191633179055565b60015473ffffffffffffffffffffffffffffffffffffffff169056fea165627a7a72305820c7f729cb24e05c221f5aa913700793994656f233fe2ce3b9fd9a505ea17e8d8a0029");
|
||||
|
||||
private static final KeyPair KEY_PAIR =
|
||||
SIGNATURE_ALGORITHM
|
||||
.get()
|
||||
.createKeyPair(
|
||||
SIGNATURE_ALGORITHM
|
||||
.get()
|
||||
.createPrivateKey(
|
||||
new BigInteger(
|
||||
"8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63", 16)));
|
||||
|
||||
private static final PrivateTransaction PRIVATE_TRANSACTION =
|
||||
PrivateTransaction.builder()
|
||||
.chainId(BigInteger.valueOf(1337))
|
||||
.gasLimit(1000)
|
||||
.gasPrice(Wei.ZERO)
|
||||
.nonce(0)
|
||||
.payload(MOCK_PAYLOAD)
|
||||
.to(null)
|
||||
.privateFrom(ENCLAVE_PUBLIC_KEY)
|
||||
.privateFor(Collections.singletonList(ENCLAVE_PUBLIC_KEY))
|
||||
.restriction(Restriction.RESTRICTED)
|
||||
.value(Wei.ZERO)
|
||||
.signAndBuild(KEY_PAIR);
|
||||
|
||||
@Provides
|
||||
EnclaveFactory provideMockableEnclaveFactory() {
|
||||
Enclave mockEnclave = mock(Enclave.class);
|
||||
final BytesValueRLPOutput rlpOutput = new BytesValueRLPOutput();
|
||||
PRIVATE_TRANSACTION.writeTo(rlpOutput);
|
||||
when(mockEnclave.receive(any()))
|
||||
.thenReturn(
|
||||
new ReceiveResponse(
|
||||
rlpOutput.encoded().toBase64String().getBytes(StandardCharsets.UTF_8),
|
||||
PRIVACY_GROUP_BYTES32.toBase64String(),
|
||||
ENCLAVE_PUBLIC_KEY.toBase64String()));
|
||||
EnclaveFactory enclaveFactory = mock(EnclaveFactory.class);
|
||||
when(enclaveFactory.createVertxEnclave(any())).thenReturn(mockEnclave);
|
||||
return enclaveFactory;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright contributors to Hyperledger Besu.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
package org.hyperledger.besu.components;
|
||||
|
||||
import org.hyperledger.besu.config.GenesisConfigFile;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
@Module
|
||||
public class GenesisConfigModule {
|
||||
|
||||
@Named("default")
|
||||
@Provides
|
||||
GenesisConfigFile provideDefaultGenesisConfigFile() {
|
||||
return GenesisConfigFile.DEFAULT;
|
||||
}
|
||||
|
||||
@Named("mainnet")
|
||||
@Provides
|
||||
GenesisConfigFile provideMainnetGenesisConfigFile() {
|
||||
return GenesisConfigFile.mainnet();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright contributors to Hyperledger Besu.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
package org.hyperledger.besu.components;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.hyperledger.besu.cli.BesuCommand;
|
||||
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Module
|
||||
public class MockBesuCommandModule {
|
||||
|
||||
@Provides
|
||||
BesuCommand provideBesuCommand() {
|
||||
return mock(BesuCommand.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
MetricsConfiguration provideMetricsConfiguration() {
|
||||
return MetricsConfiguration.builder().build();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("besuCommandLogger")
|
||||
@Singleton
|
||||
Logger provideBesuCommandLogger() {
|
||||
return LoggerFactory.getLogger(MockBesuCommandModule.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright contributors to Hyperledger Besu.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
package org.hyperledger.besu.components;
|
||||
|
||||
import org.hyperledger.besu.metrics.ObservableMetricsSystem;
|
||||
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
|
||||
import org.hyperledger.besu.plugin.services.MetricsSystem;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
@Module
|
||||
public class NoOpMetricsSystemModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
MetricsSystem provideMetricsSystem() {
|
||||
return new NoOpMetricsSystem();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
ObservableMetricsSystem provideObservableMetricsSystem() {
|
||||
return new NoOpMetricsSystem();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright contributors to Hyperledger Besu.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
package org.hyperledger.besu.components;
|
||||
|
||||
import org.hyperledger.besu.enclave.EnclaveFactory;
|
||||
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
|
||||
import org.hyperledger.besu.ethereum.privacy.storage.PrivacyStorageProvider;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import io.vertx.core.Vertx;
|
||||
|
||||
/** Provides a general use PrivacyParameters instance for testing. */
|
||||
@Module
|
||||
public class PrivacyParametersModule {
|
||||
|
||||
@Provides
|
||||
PrivacyParameters providePrivacyParameters(
|
||||
final PrivacyStorageProvider storageProvider, final Vertx vertx) {
|
||||
try {
|
||||
return new PrivacyParameters.Builder()
|
||||
.setEnabled(true)
|
||||
.setEnclaveUrl(new URI("http://127.0.0.1:8000"))
|
||||
.setStorageProvider(storageProvider)
|
||||
.setEnclaveFactory(new EnclaveFactory(vertx))
|
||||
.setFlexiblePrivacyGroupsEnabled(false)
|
||||
.build();
|
||||
} catch (URISyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright contributors to Hyperledger Besu.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
package org.hyperledger.besu.components;
|
||||
|
||||
import static org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBCLIOptions.DEFAULT_BACKGROUND_THREAD_COUNT;
|
||||
import static org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBCLIOptions.DEFAULT_CACHE_CAPACITY;
|
||||
import static org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBCLIOptions.DEFAULT_IS_HIGH_SPEC;
|
||||
import static org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBCLIOptions.DEFAULT_MAX_OPEN_FILES;
|
||||
|
||||
import org.hyperledger.besu.ethereum.privacy.storage.PrivacyStorageProvider;
|
||||
import org.hyperledger.besu.ethereum.privacy.storage.keyvalue.PrivacyKeyValueStorageProviderBuilder;
|
||||
import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier;
|
||||
import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration;
|
||||
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
|
||||
import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBKeyValuePrivacyStorageFactory;
|
||||
import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBKeyValueStorageFactory;
|
||||
import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBMetricsFactory;
|
||||
import org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBFactoryConfiguration;
|
||||
import org.hyperledger.besu.services.BesuConfigurationImpl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import io.vertx.core.Vertx;
|
||||
|
||||
@Module
|
||||
public class PrivacyTestModule {
|
||||
|
||||
@Provides
|
||||
@Named("dataDir")
|
||||
Path provideDataDir() {
|
||||
try {
|
||||
return Files.createTempDirectory("PrivacyTestDatadir");
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Provides
|
||||
Vertx provideVertx() {
|
||||
return Vertx.vertx();
|
||||
}
|
||||
|
||||
@Provides
|
||||
DataStorageConfiguration provideDataStorageConfiguration() {
|
||||
return DataStorageConfiguration.DEFAULT_FOREST_CONFIG;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("dbDir")
|
||||
Path provideDbDir(@Named("dataDir") final Path dataDir) {
|
||||
try {
|
||||
final Path dbDir = Files.createTempDirectory(dataDir, "database");
|
||||
return dbDir;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("flexibleEnabled")
|
||||
Boolean provideFlexibleEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@SuppressWarnings("CloseableProvides")
|
||||
PrivacyStorageProvider provideKeyValueStorageProvider(
|
||||
@Named("dbDir") final Path dbDir,
|
||||
final DataStorageConfiguration dataStorageConfiguration,
|
||||
@Named("dataDir") final Path dataDir) {
|
||||
final var besuConfiguration = new BesuConfigurationImpl();
|
||||
besuConfiguration.init(dataDir, dbDir, dataStorageConfiguration);
|
||||
return new PrivacyKeyValueStorageProviderBuilder()
|
||||
.withStorageFactory(
|
||||
new RocksDBKeyValuePrivacyStorageFactory(
|
||||
new RocksDBKeyValueStorageFactory(
|
||||
() ->
|
||||
new RocksDBFactoryConfiguration(
|
||||
DEFAULT_MAX_OPEN_FILES,
|
||||
DEFAULT_BACKGROUND_THREAD_COUNT,
|
||||
DEFAULT_CACHE_CAPACITY,
|
||||
DEFAULT_IS_HIGH_SPEC),
|
||||
Arrays.asList(KeyValueSegmentIdentifier.values()),
|
||||
RocksDBMetricsFactory.PRIVATE_ROCKS_DB_METRICS)))
|
||||
.withCommonConfiguration(besuConfiguration)
|
||||
.withMetricsSystem(new NoOpMetricsSystem())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.hyperledger.besu.components.BesuComponent;
|
||||
import org.hyperledger.besu.config.CheckpointConfigOptions;
|
||||
import org.hyperledger.besu.config.GenesisConfigFile;
|
||||
import org.hyperledger.besu.config.GenesisConfigOptions;
|
||||
@@ -157,6 +158,7 @@ public abstract class AbstractBftBesuControllerBuilderTest {
|
||||
.storageProvider(storageProvider)
|
||||
.gasLimitCalculator(gasLimitCalculator)
|
||||
.evmConfiguration(EvmConfiguration.DEFAULT)
|
||||
.besuComponent(mock(BesuComponent.class))
|
||||
.networkConfiguration(NetworkingConfiguration.create());
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.hyperledger.besu.components.BesuComponent;
|
||||
import org.hyperledger.besu.config.CheckpointConfigOptions;
|
||||
import org.hyperledger.besu.config.GenesisConfigFile;
|
||||
import org.hyperledger.besu.config.GenesisConfigOptions;
|
||||
@@ -190,6 +191,7 @@ public class CliqueBesuControllerBuilderTest {
|
||||
.storageProvider(storageProvider)
|
||||
.gasLimitCalculator(gasLimitCalculator)
|
||||
.evmConfiguration(EvmConfiguration.DEFAULT)
|
||||
.besuComponent(mock(BesuComponent.class))
|
||||
.networkConfiguration(NetworkingConfiguration.create());
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.hyperledger.besu.components.BesuComponent;
|
||||
import org.hyperledger.besu.config.CheckpointConfigOptions;
|
||||
import org.hyperledger.besu.config.GenesisConfigFile;
|
||||
import org.hyperledger.besu.config.GenesisConfigOptions;
|
||||
@@ -190,6 +191,7 @@ public class MergeBesuControllerBuilderTest {
|
||||
.storageProvider(storageProvider)
|
||||
.evmConfiguration(EvmConfiguration.DEFAULT)
|
||||
.networkConfiguration(NetworkingConfiguration.create())
|
||||
.besuComponent(mock(BesuComponent.class))
|
||||
.networkId(networkId);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.hyperledger.besu.consensus.clique.jsonrpc.methods;
|
||||
import org.hyperledger.besu.consensus.common.validator.ValidatorProvider;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
|
||||
@@ -67,8 +68,13 @@ public class CliqueGetSigners implements JsonRpcMethod {
|
||||
}
|
||||
|
||||
private Optional<BlockHeader> determineBlockHeader(final JsonRpcRequestContext request) {
|
||||
final Optional<BlockParameter> blockParameter =
|
||||
request.getOptionalParameter(0, BlockParameter.class);
|
||||
final Optional<BlockParameter> blockParameter;
|
||||
try {
|
||||
blockParameter = request.getOptionalParameter(0, BlockParameter.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
|
||||
}
|
||||
final long latest = blockchainQueries.headBlockNumber();
|
||||
final long blockNumber = blockParameter.map(b -> b.getNumber().orElse(latest)).orElse(latest);
|
||||
return blockchainQueries.blockByNumber(blockNumber).map(BlockWithMetadata::getHeader);
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.hyperledger.besu.consensus.common.validator.ValidatorProvider;
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
|
||||
@@ -67,7 +68,13 @@ public class CliqueGetSignersAtHash implements JsonRpcMethod {
|
||||
}
|
||||
|
||||
private Optional<BlockHeader> determineBlockHeader(final JsonRpcRequestContext request) {
|
||||
final Hash hash = request.getRequiredParameter(0, Hash.class);
|
||||
final Hash hash;
|
||||
try {
|
||||
hash = request.getRequiredParameter(0, Hash.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e);
|
||||
}
|
||||
return blockchainQueries.blockByHash(hash).map(BlockWithMetadata::getHeader);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,11 @@ import org.hyperledger.besu.consensus.common.validator.ValidatorProvider;
|
||||
import org.hyperledger.besu.datatypes.Address;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
|
||||
/** The Discard Json RPC method. */
|
||||
public class Discard implements JsonRpcMethod {
|
||||
@@ -46,7 +48,13 @@ public class Discard implements JsonRpcMethod {
|
||||
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
|
||||
checkState(
|
||||
validatorProvider.getVoteProviderAtHead().isPresent(), "Clique requires a vote provider");
|
||||
final Address address = requestContext.getRequiredParameter(0, Address.class);
|
||||
final Address address;
|
||||
try {
|
||||
address = requestContext.getRequiredParameter(0, Address.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e);
|
||||
}
|
||||
validatorProvider.getVoteProviderAtHead().get().discardVote(address);
|
||||
return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), true);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.hyperledger.besu.consensus.common.validator.ValidatorProvider;
|
||||
import org.hyperledger.besu.datatypes.Address;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
|
||||
@@ -49,8 +50,20 @@ public class Propose implements JsonRpcMethod {
|
||||
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
|
||||
checkState(
|
||||
validatorProvider.getVoteProviderAtHead().isPresent(), "Clique requires a vote provider");
|
||||
final Address address = requestContext.getRequiredParameter(0, Address.class);
|
||||
final Boolean auth = requestContext.getRequiredParameter(1, Boolean.class);
|
||||
final Address address;
|
||||
try {
|
||||
address = requestContext.getRequiredParameter(0, Address.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e);
|
||||
}
|
||||
final Boolean auth;
|
||||
try {
|
||||
auth = requestContext.getRequiredParameter(1, Boolean.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid auth parameter (index 1)", RpcErrorType.INVALID_PROPOSAL_PARAMS, e);
|
||||
}
|
||||
if (address.equals(CliqueBlockInterface.NO_VOTE_SUBJECT)) {
|
||||
return new JsonRpcErrorResponse(
|
||||
requestContext.getRequest().getId(), RpcErrorType.INVALID_REQUEST);
|
||||
|
||||
@@ -75,14 +75,14 @@ public class CliqueGetSignerMetricsTest {
|
||||
public void exceptionWhenInvalidStartBlockSupplied() {
|
||||
assertThatThrownBy(() -> method.response(requestWithParams("INVALID")))
|
||||
.isInstanceOf(InvalidJsonRpcParameters.class)
|
||||
.hasMessageContaining("Invalid json rpc parameter at index 0");
|
||||
.hasMessageContaining("Invalid start block parameter (index 0)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exceptionWhenInvalidEndBlockSupplied() {
|
||||
assertThatThrownBy(() -> method.response(requestWithParams("1", "INVALID")))
|
||||
.isInstanceOf(InvalidJsonRpcParameters.class)
|
||||
.hasMessageContaining("Invalid json rpc parameter at index 1");
|
||||
.hasMessageContaining("Invalid end block parameter (index 1)");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -101,7 +101,7 @@ public class CliqueGetSignersAtHashTest {
|
||||
|
||||
assertThat(thrown)
|
||||
.isInstanceOf(InvalidJsonRpcParameters.class)
|
||||
.hasMessage("Missing required json rpc parameter at index 0");
|
||||
.hasMessage("Invalid block hash parameter (index 0)");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -121,7 +121,7 @@ public class DiscardTest {
|
||||
final Discard discard = new Discard(validatorProvider);
|
||||
|
||||
assertThatThrownBy(() -> discard.response(requestWithParams()))
|
||||
.hasMessage("Missing required json rpc parameter at index 0")
|
||||
.hasMessage("Invalid address parameter (index 0)")
|
||||
.isInstanceOf(InvalidJsonRpcParameters.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.hyperledger.besu.consensus.common.BlockInterface;
|
||||
import org.hyperledger.besu.consensus.common.validator.ValidatorProvider;
|
||||
import org.hyperledger.besu.datatypes.Address;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
|
||||
@@ -66,17 +67,27 @@ public abstract class AbstractGetSignerMetricsMethod {
|
||||
*/
|
||||
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
|
||||
|
||||
final Optional<BlockParameter> startBlockParameter =
|
||||
requestContext.getOptionalParameter(0, BlockParameter.class);
|
||||
final Optional<BlockParameter> endBlockParameter =
|
||||
requestContext.getOptionalParameter(1, BlockParameter.class);
|
||||
final Optional<BlockParameter> startBlockParameter;
|
||||
try {
|
||||
startBlockParameter = requestContext.getOptionalParameter(0, BlockParameter.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid start block parameter (index 0)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e);
|
||||
}
|
||||
final Optional<BlockParameter> endBlockParameter;
|
||||
try {
|
||||
endBlockParameter = requestContext.getOptionalParameter(1, BlockParameter.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid end block parameter (index 1)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e);
|
||||
}
|
||||
|
||||
final long fromBlockNumber = getFromBlockNumber(startBlockParameter);
|
||||
final long toBlockNumber = getEndBlockNumber(endBlockParameter);
|
||||
|
||||
if (!isValidParameters(fromBlockNumber, toBlockNumber)) {
|
||||
return new JsonRpcErrorResponse(
|
||||
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
|
||||
requestContext.getRequest().getId(), RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS);
|
||||
}
|
||||
|
||||
final Map<Address, SignerMetricResult> proposersMap = new HashMap<>();
|
||||
|
||||
@@ -20,9 +20,11 @@ import org.hyperledger.besu.consensus.common.validator.ValidatorProvider;
|
||||
import org.hyperledger.besu.datatypes.Address;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -50,7 +52,13 @@ public class IbftDiscardValidatorVote implements JsonRpcMethod {
|
||||
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
|
||||
checkState(
|
||||
validatorProvider.getVoteProviderAtHead().isPresent(), "Ibft requires a vote provider");
|
||||
final Address validatorAddress = requestContext.getRequiredParameter(0, Address.class);
|
||||
final Address validatorAddress;
|
||||
try {
|
||||
validatorAddress = requestContext.getRequiredParameter(0, Address.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid validator address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e);
|
||||
}
|
||||
LOG.trace("Received RPC rpcName={} address={}", getName(), validatorAddress);
|
||||
validatorProvider.getVoteProviderAtHead().get().discardVote(validatorAddress);
|
||||
|
||||
|
||||
@@ -18,9 +18,11 @@ import org.hyperledger.besu.consensus.common.BlockInterface;
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
import org.hyperledger.besu.ethereum.chain.Blockchain;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
|
||||
@@ -61,7 +63,13 @@ public class IbftGetValidatorsByBlockHash implements JsonRpcMethod {
|
||||
}
|
||||
|
||||
private Object blockResult(final JsonRpcRequestContext request) {
|
||||
final Hash hash = request.getRequiredParameter(0, Hash.class);
|
||||
final Hash hash;
|
||||
try {
|
||||
hash = request.getRequiredParameter(0, Hash.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e);
|
||||
}
|
||||
LOG.trace("Received RPC rpcName={} blockHash={}", getName(), hash);
|
||||
final Optional<BlockHeader> blockHeader = blockchain.getBlockHeader(hash);
|
||||
return blockHeader
|
||||
|
||||
@@ -17,9 +17,11 @@ package org.hyperledger.besu.consensus.ibft.jsonrpc.methods;
|
||||
import org.hyperledger.besu.consensus.common.BlockInterface;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AbstractBlockParameterMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
|
||||
@@ -50,7 +52,12 @@ public class IbftGetValidatorsByBlockNumber extends AbstractBlockParameterMethod
|
||||
|
||||
@Override
|
||||
protected BlockParameter blockParameter(final JsonRpcRequestContext request) {
|
||||
return request.getRequiredParameter(0, BlockParameter.class);
|
||||
try {
|
||||
return request.getRequiredParameter(0, BlockParameter.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,9 +21,11 @@ import org.hyperledger.besu.consensus.common.validator.VoteType;
|
||||
import org.hyperledger.besu.datatypes.Address;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -51,7 +53,13 @@ public class IbftProposeValidatorVote implements JsonRpcMethod {
|
||||
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
|
||||
checkState(
|
||||
validatorProvider.getVoteProviderAtHead().isPresent(), "Ibft requires a vote provider");
|
||||
final Address validatorAddress = requestContext.getRequiredParameter(0, Address.class);
|
||||
final Address validatorAddress;
|
||||
try {
|
||||
validatorAddress = requestContext.getRequiredParameter(0, Address.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e);
|
||||
}
|
||||
final Boolean add = requestContext.getRequiredParameter(1, Boolean.class);
|
||||
LOG.trace(
|
||||
"Received RPC rpcName={} voteType={} address={}",
|
||||
|
||||
@@ -56,14 +56,14 @@ public class IbftDiscardValidatorVoteTest {
|
||||
public void exceptionWhenNoParamsSupplied() {
|
||||
assertThatThrownBy(() -> method.response(requestWithParams()))
|
||||
.isInstanceOf(InvalidJsonRpcParameters.class)
|
||||
.hasMessage("Missing required json rpc parameter at index 0");
|
||||
.hasMessage("Invalid validator address parameter (index 0)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exceptionWhenInvalidAddressParameterSupplied() {
|
||||
assertThatThrownBy(() -> method.response(requestWithParams("InvalidAddress")))
|
||||
.isInstanceOf(InvalidJsonRpcParameters.class)
|
||||
.hasMessageContaining("Invalid json rpc parameter at index 0");
|
||||
.hasMessageContaining("Invalid validator address parameter (index 0)");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -75,14 +75,14 @@ public class IbftGetSignerMetricsTest {
|
||||
public void exceptionWhenInvalidStartBlockSupplied() {
|
||||
assertThatThrownBy(() -> method.response(requestWithParams("INVALID")))
|
||||
.isInstanceOf(InvalidJsonRpcParameters.class)
|
||||
.hasMessageContaining("Invalid json rpc parameter at index 0");
|
||||
.hasMessageContaining("Invalid start block parameter (index 0)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exceptionWhenInvalidEndBlockSupplied() {
|
||||
assertThatThrownBy(() -> method.response(requestWithParams("1", "INVALID")))
|
||||
.isInstanceOf(InvalidJsonRpcParameters.class)
|
||||
.hasMessageContaining("Invalid json rpc parameter at index 1");
|
||||
.hasMessageContaining("Invalid end block parameter (index 1)");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -56,7 +56,7 @@ public class IbftProposeValidatorVoteTest {
|
||||
public void exceptionWhenNoParamsSupplied() {
|
||||
assertThatThrownBy(() -> method.response(requestWithParams()))
|
||||
.isInstanceOf(InvalidJsonRpcParameters.class)
|
||||
.hasMessage("Missing required json rpc parameter at index 0");
|
||||
.hasMessage("Invalid address parameter (index 0)");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -70,7 +70,7 @@ public class IbftProposeValidatorVoteTest {
|
||||
public void exceptionWhenNoAddressSupplied() {
|
||||
assertThatThrownBy(() -> method.response(requestWithParams("true")))
|
||||
.isInstanceOf(InvalidJsonRpcParameters.class)
|
||||
.hasMessageContaining("Invalid json rpc parameter at index 0");
|
||||
.hasMessageContaining("Invalid address parameter (index 0)");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.hyperledger.besu.ethereum.core.Difficulty;
|
||||
import org.hyperledger.besu.ethereum.core.MiningParameters;
|
||||
import org.hyperledger.besu.ethereum.core.PermissionTransactionFilter;
|
||||
import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader;
|
||||
import org.hyperledger.besu.ethereum.mainnet.HardforkId;
|
||||
import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule;
|
||||
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
|
||||
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
|
||||
@@ -241,6 +242,13 @@ public class TransitionProtocolSchedule implements ProtocolSchedule {
|
||||
return transitionUtils.dispatchFunctionAccordingToMergeState(ProtocolSchedule::listMilestones);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Long> milestoneFor(final HardforkId hardforkId) {
|
||||
return mergeContext.isPostMerge()
|
||||
? transitionUtils.getPostMergeObject().milestoneFor(hardforkId)
|
||||
: transitionUtils.getPreMergeObject().milestoneFor(hardforkId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets transaction filter.
|
||||
*
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.hyperledger.besu.consensus.common.validator.ValidatorProvider;
|
||||
import org.hyperledger.besu.datatypes.Address;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
|
||||
@@ -49,7 +50,15 @@ public class QbftDiscardValidatorVote implements JsonRpcMethod {
|
||||
@Override
|
||||
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
|
||||
if (validatorProvider.getVoteProviderAtHead().isPresent()) {
|
||||
final Address validatorAddress = requestContext.getRequiredParameter(0, Address.class);
|
||||
final Address validatorAddress;
|
||||
try {
|
||||
validatorAddress = requestContext.getRequiredParameter(0, Address.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid validator address parameter (index 0)",
|
||||
RpcErrorType.INVALID_ADDRESS_PARAMS,
|
||||
e);
|
||||
}
|
||||
LOG.trace("Received RPC rpcName={} address={}", getName(), validatorAddress);
|
||||
validatorProvider.getVoteProviderAtHead().get().discardVote(validatorAddress);
|
||||
|
||||
|
||||
@@ -19,9 +19,11 @@ import org.hyperledger.besu.datatypes.Address;
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
import org.hyperledger.besu.ethereum.chain.Blockchain;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
|
||||
@@ -62,7 +64,13 @@ public class QbftGetValidatorsByBlockHash implements JsonRpcMethod {
|
||||
}
|
||||
|
||||
private Object blockResult(final JsonRpcRequestContext request) {
|
||||
final Hash hash = request.getRequiredParameter(0, Hash.class);
|
||||
final Hash hash;
|
||||
try {
|
||||
hash = request.getRequiredParameter(0, Hash.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e);
|
||||
}
|
||||
LOG.trace("Received RPC rpcName={} blockHash={}", getName(), hash);
|
||||
final Optional<BlockHeader> blockHeader = blockchain.getBlockHeader(hash);
|
||||
return blockHeader
|
||||
|
||||
@@ -18,9 +18,11 @@ import org.hyperledger.besu.consensus.common.validator.ValidatorProvider;
|
||||
import org.hyperledger.besu.datatypes.Address;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AbstractBlockParameterMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
|
||||
@@ -50,7 +52,12 @@ public class QbftGetValidatorsByBlockNumber extends AbstractBlockParameterMethod
|
||||
|
||||
@Override
|
||||
protected BlockParameter blockParameter(final JsonRpcRequestContext request) {
|
||||
return request.getRequiredParameter(0, BlockParameter.class);
|
||||
try {
|
||||
return request.getRequiredParameter(0, BlockParameter.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.hyperledger.besu.consensus.common.validator.VoteType;
|
||||
import org.hyperledger.besu.datatypes.Address;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
|
||||
@@ -50,7 +51,15 @@ public class QbftProposeValidatorVote implements JsonRpcMethod {
|
||||
@Override
|
||||
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
|
||||
if (validatorProvider.getVoteProviderAtHead().isPresent()) {
|
||||
final Address validatorAddress = requestContext.getRequiredParameter(0, Address.class);
|
||||
final Address validatorAddress;
|
||||
try {
|
||||
validatorAddress = requestContext.getRequiredParameter(0, Address.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid validator address parameter (index 0)",
|
||||
RpcErrorType.INVALID_ADDRESS_PARAMS,
|
||||
e);
|
||||
}
|
||||
final Boolean add = requestContext.getRequiredParameter(1, Boolean.class);
|
||||
LOG.trace(
|
||||
"Received RPC rpcName={} voteType={} address={}",
|
||||
|
||||
@@ -58,14 +58,14 @@ public class QbftDiscardValidatorVoteTest {
|
||||
public void exceptionWhenNoParamsSupplied() {
|
||||
assertThatThrownBy(() -> method.response(requestWithParams()))
|
||||
.isInstanceOf(InvalidJsonRpcParameters.class)
|
||||
.hasMessage("Missing required json rpc parameter at index 0");
|
||||
.hasMessage("Invalid validator address parameter (index 0)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exceptionWhenInvalidAddressParameterSupplied() {
|
||||
assertThatThrownBy(() -> method.response(requestWithParams("InvalidAddress")))
|
||||
.isInstanceOf(InvalidJsonRpcParameters.class)
|
||||
.hasMessageContaining("Invalid json rpc parameter at index 0");
|
||||
.hasMessageContaining("Invalid validator address parameter (index 0)");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -75,14 +75,14 @@ public class QbftGetSignerMetricsTest {
|
||||
public void exceptionWhenInvalidStartBlockSupplied() {
|
||||
assertThatThrownBy(() -> method.response(requestWithParams("INVALID")))
|
||||
.isInstanceOf(InvalidJsonRpcParameters.class)
|
||||
.hasMessageContaining("Invalid json rpc parameter at index 0");
|
||||
.hasMessageContaining("Invalid start block parameter (index 0)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exceptionWhenInvalidEndBlockSupplied() {
|
||||
assertThatThrownBy(() -> method.response(requestWithParams("1", "INVALID")))
|
||||
.isInstanceOf(InvalidJsonRpcParameters.class)
|
||||
.hasMessageContaining("Invalid json rpc parameter at index 1");
|
||||
.hasMessageContaining("Invalid end block parameter (index 1)");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -58,7 +58,7 @@ public class QbftProposeValidatorVoteTest {
|
||||
public void exceptionWhenNoParamsSupplied() {
|
||||
assertThatThrownBy(() -> method.response(requestWithParams()))
|
||||
.isInstanceOf(InvalidJsonRpcParameters.class)
|
||||
.hasMessage("Missing required json rpc parameter at index 0");
|
||||
.hasMessage("Invalid validator address parameter (index 0)");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,7 +72,7 @@ public class QbftProposeValidatorVoteTest {
|
||||
public void exceptionWhenNoAddressSupplied() {
|
||||
assertThatThrownBy(() -> method.response(requestWithParams("true")))
|
||||
.isInstanceOf(InvalidJsonRpcParameters.class)
|
||||
.hasMessageContaining("Invalid json rpc parameter at index 0");
|
||||
.hasMessageContaining("Invalid validator address parameter");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -410,7 +410,7 @@ public class EthGetBlockByNumberIntegrationTest {
|
||||
|
||||
assertThat(thrown)
|
||||
.isInstanceOf(InvalidJsonRpcParameters.class)
|
||||
.hasMessageContaining("Invalid json rpc parameter at index 0");
|
||||
.hasMessageContaining("Invalid block parameter");
|
||||
}
|
||||
|
||||
/** The Tag | Quantity is the first parameter, either a String or a number */
|
||||
@@ -422,7 +422,7 @@ public class EthGetBlockByNumberIntegrationTest {
|
||||
|
||||
assertThat(thrown)
|
||||
.isInstanceOf(InvalidJsonRpcParameters.class)
|
||||
.hasMessageContaining("Invalid json rpc parameter at index 0");
|
||||
.hasMessageContaining("Invalid block parameter");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -437,7 +437,6 @@ public class EthGetBlockByNumberIntegrationTest {
|
||||
|
||||
assertThat(thrown)
|
||||
.isInstanceOf(InvalidJsonRpcParameters.class)
|
||||
.hasNoCause()
|
||||
.hasMessage("Missing required json rpc parameter at index 1");
|
||||
}
|
||||
|
||||
@@ -453,8 +452,7 @@ public class EthGetBlockByNumberIntegrationTest {
|
||||
|
||||
assertThat(thrown)
|
||||
.isInstanceOf(InvalidJsonRpcParameters.class)
|
||||
.hasNoCause()
|
||||
.hasMessage("Missing required json rpc parameter at index 0");
|
||||
.hasMessage("Invalid block parameter (index 0)");
|
||||
}
|
||||
|
||||
private JsonRpcRequestContext requestWithParams(final Object... params) {
|
||||
|
||||
@@ -86,6 +86,7 @@ public enum RpcMethod {
|
||||
PRIV_GET_FILTER_LOGS("priv_getFilterLogs"),
|
||||
PRIV_SUBSCRIBE("priv_subscribe"),
|
||||
PRIV_UNSUBSCRIBE("priv_unsubscribe"),
|
||||
PRIV_TRACE_TRANSACTION("priv_traceTransaction"),
|
||||
PRIVX_FIND_PRIVACY_GROUP_OLD("privx_findOnchainPrivacyGroup"),
|
||||
PRIVX_FIND_PRIVACY_GROUP("privx_findFlexiblePrivacyGroup"),
|
||||
EEA_SEND_RAW_TRANSACTION("eea_sendRawTransaction"),
|
||||
|
||||
@@ -43,8 +43,12 @@ public class BaseJsonRpcProcessor implements JsonRpcProcessor {
|
||||
try {
|
||||
return method.response(request);
|
||||
} catch (final InvalidJsonRpcParameters e) {
|
||||
LOG.debug("Invalid Params for method: {}", method.getName(), e);
|
||||
return new JsonRpcErrorResponse(id, RpcErrorType.INVALID_PARAMS);
|
||||
LOG.debug(
|
||||
"Invalid Params for method: {}, error: {}",
|
||||
method.getName(),
|
||||
e.getRpcErrorType().getMessage(),
|
||||
e);
|
||||
return new JsonRpcErrorResponse(id, e.getRpcErrorType());
|
||||
} catch (final MultiTenancyValidationException e) {
|
||||
return new JsonRpcUnauthorizedResponse(id, RpcErrorType.UNAUTHORIZED);
|
||||
} catch (final RuntimeException e) {
|
||||
|
||||
@@ -60,7 +60,6 @@ public class TracedJsonRpcProcessor implements JsonRpcProcessor {
|
||||
case INVALID_ACCOUNT_PARAMS:
|
||||
case INVALID_ADDRESS_HASH_PARAMS:
|
||||
case INVALID_ADDRESS_PARAMS:
|
||||
case INVALID_AUTH_PARAMS:
|
||||
case INVALID_BLOB_COUNT:
|
||||
case INVALID_BLOB_GAS_USED_PARAMS:
|
||||
case INVALID_BLOCK_PARAMS:
|
||||
@@ -104,6 +103,7 @@ public class TracedJsonRpcProcessor implements JsonRpcProcessor {
|
||||
case INVALID_PRIVACY_GROUP_PARAMS:
|
||||
case INVALID_PRIVATE_FROM_PARAMS:
|
||||
case INVALID_PRIVATE_FOR_PARAMS:
|
||||
case INVALID_PROPOSAL_PARAMS:
|
||||
case INVALID_REMOTE_CAPABILITIES_PARAMS:
|
||||
case INVALID_REWARD_PERCENTILES_PARAMS:
|
||||
case INVALID_SEALER_ID_PARAMS:
|
||||
|
||||
@@ -19,10 +19,12 @@ import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErr
|
||||
|
||||
import org.hyperledger.besu.ethereum.ProtocolContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AbstractBlockParameterMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
|
||||
import org.hyperledger.besu.ethereum.core.Block;
|
||||
import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode;
|
||||
@@ -56,7 +58,12 @@ public class DebugReplayBlock extends AbstractBlockParameterMethod {
|
||||
|
||||
@Override
|
||||
protected BlockParameter blockParameter(final JsonRpcRequestContext request) {
|
||||
return request.getRequiredParameter(0, BlockParameter.class);
|
||||
try {
|
||||
return request.getRequiredParameter(0, BlockParameter.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -106,7 +106,7 @@ public abstract class AbstractBlockParameterOrBlockHashMethod implements JsonRpc
|
||||
final OptionalLong blockNumber = blockParameterOrBlockHash.getNumber();
|
||||
if (blockNumber.isEmpty() || blockNumber.getAsLong() < 0) {
|
||||
return new JsonRpcErrorResponse(
|
||||
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
|
||||
requestContext.getRequest().getId(), RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS);
|
||||
} else if (blockNumber.getAsLong() > getBlockchainQueries().headBlockNumber()) {
|
||||
return new JsonRpcErrorResponse(
|
||||
requestContext.getRequest().getId(), RpcErrorType.BLOCK_NOT_FOUND);
|
||||
@@ -123,7 +123,7 @@ public abstract class AbstractBlockParameterOrBlockHashMethod implements JsonRpc
|
||||
Optional<Hash> blockHash = blockParameterOrBlockHash.getHash();
|
||||
if (blockHash.isEmpty()) {
|
||||
return new JsonRpcErrorResponse(
|
||||
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
|
||||
requestContext.getRequest().getId(), RpcErrorType.INVALID_BLOCK_HASH_PARAMS);
|
||||
}
|
||||
|
||||
// return error if block hash does not find a block
|
||||
|
||||
@@ -17,9 +17,11 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
|
||||
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter.TraceType;
|
||||
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TraceCallResult;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.diff.StateDiffGenerator;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.diff.StateDiffTrace;
|
||||
@@ -62,8 +64,13 @@ public abstract class AbstractTraceByBlock extends AbstractBlockParameterMethod
|
||||
|
||||
@Override
|
||||
protected BlockParameter blockParameter(final JsonRpcRequestContext request) {
|
||||
final Optional<BlockParameter> maybeBlockParameter =
|
||||
request.getOptionalParameter(2, BlockParameter.class);
|
||||
final Optional<BlockParameter> maybeBlockParameter;
|
||||
try {
|
||||
maybeBlockParameter = request.getOptionalParameter(2, BlockParameter.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block parameter (index 2)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
|
||||
}
|
||||
|
||||
if (maybeBlockParameter.isPresent()) {
|
||||
return maybeBlockParameter.get();
|
||||
|
||||
@@ -16,9 +16,11 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
|
||||
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
|
||||
|
||||
import java.util.Optional;
|
||||
@@ -38,8 +40,13 @@ public class AdminGenerateLogBloomCache implements JsonRpcMethod {
|
||||
|
||||
@Override
|
||||
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
|
||||
final Optional<BlockParameter> startBlockParam =
|
||||
requestContext.getOptionalParameter(0, BlockParameter.class);
|
||||
final Optional<BlockParameter> startBlockParam;
|
||||
try {
|
||||
startBlockParam = requestContext.getOptionalParameter(0, BlockParameter.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid start block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
|
||||
}
|
||||
final long startBlock;
|
||||
if (startBlockParam.isEmpty() || startBlockParam.get().isEarliest()) {
|
||||
startBlock = 0;
|
||||
@@ -50,8 +57,13 @@ public class AdminGenerateLogBloomCache implements JsonRpcMethod {
|
||||
startBlock = Long.MAX_VALUE;
|
||||
}
|
||||
|
||||
final Optional<BlockParameter> stopBlockParam =
|
||||
requestContext.getOptionalParameter(1, BlockParameter.class);
|
||||
final Optional<BlockParameter> stopBlockParam;
|
||||
try {
|
||||
stopBlockParam = requestContext.getOptionalParameter(1, BlockParameter.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid stop block parameter (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
|
||||
}
|
||||
final long stopBlock;
|
||||
if (stopBlockParam.isEmpty()) {
|
||||
if (startBlockParam.isEmpty()) {
|
||||
|
||||
@@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
|
||||
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
|
||||
@@ -42,10 +43,20 @@ public class AdminLogsRemoveCache implements JsonRpcMethod {
|
||||
|
||||
@Override
|
||||
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
|
||||
final Optional<BlockParameter> startBlockParameter =
|
||||
requestContext.getOptionalParameter(0, BlockParameter.class);
|
||||
final Optional<BlockParameter> stopBlockParameter =
|
||||
requestContext.getOptionalParameter(1, BlockParameter.class);
|
||||
final Optional<BlockParameter> startBlockParameter;
|
||||
try {
|
||||
startBlockParameter = requestContext.getOptionalParameter(0, BlockParameter.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid start block parameter (index 0)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e);
|
||||
}
|
||||
final Optional<BlockParameter> stopBlockParameter;
|
||||
try {
|
||||
stopBlockParameter = requestContext.getOptionalParameter(1, BlockParameter.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid stop block parameter (index 1)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e);
|
||||
}
|
||||
|
||||
final long startBlock;
|
||||
if (startBlockParameter.isEmpty() || startBlockParameter.get().isEarliest()) {
|
||||
@@ -81,7 +92,7 @@ public class AdminLogsRemoveCache implements JsonRpcMethod {
|
||||
|
||||
if (stopBlock < startBlock) {
|
||||
return new JsonRpcErrorResponse(
|
||||
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
|
||||
requestContext.getRequest().getId(), RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS);
|
||||
}
|
||||
|
||||
final TransactionLogBloomCacher transactionLogBloomCacher =
|
||||
|
||||
@@ -16,8 +16,10 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
|
||||
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
|
||||
import org.hyperledger.besu.ethereum.api.query.cache.TransactionLogBloomCacher;
|
||||
|
||||
@@ -38,7 +40,13 @@ public class AdminLogsRepairCache implements JsonRpcMethod {
|
||||
|
||||
@Override
|
||||
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
|
||||
final Optional<Long> blockNumber = requestContext.getOptionalParameter(0, Long.class);
|
||||
final Optional<Long> blockNumber;
|
||||
try {
|
||||
blockNumber = requestContext.getOptionalParameter(0, Long.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block number parameter (index 0)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e);
|
||||
}
|
||||
|
||||
if (blockNumber.isPresent()
|
||||
&& blockchainQueries.getBlockchain().getBlockByNumber(blockNumber.get()).isEmpty()) {
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.hyperledger.besu.datatypes.Address;
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameterOrBlockHash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer;
|
||||
@@ -66,14 +67,25 @@ public class DebugAccountAt extends AbstractBlockParameterOrBlockHashMethod {
|
||||
@Override
|
||||
protected BlockParameterOrBlockHash blockParameterOrBlockHash(
|
||||
final JsonRpcRequestContext requestContext) {
|
||||
return requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class);
|
||||
try {
|
||||
return requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block or block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object resultByBlockHash(
|
||||
final JsonRpcRequestContext requestContext, final Hash blockHash) {
|
||||
final Integer txIndex = requestContext.getRequiredParameter(1, Integer.class);
|
||||
final Address address = requestContext.getRequiredParameter(2, Address.class);
|
||||
final Address address;
|
||||
try {
|
||||
address = requestContext.getRequiredParameter(2, Address.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid address parameter (index 2)", RpcErrorType.INVALID_ADDRESS_PARAMS, e);
|
||||
}
|
||||
|
||||
Optional<BlockWithMetadata<TransactionWithMetadata, Hash>> block =
|
||||
blockchainQueries.get().blockByHash(blockHash);
|
||||
|
||||
@@ -58,14 +58,22 @@ public class DebugAccountRange implements JsonRpcMethod {
|
||||
|
||||
@Override
|
||||
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
|
||||
final BlockParameterOrBlockHash blockParameterOrBlockHash =
|
||||
requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class);
|
||||
final BlockParameterOrBlockHash blockParameterOrBlockHash;
|
||||
try {
|
||||
blockParameterOrBlockHash =
|
||||
requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block parameter or block hash parameter (index 0)",
|
||||
RpcErrorType.INVALID_BLOCK_PARAMS,
|
||||
e);
|
||||
}
|
||||
final String addressHash;
|
||||
try {
|
||||
addressHash = requestContext.getRequiredParameter(2, String.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid address hash parameter", RpcErrorType.INVALID_ADDRESS_HASH_PARAMS, e);
|
||||
"Invalid address hash parameter (index 2)", RpcErrorType.INVALID_ADDRESS_HASH_PARAMS, e);
|
||||
}
|
||||
final int maxResults = requestContext.getRequiredParameter(3, Integer.TYPE);
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
|
||||
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
@@ -37,7 +38,12 @@ public class DebugGetRawBlock extends AbstractBlockParameterMethod {
|
||||
|
||||
@Override
|
||||
protected BlockParameter blockParameter(final JsonRpcRequestContext request) {
|
||||
return request.getRequiredParameter(0, BlockParameter.class);
|
||||
try {
|
||||
return request.getRequiredParameter(0, BlockParameter.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
|
||||
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
@@ -37,7 +38,12 @@ public class DebugGetRawHeader extends AbstractBlockParameterMethod {
|
||||
|
||||
@Override
|
||||
protected BlockParameter blockParameter(final JsonRpcRequestContext request) {
|
||||
return request.getRequiredParameter(0, BlockParameter.class);
|
||||
try {
|
||||
return request.getRequiredParameter(0, BlockParameter.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,7 +17,9 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameterOrBlockHash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
|
||||
import org.hyperledger.besu.ethereum.core.TransactionReceipt;
|
||||
import org.hyperledger.besu.ethereum.rlp.RLP;
|
||||
@@ -40,7 +42,12 @@ public class DebugGetRawReceipts extends AbstractBlockParameterOrBlockHashMethod
|
||||
@Override
|
||||
protected BlockParameterOrBlockHash blockParameterOrBlockHash(
|
||||
final JsonRpcRequestContext request) {
|
||||
return request.getRequiredParameter(0, BlockParameterOrBlockHash.class);
|
||||
try {
|
||||
return request.getRequiredParameter(0, BlockParameterOrBlockHash.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block or block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,9 +20,11 @@ import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.ethereum.ProtocolContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
|
||||
|
||||
import java.util.Optional;
|
||||
@@ -43,7 +45,12 @@ public class DebugSetHead extends AbstractBlockParameterMethod {
|
||||
|
||||
@Override
|
||||
protected BlockParameter blockParameter(final JsonRpcRequestContext request) {
|
||||
return request.getRequiredParameter(0, BlockParameter.class);
|
||||
try {
|
||||
return request.getRequiredParameter(0, BlockParameter.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.ethereum.ProtocolContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTracer;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
|
||||
@@ -52,7 +53,13 @@ public class DebugStandardTraceBadBlockToFile extends DebugStandardTraceBlockToF
|
||||
|
||||
@Override
|
||||
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
|
||||
final Hash blockHash = requestContext.getRequiredParameter(0, Hash.class);
|
||||
final Hash blockHash;
|
||||
try {
|
||||
blockHash = requestContext.getRequiredParameter(0, Hash.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e);
|
||||
}
|
||||
final Optional<TransactionTraceParams> transactionTraceParams =
|
||||
requestContext.getOptionalParameter(1, TransactionTraceParams.class);
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Trans
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTracer;
|
||||
@@ -59,7 +60,13 @@ public class DebugStandardTraceBlockToFile implements JsonRpcMethod {
|
||||
|
||||
@Override
|
||||
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
|
||||
final Hash blockHash = requestContext.getRequiredParameter(0, Hash.class);
|
||||
final Hash blockHash;
|
||||
try {
|
||||
blockHash = requestContext.getRequiredParameter(0, Hash.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e);
|
||||
}
|
||||
final Optional<TransactionTraceParams> transactionTraceParams =
|
||||
requestContext.getOptionalParameter(1, TransactionTraceParams.class);
|
||||
|
||||
|
||||
@@ -18,12 +18,14 @@ import org.hyperledger.besu.datatypes.Address;
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameterOrBlockHash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockReplay;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer.TraceableState;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugStorageRangeAtResult;
|
||||
import org.hyperledger.besu.ethereum.api.query.BlockWithMetadata;
|
||||
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
|
||||
@@ -67,10 +69,22 @@ public class DebugStorageRangeAt implements JsonRpcMethod {
|
||||
|
||||
@Override
|
||||
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
|
||||
final BlockParameterOrBlockHash blockParameterOrBlockHash =
|
||||
requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class);
|
||||
final BlockParameterOrBlockHash blockParameterOrBlockHash;
|
||||
try {
|
||||
blockParameterOrBlockHash =
|
||||
requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block or block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
|
||||
}
|
||||
final int transactionIndex = requestContext.getRequiredParameter(1, Integer.class);
|
||||
final Address accountAddress = requestContext.getRequiredParameter(2, Address.class);
|
||||
final Address accountAddress;
|
||||
try {
|
||||
accountAddress = requestContext.getRequiredParameter(2, Address.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid account address parameter (index 2)", RpcErrorType.INVALID_ADDRESS_PARAMS, e);
|
||||
}
|
||||
final Hash startKey =
|
||||
Hash.fromHexStringLenient(requestContext.getRequiredParameter(3, String.class));
|
||||
final int limit = requestContext.getRequiredParameter(4, Integer.class);
|
||||
|
||||
@@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
|
||||
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer;
|
||||
@@ -69,9 +70,12 @@ public class DebugTraceBlock implements JsonRpcMethod {
|
||||
try {
|
||||
block = Block.readFrom(RLP.input(Bytes.fromHexString(input)), this.blockHeaderFunctions);
|
||||
} catch (final RLPException e) {
|
||||
LOG.debug("Failed to parse block RLP", e);
|
||||
LOG.debug("Failed to parse block RLP (index 0)", e);
|
||||
return new JsonRpcErrorResponse(
|
||||
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
|
||||
requestContext.getRequest().getId(), RpcErrorType.INVALID_BLOCK_PARAMS);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block params (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
|
||||
}
|
||||
final TraceOptions traceOptions =
|
||||
requestContext
|
||||
|
||||
@@ -17,12 +17,14 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugTraceTransactionResult;
|
||||
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
|
||||
import org.hyperledger.besu.ethereum.debug.TraceOptions;
|
||||
@@ -50,7 +52,13 @@ public class DebugTraceBlockByHash implements JsonRpcMethod {
|
||||
|
||||
@Override
|
||||
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
|
||||
final Hash blockHash = requestContext.getRequiredParameter(0, Hash.class);
|
||||
final Hash blockHash;
|
||||
try {
|
||||
blockHash = requestContext.getRequiredParameter(0, Hash.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e);
|
||||
}
|
||||
final TraceOptions traceOptions =
|
||||
requestContext
|
||||
.getOptionalParameter(1, TransactionTraceParams.class)
|
||||
|
||||
@@ -17,11 +17,13 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugTraceTransactionResult;
|
||||
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
|
||||
import org.hyperledger.besu.ethereum.debug.TraceOptions;
|
||||
@@ -47,7 +49,12 @@ public class DebugTraceBlockByNumber extends AbstractBlockParameterMethod {
|
||||
|
||||
@Override
|
||||
protected BlockParameter blockParameter(final JsonRpcRequestContext request) {
|
||||
return request.getRequiredParameter(0, BlockParameter.class);
|
||||
try {
|
||||
return request.getRequiredParameter(0, BlockParameter.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,11 +18,13 @@ import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErr
|
||||
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugTraceTransactionResult;
|
||||
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
|
||||
import org.hyperledger.besu.ethereum.debug.TraceOptions;
|
||||
@@ -61,8 +63,13 @@ public class DebugTraceCall extends AbstractTraceCall {
|
||||
|
||||
@Override
|
||||
protected BlockParameter blockParameter(final JsonRpcRequestContext request) {
|
||||
final Optional<BlockParameter> maybeBlockParameter =
|
||||
request.getOptionalParameter(1, BlockParameter.class);
|
||||
final Optional<BlockParameter> maybeBlockParameter;
|
||||
try {
|
||||
maybeBlockParameter = request.getOptionalParameter(1, BlockParameter.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block parameter (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
|
||||
}
|
||||
|
||||
return maybeBlockParameter.orElse(BlockParameter.LATEST);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.hyperledger.besu.datatypes.Wei;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcErrorConverter;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameterOrBlockHash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError;
|
||||
@@ -57,7 +58,12 @@ public class EthCall extends AbstractBlockParameterOrBlockHashMethod {
|
||||
@Override
|
||||
protected BlockParameterOrBlockHash blockParameterOrBlockHash(
|
||||
final JsonRpcRequestContext request) {
|
||||
return request.getRequiredParameter(1, BlockParameterOrBlockHash.class);
|
||||
try {
|
||||
return request.getRequiredParameter(1, BlockParameterOrBlockHash.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block or block hash parameters (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.hyperledger.besu.datatypes.Wei;
|
||||
import org.hyperledger.besu.ethereum.api.ApiConfiguration;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedIntParameter;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
|
||||
@@ -87,11 +88,24 @@ public class EthFeeHistory implements JsonRpcMethod {
|
||||
public JsonRpcResponse response(final JsonRpcRequestContext request) {
|
||||
final Object requestId = request.getRequest().getId();
|
||||
|
||||
final int blockCount = request.getRequiredParameter(0, UnsignedIntParameter.class).getValue();
|
||||
if (isInvalidBlockCount(blockCount)) {
|
||||
return new JsonRpcErrorResponse(requestId, RpcErrorType.INVALID_PARAMS);
|
||||
final int blockCount;
|
||||
try {
|
||||
blockCount = request.getRequiredParameter(0, UnsignedIntParameter.class).getValue();
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block count parameter (index 0)", RpcErrorType.INVALID_BLOCK_COUNT_PARAMS, e);
|
||||
}
|
||||
final BlockParameter highestBlock = request.getRequiredParameter(1, BlockParameter.class);
|
||||
if (isInvalidBlockCount(blockCount)) {
|
||||
return new JsonRpcErrorResponse(requestId, RpcErrorType.INVALID_BLOCK_COUNT_PARAMS);
|
||||
}
|
||||
final BlockParameter highestBlock;
|
||||
try {
|
||||
highestBlock = request.getRequiredParameter(1, BlockParameter.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid highest block parameter (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
|
||||
}
|
||||
|
||||
final Optional<List<Double>> maybeRewardPercentiles =
|
||||
request.getOptionalParameter(2, Double[].class).map(Arrays::asList);
|
||||
|
||||
@@ -99,7 +113,7 @@ public class EthFeeHistory implements JsonRpcMethod {
|
||||
final long chainHeadBlockNumber = chainHeadHeader.getNumber();
|
||||
final long highestBlockNumber = highestBlock.getNumber().orElse(chainHeadBlockNumber);
|
||||
if (highestBlockNumber > chainHeadBlockNumber) {
|
||||
return new JsonRpcErrorResponse(requestId, RpcErrorType.INVALID_PARAMS);
|
||||
return new JsonRpcErrorResponse(requestId, RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS);
|
||||
}
|
||||
|
||||
final long firstBlock = Math.max(0, highestBlockNumber - (blockCount - 1));
|
||||
|
||||
@@ -18,7 +18,9 @@ import org.hyperledger.besu.datatypes.Address;
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameterOrBlockHash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity;
|
||||
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
|
||||
|
||||
@@ -41,12 +43,23 @@ public class EthGetBalance extends AbstractBlockParameterOrBlockHashMethod {
|
||||
@Override
|
||||
protected BlockParameterOrBlockHash blockParameterOrBlockHash(
|
||||
final JsonRpcRequestContext request) {
|
||||
return request.getRequiredParameter(1, BlockParameterOrBlockHash.class);
|
||||
try {
|
||||
return request.getRequiredParameter(1, BlockParameterOrBlockHash.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block or block hash parameter (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String resultByBlockHash(final JsonRpcRequestContext request, final Hash blockHash) {
|
||||
final Address address = request.getRequiredParameter(0, Address.class);
|
||||
final Address address;
|
||||
try {
|
||||
address = request.getRequiredParameter(0, Address.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e);
|
||||
}
|
||||
return blockchainQueries
|
||||
.get()
|
||||
.accountBalance(address, blockHash)
|
||||
|
||||
@@ -17,8 +17,10 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResult;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory;
|
||||
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
|
||||
@@ -59,7 +61,13 @@ public class EthGetBlockByHash implements JsonRpcMethod {
|
||||
}
|
||||
|
||||
private BlockResult blockResult(final JsonRpcRequestContext request) {
|
||||
final Hash hash = request.getRequiredParameter(0, Hash.class);
|
||||
final Hash hash;
|
||||
try {
|
||||
hash = request.getRequiredParameter(0, Hash.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e);
|
||||
}
|
||||
|
||||
if (isCompleteTransactions(request)) {
|
||||
return transactionComplete(hash);
|
||||
|
||||
@@ -17,7 +17,9 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResult;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory;
|
||||
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
|
||||
@@ -62,7 +64,12 @@ public class EthGetBlockByNumber extends AbstractBlockParameterMethod {
|
||||
|
||||
@Override
|
||||
protected BlockParameter blockParameter(final JsonRpcRequestContext request) {
|
||||
return request.getRequiredParameter(0, BlockParameter.class);
|
||||
try {
|
||||
return request.getRequiredParameter(0, BlockParameter.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,7 +17,9 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameterOrBlockHash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockReceiptsResult;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionReceiptResult;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionReceiptRootResult;
|
||||
@@ -53,7 +55,12 @@ public class EthGetBlockReceipts extends AbstractBlockParameterOrBlockHashMethod
|
||||
@Override
|
||||
protected BlockParameterOrBlockHash blockParameterOrBlockHash(
|
||||
final JsonRpcRequestContext request) {
|
||||
return request.getRequiredParameter(0, BlockParameterOrBlockHash.class);
|
||||
try {
|
||||
return request.getRequiredParameter(0, BlockParameterOrBlockHash.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block or block hash parameters (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,8 +17,10 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity;
|
||||
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
|
||||
|
||||
@@ -37,7 +39,15 @@ public class EthGetBlockTransactionCountByHash implements JsonRpcMethod {
|
||||
|
||||
@Override
|
||||
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
|
||||
final Hash hash = requestContext.getRequiredParameter(0, Hash.class);
|
||||
final Hash hash;
|
||||
try {
|
||||
hash = requestContext.getRequiredParameter(0, Hash.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block header hash parameter (index 0)",
|
||||
RpcErrorType.INVALID_BLOCK_HASH_PARAMS,
|
||||
e);
|
||||
}
|
||||
final Integer count = blockchain.getTransactionCount(hash);
|
||||
|
||||
if (count == -1) {
|
||||
|
||||
@@ -16,7 +16,9 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
|
||||
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity;
|
||||
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
|
||||
|
||||
@@ -33,7 +35,12 @@ public class EthGetBlockTransactionCountByNumber extends AbstractBlockParameterM
|
||||
|
||||
@Override
|
||||
protected BlockParameter blockParameter(final JsonRpcRequestContext request) {
|
||||
return request.getRequiredParameter(0, BlockParameter.class);
|
||||
try {
|
||||
return request.getRequiredParameter(0, BlockParameter.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block parameters (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,7 +18,9 @@ import org.hyperledger.besu.datatypes.Address;
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameterOrBlockHash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
@@ -43,12 +45,23 @@ public class EthGetCode extends AbstractBlockParameterOrBlockHashMethod {
|
||||
@Override
|
||||
protected BlockParameterOrBlockHash blockParameterOrBlockHash(
|
||||
final JsonRpcRequestContext request) {
|
||||
return request.getRequiredParameter(1, BlockParameterOrBlockHash.class);
|
||||
try {
|
||||
return request.getRequiredParameter(1, BlockParameterOrBlockHash.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block or block hash parameter (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String resultByBlockHash(final JsonRpcRequestContext request, final Hash blockHash) {
|
||||
final Address address = request.getRequiredParameter(0, Address.class);
|
||||
final Address address;
|
||||
try {
|
||||
address = request.getRequiredParameter(0, Address.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e);
|
||||
}
|
||||
return getBlockchainQueries().getCode(address, blockHash).map(Bytes::toString).orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
|
||||
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
|
||||
@@ -78,16 +79,22 @@ public class EthGetLogs implements JsonRpcMethod {
|
||||
.getBlockNumber(blockchain)
|
||||
.orElseThrow(
|
||||
() ->
|
||||
new Exception("fromBlock not found: " + filter.getFromBlock()));
|
||||
new InvalidJsonRpcParameters(
|
||||
"fromBlock not found: " + filter.getFromBlock(),
|
||||
RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS));
|
||||
toBlockNumber =
|
||||
filter
|
||||
.getToBlock()
|
||||
.getBlockNumber(blockchain)
|
||||
.orElseThrow(
|
||||
() -> new Exception("toBlock not found: " + filter.getToBlock()));
|
||||
() ->
|
||||
new InvalidJsonRpcParameters(
|
||||
"toBlock not found: " + filter.getToBlock(),
|
||||
RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS));
|
||||
if (maxLogRange > 0 && (toBlockNumber - fromBlockNumber) > maxLogRange) {
|
||||
throw new IllegalArgumentException(
|
||||
"Requested range exceeds maximum range limit");
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Requested range exceeds maximum range limit",
|
||||
RpcErrorType.EXCEEDS_RPC_MAX_BLOCK_RANGE);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
ex.set(e);
|
||||
@@ -107,12 +114,13 @@ public class EthGetLogs implements JsonRpcMethod {
|
||||
.addArgument(requestContext.getRequest())
|
||||
.setCause(ex.get())
|
||||
.log();
|
||||
if (ex.get() instanceof IllegalArgumentException) {
|
||||
if (ex.get() instanceof InvalidJsonRpcParameters) {
|
||||
return new JsonRpcErrorResponse(
|
||||
requestContext.getRequest().getId(), RpcErrorType.EXCEEDS_RPC_MAX_BLOCK_RANGE);
|
||||
requestContext.getRequest().getId(),
|
||||
((InvalidJsonRpcParameters) ex.get()).getRpcErrorType());
|
||||
} else {
|
||||
throw new RuntimeException(ex.get());
|
||||
}
|
||||
return new JsonRpcErrorResponse(
|
||||
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
|
||||
}
|
||||
|
||||
return new JsonRpcSuccessResponse(
|
||||
|
||||
@@ -18,8 +18,10 @@ import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.datatypes.Wei;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.ImmutableMinerDataResult;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.ImmutableUncleRewardResult;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.MinerDataResult;
|
||||
@@ -60,7 +62,13 @@ public class EthGetMinerDataByBlockHash implements JsonRpcMethod {
|
||||
|
||||
@Override
|
||||
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
|
||||
final Hash hash = requestContext.getRequest().getRequiredParameter(0, Hash.class);
|
||||
final Hash hash;
|
||||
try {
|
||||
hash = requestContext.getRequest().getRequiredParameter(0, Hash.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_HASH_PARAMS, e);
|
||||
}
|
||||
|
||||
BlockWithMetadata<TransactionWithMetadata, Hash> block =
|
||||
blockchain.get().blockByHash(hash).orElse(null);
|
||||
|
||||
@@ -17,7 +17,9 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.MinerDataResult;
|
||||
import org.hyperledger.besu.ethereum.api.query.BlockWithMetadata;
|
||||
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
|
||||
@@ -40,7 +42,12 @@ public class EthGetMinerDataByBlockNumber extends AbstractBlockParameterMethod {
|
||||
|
||||
@Override
|
||||
protected BlockParameter blockParameter(final JsonRpcRequestContext request) {
|
||||
return request.getRequiredParameter(0, BlockParameter.class);
|
||||
try {
|
||||
return request.getRequiredParameter(0, BlockParameter.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.hyperledger.besu.datatypes.Address;
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameterOrBlockHash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
|
||||
@@ -48,14 +49,25 @@ public class EthGetProof extends AbstractBlockParameterOrBlockHashMethod {
|
||||
@Override
|
||||
protected BlockParameterOrBlockHash blockParameterOrBlockHash(
|
||||
final JsonRpcRequestContext request) {
|
||||
return request.getRequiredParameter(2, BlockParameterOrBlockHash.class);
|
||||
try {
|
||||
return request.getRequiredParameter(2, BlockParameterOrBlockHash.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block or block hash parameter (index 2)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object resultByBlockHash(
|
||||
final JsonRpcRequestContext requestContext, final Hash blockHash) {
|
||||
|
||||
final Address address = requestContext.getRequiredParameter(0, Address.class);
|
||||
final Address address;
|
||||
try {
|
||||
address = requestContext.getRequiredParameter(0, Address.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e);
|
||||
}
|
||||
final List<UInt256> storageKeys = getStorageKeys(requestContext);
|
||||
|
||||
final Blockchain blockchain = getBlockchainQueries().getBlockchain();
|
||||
|
||||
@@ -18,8 +18,10 @@ import org.hyperledger.besu.datatypes.Address;
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameterOrBlockHash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UInt256Parameter;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
|
||||
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
|
||||
|
||||
import org.apache.tuweni.units.bigints.UInt256;
|
||||
@@ -37,12 +39,23 @@ public class EthGetStorageAt extends AbstractBlockParameterOrBlockHashMethod {
|
||||
@Override
|
||||
protected BlockParameterOrBlockHash blockParameterOrBlockHash(
|
||||
final JsonRpcRequestContext request) {
|
||||
return request.getRequiredParameter(2, BlockParameterOrBlockHash.class);
|
||||
try {
|
||||
return request.getRequiredParameter(2, BlockParameterOrBlockHash.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid block or block hash parameter (index 2)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String resultByBlockHash(final JsonRpcRequestContext request, final Hash blockHash) {
|
||||
final Address address = request.getRequiredParameter(0, Address.class);
|
||||
final Address address;
|
||||
try {
|
||||
address = request.getRequiredParameter(0, Address.class);
|
||||
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
|
||||
throw new InvalidJsonRpcParameters(
|
||||
"Invalid address parameter (index 0)", RpcErrorType.INVALID_ADDRESS_PARAMS, e);
|
||||
}
|
||||
final UInt256 position = request.getRequiredParameter(1, UInt256Parameter.class).getValue();
|
||||
return blockchainQueries
|
||||
.get()
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user