From 22a570eda42dd4bba917bcaac93bdf642fe765fd Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Wed, 30 Oct 2024 16:21:10 +0100 Subject: [PATCH 01/56] Fix registering new metric categories from plugins (#7825) Signed-off-by: Fabio Di Fabio --- CHANGELOG.md | 1 + .../acceptance/plugins/TestMetricsPlugin.java | 76 +++++++++++++++++++ .../acceptance/plugins/MetricsPluginTest.java | 73 ++++++++++++++++++ .../org/hyperledger/besu/cli/BesuCommand.java | 18 ++--- .../converter/MetricCategoryConverter.java | 73 ------------------ .../cli/options/stable/MetricsOptions.java | 47 +++++++++++- .../hyperledger/besu/cli/BesuCommandTest.java | 41 ++++++---- .../MetricCategoryConverterTest.java | 63 --------------- .../besu/cli/options/MetricsOptionsTest.java | 16 +++- .../metrics/MetricCategoryRegistryImpl.java | 47 +++++++++--- 10 files changed, 279 insertions(+), 176 deletions(-) create mode 100644 acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestMetricsPlugin.java create mode 100644 acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/MetricsPluginTest.java delete mode 100644 besu/src/main/java/org/hyperledger/besu/cli/converter/MetricCategoryConverter.java delete mode 100644 besu/src/test/java/org/hyperledger/besu/cli/converter/MetricCategoryConverterTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bfb4ebd3ec..4b20bc15aea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - Add a method to get all the transaction in the pool, to the `TransactionPoolService`, to easily access the transaction pool content from plugins [#7813](https://github.com/hyperledger/besu/pull/7813) ### Bug fixes +- Fix registering new metric categories from plugins [#7825](https://github.com/hyperledger/besu/pull/7825) ## 24.10.0 diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestMetricsPlugin.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestMetricsPlugin.java new file mode 100644 index 00000000000..7e1ac2ccdec --- /dev/null +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestMetricsPlugin.java @@ -0,0 +1,76 @@ +/* + * Copyright contributors to 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.plugins; + +import org.hyperledger.besu.plugin.BesuContext; +import org.hyperledger.besu.plugin.BesuPlugin; +import org.hyperledger.besu.plugin.services.MetricsSystem; +import org.hyperledger.besu.plugin.services.metrics.MetricCategory; +import org.hyperledger.besu.plugin.services.metrics.MetricCategoryRegistry; + +import java.util.Locale; +import java.util.Optional; + +import com.google.auto.service.AutoService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@AutoService(BesuPlugin.class) +public class TestMetricsPlugin implements BesuPlugin { + private static final Logger LOG = LoggerFactory.getLogger(TestMetricsPlugin.class); + private BesuContext besuContext; + + @Override + public void register(final BesuContext context) { + LOG.info("Registering TestMetricsPlugin"); + besuContext = context; + context + .getService(MetricCategoryRegistry.class) + .orElseThrow() + .addMetricCategory(TestMetricCategory.TEST_METRIC_CATEGORY); + } + + @Override + public void start() { + LOG.info("Starting TestMetricsPlugin"); + besuContext + .getService(MetricsSystem.class) + .orElseThrow() + .createGauge( + TestMetricCategory.TEST_METRIC_CATEGORY, + "test_metric", + "Returns 1 on succes", + () -> 1.0); + } + + @Override + public void stop() { + LOG.info("Stopping TestMetricsPlugin"); + } + + public enum TestMetricCategory implements MetricCategory { + TEST_METRIC_CATEGORY; + + @Override + public String getName() { + return name().toLowerCase(Locale.ROOT); + } + + @Override + public Optional getApplicationPrefix() { + return Optional.of("plugin_test_"); + } + } +} diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/MetricsPluginTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/MetricsPluginTest.java new file mode 100644 index 00000000000..75592007204 --- /dev/null +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/MetricsPluginTest.java @@ -0,0 +1,73 @@ +/* + * Copyright contributors to 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.plugins; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hyperledger.besu.tests.acceptance.plugins.TestMetricsPlugin.TestMetricCategory.TEST_METRIC_CATEGORY; + +import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; +import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase; +import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; +import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.BesuNodeConfigurationBuilder; + +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.util.List; +import java.util.Set; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class MetricsPluginTest extends AcceptanceTestBase { + private BesuNode node; + private MetricsConfiguration metricsConfiguration; + + @BeforeEach + public void setUp() throws Exception { + metricsConfiguration = + MetricsConfiguration.builder() + .enabled(true) + .port(0) + .metricCategories(Set.of(TEST_METRIC_CATEGORY)) + .build(); + node = + besu.create( + new BesuNodeConfigurationBuilder() + .name("node1") + .plugins(List.of("testPlugins")) + .metricsConfiguration(metricsConfiguration) + .build()); + + cluster.start(node); + } + + @Test + public void metricCategoryAdded() throws IOException, InterruptedException { + final var httpClient = HttpClient.newHttpClient(); + final var req = HttpRequest.newBuilder(URI.create(node.metricsHttpUrl().get())).build(); + final var resp = httpClient.send(req, HttpResponse.BodyHandlers.ofLines()); + assertThat(resp.statusCode()).isEqualTo(200); + final var foundMetric = + resp.body() + .filter( + line -> line.startsWith(TEST_METRIC_CATEGORY.getApplicationPrefix().orElseThrow())) + .findFirst() + .orElseThrow(); + assertThat(foundMetric).endsWith("1.0"); + } +} diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index 886e3d68383..45feaf10052 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -37,7 +37,6 @@ import org.hyperledger.besu.cli.config.EthNetworkConfig; import org.hyperledger.besu.cli.config.NetworkName; import org.hyperledger.besu.cli.config.ProfilesCompletionCandidates; -import org.hyperledger.besu.cli.converter.MetricCategoryConverter; import org.hyperledger.besu.cli.custom.JsonRPCAllowlistHostsProperty; import org.hyperledger.besu.cli.error.BesuExecutionExceptionHandler; import org.hyperledger.besu.cli.error.BesuParameterExceptionHandler; @@ -170,7 +169,6 @@ import org.hyperledger.besu.plugin.services.TransactionSelectionService; import org.hyperledger.besu.plugin.services.TransactionSimulationService; import org.hyperledger.besu.plugin.services.exception.StorageException; -import org.hyperledger.besu.plugin.services.metrics.MetricCategory; import org.hyperledger.besu.plugin.services.metrics.MetricCategoryRegistry; import org.hyperledger.besu.plugin.services.p2p.P2PService; import org.hyperledger.besu.plugin.services.rlp.RlpConverterService; @@ -332,7 +330,6 @@ public class BesuCommand implements DefaultCommandValues, Runnable { private final Map environment; private final MetricCategoryRegistryImpl metricCategoryRegistry = new MetricCategoryRegistryImpl(); - private final MetricCategoryConverter metricCategoryConverter = new MetricCategoryConverter(); private final PreSynchronizationTaskRunner preSynchronizationTaskRunner = new PreSynchronizationTaskRunner(); @@ -1136,10 +1133,6 @@ private void registerConverters() { commandLine.registerConverter(Hash.class, Hash::fromHexString); commandLine.registerConverter(Optional.class, Optional::of); commandLine.registerConverter(Double.class, Double::parseDouble); - - metricCategoryConverter.addCategories(BesuMetricCategory.class); - metricCategoryConverter.addCategories(StandardMetricCategory.class); - commandLine.registerConverter(MetricCategory.class, metricCategoryConverter); } private void handleStableOptions() { @@ -1174,6 +1167,9 @@ private void preparePlugins() { besuPluginContext.addService(PicoCLIOptions.class, new PicoCLIOptionsImpl(commandLine)); besuPluginContext.addService(SecurityModuleService.class, securityModuleService); besuPluginContext.addService(StorageService.class, storageService); + + metricCategoryRegistry.addCategories(BesuMetricCategory.class); + metricCategoryRegistry.addCategories(StandardMetricCategory.class); besuPluginContext.addService(MetricCategoryRegistry.class, metricCategoryRegistry); besuPluginContext.addService(PermissioningService.class, permissioningService); besuPluginContext.addService(PrivacyPluginService.class, privacyPluginService); @@ -1191,10 +1187,6 @@ private void preparePlugins() { rocksDBPlugin.register(besuPluginContext); new InMemoryStoragePlugin().register(besuPluginContext); - metricCategoryRegistry - .getMetricCategories() - .forEach(metricCategoryConverter::addRegistryCategory); - // register default security module securityModuleService.register( DEFAULT_SECURITY_MODULE, Suppliers.memoize(this::defaultSecurityModule)); @@ -1891,6 +1883,10 @@ public MetricsConfiguration metricsConfiguration() { "--metrics-push-interval", "--metrics-push-prometheus-job")); + metricsOptions.setMetricCategoryRegistry(metricCategoryRegistry); + + metricsOptions.validate(commandLine); + final MetricsConfiguration.Builder metricsConfigurationBuilder = metricsOptions.toDomainObject(); metricsConfigurationBuilder diff --git a/besu/src/main/java/org/hyperledger/besu/cli/converter/MetricCategoryConverter.java b/besu/src/main/java/org/hyperledger/besu/cli/converter/MetricCategoryConverter.java deleted file mode 100644 index 339da86b2d7..00000000000 --- a/besu/src/main/java/org/hyperledger/besu/cli/converter/MetricCategoryConverter.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * 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.cli.converter; - -import org.hyperledger.besu.plugin.services.metrics.MetricCategory; - -import java.util.EnumSet; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - -import com.google.common.annotations.VisibleForTesting; -import picocli.CommandLine; - -/** The Metric category converter for CLI options. */ -public class MetricCategoryConverter implements CommandLine.ITypeConverter { - - private final Map metricCategories = new HashMap<>(); - - /** Default Constructor. */ - public MetricCategoryConverter() {} - - @Override - public MetricCategory convert(final String value) { - final MetricCategory category = metricCategories.get(value); - if (category == null) { - throw new IllegalArgumentException("Unknown category: " + value); - } - return category; - } - - /** - * Add Metrics categories. - * - * @param the type parameter - * @param categoryEnum the category enum - */ - public & MetricCategory> void addCategories(final Class categoryEnum) { - EnumSet.allOf(categoryEnum) - .forEach(category -> metricCategories.put(category.name(), category)); - } - - /** - * Add registry category. - * - * @param metricCategory the metric category - */ - public void addRegistryCategory(final MetricCategory metricCategory) { - metricCategories.put(metricCategory.getName().toUpperCase(Locale.ROOT), metricCategory); - } - - /** - * Gets metric categories. - * - * @return the metric categories - */ - @VisibleForTesting - Map getMetricCategories() { - return metricCategories; - } -} diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/MetricsOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/stable/MetricsOptions.java index 4906cf538e4..beba20e29b5 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/MetricsOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/stable/MetricsOptions.java @@ -14,6 +14,8 @@ */ package org.hyperledger.besu.cli.options.stable; +import static com.google.common.base.Preconditions.checkState; +import static java.util.stream.Collectors.toUnmodifiableSet; import static org.hyperledger.besu.cli.DefaultCommandValues.MANDATORY_HOST_FORMAT_HELP; import static org.hyperledger.besu.cli.DefaultCommandValues.MANDATORY_INTEGER_FORMAT_HELP; import static org.hyperledger.besu.cli.DefaultCommandValues.MANDATORY_PORT_FORMAT_HELP; @@ -24,6 +26,7 @@ import org.hyperledger.besu.cli.options.CLIOptions; import org.hyperledger.besu.cli.util.CommandLineUtils; +import org.hyperledger.besu.metrics.MetricCategoryRegistryImpl; import org.hyperledger.besu.metrics.MetricsProtocol; import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; @@ -36,6 +39,7 @@ /** Command line options for configuring metrics. */ // TODO: implement CLIOption public class MetricsOptions implements CLIOptions { + private MetricCategoryRegistryImpl metricCategoryRegistry; /** * Returns a MetricsConfiguration.Builder because fields are often overridden from other domains, @@ -77,7 +81,10 @@ public static MetricsOptions fromConfiguration(final MetricsConfiguration config metricsOptions.metricsHost = config.getHost(); metricsOptions.metricsPort = config.getPort(); metricsOptions.metricsProtocol = config.getProtocol(); - metricsOptions.metricCategories = config.getMetricCategories(); + metricsOptions.metricCategories = + config.getMetricCategories().stream() + .map(MetricCategory::getName) + .collect(toUnmodifiableSet()); metricsOptions.metricsPrometheusJob = config.getPrometheusJob(); metricsOptions.isMetricsPushEnabled = config.isPushEnabled(); metricsOptions.metricsPushHost = config.getPushHost(); @@ -126,7 +133,8 @@ public List getCLIOptions() { arity = "1..*", description = "Comma separated list of categories to track metrics for (default: ${DEFAULT-VALUE})") - private Set metricCategories = DEFAULT_METRIC_CATEGORIES; + private Set metricCategories = + DEFAULT_METRIC_CATEGORIES.stream().map(MetricCategory::getName).collect(toUnmodifiableSet()); @CommandLine.Option( names = {"--metrics-push-enabled"}, @@ -216,7 +224,13 @@ public Integer getMetricsPort() { * @return the metric categories */ public Set getMetricCategories() { - return metricCategories; + checkState( + metricCategoryRegistry != null, "Set metricCategoryRegistry before calling this method"); + + final var list = + metricCategories.stream().map(metricCategoryRegistry::getMetricCategory).toList(); + + return Set.copyOf(list); } /** @@ -264,6 +278,33 @@ public String getMetricsPrometheusJob() { return metricsPrometheusJob; } + /** + * Perform final validation after all the options, and the metric category registry, have been set + * + * @param commandLine the command line + */ + public void validate(final CommandLine commandLine) { + checkState( + metricCategoryRegistry != null, "Set metricCategoryRegistry before calling this method"); + final var unknownCategories = + metricCategories.stream() + .filter(category -> !metricCategoryRegistry.containsMetricCategory(category)) + .toList(); + if (!unknownCategories.isEmpty()) { + throw new CommandLine.ParameterException( + commandLine, "--metrics-categories contains unknown categories: " + unknownCategories); + } + } + + /** + * Set the metric category registry in order to support verification and conversion + * + * @param metricCategoryRegistry the metric category registry + */ + public void setMetricCategoryRegistry(final MetricCategoryRegistryImpl metricCategoryRegistry) { + this.metricCategoryRegistry = metricCategoryRegistry; + } + @CommandLine.ArgGroup(validate = false) private final MetricsOptions.Unstable unstableOptions = new MetricsOptions.Unstable(); diff --git a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java index 019e8d83cd3..cf3c40860d3 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java @@ -40,6 +40,7 @@ import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; import org.hyperledger.besu.BesuInfo; import org.hyperledger.besu.cli.config.EthNetworkConfig; @@ -99,7 +100,6 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.io.TempDir; import org.mockito.ArgumentCaptor; -import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import picocli.CommandLine; @@ -566,7 +566,7 @@ public void genesisAndNetworkMustNotBeUsedTogether() throws Exception { parseCommand("--genesis-file", genesisFile.toString(), "--network", "mainnet"); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)) @@ -578,7 +578,7 @@ public void nonExistentGenesisGivesError() { final String nonExistentGenesis = "non-existent-genesis.json"; parseCommand("--genesis-file", nonExistentGenesis); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)).startsWith("Unable to load genesis file"); @@ -1177,7 +1177,7 @@ public void remoteConnectionsPercentageWithInvalidFormatMustFail() { parseCommand( "--remote-connections-limit-enabled", "--remote-connections-max-percentage", "invalid"); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)) .contains( @@ -1190,7 +1190,7 @@ public void remoteConnectionsPercentageWithOutOfRangeMustFail() { parseCommand( "--remote-connections-limit-enabled", "--remote-connections-max-percentage", "150"); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)) .contains( @@ -1225,7 +1225,7 @@ public void syncMode_full_requires_bonsaiLimitTrieLogsToBeDisabled() { @Test public void syncMode_invalid() { parseCommand("--sync-mode", "bogus"); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)) @@ -1275,7 +1275,7 @@ public void syncMode_snap_by_default() { public void helpShouldDisplayFastSyncOptions() { parseCommand("--help"); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).contains("--fast-sync-min-peers"); // whitelist is now a hidden option @@ -1335,7 +1335,7 @@ public void parsesValidSyncMinPeersOption() { public void parsesInvalidFastSyncMinPeersOptionWrongFormatShouldFail() { parseCommand("--sync-mode", "FAST", "--fast-sync-min-peers", "ten"); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)) .contains("Invalid value for option '--fast-sync-min-peers': 'ten' is not an int"); @@ -1358,7 +1358,7 @@ public void netRestrictParsedCorrectly() { public void netRestrictInvalidShouldFail() { final String subnet = "127.0.0.1/abc"; parseCommand("--net-restrict", subnet); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandErrorOutput.toString(UTF_8)) .contains("Invalid value for option '--net-restrict'"); } @@ -1382,7 +1382,7 @@ public void ethStatsContactOptionIsParsedCorrectly() { @Test public void ethStatsContactOptionCannotBeUsedWithoutEthStatsServerProvided() { parseCommand("--ethstats-contact", "besu-updated"); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)) .contains( @@ -1435,7 +1435,7 @@ public void bonsaiLimitTrieLogsDisabledWhenFullSyncEnabled() { public void parsesInvalidWhenFullSyncAndBonsaiLimitTrieLogsExplicitlyTrue() { parseCommand("--sync-mode=FULL", "--bonsai-limit-trie-logs-enabled=true"); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)) .contains( @@ -1467,7 +1467,7 @@ public void parsesInvalidBonsaiHistoricalBlockLimitOption() { parseCommand("--data-storage-format", "BONSAI", "--bonsai-maximum-back-layers-to-load", "ten"); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)) .contains( @@ -1501,7 +1501,7 @@ public void dnsUpdateEnabledOptionIsParsedCorrectly() { @Test public void dnsUpdateEnabledOptionCannotBeUsedWithoutDnsEnabled() { parseCommand("--Xdns-update-enabled", "true"); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)) .contains( @@ -1720,6 +1720,17 @@ public void metricsCategoryPropertyMustBeUsed() { assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); } + @Test + public void metricsUnknownCategoryRaiseError() { + parseCommand("--metrics-enabled", "--metrics-category", "UNKNOWN_CATEGORY"); + + verifyNoInteractions(mockRunnerBuilder); + + assertThat(commandOutput.toString(UTF_8)).isEmpty(); + assertThat(commandErrorOutput.toString(UTF_8)) + .startsWith("--metrics-categories contains unknown categories: [UNKNOWN_CATEGORY]"); + } + @Test public void metricsPushEnabledPropertyMustBeUsed() { parseCommand("--metrics-push-enabled"); @@ -1799,7 +1810,7 @@ public void metricsPrometheusJobMustBeUsed() { public void metricsAndMetricsPushMustNotBeUsedTogether() { parseCommand("--metrics-enabled", "--metrics-push-enabled"); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)) @@ -2023,7 +2034,7 @@ private void networkValuesCanBeOverridden(final String network) { public void fullCLIOptionsShown() { parseCommand("--help"); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).contains("--config-file"); assertThat(commandOutput.toString(UTF_8)).contains("--data-path"); diff --git a/besu/src/test/java/org/hyperledger/besu/cli/converter/MetricCategoryConverterTest.java b/besu/src/test/java/org/hyperledger/besu/cli/converter/MetricCategoryConverterTest.java deleted file mode 100644 index 8c78b7fecc2..00000000000 --- a/besu/src/test/java/org/hyperledger/besu/cli/converter/MetricCategoryConverterTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * 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.cli.converter; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.mockito.Mockito.when; - -import org.hyperledger.besu.plugin.services.metrics.MetricCategory; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -@ExtendWith(MockitoExtension.class) -public class MetricCategoryConverterTest { - - private MetricCategoryConverter metricCategoryConverter; - - @Mock MetricCategory metricCategory; - - @BeforeEach - public void setUp() { - metricCategoryConverter = new MetricCategoryConverter(); - } - - @Test - public void convertShouldFailIfValueNotRegistered() { - assertThatExceptionOfType(IllegalArgumentException.class) - .isThrownBy(() -> metricCategoryConverter.convert("notRegistered")); - } - - @Test - public void addRegistryCategoryShouldUppercaseInputValues() { - when(metricCategory.getName()).thenReturn("testcat"); - metricCategoryConverter.addRegistryCategory(metricCategory); - when(metricCategory.getName()).thenReturn("tesTCat2"); - metricCategoryConverter.addRegistryCategory(metricCategory); - - final boolean containsLowercase = - metricCategoryConverter.getMetricCategories().keySet().stream() - .anyMatch(testString -> testString.chars().anyMatch(Character::isLowerCase)); - - assertThat(containsLowercase).isFalse(); - assertThat(metricCategoryConverter.getMetricCategories().size()).isEqualTo(2); - assertThat(metricCategoryConverter.getMetricCategories().keySet()) - .containsExactlyInAnyOrder("TESTCAT", "TESTCAT2"); - } -} diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsOptionsTest.java index 992dcc437d4..7f35effb7d6 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsOptionsTest.java @@ -15,14 +15,26 @@ package org.hyperledger.besu.cli.options; import org.hyperledger.besu.cli.options.stable.MetricsOptions; +import org.hyperledger.besu.metrics.BesuMetricCategory; +import org.hyperledger.besu.metrics.MetricCategoryRegistryImpl; +import org.hyperledger.besu.metrics.StandardMetricCategory; import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) public class MetricsOptionsTest extends AbstractCLIOptionsTest { + private MetricCategoryRegistryImpl categoryRegistry; + + @BeforeEach + public void setUp() { + categoryRegistry = new MetricCategoryRegistryImpl(); + categoryRegistry.addCategories(BesuMetricCategory.class); + categoryRegistry.addCategories(StandardMetricCategory.class); + } @Override protected MetricsConfiguration.Builder createDefaultDomainObject() { @@ -39,7 +51,9 @@ protected MetricsConfiguration.Builder createCustomizedDomainObject() { @Override protected MetricsOptions optionsFromDomainObject( final MetricsConfiguration.Builder domainObject) { - return MetricsOptions.fromConfiguration(domainObject.build()); + final var options = MetricsOptions.fromConfiguration(domainObject.build()); + options.setMetricCategoryRegistry(categoryRegistry); + return options; } @Override diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImpl.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImpl.java index b0a31793bcc..b78bcf18a8b 100644 --- a/metrics/core/src/main/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImpl.java +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImpl.java @@ -17,28 +17,55 @@ import org.hyperledger.besu.plugin.services.metrics.MetricCategory; import org.hyperledger.besu.plugin.services.metrics.MetricCategoryRegistry; -import java.util.ArrayList; -import java.util.List; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; /** The Metric category registry implementation. */ public class MetricCategoryRegistryImpl implements MetricCategoryRegistry { - - private final List metricCategories = new ArrayList<>(); + private final Map metricCategories = new HashMap<>(); /** Default constructor */ public MetricCategoryRegistryImpl() {} /** - * Gets metric categories. + * Add Metrics categories. * - * @return the metric categories + * @param the type parameter + * @param categoryEnum the category enum */ - public List getMetricCategories() { - return metricCategories; + public & MetricCategory> void addCategories(final Class categoryEnum) { + EnumSet.allOf(categoryEnum).forEach(this::addMetricCategory); } + /** + * Add registry category. + * + * @param metricCategory the metric category + */ @Override - public void addMetricCategory(final MetricCategory newMetricCategory) { - metricCategories.add(newMetricCategory); + public void addMetricCategory(final MetricCategory metricCategory) { + metricCategories.put(metricCategory.getName().toUpperCase(Locale.ROOT), metricCategory); + } + + /** + * Return true if a category with that name is already registered + * + * @param name the category name + * @return true if a category with that name is already registered + */ + public boolean containsMetricCategory(final String name) { + return metricCategories.containsKey(name.toUpperCase(Locale.ROOT)); + } + + /** + * Return a metric category by name + * + * @param name the category name + * @return the metric category or null if not registered + */ + public MetricCategory getMetricCategory(final String name) { + return metricCategories.get(name.toUpperCase(Locale.ROOT)); } } From ba86ce1181a923a2ea04f18b61f488df4ebef5f5 Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Wed, 30 Oct 2024 18:12:10 +0100 Subject: [PATCH 02/56] Add a method to check if a metric category is enabled to the plugin API (#7832) Signed-off-by: Fabio Di Fabio --- CHANGELOG.md | 1 + .../org/hyperledger/besu/cli/BesuCommand.java | 4 +- .../besu/cli/options/MetricsOptionsTest.java | 5 ++ .../metrics/MetricCategoryRegistryImpl.java | 22 +++++++ .../MetricCategoryRegistryImplTest.java | 66 +++++++++++++++++++ plugin-api/build.gradle | 2 +- .../metrics/MetricCategoryRegistry.java | 10 ++- 7 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 metrics/core/src/test/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImplTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b20bc15aea..26342cf7be5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - Create and publish Besu BOM (Bill of Materials) [#7615](https://github.com/hyperledger/besu/pull/7615) - Update Java dependencies [#7786](https://github.com/hyperledger/besu/pull/7786) - Add a method to get all the transaction in the pool, to the `TransactionPoolService`, to easily access the transaction pool content from plugins [#7813](https://github.com/hyperledger/besu/pull/7813) +- Add a method to check if a metric category is enabled to the plugin API [#7832](https://github.com/hyperledger/besu/pull/7832) ### Bug fixes - Fix registering new metric categories from plugins [#7825](https://github.com/hyperledger/besu/pull/7825) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index 45feaf10052..bf79da288da 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -1899,7 +1899,9 @@ public MetricsConfiguration metricsConfiguration() { ? p2PDiscoveryOptions.autoDiscoverDefaultIP().getHostAddress() : metricsOptions.getMetricsPushHost()) .hostsAllowlist(hostsAllowlist); - return metricsConfigurationBuilder.build(); + final var metricsConfiguration = metricsConfigurationBuilder.build(); + metricCategoryRegistry.setMetricsConfiguration(metricsConfiguration); + return metricsConfiguration; } private PrivacyParameters privacyParameters() { diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsOptionsTest.java index 7f35effb7d6..cd541759ad8 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsOptionsTest.java @@ -60,4 +60,9 @@ protected MetricsOptions optionsFromDomainObject( protected MetricsOptions getOptionsFromBesuCommand(final TestBesuCommand besuCommand) { return besuCommand.getMetricsOptions(); } + + @Override + protected String[] getNonOptionFields() { + return new String[] {"metricCategoryRegistry"}; + } } diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImpl.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImpl.java index b78bcf18a8b..6596268acb7 100644 --- a/metrics/core/src/main/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImpl.java +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImpl.java @@ -14,6 +14,9 @@ */ package org.hyperledger.besu.metrics; +import static com.google.common.base.Preconditions.checkNotNull; + +import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; import org.hyperledger.besu.plugin.services.metrics.MetricCategoryRegistry; @@ -25,6 +28,7 @@ /** The Metric category registry implementation. */ public class MetricCategoryRegistryImpl implements MetricCategoryRegistry { private final Map metricCategories = new HashMap<>(); + private MetricsConfiguration metricsConfiguration; /** Default constructor */ public MetricCategoryRegistryImpl() {} @@ -49,6 +53,14 @@ public void addMetricCategory(final MetricCategory metricCategory) { metricCategories.put(metricCategory.getName().toUpperCase(Locale.ROOT), metricCategory); } + @Override + public boolean isMetricCategoryEnabled(final MetricCategory metricCategory) { + checkNotNull( + metricsConfiguration, "Metrics configuration must be set before calling this method"); + return (metricsConfiguration.isEnabled() || metricsConfiguration.isPushEnabled()) + && metricsConfiguration.getMetricCategories().contains(metricCategory); + } + /** * Return true if a category with that name is already registered * @@ -68,4 +80,14 @@ public boolean containsMetricCategory(final String name) { public MetricCategory getMetricCategory(final String name) { return metricCategories.get(name.toUpperCase(Locale.ROOT)); } + + /** + * Set the metric configuration via a method since it is still not available when creating this + * object + * + * @param metricsConfiguration the metrics configuration + */ + public void setMetricsConfiguration(final MetricsConfiguration metricsConfiguration) { + this.metricsConfiguration = metricsConfiguration; + } } diff --git a/metrics/core/src/test/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImplTest.java b/metrics/core/src/test/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImplTest.java new file mode 100644 index 00000000000..b2da02f480b --- /dev/null +++ b/metrics/core/src/test/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImplTest.java @@ -0,0 +1,66 @@ +/* + * Copyright contributors to 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.metrics; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; + +import java.util.Set; + +import org.junit.jupiter.api.Test; + +class MetricCategoryRegistryImplTest { + + @Test + void metricCategoryIsEnabledAndMetricsAreEnabled() { + final var registry = new MetricCategoryRegistryImpl(); + registry.addMetricCategory(BesuMetricCategory.BLOCKCHAIN); + final var metricsConfiguration = + MetricsConfiguration.builder() + .enabled(true) + .metricCategories(Set.of(BesuMetricCategory.BLOCKCHAIN)) + .build(); + registry.setMetricsConfiguration(metricsConfiguration); + assertTrue(registry.isMetricCategoryEnabled(BesuMetricCategory.BLOCKCHAIN)); + } + + @Test + void metricCategoryIsDisabledAndMetricsAreEnabled() { + final var registry = new MetricCategoryRegistryImpl(); + registry.addMetricCategory(BesuMetricCategory.ETHEREUM); + final var metricsConfiguration = + MetricsConfiguration.builder() + .enabled(true) + .metricCategories(Set.of(BesuMetricCategory.ETHEREUM)) + .build(); + registry.setMetricsConfiguration(metricsConfiguration); + assertFalse(registry.isMetricCategoryEnabled(BesuMetricCategory.BLOCKCHAIN)); + } + + @Test + void metricCategoryNotEnabledWhenMetricsAreDisabled() { + final var registry = new MetricCategoryRegistryImpl(); + registry.addMetricCategory(BesuMetricCategory.BLOCKCHAIN); + final var metricsConfiguration = + MetricsConfiguration.builder() + .enabled(false) + .metricCategories(Set.of(BesuMetricCategory.BLOCKCHAIN)) + .build(); + registry.setMetricsConfiguration(metricsConfiguration); + assertFalse(registry.isMetricCategoryEnabled(BesuMetricCategory.BLOCKCHAIN)); + } +} diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 3632bb5ae1a..c7ec6728674 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -71,7 +71,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'uNQzVjMa7m1fw3d10NuVOjmzGxmCkgZd88yGFgP3qoY=' + knownHash = '8rPIE3fYl48RPRQXxYhMk559e/r+wHSKU9bGSJmruKQ=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/MetricCategoryRegistry.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/MetricCategoryRegistry.java index d6e460aa2f6..1f84953460f 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/MetricCategoryRegistry.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/MetricCategoryRegistry.java @@ -29,5 +29,13 @@ public interface MetricCategoryRegistry extends BesuService { * * @param newMetricCategory The {@link MetricCategory} that is being registered. */ - public void addMetricCategory(final MetricCategory newMetricCategory); + void addMetricCategory(final MetricCategory newMetricCategory); + + /** + * Return true if the metrics are enabled and the metric category is enabled + * + * @param metricCategory the metric category + * @return true if the metrics are enabled and the metric category is enabled + */ + boolean isMetricCategoryEnabled(final MetricCategory metricCategory); } From f9f721c10e839c0e6e72dedfc2295074a0c052a9 Mon Sep 17 00:00:00 2001 From: Ade Lucas <37906710+cloudspores@users.noreply.github.com> Date: Wed, 30 Oct 2024 15:26:54 -0400 Subject: [PATCH 03/56] Issue 5589 trigger a timeout (#7469) * Make timeout feature use vertx timer. * Handle all errors resulting from timeout. * Ensure that after the timeout occurs, we properly handle the response and don't allow the execution to continue. --------- Signed-off-by: Ade Lucas Signed-off-by: cloudspores Co-authored-by: Ade Lucas Co-authored-by: Ade Lucas Co-authored-by: Justin Florentine --- .../api/handlers/AbstractJsonRpcExecutor.java | 1 + .../api/handlers/JsonRpcExecutorHandler.java | 44 ++++++- .../handlers/JsonRpcExecutorHandlerTest.java | 110 ++++++++++++++++++ 3 files changed, 151 insertions(+), 4 deletions(-) create mode 100644 ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/handlers/JsonRpcExecutorHandlerTest.java diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/handlers/AbstractJsonRpcExecutor.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/handlers/AbstractJsonRpcExecutor.java index 95dc88f6a5d..f73d162fa14 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/handlers/AbstractJsonRpcExecutor.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/handlers/AbstractJsonRpcExecutor.java @@ -106,6 +106,7 @@ protected static void handleJsonRpcError( private static HttpResponseStatus statusCodeFromError(final RpcErrorType error) { return switch (error) { case INVALID_REQUEST, PARSE_ERROR -> HttpResponseStatus.BAD_REQUEST; + case TIMEOUT_ERROR -> HttpResponseStatus.REQUEST_TIMEOUT; default -> HttpResponseStatus.OK; }; } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/handlers/JsonRpcExecutorHandler.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/handlers/JsonRpcExecutorHandler.java index 278a38c5578..83866316959 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/handlers/JsonRpcExecutorHandler.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/handlers/JsonRpcExecutorHandler.java @@ -34,6 +34,9 @@ public class JsonRpcExecutorHandler { private static final Logger LOG = LoggerFactory.getLogger(JsonRpcExecutorHandler.class); + // Default timeout for RPC calls in seconds + private static final long DEFAULT_TIMEOUT_MILLISECONDS = 30_000L; + private JsonRpcExecutorHandler() {} public static Handler handler( @@ -49,6 +52,19 @@ public static Handler handler( final Tracer tracer, final JsonRpcConfiguration jsonRpcConfiguration) { return ctx -> { + final long timerId = + ctx.vertx() + .setTimer( + DEFAULT_TIMEOUT_MILLISECONDS, + id -> { + final String method = + ctx.get(ContextKey.REQUEST_BODY_AS_JSON_OBJECT.name()).toString(); + LOG.error("Timeout occurred in JSON-RPC executor for method {}", method); + handleErrorAndEndResponse(ctx, null, RpcErrorType.TIMEOUT_ERROR); + }); + + ctx.put("timerId", timerId); + try { createExecutor(jsonRpcExecutor, tracer, ctx, jsonRpcConfiguration) .ifPresentOrElse( @@ -58,18 +74,38 @@ public static Handler handler( } catch (IOException e) { final String method = executor.getRpcMethodName(ctx); LOG.error("{} - Error streaming JSON-RPC response", method, e); - handleJsonRpcError(ctx, null, RpcErrorType.INTERNAL_ERROR); + handleErrorAndEndResponse(ctx, null, RpcErrorType.INTERNAL_ERROR); + } finally { + cancelTimer(ctx); } }, - () -> handleJsonRpcError(ctx, null, RpcErrorType.PARSE_ERROR)); + () -> { + handleErrorAndEndResponse(ctx, null, RpcErrorType.PARSE_ERROR); + cancelTimer(ctx); + }); } catch (final RuntimeException e) { - final String method = ctx.get(ContextKey.REQUEST_BODY_AS_JSON_OBJECT.name()); + final String method = ctx.get(ContextKey.REQUEST_BODY_AS_JSON_OBJECT.name()).toString(); LOG.error("Unhandled exception in JSON-RPC executor for method {}", method, e); - handleJsonRpcError(ctx, null, RpcErrorType.INTERNAL_ERROR); + handleErrorAndEndResponse(ctx, null, RpcErrorType.INTERNAL_ERROR); + cancelTimer(ctx); } }; } + private static void cancelTimer(final RoutingContext ctx) { + Long timerId = ctx.get("timerId"); + if (timerId != null) { + ctx.vertx().cancelTimer(timerId); + } + } + + private static void handleErrorAndEndResponse( + final RoutingContext ctx, final Object id, final RpcErrorType errorType) { + if (!ctx.response().ended()) { + handleJsonRpcError(ctx, id, errorType); + } + } + private static Optional createExecutor( final JsonRpcExecutor jsonRpcExecutor, final Tracer tracer, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/handlers/JsonRpcExecutorHandlerTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/handlers/JsonRpcExecutorHandlerTest.java new file mode 100644 index 00000000000..ee00e433b2f --- /dev/null +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/handlers/JsonRpcExecutorHandlerTest.java @@ -0,0 +1,110 @@ +/* + * 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.ethereum.api.handlers; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.contains; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration; +import org.hyperledger.besu.ethereum.api.jsonrpc.context.ContextKey; +import org.hyperledger.besu.ethereum.api.jsonrpc.execution.JsonRpcExecutor; + +import io.netty.handler.codec.http.HttpResponseStatus; +import io.opentelemetry.api.trace.Tracer; +import io.vertx.core.Handler; +import io.vertx.core.Vertx; +import io.vertx.core.http.HttpServerResponse; +import io.vertx.ext.web.RoutingContext; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +class JsonRpcExecutorHandlerTest { + + private JsonRpcExecutor mockExecutor; + private Tracer mockTracer; + private JsonRpcConfiguration mockConfig; + private RoutingContext mockContext; + private Vertx mockVertx; + private HttpServerResponse mockResponse; + + @BeforeEach + void setUp() { + mockExecutor = mock(JsonRpcExecutor.class); + mockTracer = mock(Tracer.class); + mockConfig = mock(JsonRpcConfiguration.class); + mockContext = mock(RoutingContext.class); + mockVertx = mock(Vertx.class); + mockResponse = mock(HttpServerResponse.class); + + when(mockContext.vertx()).thenReturn(mockVertx); + when(mockContext.response()).thenReturn(mockResponse); + when(mockResponse.ended()).thenReturn(false); + when(mockResponse.setStatusCode(anyInt())).thenReturn(mockResponse); + } + + @Test + void testTimeoutHandling() { + // Arrange + Handler handler = + JsonRpcExecutorHandler.handler(mockExecutor, mockTracer, mockConfig); + ArgumentCaptor delayCaptor = ArgumentCaptor.forClass(Long.class); + @SuppressWarnings("unchecked") + ArgumentCaptor> timerHandlerCaptor = ArgumentCaptor.forClass(Handler.class); + + when(mockContext.get(eq(ContextKey.REQUEST_BODY_AS_JSON_OBJECT.name()))).thenReturn("{}"); + when(mockVertx.setTimer(delayCaptor.capture(), timerHandlerCaptor.capture())).thenReturn(1L); + when(mockContext.get("timerId")).thenReturn(1L); + + // Act + handler.handle(mockContext); + + // Assert + verify(mockVertx).setTimer(eq(30000L), any()); + + // Simulate timeout + timerHandlerCaptor.getValue().handle(1L); + + // Verify timeout handling + verify(mockResponse, times(1)) + .setStatusCode(eq(HttpResponseStatus.REQUEST_TIMEOUT.code())); // Expect 408 Request Timeout + verify(mockResponse, times(1)).end(contains("Timeout expired")); + verify(mockVertx, times(1)).cancelTimer(1L); + } + + @Test + void testCancelTimerOnSuccessfulExecution() { + // Arrange + Handler handler = + JsonRpcExecutorHandler.handler(mockExecutor, mockTracer, mockConfig); + when(mockContext.get(eq(ContextKey.REQUEST_BODY_AS_JSON_OBJECT.name()))).thenReturn("{}"); + when(mockVertx.setTimer(anyLong(), any())).thenReturn(1L); + when(mockContext.get("timerId")).thenReturn(1L); + + // Act + handler.handle(mockContext); + + // Assert + verify(mockVertx).setTimer(anyLong(), any()); + verify(mockVertx).cancelTimer(1L); + } +} From db29df7c8d686a3bcb13b16dc21a218cea87b247 Mon Sep 17 00:00:00 2001 From: Matilda-Clerke Date: Thu, 31 Oct 2024 09:29:46 +1100 Subject: [PATCH 04/56] 7311: add GetReceiptsFromPeerTask (#7638) Signed-off-by: Matilda Clerke --- .../controller/BesuControllerBuilder.java | 8 + .../TransitionBesuControllerBuilder.java | 3 + .../java/org/hyperledger/besu/RunnerTest.java | 30 +- .../jsonrpc/execution/JsonRpcExecutor.java | 4 +- .../eth/manager/EthProtocolManager.java | 1 - .../ethereum/eth/manager/EthScheduler.java | 15 +- .../eth/manager/peertask/PeerTask.java | 4 +- .../manager/peertask/PeerTaskExecutor.java | 2 +- .../task/GetReceiptsFromPeerTask.java | 135 +++++++++ .../eth/sync/DefaultSynchronizer.java | 5 + .../CheckpointDownloadBlockStep.java | 73 ++++- .../CheckpointDownloaderFactory.java | 4 + .../checkpointsync/CheckpointSyncActions.java | 4 + .../CheckpointSyncChainDownloader.java | 10 +- ...CheckpointSyncDownloadPipelineFactory.java | 14 +- .../sync/fastsync/DownloadReceiptsStep.java | 80 +++++- .../eth/sync/fastsync/FastSyncActions.java | 5 + .../fastsync/FastSyncChainDownloader.java | 10 +- .../FastSyncDownloadPipelineFactory.java | 7 +- .../worldstate/FastDownloaderFactory.java | 3 + .../sync/snapsync/SnapDownloaderFactory.java | 3 + .../peertask/PeerTaskExecutorTest.java | 12 +- .../task/GetReceiptsFromPeerTaskTest.java | 264 ++++++++++++++++++ .../CheckPointSyncChainDownloaderTest.java | 137 ++++++++- .../fastsync/DownloadReceiptsStepTest.java | 73 ++++- .../fastsync/FastDownloaderFactoryTest.java | 7 + .../sync/fastsync/FastSyncActionsTest.java | 2 + .../fastsync/FastSyncChainDownloaderTest.java | 2 + 28 files changed, 864 insertions(+), 53 deletions(-) create mode 100644 ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTask.java create mode 100644 ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTaskTest.java diff --git a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java index a26bcb9811a..6a4cc203a3b 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java @@ -55,6 +55,8 @@ import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.MergePeerFilter; import org.hyperledger.besu.ethereum.eth.manager.MonitoredExecutors; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskRequestSender; import org.hyperledger.besu.ethereum.eth.manager.snap.SnapProtocolManager; import org.hyperledger.besu.ethereum.eth.peervalidation.CheckpointBlocksPeerValidator; import org.hyperledger.besu.ethereum.eth.peervalidation.ClassicForkPeerValidator; @@ -653,6 +655,8 @@ public BesuController build() { } final EthContext ethContext = new EthContext(ethPeers, ethMessages, snapMessages, scheduler); + final PeerTaskExecutor peerTaskExecutor = + new PeerTaskExecutor(ethPeers, new PeerTaskRequestSender(), metricsSystem); final boolean fullSyncDisabled = !SyncMode.isFullSync(syncConfig.getSyncMode()); final SyncState syncState = new SyncState(blockchain, ethPeers, fullSyncDisabled, checkpoint); @@ -704,6 +708,7 @@ public BesuController build() { worldStateStorageCoordinator, protocolContext, ethContext, + peerTaskExecutor, syncState, ethProtocolManager, pivotBlockSelector); @@ -830,6 +835,7 @@ private TrieLogPruner createTrieLogPruner( * @param worldStateStorageCoordinator the world state storage * @param protocolContext the protocol context * @param ethContext the eth context + * @param peerTaskExecutor the PeerTaskExecutor * @param syncState the sync state * @param ethProtocolManager the eth protocol manager * @param pivotBlockSelector the pivot block selector @@ -840,6 +846,7 @@ protected DefaultSynchronizer createSynchronizer( final WorldStateStorageCoordinator worldStateStorageCoordinator, final ProtocolContext protocolContext, final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, final SyncState syncState, final EthProtocolManager ethProtocolManager, final PivotBlockSelector pivotBlockSelector) { @@ -851,6 +858,7 @@ protected DefaultSynchronizer createSynchronizer( worldStateStorageCoordinator, ethProtocolManager.getBlockBroadcaster(), ethContext, + peerTaskExecutor, syncState, dataDirectory, storageProvider, diff --git a/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java index ee2611d9c87..703592f90a9 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java @@ -40,6 +40,7 @@ import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.MergePeerFilter; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidator; import org.hyperledger.besu.ethereum.eth.sync.DefaultSynchronizer; import org.hyperledger.besu.ethereum.eth.sync.PivotBlockSelector; @@ -225,6 +226,7 @@ protected DefaultSynchronizer createSynchronizer( final WorldStateStorageCoordinator worldStateStorageCoordinator, final ProtocolContext protocolContext, final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, final SyncState syncState, final EthProtocolManager ethProtocolManager, final PivotBlockSelector pivotBlockSelector) { @@ -235,6 +237,7 @@ protected DefaultSynchronizer createSynchronizer( worldStateStorageCoordinator, protocolContext, ethContext, + peerTaskExecutor, syncState, ethProtocolManager, pivotBlockSelector); diff --git a/besu/src/test/java/org/hyperledger/besu/RunnerTest.java b/besu/src/test/java/org/hyperledger/besu/RunnerTest.java index cbbf9804084..6324fabb743 100644 --- a/besu/src/test/java/org/hyperledger/besu/RunnerTest.java +++ b/besu/src/test/java/org/hyperledger/besu/RunnerTest.java @@ -153,7 +153,15 @@ public void fullSyncFromGenesis() throws Exception { // set merge flag to false, otherwise this test can fail if a merge test runs first MergeConfiguration.setMergeEnabled(false); - syncFromGenesis(SyncMode.FULL, getFastSyncGenesis()); + syncFromGenesis(SyncMode.FULL, getFastSyncGenesis(), false); + } + + @Test + public void fullSyncFromGenesisUsingPeerTaskSystem() throws Exception { + // set merge flag to false, otherwise this test can fail if a merge test runs first + MergeConfiguration.setMergeEnabled(false); + + syncFromGenesis(SyncMode.FULL, getFastSyncGenesis(), true); } @Test @@ -161,10 +169,21 @@ public void fastSyncFromGenesis() throws Exception { // set merge flag to false, otherwise this test can fail if a merge test runs first MergeConfiguration.setMergeEnabled(false); - syncFromGenesis(SyncMode.FAST, getFastSyncGenesis()); + syncFromGenesis(SyncMode.FAST, getFastSyncGenesis(), false); + } + + @Test + public void fastSyncFromGenesisUsingPeerTaskSystem() throws Exception { + // set merge flag to false, otherwise this test can fail if a merge test runs first + MergeConfiguration.setMergeEnabled(false); + + syncFromGenesis(SyncMode.FAST, getFastSyncGenesis(), true); } - private void syncFromGenesis(final SyncMode mode, final GenesisConfigFile genesisConfig) + private void syncFromGenesis( + final SyncMode mode, + final GenesisConfigFile genesisConfig, + final boolean isPeerTaskSystemEnabled) throws Exception { final Path dataDirAhead = Files.createTempDirectory(temp, "db-ahead"); final Path dbAhead = dataDirAhead.resolve("database"); @@ -172,7 +191,10 @@ private void syncFromGenesis(final SyncMode mode, final GenesisConfigFile genesi final NodeKey aheadDbNodeKey = NodeKeyUtils.createFrom(KeyPairUtil.loadKeyPair(dataDirAhead)); final NodeKey behindDbNodeKey = NodeKeyUtils.generate(); final SynchronizerConfiguration syncConfigAhead = - SynchronizerConfiguration.builder().syncMode(SyncMode.FULL).build(); + SynchronizerConfiguration.builder() + .syncMode(SyncMode.FULL) + .isPeerTaskSystemEnabled(isPeerTaskSystemEnabled) + .build(); final ObservableMetricsSystem noOpMetricsSystem = new NoOpMetricsSystem(); final var miningParameters = MiningParameters.newDefault(); final var dataStorageConfiguration = DataStorageConfiguration.DEFAULT_FOREST_CONFIG; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/execution/JsonRpcExecutor.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/execution/JsonRpcExecutor.java index 6fedcc70ca4..b8786eb7a5d 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/execution/JsonRpcExecutor.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/execution/JsonRpcExecutor.java @@ -104,9 +104,9 @@ public JsonRpcResponse execute( private Optional validateMethodAvailability(final JsonRpcRequest request) { final String name = request.getMethod(); - if (LOG.isDebugEnabled()) { + if (LOG.isTraceEnabled()) { final JsonArray params = JsonObject.mapFrom(request).getJsonArray("params"); - LOG.debug("JSON-RPC request -> {} {}", name, params); + LOG.trace("JSON-RPC request -> {} {}", name, params); } final JsonRpcMethod method = rpcMethods.get(name); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java index 58318f9611e..30cd03c15c3 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java @@ -337,7 +337,6 @@ public void processMessage(final Capability cap, final Message message) { public void handleNewConnection(final PeerConnection connection) { ethPeers.registerNewConnection(connection, peerValidators); final EthPeer peer = ethPeers.peer(connection); - final Capability cap = connection.capability(getSupportedProtocol()); final ForkId latestForkId = cap.getVersion() >= 64 ? forkIdManager.getForkIdForChainHead() : null; diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthScheduler.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthScheduler.java index 1e2f3eb6abb..8c90993c689 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthScheduler.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthScheduler.java @@ -145,7 +145,7 @@ public void executeServiceTask(final Runnable command) { servicesExecutor.execute(command); } - public CompletableFuture scheduleServiceTask(final Runnable task) { + public CompletableFuture scheduleServiceTask(final Runnable task) { return CompletableFuture.runAsync(task, servicesExecutor); } @@ -156,6 +156,19 @@ public CompletableFuture scheduleServiceTask(final EthTask task) { return serviceFuture; } + public CompletableFuture scheduleServiceTask(final Supplier> future) { + final CompletableFuture promise = new CompletableFuture<>(); + final Future workerFuture = servicesExecutor.submit(() -> propagateResult(future, promise)); + // If returned promise is cancelled, cancel the worker future + promise.whenComplete( + (r, t) -> { + if (t instanceof CancellationException) { + workerFuture.cancel(false); + } + }); + return promise; + } + public CompletableFuture startPipeline(final Pipeline pipeline) { final CompletableFuture pipelineFuture = pipeline.start(servicesExecutor); pendingFutures.add(pipelineFuture); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTask.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTask.java index 1243846ac3d..fed671d38d2 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTask.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTask.java @@ -41,13 +41,13 @@ public interface PeerTask { MessageData getRequestMessage(); /** - * Parses the MessageData response from the EthPeer + * Parses and processes the MessageData response from the EthPeer * * @param messageData the response MessageData to be parsed * @return a T built from the response MessageData * @throws InvalidPeerTaskResponseException if the response messageData is invalid */ - T parseResponse(MessageData messageData) throws InvalidPeerTaskResponseException; + T processResponse(MessageData messageData) throws InvalidPeerTaskResponseException; /** * Gets the number of times this task may be attempted against other peers diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutor.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutor.java index 984cedccecb..a2ae0455263 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutor.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutor.java @@ -133,7 +133,7 @@ public PeerTaskExecutorResult executeAgainstPeer( MessageData responseMessageData = requestSender.sendRequest(peerTask.getSubProtocol(), requestMessageData, peer); - result = peerTask.parseResponse(responseMessageData); + result = peerTask.processResponse(responseMessageData); } finally { inflightRequestCountForThisTaskClass.decrementAndGet(); } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTask.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTask.java new file mode 100644 index 00000000000..7d4b5d585e5 --- /dev/null +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTask.java @@ -0,0 +1,135 @@ +/* + * 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.ethereum.eth.manager.peertask.task; + +import static java.util.Collections.emptyList; + +import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.core.TransactionReceipt; +import org.hyperledger.besu.ethereum.eth.EthProtocol; +import org.hyperledger.besu.ethereum.eth.manager.EthPeer; +import org.hyperledger.besu.ethereum.eth.manager.peertask.InvalidPeerTaskResponseException; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTask; +import org.hyperledger.besu.ethereum.eth.messages.GetReceiptsMessage; +import org.hyperledger.besu.ethereum.eth.messages.ReceiptsMessage; +import org.hyperledger.besu.ethereum.mainnet.BodyValidation; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; +import org.hyperledger.besu.ethereum.p2p.rlpx.wire.SubProtocol; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Predicate; + +public class GetReceiptsFromPeerTask + implements PeerTask>> { + + private final Collection blockHeaders; + private final ProtocolSchedule protocolSchedule; + private final Map> receiptsByBlockHeader = new HashMap<>(); + private final Map> headersByReceiptsRoot = new HashMap<>(); + private final long requiredBlockchainHeight; + + public GetReceiptsFromPeerTask( + final Collection blockHeaders, final ProtocolSchedule protocolSchedule) { + this.blockHeaders = new ArrayList<>(blockHeaders); + this.protocolSchedule = protocolSchedule; + + // pre-fill any headers with an empty receipts root into the result map + this.blockHeaders.stream() + .filter(header -> header.getReceiptsRoot().equals(Hash.EMPTY_TRIE_HASH)) + .forEach(header -> receiptsByBlockHeader.put(header, emptyList())); + this.blockHeaders.removeAll(receiptsByBlockHeader.keySet()); + + // group headers by their receipts root hash to reduce total number of receipts hashes requested + // for + this.blockHeaders.forEach( + header -> + headersByReceiptsRoot + .computeIfAbsent(header.getReceiptsRoot(), key -> new ArrayList<>()) + .add(header)); + + // calculate the minimum required blockchain height a peer will need to be able to fulfil this + // request + requiredBlockchainHeight = + this.blockHeaders.stream() + .mapToLong(BlockHeader::getNumber) + .max() + .orElse(BlockHeader.GENESIS_BLOCK_NUMBER); + } + + @Override + public SubProtocol getSubProtocol() { + return EthProtocol.get(); + } + + @Override + public MessageData getRequestMessage() { + // Since we have to match up the data by receipt root, we only need to request receipts + // for one of the headers with each unique receipt root. + final List blockHashes = + headersByReceiptsRoot.values().stream() + .map(headers -> headers.getFirst().getHash()) + .toList(); + return GetReceiptsMessage.create(blockHashes); + } + + @Override + public Map> processResponse(final MessageData messageData) + throws InvalidPeerTaskResponseException { + if (messageData == null) { + throw new InvalidPeerTaskResponseException(); + } + final ReceiptsMessage receiptsMessage = ReceiptsMessage.readFrom(messageData); + final List> receiptsByBlock = receiptsMessage.receipts(); + // take a copy of the pre-filled receiptsByBlockHeader, to ensure idempotency of subsequent + // calls to processResponse + final Map> receiptsByHeader = + new HashMap<>(receiptsByBlockHeader); + if (!blockHeaders.isEmpty()) { + if (receiptsByBlock.isEmpty() || receiptsByBlock.size() > blockHeaders.size()) { + throw new InvalidPeerTaskResponseException(); + } + + for (final List receiptsInBlock : receiptsByBlock) { + final List blockHeaders = + headersByReceiptsRoot.get(BodyValidation.receiptsRoot(receiptsInBlock)); + if (blockHeaders == null) { + // Contains receipts that we didn't request, so mustn't be the response we're looking for. + throw new InvalidPeerTaskResponseException(); + } + blockHeaders.forEach(header -> receiptsByHeader.put(header, receiptsInBlock)); + } + } + return receiptsByHeader; + } + + @Override + public Predicate getPeerRequirementFilter() { + return (ethPeer) -> + ethPeer.getProtocolName().equals(getSubProtocol().getName()) + && (protocolSchedule.anyMatch((ps) -> ps.spec().isPoS()) + || ethPeer.chainState().getEstimatedHeight() >= requiredBlockchainHeight); + } + + @Override + public boolean isSuccess(final Map> result) { + return !result.isEmpty(); + } +} diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java index 23844372999..66684ab7873 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java @@ -22,6 +22,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.manager.EthContext; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.sync.checkpointsync.CheckpointDownloaderFactory; import org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncDownloader; import org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncState; @@ -82,6 +83,7 @@ public DefaultSynchronizer( final WorldStateStorageCoordinator worldStateStorageCoordinator, final BlockBroadcaster blockBroadcaster, final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, final SyncState syncState, final Path dataDirectory, final StorageProvider storageProvider, @@ -147,6 +149,7 @@ public DefaultSynchronizer( protocolContext, metricsSystem, ethContext, + peerTaskExecutor, worldStateStorageCoordinator, syncState, clock, @@ -163,6 +166,7 @@ public DefaultSynchronizer( protocolContext, metricsSystem, ethContext, + peerTaskExecutor, worldStateStorageCoordinator, syncState, clock, @@ -179,6 +183,7 @@ public DefaultSynchronizer( protocolContext, metricsSystem, ethContext, + peerTaskExecutor, worldStateStorageCoordinator, syncState, clock, diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointDownloadBlockStep.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointDownloadBlockStep.java index b4bdf585410..72f1fae764f 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointDownloadBlockStep.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointDownloadBlockStep.java @@ -16,17 +16,23 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.core.Block; +import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockWithReceipts; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthContext; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResponseCode; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResult; +import org.hyperledger.besu.ethereum.eth.manager.peertask.task.GetReceiptsFromPeerTask; import org.hyperledger.besu.ethereum.eth.manager.task.AbstractPeerTask.PeerTaskResult; import org.hyperledger.besu.ethereum.eth.manager.task.GetBlockFromPeerTask; -import org.hyperledger.besu.ethereum.eth.manager.task.GetReceiptsFromPeerTask; +import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; import org.hyperledger.besu.ethereum.eth.sync.fastsync.checkpoint.Checkpoint; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.plugin.services.MetricsSystem; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.concurrent.CompletableFuture; @@ -34,17 +40,23 @@ public class CheckpointDownloadBlockStep { private final ProtocolSchedule protocolSchedule; private final EthContext ethContext; + private final PeerTaskExecutor peerTaskExecutor; private final Checkpoint checkpoint; + private final SynchronizerConfiguration synchronizerConfiguration; private final MetricsSystem metricsSystem; public CheckpointDownloadBlockStep( final ProtocolSchedule protocolSchedule, final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, final Checkpoint checkpoint, + final SynchronizerConfiguration synchronizerConfiguration, final MetricsSystem metricsSystem) { this.protocolSchedule = protocolSchedule; this.ethContext = ethContext; + this.peerTaskExecutor = peerTaskExecutor; this.checkpoint = checkpoint; + this.synchronizerConfiguration = synchronizerConfiguration; this.metricsSystem = metricsSystem; } @@ -65,17 +77,52 @@ public CompletableFuture> downloadBlock(final Hash h private CompletableFuture> downloadReceipts( final PeerTaskResult peerTaskResult) { final Block block = peerTaskResult.getResult(); - final GetReceiptsFromPeerTask getReceiptsFromPeerTask = - GetReceiptsFromPeerTask.forHeaders(ethContext, List.of(block.getHeader()), metricsSystem); - return getReceiptsFromPeerTask - .run() - .thenCompose( - receiptTaskResult -> { - final Optional> transactionReceipts = - Optional.ofNullable(receiptTaskResult.getResult().get(block.getHeader())); - return CompletableFuture.completedFuture( - transactionReceipts.map(receipts -> new BlockWithReceipts(block, receipts))); - }) - .exceptionally(throwable -> Optional.empty()); + if (synchronizerConfiguration.isPeerTaskSystemEnabled()) { + return ethContext + .getScheduler() + .scheduleServiceTask( + () -> { + GetReceiptsFromPeerTask task = + new GetReceiptsFromPeerTask(List.of(block.getHeader()), protocolSchedule); + PeerTaskExecutorResult>> executorResult = + peerTaskExecutor.execute(task); + + if (executorResult.responseCode() == PeerTaskExecutorResponseCode.SUCCESS) { + List transactionReceipts = + executorResult + .result() + .map((map) -> map.get(block.getHeader())) + .orElseThrow( + () -> + new IllegalStateException( + "PeerTask response code was success, but empty")); + if (block.getBody().getTransactions().size() != transactionReceipts.size()) { + throw new IllegalStateException( + "PeerTask response code was success, but incorrect number of receipts returned"); + } + BlockWithReceipts blockWithReceipts = + new BlockWithReceipts(block, transactionReceipts); + return CompletableFuture.completedFuture(Optional.of(blockWithReceipts)); + } else { + return CompletableFuture.completedFuture(Optional.empty()); + } + }); + + } else { + final org.hyperledger.besu.ethereum.eth.manager.task.GetReceiptsFromPeerTask + getReceiptsFromPeerTask = + org.hyperledger.besu.ethereum.eth.manager.task.GetReceiptsFromPeerTask.forHeaders( + ethContext, List.of(block.getHeader()), metricsSystem); + return getReceiptsFromPeerTask + .run() + .thenCompose( + receiptTaskResult -> { + final Optional> transactionReceipts = + Optional.ofNullable(receiptTaskResult.getResult().get(block.getHeader())); + return CompletableFuture.completedFuture( + transactionReceipts.map(receipts -> new BlockWithReceipts(block, receipts))); + }) + .exceptionally(throwable -> Optional.empty()); + } } } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointDownloaderFactory.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointDownloaderFactory.java index 03df47e4407..30134d9f6c5 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointDownloaderFactory.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointDownloaderFactory.java @@ -17,6 +17,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.eth.manager.EthContext; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.sync.PivotBlockSelector; import org.hyperledger.besu.ethereum.eth.sync.SyncMode; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; @@ -61,6 +62,7 @@ public static Optional> createCheckpointDownloader( final ProtocolContext protocolContext, final MetricsSystem metricsSystem, final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, final WorldStateStorageCoordinator worldStateStorageCoordinator, final SyncState syncState, final Clock clock, @@ -110,6 +112,7 @@ public static Optional> createCheckpointDownloader( protocolSchedule, protocolContext, ethContext, + peerTaskExecutor, syncState, pivotBlockSelector, metricsSystem); @@ -127,6 +130,7 @@ public static Optional> createCheckpointDownloader( protocolSchedule, protocolContext, ethContext, + peerTaskExecutor, syncState, pivotBlockSelector, metricsSystem); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncActions.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncActions.java index 5096b74e24f..61b997e6c53 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncActions.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncActions.java @@ -16,6 +16,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.sync.ChainDownloader; import org.hyperledger.besu.ethereum.eth.sync.PivotBlockSelector; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; @@ -34,6 +35,7 @@ public CheckpointSyncActions( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, final SyncState syncState, final PivotBlockSelector pivotBlockSelector, final MetricsSystem metricsSystem) { @@ -43,6 +45,7 @@ public CheckpointSyncActions( protocolSchedule, protocolContext, ethContext, + peerTaskExecutor, syncState, pivotBlockSelector, metricsSystem); @@ -57,6 +60,7 @@ public ChainDownloader createChainDownloader( protocolSchedule, protocolContext, ethContext, + peerTaskExecutor, syncState, metricsSystem, currentState, diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncChainDownloader.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncChainDownloader.java index 5450b9e5a49..2590e4736ae 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncChainDownloader.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncChainDownloader.java @@ -16,6 +16,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.sync.ChainDownloader; import org.hyperledger.besu.ethereum.eth.sync.PipelineChainDownloader; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; @@ -36,6 +37,7 @@ public static ChainDownloader create( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, final SyncState syncState, final MetricsSystem metricsSystem, final FastSyncState fastSyncState, @@ -55,7 +57,13 @@ public static ChainDownloader create( syncState, syncTargetManager, new CheckpointSyncDownloadPipelineFactory( - config, protocolSchedule, protocolContext, ethContext, fastSyncState, metricsSystem), + config, + protocolSchedule, + protocolContext, + ethContext, + peerTaskExecutor, + fastSyncState, + metricsSystem), ethContext.getScheduler(), metricsSystem, syncDurationMetrics); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncDownloadPipelineFactory.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncDownloadPipelineFactory.java index 45f3f243d8c..0be10869861 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncDownloadPipelineFactory.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncDownloadPipelineFactory.java @@ -19,6 +19,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; import org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncDownloadPipelineFactory; import org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncState; @@ -40,9 +41,17 @@ public CheckpointSyncDownloadPipelineFactory( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, final FastSyncState fastSyncState, final MetricsSystem metricsSystem) { - super(syncConfig, protocolSchedule, protocolContext, ethContext, fastSyncState, metricsSystem); + super( + syncConfig, + protocolSchedule, + protocolContext, + ethContext, + peerTaskExecutor, + fastSyncState, + metricsSystem); } @Override @@ -76,7 +85,8 @@ protected Pipeline createDownloadCheckPointPipeline( checkPointSource, checkpoint, protocolContext.getBlockchain()); final CheckpointDownloadBlockStep checkPointDownloadBlockStep = - new CheckpointDownloadBlockStep(protocolSchedule, ethContext, checkpoint, metricsSystem); + new CheckpointDownloadBlockStep( + protocolSchedule, ethContext, peerTaskExecutor, checkpoint, syncConfig, metricsSystem); return PipelineBuilder.createPipelineFrom( "fetchCheckpoints", diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStep.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStep.java index cd57de371dd..876e96d1072 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStep.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStep.java @@ -22,10 +22,16 @@ import org.hyperledger.besu.ethereum.core.BlockWithReceipts; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthContext; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResponseCode; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResult; +import org.hyperledger.besu.ethereum.eth.manager.peertask.task.GetReceiptsFromPeerTask; +import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; import org.hyperledger.besu.ethereum.eth.sync.tasks.GetReceiptsForHeadersTask; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.plugin.services.MetricsSystem; -import org.hyperledger.besu.util.FutureUtils; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; @@ -33,24 +39,69 @@ public class DownloadReceiptsStep implements Function, CompletableFuture>> { + + private final ProtocolSchedule protocolSchedule; private final EthContext ethContext; + private final PeerTaskExecutor peerTaskExecutor; + private final SynchronizerConfiguration synchronizerConfiguration; private final MetricsSystem metricsSystem; - public DownloadReceiptsStep(final EthContext ethContext, final MetricsSystem metricsSystem) { + public DownloadReceiptsStep( + final ProtocolSchedule protocolSchedule, + final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, + final SynchronizerConfiguration synchronizerConfiguration, + final MetricsSystem metricsSystem) { + this.protocolSchedule = protocolSchedule; this.ethContext = ethContext; + this.peerTaskExecutor = peerTaskExecutor; + this.synchronizerConfiguration = synchronizerConfiguration; this.metricsSystem = metricsSystem; } @Override public CompletableFuture> apply(final List blocks) { final List headers = blocks.stream().map(Block::getHeader).collect(toList()); - final CompletableFuture>> getReceipts = - GetReceiptsForHeadersTask.forHeaders(ethContext, headers, metricsSystem).run(); - final CompletableFuture> combineWithBlocks = - getReceipts.thenApply( - receiptsByHeader -> combineBlocksAndReceipts(blocks, receiptsByHeader)); - FutureUtils.propagateCancellation(combineWithBlocks, getReceipts); - return combineWithBlocks; + if (synchronizerConfiguration.isPeerTaskSystemEnabled()) { + return ethContext + .getScheduler() + .scheduleServiceTask(() -> getReceiptsWithPeerTaskSystem(headers)) + .thenApply((receipts) -> combineBlocksAndReceipts(blocks, receipts)); + + } else { + return GetReceiptsForHeadersTask.forHeaders(ethContext, headers, metricsSystem) + .run() + .thenApply((receipts) -> combineBlocksAndReceipts(blocks, receipts)); + } + } + + private CompletableFuture>> + getReceiptsWithPeerTaskSystem(final List headers) { + Map> getReceipts = new HashMap<>(); + do { + GetReceiptsFromPeerTask task = new GetReceiptsFromPeerTask(headers, protocolSchedule); + PeerTaskExecutorResult>> getReceiptsResult = + peerTaskExecutor.execute(task); + if (getReceiptsResult.responseCode() == PeerTaskExecutorResponseCode.SUCCESS + && getReceiptsResult.result().isPresent()) { + Map> taskResult = getReceiptsResult.result().get(); + taskResult + .keySet() + .forEach( + (blockHeader) -> + getReceipts.merge( + blockHeader, + taskResult.get(blockHeader), + (initialReceipts, newReceipts) -> { + throw new IllegalStateException( + "Unexpectedly got receipts for block header already populated!"); + })); + // remove all the headers we found receipts for + headers.removeAll(getReceipts.keySet()); + } + // repeat until all headers have receipts + } while (!headers.isEmpty()); + return CompletableFuture.completedFuture(getReceipts); } private List combineBlocksAndReceipts( @@ -60,8 +111,17 @@ private List combineBlocksAndReceipts( block -> { final List receipts = receiptsByHeader.getOrDefault(block.getHeader(), emptyList()); + if (block.getBody().getTransactions().size() != receipts.size()) { + throw new IllegalStateException( + "PeerTask response code was success, but incorrect number of receipts returned. Header hash: " + + block.getHeader().getHash() + + ", Transactions: " + + block.getBody().getTransactions().size() + + ", receipts: " + + receipts.size()); + } return new BlockWithReceipts(block, receipts); }) - .collect(toList()); + .toList(); } } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActions.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActions.java index 7f6bbae3f31..58a64bd562a 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActions.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActions.java @@ -19,6 +19,7 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.manager.task.WaitForPeersTask; import org.hyperledger.besu.ethereum.eth.sync.ChainDownloader; import org.hyperledger.besu.ethereum.eth.sync.PivotBlockSelector; @@ -48,6 +49,7 @@ public class FastSyncActions { protected final ProtocolSchedule protocolSchedule; protected final ProtocolContext protocolContext; protected final EthContext ethContext; + protected final PeerTaskExecutor peerTaskExecutor; protected final SyncState syncState; protected final PivotBlockSelector pivotBlockSelector; protected final MetricsSystem metricsSystem; @@ -60,6 +62,7 @@ public FastSyncActions( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, final SyncState syncState, final PivotBlockSelector pivotBlockSelector, final MetricsSystem metricsSystem) { @@ -68,6 +71,7 @@ public FastSyncActions( this.protocolSchedule = protocolSchedule; this.protocolContext = protocolContext; this.ethContext = ethContext; + this.peerTaskExecutor = peerTaskExecutor; this.syncState = syncState; this.pivotBlockSelector = pivotBlockSelector; this.metricsSystem = metricsSystem; @@ -164,6 +168,7 @@ public ChainDownloader createChainDownloader( protocolSchedule, protocolContext, ethContext, + peerTaskExecutor, syncState, metricsSystem, currentState, diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncChainDownloader.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncChainDownloader.java index c36ff7cb482..1bf55a3811a 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncChainDownloader.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncChainDownloader.java @@ -16,6 +16,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.sync.ChainDownloader; import org.hyperledger.besu.ethereum.eth.sync.PipelineChainDownloader; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; @@ -35,6 +36,7 @@ public static ChainDownloader create( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, final SyncState syncState, final MetricsSystem metricsSystem, final FastSyncState fastSyncState, @@ -53,7 +55,13 @@ public static ChainDownloader create( syncState, syncTargetManager, new FastSyncDownloadPipelineFactory( - config, protocolSchedule, protocolContext, ethContext, fastSyncState, metricsSystem), + config, + protocolSchedule, + protocolContext, + ethContext, + peerTaskExecutor, + fastSyncState, + metricsSystem), ethContext.getScheduler(), metricsSystem, syncDurationMetrics); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java index 87032b76e57..ac562608873 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java @@ -26,6 +26,7 @@ import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthPeer; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.sync.DownloadBodiesStep; import org.hyperledger.besu.ethereum.eth.sync.DownloadHeadersStep; import org.hyperledger.besu.ethereum.eth.sync.DownloadPipelineFactory; @@ -58,6 +59,7 @@ public class FastSyncDownloadPipelineFactory implements DownloadPipelineFactory protected final ProtocolSchedule protocolSchedule; protected final ProtocolContext protocolContext; protected final EthContext ethContext; + protected final PeerTaskExecutor peerTaskExecutor; protected final FastSyncState fastSyncState; protected final MetricsSystem metricsSystem; protected final FastSyncValidationPolicy attachedValidationPolicy; @@ -69,12 +71,14 @@ public FastSyncDownloadPipelineFactory( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, final FastSyncState fastSyncState, final MetricsSystem metricsSystem) { this.syncConfig = syncConfig; this.protocolSchedule = protocolSchedule; this.protocolContext = protocolContext; this.ethContext = ethContext; + this.peerTaskExecutor = peerTaskExecutor; this.fastSyncState = fastSyncState; this.metricsSystem = metricsSystem; final LabelledMetric fastSyncValidationCounter = @@ -145,7 +149,8 @@ public Pipeline createDownloadPipelineForSyncTarget(final SyncT final DownloadBodiesStep downloadBodiesStep = new DownloadBodiesStep(protocolSchedule, ethContext, metricsSystem); final DownloadReceiptsStep downloadReceiptsStep = - new DownloadReceiptsStep(ethContext, metricsSystem); + new DownloadReceiptsStep( + protocolSchedule, ethContext, peerTaskExecutor, syncConfig, metricsSystem); final ImportBlocksStep importBlockStep = new ImportBlocksStep( protocolSchedule, diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastDownloaderFactory.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastDownloaderFactory.java index 8b71a57885d..1d775cc80fd 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastDownloaderFactory.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastDownloaderFactory.java @@ -17,6 +17,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.eth.manager.EthContext; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.sync.PivotBlockSelector; import org.hyperledger.besu.ethereum.eth.sync.SyncMode; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; @@ -59,6 +60,7 @@ public static Optional> create( final ProtocolContext protocolContext, final MetricsSystem metricsSystem, final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, final WorldStateStorageCoordinator worldStateStorageCoordinator, final SyncState syncState, final Clock clock, @@ -126,6 +128,7 @@ public static Optional> create( protocolSchedule, protocolContext, ethContext, + peerTaskExecutor, syncState, pivotBlockSelector, metricsSystem), diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapDownloaderFactory.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapDownloaderFactory.java index 5de8ceb9843..6c5ce0b04e9 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapDownloaderFactory.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapDownloaderFactory.java @@ -17,6 +17,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.eth.manager.EthContext; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.sync.PivotBlockSelector; import org.hyperledger.besu.ethereum.eth.sync.SyncMode; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; @@ -57,6 +58,7 @@ public static Optional> createSnapDownloader( final ProtocolContext protocolContext, final MetricsSystem metricsSystem, final EthContext ethContext, + final PeerTaskExecutor peerTaskExecutor, final WorldStateStorageCoordinator worldStateStorageCoordinator, final SyncState syncState, final Clock clock, @@ -121,6 +123,7 @@ public static Optional> createSnapDownloader( protocolSchedule, protocolContext, ethContext, + peerTaskExecutor, syncState, pivotBlockSelector, metricsSystem), diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutorTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutorTest.java index 0262e276da2..9639de154d7 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutorTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutorTest.java @@ -72,7 +72,7 @@ public void testExecuteAgainstPeerWithNoRetriesAndSuccessfulFlow() Mockito.when(subprotocol.getName()).thenReturn("subprotocol"); Mockito.when(requestSender.sendRequest(subprotocol, requestMessageData, ethPeer)) .thenReturn(responseMessageData); - Mockito.when(peerTask.parseResponse(responseMessageData)).thenReturn(responseObject); + Mockito.when(peerTask.processResponse(responseMessageData)).thenReturn(responseObject); Mockito.when(peerTask.isSuccess(responseObject)).thenReturn(true); PeerTaskExecutorResult result = peerTaskExecutor.executeAgainstPeer(peerTask, ethPeer); @@ -101,7 +101,7 @@ public void testExecuteAgainstPeerWithNoRetriesAndPartialSuccessfulFlow() Mockito.when(subprotocol.getName()).thenReturn("subprotocol"); Mockito.when(requestSender.sendRequest(subprotocol, requestMessageData, ethPeer)) .thenReturn(responseMessageData); - Mockito.when(peerTask.parseResponse(responseMessageData)).thenReturn(responseObject); + Mockito.when(peerTask.processResponse(responseMessageData)).thenReturn(responseObject); Mockito.when(peerTask.isSuccess(responseObject)).thenReturn(false); PeerTaskExecutorResult result = peerTaskExecutor.executeAgainstPeer(peerTask, ethPeer); @@ -130,7 +130,7 @@ public void testExecuteAgainstPeerWithRetriesAndSuccessfulFlowAfterFirstFailure( .thenThrow(new TimeoutException()) .thenReturn(responseMessageData); Mockito.when(requestMessageData.getCode()).thenReturn(requestMessageDataCode); - Mockito.when(peerTask.parseResponse(responseMessageData)).thenReturn(responseObject); + Mockito.when(peerTask.processResponse(responseMessageData)).thenReturn(responseObject); Mockito.when(peerTask.isSuccess(responseObject)).thenReturn(true); PeerTaskExecutorResult result = peerTaskExecutor.executeAgainstPeer(peerTask, ethPeer); @@ -204,7 +204,7 @@ public void testExecuteAgainstPeerWithNoRetriesAndInvalidResponseMessage() Mockito.when(subprotocol.getName()).thenReturn("subprotocol"); Mockito.when(requestSender.sendRequest(subprotocol, requestMessageData, ethPeer)) .thenReturn(responseMessageData); - Mockito.when(peerTask.parseResponse(responseMessageData)) + Mockito.when(peerTask.processResponse(responseMessageData)) .thenThrow(new InvalidPeerTaskResponseException()); PeerTaskExecutorResult result = peerTaskExecutor.executeAgainstPeer(peerTask, ethPeer); @@ -236,7 +236,7 @@ public void testExecuteWithNoRetriesAndSuccessFlow() Mockito.when(subprotocol.getName()).thenReturn("subprotocol"); Mockito.when(requestSender.sendRequest(subprotocol, requestMessageData, ethPeer)) .thenReturn(responseMessageData); - Mockito.when(peerTask.parseResponse(responseMessageData)).thenReturn(responseObject); + Mockito.when(peerTask.processResponse(responseMessageData)).thenReturn(responseObject); Mockito.when(peerTask.isSuccess(responseObject)).thenReturn(true); PeerTaskExecutorResult result = peerTaskExecutor.executeAgainstPeer(peerTask, ethPeer); @@ -274,7 +274,7 @@ public void testExecuteWithPeerSwitchingAndSuccessFlow() Mockito.when(requestMessageData.getCode()).thenReturn(requestMessageDataCode); Mockito.when(requestSender.sendRequest(subprotocol, requestMessageData, peer2)) .thenReturn(responseMessageData); - Mockito.when(peerTask.parseResponse(responseMessageData)).thenReturn(responseObject); + Mockito.when(peerTask.processResponse(responseMessageData)).thenReturn(responseObject); Mockito.when(peerTask.isSuccess(responseObject)).thenReturn(true); PeerTaskExecutorResult result = peerTaskExecutor.execute(peerTask); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTaskTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTaskTest.java new file mode 100644 index 00000000000..90e6f738fcd --- /dev/null +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTaskTest.java @@ -0,0 +1,264 @@ +/* + * 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.ethereum.eth.manager.peertask.task; + +import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.core.TransactionReceipt; +import org.hyperledger.besu.ethereum.eth.EthProtocol; +import org.hyperledger.besu.ethereum.eth.manager.ChainState; +import org.hyperledger.besu.ethereum.eth.manager.EthPeer; +import org.hyperledger.besu.ethereum.eth.manager.peertask.InvalidPeerTaskResponseException; +import org.hyperledger.besu.ethereum.eth.messages.EthPV63; +import org.hyperledger.besu.ethereum.eth.messages.GetReceiptsMessage; +import org.hyperledger.besu.ethereum.eth.messages.ReceiptsMessage; +import org.hyperledger.besu.ethereum.mainnet.BodyValidation; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import org.apache.commons.lang3.StringUtils; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +public class GetReceiptsFromPeerTaskTest { + + @Test + public void testGetSubProtocol() { + GetReceiptsFromPeerTask task = new GetReceiptsFromPeerTask(Collections.emptyList(), null); + Assertions.assertEquals(EthProtocol.get(), task.getSubProtocol()); + } + + @Test + public void testGetRequestMessage() { + BlockHeader blockHeader1 = mockBlockHeader(1); + TransactionReceipt receiptForBlock1 = + new TransactionReceipt(1, 123, Collections.emptyList(), Optional.empty()); + Mockito.when(blockHeader1.getReceiptsRoot()) + .thenReturn(BodyValidation.receiptsRoot(List.of(receiptForBlock1))); + + BlockHeader blockHeader2 = mockBlockHeader(2); + TransactionReceipt receiptForBlock2 = + new TransactionReceipt(1, 456, Collections.emptyList(), Optional.empty()); + Mockito.when(blockHeader2.getReceiptsRoot()) + .thenReturn(BodyValidation.receiptsRoot(List.of(receiptForBlock2))); + + BlockHeader blockHeader3 = mockBlockHeader(3); + TransactionReceipt receiptForBlock3 = + new TransactionReceipt(1, 789, Collections.emptyList(), Optional.empty()); + Mockito.when(blockHeader3.getReceiptsRoot()) + .thenReturn(BodyValidation.receiptsRoot(List.of(receiptForBlock3))); + + GetReceiptsFromPeerTask task = + new GetReceiptsFromPeerTask(List.of(blockHeader1, blockHeader2, blockHeader3), null); + + MessageData messageData = task.getRequestMessage(); + GetReceiptsMessage getReceiptsMessage = GetReceiptsMessage.readFrom(messageData); + + Assertions.assertEquals(EthPV63.GET_RECEIPTS, getReceiptsMessage.getCode()); + Iterable hashesInMessage = getReceiptsMessage.hashes(); + List expectedHashes = + List.of( + Hash.fromHexString(StringUtils.repeat("00", 31) + "11"), + Hash.fromHexString(StringUtils.repeat("00", 31) + "21"), + Hash.fromHexString(StringUtils.repeat("00", 31) + "31")); + List actualHashes = new ArrayList<>(); + hashesInMessage.forEach(actualHashes::add); + + Assertions.assertEquals(3, actualHashes.size()); + Assertions.assertEquals( + expectedHashes.stream().sorted().toList(), actualHashes.stream().sorted().toList()); + } + + @Test + public void testParseResponseWithNullResponseMessage() { + GetReceiptsFromPeerTask task = new GetReceiptsFromPeerTask(Collections.emptyList(), null); + Assertions.assertThrows( + InvalidPeerTaskResponseException.class, () -> task.processResponse(null)); + } + + @Test + public void testParseResponseForInvalidResponse() { + BlockHeader blockHeader1 = mockBlockHeader(1); + TransactionReceipt receiptForBlock1 = + new TransactionReceipt(1, 123, Collections.emptyList(), Optional.empty()); + Mockito.when(blockHeader1.getReceiptsRoot()) + .thenReturn(BodyValidation.receiptsRoot(List.of(receiptForBlock1))); + + BlockHeader blockHeader2 = mockBlockHeader(2); + TransactionReceipt receiptForBlock2 = + new TransactionReceipt(1, 456, Collections.emptyList(), Optional.empty()); + Mockito.when(blockHeader2.getReceiptsRoot()) + .thenReturn(BodyValidation.receiptsRoot(List.of(receiptForBlock2))); + + BlockHeader blockHeader3 = mockBlockHeader(3); + TransactionReceipt receiptForBlock3 = + new TransactionReceipt(1, 789, Collections.emptyList(), Optional.empty()); + Mockito.when(blockHeader3.getReceiptsRoot()) + .thenReturn(BodyValidation.receiptsRoot(List.of(receiptForBlock3))); + GetReceiptsFromPeerTask task = + new GetReceiptsFromPeerTask(List.of(blockHeader1, blockHeader2, blockHeader3), null); + ReceiptsMessage receiptsMessage = + ReceiptsMessage.create( + List.of( + List.of(receiptForBlock1), + List.of(receiptForBlock2), + List.of(receiptForBlock3), + List.of( + new TransactionReceipt(1, 101112, Collections.emptyList(), Optional.empty())))); + + Assertions.assertThrows( + InvalidPeerTaskResponseException.class, () -> task.processResponse(receiptsMessage)); + } + + @Test + public void testParseResponse() throws InvalidPeerTaskResponseException { + BlockHeader blockHeader1 = mockBlockHeader(1); + TransactionReceipt receiptForBlock1 = + new TransactionReceipt(1, 123, Collections.emptyList(), Optional.empty()); + Mockito.when(blockHeader1.getReceiptsRoot()) + .thenReturn(BodyValidation.receiptsRoot(List.of(receiptForBlock1))); + + BlockHeader blockHeader2 = mockBlockHeader(2); + TransactionReceipt receiptForBlock2 = + new TransactionReceipt(1, 456, Collections.emptyList(), Optional.empty()); + Mockito.when(blockHeader2.getReceiptsRoot()) + .thenReturn(BodyValidation.receiptsRoot(List.of(receiptForBlock2))); + + BlockHeader blockHeader3 = mockBlockHeader(3); + TransactionReceipt receiptForBlock3 = + new TransactionReceipt(1, 789, Collections.emptyList(), Optional.empty()); + Mockito.when(blockHeader3.getReceiptsRoot()) + .thenReturn(BodyValidation.receiptsRoot(List.of(receiptForBlock3))); + + BlockHeader blockHeader4 = mockBlockHeader(4); + Mockito.when(blockHeader4.getReceiptsRoot()).thenReturn(Hash.EMPTY_TRIE_HASH); + + GetReceiptsFromPeerTask task = + new GetReceiptsFromPeerTask( + List.of(blockHeader1, blockHeader2, blockHeader3, blockHeader4), null); + + ReceiptsMessage receiptsMessage = + ReceiptsMessage.create( + List.of( + List.of(receiptForBlock1), List.of(receiptForBlock2), List.of(receiptForBlock3))); + + Map> resultMap = task.processResponse(receiptsMessage); + + Assertions.assertEquals(4, resultMap.size()); + Assertions.assertEquals(Collections.emptyList(), resultMap.get(blockHeader4)); + Assertions.assertEquals(List.of(receiptForBlock1), resultMap.get(blockHeader1)); + Assertions.assertEquals(List.of(receiptForBlock2), resultMap.get(blockHeader2)); + Assertions.assertEquals(List.of(receiptForBlock3), resultMap.get(blockHeader3)); + } + + @Test + public void testParseResponseForOnlyPrefilledEmptyTrieReceiptsRoots() + throws InvalidPeerTaskResponseException { + BlockHeader blockHeader1 = mockBlockHeader(1); + Mockito.when(blockHeader1.getReceiptsRoot()).thenReturn(Hash.EMPTY_TRIE_HASH); + + GetReceiptsFromPeerTask task = new GetReceiptsFromPeerTask(List.of(blockHeader1), null); + + ReceiptsMessage receiptsMessage = ReceiptsMessage.create(Collections.emptyList()); + + Map> resultMap = task.processResponse(receiptsMessage); + + Assertions.assertEquals(1, resultMap.size()); + Assertions.assertEquals(Collections.emptyList(), resultMap.get(blockHeader1)); + } + + @Test + public void testGetPeerRequirementFilter() { + BlockHeader blockHeader1 = mockBlockHeader(1); + TransactionReceipt receiptForBlock1 = + new TransactionReceipt(1, 123, Collections.emptyList(), Optional.empty()); + Mockito.when(blockHeader1.getReceiptsRoot()) + .thenReturn(BodyValidation.receiptsRoot(List.of(receiptForBlock1))); + + BlockHeader blockHeader2 = mockBlockHeader(2); + TransactionReceipt receiptForBlock2 = + new TransactionReceipt(1, 456, Collections.emptyList(), Optional.empty()); + Mockito.when(blockHeader2.getReceiptsRoot()) + .thenReturn(BodyValidation.receiptsRoot(List.of(receiptForBlock2))); + + BlockHeader blockHeader3 = mockBlockHeader(3); + TransactionReceipt receiptForBlock3 = + new TransactionReceipt(1, 789, Collections.emptyList(), Optional.empty()); + Mockito.when(blockHeader3.getReceiptsRoot()) + .thenReturn(BodyValidation.receiptsRoot(List.of(receiptForBlock3))); + + ProtocolSchedule protocolSchedule = Mockito.mock(ProtocolSchedule.class); + Mockito.when(protocolSchedule.anyMatch(Mockito.any())).thenReturn(false); + + GetReceiptsFromPeerTask task = + new GetReceiptsFromPeerTask( + List.of(blockHeader1, blockHeader2, blockHeader3), protocolSchedule); + + EthPeer failForIncorrectProtocol = mockPeer("incorrectProtocol", 5); + EthPeer failForShortChainHeight = mockPeer("incorrectProtocol", 1); + EthPeer successfulCandidate = mockPeer(EthProtocol.NAME, 5); + + Assertions.assertFalse(task.getPeerRequirementFilter().test(failForIncorrectProtocol)); + Assertions.assertFalse(task.getPeerRequirementFilter().test(failForShortChainHeight)); + Assertions.assertTrue(task.getPeerRequirementFilter().test(successfulCandidate)); + } + + @Test + public void testIsSuccessForPartialSuccess() { + GetReceiptsFromPeerTask task = new GetReceiptsFromPeerTask(Collections.emptyList(), null); + + Assertions.assertFalse(task.isSuccess(Collections.emptyMap())); + } + + @Test + public void testIsSuccessForFullSuccess() { + GetReceiptsFromPeerTask task = new GetReceiptsFromPeerTask(Collections.emptyList(), null); + + Map> map = new HashMap<>(); + map.put(mockBlockHeader(1), null); + + Assertions.assertTrue(task.isSuccess(map)); + } + + private BlockHeader mockBlockHeader(final long blockNumber) { + BlockHeader blockHeader = Mockito.mock(BlockHeader.class); + Mockito.when(blockHeader.getNumber()).thenReturn(blockNumber); + // second to last hex digit indicates the blockNumber, last hex digit indicates the usage of the + // hash + Mockito.when(blockHeader.getHash()) + .thenReturn(Hash.fromHexString(StringUtils.repeat("00", 31) + blockNumber + "1")); + + return blockHeader; + } + + private EthPeer mockPeer(final String protocol, final long chainHeight) { + EthPeer ethPeer = Mockito.mock(EthPeer.class); + ChainState chainState = Mockito.mock(ChainState.class); + + Mockito.when(ethPeer.getProtocolName()).thenReturn(protocol); + Mockito.when(ethPeer.chainState()).thenReturn(chainState); + Mockito.when(chainState.getEstimatedHeight()).thenReturn(chainHeight); + + return ethPeer; + } +} diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckPointSyncChainDownloaderTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckPointSyncChainDownloaderTest.java index 43f03100a75..56e0461f706 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckPointSyncChainDownloaderTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckPointSyncChainDownloaderTest.java @@ -22,13 +22,19 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; +import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.core.Difficulty; +import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResponseCode; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResult; +import org.hyperledger.besu.ethereum.eth.manager.peertask.task.GetReceiptsFromPeerTask; import org.hyperledger.besu.ethereum.eth.sync.ChainDownloader; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; import org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncState; @@ -44,8 +50,15 @@ import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; +import java.lang.reflect.Field; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; import java.util.stream.Stream; import org.junit.jupiter.api.AfterEach; @@ -55,12 +68,16 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.ArgumentsProvider; import org.junit.jupiter.params.provider.ArgumentsSource; +import org.junit.platform.commons.util.ReflectionUtils; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; public class CheckPointSyncChainDownloaderTest { protected ProtocolSchedule protocolSchedule; protected EthProtocolManager ethProtocolManager; protected EthContext ethContext; + private PeerTaskExecutor peerTaskExecutor; protected ProtocolContext protocolContext; private SyncState syncState; @@ -100,6 +117,7 @@ public void setup(final DataStorageFormat dataStorageFormat) { localBlockchain = localBlockchainSetup.getBlockchain(); otherBlockchainSetup = BlockchainSetupUtil.forTesting(dataStorageFormat); otherBlockchain = otherBlockchainSetup.getBlockchain(); + otherBlockchainSetup.importFirstBlocks(30); protocolSchedule = localBlockchainSetup.getProtocolSchedule(); protocolContext = localBlockchainSetup.getProtocolContext(); ethProtocolManager = @@ -123,6 +141,41 @@ public void setup(final DataStorageFormat dataStorageFormat) { ethContext.getEthPeers(), true, Optional.of(checkpoint)); + + peerTaskExecutor = mock(PeerTaskExecutor.class); + + when(peerTaskExecutor.execute(any(GetReceiptsFromPeerTask.class))) + .thenAnswer( + new Answer>>>() { + @Override + public PeerTaskExecutorResult>> answer( + final InvocationOnMock invocationOnMock) throws Throwable { + GetReceiptsFromPeerTask task = + invocationOnMock.getArgument(0, GetReceiptsFromPeerTask.class); + + return processTask(task); + } + }); + } + + @SuppressWarnings("unchecked") + private PeerTaskExecutorResult>> processTask( + final GetReceiptsFromPeerTask task) throws IllegalAccessException { + Map> getReceiptsFromPeerTaskResult = new HashMap<>(); + List fields = + ReflectionUtils.findFields( + task.getClass(), + (field) -> field.getName().equals("blockHeaders"), + ReflectionUtils.HierarchyTraversalMode.TOP_DOWN); + fields.forEach((f) -> f.setAccessible(true)); + Collection blockHeaders = (Collection) fields.getFirst().get(task); + blockHeaders.forEach( + (bh) -> + getReceiptsFromPeerTaskResult.put( + bh, otherBlockchain.getTxReceipts(bh.getHash()).get())); + + return new PeerTaskExecutorResult<>( + Optional.of(getReceiptsFromPeerTaskResult), PeerTaskExecutorResponseCode.SUCCESS); } @AfterEach @@ -140,6 +193,7 @@ private ChainDownloader downloader( protocolSchedule, protocolContext, ethContext, + peerTaskExecutor, syncState, new NoOpMetricsSystem(), new FastSyncState(otherBlockchain.getBlockHeader(pivotBlockNumber).get()), @@ -148,9 +202,9 @@ private ChainDownloader downloader( @ParameterizedTest @ArgumentsSource(CheckPointSyncChainDownloaderTestArguments.class) - public void shouldSyncToPivotBlockInMultipleSegments(final DataStorageFormat storageFormat) { + public void shouldSyncToPivotBlockInMultipleSegments(final DataStorageFormat storageFormat) + throws IllegalAccessException { setup(storageFormat); - otherBlockchainSetup.importFirstBlocks(30); final RespondingEthPeer peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, otherBlockchain); @@ -161,6 +215,7 @@ public void shouldSyncToPivotBlockInMultipleSegments(final DataStorageFormat sto SynchronizerConfiguration.builder() .downloaderChainSegmentSize(5) .downloaderHeadersRequestSize(3) + .isPeerTaskSystemEnabled(false) .build(); final long pivotBlockNumber = 25; ethContext @@ -184,9 +239,9 @@ public void shouldSyncToPivotBlockInMultipleSegments(final DataStorageFormat sto @ParameterizedTest @ArgumentsSource(CheckPointSyncChainDownloaderTestArguments.class) - public void shouldSyncToPivotBlockInSingleSegment(final DataStorageFormat storageFormat) { + public void shouldSyncToPivotBlockInSingleSegment(final DataStorageFormat storageFormat) + throws IllegalAccessException { setup(storageFormat); - otherBlockchainSetup.importFirstBlocks(30); final RespondingEthPeer peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, otherBlockchain); @@ -194,7 +249,79 @@ public void shouldSyncToPivotBlockInSingleSegment(final DataStorageFormat storag RespondingEthPeer.blockchainResponder(otherBlockchain); final long pivotBlockNumber = 10; - final SynchronizerConfiguration syncConfig = SynchronizerConfiguration.builder().build(); + final SynchronizerConfiguration syncConfig = + SynchronizerConfiguration.builder().isPeerTaskSystemEnabled(false).build(); + ethContext + .getEthPeers() + .streamAvailablePeers() + .forEach( + ethPeer -> { + ethPeer.setCheckpointHeader( + otherBlockchainSetup.getBlocks().get((int) checkpoint.blockNumber()).getHeader()); + }); + final ChainDownloader downloader = downloader(syncConfig, pivotBlockNumber); + final CompletableFuture result = downloader.start(); + + peer.respondWhileOtherThreadsWork(responder, () -> !result.isDone()); + + assertThat(result).isCompleted(); + assertThat(localBlockchain.getChainHeadBlockNumber()).isEqualTo(pivotBlockNumber); + assertThat(localBlockchain.getChainHeadHeader()) + .isEqualTo(otherBlockchain.getBlockHeader(pivotBlockNumber).get()); + } + + @ParameterizedTest + @ArgumentsSource(CheckPointSyncChainDownloaderTestArguments.class) + public void shouldSyncToPivotBlockInMultipleSegmentsWithPeerTaskSystem( + final DataStorageFormat storageFormat) + throws IllegalAccessException, ExecutionException, InterruptedException, TimeoutException { + setup(storageFormat); + + final RespondingEthPeer peer = + EthProtocolManagerTestUtil.createPeer(ethProtocolManager, otherBlockchain); + final RespondingEthPeer.Responder responder = + RespondingEthPeer.blockchainResponder(otherBlockchain); + + final SynchronizerConfiguration syncConfig = + SynchronizerConfiguration.builder() + .downloaderChainSegmentSize(5) + .downloaderHeadersRequestSize(3) + .isPeerTaskSystemEnabled(true) + .build(); + final long pivotBlockNumber = 25; + ethContext + .getEthPeers() + .streamAvailablePeers() + .forEach( + ethPeer -> { + ethPeer.setCheckpointHeader( + otherBlockchainSetup.getBlocks().get((int) checkpoint.blockNumber()).getHeader()); + }); + final ChainDownloader downloader = downloader(syncConfig, pivotBlockNumber); + final CompletableFuture result = downloader.start(); + + peer.respondWhileOtherThreadsWork(responder, () -> !result.isDone()); + + assertThat(result).isCompleted(); + assertThat(localBlockchain.getChainHeadBlockNumber()).isEqualTo(pivotBlockNumber); + assertThat(localBlockchain.getChainHeadHeader()) + .isEqualTo(otherBlockchain.getBlockHeader(pivotBlockNumber).get()); + } + + @ParameterizedTest + @ArgumentsSource(CheckPointSyncChainDownloaderTestArguments.class) + public void shouldSyncToPivotBlockInSingleSegmentWithPeerTaskSystem( + final DataStorageFormat storageFormat) throws IllegalAccessException { + setup(storageFormat); + + final RespondingEthPeer peer = + EthProtocolManagerTestUtil.createPeer(ethProtocolManager, otherBlockchain); + final RespondingEthPeer.Responder responder = + RespondingEthPeer.blockchainResponder(otherBlockchain); + + final long pivotBlockNumber = 10; + final SynchronizerConfiguration syncConfig = + SynchronizerConfiguration.builder().isPeerTaskSystemEnabled(true).build(); ethContext .getEthPeers() .streamAvailablePeers() diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStepTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStepTest.java index c9cfeda1191..4559b211e6e 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStepTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStepTest.java @@ -18,47 +18,64 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; +import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; +import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockWithReceipts; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture; +import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResponseCode; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResult; +import org.hyperledger.besu.ethereum.eth.manager.peertask.task.GetReceiptsFromPeerTask; +import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Optional; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.Mockito; public class DownloadReceiptsStepTest { private static ProtocolContext protocolContext; + private static ProtocolSchedule protocolSchedule; private static MutableBlockchain blockchain; + private PeerTaskExecutor peerTaskExecutor; private EthProtocolManager ethProtocolManager; - private DownloadReceiptsStep downloadReceiptsStep; @BeforeAll public static void setUpClass() { final BlockchainSetupUtil setupUtil = BlockchainSetupUtil.forTesting(DataStorageFormat.FOREST); setupUtil.importFirstBlocks(20); protocolContext = setupUtil.getProtocolContext(); + protocolSchedule = setupUtil.getProtocolSchedule(); blockchain = setupUtil.getBlockchain(); } @BeforeEach public void setUp() { + peerTaskExecutor = mock(PeerTaskExecutor.class); TransactionPool transactionPool = mock(TransactionPool.class); ethProtocolManager = EthProtocolManagerTestUtil.create( @@ -68,12 +85,17 @@ public void setUp() { protocolContext.getWorldStateArchive(), transactionPool, EthProtocolConfiguration.defaultConfig()); - downloadReceiptsStep = - new DownloadReceiptsStep(ethProtocolManager.ethContext(), new NoOpMetricsSystem()); } @Test public void shouldDownloadReceiptsForBlocks() { + DownloadReceiptsStep downloadReceiptsStep = + new DownloadReceiptsStep( + protocolSchedule, + ethProtocolManager.ethContext(), + peerTaskExecutor, + SynchronizerConfiguration.builder().isPeerTaskSystemEnabled(false).build(), + new NoOpMetricsSystem()); final RespondingEthPeer peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, 1000); final List blocks = asList(block(1), block(2), block(3), block(4)); @@ -90,6 +112,39 @@ public void shouldDownloadReceiptsForBlocks() { blockWithReceipts(4))); } + @Test + public void shouldDownloadReceiptsForBlocksUsingPeerTaskSystem() + throws ExecutionException, InterruptedException { + DownloadReceiptsStep downloadReceiptsStep = + new DownloadReceiptsStep( + protocolSchedule, + ethProtocolManager.ethContext(), + peerTaskExecutor, + SynchronizerConfiguration.builder().isPeerTaskSystemEnabled(true).build(), + new NoOpMetricsSystem()); + + final List blocks = asList(mockBlock(), mockBlock(), mockBlock(), mockBlock()); + Map> receiptsMap = new HashMap<>(); + blocks.forEach( + (b) -> receiptsMap.put(b.getHeader(), List.of(Mockito.mock(TransactionReceipt.class)))); + PeerTaskExecutorResult>> peerTaskResult = + new PeerTaskExecutorResult<>( + Optional.of(receiptsMap), PeerTaskExecutorResponseCode.SUCCESS); + Mockito.when(peerTaskExecutor.execute(Mockito.any(GetReceiptsFromPeerTask.class))) + .thenReturn(peerTaskResult); + + final CompletableFuture> result = downloadReceiptsStep.apply(blocks); + + assertThat(result.get().get(0).getBlock()).isEqualTo(blocks.get(0)); + assertThat(result.get().get(0).getReceipts().size()).isEqualTo(1); + assertThat(result.get().get(1).getBlock()).isEqualTo(blocks.get(1)); + assertThat(result.get().get(1).getReceipts().size()).isEqualTo(1); + assertThat(result.get().get(2).getBlock()).isEqualTo(blocks.get(2)); + assertThat(result.get().get(2).getReceipts().size()).isEqualTo(1); + assertThat(result.get().get(3).getBlock()).isEqualTo(blocks.get(3)); + assertThat(result.get().get(3).getReceipts().size()).isEqualTo(1); + } + private Block block(final long number) { final BlockHeader header = blockchain.getBlockHeader(number).get(); return new Block(header, blockchain.getBlockBody(header.getHash()).get()); @@ -100,4 +155,16 @@ private BlockWithReceipts blockWithReceipts(final long number) { final List receipts = blockchain.getTxReceipts(block.getHash()).get(); return new BlockWithReceipts(block, receipts); } + + private Block mockBlock() { + final Block block = Mockito.mock(Block.class); + final BlockHeader blockHeader = Mockito.mock(BlockHeader.class); + Mockito.when(block.getHeader()).thenAnswer((invocationOnMock) -> blockHeader); + Mockito.when(blockHeader.getReceiptsRoot()).thenReturn(Hash.fromHexStringLenient("DEADBEEF")); + final BlockBody blockBody = Mockito.mock(BlockBody.class); + Mockito.when(block.getBody()).thenAnswer((invocationOnMock) -> blockBody); + Mockito.when(blockBody.getTransactions()) + .thenAnswer((invocationOnMock) -> List.of(Mockito.mock(Transaction.class))); + return block; + } } diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastDownloaderFactoryTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastDownloaderFactoryTest.java index 37ca5be2e99..bc493ebd036 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastDownloaderFactoryTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastDownloaderFactoryTest.java @@ -25,6 +25,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.eth.manager.EthContext; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.sync.PivotBlockSelector; import org.hyperledger.besu.ethereum.eth.sync.SyncMode; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; @@ -71,6 +72,7 @@ public class FastDownloaderFactoryTest { @Mock private ProtocolContext protocolContext; @Mock private MetricsSystem metricsSystem; @Mock private EthContext ethContext; + @Mock private PeerTaskExecutor peerTaskExecutor; @Mock private SyncState syncState; @Mock private Clock clock; @Mock private Path dataDirectory; @@ -114,6 +116,7 @@ public void shouldThrowIfSyncModeChangedWhileFastSyncIncomplete( protocolContext, metricsSystem, ethContext, + peerTaskExecutor, worldStateStorageCoordinator, syncState, clock, @@ -139,6 +142,7 @@ public void shouldNotThrowIfSyncModeChangedWhileFastSyncComplete( protocolContext, metricsSystem, ethContext, + peerTaskExecutor, worldStateStorageCoordinator, syncState, clock, @@ -167,6 +171,7 @@ public void shouldNotThrowWhenFastSyncModeRequested(final DataStorageFormat data protocolContext, metricsSystem, ethContext, + peerTaskExecutor, worldStateStorageCoordinator, syncState, clock, @@ -202,6 +207,7 @@ public void shouldClearWorldStateDuringFastSyncWhenStateQueDirectoryExists( protocolContext, metricsSystem, ethContext, + peerTaskExecutor, worldStateStorageCoordinator, syncState, clock, @@ -239,6 +245,7 @@ public void shouldCrashWhenStateQueueIsNotDirectory(final DataStorageFormat data protocolContext, metricsSystem, ethContext, + peerTaskExecutor, worldStateStorageCoordinator, syncState, clock, diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActionsTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActionsTest.java index 68caf2182c0..7af807c1c7b 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActionsTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActionsTest.java @@ -34,6 +34,7 @@ import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidator; import org.hyperledger.besu.ethereum.eth.sync.PivotBlockSelector; import org.hyperledger.besu.ethereum.eth.sync.SyncMode; @@ -536,6 +537,7 @@ private FastSyncActions createFastSyncActions( protocolSchedule, protocolContext, ethContext, + new PeerTaskExecutor(null, null, new NoOpMetricsSystem()), new SyncState(blockchain, ethContext.getEthPeers(), true, Optional.empty()), pivotBlockSelector, new NoOpMetricsSystem()); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncChainDownloaderTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncChainDownloaderTest.java index 34014246d28..0e5b5ec2c7c 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncChainDownloaderTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncChainDownloaderTest.java @@ -29,6 +29,7 @@ import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; +import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.messages.EthPV62; import org.hyperledger.besu.ethereum.eth.messages.GetBlockHeadersMessage; import org.hyperledger.besu.ethereum.eth.sync.ChainDownloader; @@ -110,6 +111,7 @@ private ChainDownloader downloader( protocolSchedule, protocolContext, ethContext, + new PeerTaskExecutor(null, null, new NoOpMetricsSystem()), syncState, new NoOpMetricsSystem(), new FastSyncState(otherBlockchain.getBlockHeader(pivotBlockNumber).get()), From c5020be1d673f4f6e2d9d0a14d6aaa8b8281ebd1 Mon Sep 17 00:00:00 2001 From: monem <119044801+pucedoteth@users.noreply.github.com> Date: Thu, 31 Oct 2024 04:54:11 +0200 Subject: [PATCH 05/56] Update DCO.md (#7827) Signed-off-by: monem <119044801+pucedoteth@users.noreply.github.com> Co-authored-by: Sally MacFarlane --- DCO.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DCO.md b/DCO.md index 4bf56cb80ae..48227cadcdf 100644 --- a/DCO.md +++ b/DCO.md @@ -5,4 +5,4 @@ As per section 13.a of the [Hyperledger Charter](https://www.hyperledger.org/abo The sign off needs to be using your legal name, not a pseudonym. Git has a built-in mechanism to allow this with the `-s` or `--signoff` argument to `git commit` command, providing your `user.name` and `user.email` have been setup correctly. -If you have any questions, you can reach us on Besu chat; first, [join the Discord server](https://discord.gg/hyperledger/) then [join the Besu channel](https://discord.com/channels/905194001349627914/938504958909747250). +If you have any questions, you can reach us on Besu chat; first, [join the Discord server](https://discord.com/invite/hyperledger) then [join the Besu channel](https://discord.com/channels/905194001349627914/938504958909747250). From ec46074ca656a1f4869b69dfe9b5921e94740f68 Mon Sep 17 00:00:00 2001 From: Simon Dudley Date: Thu, 31 Oct 2024 15:54:32 +1000 Subject: [PATCH 06/56] Test against EngineNewPayloadV4 in EngineNewPayloadV4Test (#7837) Also change "Missing" -> "Unexpected" message when V3 blob params sent to V2 Signed-off-by: Simon Dudley --- .../methods/engine/EngineNewPayloadV2.java | 4 +- .../engine/AbstractEngineNewPayloadTest.java | 88 +++++------ .../engine/EngineNewPayloadV2Test.java | 20 +-- .../engine/EngineNewPayloadV3Test.java | 36 +++-- .../engine/EngineNewPayloadV4Test.java | 137 +++++++----------- 5 files changed, 126 insertions(+), 159 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2.java index 00b0f830540..8d6bd7e4333 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2.java @@ -61,11 +61,11 @@ protected ValidationResult validateParameters( final Optional> maybeRequestsParam) { if (payloadParameter.getBlobGasUsed() != null) { return ValidationResult.invalid( - RpcErrorType.INVALID_BLOB_GAS_USED_PARAMS, "Missing blob gas used field"); + RpcErrorType.INVALID_BLOB_GAS_USED_PARAMS, "Unexpected blob gas used field present"); } if (payloadParameter.getExcessBlobGas() != null) { return ValidationResult.invalid( - RpcErrorType.INVALID_EXCESS_BLOB_GAS_PARAMS, "Missing excess blob gas field"); + RpcErrorType.INVALID_EXCESS_BLOB_GAS_PARAMS, "Unexpected excess blob gas field present"); } return ValidationResult.valid(); } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayloadTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayloadTest.java index e793ee8b577..0b81ac111a4 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayloadTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayloadTest.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine; +import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.ACCEPTED; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.INVALID; @@ -51,7 +52,6 @@ import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.Request; import org.hyperledger.besu.ethereum.core.Withdrawal; import org.hyperledger.besu.ethereum.eth.manager.EthPeers; import org.hyperledger.besu.ethereum.mainnet.BodyValidation; @@ -62,7 +62,6 @@ import org.hyperledger.besu.plugin.services.exception.StorageException; import org.hyperledger.besu.plugin.services.rpc.RpcResponseType; -import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; @@ -123,12 +122,11 @@ public void shouldReturnValid() { BlockHeader mockHeader = setupValidPayload( new BlockProcessingResult(Optional.of(new BlockProcessingOutputs(null, List.of()))), - Optional.empty(), Optional.empty()); lenient() .when(blockchain.getBlockHeader(mockHeader.getParentHash())) .thenReturn(Optional.of(mock(BlockHeader.class))); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); assertValidResponse(mockHeader, resp); } @@ -136,12 +134,11 @@ public void shouldReturnValid() { @Test public void shouldReturnInvalidOnBlockExecutionError() { BlockHeader mockHeader = - setupValidPayload( - new BlockProcessingResult("error 42"), Optional.empty(), Optional.empty()); + setupValidPayload(new BlockProcessingResult("error 42"), Optional.empty()); lenient() .when(blockchain.getBlockHeader(mockHeader.getParentHash())) .thenReturn(Optional.of(mock(BlockHeader.class))); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); EnginePayloadStatusResult res = fromSuccessResp(resp); assertThat(res.getLatestValidHash().get()).isEqualTo(mockHash); @@ -152,14 +149,14 @@ public void shouldReturnInvalidOnBlockExecutionError() { @Test public void shouldReturnAcceptedOnLatestValidAncestorEmpty() { - BlockHeader mockHeader = createBlockHeader(Optional.empty(), Optional.empty()); + BlockHeader mockHeader = createBlockHeader(Optional.empty()); when(blockchain.getBlockByHash(mockHeader.getHash())).thenReturn(Optional.empty()); when(blockchain.getBlockHeader(mockHeader.getParentHash())) .thenReturn(Optional.of(mock(BlockHeader.class))); when(mergeCoordinator.getLatestValidAncestor(any(BlockHeader.class))) .thenReturn(Optional.empty()); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); EnginePayloadStatusResult res = fromSuccessResp(resp); assertThat(res.getLatestValidHash()).isEmpty(); @@ -170,20 +167,19 @@ public void shouldReturnAcceptedOnLatestValidAncestorEmpty() { @Test public void shouldReturnSuccessOnAlreadyPresent() { - BlockHeader mockHeader = createBlockHeader(Optional.empty(), Optional.empty()); - Block mockBlock = - new Block(mockHeader, new BlockBody(Collections.emptyList(), Collections.emptyList())); + BlockHeader mockHeader = createBlockHeader(Optional.empty()); + Block mockBlock = new Block(mockHeader, new BlockBody(emptyList(), emptyList())); when(blockchain.getBlockByHash(any())).thenReturn(Optional.of(mockBlock)); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); assertValidResponse(mockHeader, resp); } @Test public void shouldReturnInvalidWithLatestValidHashIsABadBlock() { - BlockHeader mockHeader = createBlockHeader(Optional.empty(), Optional.empty()); + BlockHeader mockHeader = createBlockHeader(Optional.empty()); Hash latestValidHash = Hash.hash(Bytes32.fromHexStringLenient("0xcafebabe")); when(blockchain.getBlockByHash(mockHeader.getHash())).thenReturn(Optional.empty()); @@ -191,7 +187,7 @@ public void shouldReturnInvalidWithLatestValidHashIsABadBlock() { when(mergeCoordinator.getLatestValidHashOfBadBlock(mockHeader.getHash())) .thenReturn(Optional.of(latestValidHash)); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); EnginePayloadStatusResult res = fromSuccessResp(resp); assertThat(res.getLatestValidHash()).isEqualTo(Optional.of(latestValidHash)); @@ -204,12 +200,11 @@ public void shouldNotReturnInvalidOnStorageException() { BlockHeader mockHeader = setupValidPayload( new BlockProcessingResult(Optional.empty(), new StorageException("database bedlam")), - Optional.empty(), Optional.empty()); lenient() .when(blockchain.getBlockHeader(mockHeader.getParentHash())) .thenReturn(Optional.of(mock(BlockHeader.class))); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); fromErrorResp(resp); verify(engineCallListener, times(1)).executionEngineCalled(); @@ -220,13 +215,12 @@ public void shouldNotReturnInvalidOnHandledMerkleTrieException() { BlockHeader mockHeader = setupValidPayload( new BlockProcessingResult(Optional.empty(), new MerkleTrieException("missing leaf")), - Optional.empty(), Optional.empty()); lenient() .when(blockchain.getBlockHeader(mockHeader.getParentHash())) .thenReturn(Optional.of(mock(BlockHeader.class))); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); verify(engineCallListener, times(1)).executionEngineCalled(); @@ -235,7 +229,7 @@ public void shouldNotReturnInvalidOnHandledMerkleTrieException() { @Test public void shouldNotReturnInvalidOnThrownMerkleTrieException() { - BlockHeader mockHeader = createBlockHeader(Optional.empty(), Optional.empty()); + BlockHeader mockHeader = createBlockHeader(Optional.empty()); when(blockchain.getBlockByHash(mockHeader.getHash())).thenReturn(Optional.empty()); when(blockchain.getBlockHeader(mockHeader.getParentHash())) .thenReturn(Optional.of(mock(BlockHeader.class))); @@ -243,7 +237,7 @@ public void shouldNotReturnInvalidOnThrownMerkleTrieException() { .thenReturn(Optional.of(mockHash)); when(mergeCoordinator.rememberBlock(any())).thenThrow(new MerkleTrieException("missing leaf")); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); verify(engineCallListener, times(1)).executionEngineCalled(); @@ -252,7 +246,7 @@ public void shouldNotReturnInvalidOnThrownMerkleTrieException() { @Test public void shouldReturnInvalidBlockHashOnBadHashParameter() { - BlockHeader mockHeader = spy(createBlockHeader(Optional.empty(), Optional.empty())); + BlockHeader mockHeader = spy(createBlockHeader(Optional.empty())); lenient() .when(mergeCoordinator.getLatestValidAncestor(mockHeader.getBlockHash())) .thenReturn(Optional.empty()); @@ -260,7 +254,7 @@ public void shouldReturnInvalidBlockHashOnBadHashParameter() { .when(blockchain.getBlockHeader(mockHeader.getParentHash())) .thenReturn(Optional.of(mock(BlockHeader.class))); lenient().when(mockHeader.getHash()).thenReturn(Hash.fromHexStringLenient("0x1337")); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); EnginePayloadStatusResult res = fromSuccessResp(resp); assertThat(res.getStatusAsString()).isEqualTo(getExpectedInvalidBlockHashStatus().name()); @@ -269,11 +263,11 @@ public void shouldReturnInvalidBlockHashOnBadHashParameter() { @Test public void shouldCheckBlockValidityBeforeCheckingByHashForExisting() { - BlockHeader realHeader = createBlockHeader(Optional.empty(), Optional.empty()); + BlockHeader realHeader = createBlockHeader(Optional.empty()); BlockHeader paramHeader = spy(realHeader); when(paramHeader.getHash()).thenReturn(Hash.fromHexStringLenient("0x1337")); - var resp = resp(mockEnginePayload(paramHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(paramHeader, emptyList())); EnginePayloadStatusResult res = fromSuccessResp(resp); assertThat(res.getLatestValidHash()).isEmpty(); @@ -283,7 +277,7 @@ public void shouldCheckBlockValidityBeforeCheckingByHashForExisting() { @Test public void shouldReturnInvalidOnMalformedTransactions() { - BlockHeader mockHeader = createBlockHeader(Optional.empty(), Optional.empty()); + BlockHeader mockHeader = createBlockHeader(Optional.empty()); when(mergeCoordinator.getLatestValidAncestor(any(Hash.class))) .thenReturn(Optional.of(mockHash)); @@ -298,9 +292,9 @@ public void shouldReturnInvalidOnMalformedTransactions() { @Test public void shouldRespondWithSyncingDuringForwardSync() { - BlockHeader mockHeader = createBlockHeader(Optional.empty(), Optional.empty()); + BlockHeader mockHeader = createBlockHeader(Optional.empty()); when(mergeContext.isSyncing()).thenReturn(Boolean.TRUE); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); EnginePayloadStatusResult res = fromSuccessResp(resp); assertThat(res.getError()).isNull(); @@ -311,10 +305,10 @@ public void shouldRespondWithSyncingDuringForwardSync() { @Test public void shouldRespondWithSyncingDuringBackwardsSync() { - BlockHeader mockHeader = createBlockHeader(Optional.empty(), Optional.empty()); + BlockHeader mockHeader = createBlockHeader(Optional.empty()); when(mergeCoordinator.appendNewPayloadToSync(any())) .thenReturn(CompletableFuture.completedFuture(null)); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); EnginePayloadStatusResult res = fromSuccessResp(resp); assertThat(res.getLatestValidHash()).isEmpty(); @@ -325,12 +319,12 @@ public void shouldRespondWithSyncingDuringBackwardsSync() { @Test public void shouldRespondWithInvalidIfExtraDataIsNull() { - BlockHeader realHeader = createBlockHeader(Optional.empty(), Optional.empty()); + BlockHeader realHeader = createBlockHeader(Optional.empty()); BlockHeader paramHeader = spy(realHeader); when(paramHeader.getHash()).thenReturn(Hash.fromHexStringLenient("0x1337")); when(paramHeader.getExtraData().toHexString()).thenReturn(null); - var resp = resp(mockEnginePayload(paramHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(paramHeader, emptyList())); EnginePayloadStatusResult res = fromSuccessResp(resp); assertThat(res.getLatestValidHash()).isEmpty(); @@ -342,8 +336,8 @@ public void shouldRespondWithInvalidIfExtraDataIsNull() { @Test public void shouldReturnInvalidWhenBadBlock() { when(mergeCoordinator.isBadBlock(any(Hash.class))).thenReturn(true); - BlockHeader mockHeader = createBlockHeader(Optional.empty(), Optional.empty()); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); + BlockHeader mockHeader = createBlockHeader(Optional.empty()); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); when(protocolSpec.getWithdrawalsValidator()) .thenReturn(new WithdrawalsValidator.AllowedWithdrawals()); EnginePayloadStatusResult res = fromSuccessResp(resp); @@ -359,12 +353,11 @@ public void shouldReturnValidIfProtocolScheduleIsEmpty() { BlockHeader mockHeader = setupValidPayload( new BlockProcessingResult(Optional.of(new BlockProcessingOutputs(null, List.of()))), - Optional.empty(), Optional.empty()); lenient() .when(blockchain.getBlockHeader(mockHeader.getParentHash())) .thenReturn(Optional.of(mock(BlockHeader.class))); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); assertValidResponse(mockHeader, resp); } @@ -408,11 +401,9 @@ protected EnginePayloadParameter mockEnginePayload( } protected BlockHeader setupValidPayload( - final BlockProcessingResult value, - final Optional> maybeWithdrawals, - final Optional> maybeRequests) { + final BlockProcessingResult value, final Optional> maybeWithdrawals) { - BlockHeader mockHeader = createBlockHeader(maybeWithdrawals, maybeRequests); + BlockHeader mockHeader = createBlockHeader(maybeWithdrawals); when(blockchain.getBlockByHash(mockHeader.getHash())).thenReturn(Optional.empty()); when(mergeCoordinator.getLatestValidAncestor(any(BlockHeader.class))) .thenReturn(Optional.of(mockHash)); @@ -425,6 +416,11 @@ protected ExecutionEngineJsonRpcMethod.EngineStatus getExpectedInvalidBlockHashS } protected EnginePayloadStatusResult fromSuccessResp(final JsonRpcResponse resp) { + if (resp.getType().equals(RpcResponseType.ERROR)) { + final JsonRpcError jsonRpcError = fromErrorResp(resp); + throw new AssertionError( + "Expected success but was error with message: " + jsonRpcError.getMessage()); + } assertThat(resp.getType()).isEqualTo(RpcResponseType.SUCCESS); return Optional.of(resp) .map(JsonRpcSuccessResponse.class::cast) @@ -441,15 +437,12 @@ protected JsonRpcError fromErrorResp(final JsonRpcResponse resp) { .get(); } - protected BlockHeader createBlockHeader( - final Optional> maybeWithdrawals, - final Optional> maybeRequests) { - return createBlockHeaderFixture(maybeWithdrawals, maybeRequests).buildHeader(); + protected BlockHeader createBlockHeader(final Optional> maybeWithdrawals) { + return createBlockHeaderFixture(maybeWithdrawals).buildHeader(); } protected BlockHeaderTestFixture createBlockHeaderFixture( - final Optional> maybeWithdrawals, - final Optional> maybeRequests) { + final Optional> maybeWithdrawals) { BlockHeader parentBlockHeader = new BlockHeaderTestFixture().baseFeePerGas(Wei.ONE).buildHeader(); return new BlockHeaderTestFixture() @@ -458,8 +451,7 @@ protected BlockHeaderTestFixture createBlockHeaderFixture( .number(parentBlockHeader.getNumber() + 1) .timestamp(parentBlockHeader.getTimestamp() + 1) .withdrawalsRoot(maybeWithdrawals.map(BodyValidation::withdrawalsRoot).orElse(null)) - .parentBeaconBlockRoot(maybeParentBeaconBlockRoot) - .requestsHash(maybeRequests.map(BodyValidation::requestsHash).orElse(null)); + .parentBeaconBlockRoot(maybeParentBeaconBlockRoot); } protected void assertValidResponse(final BlockHeader mockHeader, final JsonRpcResponse resp) { diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2Test.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2Test.java index abf2c297673..171ee0499f2 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2Test.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2Test.java @@ -82,8 +82,7 @@ public void shouldReturnValidIfWithdrawalsIsNotNull_WhenWithdrawalsAllowed() { BlockHeader mockHeader = setupValidPayload( new BlockProcessingResult(Optional.of(new BlockProcessingOutputs(null, List.of()))), - Optional.of(withdrawals), - Optional.empty()); + Optional.of(withdrawals)); lenient() .when(blockchain.getBlockHeader(mockHeader.getParentHash())) .thenReturn(Optional.of(mock(BlockHeader.class))); @@ -100,7 +99,6 @@ public void shouldReturnValidIfWithdrawalsIsNull_WhenWithdrawalsProhibited() { BlockHeader mockHeader = setupValidPayload( new BlockProcessingResult(Optional.of(new BlockProcessingOutputs(null, List.of()))), - Optional.empty(), Optional.empty()); lenient() .when(blockchain.getBlockHeader(mockHeader.getParentHash())) @@ -120,7 +118,7 @@ public void shouldReturnInvalidIfWithdrawalsIsNotNull_WhenWithdrawalsProhibited( var resp = resp( mockEnginePayload( - createBlockHeader(Optional.of(Collections.emptyList()), Optional.empty()), + createBlockHeader(Optional.of(Collections.emptyList())), Collections.emptyList(), withdrawals)); @@ -133,14 +131,14 @@ public void shouldReturnInvalidIfWithdrawalsIsNotNull_WhenWithdrawalsProhibited( public void shouldValidateBlobGasUsedCorrectly() { // V2 should return error if non-null blobGasUsed BlockHeader blockHeader = - createBlockHeaderFixture(Optional.of(Collections.emptyList()), Optional.empty()) + createBlockHeaderFixture(Optional.of(Collections.emptyList())) .blobGasUsed(100L) .buildHeader(); var resp = resp(mockEnginePayload(blockHeader, Collections.emptyList(), List.of())); final JsonRpcError jsonRpcError = fromErrorResp(resp); assertThat(jsonRpcError.getCode()).isEqualTo(INVALID_BLOB_GAS_USED_PARAMS.getCode()); - assertThat(jsonRpcError.getData()).isEqualTo("Missing blob gas used field"); + assertThat(jsonRpcError.getData()).isEqualTo("Unexpected blob gas used field present"); verify(engineCallListener, times(1)).executionEngineCalled(); } @@ -148,7 +146,7 @@ public void shouldValidateBlobGasUsedCorrectly() { public void shouldValidateExcessBlobGasCorrectly() { // V2 should return error if non-null ExcessBlobGas BlockHeader blockHeader = - createBlockHeaderFixture(Optional.of(Collections.emptyList()), Optional.empty()) + createBlockHeaderFixture(Optional.of(Collections.emptyList())) .excessBlobGas(BlobGas.MAX_BLOB_GAS) .buildHeader(); @@ -156,7 +154,7 @@ public void shouldValidateExcessBlobGasCorrectly() { final JsonRpcError jsonRpcError = fromErrorResp(resp); assertThat(jsonRpcError.getCode()).isEqualTo(INVALID_PARAMS.getCode()); - assertThat(jsonRpcError.getData()).isEqualTo("Missing excess blob gas field"); + assertThat(jsonRpcError.getData()).isEqualTo("Unexpected excess blob gas field present"); verify(engineCallListener, times(1)).executionEngineCalled(); } @@ -169,9 +167,7 @@ public void shouldReturnInvalidIfWithdrawalsIsNull_WhenWithdrawalsAllowed() { var resp = resp( mockEnginePayload( - createBlockHeader(Optional.empty(), Optional.empty()), - Collections.emptyList(), - withdrawals)); + createBlockHeader(Optional.empty()), Collections.emptyList(), withdrawals)); assertThat(fromErrorResp(resp).getCode()).isEqualTo(INVALID_PARAMS.getCode()); verify(engineCallListener, times(1)).executionEngineCalled(); @@ -182,7 +178,7 @@ public void shouldReturnUnsupportedForkIfBlockTimestampIsAfterCancunMilestone() // Cancun starte at timestamp 30 final long blockTimestamp = 31L; BlockHeader blockHeader = - createBlockHeaderFixture(Optional.of(Collections.emptyList()), Optional.empty()) + createBlockHeaderFixture(Optional.of(Collections.emptyList())) .timestamp(blockTimestamp) .buildHeader(); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3Test.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3Test.java index b79cb587eb3..1810ce94508 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3Test.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3Test.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine; +import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.INVALID; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType.INVALID_PARAMS; @@ -44,7 +45,6 @@ import org.hyperledger.besu.ethereum.core.BlobTestFixture; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.Request; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionTestFixture; import org.hyperledger.besu.ethereum.core.Withdrawal; @@ -56,7 +56,6 @@ import org.hyperledger.besu.evm.gascalculator.CancunGasCalculator; import java.math.BigInteger; -import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.function.Supplier; @@ -112,8 +111,18 @@ public void shouldInvalidVersionedHash_whenShortVersionedHash() { when(payload.getExcessBlobGas()).thenReturn("99"); when(payload.getBlobGasUsed()).thenReturn(9l); + // TODO locking this as V3 otherwise this breaks the EngineNewPayloadV4Test subclass when method + // field is V4 + final EngineNewPayloadV3 methodV3 = + new EngineNewPayloadV3( + vertx, + protocolSchedule, + protocolContext, + mergeCoordinator, + ethPeers, + engineCallListener); final JsonRpcResponse badParam = - method.response( + methodV3.response( new JsonRpcRequestContext( new JsonRpcRequest( "2.0", @@ -133,24 +142,20 @@ public void shouldValidVersionedHash_whenListIsEmpty() { final BlockHeader mockHeader = setupValidPayload( new BlockProcessingResult(Optional.of(new BlockProcessingOutputs(null, List.of()))), - Optional.empty(), Optional.empty()); - final EnginePayloadParameter payload = - mockEnginePayload(mockHeader, Collections.emptyList(), null); + final EnginePayloadParameter payload = mockEnginePayload(mockHeader, emptyList(), null); ValidationResult res = method.validateParameters( payload, Optional.of(List.of()), Optional.of("0x0000000000000000000000000000000000000000000000000000000000000000"), - Optional.empty()); + Optional.of(emptyList())); assertThat(res.isValid()).isTrue(); } @Override - protected BlockHeader createBlockHeader( - final Optional> maybeWithdrawals, - final Optional> maybeRequests) { + protected BlockHeader createBlockHeader(final Optional> maybeWithdrawals) { BlockHeader parentBlockHeader = new BlockHeaderTestFixture() .baseFeePerGas(Wei.ONE) @@ -186,12 +191,12 @@ public void shouldReturnValidIfProtocolScheduleIsEmpty() { public void shouldValidateBlobGasUsedCorrectly() { // V3 must return error if null blobGasUsed BlockHeader blockHeader = - createBlockHeaderFixture(Optional.of(Collections.emptyList()), Optional.empty()) + createBlockHeaderFixture(Optional.of(emptyList())) .excessBlobGas(BlobGas.MAX_BLOB_GAS) .blobGasUsed(null) .buildHeader(); - var resp = resp(mockEnginePayload(blockHeader, Collections.emptyList(), List.of())); + var resp = resp(mockEnginePayload(blockHeader, emptyList(), List.of())); final JsonRpcError jsonRpcError = fromErrorResp(resp); assertThat(jsonRpcError.getCode()).isEqualTo(INVALID_PARAMS.getCode()); @@ -204,12 +209,12 @@ public void shouldValidateBlobGasUsedCorrectly() { public void shouldValidateExcessBlobGasCorrectly() { // V3 must return error if null excessBlobGas BlockHeader blockHeader = - createBlockHeaderFixture(Optional.of(Collections.emptyList()), Optional.empty()) + createBlockHeaderFixture(Optional.of(emptyList())) .excessBlobGas(null) .blobGasUsed(100L) .buildHeader(); - var resp = resp(mockEnginePayload(blockHeader, Collections.emptyList(), List.of())); + var resp = resp(mockEnginePayload(blockHeader, emptyList(), List.of())); final JsonRpcError jsonRpcError = fromErrorResp(resp); assertThat(jsonRpcError.getCode()).isEqualTo(INVALID_PARAMS.getCode()); @@ -229,7 +234,6 @@ public void shouldRejectTransactionsWithFullBlobs() { BlockHeader mockHeader = setupValidPayload( new BlockProcessingResult(Optional.of(new BlockProcessingOutputs(null, List.of()))), - Optional.empty(), Optional.empty()); var resp = resp(mockEnginePayload(mockHeader, transactions)); @@ -265,7 +269,7 @@ public void shouldReturnUnsupportedForkIfBlockTimestampIsAfterCancunMilestone() protected JsonRpcResponse resp(final EnginePayloadParameter payload) { Object[] params = maybeParentBeaconBlockRoot - .map(bytes32 -> new Object[] {payload, Collections.emptyList(), bytes32.toHexString()}) + .map(bytes32 -> new Object[] {payload, emptyList(), bytes32.toHexString()}) .orElseGet(() -> new Object[] {payload}); return method.response( new JsonRpcRequestContext(new JsonRpcRequest("2.0", this.method.getName(), params))); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV4Test.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV4Test.java index c8504e7451d..fe7c38917c3 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV4Test.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV4Test.java @@ -14,8 +14,10 @@ */ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine; +import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.ethereum.api.graphql.internal.response.GraphQLError.INVALID_PARAMS; +import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType.INVALID_EXECUTION_REQUESTS_PARAMS; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; @@ -42,7 +44,6 @@ import org.hyperledger.besu.ethereum.mainnet.requests.ProhibitedRequestValidator; import org.hyperledger.besu.evm.gascalculator.PragueGasCalculator; -import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Optional; @@ -59,14 +60,19 @@ public class EngineNewPayloadV4Test extends EngineNewPayloadV3Test { public EngineNewPayloadV4Test() {} + private static final List VALID_REQUESTS = + List.of( + new Request(RequestType.DEPOSIT, Bytes.of(1)), + new Request(RequestType.WITHDRAWAL, Bytes.of(1)), + new Request(RequestType.CONSOLIDATION, Bytes.of(1))); + @BeforeEach @Override public void before() { super.before(); maybeParentBeaconBlockRoot = Optional.of(Bytes32.ZERO); - // TODO this should be using NewPayloadV4 this.method = - new EngineNewPayloadV3( + new EngineNewPayloadV4( vertx, protocolSchedule, protocolContext, @@ -75,95 +81,63 @@ public void before() { engineCallListener); lenient().when(protocolSchedule.hardforkFor(any())).thenReturn(Optional.of(pragueHardfork)); lenient().when(protocolSpec.getGasCalculator()).thenReturn(new PragueGasCalculator()); + mockAllowedRequestsValidator(); } @Override public void shouldReturnExpectedMethodName() { - assertThat(method.getName()).isEqualTo("engine_newPayloadV3"); - } - - @Test - public void shouldReturnValidIfRequestsIsNull_WhenRequestsProhibited() { - mockProhibitedRequestsValidator(); - - BlockHeader mockHeader = - setupValidPayload( - new BlockProcessingResult( - Optional.of(new BlockProcessingOutputs(null, List.of(), Optional.empty()))), - Optional.empty(), - Optional.empty()); - when(blockchain.getBlockHeader(mockHeader.getParentHash())) - .thenReturn(Optional.of(mock(BlockHeader.class))); - when(mergeCoordinator.getLatestValidAncestor(mockHeader)) - .thenReturn(Optional.of(mockHeader.getHash())); - - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList())); - - assertValidResponse(mockHeader, resp); + assertThat(method.getName()).isEqualTo("engine_newPayloadV4"); } @Test public void shouldReturnInvalidIfRequestsIsNull_WhenRequestsAllowed() { - mockAllowedRequestsValidator(); var resp = - resp( - mockEnginePayload( - createBlockHeader(Optional.empty(), Optional.empty()), Collections.emptyList())); + respWithInvalidRequests( + mockEnginePayload(createValidBlockHeaderForV4(Optional.empty()), emptyList())); assertThat(fromErrorResp(resp).getCode()).isEqualTo(INVALID_PARAMS.getCode()); + assertThat(fromErrorResp(resp).getMessage()) + .isEqualTo(INVALID_EXECUTION_REQUESTS_PARAMS.getMessage()); verify(engineCallListener, times(1)).executionEngineCalled(); } @Test public void shouldReturnValidIfRequestsIsNotNull_WhenRequestsAllowed() { - final List requests = - List.of( - new Request(RequestType.DEPOSIT, Bytes.of(1)), - new Request(RequestType.WITHDRAWAL, Bytes.of(1)), - new Request(RequestType.CONSOLIDATION, Bytes.of(1))); - - mockAllowedRequestsValidator(); BlockHeader mockHeader = setupValidPayload( new BlockProcessingResult( - Optional.of(new BlockProcessingOutputs(null, List.of(), Optional.of(requests)))), - Optional.empty(), + Optional.of( + new BlockProcessingOutputs(null, List.of(), Optional.of(VALID_REQUESTS)))), Optional.empty()); when(blockchain.getBlockHeader(mockHeader.getParentHash())) .thenReturn(Optional.of(mock(BlockHeader.class))); when(mergeCoordinator.getLatestValidAncestor(mockHeader)) .thenReturn(Optional.of(mockHeader.getHash())); - var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList()), requests); + var resp = resp(mockEnginePayload(mockHeader, emptyList())); assertValidResponse(mockHeader, resp); } @Test public void shouldReturnInvalidIfRequestsIsNotNull_WhenRequestsProhibited() { - final List requests = - List.of( - new Request(RequestType.DEPOSIT, Bytes.of(1)), - new Request(RequestType.WITHDRAWAL, Bytes.of(1)), - new Request(RequestType.CONSOLIDATION, Bytes.of(1))); - mockProhibitedRequestsValidator(); - var resp = - resp( - mockEnginePayload( - createBlockHeader(Optional.empty(), Optional.of(Collections.emptyList())), - Collections.emptyList()), - requests); + var resp = resp(mockEnginePayload(createValidBlockHeaderForV4(Optional.empty()), emptyList())); final JsonRpcError jsonRpcError = fromErrorResp(resp); assertThat(jsonRpcError.getCode()).isEqualTo(INVALID_PARAMS.getCode()); verify(engineCallListener, times(1)).executionEngineCalled(); } - @Override - protected BlockHeader createBlockHeader( - final Optional> maybeWithdrawals, - final Optional> maybeRequests) { + private BlockHeader createValidBlockHeaderForV4( + final Optional> maybeWithdrawals) { + return createBlockHeaderFixtureForV3(maybeWithdrawals) + .requestsHash(BodyValidation.requestsHash(VALID_REQUESTS)) + .buildHeader(); + } + + private BlockHeaderTestFixture createBlockHeaderFixtureForV3( + final Optional> maybeWithdrawals) { BlockHeader parentBlockHeader = new BlockHeaderTestFixture() .baseFeePerGas(Wei.ONE) @@ -172,48 +146,49 @@ protected BlockHeader createBlockHeader( .blobGasUsed(0L) .buildHeader(); - BlockHeader mockHeader = - new BlockHeaderTestFixture() - .baseFeePerGas(Wei.ONE) - .parentHash(parentBlockHeader.getParentHash()) - .number(parentBlockHeader.getNumber() + 1) - .timestamp(parentBlockHeader.getTimestamp() + 1) - .withdrawalsRoot(maybeWithdrawals.map(BodyValidation::withdrawalsRoot).orElse(null)) - .excessBlobGas(BlobGas.ZERO) - .blobGasUsed(0L) - .requestsHash(maybeRequests.map(BodyValidation::requestsHash).orElse(null)) - .parentBeaconBlockRoot( - maybeParentBeaconBlockRoot.isPresent() ? maybeParentBeaconBlockRoot : null) - .buildHeader(); - return mockHeader; + return new BlockHeaderTestFixture() + .baseFeePerGas(Wei.ONE) + .parentHash(parentBlockHeader.getParentHash()) + .number(parentBlockHeader.getNumber() + 1) + .timestamp(parentBlockHeader.getTimestamp() + 1) + .withdrawalsRoot(maybeWithdrawals.map(BodyValidation::withdrawalsRoot).orElse(null)) + .excessBlobGas(BlobGas.ZERO) + .blobGasUsed(0L) + .parentBeaconBlockRoot( + maybeParentBeaconBlockRoot.isPresent() ? maybeParentBeaconBlockRoot : null); + } + + @Override + protected BlockHeader createBlockHeader(final Optional> maybeWithdrawals) { + return createValidBlockHeaderForV4(maybeWithdrawals); } @Override protected JsonRpcResponse resp(final EnginePayloadParameter payload) { + final List requestsWithoutRequestId = + VALID_REQUESTS.stream() + .sorted(Comparator.comparing(Request::getType)) + .map(r -> r.getData().toHexString()) + .toList(); Object[] params = maybeParentBeaconBlockRoot - .map(bytes32 -> new Object[] {payload, Collections.emptyList(), bytes32.toHexString()}) + .map( + bytes32 -> + new Object[] { + payload, emptyList(), bytes32.toHexString(), requestsWithoutRequestId + }) .orElseGet(() -> new Object[] {payload}); return method.response( new JsonRpcRequestContext(new JsonRpcRequest("2.0", this.method.getName(), params))); } - protected JsonRpcResponse resp( - final EnginePayloadParameter payload, final List requests) { - final List requestsWithoutRequestId = - requests.stream() - .sorted(Comparator.comparing(Request::getType)) - .map(r -> r.getData().toHexString()) - .toList(); + protected JsonRpcResponse respWithInvalidRequests(final EnginePayloadParameter payload) { Object[] params = maybeParentBeaconBlockRoot .map( bytes32 -> - new Object[] { - payload, - Collections.emptyList(), - bytes32.toHexString(), - requestsWithoutRequestId + new Object[] {payload, emptyList(), bytes32.toHexString() + // empty requests param is invalid }) .orElseGet(() -> new Object[] {payload}); return method.response( From 24ed2d0b21633cea067d64bdf37c1a0c671801cf Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Thu, 31 Oct 2024 18:09:22 +1000 Subject: [PATCH 07/56] update discord invite link (#7836) Signed-off-by: Sally MacFarlane --- CONTRIBUTING.md | 2 +- MAINTAINERS.md | 2 +- README.md | 4 ++-- SUPPORT.md | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c2d6c57d25a..c13ea678524 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,7 +8,7 @@ Welcome to the Besu repository! The following links are a set of guidelines for Having the following accounts is necessary for contributing code/issues to Besu. * If you want to contribute code, you can make a [github account here](https://github.com). * If you want to raise an issue, do so [in the issues tab](https://github.com/hyperledger/besu/issues). -* To ask questions or chat with us, join our [Discord](https://discord.gg/hyperledger) +* To ask questions or chat with us, join our [Discord](https://discord.com/invite/hyperledger) * To edit pages in our wiki, you'll need a [Linux Foundation (LF) account]. ### Useful contributing links diff --git a/MAINTAINERS.md b/MAINTAINERS.md index ae6720632a4..afb82b6fc59 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -84,7 +84,7 @@ The following steps must occur for a contributor to be "upgraded" as a maintaine - The proposed maintainer accepts the nomination and expresses a willingness to be a long-term (more than 6 month) committer by adding a comment in the proposal PR. - The PR will be communicated in all appropriate communication channels - including at least [besu-contributors channel on Discord](https://discord.gg/hyperledger), + including at least [besu-contributors channel on Discord](https://discord.com/invite/hyperledger), the [mailing list](https://lists.hyperledger.org/g/besu) and any maintainer/community call. - Approval by at least 3 current maintainers within two weeks of the proposal or diff --git a/README.md b/README.md index 7139df85805..8f5f51a7264 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Documentation](https://img.shields.io/github/actions/workflow/status/hyperledger/besu-docs/publish-main-docs.yml?branch=main&label=docs)](https://github.com/hyperledger/besu-docs/actions/workflows/publish-main-docs.yml) [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/3174/badge)](https://bestpractices.coreinfrastructure.org/projects/3174) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/hyperledger/besu/blob/main/LICENSE) - [![Discord](https://img.shields.io/discord/905194001349627914?logo=Hyperledger&style=plastic)](https://discord.gg/hyperledger) + [![Discord](https://img.shields.io/discord/905194001349627914?logo=Hyperledger&style=plastic)](https://discord.com/invite/hyperledger) [![Twitter Follow](https://img.shields.io/twitter/follow/HyperledgerBesu)](https://twitter.com/HyperledgerBesu) [Download](https://github.com/hyperledger/besu/releases) @@ -67,5 +67,5 @@ and YourKit YouMonitor. [Besu Issues]: https://github.com/hyperledger/besu/issues [Besu User Documentation]: https://besu.hyperledger.org -[Besu channel on Discord]: https://discord.gg/hyperledger +[Besu channel on Discord]: https://discord.com/invite/hyperledger [Contributing Guidelines]: CONTRIBUTING.md diff --git a/SUPPORT.md b/SUPPORT.md index 9e4a7b7b42b..97715857cb4 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -20,5 +20,5 @@ Having Github, Discord, and Linux Foundation accounts is necessary for obtaining [Besu User Documentation]: https://besu.hyperledger.org -[Besu channel on Discord]: https://discord.gg/hyperledger +[Besu channel on Discord]: https://discord.com/invite/hyperledger [Contributing Guidelines]: CONTRIBUTING.md From d846e3749bed4d1d665d2a20435d4421efbefefe Mon Sep 17 00:00:00 2001 From: garyschulte Date: Thu, 31 Oct 2024 12:18:27 -0700 Subject: [PATCH 08/56] Remove retesteth rpc service and commands (#7833) * remove retesteth rpc service and commands Signed-off-by: garyschulte --- CHANGELOG.md | 1 + .../org/hyperledger/besu/cli/BesuCommand.java | 2 - .../cli/subcommands/RetestethSubCommand.java | 149 ------- ethereum/retesteth/build.gradle | 58 --- .../NoRewardProtocolScheduleWrapper.java | 145 ------- .../ethereum/retesteth/RetestethClock.java | 60 --- .../retesteth/RetestethConfiguration.java | 30 -- .../ethereum/retesteth/RetestethContext.java | 370 ------------------ .../ethereum/retesteth/RetestethService.java | 122 ------ .../retesteth/methods/TestGetLogHash.java | 73 ---- .../retesteth/methods/TestImportRawBlock.java | 107 ----- .../retesteth/methods/TestMineBlocks.java | 97 ----- .../methods/TestModifyTimestamp.java | 51 --- .../retesteth/methods/TestRewindToBlock.java | 53 --- .../retesteth/methods/TestSetChainParams.java | 159 -------- .../methods/TestImportRawBlockTest.java | 129 ------ .../methods/TestSetChainParamsTest.java | 115 ------ .../retesteth/methods/1559ChainParams.json | 21 - ...ultimpleBalanceInstructionChainParams.json | 102 ----- 19 files changed, 1 insertion(+), 1843 deletions(-) delete mode 100644 besu/src/main/java/org/hyperledger/besu/cli/subcommands/RetestethSubCommand.java delete mode 100644 ethereum/retesteth/build.gradle delete mode 100644 ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/NoRewardProtocolScheduleWrapper.java delete mode 100644 ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethClock.java delete mode 100644 ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethConfiguration.java delete mode 100644 ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java delete mode 100644 ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethService.java delete mode 100644 ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestGetLogHash.java delete mode 100644 ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.java delete mode 100644 ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java delete mode 100644 ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestModifyTimestamp.java delete mode 100644 ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestRewindToBlock.java delete mode 100644 ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestSetChainParams.java delete mode 100644 ethereum/retesteth/src/test/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlockTest.java delete mode 100644 ethereum/retesteth/src/test/java/org/hyperledger/besu/ethereum/retesteth/methods/TestSetChainParamsTest.java delete mode 100644 ethereum/retesteth/src/test/resources/org/hyperledger/besu/ethereum/retesteth/methods/1559ChainParams.json delete mode 100644 ethereum/retesteth/src/test/resources/org/hyperledger/besu/ethereum/retesteth/methods/multimpleBalanceInstructionChainParams.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 26342cf7be5..41aea176def 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Added isLabelsObserved to LabelledGauge in plugin-api. Default implementation returns false. ### Breaking Changes +- Removed Retesteth rpc service and commands [#7833](https://github.com/hyperledger/besu/pull/7783) ### Upcoming Breaking Changes diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index bf79da288da..8a012367256 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -74,7 +74,6 @@ import org.hyperledger.besu.cli.presynctasks.PrivateDatabaseMigrationPreSyncTask; import org.hyperledger.besu.cli.subcommands.PasswordSubCommand; import org.hyperledger.besu.cli.subcommands.PublicKeySubCommand; -import org.hyperledger.besu.cli.subcommands.RetestethSubCommand; import org.hyperledger.besu.cli.subcommands.TxParseSubCommand; import org.hyperledger.besu.cli.subcommands.ValidateConfigSubCommand; import org.hyperledger.besu.cli.subcommands.blocks.BlocksSubCommand; @@ -1105,7 +1104,6 @@ private void addSubCommands(final InputStream in) { PublicKeySubCommand.COMMAND_NAME, new PublicKeySubCommand(commandLine.getOut())); commandLine.addSubcommand( PasswordSubCommand.COMMAND_NAME, new PasswordSubCommand(commandLine.getOut())); - commandLine.addSubcommand(RetestethSubCommand.COMMAND_NAME, new RetestethSubCommand()); commandLine.addSubcommand( RLPSubCommand.COMMAND_NAME, new RLPSubCommand(commandLine.getOut(), in)); commandLine.addSubcommand( diff --git a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/RetestethSubCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/RetestethSubCommand.java deleted file mode 100644 index 67af49c400e..00000000000 --- a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/RetestethSubCommand.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * 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.cli.subcommands; - -import static org.hyperledger.besu.cli.subcommands.RetestethSubCommand.COMMAND_NAME; - -import org.hyperledger.besu.BesuInfo; -import org.hyperledger.besu.cli.DefaultCommandValues; -import org.hyperledger.besu.cli.custom.JsonRPCAllowlistHostsProperty; -import org.hyperledger.besu.cli.options.stable.LoggingLevelOption; -import org.hyperledger.besu.cli.util.VersionProvider; -import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration; -import org.hyperledger.besu.ethereum.retesteth.RetestethConfiguration; -import org.hyperledger.besu.ethereum.retesteth.RetestethService; -import org.hyperledger.besu.util.LogConfigurator; - -import java.net.InetAddress; -import java.nio.file.Path; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import picocli.CommandLine.Command; -import picocli.CommandLine.Mixin; -import picocli.CommandLine.Option; - -/** Subcommand to run a Retesteth compatible server for reference tests. */ -@Command( - name = COMMAND_NAME, - description = "Run a Retesteth compatible server for reference tests.", - mixinStandardHelpOptions = true, - versionProvider = VersionProvider.class) -@SuppressWarnings("unused") -public class RetestethSubCommand implements Runnable { - - private static final Logger LOG = LoggerFactory.getLogger(RetestethSubCommand.class); - - /** The constant COMMAND_NAME. */ - public static final String COMMAND_NAME = "retesteth"; - - /** - * Using a distinct port for retesteth will result in less testing collisions and accidental RPC - * calls. This is 0xba5e in hex, a hex speak play on the english translation of - * "Besu." - */ - public static final int RETESTETH_PORT = 47710; - - @Option( - names = {"--data-path"}, - paramLabel = DefaultCommandValues.MANDATORY_PATH_FORMAT_HELP, - description = "The path to Besu data directory (default: ${DEFAULT-VALUE})") - private final Path dataPath = DefaultCommandValues.getDefaultBesuDataPath(this); - - @Mixin private LoggingLevelOption loggingLevelOption; - - @SuppressWarnings({"FieldCanBeFinal", "FieldMayBeFinal"}) // PicoCLI requires non-final Strings. - @Option( - names = {"--rpc-http-host"}, - paramLabel = DefaultCommandValues.MANDATORY_HOST_FORMAT_HELP, - description = "Host for Retesteth JSON-RPC HTTP to listen on (default: ${DEFAULT-VALUE})", - arity = "1") - private String rpcHttpHost = autoDiscoverDefaultIP().getHostAddress(); - - @Option( - names = {"--rpc-http-port"}, - paramLabel = DefaultCommandValues.MANDATORY_PORT_FORMAT_HELP, - description = "Port for Retesteth JSON-RPC HTTP to listen on (default: ${DEFAULT-VALUE})", - arity = "1") - private final Integer rpcHttpPort = RETESTETH_PORT; - - @Option( - names = {"--host-allowlist", "--host-whitelist"}, - paramLabel = "[,...]... or * or all", - description = - "Comma separated list of hostnames to allow for RPC access, or * to accept any host (default: ${DEFAULT-VALUE})", - defaultValue = "localhost,127.0.0.1") - private final JsonRPCAllowlistHostsProperty hostsAllowlist = new JsonRPCAllowlistHostsProperty(); - - private InetAddress autoDiscoveredDefaultIP; - - /** Default Constructor. */ - public RetestethSubCommand() {} - - // Used to discover the default IP of the client. - // Loopback IP is used by default as this is how smokeTests require it to be - // and it's probably a good security behaviour to default only on the localhost. - private InetAddress autoDiscoverDefaultIP() { - - if (autoDiscoveredDefaultIP != null) { - return autoDiscoveredDefaultIP; - } - - autoDiscoveredDefaultIP = InetAddress.getLoopbackAddress(); - - return autoDiscoveredDefaultIP; - } - - private void prepareLogging() { - // set log level per CLI flags - final String logLevel = loggingLevelOption.getLogLevel(); - if (logLevel != null) { - System.out.println("Setting logging level to " + logLevel); - LogConfigurator.setLevel("", logLevel); - } - } - - @Override - public void run() { - prepareLogging(); - - final RetestethConfiguration retestethConfiguration = new RetestethConfiguration(dataPath); - final JsonRpcConfiguration jsonRpcConfiguration = JsonRpcConfiguration.createDefault(); - jsonRpcConfiguration.setHost(rpcHttpHost); - jsonRpcConfiguration.setPort(rpcHttpPort); - jsonRpcConfiguration.setHostsAllowlist(hostsAllowlist); - - final RetestethService retestethService = - new RetestethService(BesuInfo.version(), retestethConfiguration, jsonRpcConfiguration); - - Runtime.getRuntime() - .addShutdownHook( - new Thread( - () -> { - try { - retestethService.close(); - LogConfigurator.shutdown(); - } catch (final Exception e) { - LOG.error("Failed to stop Besu Retesteth"); - } - })); - retestethService.start(); - try { - Thread.sleep(Long.MAX_VALUE); // Is there a better way? - } catch (final InterruptedException e) { - // e.printStackTrace(); - } - } -} diff --git a/ethereum/retesteth/build.gradle b/ethereum/retesteth/build.gradle deleted file mode 100644 index 484953a3919..00000000000 --- a/ethereum/retesteth/build.gradle +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2019 ConsenSys AG. - * - * 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. - */ - -apply plugin: 'java-library' - -jar { - archiveBaseName = 'besu-retesteth' - manifest { - attributes( - 'Specification-Title': archiveBaseName, - 'Specification-Version': project.version, - 'Implementation-Title': archiveBaseName, - 'Implementation-Version': calculateVersion(), - 'Commit-Hash': getGitCommitDetails(40).hash - ) - } -} - -dependencies { - api 'org.slf4j:slf4j-api' - - implementation project(':config') - implementation project(':datatypes') - implementation project(':ethereum:api') - implementation project(':ethereum:api') - implementation project(':ethereum:blockcreation') - implementation project(':ethereum:core') - implementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts') - implementation project(':ethereum:eth') - implementation project(':ethereum:p2p') - implementation project(':ethereum:rlp') - implementation project(':evm') - implementation project(':metrics:core') - implementation project(':nat') - implementation project(':services:kvstore') - implementation project(':util') - - implementation 'com.google.guava:guava' - implementation 'io.vertx:vertx-core' - implementation 'io.vertx:vertx-web' - implementation 'com.fasterxml.jackson.core:jackson-databind' - implementation 'io.tmio:tuweni-bytes' - implementation 'io.tmio:tuweni-units' - - testImplementation 'org.assertj:assertj-core' - testImplementation 'org.junit.jupiter:junit-jupiter' - testImplementation 'org.mockito:mockito-core' -} diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/NoRewardProtocolScheduleWrapper.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/NoRewardProtocolScheduleWrapper.java deleted file mode 100644 index db1ac943f01..00000000000 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/NoRewardProtocolScheduleWrapper.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * 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.ethereum.retesteth; - -import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.BlockValidator; -import org.hyperledger.besu.ethereum.MainnetBlockValidator; -import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.BlockImporter; -import org.hyperledger.besu.ethereum.core.PermissionTransactionFilter; -import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader; -import org.hyperledger.besu.ethereum.mainnet.BlockProcessor; -import org.hyperledger.besu.ethereum.mainnet.MainnetBlockImporter; -import org.hyperledger.besu.ethereum.mainnet.MainnetBlockProcessor; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; -import org.hyperledger.besu.ethereum.mainnet.ScheduledProtocolSpec; -import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; - -import java.math.BigInteger; -import java.util.Optional; -import java.util.function.Predicate; - -public class NoRewardProtocolScheduleWrapper implements ProtocolSchedule { - - private final ProtocolSchedule delegate; - private final BadBlockManager badBlockManager; - - NoRewardProtocolScheduleWrapper( - final ProtocolSchedule delegate, final BadBlockManager badBlockManager) { - this.delegate = delegate; - this.badBlockManager = badBlockManager; - } - - @Override - public ProtocolSpec getByBlockHeader(final ProcessableBlockHeader blockHeader) { - final ProtocolSpec original = delegate.getByBlockHeader(blockHeader); - final BlockProcessor noRewardBlockProcessor = - new MainnetBlockProcessor( - original.getTransactionProcessor(), - original.getTransactionReceiptFactory(), - Wei.ZERO, - original.getMiningBeneficiaryCalculator(), - original.isSkipZeroBlockRewards(), - delegate); - final BlockValidator noRewardBlockValidator = - new MainnetBlockValidator( - original.getBlockHeaderValidator(), - original.getBlockBodyValidator(), - noRewardBlockProcessor, - badBlockManager); - final BlockImporter noRewardBlockImporter = new MainnetBlockImporter(noRewardBlockValidator); - return new ProtocolSpec( - original.getName(), - original.getEvm(), - original.getTransactionValidatorFactory(), - original.getTransactionProcessor(), - original.getPrivateTransactionProcessor(), - original.getBlockHeaderValidator(), - original.getOmmerHeaderValidator(), - original.getBlockBodyValidator(), - noRewardBlockProcessor, - noRewardBlockImporter, - noRewardBlockValidator, - original.getBlockHeaderFunctions(), - original.getTransactionReceiptFactory(), - original.getDifficultyCalculator(), - Wei.ZERO, // block reward - original.getMiningBeneficiaryCalculator(), - original.getPrecompileContractRegistry(), - original.isSkipZeroBlockRewards(), - original.getGasCalculator(), - original.getGasLimitCalculator(), - original.getFeeMarket(), - Optional.empty(), - original.getWithdrawalsValidator(), - original.getWithdrawalsProcessor(), - original.getRequestsValidator(), - original.getRequestProcessorCoordinator(), - original.getBlockHashProcessor(), - original.isPoS(), - original.isReplayProtectionSupported()); - } - - @Override - public boolean anyMatch(final Predicate predicate) { - return delegate.anyMatch(predicate); - } - - @Override - public boolean isOnMilestoneBoundary(final BlockHeader blockHeader) { - return delegate.isOnMilestoneBoundary(blockHeader); - } - - @Override - public Optional getChainId() { - return delegate.getChainId(); - } - - @Override - public void putBlockNumberMilestone(final long blockNumber, final ProtocolSpec protocolSpec) { - delegate.putBlockNumberMilestone(blockNumber, protocolSpec); - } - - @Override - public void putTimestampMilestone(final long timestamp, final ProtocolSpec protocolSpec) { - delegate.putTimestampMilestone(timestamp, protocolSpec); - } - - @Override - public Optional hardforkFor( - final Predicate predicate) { - return delegate.hardforkFor(predicate); - } - - @Override - public String listMilestones() { - return delegate.listMilestones(); - } - - @Override - public void setPermissionTransactionFilter( - final PermissionTransactionFilter permissionTransactionFilter) { - delegate.setPermissionTransactionFilter(permissionTransactionFilter); - } - - @Override - public void setPublicWorldStateArchiveForPrivacyBlockProcessor( - final WorldStateArchive publicWorldStateArchive) { - delegate.setPublicWorldStateArchiveForPrivacyBlockProcessor(publicWorldStateArchive); - } -} diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethClock.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethClock.java deleted file mode 100644 index fdd22f42b04..00000000000 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethClock.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * 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.ethereum.retesteth; - -import java.time.Clock; -import java.time.Instant; -import java.time.ZoneId; -import java.util.Optional; - -public class RetestethClock extends Clock { - - private Optional fixedInstant; - private final Clock delegateClock; - - RetestethClock() { - this(Clock.systemUTC()); - } - - private RetestethClock(final Clock delegateClock) { - fixedInstant = Optional.empty(); - this.delegateClock = delegateClock; - } - - @Override - public ZoneId getZone() { - return delegateClock.getZone(); - } - - @Override - public Clock withZone(final ZoneId zone) { - final RetestethClock zonedClock = new RetestethClock(delegateClock.withZone(zone)); - zonedClock.fixedInstant = fixedInstant; - return zonedClock; - } - - @Override - public Instant instant() { - return fixedInstant.orElseGet(delegateClock::instant); - } - - public void resetTime(final long time) { - fixedInstant = Optional.of(Instant.ofEpochSecond(time)); - } - - public void advanceSeconds(final long seconds) { - fixedInstant = Optional.of(Instant.ofEpochSecond(instant().getEpochSecond() + seconds)); - } -} diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethConfiguration.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethConfiguration.java deleted file mode 100644 index bb4fa31a559..00000000000 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethConfiguration.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * 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.ethereum.retesteth; - -import java.nio.file.Path; - -public class RetestethConfiguration { - - private final Path dataPath; - - public RetestethConfiguration(final Path dataPath) { - this.dataPath = dataPath; - } - - Path getDataPath() { - return dataPath; - } -} diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java deleted file mode 100644 index 32d4e0bab10..00000000000 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java +++ /dev/null @@ -1,370 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * 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.ethereum.retesteth; - -import static org.hyperledger.besu.config.JsonUtil.normalizeKeys; - -import org.hyperledger.besu.config.JsonGenesisConfigOptions; -import org.hyperledger.besu.config.JsonUtil; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.ProtocolContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockReplay; -import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; -import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.chain.DefaultBlockchain; -import org.hyperledger.besu.ethereum.chain.GenesisState; -import org.hyperledger.besu.ethereum.chain.MutableBlockchain; -import org.hyperledger.besu.ethereum.chain.VariablesStorage; -import org.hyperledger.besu.ethereum.core.Block; -import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.Unstable; -import org.hyperledger.besu.ethereum.core.MiningParameters; -import org.hyperledger.besu.ethereum.core.MutableWorldState; -import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; -import org.hyperledger.besu.ethereum.eth.manager.EthContext; -import org.hyperledger.besu.ethereum.eth.manager.EthMessages; -import org.hyperledger.besu.ethereum.eth.manager.EthPeers; -import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; -import org.hyperledger.besu.ethereum.eth.sync.SyncMode; -import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; -import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; -import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration; -import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; -import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration; -import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolFactory; -import org.hyperledger.besu.ethereum.forkid.ForkIdManager; -import org.hyperledger.besu.ethereum.mainnet.EpochCalculator; -import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode; -import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; -import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule; -import org.hyperledger.besu.ethereum.mainnet.PoWHasher; -import org.hyperledger.besu.ethereum.mainnet.PoWSolution; -import org.hyperledger.besu.ethereum.mainnet.PoWSolver; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; -import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions; -import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage; -import org.hyperledger.besu.ethereum.storage.keyvalue.VariablesKeyValueStorage; -import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStatePreimageKeyValueStorage; -import org.hyperledger.besu.ethereum.trie.forest.ForestWorldStateArchive; -import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; -import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; -import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; -import org.hyperledger.besu.evm.internal.EvmConfiguration; -import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; -import org.hyperledger.besu.plugin.services.MetricsSystem; -import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage; -import org.hyperledger.besu.util.Subscribers; -import org.hyperledger.besu.util.number.Fraction; - -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.locks.ReentrantLock; -import java.util.function.Supplier; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; -import org.apache.tuweni.units.bigints.UInt256; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class RetestethContext { - - private static final Logger LOG = LoggerFactory.getLogger(RetestethContext.class); - private static final PoWHasher NO_WORK_HASHER = - (final long nonce, final long number, EpochCalculator epochCalc, final Bytes headerHash) -> - new PoWSolution(nonce, Hash.ZERO, UInt256.ZERO, Hash.ZERO); - public static final int MAX_PEERS = 25; - - private final ReentrantLock contextLock = new ReentrantLock(); - private final BadBlockManager badBlockManager = new BadBlockManager(); - private Address coinbase; - private Bytes extraData; - private MutableBlockchain blockchain; - private ProtocolContext protocolContext; - private BlockchainQueries blockchainQueries; - private ProtocolSchedule protocolSchedule; - private BlockHeaderFunctions blockHeaderFunctions; - private HeaderValidationMode headerValidationMode; - private BlockReplay blockReplay; - private RetestethClock retestethClock; - private MiningParameters miningParameters; - private TransactionPool transactionPool; - private EthScheduler ethScheduler; - private PoWSolver poWSolver; - - private Optional terminalTotalDifficulty; - private Optional mixHash; - - public boolean resetContext( - final String genesisConfigString, final String sealEngine, final Optional clockTime) { - contextLock.lock(); - try { - tearDownContext(); - return buildContext(genesisConfigString, sealEngine, clockTime); - } catch (final Exception e) { - LOG.error("Error shutting down existing runner", e); - return false; - } finally { - contextLock.unlock(); - } - } - - private void tearDownContext() { - try { - if (ethScheduler != null) { - ethScheduler.stop(); - ethScheduler.awaitStop(); - } - } catch (final InterruptedException e) { - throw new RuntimeException(e); - } - } - - private boolean buildContext( - final String genesisConfigString, final String sealEngine, final Optional clockTime) { - final ObjectNode genesisConfig = - normalizeKeys(JsonUtil.objectNodeFromString(genesisConfigString)); - - retestethClock = new RetestethClock(); - clockTime.ifPresent(retestethClock::resetTime); - final MetricsSystem metricsSystem = new NoOpMetricsSystem(); - - terminalTotalDifficulty = - Optional.ofNullable(genesisConfig.get("params")) - .map(n -> n.get("terminaltotaldifficulty")) - .map(JsonNode::asText) - .map(Bytes::fromHexString); - - final JsonGenesisConfigOptions jsonGenesisConfigOptions = - JsonGenesisConfigOptions.fromJsonObject( - JsonUtil.getObjectNode(genesisConfig, "config").get()); - protocolSchedule = - MainnetProtocolSchedule.fromConfig( - jsonGenesisConfigOptions, - EvmConfiguration.DEFAULT, - miningParameters, - badBlockManager, - false, - new NoOpMetricsSystem()); - if ("NoReward".equalsIgnoreCase(sealEngine)) { - protocolSchedule = new NoRewardProtocolScheduleWrapper(protocolSchedule, badBlockManager); - } - blockHeaderFunctions = ScheduleBasedBlockHeaderFunctions.create(protocolSchedule); - - final GenesisState genesisState = GenesisState.fromJson(genesisConfigString, protocolSchedule); - coinbase = genesisState.getBlock().getHeader().getCoinbase(); - extraData = genesisState.getBlock().getHeader().getExtraData(); - mixHash = Optional.ofNullable(genesisState.getBlock().getHeader().getMixHashOrPrevRandao()); - - final WorldStateArchive worldStateArchive = - new ForestWorldStateArchive( - new WorldStateStorageCoordinator( - new ForestWorldStateKeyValueStorage(new InMemoryKeyValueStorage())), - new WorldStatePreimageKeyValueStorage(new InMemoryKeyValueStorage()), - EvmConfiguration.DEFAULT); - final MutableWorldState worldState = worldStateArchive.getMutable(); - genesisState.writeStateTo(worldState); - - blockchain = createInMemoryBlockchain(genesisState.getBlock()); - protocolContext = new ProtocolContext(blockchain, worldStateArchive, null, badBlockManager); - - blockchainQueries = - new BlockchainQueries( - protocolSchedule, blockchain, worldStateArchive, ethScheduler, miningParameters); - - final String sealengine = JsonUtil.getString(genesisConfig, "sealengine", ""); - headerValidationMode = - "NoProof".equals(sealengine) || "NoReward".equals(sealEngine) - ? HeaderValidationMode.LIGHT - : HeaderValidationMode.FULL; - - miningParameters = - ImmutableMiningParameters.builder() - .mutableInitValues( - MutableInitValues.builder() - .coinbase(coinbase) - .extraData(extraData) - .targetGasLimit(blockchain.getChainHeadHeader().getGasLimit()) - .minBlockOccupancyRatio(0.0) - .minTransactionGasPrice(Wei.ZERO) - .build()) - .unstable(Unstable.builder().powJobTimeToLive(1000).maxOmmerDepth(8).build()) - .build(); - miningParameters.setMinTransactionGasPrice(Wei.ZERO); - poWSolver = - ("NoProof".equals(sealengine) || "NoReward".equals(sealEngine)) - ? new PoWSolver( - miningParameters, - NO_WORK_HASHER, - false, - Subscribers.none(), - new EpochCalculator.DefaultEpochCalculator()) - : new PoWSolver( - miningParameters, - PoWHasher.ETHASH_LIGHT, - false, - Subscribers.none(), - new EpochCalculator.DefaultEpochCalculator()); - - blockReplay = - new BlockReplay(protocolSchedule, protocolContext, blockchainQueries.getBlockchain()); - - final Bytes localNodeKey = Bytes.wrap(new byte[64]); - - // mining support - - final Supplier currentProtocolSpecSupplier = - () -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()); - final EthPeers ethPeers = - new EthPeers( - "reteseth", - currentProtocolSpecSupplier, - retestethClock, - metricsSystem, - EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE, - Collections.emptyList(), - localNodeKey, - MAX_PEERS, - MAX_PEERS, - false, - SyncMode.FAST, - new ForkIdManager(blockchain, List.of(), List.of(), false)); - final SyncState syncState = new SyncState(blockchain, ethPeers); - - ethScheduler = new EthScheduler(1, 1, 1, 1, metricsSystem); - final EthContext ethContext = new EthContext(ethPeers, new EthMessages(), ethScheduler); - - final TransactionPoolConfiguration transactionPoolConfiguration = - ImmutableTransactionPoolConfiguration.builder() - .txPoolLimitByAccountPercentage(Fraction.fromFloat(0.004f)) - .build(); - - transactionPool = - TransactionPoolFactory.createTransactionPool( - protocolSchedule, - protocolContext, - ethContext, - retestethClock, - metricsSystem, - syncState, - transactionPoolConfiguration, - new BlobCache(), - MiningParameters.newDefault()); - - if (LOG.isTraceEnabled()) { - LOG.trace("Genesis Block {} ", genesisState.getBlock()); - } - - return true; - } - - private static MutableBlockchain createInMemoryBlockchain(final Block genesisBlock) { - return createInMemoryBlockchain(genesisBlock, new MainnetBlockHeaderFunctions()); - } - - private static MutableBlockchain createInMemoryBlockchain( - final Block genesisBlock, final BlockHeaderFunctions blockHeaderFunctions) { - final InMemoryKeyValueStorage keyValueStorage = new InMemoryKeyValueStorage(); - final VariablesStorage variablesStorage = - new VariablesKeyValueStorage(new InMemoryKeyValueStorage()); - return DefaultBlockchain.createMutable( - genesisBlock, - new KeyValueStoragePrefixedKeyBlockchainStorage( - keyValueStorage, variablesStorage, blockHeaderFunctions, false), - new NoOpMetricsSystem(), - 100); - } - - public ProtocolSchedule getProtocolSchedule() { - return protocolSchedule; - } - - public BlockHeaderFunctions getBlockHeaderFunctions() { - return blockHeaderFunctions; - } - - public ProtocolContext getProtocolContext() { - return protocolContext; - } - - public EthScheduler getEthScheduler() { - return ethScheduler; - } - - public void setEthScheduler(final EthScheduler ethScheduler) { - this.ethScheduler = ethScheduler; - } - - public long getBlockHeight() { - return blockchain.getChainHeadBlockNumber(); - } - - public ProtocolSpec getProtocolSpec(final BlockHeader blockHeader) { - return getProtocolSchedule().getByBlockHeader(blockHeader); - } - - public BlockHeader getBlockHeader(final long blockNumber) { - return blockchain.getBlockHeader(blockNumber).get(); - } - - public BlockchainQueries getBlockchainQueries() { - return blockchainQueries; - } - - public HeaderValidationMode getHeaderValidationMode() { - return headerValidationMode; - } - - BlockReplay getBlockReplay() { - return blockReplay; - } - - public TransactionPool getTransactionPool() { - return transactionPool; - } - - public MiningParameters getMiningParameters() { - return miningParameters; - } - - public MutableBlockchain getBlockchain() { - return blockchain; - } - - public RetestethClock getRetestethClock() { - return retestethClock; - } - - public Optional getTerminalTotalDifficulty() { - return terminalTotalDifficulty; - } - - public Optional getMixHash() { - return mixHash; - } - - public PoWSolver getEthHashSolver() { - return poWSolver; - } -} diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethService.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethService.java deleted file mode 100644 index 877c5976862..00000000000 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethService.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * 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.ethereum.retesteth; - -import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration; -import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcHttpService; -import org.hyperledger.besu.ethereum.api.jsonrpc.health.HealthService; -import org.hyperledger.besu.ethereum.api.jsonrpc.health.LivenessCheck; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugAccountRange; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugStorageRangeAt; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthBlockNumber; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetBalance; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetBlockByHash; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetBlockByNumber; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetCode; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetTransactionCount; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthSendRawTransaction; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.Web3ClientVersion; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory; -import org.hyperledger.besu.ethereum.core.DummySynchronizer; -import org.hyperledger.besu.ethereum.core.Synchronizer; -import org.hyperledger.besu.ethereum.retesteth.methods.TestGetLogHash; -import org.hyperledger.besu.ethereum.retesteth.methods.TestImportRawBlock; -import org.hyperledger.besu.ethereum.retesteth.methods.TestMineBlocks; -import org.hyperledger.besu.ethereum.retesteth.methods.TestModifyTimestamp; -import org.hyperledger.besu.ethereum.retesteth.methods.TestRewindToBlock; -import org.hyperledger.besu.ethereum.retesteth.methods.TestSetChainParams; -import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; -import org.hyperledger.besu.nat.NatService; - -import java.util.Arrays; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; - -import io.vertx.core.Vertx; - -public class RetestethService { - - private final JsonRpcHttpService jsonRpcHttpService; - private final Vertx vertx; - - private final RetestethContext retestethContext; - - public RetestethService( - final String clientVersion, - final RetestethConfiguration retestethConfiguration, - final JsonRpcConfiguration jsonRpcConfiguration) { - vertx = Vertx.vertx(); - retestethContext = new RetestethContext(); - - final BlockResultFactory blockResult = new BlockResultFactory(); - final NatService natService = new NatService(Optional.empty()); - - // Synchronizer needed by RPC methods. Didn't wanna mock it, since this isn't the test module. - Synchronizer sync = new DummySynchronizer(); - - final Map jsonRpcMethods = - mapOf( - new Web3ClientVersion(clientVersion), - new TestSetChainParams(retestethContext), - new TestImportRawBlock(retestethContext), - new EthBlockNumber(retestethContext::getBlockchainQueries, true), - new EthGetBlockByNumber( - retestethContext::getBlockchainQueries, blockResult, sync, true), - new DebugAccountRange(retestethContext::getBlockchainQueries), - new EthGetBalance(retestethContext::getBlockchainQueries), - new EthGetBlockByHash(retestethContext::getBlockchainQueries, blockResult, true), - new EthGetCode(retestethContext::getBlockchainQueries), - new EthGetTransactionCount( - retestethContext::getBlockchainQueries, retestethContext::getTransactionPool), - new DebugStorageRangeAt( - retestethContext::getBlockchainQueries, retestethContext::getBlockReplay, true), - new TestModifyTimestamp(retestethContext), - new EthSendRawTransaction(retestethContext::getTransactionPool, true), - new TestMineBlocks(retestethContext), - new TestGetLogHash(retestethContext), - new TestRewindToBlock(retestethContext)); - - jsonRpcHttpService = - new JsonRpcHttpService( - vertx, - retestethConfiguration.getDataPath(), - jsonRpcConfiguration, - new NoOpMetricsSystem(), - natService, - jsonRpcMethods, - new HealthService(new LivenessCheck()), - HealthService.ALWAYS_HEALTHY); - } - - public void start() { - jsonRpcHttpService.start(); - } - - public void close() { - stop(); - } - - public void stop() { - jsonRpcHttpService.stop(); - vertx.close(); - } - - private static Map mapOf(final JsonRpcMethod... rpcMethods) { - return Arrays.stream(rpcMethods) - .collect(Collectors.toMap(JsonRpcMethod::getName, rpcMethod -> rpcMethod)); - } -} diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestGetLogHash.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestGetLogHash.java deleted file mode 100644 index 398d72d6653..00000000000 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestGetLogHash.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * 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.ethereum.retesteth.methods; - -import org.hyperledger.besu.datatypes.Hash; -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.JsonRpcParameter.JsonRpcParameterException; -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.TransactionReceiptWithMetadata; -import org.hyperledger.besu.ethereum.retesteth.RetestethContext; -import org.hyperledger.besu.ethereum.rlp.RLP; -import org.hyperledger.besu.evm.log.Log; - -import java.util.Optional; - -public class TestGetLogHash implements JsonRpcMethod { - private final RetestethContext context; - - public TestGetLogHash(final RetestethContext context) { - this.context = context; - } - - @Override - public String getName() { - return "test_getLogHash"; - } - - @Override - public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final Hash txHash; - try { - txHash = requestContext.getRequiredParameter(0, Hash.class); - } catch (JsonRpcParameterException e) { - throw new InvalidJsonRpcParameters( - "Invalid transaction hash parameter (index 0)", - RpcErrorType.INVALID_TRANSACTION_HASH_PARAMS, - e); - } - - final Optional receipt = - context - .getBlockchainQueries() - .transactionReceiptByTransactionHash(txHash, context.getProtocolSchedule()); - return new JsonRpcSuccessResponse( - requestContext.getRequest().getId(), - receipt.map(this::calculateLogHash).orElse(Hash.EMPTY_LIST_HASH).toString()); - } - - private Hash calculateLogHash( - final TransactionReceiptWithMetadata transactionReceiptWithMetadata) { - return Hash.hash( - RLP.encode( - out -> - out.writeList( - transactionReceiptWithMetadata.getReceipt().getLogsList(), Log::writeTo))); - } -} diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.java deleted file mode 100644 index 580b107a8b5..00000000000 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * 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.ethereum.retesteth.methods; - -import org.hyperledger.besu.ethereum.ProtocolContext; -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.JsonRpcParameter.JsonRpcParameterException; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; -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.core.Block; -import org.hyperledger.besu.ethereum.core.BlockImporter; -import org.hyperledger.besu.ethereum.mainnet.BlockImportResult; -import org.hyperledger.besu.ethereum.retesteth.RetestethContext; -import org.hyperledger.besu.ethereum.rlp.RLP; -import org.hyperledger.besu.ethereum.rlp.RLPException; - -import java.util.Collections; - -import org.apache.tuweni.bytes.Bytes; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class TestImportRawBlock implements JsonRpcMethod { - private static final Logger LOG = LoggerFactory.getLogger(TestImportRawBlock.class); - - public static final String METHOD_NAME = "test_importRawBlock"; - - private final RetestethContext context; - - public TestImportRawBlock(final RetestethContext context) { - this.context = context; - } - - @Override - public String getName() { - return METHOD_NAME; - } - - @Override - public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final String input; - try { - input = requestContext.getRequiredParameter(0, String.class); - } catch (JsonRpcParameterException e) { - throw new InvalidJsonRpcParameters( - "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); - } - final ProtocolContext protocolContext = this.context.getProtocolContext(); - - final Block block; - try { - block = - Block.readFrom(RLP.input(Bytes.fromHexString(input)), context.getBlockHeaderFunctions()); - } catch (final RLPException | IllegalArgumentException e) { - LOG.debug("Failed to parse block RLP", e); - return new JsonRpcErrorResponse( - requestContext.getRequest().getId(), RpcErrorType.BLOCK_RLP_IMPORT_ERROR); - } - - // retesteth expects test_rawImportBlock to not only import the block, but append it to head - if (context.getBlockchain().contains(block.getHash())) { - // if we already have the block but it is not head, append it: - context - .getBlockchain() - .appendBlock( - block, - context - .getBlockchain() - .getTxReceipts(block.getHash()) - .orElse(Collections.emptyList())); - } else { - // otherwise attempt to import the block - final BlockImporter blockImporter = - context.getProtocolSpec(block.getHeader()).getBlockImporter(); - final BlockImportResult result = - blockImporter.importBlock( - protocolContext, - block, - context.getHeaderValidationMode(), - context.getHeaderValidationMode()); - if (!result.isImported()) { - LOG.debug("Failed to import block."); - return new JsonRpcErrorResponse( - requestContext.getRequest().getId(), RpcErrorType.BLOCK_IMPORT_ERROR); - } - } - // return success on append or import - return new JsonRpcSuccessResponse( - requestContext.getRequest().getId(), block.getHash().toString()); - } -} diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java deleted file mode 100644 index 00a27bb7a8a..00000000000 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * 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.ethereum.retesteth.methods; - -import org.hyperledger.besu.ethereum.ProtocolContext; -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.JsonRpcParameter.JsonRpcParameterException; -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.blockcreation.PoWBlockCreator; -import org.hyperledger.besu.ethereum.chain.MutableBlockchain; -import org.hyperledger.besu.ethereum.core.Block; -import org.hyperledger.besu.ethereum.core.BlockImporter; -import org.hyperledger.besu.ethereum.core.MiningParameters; -import org.hyperledger.besu.ethereum.mainnet.BlockImportResult; -import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; -import org.hyperledger.besu.ethereum.retesteth.RetestethClock; -import org.hyperledger.besu.ethereum.retesteth.RetestethContext; - -public class TestMineBlocks implements JsonRpcMethod { - private final RetestethContext context; - - public TestMineBlocks(final RetestethContext context) { - this.context = context; - } - - @Override - public String getName() { - return "test_mineBlocks"; - } - - @Override - public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - long blocksToMine = 0; - try { - blocksToMine = requestContext.getRequiredParameter(0, Long.class); - } catch (JsonRpcParameterException e) { - throw new InvalidJsonRpcParameters( - "Invalid blocks to mine (index 0)", RpcErrorType.INVALID_BLOCK_COUNT_PARAMS, e); - } - while (blocksToMine-- > 0) { - if (!mineNewBlock()) { - return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), false); - } - } - - return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), true); - } - - private boolean mineNewBlock() { - final RetestethClock retesethClock = context.getRetestethClock(); - final ProtocolSchedule protocolSchedule = context.getProtocolSchedule(); - final ProtocolContext protocolContext = context.getProtocolContext(); - final MutableBlockchain blockchain = context.getBlockchain(); - final HeaderValidationMode headerValidationMode = context.getHeaderValidationMode(); - final MiningParameters miningParameters = context.getMiningParameters(); - final PoWBlockCreator blockCreator = - new PoWBlockCreator( - miningParameters, - header -> miningParameters.getExtraData(), - context.getTransactionPool(), - protocolContext, - protocolSchedule, - context.getEthHashSolver(), - context.getEthScheduler()); - final Block block = - blockCreator - .createBlock(retesethClock.instant().getEpochSecond(), blockchain.getChainHeadHeader()) - .getBlock(); - - // advance clock so next mine won't hit the same timestamp - retesethClock.advanceSeconds(1); - - final BlockImporter blockImporter = - protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()).getBlockImporter(); - final BlockImportResult result = - blockImporter.importBlock( - protocolContext, block, headerValidationMode, headerValidationMode); - return result.isImported(); - } -} diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestModifyTimestamp.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestModifyTimestamp.java deleted file mode 100644 index 717cf41b459..00000000000 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestModifyTimestamp.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * 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.ethereum.retesteth.methods; - -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.JsonRpcParameter.JsonRpcParameterException; -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.retesteth.RetestethContext; - -public class TestModifyTimestamp implements JsonRpcMethod { - - private final RetestethContext context; - - public TestModifyTimestamp(final RetestethContext context) { - this.context = context; - } - - @Override - public String getName() { - return "test_modifyTimestamp"; - } - - @Override - public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final long epochSeconds; - try { - epochSeconds = requestContext.getRequiredParameter(0, Long.class); - } catch (JsonRpcParameterException e) { - throw new InvalidJsonRpcParameters( - "Invalid timestamp parameter (index 0)", RpcErrorType.INVALID_TIMESTAMP_PARAMS, e); - } - context.getRetestethClock().resetTime(epochSeconds); - return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), true); - } -} diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestRewindToBlock.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestRewindToBlock.java deleted file mode 100644 index d9b847af425..00000000000 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestRewindToBlock.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * 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.ethereum.retesteth.methods; - -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.JsonRpcParameter.JsonRpcParameterException; -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.retesteth.RetestethContext; - -public class TestRewindToBlock implements JsonRpcMethod { - private final RetestethContext context; - - public static final String METHOD_NAME = "test_rewindToBlock"; - - public TestRewindToBlock(final RetestethContext context) { - this.context = context; - } - - @Override - public String getName() { - return METHOD_NAME; - } - - @Override - public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final long blockNumber; - try { - blockNumber = requestContext.getRequiredParameter(0, Long.TYPE); - } catch (JsonRpcParameterException e) { - throw new InvalidJsonRpcParameters( - "Invalid block number parameter (index 0)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e); - } - - return new JsonRpcSuccessResponse( - requestContext.getRequest().getId(), context.getBlockchain().rewindToBlock(blockNumber)); - } -} diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestSetChainParams.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestSetChainParams.java deleted file mode 100644 index 1446fd939fb..00000000000 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestSetChainParams.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * 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.ethereum.retesteth.methods; - -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; -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; -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.retesteth.RetestethContext; - -import java.util.Iterator; -import java.util.Map; -import java.util.Optional; - -import io.vertx.core.json.JsonObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class TestSetChainParams implements JsonRpcMethod { - - private static final Logger LOG = LoggerFactory.getLogger(TestSetChainParams.class); - - public static final String METHOD_NAME = "test_setChainParams"; - private final RetestethContext context; - - public TestSetChainParams(final RetestethContext context) { - this.context = context; - } - - @Override - public String getName() { - return METHOD_NAME; - } - - @SuppressWarnings("unchecked") - @Override - public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - - try { - final JsonObject chainParamsAsJson = - new JsonObject((Map) requestContext.getRequest().getParams()[0]); - final String chainParamsAsString = chainParamsAsJson.encodePrettily(); - LOG.trace("ChainParams {}", chainParamsAsString); - final String genesisFileAsString = modifyGenesisFile(chainParamsAsString); - LOG.trace("Genesis {}", genesisFileAsString); - final boolean result = - context.resetContext( - genesisFileAsString, - chainParamsAsJson.getString("sealEngine", "NoProof"), - Optional.empty()); - - return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), result); - } catch (final Exception e) { - LOG.error("Unhandled error", e); - return new JsonRpcErrorResponse( - requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS); - } - } - - private static void maybeMove( - final JsonObject src, final String srcName, final JsonObject dest, final String destName) { - if (src.containsKey(srcName)) { - dest.put(destName, src.getValue(srcName)); - src.remove(srcName); - } - } - - private static void maybeMoveToNumber( - final JsonObject src, final String srcName, final JsonObject dest, final String destName) { - if (src.containsKey(srcName)) { - dest.put(destName, Long.decode(src.getString(srcName))); - src.remove(srcName); - } - } - - private static void maybeMoveToNumber( - final JsonObject src, - final String srcName, - final JsonObject dest, - final String destName, - final long defaultValue) { - if (src.containsKey(srcName)) { - dest.put(destName, Long.decode(src.getString(srcName))); - src.remove(srcName); - } else { - dest.put(destName, defaultValue); - } - } - - private static String modifyGenesisFile(final String initialGenesis) { - final JsonObject chainParamsJson = new JsonObject(initialGenesis); - final JsonObject config = new JsonObject(); - chainParamsJson.put("config", config); - final JsonObject params = chainParamsJson.getJsonObject("params"); - final JsonObject genesis = chainParamsJson.getJsonObject("genesis"); - - // Whether sealEngine is NoProof, Ethash, or NoReward the genesis file is the same - final JsonObject ethash = new JsonObject(); - config.put("ethash", ethash); - - maybeMoveToNumber(params, "homesteadForkBlock", config, "homesteadBlock"); - maybeMoveToNumber(params, "daoHardforkBlock", config, "daoForkBlock"); - maybeMoveToNumber(params, "EIP150ForkBlock", config, "eip150Block"); - maybeMoveToNumber(params, "EIP158ForkBlock", config, "eip158Block"); - maybeMoveToNumber(params, "byzantiumForkBlock", config, "byzantiumBlock"); - maybeMoveToNumber(params, "constantinopleForkBlock", config, "constantinopleBlock"); - maybeMoveToNumber(params, "constantinopleFixForkBlock", config, "petersburgBlock"); - maybeMoveToNumber(params, "istanbulForkBlock", config, "istanbulBlock"); - maybeMoveToNumber(params, "muirGlacierForkBlock", config, "muirGlacierBlock"); - maybeMoveToNumber(params, "berlinForkBlock", config, "berlinBlock"); - maybeMoveToNumber(params, "londonForkBlock", config, "londonBlock"); - maybeMoveToNumber(params, "arrowGlacierForkBlock", config, "arrowGlacierBlock"); - maybeMoveToNumber(params, "grayGlacierForkBlock", config, "grayGlacierBlock"); - maybeMoveToNumber(params, "mergeNetSplitForkBlock", config, "mergeNetSplitBlock"); - maybeMoveToNumber(params, "shanghaiForkTime", config, "shanghaiTime"); - maybeMoveToNumber(params, "cancunForkTime", config, "cancunTime"); - maybeMoveToNumber(params, "pragueForkTime", config, "pragueTime"); - maybeMoveToNumber(params, "futureEipsForkTime", config, "futureEipsTime"); - maybeMoveToNumber(params, "experimentalEipsForkTime", config, "experimentalEipsTime"); - maybeMoveToNumber(params, "chainID", config, "chainId", 1); - - maybeMove(genesis, "author", chainParamsJson, "coinbase"); - maybeMove(genesis, "difficulty", chainParamsJson, "difficulty"); - maybeMove(genesis, "extraData", chainParamsJson, "extraData"); - maybeMove(genesis, "gasLimit", chainParamsJson, "gasLimit"); - maybeMove(genesis, "mixHash", chainParamsJson, "mixHash"); - maybeMove(genesis, "nonce", chainParamsJson, "nonce"); - maybeMove(genesis, "timestamp", chainParamsJson, "timestamp"); - maybeMove(chainParamsJson, "accounts", chainParamsJson, "alloc"); - maybeMove(genesis, "baseFeePerGas", chainParamsJson, "baseFeePerGas"); - - // strip out precompiles with zero balance - final JsonObject alloc = chainParamsJson.getJsonObject("alloc"); - final Iterator fieldNamesIter = alloc.fieldNames().iterator(); - while (fieldNamesIter.hasNext()) { - final String address = fieldNamesIter.next(); - final JsonObject account = alloc.getJsonObject(address); - if (account.containsKey("precompiled") && !account.containsKey("balance")) { - fieldNamesIter.remove(); - } - } - - return chainParamsJson.encodePrettily(); - } -} diff --git a/ethereum/retesteth/src/test/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlockTest.java b/ethereum/retesteth/src/test/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlockTest.java deleted file mode 100644 index b156f2294df..00000000000 --- a/ethereum/retesteth/src/test/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlockTest.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * 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.ethereum.retesteth.methods; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; -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.retesteth.RetestethContext; -import org.hyperledger.besu.plugin.services.rpc.RpcResponseType; - -import java.io.IOException; - -import com.google.common.base.Charsets; -import com.google.common.io.Resources; -import io.vertx.core.json.JsonObject; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -public class TestImportRawBlockTest { - private TestImportRawBlock test_importRawBlock; - private TestRewindToBlock test_rewindToBlock; - private RetestethContext context; - - @BeforeEach - public void setupClass() throws IOException { - context = new RetestethContext(); - test_importRawBlock = new TestImportRawBlock(context); - test_rewindToBlock = new TestRewindToBlock(context); - final TestSetChainParams test_setChainParams = new TestSetChainParams(context); - final String chainParamsJsonString = - Resources.toString( - TestSetChainParamsTest.class.getResource("multimpleBalanceInstructionChainParams.json"), - Charsets.UTF_8); - final JsonObject chainParamsJson = new JsonObject(chainParamsJsonString); - - final JsonRpcRequestContext request = - new JsonRpcRequestContext( - new JsonRpcRequest( - "2.0", TestSetChainParams.METHOD_NAME, new Object[] {chainParamsJson.getMap()})); - - assertThat(test_setChainParams.response(request)) - .isEqualTo(new JsonRpcSuccessResponse(null, true)); - } - - @Test - public void testMissingParent() { - final String rawBlockRLPString = - "0xf9045df901f9a0e38bef3dadb98e856ea82c7e9813b76a6ec8d9cf60694dd65d800a1669c1a1fda03770bba814f8cc5534ab5e40bdb3fe51866b537805c5577888091766e621fc13948888f1f195afa192cfee860698584c030f4c9db1a019ce64082807650d3d01ac60cd16a583e9472dcc0ccb8f39dd867e317cf025dda09735e49acaddb4d8338ed33df8dd006449b20b85e89e47224ac8ec8f7ea26071a0056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830200000483301fd28252088454c99c2142a00000000000000000000000000000000000000000000000000000000000000000880000000000000000f862f86003018304cb2f94095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba0a7b7f2fa93025fc1e6aa18c1aa07c32a456439754e196cb74f2f7d12cf3e840da02078cf840fb25fc3d858b2a85b622f21be0588b5c5d81d433427f6470e06a4a7f901faf901f7a0f88512d9e022357594866c44ecaa2fc9cb48f34d1987e401109400761aeb898da01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794bcde5374fce5edbc8e2a8697c15331677e6ebf0ba0fe87abb0d3ab38d4eb64405de03db5245b0d40c4b85d8a1b5028ada8643de2dba056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000002833007cf808454c9945142a00000000000000000000000000000000000000000000000000000000000000000880000000000000000"; - - final JsonRpcRequestContext request = - new JsonRpcRequestContext( - new JsonRpcRequest( - "2.0", TestImportRawBlock.METHOD_NAME, new Object[] {rawBlockRLPString})); - - final var response = test_importRawBlock.response(request); - assertThat(response.getType()).isEqualTo(RpcResponseType.ERROR); - assertThat(((JsonRpcErrorResponse) response).getErrorType()) - .isEqualTo(RpcErrorType.BLOCK_IMPORT_ERROR); - } - - @Test - public void testBadBlock() { - final String rawBlockRLPString = "0xf9045df901f9a08"; - - final JsonRpcRequestContext request = - new JsonRpcRequestContext( - new JsonRpcRequest( - "2.0", TestImportRawBlock.METHOD_NAME, new Object[] {rawBlockRLPString})); - - final var response = test_importRawBlock.response(request); - assertThat(response.getType()).isEqualTo(RpcResponseType.ERROR); - assertThat(((JsonRpcErrorResponse) response).getErrorType()) - .isEqualTo(RpcErrorType.BLOCK_RLP_IMPORT_ERROR); - } - - @Test - public void testGoodBlock() { - final String rawBlockRLPString = - "0xf90262f901faa0e38bef3dadb98e856ea82c7e9813b76a6ec8d9cf60694dd65d800a1669c1a1fda01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a06e6be3f633fe0399cb17a9d8238b988a39bd9ab3e0ac0820f4df705a1ee37536a06fb77a9ddaa64a8e161b643d05533a4093f2be900ad06279b1b56b3bcee3b979a04b33fa3c9c50b7b9a4500f5c0b1e71ab43362abc81c2cf31fd2b54acf7d750d8b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000001832fefba83016b66845db7320980a00000000000000000000000000000000000000000000000000000000000000000880000000000000000f862f860800a830249f094095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba0d42a045ac77a6d4676dd5fbc5104ed7471b6cef2465cfefaa52919b340f942a9a06e4d319aea79e45cde79d337e6edf849ceac505cab65dd41a572cab132d4dccac0"; - - final JsonRpcRequestContext request = - new JsonRpcRequestContext( - new JsonRpcRequest( - "2.0", TestImportRawBlock.METHOD_NAME, new Object[] {rawBlockRLPString})); - - final var response = test_importRawBlock.response(request); - assertThat(response.getType()).isEqualTo(RpcResponseType.SUCCESS); - } - - @Test - public void testReimportExistingBlock() { - final String rawBlockRLPString = - "0xf90262f901faa0e38bef3dadb98e856ea82c7e9813b76a6ec8d9cf60694dd65d800a1669c1a1fda01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a06e6be3f633fe0399cb17a9d8238b988a39bd9ab3e0ac0820f4df705a1ee37536a06fb77a9ddaa64a8e161b643d05533a4093f2be900ad06279b1b56b3bcee3b979a04b33fa3c9c50b7b9a4500f5c0b1e71ab43362abc81c2cf31fd2b54acf7d750d8b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000001832fefba83016b66845db7320980a00000000000000000000000000000000000000000000000000000000000000000880000000000000000f862f860800a830249f094095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba0d42a045ac77a6d4676dd5fbc5104ed7471b6cef2465cfefaa52919b340f942a9a06e4d319aea79e45cde79d337e6edf849ceac505cab65dd41a572cab132d4dccac0"; - - final JsonRpcRequestContext request = - new JsonRpcRequestContext( - new JsonRpcRequest( - "2.0", TestImportRawBlock.METHOD_NAME, new Object[] {rawBlockRLPString})); - - final JsonRpcRequestContext requestRewind = - new JsonRpcRequestContext( - new JsonRpcRequest("2.0", TestRewindToBlock.METHOD_NAME, new Object[] {0L})); - - final var response = test_importRawBlock.response(request); - assertThat(response.getType()).isEqualTo(RpcResponseType.SUCCESS); - final var rewindResponse = test_rewindToBlock.response(requestRewind); - assertThat(rewindResponse.getType()).isEqualTo(RpcResponseType.SUCCESS); - final var reimportResponse = test_importRawBlock.response(request); - assertThat(reimportResponse.getType()).isEqualTo(RpcResponseType.SUCCESS); - - assertThat(context.getBlockchain().getChainHead().getHeight()).isEqualTo(1L); - } -} diff --git a/ethereum/retesteth/src/test/java/org/hyperledger/besu/ethereum/retesteth/methods/TestSetChainParamsTest.java b/ethereum/retesteth/src/test/java/org/hyperledger/besu/ethereum/retesteth/methods/TestSetChainParamsTest.java deleted file mode 100644 index f376fa0c250..00000000000 --- a/ethereum/retesteth/src/test/java/org/hyperledger/besu/ethereum/retesteth/methods/TestSetChainParamsTest.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * 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.ethereum.retesteth.methods; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.retesteth.RetestethContext; - -import java.io.IOException; - -import com.google.common.base.Charsets; -import com.google.common.io.Resources; -import io.vertx.core.json.JsonObject; -import org.apache.tuweni.units.bigints.UInt256; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -public class TestSetChainParamsTest { - - private static RetestethContext context; - private static TestSetChainParams test_setChainParams; - - @BeforeAll - public static void setupClass() { - context = new RetestethContext(); - test_setChainParams = new TestSetChainParams(context); - } - - @Test - public void testValidateGenesisImport() throws IOException { - final String chainParamsJsonString = - Resources.toString( - TestSetChainParamsTest.class.getResource("multimpleBalanceInstructionChainParams.json"), - Charsets.UTF_8); - final JsonObject chainParamsJson = new JsonObject(chainParamsJsonString); - - final JsonRpcRequestContext request = - new JsonRpcRequestContext( - new JsonRpcRequest( - "2.0", TestSetChainParams.METHOD_NAME, new Object[] {chainParamsJson.getMap()})); - - assertThat(test_setChainParams.response(request)) - .isEqualTo(new JsonRpcSuccessResponse(null, true)); - - final BlockHeader blockHeader = context.getBlockHeader(0); - - assertThat(blockHeader.getLogsBloom().toString()) - .isEqualTo( - "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); - assertThat(blockHeader.getCoinbase().toString()) - .isEqualTo("0x8888f1f195afa192cfee860698584c030f4c9db1"); - assertThat(blockHeader.getDifficulty()).isEqualTo(UInt256.fromHexString("0x20000")); - assertThat(blockHeader.getExtraData().toHexString()).isEqualTo("0x42"); - assertThat(blockHeader.getGasLimit()).isEqualTo(3141592); - assertThat(blockHeader.getGasUsed()).isEqualTo(0); - assertThat(blockHeader.getMixHash().toString()) - .isEqualTo("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"); - assertThat(blockHeader.getNonce()).isEqualTo(0x0102030405060708L); - assertThat(blockHeader.getNumber()).isEqualTo(0); - assertThat(blockHeader.getParentHash().toString()) - .isEqualTo("0x0000000000000000000000000000000000000000000000000000000000000000"); - assertThat(blockHeader.getReceiptsRoot().toString()) - .isEqualTo("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"); - assertThat(blockHeader.getStateRoot().toString()) - .isEqualTo("0xf403922bfd555a9223f68fc755564004e20d78bb42aae647e867e3b23c48beba"); - assertThat(blockHeader.getTimestamp()).isEqualTo(0x54c98c81); - assertThat(blockHeader.getTransactionsRoot().toString()) - .isEqualTo("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"); - assertThat(blockHeader.getOmmersHash().toString()) - .isEqualTo("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"); - } - - @Test - public void testValidate1559GenesisImport() throws IOException { - final String chainParamsJsonString = - Resources.toString( - TestSetChainParamsTest.class.getResource("1559ChainParams.json"), Charsets.UTF_8); - final JsonObject chainParamsJson = new JsonObject(chainParamsJsonString); - - final JsonRpcRequestContext request = - new JsonRpcRequestContext( - new JsonRpcRequest( - "2.0", TestSetChainParams.METHOD_NAME, new Object[] {chainParamsJson.getMap()})); - - assertThat(test_setChainParams.response(request)) - .isEqualTo(new JsonRpcSuccessResponse(null, true)); - - final BlockHeader blockHeader = context.getBlockHeader(0); - assertThat(blockHeader.getDifficulty()).isEqualTo(UInt256.fromHexString("0x20000")); - assertThat(blockHeader.getGasLimit()).isEqualTo(1234L); - assertThat(blockHeader.getBaseFee()).hasValue(Wei.of(12345L)); - assertThat(blockHeader.getExtraData().toHexString()).isEqualTo("0x00"); - assertThat(blockHeader.getTimestamp()).isEqualTo(0l); - assertThat(blockHeader.getNonce()).isEqualTo(0L); - assertThat(blockHeader.getMixHash().toHexString()) - .isEqualTo("0x0000000000000000000000000000000000000000000000000000000000000000"); - } -} diff --git a/ethereum/retesteth/src/test/resources/org/hyperledger/besu/ethereum/retesteth/methods/1559ChainParams.json b/ethereum/retesteth/src/test/resources/org/hyperledger/besu/ethereum/retesteth/methods/1559ChainParams.json deleted file mode 100644 index 95535e269f7..00000000000 --- a/ethereum/retesteth/src/test/resources/org/hyperledger/besu/ethereum/retesteth/methods/1559ChainParams.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "genesis" : { - "author" : "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", - "difficulty" : "0x020000", - "gasLimit" : "0x04d2", - "baseFeePerGas" : "0x3039", - "extraData" : "0x00", - "timestamp" : "0x00", - "nonce" : "0x0000000000000000", - "mixHash" : "0x0000000000000000000000000000000000000000000000000000000000000000" - }, - "params": { - "EIP150ForkBlock": "0x00", - "EIP158ForkBlock": "0x00", - "byzantiumForkBlock": "0x00", - "homesteadForkBlock": "0x00", - "londonForkBlock": "0x00" - }, - "sealEngine": "NoProof", - "accounts": {} -} \ No newline at end of file diff --git a/ethereum/retesteth/src/test/resources/org/hyperledger/besu/ethereum/retesteth/methods/multimpleBalanceInstructionChainParams.json b/ethereum/retesteth/src/test/resources/org/hyperledger/besu/ethereum/retesteth/methods/multimpleBalanceInstructionChainParams.json deleted file mode 100644 index 0cb0cfc9608..00000000000 --- a/ethereum/retesteth/src/test/resources/org/hyperledger/besu/ethereum/retesteth/methods/multimpleBalanceInstructionChainParams.json +++ /dev/null @@ -1,102 +0,0 @@ -{ - "accounts": { - "0x0000000000000000000000000000000000000001": { - "precompiled": { - "linear": { - "base": 3000, - "word": 0 - }, - "name": "ecrecover" - } - }, - "0x0000000000000000000000000000000000000002": { - "precompiled": { - "linear": { - "base": 60, - "word": 12 - }, - "name": "sha256" - } - }, - "0x0000000000000000000000000000000000000003": { - "precompiled": { - "linear": { - "base": 600, - "word": 120 - }, - "name": "sha256" - } - }, - "0x0000000000000000000000000000000000000004": { - "precompiled": { - "linear": { - "base": 15, - "word": 3 - }, - "name": "identity" - } - }, - "0x0000000000000000000000000000000000000005": { - "precompiled": { - "name": "modexp" - } - }, - "0x0000000000000000000000000000000000000006": { - "precompiled": { - "linear": { - "base": 500, - "word": 0 - }, - "name": "alt_bn128_G1_add" - } - }, - "0x0000000000000000000000000000000000000007": { - "precompiled": { - "linear": { - "base": 40000, - "word": 0 - }, - "name": "alt_bn128_G1_mul" - } - }, - "0x0000000000000000000000000000000000000008": { - "precompiled": { - "name": "alt_bn128_pairing_product" - } - }, - "0x095e7baea6a6c7c4c2dfeb977efac326af552d87": { - "balance": "0x0186a0", - "code": "0x73a94f5374fce5edbc8e2a8697c15331677e6ebf0b31600055738888f1f195afa192cfee860698584c030f4c9db13160015573a94f5374fce5edbc8e2a8697c15331677e6ebf0b31600255738888f1f195afa192cfee860698584c030f4c9db13160035573095e7baea6a6c7c4c2dfeb977efac326af552d8731600555", - "nonce": "0x00", - "storage": {} - }, - "0x195e7baea6a6c7c4c2dfeb977efac326af552d87": { - "balance": "0x0186a0", - "code": "0x73a94f5374fce5edbc8e2a8697c15331677e6ebf0b31600055738888f1f195afa192cfee860698584c030f4c9db13160015573a94f5374fce5edbc8e2a8697c15331677e6ebf0b31600255738888f1f195afa192cfee860698584c030f4c9db13160035573095e7baea6a6c7c4c2dfeb977efac326af552d873160045573195e7baea6a6c7c4c2dfeb977efac326af552d8731600555", - "nonce": "0x00", - "storage": {} - }, - "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { - "balance": "0x1748721582", - "code": "0x", - "nonce": "0x00", - "storage": {} - } - }, - "genesis": { - "author": "0x8888f1f195afa192cfee860698584c030f4c9db1", - "difficulty": "0x020000", - "extraData": "0x42", - "gasLimit": "0x2fefd8", - "mixHash": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "nonce": "0x0102030405060708", - "timestamp": "0x54c98c81" - }, - "params": { - "EIP150ForkBlock": "0x00", - "EIP158ForkBlock": "0x00", - "byzantiumForkBlock": "0x00", - "homesteadForkBlock": "0x00" - }, - "sealEngine": "NoProof" -} \ No newline at end of file From 7eb7b870c34be8801673ae1aee627661183bce4f Mon Sep 17 00:00:00 2001 From: Justin Florentine Date: Thu, 31 Oct 2024 19:26:41 -0400 Subject: [PATCH 09/56] Refactoring around MiningParameters (#7798) decoupled parent block header from block creators optionalized some fields of ProtocolSchedule constructor, which will allow us to reduce number of constructors later. Refactored JsonBlockImporterTest so it can provide a BesuComponent ProtocolScheduleBuilder optionalizes the default chainid Blocks SubCommand is now Dagger aware Creates but rarely uses ProtocolSpec and ProtocolSchedule modules. Deeper adoption pending. Adds a Coinbase module with fixed values for use in testing. Introduces an EthereumCoreComponent, to be used as a subcomponent of BesuComponent in the future. Introduces a MiningParameters module with common static values used by tests. Removes MiningParameters static constructor. --------- Signed-off-by: Justin Florentine Signed-off-by: jflo --- .../dsl/node/ThreadBesuNodeRunner.java | 29 +++- acceptance-tests/tests/build.gradle | 4 + .../CliqueBesuControllerBuilder.java | 1 - .../MainnetBesuControllerBuilder.java | 10 +- .../besu/services/BesuConfigurationImpl.java | 2 +- .../chainimport/JsonBlockImporterTest.java | 34 ++++- config/build.gradle | 2 + .../clique/CliqueProtocolSchedule.java | 2 +- .../bft/BaseBftProtocolScheduleBuilder.java | 3 +- .../CombinedProtocolScheduleFactoryTest.java | 2 +- consensus/ibft/build.gradle | 2 + .../ibft/IbftProtocolScheduleTest.java | 140 +++++++++++++----- .../IbftBlockHeightManagerTest.java | 2 +- .../merge/MergeProtocolSchedule.java | 2 +- .../QbftBlockHeightManagerTest.java | 2 +- .../AbstractBlockCreatorTest.java | 2 +- ...FeeMarketBlockTransactionSelectorTest.java | 3 +- ...FeeMarketBlockTransactionSelectorTest.java | 3 +- .../blockcreation/PoWBlockCreatorTest.java | 9 +- ethereum/core/build.gradle | 2 + .../components/ProtocolScheduleModule.java | 100 +++++++++++++ .../components/ProtocolSpecModule.java | 51 +++++++ .../core/components/CoinbaseModule.java | 31 ++++ .../components/EthereumCoreComponent.java | 32 ++++ .../components/MiningParametersModule.java | 64 ++++++++ .../FixedDifficultyProtocolSchedule.java | 8 +- .../mainnet/MainnetProtocolSchedule.java | 39 ++--- .../mainnet/ProtocolScheduleBuilder.java | 57 +------ .../core/ExecutionContextTestFixture.java | 2 +- .../core/ProtocolScheduleFixture.java | 8 +- .../mainnet/DefaultProtocolScheduleTest.java | 2 +- .../mainnet/ProtocolScheduleBuilderTest.java | 4 +- .../AbstractTransactionPoolTestBase.java | 2 +- .../TransactionPoolFactoryTest.java | 2 +- .../evmtool/MainnetGenesisFileModule.java | 2 +- ethereum/referencetests/build.gradle | 2 + .../ReferenceTestProtocolSchedules.java | 3 +- .../mainnet/DifficultyCalculatorTests.java | 28 ++-- 38 files changed, 537 insertions(+), 156 deletions(-) create mode 100644 ethereum/core/src/main/java/org/hyperledger/besu/ethereum/components/ProtocolScheduleModule.java create mode 100644 ethereum/core/src/main/java/org/hyperledger/besu/ethereum/components/ProtocolSpecModule.java create mode 100644 ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/CoinbaseModule.java create mode 100644 ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/EthereumCoreComponent.java create mode 100644 ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/MiningParametersModule.java diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java index 42c0df73c71..036a1e0019b 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java @@ -57,6 +57,7 @@ import org.hyperledger.besu.metrics.MetricCategoryRegistryImpl; import org.hyperledger.besu.metrics.MetricsSystemModule; import org.hyperledger.besu.metrics.ObservableMetricsSystem; +import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; import org.hyperledger.besu.plugin.data.EnodeURL; import org.hyperledger.besu.plugin.services.BesuConfiguration; @@ -406,9 +407,18 @@ MetricCategoryRegistryImpl provideMetricCategoryRegistry() { } } + @Module + public static class ThreadBesuNodeRunnerModule { + @Provides + @Singleton + public ThreadBesuNodeRunner provideThreadBesuNodeRunner() { + return new ThreadBesuNodeRunner(); + } + } + @Module @SuppressWarnings("CloseableProvides") - static class BesuControllerModule { + public static class BesuControllerModule { @Provides @Singleton public SynchronizerConfiguration provideSynchronizationConfiguration() { @@ -579,7 +589,16 @@ BesuConfiguration provideBesuConfiguration( } @Module - static class MockBesuCommandModule { + public static class ObservableMetricsSystemModule { + @Provides + @Singleton + public ObservableMetricsSystem provideObservableMetricsSystem() { + return new NoOpMetricsSystem(); + } + } + + @Module + public static class MockBesuCommandModule { @Provides BesuCommand provideBesuCommand(final BesuPluginContextImpl pluginContext) { @@ -610,6 +629,8 @@ Logger provideBesuCommandLogger() { modules = { ThreadBesuNodeRunner.BesuControllerModule.class, ThreadBesuNodeRunner.MockBesuCommandModule.class, + ThreadBesuNodeRunner.ObservableMetricsSystemModule.class, + ThreadBesuNodeRunnerModule.class, BonsaiCachedMerkleTrieLoaderModule.class, MetricsSystemModule.class, ThreadBesuNodeRunner.BesuNodeProviderModule.class, @@ -625,5 +646,9 @@ public interface AcceptanceTestBesuComponent extends BesuComponent { RpcEndpointServiceImpl rpcEndpointService(); BlockchainServiceImpl blockchainService(); + + ObservableMetricsSystem getObservableMetricsSystem(); + + ThreadBesuNodeRunner getThreadBesuNodeRunner(); } } diff --git a/acceptance-tests/tests/build.gradle b/acceptance-tests/tests/build.gradle index fdc77354522..b6c388172e7 100644 --- a/acceptance-tests/tests/build.gradle +++ b/acceptance-tests/tests/build.gradle @@ -31,6 +31,7 @@ dependencies { api 'org.slf4j:slf4j-api' implementation project(':crypto:algorithms') + implementation project(':ethereum:eth') testImplementation project(':acceptance-tests:dsl') testImplementation project(':acceptance-tests:test-plugins') @@ -42,6 +43,7 @@ dependencies { testImplementation project(':ethereum:api') testImplementation project(':ethereum:core') testImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts') + testImplementation project(':ethereum:eth') testImplementation project(':ethereum:p2p') testImplementation project(':ethereum:permissioning') testImplementation project(':ethereum:rlp') @@ -78,6 +80,8 @@ dependencies { testImplementation 'org.web3j:besu' testImplementation 'org.web3j:core' testImplementation 'org.wiremock:wiremock' + testImplementation 'com.google.dagger:dagger' + testAnnotationProcessor 'com.google.dagger:dagger-compiler' testImplementation project(path: ':acceptance-tests:tests:shanghai') } diff --git a/besu/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java index b4ada605498..77bf60b034e 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java @@ -132,7 +132,6 @@ protected ProtocolSchedule createProtocolSchedule() { genesisConfigOptions, forksSchedule, nodeKey, - privacyParameters, isRevertReasonEnabled, evmConfiguration, miningParameters, diff --git a/besu/src/main/java/org/hyperledger/besu/controller/MainnetBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/MainnetBesuControllerBuilder.java index e0fbed608ab..dbd2c5904a4 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/MainnetBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/MainnetBesuControllerBuilder.java @@ -31,6 +31,8 @@ import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; +import java.util.Optional; + /** The Mainnet besu controller builder. */ public class MainnetBesuControllerBuilder extends BesuControllerBuilder { @@ -95,10 +97,10 @@ protected PluginServiceFactory createAdditionalPluginServices( protected ProtocolSchedule createProtocolSchedule() { return MainnetProtocolSchedule.fromConfig( genesisConfigOptions, - privacyParameters, - isRevertReasonEnabled, - evmConfiguration, - miningParameters, + Optional.of(privacyParameters), + Optional.of(isRevertReasonEnabled), + Optional.of(evmConfiguration), + super.miningParameters, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); diff --git a/besu/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java b/besu/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java index 0adbda23b74..6d9a5410c47 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java @@ -31,7 +31,7 @@ public class BesuConfigurationImpl implements BesuConfiguration { private DataStorageConfiguration dataStorageConfiguration; // defaults - private MiningParameters miningParameters = MiningParameters.newDefault(); + private MiningParameters miningParameters; private Optional rpcHttpHost = Optional.of("http://localhost"); private Optional rpcHttpPort = Optional.of(8545); diff --git a/besu/src/test/java/org/hyperledger/besu/chainimport/JsonBlockImporterTest.java b/besu/src/test/java/org/hyperledger/besu/chainimport/JsonBlockImporterTest.java index 7b1a4bc7d2c..bc52cb60be2 100644 --- a/besu/src/test/java/org/hyperledger/besu/chainimport/JsonBlockImporterTest.java +++ b/besu/src/test/java/org/hyperledger/besu/chainimport/JsonBlockImporterTest.java @@ -17,9 +17,10 @@ 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.BesuCommandModule; import org.hyperledger.besu.components.BesuComponent; +import org.hyperledger.besu.components.BesuPluginContextModule; import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.config.JsonUtil; import org.hyperledger.besu.controller.BesuController; @@ -36,12 +37,16 @@ import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Transaction; +import org.hyperledger.besu.ethereum.core.components.MiningParametersModule; 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.trie.diffbased.bonsai.cache.BonsaiCachedMerkleTrieLoader; import org.hyperledger.besu.evm.internal.EvmConfiguration; +import org.hyperledger.besu.metrics.MetricsSystemModule; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.testutil.TestClock; @@ -52,9 +57,13 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Stream; +import javax.inject.Singleton; import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.io.Resources; +import dagger.Component; +import dagger.Module; +import dagger.Provides; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -465,7 +474,28 @@ protected BesuController createController(final GenesisConfigFile genesisConfigF .gasLimitCalculator(GasLimitCalculator.constant()) .evmConfiguration(EvmConfiguration.DEFAULT) .networkConfiguration(NetworkingConfiguration.create()) - .besuComponent(mock(BesuComponent.class)) + .besuComponent(DaggerJsonBlockImporterTest_JsonBlockImportComponent.builder().build()) .build(); } + + @Module + public static class JsonBlockImporterModule { + + @Provides + BonsaiCachedMerkleTrieLoader provideCachedMerkleTrieLoaderModule() { + return new BonsaiCachedMerkleTrieLoader(new NoOpMetricsSystem()); + } + } + + @Singleton + @Component( + modules = { + BesuCommandModule.class, + MiningParametersModule.class, + MetricsSystemModule.class, + JsonBlockImporterModule.class, + BesuPluginContextModule.class, + BlobCacheModule.class + }) + interface JsonBlockImportComponent extends BesuComponent {} } diff --git a/config/build.gradle b/config/build.gradle index a78b9a7105c..e269ce51fc9 100644 --- a/config/build.gradle +++ b/config/build.gradle @@ -36,11 +36,13 @@ dependencies { implementation 'com.fasterxml.jackson.core:jackson-databind' implementation 'com.google.guava:guava' + implementation 'com.google.dagger:dagger' implementation 'info.picocli:picocli' implementation 'io.tmio:tuweni-bytes' implementation 'io.tmio:tuweni-units' implementation "org.immutables:value-annotations" annotationProcessor "org.immutables:value" + annotationProcessor 'com.google.dagger:dagger-compiler' testImplementation project(':testutil') diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueProtocolSchedule.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueProtocolSchedule.java index cd197556386..551a8c3f442 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueProtocolSchedule.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueProtocolSchedule.java @@ -110,7 +110,7 @@ public static ProtocolSchedule create( return new ProtocolScheduleBuilder( config, - DEFAULT_CHAIN_ID, + Optional.of(DEFAULT_CHAIN_ID), specAdapters, privacyParameters, isRevertReasonEnabled, diff --git a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilder.java b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilder.java index 311bf30faef..0df63452b34 100644 --- a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilder.java +++ b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilder.java @@ -38,6 +38,7 @@ import java.math.BigInteger; import java.util.HashMap; import java.util.Map; +import java.util.Optional; import java.util.function.Function; /** Defines the protocol behaviours for a blockchain using a BFT consensus mechanism. */ @@ -90,7 +91,7 @@ public BftProtocolSchedule createProtocolSchedule( final ProtocolSchedule protocolSchedule = new ProtocolScheduleBuilder( config, - DEFAULT_CHAIN_ID, + Optional.of(DEFAULT_CHAIN_ID), specAdapters, privacyParameters, isRevertReasonEnabled, diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java index 02689d52af1..659337bdd2e 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java @@ -172,7 +172,7 @@ private BftProtocolSchedule createProtocolSchedule( final ProtocolScheduleBuilder protocolScheduleBuilder = new ProtocolScheduleBuilder( genesisConfigOptions, - BigInteger.ONE, + Optional.of(BigInteger.ONE), ProtocolSpecAdapters.create(0, Function.identity()), new PrivacyParameters(), false, diff --git a/consensus/ibft/build.gradle b/consensus/ibft/build.gradle index da6304c4e58..e95c8661431 100644 --- a/consensus/ibft/build.gradle +++ b/consensus/ibft/build.gradle @@ -76,4 +76,6 @@ dependencies { testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' testImplementation 'org.mockito:mockito-junit-jupiter' + testImplementation 'com.google.dagger:dagger' + testAnnotationProcessor 'com.google.dagger:dagger-compiler' } diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleTest.java index e5551ff3f31..a5510ea80a6 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleTest.java @@ -22,7 +22,6 @@ import static org.mockito.Mockito.when; import org.hyperledger.besu.config.BftConfigOptions; -import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.config.JsonGenesisConfigOptions; import org.hyperledger.besu.config.JsonQbftConfigOptions; import org.hyperledger.besu.config.JsonUtil; @@ -43,28 +42,36 @@ import org.hyperledger.besu.ethereum.core.MiningParameters; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Util; +import org.hyperledger.besu.ethereum.core.components.EthereumCoreComponent; import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import java.math.BigInteger; -import java.util.Collection; import java.util.List; +import javax.inject.Singleton; +import dagger.Component; +import dagger.Module; +import dagger.Provides; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; public class IbftProtocolScheduleTest { - private final BftExtraDataCodec bftExtraDataCodec = mock(BftExtraDataCodec.class); - private final BftExtraData bftExtraData = mock(BftExtraData.class); - private final NodeKey proposerNodeKey = NodeKeyUtils.generate(); - private final Address proposerAddress = Util.publicKeyToAddress(proposerNodeKey.getPublicKey()); - private final List
validators = singletonList(proposerAddress); + + private ProtocolContext protocolContext; + private List
validators; + private NodeKey proposerNodeKey; + private TestEthCoreComponent component; @BeforeEach public void setup() { - when(bftExtraDataCodec.decode(any())).thenReturn(bftExtraData); - when(bftExtraData.getValidators()).thenReturn(validators); + TestEthCoreComponent component = + DaggerIbftProtocolScheduleTest_TestEthCoreComponent.builder().build(); + this.component = component; + this.protocolContext = component.protocolContext(); + this.validators = component.validators(); + this.proposerNodeKey = component.nodeKey(); } @Test @@ -81,24 +88,41 @@ public void blockModeTransitionsCreatesBlockModeHeaderValidators() { .buildHeader(); final BftProtocolSchedule schedule = - createProtocolSchedule( - JsonGenesisConfigOptions.fromJsonObject(JsonUtil.createEmptyObjectNode()), - List.of( - new ForkSpec<>(0, JsonQbftConfigOptions.DEFAULT), - new ForkSpec<>(1, arbitraryTransition), - new ForkSpec<>(2, JsonQbftConfigOptions.DEFAULT))); + createProtocolSchedule(component.bftExtraDataCodec(), arbitraryTransition); assertThat(new MilestoneStreamingProtocolSchedule(schedule).streamMilestoneBlocks().count()) .isEqualTo(3); - assertThat(validateHeader(schedule, validators, parentHeader, blockHeader, 0)).isTrue(); - assertThat(validateHeader(schedule, validators, parentHeader, blockHeader, 1)).isTrue(); - assertThat(validateHeader(schedule, validators, parentHeader, blockHeader, 2)).isTrue(); + assertThat(validateHeader(schedule, parentHeader, blockHeader, 0)).isTrue(); + assertThat(validateHeader(schedule, parentHeader, blockHeader, 1)).isTrue(); + assertThat(validateHeader(schedule, parentHeader, blockHeader, 2)).isTrue(); + } + + private boolean validateHeader( + final BftProtocolSchedule schedule, + final BlockHeader parentHeader, + final BlockHeader blockHeader, + final int block) { + return schedule + .getByBlockNumberOrTimestamp(block, blockHeader.getTimestamp()) + .getBlockHeaderValidator() + .validateHeader( + blockHeader, parentHeader, this.protocolContext, HeaderValidationMode.LIGHT); } private BftProtocolSchedule createProtocolSchedule( - final GenesisConfigOptions genesisConfig, final List> forks) { + final BftExtraDataCodec bftExtraDataCodec, + final MutableBftConfigOptions arbitraryTransition) { + + var genesisConfig = JsonGenesisConfigOptions.fromJsonObject(JsonUtil.createEmptyObjectNode()); + ForksSchedule forkSched = + new ForksSchedule<>( + List.of( + new ForkSpec<>(0, JsonQbftConfigOptions.DEFAULT), + new ForkSpec<>(1, arbitraryTransition), + new ForkSpec<>(2, JsonQbftConfigOptions.DEFAULT))); + return IbftProtocolScheduleBuilder.create( genesisConfig, - new ForksSchedule<>(forks), + forkSched, PrivacyParameters.DEFAULT, false, bftExtraDataCodec, @@ -109,24 +133,66 @@ private BftProtocolSchedule createProtocolSchedule( new NoOpMetricsSystem()); } - private boolean validateHeader( - final BftProtocolSchedule schedule, - final List
validators, - final BlockHeader parentHeader, - final BlockHeader blockHeader, - final int block) { - return schedule - .getByBlockNumberOrTimestamp(block, blockHeader.getTimestamp()) - .getBlockHeaderValidator() - .validateHeader( - blockHeader, parentHeader, protocolContext(validators), HeaderValidationMode.LIGHT); + @Module + static class IbftProtocolScheduleModule { + @Provides + @Singleton + NodeKey nodeKey() { + return NodeKeyUtils.generate(); + } + + @Provides + Address provideProposerAddress(final NodeKey proposerNodeKey) { + return Util.publicKeyToAddress(proposerNodeKey.getPublicKey()); + } + + @Provides + List
provideValidators(final Address proposerAddress) { + return singletonList(proposerAddress); + } + + @Provides + public BftExtraData mockBftExtraData(final List
validators) { + BftExtraData bftExtraData = mock(BftExtraData.class); + when(bftExtraData.getValidators()).thenReturn(validators); + return bftExtraData; + } + + @Provides + public BftExtraDataCodec mockBftExtraDataCodec(final BftExtraData bftExtraData) { + BftExtraDataCodec bftExtraDataCodec = mock(BftExtraDataCodec.class); + when(bftExtraDataCodec.decode(any())).thenReturn(bftExtraData); + return bftExtraDataCodec; + } + + @Provides + ProtocolContext protocolContext( + final List
validators, final BftExtraDataCodec bftExtraDataCodec) { + return new ProtocolContext( + null, + null, + setupContextWithBftExtraDataEncoder(BftContext.class, validators, bftExtraDataCodec), + new BadBlockManager()); + } + } + + @Singleton + @Component(modules = {NoMiningParamters.class, IbftProtocolScheduleModule.class}) + interface TestEthCoreComponent extends EthereumCoreComponent { + ProtocolContext protocolContext(); + + List
validators(); + + NodeKey nodeKey(); + + BftExtraDataCodec bftExtraDataCodec(); } - private ProtocolContext protocolContext(final Collection
validators) { - return new ProtocolContext( - null, - null, - setupContextWithBftExtraDataEncoder(BftContext.class, validators, bftExtraDataCodec), - new BadBlockManager()); + @Module + static class NoMiningParamters { + @Provides + MiningParameters provideMiningParameters() { + return MiningParameters.MINING_DISABLED; + } } } diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java index b9f57debb6b..9ca5b0b8e1e 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java @@ -180,7 +180,7 @@ public void setup() { final ProtocolScheduleBuilder protocolScheduleBuilder = new ProtocolScheduleBuilder( new StubGenesisConfigOptions(), - BigInteger.ONE, + Optional.empty(), ProtocolSpecAdapters.create(0, Function.identity()), new PrivacyParameters(), false, diff --git a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/MergeProtocolSchedule.java b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/MergeProtocolSchedule.java index abbc3b130aa..f794152a78b 100644 --- a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/MergeProtocolSchedule.java +++ b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/MergeProtocolSchedule.java @@ -101,7 +101,7 @@ public static ProtocolSchedule create( return new ProtocolScheduleBuilder( config, - DEFAULT_CHAIN_ID, + Optional.of(DEFAULT_CHAIN_ID), new ProtocolSpecAdapters(postMergeModifications), privacyParameters, isRevertReasonEnabled, diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManagerTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManagerTest.java index 190c87e020f..23321f23cc2 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManagerTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManagerTest.java @@ -182,7 +182,7 @@ BftContext.class, validators, new QbftExtraDataCodec()), final ProtocolScheduleBuilder protocolScheduleBuilder = new ProtocolScheduleBuilder( new StubGenesisConfigOptions(), - BigInteger.ONE, + Optional.of(BigInteger.ONE), ProtocolSpecAdapters.create(0, Function.identity()), new PrivacyParameters(), false, diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java index d30349e3d0e..727cfd440f5 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java @@ -304,7 +304,7 @@ private CreateOn createBlockCreator(final ProtocolSpecAdapters protocolSpecAdapt .protocolSchedule( new ProtocolScheduleBuilder( genesisConfigFile.getConfigOptions(), - BigInteger.valueOf(42), + Optional.of(BigInteger.valueOf(42)), protocolSpecAdapters, PrivacyParameters.DEFAULT, false, diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LegacyFeeMarketBlockTransactionSelectorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LegacyFeeMarketBlockTransactionSelectorTest.java index 940d076bbc3..731b8b38546 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LegacyFeeMarketBlockTransactionSelectorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LegacyFeeMarketBlockTransactionSelectorTest.java @@ -42,6 +42,7 @@ import org.hyperledger.besu.util.number.Fraction; import java.time.ZoneId; +import java.util.Optional; import java.util.function.Function; public class LegacyFeeMarketBlockTransactionSelectorTest @@ -56,7 +57,7 @@ protected GenesisConfigFile getGenesisConfigFile() { protected ProtocolSchedule createProtocolSchedule() { return new ProtocolScheduleBuilder( genesisConfigFile.getConfigOptions(), - CHAIN_ID, + Optional.of(CHAIN_ID), ProtocolSpecAdapters.create(0, Function.identity()), new PrivacyParameters(), false, diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java index 68d9a71de6f..3bb559550b8 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java @@ -51,6 +51,7 @@ import java.time.ZoneId; import java.util.List; +import java.util.Optional; import java.util.function.Function; import org.junit.jupiter.api.Test; @@ -67,7 +68,7 @@ protected GenesisConfigFile getGenesisConfigFile() { protected ProtocolSchedule createProtocolSchedule() { return new ProtocolScheduleBuilder( genesisConfigFile.getConfigOptions(), - CHAIN_ID, + Optional.of(CHAIN_ID), ProtocolSpecAdapters.create(0, Function.identity()), new PrivacyParameters(), false, diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java index 509efd7b19b..8e7f992ad55 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java @@ -62,6 +62,7 @@ import java.io.IOException; import java.math.BigInteger; import java.util.Collections; +import java.util.Optional; import java.util.function.Function; import com.google.common.collect.Lists; @@ -93,7 +94,7 @@ void createMainnetBlock1() throws IOException { .protocolSchedule( new ProtocolScheduleBuilder( genesisConfigFile.getConfigOptions(), - BigInteger.valueOf(42), + Optional.of(BigInteger.valueOf(42)), ProtocolSpecAdapters.create(0, Function.identity()), PrivacyParameters.DEFAULT, false, @@ -152,7 +153,7 @@ void createMainnetBlock1_fixedDifficulty1() { .protocolSchedule( new ProtocolScheduleBuilder( genesisConfigFile.getConfigOptions(), - BigInteger.valueOf(42), + Optional.of(BigInteger.valueOf(42)), ProtocolSpecAdapters.create( 0, specBuilder -> @@ -208,7 +209,7 @@ void rewardBeneficiary_zeroReward_skipZeroRewardsFalse() { ProtocolSchedule protocolSchedule = new ProtocolScheduleBuilder( genesisConfigFile.getConfigOptions(), - BigInteger.valueOf(42), + Optional.of(BigInteger.valueOf(42)), ProtocolSpecAdapters.create( 0, specBuilder -> @@ -285,7 +286,7 @@ void rewardBeneficiary_zeroReward_skipZeroRewardsTrue() { ProtocolSchedule protocolSchedule = new ProtocolScheduleBuilder( genesisConfigFile.getConfigOptions(), - BigInteger.valueOf(42), + Optional.of(BigInteger.valueOf(42)), ProtocolSpecAdapters.create( 0, specBuilder -> diff --git a/ethereum/core/build.gradle b/ethereum/core/build.gradle index 912d8673a58..c5ab4462669 100644 --- a/ethereum/core/build.gradle +++ b/ethereum/core/build.gradle @@ -107,6 +107,8 @@ dependencies { testSupportImplementation 'org.junit.jupiter:junit-jupiter' testSupportImplementation 'org.assertj:assertj-core' testSupportImplementation 'org.mockito:mockito-core' + testSupportImplementation 'com.google.dagger:dagger' + testSupportAnnotationProcessor 'com.google.dagger:dagger-compiler' jmhImplementation project(path: ':config', configuration: 'testSupportArtifacts') jmhImplementation project(':crypto:algorithms') diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/components/ProtocolScheduleModule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/components/ProtocolScheduleModule.java new file mode 100644 index 00000000000..039747db0b0 --- /dev/null +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/components/ProtocolScheduleModule.java @@ -0,0 +1,100 @@ +/* + * 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.ethereum.components; + +import org.hyperledger.besu.config.GenesisConfigOptions; +import org.hyperledger.besu.ethereum.chain.BadBlockManager; +import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.PrivacyParameters; +import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecAdapters; +import org.hyperledger.besu.evm.internal.EvmConfiguration; +import org.hyperledger.besu.plugin.services.MetricsSystem; + +import java.math.BigInteger; +import java.util.Optional; +import javax.inject.Singleton; + +import dagger.Module; +import dagger.Provides; + +/** Provides the protocol schedule for the network. */ +@Module +public class ProtocolScheduleModule { + + /** Default constructor. */ + public ProtocolScheduleModule() {} + + /** + * Provides the protocol schedule builder. + * + * @param config the genesis config options + * @param protocolSpecAdapters the protocol spec adapters + * @param privacyParameters the privacy parameters + * @param isRevertReasonEnabled whether revert reason is enabled + * @param evmConfiguration the EVM configuration + * @param badBlockManager the bad block manager + * @param isParallelTxProcessingEnabled whether parallel tx processing is enabled + * @param metricsSystem the metrics system + * @param miningParameters the mining parameters + * @return the protocol schedule builder + */ + @Singleton + @Provides + public ProtocolScheduleBuilder provideProtocolScheduleBuilder( + final GenesisConfigOptions config, + final ProtocolSpecAdapters protocolSpecAdapters, + final PrivacyParameters privacyParameters, + final boolean isRevertReasonEnabled, + final EvmConfiguration evmConfiguration, + final BadBlockManager badBlockManager, + final boolean isParallelTxProcessingEnabled, + final MetricsSystem metricsSystem, + final MiningParameters miningParameters) { + + ProtocolScheduleBuilder builder = + new ProtocolScheduleBuilder( + config, + config.getChainId(), + protocolSpecAdapters, + privacyParameters, + isRevertReasonEnabled, + evmConfiguration, + miningParameters, + badBlockManager, + isParallelTxProcessingEnabled, + metricsSystem); + + return builder; + } + + /** + * Provides the protocol schedule. + * + * @param builder the protocol schedule builder + * @param config the genesis config options + * @return the protocol schedule + */ + @Provides + public ProtocolSchedule createProtocolSchedule( + final ProtocolScheduleBuilder builder, final GenesisConfigOptions config) { + final Optional chainId = config.getChainId().or(() -> builder.getDefaultChainId()); + DefaultProtocolSchedule protocolSchedule = new DefaultProtocolSchedule(chainId); + builder.initSchedule(protocolSchedule, chainId); + return protocolSchedule; + } +} diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/components/ProtocolSpecModule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/components/ProtocolSpecModule.java new file mode 100644 index 00000000000..fe9b0f3fab4 --- /dev/null +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/components/ProtocolSpecModule.java @@ -0,0 +1,51 @@ +/* + * 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.ethereum.components; + +import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSpecs; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecBuilder; +import org.hyperledger.besu.evm.internal.EvmConfiguration; +import org.hyperledger.besu.plugin.services.MetricsSystem; + +import javax.inject.Named; + +import dagger.Module; +import dagger.Provides; + +/** Provides protocol specs for network forks. */ +@Module +public class ProtocolSpecModule { + + /** Default constructor. */ + public ProtocolSpecModule() {} + + /** + * Provides the protocol spec for the frontier network fork. + * + * @param evmConfiguration the EVM configuration + * @param isParalleltxEnabled whether parallel tx processing is enabled + * @param metricsSystem the metrics system + * @return the protocol spec for the frontier network fork + */ + @Provides + @Named("frontier") + public ProtocolSpecBuilder frontierProtocolSpec( + final EvmConfiguration evmConfiguration, + final boolean isParalleltxEnabled, + final MetricsSystem metricsSystem) { + return MainnetProtocolSpecs.frontierDefinition( + evmConfiguration, isParalleltxEnabled, metricsSystem); + } +} diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/CoinbaseModule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/CoinbaseModule.java new file mode 100644 index 00000000000..bb613b4e17f --- /dev/null +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/CoinbaseModule.java @@ -0,0 +1,31 @@ +/* + * 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.ethereum.core.components; + +import org.hyperledger.besu.datatypes.Address; + +import javax.inject.Named; + +import dagger.Module; +import dagger.Provides; + +@Module +public class CoinbaseModule { + @Provides + @Named("emptyCoinbase") + Address provideEmptyCoinbase() { + return Address.fromHexString(String.format("%020x", 1)); + } +} diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/EthereumCoreComponent.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/EthereumCoreComponent.java new file mode 100644 index 00000000000..2b081399a93 --- /dev/null +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/EthereumCoreComponent.java @@ -0,0 +1,32 @@ +/* + * 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.ethereum.core.components; + +import org.hyperledger.besu.ethereum.components.ProtocolScheduleModule; +import org.hyperledger.besu.ethereum.core.MiningParameters; + +import javax.inject.Singleton; + +import dagger.Subcomponent; + +@Singleton +@Subcomponent( + modules = { + MiningParametersModule.class, + ProtocolScheduleModule.class, + }) +public interface EthereumCoreComponent { + MiningParameters getMiningParameters(); +} diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/MiningParametersModule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/MiningParametersModule.java new file mode 100644 index 00000000000..8551d0e946c --- /dev/null +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/MiningParametersModule.java @@ -0,0 +1,64 @@ +/* + * 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.ethereum.core.components; + +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; +import org.hyperledger.besu.ethereum.core.MiningParameters; + +import javax.inject.Named; + +import dagger.Module; +import dagger.Provides; + +@Module +public class MiningParametersModule { + + @Provides + @Named("defaultMiningParameters") + protected MiningParameters createImmutableMiningParams() { + return ImmutableMiningParameters.builder().build(); + } + + @Provides + @Named("noMining") + protected MiningParameters createNoMining() { + return ImmutableMiningParameters.builder() + .mutableInitValues( + ImmutableMiningParameters.MutableInitValues.builder().isMiningEnabled(false).build()) + .build(); + } + + @Provides + @Named("zeroGas") + MiningParameters createZeroGasMining(final @Named("emptyCoinbase") Address coinbase) { + final MiningParameters miningParameters = + ImmutableMiningParameters.builder() + .mutableInitValues( + ImmutableMiningParameters.MutableInitValues.builder() + .isMiningEnabled(true) + .minTransactionGasPrice(Wei.ZERO) + .coinbase(coinbase) + .build()) + .build(); + return miningParameters; + } + + @Provides + MiningParameters provideMiningParameters() { + throw new IllegalStateException("unimplemented"); + } +} diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyProtocolSchedule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyProtocolSchedule.java index b86b2b0de22..4290679baec 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyProtocolSchedule.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyProtocolSchedule.java @@ -24,7 +24,12 @@ import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.plugin.services.MetricsSystem; -/** A ProtocolSchedule which behaves similarly to MainNet, but with a much reduced difficulty. */ +import java.util.Optional; + +/** + * A ProtocolSchedule which behaves similarly to pre-merge MainNet, but with a much reduced + * difficulty. + */ public class FixedDifficultyProtocolSchedule { public static ProtocolSchedule create( @@ -38,6 +43,7 @@ public static ProtocolSchedule create( final MetricsSystem metricsSystem) { return new ProtocolScheduleBuilder( config, + Optional.empty(), ProtocolSpecAdapters.create( 0, builder -> diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSchedule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSchedule.java index 88b6a5ae1be..e6c372a6822 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSchedule.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSchedule.java @@ -24,6 +24,7 @@ import org.hyperledger.besu.plugin.services.MetricsSystem; import java.math.BigInteger; +import java.util.Optional; import java.util.function.Function; /** Provides {@link ProtocolSpec} lookups for mainnet hard forks. */ @@ -47,9 +48,9 @@ public class MainnetProtocolSchedule { */ public static ProtocolSchedule fromConfig( final GenesisConfigOptions config, - final PrivacyParameters privacyParameters, - final boolean isRevertReasonEnabled, - final EvmConfiguration evmConfiguration, + final Optional privacyParameters, + final Optional isRevertReasonEnabled, + final Optional evmConfiguration, final MiningParameters miningParameters, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, @@ -57,9 +58,9 @@ public static ProtocolSchedule fromConfig( if (FixedDifficultyCalculators.isFixedDifficultyInConfig(config)) { return FixedDifficultyProtocolSchedule.create( config, - privacyParameters, - isRevertReasonEnabled, - evmConfiguration, + privacyParameters.orElse(PrivacyParameters.DEFAULT), + isRevertReasonEnabled.orElse(false), + evmConfiguration.orElse(EvmConfiguration.DEFAULT), miningParameters, badBlockManager, isParallelTxProcessingEnabled, @@ -67,11 +68,11 @@ public static ProtocolSchedule fromConfig( } return new ProtocolScheduleBuilder( config, - DEFAULT_CHAIN_ID, + Optional.of(DEFAULT_CHAIN_ID), ProtocolSpecAdapters.create(0, Function.identity()), - privacyParameters, - isRevertReasonEnabled, - evmConfiguration, + privacyParameters.orElse(PrivacyParameters.DEFAULT), + isRevertReasonEnabled.orElse(false), + evmConfiguration.orElse(EvmConfiguration.DEFAULT), miningParameters, badBlockManager, isParallelTxProcessingEnabled, @@ -101,9 +102,9 @@ public static ProtocolSchedule fromConfig( final MetricsSystem metricsSystem) { return fromConfig( config, - PrivacyParameters.DEFAULT, - isRevertReasonEnabled, - evmConfiguration, + Optional.empty(), + Optional.of(isRevertReasonEnabled), + Optional.of(evmConfiguration), miningParameters, badBlockManager, isParallelTxProcessingEnabled, @@ -130,9 +131,9 @@ public static ProtocolSchedule fromConfig( final MetricsSystem metricsSystem) { return fromConfig( config, - PrivacyParameters.DEFAULT, - false, - evmConfiguration, + Optional.empty(), + Optional.empty(), + Optional.of(evmConfiguration), miningParameters, badBlockManager, isParallelTxProcessingEnabled, @@ -157,9 +158,9 @@ public static ProtocolSchedule fromConfig( final MetricsSystem metricsSystem) { return fromConfig( config, - PrivacyParameters.DEFAULT, - false, - EvmConfiguration.DEFAULT, + Optional.empty(), + Optional.empty(), + Optional.empty(), miningParameters, badBlockManager, isParallelTxProcessingEnabled, diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java index 52003bc96c5..fd27ca05742 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java @@ -48,59 +48,12 @@ public class ProtocolScheduleBuilder { private final PrivacyParameters privacyParameters; private final boolean isRevertReasonEnabled; private final EvmConfiguration evmConfiguration; - private final MiningParameters miningParameters; private final BadBlockManager badBlockManager; private final boolean isParallelTxProcessingEnabled; private final MetricsSystem metricsSystem; + private final MiningParameters miningParameters; public ProtocolScheduleBuilder( - final GenesisConfigOptions config, - final BigInteger defaultChainId, - final ProtocolSpecAdapters protocolSpecAdapters, - final PrivacyParameters privacyParameters, - final boolean isRevertReasonEnabled, - final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, - final BadBlockManager badBlockManager, - final boolean isParallelTxProcessingEnabled, - final MetricsSystem metricsSystem) { - this( - config, - Optional.of(defaultChainId), - protocolSpecAdapters, - privacyParameters, - isRevertReasonEnabled, - evmConfiguration, - miningParameters, - badBlockManager, - isParallelTxProcessingEnabled, - metricsSystem); - } - - public ProtocolScheduleBuilder( - final GenesisConfigOptions config, - final ProtocolSpecAdapters protocolSpecAdapters, - final PrivacyParameters privacyParameters, - final boolean isRevertReasonEnabled, - final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, - final BadBlockManager badBlockManager, - final boolean isParallelTxProcessingEnabled, - final MetricsSystem metricsSystem) { - this( - config, - Optional.empty(), - protocolSpecAdapters, - privacyParameters, - isRevertReasonEnabled, - evmConfiguration, - miningParameters, - badBlockManager, - isParallelTxProcessingEnabled, - metricsSystem); - } - - private ProtocolScheduleBuilder( final GenesisConfigOptions config, final Optional defaultChainId, final ProtocolSpecAdapters protocolSpecAdapters, @@ -117,10 +70,10 @@ private ProtocolScheduleBuilder( this.isRevertReasonEnabled = isRevertReasonEnabled; this.evmConfiguration = evmConfiguration; this.defaultChainId = defaultChainId; - this.miningParameters = miningParameters; this.badBlockManager = badBlockManager; this.isParallelTxProcessingEnabled = isParallelTxProcessingEnabled; this.metricsSystem = metricsSystem; + this.miningParameters = miningParameters; } public ProtocolSchedule createProtocolSchedule() { @@ -130,7 +83,7 @@ public ProtocolSchedule createProtocolSchedule() { return protocolSchedule; } - private void initSchedule( + public void initSchedule( final ProtocolSchedule protocolSchedule, final Optional chainId) { final MainnetProtocolSpecFactory specFactory = @@ -557,4 +510,8 @@ private enum MilestoneType { TIMESTAMP } } + + public Optional getDefaultChainId() { + return defaultChainId; + } } diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java index 511b94d3ae5..e05ba212681 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java @@ -152,7 +152,7 @@ public ExecutionContextTestFixture build() { protocolSchedule = new ProtocolScheduleBuilder( genesisConfigFile.getConfigOptions(), - BigInteger.valueOf(42), + Optional.of(BigInteger.valueOf(42)), ProtocolSpecAdapters.create(0, Function.identity()), new PrivacyParameters(), false, diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ProtocolScheduleFixture.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ProtocolScheduleFixture.java index e94c6b49fd0..5eec6d61e5e 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ProtocolScheduleFixture.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ProtocolScheduleFixture.java @@ -22,10 +22,10 @@ import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; -import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import java.io.IOException; +import java.util.Optional; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParser; @@ -36,9 +36,9 @@ public class ProtocolScheduleFixture { public static final ProtocolSchedule MAINNET = MainnetProtocolSchedule.fromConfig( getMainnetConfigOptions(), - PrivacyParameters.DEFAULT, - false, - EvmConfiguration.DEFAULT, + Optional.empty(), + Optional.empty(), + Optional.empty(), MiningParameters.newDefault(), new BadBlockManager(), false, diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/DefaultProtocolScheduleTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/DefaultProtocolScheduleTest.java index 2d5dd2cee34..e48cd673027 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/DefaultProtocolScheduleTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/DefaultProtocolScheduleTest.java @@ -56,7 +56,7 @@ public void setup() { builder = new ProtocolScheduleBuilder( config, - DEFAULT_CHAIN_ID, + Optional.of(DEFAULT_CHAIN_ID), ProtocolSpecAdapters.create(FIRST_TIMESTAMP_FORK, modifier), privacyParameters, isRevertReasonEnabled, diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilderTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilderTest.java index ad261abf472..cade5bd6019 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilderTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilderTest.java @@ -62,7 +62,7 @@ public void setup() { builder = new ProtocolScheduleBuilder( configOptions, - CHAIN_ID, + Optional.of(CHAIN_ID), ProtocolSpecAdapters.create(0, Function.identity()), new PrivacyParameters(), false, @@ -257,7 +257,7 @@ private MilestoneStreamingProtocolSchedule createScheduleModifiedAt(final int bl final ProtocolScheduleBuilder builder = new ProtocolScheduleBuilder( configOptions, - CHAIN_ID, + Optional.of(CHAIN_ID), ProtocolSpecAdapters.create(blockNumber, modifier), new PrivacyParameters(), false, diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTestBase.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTestBase.java index c3ca24a4e1a..07d4e6ab4b1 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTestBase.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTestBase.java @@ -178,7 +178,7 @@ protected static ExecutionContextTestFixture createExecutionContextTestFixtureBa final ProtocolSchedule protocolSchedule = new ProtocolScheduleBuilder( genesisConfigFile.getConfigOptions(), - BigInteger.valueOf(1), + Optional.of(BigInteger.valueOf(1)), ProtocolSpecAdapters.create(0, Function.identity()), new PrivacyParameters(), false, diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactoryTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactoryTest.java index 5742637c3e8..d1bafc39699 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactoryTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactoryTest.java @@ -373,7 +373,7 @@ private void setupScheduleWith(final StubGenesisConfigOptions config) { schedule = new ProtocolScheduleBuilder( config, - DEFAULT_CHAIN_ID, + Optional.of(DEFAULT_CHAIN_ID), ProtocolSpecAdapters.create(0, Function.identity()), PrivacyParameters.DEFAULT, false, diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/MainnetGenesisFileModule.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/MainnetGenesisFileModule.java index 8dc8a74c1f9..8490312d814 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/MainnetGenesisFileModule.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/MainnetGenesisFileModule.java @@ -187,7 +187,7 @@ private static Supplier createSchedule(final GenesisConfigOpti return () -> new ProtocolScheduleBuilder( options, - options.getChainId().orElse(BigInteger.ONE), + options.getChainId(), ProtocolSpecAdapters.create(0, Function.identity()), PrivacyParameters.DEFAULT, false, diff --git a/ethereum/referencetests/build.gradle b/ethereum/referencetests/build.gradle index 48f556a5b93..5fbab994cf0 100644 --- a/ethereum/referencetests/build.gradle +++ b/ethereum/referencetests/build.gradle @@ -191,6 +191,8 @@ dependencies { implementation 'io.tmio:tuweni-rlp' implementation 'com.fasterxml.jackson.core:jackson-databind' implementation 'com.google.guava:guava' + implementation 'com.google.dagger:dagger' + annotationProcessor 'com.google.dagger:dagger-compiler' referenceTestImplementation project(path: ':config') referenceTestImplementation project(path: ':datatypes') diff --git a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestProtocolSchedules.java b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestProtocolSchedules.java index 976c8e70d29..b9af680fe3d 100644 --- a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestProtocolSchedules.java +++ b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestProtocolSchedules.java @@ -34,6 +34,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Optional; import java.util.function.Function; import java.util.stream.Collectors; @@ -151,7 +152,7 @@ public ProtocolSpec geSpecByName(final String name) { private static ProtocolSchedule createSchedule(final GenesisConfigOptions options) { return new ProtocolScheduleBuilder( options, - CHAIN_ID, + Optional.of(CHAIN_ID), ProtocolSpecAdapters.create(0, Function.identity()), PrivacyParameters.DEFAULT, false, diff --git a/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java index cfb56d1ebc1..3a61967044d 100644 --- a/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java +++ b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java @@ -61,64 +61,64 @@ public static Stream getTestParametersForConfig() throws IOException MainnetProtocolSchedule.fromConfig( GenesisConfigFile.mainnet() .withOverrides(postMergeOverrides).getConfigOptions(), - EvmConfiguration.DEFAULT, MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem())), + EvmConfiguration.DEFAULT, MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem())), Arguments.of( "/DifficultyTests/dfGrayGlacier/difficultyGrayGlacierForkBlock.json", MainnetProtocolSchedule.fromConfig( - new StubGenesisConfigOptions().grayGlacierBlock(15050000), MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()) + new StubGenesisConfigOptions().grayGlacierBlock(15050000), MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfGrayGlacier/difficultyGrayGlacierTimeDiff1.json", MainnetProtocolSchedule.fromConfig( - new StubGenesisConfigOptions().grayGlacierBlock(15050000), MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()) + new StubGenesisConfigOptions().grayGlacierBlock(15050000), MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfGrayGlacier/difficultyGrayGlacierTimeDiff2.json", MainnetProtocolSchedule.fromConfig( - new StubGenesisConfigOptions().grayGlacierBlock(15050000), MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()) + new StubGenesisConfigOptions().grayGlacierBlock(15050000), MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfArrowGlacier/difficultyArrowGlacierForkBlock.json", MainnetProtocolSchedule.fromConfig( - new StubGenesisConfigOptions().arrowGlacierBlock(13773000), MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()) + new StubGenesisConfigOptions().arrowGlacierBlock(13773000), MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfArrowGlacier/difficultyArrowGlacierTimeDiff1.json", MainnetProtocolSchedule.fromConfig( - new StubGenesisConfigOptions().arrowGlacierBlock(13773000), MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()) + new StubGenesisConfigOptions().arrowGlacierBlock(13773000), MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfArrowGlacier/difficultyArrowGlacierTimeDiff2.json", MainnetProtocolSchedule.fromConfig( - new StubGenesisConfigOptions().arrowGlacierBlock(13773000), MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()) + new StubGenesisConfigOptions().arrowGlacierBlock(13773000), MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfByzantium/difficultyByzantium.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().byzantiumBlock(0), MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().byzantiumBlock(0), MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfConstantinople/difficultyConstantinople.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().constantinopleBlock(0), MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().constantinopleBlock(0), MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfEIP2384/difficultyEIP2384.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().muirGlacierBlock(0), MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().muirGlacierBlock(0), MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfEIP2384/difficultyEIP2384_random.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().muirGlacierBlock(0), MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().muirGlacierBlock(0), MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfEIP2384/difficultyEIP2384_random_to20M.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().muirGlacierBlock(0), MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().muirGlacierBlock(0), MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfFrontier/difficultyFrontier.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions(), MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions(), MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfHomestead/difficultyHomestead.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().homesteadBlock(0), MiningParameters.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().homesteadBlock(0), MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) )); } From 8fce5aa6ff3ef28ffd60c1888cd727c7c5fafb09 Mon Sep 17 00:00:00 2001 From: Justin Florentine Date: Sun, 3 Nov 2024 18:12:00 -0500 Subject: [PATCH 10/56] IntelliJ do not fail me (#7846) Signed-off-by: jflo --- .../tests/acceptance/dsl/node/BesuNode.java | 16 ++-- .../dsl/node/ThreadBesuNodeRunner.java | 16 ++-- .../configuration/BesuNodeConfiguration.java | 12 +-- .../BesuNodeConfigurationBuilder.java | 19 +++-- .../bft/BftMiningAcceptanceTest.java | 10 +-- .../org/hyperledger/besu/RunnerBuilder.java | 28 +++---- .../org/hyperledger/besu/cli/BesuCommand.java | 10 +-- .../besu/cli/options/MiningOptions.java | 82 ++++++++++--------- .../subcommands/blocks/BlocksSubCommand.java | 12 +-- .../besu/controller/BesuController.java | 14 ++-- .../controller/BesuControllerBuilder.java | 29 +++---- .../CliqueBesuControllerBuilder.java | 16 ++-- ...onsensusScheduleBesuControllerBuilder.java | 17 ++-- .../controller/IbftBesuControllerBuilder.java | 14 ++-- .../MainnetBesuControllerBuilder.java | 16 ++-- .../MergeBesuControllerBuilder.java | 14 ++-- .../controller/MiningParameterOverrides.java | 4 +- .../controller/QbftBesuControllerBuilder.java | 16 ++-- .../TransitionBesuControllerBuilder.java | 24 +++--- .../besu/services/BesuConfigurationImpl.java | 12 +-- .../besu/FlexGroupPrivacyTest.java | 4 +- .../besu/ForkIdsNetworkConfigTest.java | 6 +- .../hyperledger/besu/PrivacyReorgTest.java | 4 +- .../org/hyperledger/besu/PrivacyTest.java | 4 +- .../hyperledger/besu/RunnerBuilderTest.java | 4 +- .../java/org/hyperledger/besu/RunnerTest.java | 12 +-- .../chainexport/RlpBlockExporterTest.java | 4 +- .../chainimport/JsonBlockImporterTest.java | 6 +- .../chainimport/RlpBlockImporterTest.java | 8 +- .../hyperledger/besu/cli/BesuCommandTest.java | 6 +- .../cli/CascadingDefaultProviderTest.java | 6 +- .../besu/cli/options/MiningOptionsTest.java | 34 ++++---- .../AbstractBftBesuControllerBuilderTest.java | 10 +-- .../CliqueBesuControllerBuilderTest.java | 10 +-- ...nsusScheduleBesuControllerBuilderTest.java | 4 +- .../MergeBesuControllerBuilderTest.java | 8 +- .../QbftBesuControllerBuilderTest.java | 4 +- .../TransitionControllerBuilderTest.java | 20 ++--- .../besu/services/BesuEventsImplTest.java | 4 +- .../besu/services/TraceServiceImplTest.java | 4 +- .../clique/CliqueProtocolSchedule.java | 14 ++-- .../blockcreation/CliqueBlockCreator.java | 8 +- .../blockcreation/CliqueMinerExecutor.java | 10 +-- .../clique/jsonrpc/CliqueJsonRpcMethods.java | 12 +-- .../clique/CliqueProtocolScheduleTest.java | 12 +-- .../blockcreation/CliqueBlockCreatorTest.java | 28 +++---- .../CliqueMinerExecutorTest.java | 26 +++--- .../bft/BaseBftProtocolScheduleBuilder.java | 8 +- .../bft/blockcreation/BftBlockCreator.java | 8 +- .../blockcreation/BftBlockCreatorFactory.java | 20 ++--- .../CombinedProtocolScheduleFactoryTest.java | 4 +- .../BaseBftProtocolScheduleBuilderTest.java | 4 +- .../ibft/support/TestContextBuilder.java | 12 +-- .../ibft/IbftProtocolScheduleBuilder.java | 14 ++-- .../ibft/jsonrpc/IbftJsonRpcMethods.java | 12 +-- .../ibft/IbftProtocolScheduleTest.java | 8 +- .../blockcreation/BftBlockCreatorTest.java | 14 ++-- .../IbftBlockHeightManagerTest.java | 4 +- .../merge/MergeProtocolSchedule.java | 14 ++-- .../merge/TransitionProtocolSchedule.java | 10 +-- .../blockcreation/MergeBlockCreator.java | 10 +-- .../merge/blockcreation/MergeCoordinator.java | 32 ++++---- .../merge/MergeProtocolScheduleTest.java | 12 +-- .../blockcreation/MergeCoordinatorTest.java | 30 +++---- .../MergeGenesisConfigHelper.java | 4 +- .../merge/blockcreation/MergeReorgTest.java | 6 +- .../qbft/support/TestContextBuilder.java | 12 +-- .../qbft/QbftProtocolScheduleBuilder.java | 20 ++--- .../QbftBlockCreatorFactory.java | 6 +- .../qbft/jsonrpc/QbftJsonRpcMethods.java | 12 +-- .../qbft/QbftProtocolScheduleTest.java | 4 +- .../QbftBlockCreatorFactoryTest.java | 10 +-- .../QbftBlockHeightManagerTest.java | 4 +- .../api/jsonrpc/BlockchainImporter.java | 4 +- .../jsonrpc/JsonRpcTestMethodsFactory.java | 12 +-- .../EthGetFilterChangesIntegrationTest.java | 4 +- .../EthGetFilterChangesIntegrationTest.java | 4 +- .../methods/miner/MinerGetExtraData.java | 10 +-- .../methods/miner/MinerGetMinGasPrice.java | 10 +-- .../methods/miner/MinerGetMinPriorityFee.java | 10 +-- .../methods/miner/MinerSetExtraData.java | 10 +-- .../methods/miner/MinerSetMinGasPrice.java | 10 +-- .../methods/miner/MinerSetMinPriorityFee.java | 10 +-- .../methods/JsonRpcMethodsFactory.java | 6 +- .../jsonrpc/methods/MinerJsonRpcMethods.java | 20 ++--- .../ethereum/api/query/BlockchainQueries.java | 26 +++--- .../AbstractEthGraphQLHttpServiceTest.java | 4 +- .../AbstractJsonRpcHttpServiceTest.java | 8 +- .../JsonRpcHttpServiceHostAllowlistTest.java | 6 +- .../jsonrpc/JsonRpcHttpServiceLoginTest.java | 6 +- .../JsonRpcHttpServiceRpcApisTest.java | 6 +- .../jsonrpc/JsonRpcHttpServiceTestBase.java | 6 +- .../JsonRpcHttpServiceTlsClientAuthTest.java | 6 +- ...RpcHttpServiceTlsMisconfigurationTest.java | 6 +- .../jsonrpc/JsonRpcHttpServiceTlsTest.java | 6 +- .../internal/methods/EthGasPriceTest.java | 18 ++-- .../methods/EthGetBlockByNumberTest.java | 4 +- .../methods/EthGetBlockReceiptsTest.java | 4 +- .../internal/methods/EthGetProofTest.java | 4 +- .../methods/EthGetTransactionReceiptTest.java | 4 +- .../methods/EthMaxPriorityFeePerGasTest.java | 16 ++-- .../methods/miner/MinerGetExtraDataTest.java | 14 ++-- .../miner/MinerGetMinGasPriceTest.java | 17 ++-- .../miner/MinerGetMinPriorityFeeTest.java | 9 +- .../methods/miner/MinerSetExtraDataTest.java | 10 +-- .../miner/MinerSetMinGasPriceTest.java | 8 +- .../miner/MinerSetMinPriorityFeeTest.java | 8 +- .../websocket/WebSocketServiceLoginTest.java | 6 +- ...ewBlockHeadersSubscriptionServiceTest.java | 4 +- .../query/BlockchainQueriesLogCacheTest.java | 4 +- .../api/query/BlockchainQueriesTest.java | 4 +- .../blockcreation/AbstractBlockCreator.java | 16 ++-- .../blockcreation/AbstractMinerExecutor.java | 14 ++-- .../blockcreation/NoopMiningCoordinator.java | 14 ++-- .../blockcreation/PoWBlockCreator.java | 8 +- .../blockcreation/PoWMinerExecutor.java | 16 ++-- .../txselection/BlockSelectionContext.java | 4 +- .../txselection/BlockTransactionSelector.java | 10 +-- .../BlockSizeTransactionSelector.java | 4 +- ...nPriorityFeePerGasTransactionSelector.java | 2 +- .../selectors/PriceTransactionSelector.java | 4 +- .../AbstractBlockCreatorTest.java | 18 ++-- .../AbstractBlockTransactionSelectorTest.java | 78 +++++++++--------- ...FeeMarketBlockTransactionSelectorTest.java | 4 +- ...FeeMarketBlockTransactionSelectorTest.java | 18 ++-- ...orityFeePerGasTransactionSelectorTest.java | 8 +- .../blockcreation/PoWBlockCreatorTest.java | 42 +++++----- .../blockcreation/PoWMinerExecutorTest.java | 10 +-- .../PoWMiningCoordinatorTest.java | 4 +- .../components/ProtocolScheduleModule.java | 8 +- ...rameters.java => MiningConfiguration.java} | 38 +++++---- .../core/MiningParametersMetrics.java | 6 +- .../components/EthereumCoreComponent.java | 4 +- .../components/MiningParametersModule.java | 26 +++--- .../FixedDifficultyProtocolSchedule.java | 14 ++-- .../mainnet/MainnetProtocolSchedule.java | 28 +++---- .../mainnet/MainnetProtocolSpecFactory.java | 30 +++---- .../mainnet/MainnetProtocolSpecs.java | 48 +++++------ .../besu/ethereum/mainnet/PoWSolver.java | 16 ++-- .../mainnet/ProtocolScheduleBuilder.java | 10 +-- .../ethereum/core/BlockchainSetupUtil.java | 2 +- .../core/ExecutionContextTestFixture.java | 2 +- .../core/ProtocolScheduleFixture.java | 2 +- .../fixed/FixedProtocolScheduleTest.java | 4 +- .../mainnet/DefaultProtocolScheduleTest.java | 4 +- .../mainnet/MainnetProtocolScheduleTest.java | 8 +- .../besu/ethereum/mainnet/PoWSolverTest.java | 12 +-- .../mainnet/ProtocolScheduleBuilderTest.java | 6 +- .../bonsai/AbstractIsolationTests.java | 22 ++--- .../transactions/TransactionPoolFactory.java | 20 ++--- .../AbstractPrioritizedTransactions.java | 8 +- .../BaseFeePrioritizedTransactions.java | 12 +-- .../GasPricePrioritizedTransactions.java | 8 +- .../eth/manager/EthProtocolManagerTest.java | 4 +- .../ethtaskutils/AbstractMessageTaskTest.java | 4 +- .../eth/messages/BlockBodiesMessageTest.java | 4 +- .../eth/messages/BlockHeadersMessageTest.java | 4 +- .../eth/sync/ChainHeadTrackerTest.java | 4 +- .../backwardsync/BackwardSyncContextTest.java | 4 +- .../backwardsync/BackwardSyncStepTest.java | 4 +- .../backwardsync/ForwardSyncStepTest.java | 4 +- .../AbstractTransactionPoolTestBase.java | 4 +- .../ethereum/eth/transactions/TestNode.java | 6 +- .../TransactionPoolFactoryTest.java | 6 +- ...stractPrioritizedTransactionsTestBase.java | 15 ++-- .../BaseFeePrioritizedTransactionsTest.java | 10 +-- .../GasPricePrioritizedTransactionsTest.java | 6 +- .../LayeredPendingTransactionsTest.java | 4 +- .../LayeredTransactionPoolBaseFeeTest.java | 4 +- .../LayeredTransactionPoolGasPriceTest.java | 4 +- .../eth/transactions/layered/LayersTest.java | 4 +- .../eth/transactions/layered/ReplayTest.java | 4 +- .../evmtool/MainnetGenesisFileModule.java | 6 +- .../ReferenceTestProtocolSchedules.java | 4 +- .../mainnet/DifficultyCalculatorTests.java | 32 ++++---- 175 files changed, 1016 insertions(+), 1008 deletions(-) rename ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/{MiningParameters.java => MiningConfiguration.java} (88%) diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java index 21ca45070bd..76e18812b09 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java @@ -27,7 +27,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.ipc.JsonRpcIpcConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration; @@ -101,7 +101,7 @@ public class BesuNode implements NodeConfiguration, RunnableNode, AutoCloseable private final boolean revertReasonEnabled; private final String name; - private MiningParameters miningParameters; + private MiningConfiguration miningConfiguration; private TransactionPoolConfiguration txPoolConfiguration; private final List runCommand; private PrivacyParameters privacyParameters = PrivacyParameters.DEFAULT; @@ -139,7 +139,7 @@ public class BesuNode implements NodeConfiguration, RunnableNode, AutoCloseable public BesuNode( final String name, final Optional dataPath, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final TransactionPoolConfiguration txPoolConfiguration, final JsonRpcConfiguration jsonRpcConfiguration, final Optional engineRpcConfiguration, @@ -191,7 +191,7 @@ public BesuNode( }, () -> this.keyPair = KeyPairUtil.loadKeyPair(homeDirectory)); this.name = name; - this.miningParameters = miningParameters; + this.miningConfiguration = miningConfiguration; this.txPoolConfiguration = txPoolConfiguration; this.jsonRpcConfiguration = jsonRpcConfiguration; this.engineRpcConfiguration = engineRpcConfiguration; @@ -678,12 +678,12 @@ public void setBootnodes(final List bootnodes) { this.bootnodes.addAll(bootnodes); } - public MiningParameters getMiningParameters() { - return miningParameters; + public MiningConfiguration getMiningParameters() { + return miningConfiguration; } - public void setMiningParameters(final MiningParameters miningParameters) { - this.miningParameters = miningParameters; + public void setMiningParameters(final MiningConfiguration miningConfiguration) { + this.miningConfiguration = miningConfiguration; } public TransactionPoolConfiguration getTransactionPoolConfiguration() { diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java index 036a1e0019b..a76a3e6dcb5 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java @@ -36,8 +36,8 @@ import org.hyperledger.besu.ethereum.api.graphql.GraphQLConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.InProcessRpcConfiguration; import org.hyperledger.besu.ethereum.chain.Blockchain; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.plugins.PluginConfiguration; import org.hyperledger.besu.ethereum.core.plugins.PluginInfo; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; @@ -448,7 +448,7 @@ public BesuController provideBesuController( final BesuControllerBuilder builder, final MetricsSystem metricsSystem, final KeyValueStorageProvider storageProvider, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { builder .synchronizerConfiguration(synchronizerConfiguration) @@ -461,7 +461,7 @@ public BesuController provideBesuController( .evmConfiguration(EvmConfiguration.DEFAULT) .maxPeers(25) .maxRemotelyInitiatedPeers(15) - .miningParameters(miningParameters) + .miningParameters(miningConfiguration) .randomPeerPriority(false) .besuComponent(null); return builder.build(); @@ -564,11 +564,11 @@ public KeyValueStorageProvider provideKeyValueStorageProvider( } @Provides - public MiningParameters provideMiningParameters( + public MiningConfiguration provideMiningParameters( final TransactionSelectionServiceImpl transactionSelectionServiceImpl, final BesuNode node) { final var miningParameters = - ImmutableMiningParameters.builder() + ImmutableMiningConfiguration.builder() .from(node.getMiningParameters()) .transactionSelectionService(transactionSelectionServiceImpl) .build(); @@ -579,11 +579,11 @@ public MiningParameters provideMiningParameters( @Provides @Inject BesuConfiguration provideBesuConfiguration( - final Path dataDir, final MiningParameters miningParameters, final BesuNode node) { + final Path dataDir, final MiningConfiguration miningConfiguration, final BesuNode node) { final BesuConfigurationImpl commonPluginConfiguration = new BesuConfigurationImpl(); commonPluginConfiguration.init( dataDir, dataDir.resolve(DATABASE_PATH), node.getDataStorageConfiguration()); - commonPluginConfiguration.withMiningParameters(miningParameters); + commonPluginConfiguration.withMiningParameters(miningConfiguration); return commonPluginConfiguration; } } diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfiguration.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfiguration.java index ba69e4ddd72..5840f1e4f1f 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfiguration.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfiguration.java @@ -21,7 +21,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.ipc.JsonRpcIpcConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration; import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration; @@ -40,7 +40,7 @@ public class BesuNodeConfiguration { private final String name; private final Optional dataPath; - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; private final TransactionPoolConfiguration transactionPoolConfiguration; private final JsonRpcConfiguration jsonRpcConfiguration; private final Optional engineRpcConfiguration; @@ -78,7 +78,7 @@ public class BesuNodeConfiguration { BesuNodeConfiguration( final String name, final Optional dataPath, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final TransactionPoolConfiguration transactionPoolConfiguration, final JsonRpcConfiguration jsonRpcConfiguration, final Optional engineRpcConfiguration, @@ -113,7 +113,7 @@ public class BesuNodeConfiguration { final boolean strictTxReplayProtectionEnabled, final Map environment) { this.name = name; - this.miningParameters = miningParameters; + this.miningConfiguration = miningConfiguration; this.transactionPoolConfiguration = transactionPoolConfiguration; this.jsonRpcConfiguration = jsonRpcConfiguration; this.engineRpcConfiguration = engineRpcConfiguration; @@ -154,8 +154,8 @@ public String getName() { return name; } - public MiningParameters getMiningParameters() { - return miningParameters; + public MiningConfiguration getMiningParameters() { + return miningConfiguration; } public TransactionPoolConfiguration getTransactionPoolConfiguration() { diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfigurationBuilder.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfigurationBuilder.java index ead01ce97d2..9b000f56f12 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfigurationBuilder.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfigurationBuilder.java @@ -33,9 +33,9 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; import org.hyperledger.besu.ethereum.api.tls.FileBasedPasswordProvider; import org.hyperledger.besu.ethereum.core.AddressHelpers; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration; import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration; @@ -61,8 +61,8 @@ public class BesuNodeConfigurationBuilder { private String name; private Optional dataPath = Optional.empty(); - private MiningParameters miningParameters = - ImmutableMiningParameters.builder() + private MiningConfiguration miningConfiguration = + ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder().coinbase(AddressHelpers.ofValue(1)).build()) .build(); @@ -125,13 +125,14 @@ public BesuNodeConfigurationBuilder miningEnabled() { } public BesuNodeConfigurationBuilder miningEnabled(final boolean enabled) { - this.miningParameters = miningParameters.setMiningEnabled(enabled); + this.miningConfiguration = miningConfiguration.setMiningEnabled(enabled); this.jsonRpcConfiguration.addRpcApi(RpcApis.MINER.name()); return this; } - public BesuNodeConfigurationBuilder miningConfiguration(final MiningParameters miningParameters) { - this.miningParameters = miningParameters; + public BesuNodeConfigurationBuilder miningConfiguration( + final MiningConfiguration miningConfiguration) { + this.miningConfiguration = miningConfiguration; this.jsonRpcConfiguration.addRpcApi(RpcApis.MINER.name()); return this; } @@ -527,7 +528,7 @@ public BesuNodeConfiguration build() { return new BesuNodeConfiguration( name, dataPath, - miningParameters, + miningConfiguration, transactionPoolConfiguration, jsonRpcConfiguration, Optional.of(engineRpcConfiguration), diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftMiningAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftMiningAcceptanceTest.java index 1e741a5cc68..177987aaaff 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftMiningAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftMiningAcceptanceTest.java @@ -17,9 +17,9 @@ import org.hyperledger.besu.config.JsonUtil; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.AddressHelpers; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.tests.acceptance.dsl.account.Account; import org.hyperledger.besu.tests.acceptance.dsl.blockchain.Amount; import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; @@ -62,8 +62,8 @@ public void shouldMineOnSingleNodeWithFreeGas_Berlin( final String testName, final BftAcceptanceTestParameterization nodeFactory) throws Exception { setUp(testName, nodeFactory); final BesuNode minerNode = nodeFactory.createNode(besu, "miner1"); - final MiningParameters zeroGasMiningParams = - ImmutableMiningParameters.builder() + final MiningConfiguration zeroGasMiningParams = + ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .isMiningEnabled(true) diff --git a/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java b/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java index 96eef547fed..d6619d6c122 100644 --- a/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java @@ -70,7 +70,7 @@ import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.manager.EthPeers; @@ -773,7 +773,7 @@ public Runner build() { final TransactionPool transactionPool = besuController.getTransactionPool(); final MiningCoordinator miningCoordinator = besuController.getMiningCoordinator(); - final MiningParameters miningParameters = besuController.getMiningParameters(); + final MiningConfiguration miningConfiguration = besuController.getMiningParameters(); final BlockchainQueries blockchainQueries = new BlockchainQueries( @@ -783,7 +783,7 @@ public Runner build() { Optional.of(dataDir.resolve(CACHE_PATH)), Optional.of(besuController.getProtocolManager().ethContext().getScheduler()), apiConfiguration, - miningParameters); + miningConfiguration); final PrivacyParameters privacyParameters = besuController.getPrivacyParameters(); @@ -802,7 +802,7 @@ public Runner build() { Optional stratumServer = Optional.empty(); - if (miningParameters.isStratumMiningEnabled()) { + if (miningConfiguration.isStratumMiningEnabled()) { if (!(miningCoordinator instanceof PoWMiningCoordinator powMiningCoordinator)) { throw new IllegalArgumentException( "Stratum mining requires the network option(--network) to be set to CLASSIC. Stratum server requires a PoWMiningCoordinator not " @@ -813,9 +813,9 @@ public Runner build() { new StratumServer( vertx, powMiningCoordinator, - miningParameters.getStratumPort(), - miningParameters.getStratumNetworkInterface(), - miningParameters.getUnstable().getStratumExtranonce(), + miningConfiguration.getStratumPort(), + miningConfiguration.getStratumNetworkInterface(), + miningConfiguration.getUnstable().getStratumExtranonce(), metricsSystem)); miningCoordinator.addEthHashObserver(stratumServer.get()); LOG.debug("added ethash observer: {}", stratumServer.get()); @@ -849,7 +849,7 @@ public Runner build() { blockchainQueries, synchronizer, transactionPool, - miningParameters, + miningConfiguration, miningCoordinator, metricsSystem, supportedCapabilities, @@ -896,7 +896,7 @@ public Runner build() { blockchainQueries, synchronizer, transactionPool, - miningParameters, + miningConfiguration, miningCoordinator, metricsSystem, supportedCapabilities, @@ -989,7 +989,7 @@ public Runner build() { blockchainQueries, synchronizer, transactionPool, - miningParameters, + miningConfiguration, miningCoordinator, metricsSystem, supportedCapabilities, @@ -1070,7 +1070,7 @@ public Runner build() { blockchainQueries, synchronizer, transactionPool, - miningParameters, + miningConfiguration, miningCoordinator, metricsSystem, supportedCapabilities, @@ -1111,7 +1111,7 @@ public Runner build() { blockchainQueries, synchronizer, transactionPool, - miningParameters, + miningConfiguration, miningCoordinator, metricsSystem, supportedCapabilities, @@ -1273,7 +1273,7 @@ private Map jsonRpcMethods( final BlockchainQueries blockchainQueries, final Synchronizer synchronizer, final TransactionPool transactionPool, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final MiningCoordinator miningCoordinator, final ObservableMetricsSystem metricsSystem, final Set supportedCapabilities, @@ -1308,7 +1308,7 @@ private Map jsonRpcMethods( protocolContext, filterManager, transactionPool, - miningParameters, + miningConfiguration, miningCoordinator, metricsSystem, supportedCapabilities, diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index 8a012367256..b974dcd3150 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -113,7 +113,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.chain.Blockchain; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.MiningParametersMetrics; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.VersionMetadata; @@ -338,7 +338,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable { Suppliers.memoize(this::readGenesisConfigFile); private final Supplier genesisConfigOptionsSupplier = Suppliers.memoize(this::readGenesisConfigOptions); - private final Supplier miningParametersSupplier = + private final Supplier miningParametersSupplier = Suppliers.memoize(this::getMiningParameters); private RocksDBPlugin rocksDBPlugin; @@ -2117,7 +2117,7 @@ private TransactionPoolConfiguration buildTransactionPoolConfiguration() { return txPoolConfBuilder.build(); } - private MiningParameters getMiningParameters() { + private MiningConfiguration getMiningParameters() { miningOptions.setTransactionSelectionService(transactionSelectionServiceImpl); final var miningParameters = miningOptions.toDomainObject(); getGenesisBlockPeriodSeconds(genesisConfigOptionsSupplier.get()) @@ -2169,8 +2169,8 @@ public DataStorageConfiguration getDataStorageConfiguration() { return dataStorageConfiguration; } - private void initMiningParametersMetrics(final MiningParameters miningParameters) { - new MiningParametersMetrics(getMetricsSystem(), miningParameters); + private void initMiningParametersMetrics(final MiningConfiguration miningConfiguration) { + new MiningParametersMetrics(getMetricsSystem(), miningConfiguration); } private OptionalInt getGenesisBlockPeriodSeconds( diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/MiningOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/MiningOptions.java index a884edfe334..fa0cf4dc068 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/MiningOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/MiningOptions.java @@ -17,27 +17,27 @@ import static com.google.common.base.Preconditions.checkNotNull; import static java.util.Arrays.asList; import static java.util.Collections.singletonList; -import static org.hyperledger.besu.ethereum.core.MiningParameters.DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME; -import static org.hyperledger.besu.ethereum.core.MiningParameters.DEFAULT_POA_BLOCK_TXS_SELECTION_MAX_TIME; -import static org.hyperledger.besu.ethereum.core.MiningParameters.MutableInitValues.DEFAULT_EXTRA_DATA; -import static org.hyperledger.besu.ethereum.core.MiningParameters.MutableInitValues.DEFAULT_MIN_BLOCK_OCCUPANCY_RATIO; -import static org.hyperledger.besu.ethereum.core.MiningParameters.MutableInitValues.DEFAULT_MIN_PRIORITY_FEE_PER_GAS; -import static org.hyperledger.besu.ethereum.core.MiningParameters.MutableInitValues.DEFAULT_MIN_TRANSACTION_GAS_PRICE; -import static org.hyperledger.besu.ethereum.core.MiningParameters.Unstable.DEFAULT_MAX_OMMERS_DEPTH; -import static org.hyperledger.besu.ethereum.core.MiningParameters.Unstable.DEFAULT_POS_BLOCK_CREATION_MAX_TIME; -import static org.hyperledger.besu.ethereum.core.MiningParameters.Unstable.DEFAULT_POS_BLOCK_CREATION_REPETITION_MIN_DURATION; -import static org.hyperledger.besu.ethereum.core.MiningParameters.Unstable.DEFAULT_POW_JOB_TTL; -import static org.hyperledger.besu.ethereum.core.MiningParameters.Unstable.DEFAULT_REMOTE_SEALERS_LIMIT; -import static org.hyperledger.besu.ethereum.core.MiningParameters.Unstable.DEFAULT_REMOTE_SEALERS_TTL; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.DEFAULT_POA_BLOCK_TXS_SELECTION_MAX_TIME; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.MutableInitValues.DEFAULT_EXTRA_DATA; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.MutableInitValues.DEFAULT_MIN_BLOCK_OCCUPANCY_RATIO; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.MutableInitValues.DEFAULT_MIN_PRIORITY_FEE_PER_GAS; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.MutableInitValues.DEFAULT_MIN_TRANSACTION_GAS_PRICE; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.Unstable.DEFAULT_MAX_OMMERS_DEPTH; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.Unstable.DEFAULT_POS_BLOCK_CREATION_MAX_TIME; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.Unstable.DEFAULT_POS_BLOCK_CREATION_REPETITION_MIN_DURATION; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.Unstable.DEFAULT_POW_JOB_TTL; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.Unstable.DEFAULT_REMOTE_SEALERS_LIMIT; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.Unstable.DEFAULT_REMOTE_SEALERS_TTL; import org.hyperledger.besu.cli.converter.PositiveNumberConverter; import org.hyperledger.besu.cli.util.CommandLineUtils; import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.plugin.services.TransactionSelectionService; import org.hyperledger.besu.util.number.PositiveNumber; @@ -50,7 +50,7 @@ import picocli.CommandLine.ParameterException; /** The Mining CLI options. */ -public class MiningOptions implements CLIOptions { +public class MiningOptions implements CLIOptions { @Option( names = {"--miner-enabled"}, @@ -300,43 +300,45 @@ public void validate( } } - static MiningOptions fromConfig(final MiningParameters miningParameters) { + static MiningOptions fromConfig(final MiningConfiguration miningConfiguration) { final MiningOptions miningOptions = MiningOptions.create(); - miningOptions.setTransactionSelectionService(miningParameters.getTransactionSelectionService()); - miningOptions.isMiningEnabled = miningParameters.isMiningEnabled(); - miningOptions.iStratumMiningEnabled = miningParameters.isStratumMiningEnabled(); - miningOptions.stratumNetworkInterface = miningParameters.getStratumNetworkInterface(); - miningOptions.stratumPort = miningParameters.getStratumPort(); - miningOptions.extraData = miningParameters.getExtraData(); - miningOptions.minTransactionGasPrice = miningParameters.getMinTransactionGasPrice(); - miningOptions.minPriorityFeePerGas = miningParameters.getMinPriorityFeePerGas(); - miningOptions.minBlockOccupancyRatio = miningParameters.getMinBlockOccupancyRatio(); + miningOptions.setTransactionSelectionService( + miningConfiguration.getTransactionSelectionService()); + miningOptions.isMiningEnabled = miningConfiguration.isMiningEnabled(); + miningOptions.iStratumMiningEnabled = miningConfiguration.isStratumMiningEnabled(); + miningOptions.stratumNetworkInterface = miningConfiguration.getStratumNetworkInterface(); + miningOptions.stratumPort = miningConfiguration.getStratumPort(); + miningOptions.extraData = miningConfiguration.getExtraData(); + miningOptions.minTransactionGasPrice = miningConfiguration.getMinTransactionGasPrice(); + miningOptions.minPriorityFeePerGas = miningConfiguration.getMinPriorityFeePerGas(); + miningOptions.minBlockOccupancyRatio = miningConfiguration.getMinBlockOccupancyRatio(); miningOptions.nonPoaBlockTxsSelectionMaxTime = - miningParameters.getNonPoaBlockTxsSelectionMaxTime(); - miningOptions.poaBlockTxsSelectionMaxTime = miningParameters.getPoaBlockTxsSelectionMaxTime(); + miningConfiguration.getNonPoaBlockTxsSelectionMaxTime(); + miningOptions.poaBlockTxsSelectionMaxTime = + miningConfiguration.getPoaBlockTxsSelectionMaxTime(); miningOptions.unstableOptions.remoteSealersLimit = - miningParameters.getUnstable().getRemoteSealersLimit(); + miningConfiguration.getUnstable().getRemoteSealersLimit(); miningOptions.unstableOptions.remoteSealersTimeToLive = - miningParameters.getUnstable().getRemoteSealersTimeToLive(); + miningConfiguration.getUnstable().getRemoteSealersTimeToLive(); miningOptions.unstableOptions.powJobTimeToLive = - miningParameters.getUnstable().getPowJobTimeToLive(); + miningConfiguration.getUnstable().getPowJobTimeToLive(); miningOptions.unstableOptions.maxOmmersDepth = - miningParameters.getUnstable().getMaxOmmerDepth(); + miningConfiguration.getUnstable().getMaxOmmerDepth(); miningOptions.unstableOptions.stratumExtranonce = - miningParameters.getUnstable().getStratumExtranonce(); + miningConfiguration.getUnstable().getStratumExtranonce(); miningOptions.unstableOptions.posBlockCreationMaxTime = - miningParameters.getUnstable().getPosBlockCreationMaxTime(); + miningConfiguration.getUnstable().getPosBlockCreationMaxTime(); miningOptions.unstableOptions.posBlockCreationRepetitionMinDuration = - miningParameters.getUnstable().getPosBlockCreationRepetitionMinDuration(); + miningConfiguration.getUnstable().getPosBlockCreationRepetitionMinDuration(); - miningParameters.getCoinbase().ifPresent(coinbase -> miningOptions.coinbase = coinbase); - miningParameters.getTargetGasLimit().ifPresent(tgl -> miningOptions.targetGasLimit = tgl); + miningConfiguration.getCoinbase().ifPresent(coinbase -> miningOptions.coinbase = coinbase); + miningConfiguration.getTargetGasLimit().ifPresent(tgl -> miningOptions.targetGasLimit = tgl); return miningOptions; } @Override - public MiningParameters toDomainObject() { + public MiningConfiguration toDomainObject() { checkNotNull( transactionSelectionService, "transactionSelectionService must be set before using this object"); @@ -356,7 +358,7 @@ public MiningParameters toDomainObject() { updatableInitValuesBuilder.coinbase(coinbase); } - return ImmutableMiningParameters.builder() + return ImmutableMiningConfiguration.builder() .transactionSelectionService(transactionSelectionService) .mutableInitValues(updatableInitValuesBuilder.build()) .isStratumMiningEnabled(iStratumMiningEnabled) @@ -365,7 +367,7 @@ public MiningParameters toDomainObject() { .nonPoaBlockTxsSelectionMaxTime(nonPoaBlockTxsSelectionMaxTime) .poaBlockTxsSelectionMaxTime(poaBlockTxsSelectionMaxTime) .unstable( - ImmutableMiningParameters.Unstable.builder() + ImmutableMiningConfiguration.Unstable.builder() .remoteSealersLimit(unstableOptions.remoteSealersLimit) .remoteSealersTimeToLive(unstableOptions.remoteSealersTimeToLive) .powJobTimeToLive(unstableOptions.powJobTimeToLive) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/blocks/BlocksSubCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/blocks/BlocksSubCommand.java index 5bd0aacee28..95617fe8ca1 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/blocks/BlocksSubCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/blocks/BlocksSubCommand.java @@ -31,9 +31,9 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.blockcreation.IncrementingNonceGenerator; import org.hyperledger.besu.ethereum.chain.Blockchain; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.metrics.MetricsService; import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; @@ -265,12 +265,12 @@ private BesuController createController() { } } - private MiningParameters getMiningParameters() { + private MiningConfiguration getMiningParameters() { final Wei minTransactionGasPrice = Wei.ZERO; // Extradata and coinbase can be configured on a per-block level via the json file final Address coinbase = Address.ZERO; final Bytes extraData = Bytes.EMPTY; - return ImmutableMiningParameters.builder() + return ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .nonceGenerator(new IncrementingNonceGenerator(0)) @@ -377,7 +377,7 @@ private BesuController createBesuController() { return parentCommand .parentCommand .setupControllerBuilder() - .miningParameters(MiningParameters.newDefault()) + .miningParameters(MiningConfiguration.newDefault()) .build(); } diff --git a/besu/src/main/java/org/hyperledger/besu/controller/BesuController.java b/besu/src/main/java/org/hyperledger/besu/controller/BesuController.java index fb99318905a..238e5c3c1c0 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/BesuController.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/BesuController.java @@ -24,7 +24,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethods; import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.manager.EthPeers; @@ -71,7 +71,7 @@ public class BesuController implements java.io.Closeable { private final MiningCoordinator miningCoordinator; private final PrivacyParameters privacyParameters; private final List closeables; - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; private final PluginServiceFactory additionalPluginServices; private final SyncState syncState; private final EthPeers ethPeers; @@ -91,7 +91,7 @@ public class BesuController implements java.io.Closeable { * @param transactionPool the transaction pool * @param miningCoordinator the mining coordinator * @param privacyParameters the privacy parameters - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param additionalJsonRpcMethodsFactory the additional json rpc methods factory * @param nodeKey the node key * @param closeables the closeables @@ -111,7 +111,7 @@ public class BesuController implements java.io.Closeable { final TransactionPool transactionPool, final MiningCoordinator miningCoordinator, final PrivacyParameters privacyParameters, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final JsonRpcMethods additionalJsonRpcMethodsFactory, final NodeKey nodeKey, final List closeables, @@ -132,7 +132,7 @@ public class BesuController implements java.io.Closeable { this.miningCoordinator = miningCoordinator; this.privacyParameters = privacyParameters; this.closeables = closeables; - this.miningParameters = miningParameters; + this.miningConfiguration = miningConfiguration; this.additionalPluginServices = additionalPluginServices; this.ethPeers = ethPeers; this.storageProvider = storageProvider; @@ -265,8 +265,8 @@ public PrivacyParameters getPrivacyParameters() { * * @return the mining parameters */ - public MiningParameters getMiningParameters() { - return miningParameters; + public MiningConfiguration getMiningParameters() { + return miningConfiguration; } /** diff --git a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java index 6a4cc203a3b..5eb5e1214da 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java @@ -43,7 +43,7 @@ import org.hyperledger.besu.ethereum.chain.VariablesStorage; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.EthProtocol; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; @@ -144,7 +144,7 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides protected BigInteger networkId; /** The Mining parameters. */ - protected MiningParameters miningParameters; + protected MiningConfiguration miningConfiguration; /** The Metrics system. */ protected ObservableMetricsSystem metricsSystem; @@ -296,11 +296,11 @@ public BesuControllerBuilder networkId(final BigInteger networkId) { /** * Mining parameters besu controller builder. * - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @return the besu controller builder */ - public BesuControllerBuilder miningParameters(final MiningParameters miningParameters) { - this.miningParameters = miningParameters; + public BesuControllerBuilder miningParameters(final MiningConfiguration miningConfiguration) { + this.miningConfiguration = miningConfiguration; return this; } @@ -543,7 +543,7 @@ public BesuController build() { checkNotNull(syncConfig, "Missing sync config"); checkNotNull(ethereumWireProtocolConfiguration, "Missing ethereum protocol configuration"); checkNotNull(networkId, "Missing network ID"); - checkNotNull(miningParameters, "Missing mining parameters"); + checkNotNull(miningConfiguration, "Missing mining parameters"); checkNotNull(metricsSystem, "Missing metrics system"); checkNotNull(privacyParameters, "Missing privacy parameters"); checkNotNull(dataDirectory, "Missing data directory"); // Why do we need this? @@ -680,7 +680,7 @@ public BesuController build() { syncState, transactionPoolConfiguration, besuComponent.map(BesuComponent::getBlobCache).orElse(new BlobCache()), - miningParameters); + miningConfiguration); final List peerValidators = createPeerValidators(protocolSchedule); @@ -734,7 +734,7 @@ public BesuController build() { protocolSchedule, protocolContext, transactionPool, - miningParameters, + miningConfiguration, syncState, ethProtocolManager); @@ -745,7 +745,8 @@ public BesuController build() { createSubProtocolConfiguration(ethProtocolManager, maybeSnapProtocolManager); final JsonRpcMethods additionalJsonRpcMethodFactory = - createAdditionalJsonRpcMethodFactory(protocolContext, protocolSchedule, miningParameters); + createAdditionalJsonRpcMethodFactory( + protocolContext, protocolSchedule, miningConfiguration); if (DataStorageFormat.BONSAI.equals(dataStorageConfiguration.getDataStorageFormat())) { final DiffBasedSubStorageConfiguration subStorageConfiguration = @@ -779,7 +780,7 @@ public BesuController build() { transactionPool, miningCoordinator, privacyParameters, - miningParameters, + miningConfiguration, additionalJsonRpcMethodFactory, nodeKey, closeables, @@ -938,13 +939,13 @@ protected void prepForBuild() {} * * @param protocolContext the protocol context * @param protocolSchedule the protocol schedule - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @return the json rpc methods */ protected JsonRpcMethods createAdditionalJsonRpcMethodFactory( final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { return apis -> Collections.emptyMap(); } @@ -972,7 +973,7 @@ protected SubProtocolConfiguration createSubProtocolConfiguration( * @param protocolSchedule the protocol schedule * @param protocolContext the protocol context * @param transactionPool the transaction pool - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param syncState the sync state * @param ethProtocolManager the eth protocol manager * @return the mining coordinator @@ -981,7 +982,7 @@ protected abstract MiningCoordinator createMiningCoordinator( ProtocolSchedule protocolSchedule, ProtocolContext protocolContext, TransactionPool transactionPool, - MiningParameters miningParameters, + MiningConfiguration miningConfiguration, SyncState syncState, EthProtocolManager ethProtocolManager); diff --git a/besu/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java index 77bf60b034e..19840fb73da 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java @@ -36,7 +36,7 @@ import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; @@ -74,8 +74,8 @@ protected void prepForBuild() { protected JsonRpcMethods createAdditionalJsonRpcMethodFactory( final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule, - final MiningParameters miningParameters) { - return new CliqueJsonRpcMethods(protocolContext, protocolSchedule, miningParameters); + final MiningConfiguration miningConfiguration) { + return new CliqueJsonRpcMethods(protocolContext, protocolSchedule, miningConfiguration); } @Override @@ -83,7 +83,7 @@ protected MiningCoordinator createMiningCoordinator( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final TransactionPool transactionPool, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final SyncState syncState, final EthProtocolManager ethProtocolManager) { final CliqueMinerExecutor miningExecutor = @@ -92,7 +92,7 @@ protected MiningCoordinator createMiningCoordinator( protocolSchedule, transactionPool, nodeKey, - miningParameters, + miningConfiguration, new CliqueBlockScheduler( clock, protocolContext.getConsensusContext(CliqueContext.class).getValidatorProvider(), @@ -113,7 +113,7 @@ protected MiningCoordinator createMiningCoordinator( .getBlockchain() .observeBlockAdded( o -> - miningParameters.setBlockPeriodSeconds( + miningConfiguration.setBlockPeriodSeconds( forksSchedule .getFork(o.getBlock().getHeader().getNumber() + 1) .getValue() @@ -134,7 +134,7 @@ protected ProtocolSchedule createProtocolSchedule() { nodeKey, isRevertReasonEnabled, evmConfiguration, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); @@ -171,7 +171,7 @@ protected CliqueContext createConsensusContext( } @Override - public MiningParameters getMiningParameterOverrides(final MiningParameters fromCli) { + public MiningConfiguration getMiningParameterOverrides(final MiningConfiguration fromCli) { // Clique mines by default, reflect that with in the mining parameters: return fromCli.setMiningEnabled(true); } diff --git a/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java index 0d0f8d2fd87..3ecd5a6c413 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java @@ -33,7 +33,7 @@ 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.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthContext; @@ -128,7 +128,7 @@ protected MiningCoordinator createMiningCoordinator( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final TransactionPool transactionPool, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final SyncState syncState, final EthProtocolManager ethProtocolManager) { @@ -143,7 +143,7 @@ protected MiningCoordinator createMiningCoordinator( protocolSchedule, protocolContext, transactionPool, - miningParameters, + miningConfiguration, syncState, ethProtocolManager))) .collect(Collectors.toList()); @@ -206,10 +206,11 @@ protected PluginServiceFactory createAdditionalPluginServices( protected JsonRpcMethods createAdditionalJsonRpcMethodFactory( final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { return besuControllerBuilderSchedule .get(0L) - .createAdditionalJsonRpcMethodFactory(protocolContext, protocolSchedule, miningParameters); + .createAdditionalJsonRpcMethodFactory( + protocolContext, protocolSchedule, miningConfiguration); } @Override @@ -297,9 +298,9 @@ public BesuControllerBuilder networkId(final BigInteger networkId) { } @Override - public BesuControllerBuilder miningParameters(final MiningParameters miningParameters) { - besuControllerBuilderSchedule.values().forEach(b -> b.miningParameters(miningParameters)); - return super.miningParameters(miningParameters); + public BesuControllerBuilder miningParameters(final MiningConfiguration miningConfiguration) { + besuControllerBuilderSchedule.values().forEach(b -> b.miningParameters(miningConfiguration)); + return super.miningParameters(miningConfiguration); } @Override diff --git a/besu/src/main/java/org/hyperledger/besu/controller/IbftBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/IbftBesuControllerBuilder.java index 738dcfc5963..ae08b11cca4 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/IbftBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/IbftBesuControllerBuilder.java @@ -60,7 +60,7 @@ import org.hyperledger.besu.ethereum.chain.MinedBlockObserver; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.eth.EthProtocol; import org.hyperledger.besu.ethereum.eth.SnapProtocol; @@ -114,8 +114,8 @@ protected void prepForBuild() { protected JsonRpcMethods createAdditionalJsonRpcMethodFactory( final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule, - final MiningParameters miningParameters) { - return new IbftJsonRpcMethods(protocolContext, protocolSchedule, miningParameters); + final MiningConfiguration miningConfiguration) { + return new IbftJsonRpcMethods(protocolContext, protocolSchedule, miningConfiguration); } @Override @@ -141,7 +141,7 @@ protected MiningCoordinator createMiningCoordinator( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final TransactionPool transactionPool, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final SyncState syncState, final EthProtocolManager ethProtocolManager) { final MutableBlockchain blockchain = protocolContext.getBlockchain(); @@ -156,7 +156,7 @@ protected MiningCoordinator createMiningCoordinator( protocolContext, bftProtocolSchedule, forksSchedule, - miningParameters, + miningConfiguration, localAddress, bftExtraDataCodec().get(), ethProtocolManager.ethContext().getScheduler()); @@ -247,7 +247,7 @@ protected MiningCoordinator createMiningCoordinator( .getBlockchain() .observeBlockAdded( o -> - miningParameters.setBlockPeriodSeconds( + miningConfiguration.setBlockPeriodSeconds( forksSchedule .getFork(o.getBlock().getHeader().getNumber() + 1) .getValue() @@ -303,7 +303,7 @@ protected ProtocolSchedule createProtocolSchedule() { isRevertReasonEnabled, bftExtraDataCodec().get(), evmConfiguration, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); diff --git a/besu/src/main/java/org/hyperledger/besu/controller/MainnetBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/MainnetBesuControllerBuilder.java index dbd2c5904a4..a642539ac5d 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/MainnetBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/MainnetBesuControllerBuilder.java @@ -21,7 +21,7 @@ import org.hyperledger.besu.ethereum.blockcreation.PoWMinerExecutor; import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.chain.Blockchain; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; @@ -46,7 +46,7 @@ protected MiningCoordinator createMiningCoordinator( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final TransactionPool transactionPool, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final SyncState syncState, final EthProtocolManager ethProtocolManager) { @@ -55,7 +55,7 @@ protected MiningCoordinator createMiningCoordinator( protocolContext, protocolSchedule, transactionPool, - miningParameters, + miningConfiguration, new DefaultBlockScheduler( MainnetBlockHeaderValidator.MINIMUM_SECONDS_SINCE_PARENT, MainnetBlockHeaderValidator.TIMESTAMP_TOLERANCE_S, @@ -68,11 +68,11 @@ protected MiningCoordinator createMiningCoordinator( protocolContext.getBlockchain(), executor, syncState, - miningParameters.getUnstable().getRemoteSealersLimit(), - miningParameters.getUnstable().getRemoteSealersTimeToLive()); + miningConfiguration.getUnstable().getRemoteSealersLimit(), + miningConfiguration.getUnstable().getRemoteSealersTimeToLive()); miningCoordinator.addMinedBlockObserver(ethProtocolManager); - miningCoordinator.setStratumMiningEnabled(miningParameters.isStratumMiningEnabled()); - if (miningParameters.isMiningEnabled()) { + miningCoordinator.setStratumMiningEnabled(miningConfiguration.isStratumMiningEnabled()); + if (miningConfiguration.isMiningEnabled()) { miningCoordinator.enable(); } @@ -100,7 +100,7 @@ protected ProtocolSchedule createProtocolSchedule() { Optional.of(privacyParameters), Optional.of(isRevertReasonEnabled), Optional.of(evmConfiguration), - super.miningParameters, + super.miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); diff --git a/besu/src/main/java/org/hyperledger/besu/controller/MergeBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/MergeBesuControllerBuilder.java index f5fc75959e1..e7c1a5c40d8 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/MergeBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/MergeBesuControllerBuilder.java @@ -26,7 +26,7 @@ import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthMessages; @@ -67,14 +67,14 @@ protected MiningCoordinator createMiningCoordinator( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final TransactionPool transactionPool, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final SyncState syncState, final EthProtocolManager ethProtocolManager) { return createTransitionMiningCoordinator( protocolSchedule, protocolContext, transactionPool, - miningParameters, + miningConfiguration, syncState, new BackwardSyncContext( protocolContext, @@ -140,7 +140,7 @@ protected EthProtocolManager createEthProtocolManager( * @param protocolSchedule the protocol schedule * @param protocolContext the protocol context * @param transactionPool the transaction pool - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param syncState the sync state * @param backwardSyncContext the backward sync context * @param ethScheduler the scheduler @@ -150,7 +150,7 @@ protected MiningCoordinator createTransitionMiningCoordinator( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final TransactionPool transactionPool, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final SyncState syncState, final BackwardSyncContext backwardSyncContext, final EthScheduler ethScheduler) { @@ -165,7 +165,7 @@ protected MiningCoordinator createTransitionMiningCoordinator( protocolSchedule, ethScheduler, transactionPool, - miningParameters, + miningConfiguration, backwardSyncContext, depositContractAddress); } @@ -176,7 +176,7 @@ protected ProtocolSchedule createProtocolSchedule() { genesisConfigOptions, privacyParameters, isRevertReasonEnabled, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); diff --git a/besu/src/main/java/org/hyperledger/besu/controller/MiningParameterOverrides.java b/besu/src/main/java/org/hyperledger/besu/controller/MiningParameterOverrides.java index e4cebc0d648..ae2ae250ba7 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/MiningParameterOverrides.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/MiningParameterOverrides.java @@ -14,7 +14,7 @@ */ package org.hyperledger.besu.controller; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; /** * This interface wraps the provided MiningParameters to enable controller-specific parameter @@ -27,7 +27,7 @@ public interface MiningParameterOverrides { * @param fromCli The mining parameters that contains original values. * @return MiningParameters constructed from provided param with additional overridden parameters. */ - default MiningParameters getMiningParameterOverrides(final MiningParameters fromCli) { + default MiningConfiguration getMiningParameterOverrides(final MiningConfiguration fromCli) { return fromCli; } } diff --git a/besu/src/main/java/org/hyperledger/besu/controller/QbftBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/QbftBesuControllerBuilder.java index 498435e4afb..75aff308714 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/QbftBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/QbftBesuControllerBuilder.java @@ -69,7 +69,7 @@ import org.hyperledger.besu.ethereum.chain.MinedBlockObserver; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.eth.EthProtocol; import org.hyperledger.besu.ethereum.eth.SnapProtocol; @@ -130,12 +130,12 @@ protected void prepForBuild() { protected JsonRpcMethods createAdditionalJsonRpcMethodFactory( final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { return new QbftJsonRpcMethods( protocolContext, protocolSchedule, - miningParameters, + miningConfiguration, createReadOnlyValidatorProvider(protocolContext.getBlockchain()), bftConfigOptions); } @@ -181,7 +181,7 @@ protected MiningCoordinator createMiningCoordinator( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final TransactionPool transactionPool, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final SyncState syncState, final EthProtocolManager ethProtocolManager) { final MutableBlockchain blockchain = protocolContext.getBlockchain(); @@ -196,7 +196,7 @@ protected MiningCoordinator createMiningCoordinator( protocolContext, bftProtocolSchedule, qbftForksSchedule, - miningParameters, + miningConfiguration, localAddress, bftExtraDataCodec().get(), ethProtocolManager.ethContext().getScheduler()); @@ -289,12 +289,12 @@ protected MiningCoordinator createMiningCoordinator( .getBlockchain() .observeBlockAdded( o -> { - miningParameters.setBlockPeriodSeconds( + miningConfiguration.setBlockPeriodSeconds( qbftForksSchedule .getFork(o.getBlock().getHeader().getNumber() + 1) .getValue() .getBlockPeriodSeconds()); - miningParameters.setEmptyBlockPeriodSeconds( + miningConfiguration.setEmptyBlockPeriodSeconds( qbftForksSchedule .getFork(o.getBlock().getHeader().getNumber() + 1) .getValue() @@ -351,7 +351,7 @@ protected ProtocolSchedule createProtocolSchedule() { isRevertReasonEnabled, bftExtraDataCodec().get(), evmConfiguration, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); diff --git a/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java index 703592f90a9..3530621fc6a 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java @@ -30,8 +30,8 @@ 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.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthContext; @@ -102,7 +102,7 @@ protected MiningCoordinator createMiningCoordinator( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final TransactionPool transactionPool, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final SyncState syncState, final EthProtocolManager ethProtocolManager) { @@ -112,8 +112,8 @@ protected MiningCoordinator createMiningCoordinator( // PoA consensus mines by default, get consensus-specific mining parameters for // TransitionCoordinator: - MiningParameters transitionMiningParameters = - preMergeBesuControllerBuilder.getMiningParameterOverrides(miningParameters); + MiningConfiguration transitionMiningConfiguration = + preMergeBesuControllerBuilder.getMiningParameterOverrides(miningConfiguration); // construct a transition backward sync context BackwardSyncContext transitionBackwardsSyncContext = @@ -131,10 +131,10 @@ protected MiningCoordinator createMiningCoordinator( transitionProtocolSchedule.getPreMergeSchedule(), protocolContext, transactionPool, - ImmutableMiningParameters.builder() - .from(miningParameters) + ImmutableMiningConfiguration.builder() + .from(miningConfiguration) .mutableInitValues( - ImmutableMiningParameters.MutableInitValues.builder() + ImmutableMiningConfiguration.MutableInitValues.builder() .isMiningEnabled(false) .build()) .build(), @@ -144,7 +144,7 @@ protected MiningCoordinator createMiningCoordinator( transitionProtocolSchedule, protocolContext, transactionPool, - transitionMiningParameters, + transitionMiningConfiguration, syncState, transitionBackwardsSyncContext, ethProtocolManager.ethContext().getScheduler())); @@ -329,9 +329,9 @@ public BesuControllerBuilder networkId(final BigInteger networkId) { } @Override - public BesuControllerBuilder miningParameters(final MiningParameters miningParameters) { - super.miningParameters(miningParameters); - return propagateConfig(z -> z.miningParameters(miningParameters)); + public BesuControllerBuilder miningParameters(final MiningConfiguration miningConfiguration) { + super.miningParameters(miningConfiguration); + return propagateConfig(z -> z.miningParameters(miningConfiguration)); } @Override diff --git a/besu/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java b/besu/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java index 6d9a5410c47..39db58ee4d8 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java @@ -16,7 +16,7 @@ import org.hyperledger.besu.cli.options.stable.JsonRpcHttpOptions; import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; import org.hyperledger.besu.plugin.services.BesuConfiguration; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; @@ -31,7 +31,7 @@ public class BesuConfigurationImpl implements BesuConfiguration { private DataStorageConfiguration dataStorageConfiguration; // defaults - private MiningParameters miningParameters; + private MiningConfiguration miningConfiguration; private Optional rpcHttpHost = Optional.of("http://localhost"); private Optional rpcHttpPort = Optional.of(8545); @@ -59,11 +59,11 @@ public BesuConfigurationImpl init( /** * Set the mining parameters * - * @param miningParameters configured mining parameters + * @param miningConfiguration configured mining parameters * @return BesuConfigurationImpl instance */ - public BesuConfigurationImpl withMiningParameters(final MiningParameters miningParameters) { - this.miningParameters = miningParameters; + public BesuConfigurationImpl withMiningParameters(final MiningConfiguration miningConfiguration) { + this.miningConfiguration = miningConfiguration; return this; } @@ -106,7 +106,7 @@ public DataStorageFormat getDatabaseFormat() { @Override public Wei getMinGasPrice() { - return miningParameters.getMinTransactionGasPrice(); + return miningConfiguration.getMinTransactionGasPrice(); } @Override diff --git a/besu/src/test/java/org/hyperledger/besu/FlexGroupPrivacyTest.java b/besu/src/test/java/org/hyperledger/besu/FlexGroupPrivacyTest.java index a246d18d2ff..ff205e87519 100644 --- a/besu/src/test/java/org/hyperledger/besu/FlexGroupPrivacyTest.java +++ b/besu/src/test/java/org/hyperledger/besu/FlexGroupPrivacyTest.java @@ -31,7 +31,7 @@ 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.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.sync.SyncMode; @@ -150,7 +150,7 @@ BesuController provideBesuController( .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) .storageProvider(new InMemoryKeyValueStorageProvider()) .networkId(BigInteger.ONE) - .miningParameters(MiningParameters.newDefault()) + .miningParameters(MiningConfiguration.newDefault()) .dataStorageConfiguration(dataStorageConfiguration) .nodeKey(NodeKeyUtils.generate()) .metricsSystem(new NoOpMetricsSystem()) diff --git a/besu/src/test/java/org/hyperledger/besu/ForkIdsNetworkConfigTest.java b/besu/src/test/java/org/hyperledger/besu/ForkIdsNetworkConfigTest.java index 5a58091577c..87bab916f23 100644 --- a/besu/src/test/java/org/hyperledger/besu/ForkIdsNetworkConfigTest.java +++ b/besu/src/test/java/org/hyperledger/besu/ForkIdsNetworkConfigTest.java @@ -31,7 +31,7 @@ import org.hyperledger.besu.ethereum.chain.GenesisState; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.MilestoneStreamingProtocolSchedule; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.forkid.ForkId; import org.hyperledger.besu.ethereum.forkid.ForkIdManager; import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule; @@ -174,7 +174,7 @@ private static MilestoneStreamingTransitionProtocolSchedule createSchedule( (DefaultProtocolSchedule) MainnetProtocolSchedule.fromConfig( configOptions, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem())); @@ -184,7 +184,7 @@ private static MilestoneStreamingTransitionProtocolSchedule createSchedule( MergeProtocolSchedule.create( configOptions, false, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem())); diff --git a/besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java b/besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java index 6298b70a953..a79b6644587 100644 --- a/besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java +++ b/besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java @@ -47,7 +47,7 @@ import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; import org.hyperledger.besu.ethereum.core.InMemoryPrivacyStorageProvider; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; @@ -547,7 +547,7 @@ BesuController provideBesuController( .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) .storageProvider(new InMemoryKeyValueStorageProvider()) .networkId(BigInteger.ONE) - .miningParameters(MiningParameters.newDefault()) + .miningParameters(MiningConfiguration.newDefault()) .nodeKey(NodeKeyUtils.generate()) .metricsSystem(new NoOpMetricsSystem()) .dataDirectory(dataDir) diff --git a/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java b/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java index 4d488ced3bc..305d786b8bd 100644 --- a/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java +++ b/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java @@ -31,7 +31,7 @@ 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.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.sync.SyncMode; @@ -125,7 +125,7 @@ BesuController provideBesuController( .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) .storageProvider(new InMemoryKeyValueStorageProvider()) .networkId(BigInteger.ONE) - .miningParameters(MiningParameters.newDefault()) + .miningParameters(MiningConfiguration.newDefault()) .dataStorageConfiguration(dataStorageConfiguration) .nodeKey(NodeKeyUtils.generate()) .metricsSystem(new NoOpMetricsSystem()) diff --git a/besu/src/test/java/org/hyperledger/besu/RunnerBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/RunnerBuilderTest.java index 7c5579d4711..230de6efd23 100644 --- a/besu/src/test/java/org/hyperledger/besu/RunnerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/RunnerBuilderTest.java @@ -49,7 +49,7 @@ import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.manager.EthContext; @@ -128,7 +128,7 @@ public void setup() { when(besuController.getProtocolContext()).thenReturn(protocolContext); when(besuController.getProtocolSchedule()).thenReturn(protocolSchedule); when(besuController.getNodeKey()).thenReturn(nodeKey); - when(besuController.getMiningParameters()).thenReturn(mock(MiningParameters.class)); + when(besuController.getMiningParameters()).thenReturn(mock(MiningConfiguration.class)); when(besuController.getPrivacyParameters()).thenReturn(mock(PrivacyParameters.class)); when(besuController.getTransactionPool()) .thenReturn(mock(TransactionPool.class, RETURNS_DEEP_STUBS)); diff --git a/besu/src/test/java/org/hyperledger/besu/RunnerTest.java b/besu/src/test/java/org/hyperledger/besu/RunnerTest.java index 6324fabb743..4239cbdc344 100644 --- a/besu/src/test/java/org/hyperledger/besu/RunnerTest.java +++ b/besu/src/test/java/org/hyperledger/besu/RunnerTest.java @@ -46,7 +46,7 @@ import org.hyperledger.besu.ethereum.core.BlockImporter; import org.hyperledger.besu.ethereum.core.BlockSyncTestUtils; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.sync.SyncMode; @@ -196,7 +196,7 @@ private void syncFromGenesis( .isPeerTaskSystemEnabled(isPeerTaskSystemEnabled) .build(); final ObservableMetricsSystem noOpMetricsSystem = new NoOpMetricsSystem(); - final var miningParameters = MiningParameters.newDefault(); + final var miningParameters = MiningConfiguration.newDefault(); final var dataStorageConfiguration = DataStorageConfiguration.DEFAULT_FOREST_CONFIG; // Setup Runner with blocks final BesuController controllerAhead = @@ -415,11 +415,11 @@ private StorageProvider createKeyValueStorageProvider( final Path dataDir, final Path dbDir, final DataStorageConfiguration dataStorageConfiguration, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { final var besuConfiguration = new BesuConfigurationImpl(); besuConfiguration .init(dataDir, dbDir, dataStorageConfiguration) - .withMiningParameters(miningParameters); + .withMiningParameters(miningConfiguration); return new KeyValueStorageProviderBuilder() .withStorageFactory( new RocksDBKeyValueStorageFactory( @@ -488,14 +488,14 @@ private BesuController getController( final NodeKey nodeKey, final StorageProvider storageProvider, final ObservableMetricsSystem metricsSystem, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { return new MainnetBesuControllerBuilder() .genesisConfigFile(genesisConfig) .synchronizerConfiguration(syncConfig) .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) .dataDirectory(dataDir) .networkId(NETWORK_ID) - .miningParameters(miningParameters) + .miningParameters(miningConfiguration) .nodeKey(nodeKey) .storageProvider(storageProvider) .metricsSystem(metricsSystem) diff --git a/besu/src/test/java/org/hyperledger/besu/chainexport/RlpBlockExporterTest.java b/besu/src/test/java/org/hyperledger/besu/chainexport/RlpBlockExporterTest.java index bbc7dea1abb..e76c06fe2d4 100644 --- a/besu/src/test/java/org/hyperledger/besu/chainexport/RlpBlockExporterTest.java +++ b/besu/src/test/java/org/hyperledger/besu/chainexport/RlpBlockExporterTest.java @@ -31,7 +31,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.sync.SyncMode; @@ -94,7 +94,7 @@ private static BesuController createController(final @TempDir Path dataDir) thro .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) .storageProvider(new InMemoryKeyValueStorageProvider()) .networkId(BigInteger.ONE) - .miningParameters(MiningParameters.newDefault()) + .miningParameters(MiningConfiguration.newDefault()) .nodeKey(NodeKeyUtils.generate()) .metricsSystem(new NoOpMetricsSystem()) .privacyParameters(PrivacyParameters.DEFAULT) diff --git a/besu/src/test/java/org/hyperledger/besu/chainimport/JsonBlockImporterTest.java b/besu/src/test/java/org/hyperledger/besu/chainimport/JsonBlockImporterTest.java index bc52cb60be2..2b534660ed2 100644 --- a/besu/src/test/java/org/hyperledger/besu/chainimport/JsonBlockImporterTest.java +++ b/besu/src/test/java/org/hyperledger/besu/chainimport/JsonBlockImporterTest.java @@ -32,8 +32,8 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Transaction; @@ -458,7 +458,7 @@ protected BesuController createController(final GenesisConfigFile genesisConfigF .storageProvider(new InMemoryKeyValueStorageProvider()) .networkId(BigInteger.valueOf(10)) .miningParameters( - ImmutableMiningParameters.builder() + ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .isMiningEnabled(true) diff --git a/besu/src/test/java/org/hyperledger/besu/chainimport/RlpBlockImporterTest.java b/besu/src/test/java/org/hyperledger/besu/chainimport/RlpBlockImporterTest.java index 2d9e587c3fa..9f405d4cb39 100644 --- a/besu/src/test/java/org/hyperledger/besu/chainimport/RlpBlockImporterTest.java +++ b/besu/src/test/java/org/hyperledger/besu/chainimport/RlpBlockImporterTest.java @@ -26,7 +26,7 @@ import org.hyperledger.besu.cryptoservices.NodeKeyUtils; import org.hyperledger.besu.ethereum.GasLimitCalculator; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.sync.SyncMode; @@ -69,7 +69,7 @@ public void blockImport() throws IOException { .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) .storageProvider(new InMemoryKeyValueStorageProvider()) .networkId(BigInteger.ONE) - .miningParameters(MiningParameters.newDefault()) + .miningParameters(MiningConfiguration.newDefault()) .nodeKey(NodeKeyUtils.generate()) .metricsSystem(new NoOpMetricsSystem()) .privacyParameters(PrivacyParameters.DEFAULT) @@ -103,7 +103,7 @@ public void blockImportRejectsBadPow() throws IOException { .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) .storageProvider(new InMemoryKeyValueStorageProvider()) .networkId(BigInteger.ONE) - .miningParameters(MiningParameters.newDefault()) + .miningParameters(MiningConfiguration.newDefault()) .nodeKey(NodeKeyUtils.generate()) .metricsSystem(new NoOpMetricsSystem()) .privacyParameters(PrivacyParameters.DEFAULT) @@ -134,7 +134,7 @@ public void blockImportCanSkipPow() throws IOException { .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) .storageProvider(new InMemoryKeyValueStorageProvider()) .networkId(BigInteger.ONE) - .miningParameters(MiningParameters.newDefault()) + .miningParameters(MiningConfiguration.newDefault()) .nodeKey(NodeKeyUtils.generate()) .metricsSystem(new NoOpMetricsSystem()) .privacyParameters(PrivacyParameters.DEFAULT) diff --git a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java index cf3c40860d3..ea06f406ed9 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java @@ -57,7 +57,7 @@ import org.hyperledger.besu.ethereum.api.handlers.TimeoutOptions; import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.sync.SyncMode; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; import org.hyperledger.besu.ethereum.p2p.peers.EnodeURLImpl; @@ -277,8 +277,8 @@ public void callingBesuCommandWithoutOptionsMustSyncWithDefaultValues() { verify(mockRunnerBuilder).build(); verify(mockControllerBuilderFactory).fromEthNetworkConfig(ethNetworkArg.capture(), any()); - final ArgumentCaptor miningArg = - ArgumentCaptor.forClass(MiningParameters.class); + final ArgumentCaptor miningArg = + ArgumentCaptor.forClass(MiningConfiguration.class); verify(mockControllerBuilder).synchronizerConfiguration(syncConfigurationCaptor.capture()); verify(mockControllerBuilder).dataDirectory(isNotNull()); verify(mockControllerBuilder).miningParameters(miningArg.capture()); diff --git a/besu/src/test/java/org/hyperledger/besu/cli/CascadingDefaultProviderTest.java b/besu/src/test/java/org/hyperledger/besu/cli/CascadingDefaultProviderTest.java index 4cdd8163d95..c1428388149 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/CascadingDefaultProviderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/CascadingDefaultProviderTest.java @@ -33,7 +33,7 @@ import org.hyperledger.besu.ethereum.api.graphql.GraphQLConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.sync.SyncMode; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; import org.hyperledger.besu.ethereum.p2p.peers.EnodeURLImpl; @@ -200,7 +200,7 @@ public void envVariableOverridesValueFromConfigFile() { setEnvironmentVariable("BESU_MINER_COINBASE", expectedCoinbase); parseCommand("--config-file", configFile); - final var captMiningParameters = ArgumentCaptor.forClass(MiningParameters.class); + final var captMiningParameters = ArgumentCaptor.forClass(MiningConfiguration.class); verify(mockControllerBuilder).miningParameters(captMiningParameters.capture()); assertThat(captMiningParameters.getValue().getCoinbase()) @@ -219,7 +219,7 @@ public void cliOptionOverridesEnvVariableAndConfig() { setEnvironmentVariable("BESU_MINER_COINBASE", "0x0000000000000000000000000000000000000004"); parseCommand("--config-file", configFile, "--miner-coinbase", expectedCoinbase); - final var captMiningParameters = ArgumentCaptor.forClass(MiningParameters.class); + final var captMiningParameters = ArgumentCaptor.forClass(MiningConfiguration.class); verify(mockControllerBuilder).miningParameters(captMiningParameters.capture()); assertThat(captMiningParameters.getValue().getCoinbase()) diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/MiningOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/MiningOptionsTest.java index e32ff0e4630..f94504ea47c 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/MiningOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/MiningOptionsTest.java @@ -15,19 +15,19 @@ package org.hyperledger.besu.cli.options; import static org.assertj.core.api.Assertions.assertThat; -import static org.hyperledger.besu.ethereum.core.MiningParameters.DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME; -import static org.hyperledger.besu.ethereum.core.MiningParameters.DEFAULT_POA_BLOCK_TXS_SELECTION_MAX_TIME; -import static org.hyperledger.besu.ethereum.core.MiningParameters.Unstable.DEFAULT_POS_BLOCK_CREATION_MAX_TIME; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.DEFAULT_POA_BLOCK_TXS_SELECTION_MAX_TIME; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.Unstable.DEFAULT_POS_BLOCK_CREATION_MAX_TIME; import static org.mockito.Mockito.atMost; import static org.mockito.Mockito.verify; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.GasLimitCalculator; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.Unstable; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.Unstable; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.util.number.PositiveNumber; import java.io.IOException; @@ -42,7 +42,7 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -public class MiningOptionsTest extends AbstractCLIOptionsTest { +public class MiningOptionsTest extends AbstractCLIOptionsTest { @Test public void besuDoesNotStartInMiningModeIfCoinbaseNotSet() { @@ -390,13 +390,13 @@ public void poaBlockTxsSelectionMaxTimeOnlyCompatibleWithPoaNetworks() { } @Override - protected MiningParameters createDefaultDomainObject() { - return MiningParameters.newDefault(); + protected MiningConfiguration createDefaultDomainObject() { + return MiningConfiguration.newDefault(); } @Override - protected MiningParameters createCustomizedDomainObject() { - return ImmutableMiningParameters.builder() + protected MiningConfiguration createCustomizedDomainObject() { + return ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .isMiningEnabled(true) @@ -410,7 +410,7 @@ protected MiningParameters createCustomizedDomainObject() { } @Override - protected MiningOptions optionsFromDomainObject(final MiningParameters domainObject) { + protected MiningOptions optionsFromDomainObject(final MiningConfiguration domainObject) { return MiningOptions.fromConfig(domainObject); } @@ -424,11 +424,11 @@ protected String[] getNonOptionFields() { return new String[] {"transactionSelectionService"}; } - private MiningParameters runtimeConfiguration( - final TestBesuCommand besuCommand, final MiningParameters miningParameters) { + private MiningConfiguration runtimeConfiguration( + final TestBesuCommand besuCommand, final MiningConfiguration miningConfiguration) { if (besuCommand.getGenesisConfigOptions().isPoa()) { - miningParameters.setBlockPeriodSeconds(POA_BLOCK_PERIOD_SECONDS); + miningConfiguration.setBlockPeriodSeconds(POA_BLOCK_PERIOD_SECONDS); } - return miningParameters; + return miningConfiguration; } } diff --git a/besu/src/test/java/org/hyperledger/besu/controller/AbstractBftBesuControllerBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/controller/AbstractBftBesuControllerBuilderTest.java index 1d9843dc5df..e17fb04acf0 100644 --- a/besu/src/test/java/org/hyperledger/besu/controller/AbstractBftBesuControllerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/controller/AbstractBftBesuControllerBuilderTest.java @@ -34,7 +34,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; @@ -90,7 +90,7 @@ public abstract class AbstractBftBesuControllerBuilderTest { TransactionPoolConfiguration.DEFAULT; private final ObservableMetricsSystem observableMetricsSystem = new NoOpMetricsSystem(); protected final ObjectMapper objectMapper = new ObjectMapper(); - private final MiningParameters miningParameters = MiningParameters.newDefault(); + private final MiningConfiguration miningConfiguration = MiningConfiguration.newDefault(); @TempDir Path tempDir; @BeforeEach @@ -146,7 +146,7 @@ public void setup() throws JsonProcessingException { .synchronizerConfiguration(synchronizerConfiguration) .ethProtocolConfiguration(ethProtocolConfiguration) .networkId(networkId) - .miningParameters(miningParameters) + .miningParameters(miningConfiguration) .metricsSystem(observableMetricsSystem) .privacyParameters(privacyParameters) .dataDirectory(tempDir) @@ -199,8 +199,8 @@ public void miningParametersBlockPeriodSecondsIsUpdatedOnTransition() { protocolContext.getBlockchain().appendBlock(block1, List.of()); - assertThat(miningParameters.getBlockPeriodSeconds()).isNotEmpty().hasValue(2); - assertThat(miningParameters.getBlockTxsSelectionMaxTime()).isEqualTo(2000 * 75 / 100); + assertThat(miningConfiguration.getBlockPeriodSeconds()).isNotEmpty().hasValue(2); + assertThat(miningConfiguration.getBlockTxsSelectionMaxTime()).isEqualTo(2000 * 75 / 100); } protected abstract BlockHeaderFunctions getBlockHeaderFunctions(); diff --git a/besu/src/test/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilderTest.java index d73907ced7a..32924e29f92 100644 --- a/besu/src/test/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilderTest.java @@ -37,7 +37,7 @@ import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; @@ -95,7 +95,7 @@ public class CliqueBesuControllerBuilderTest { TransactionPoolConfiguration.DEFAULT; private final ObservableMetricsSystem observableMetricsSystem = new NoOpMetricsSystem(); private final ObjectMapper objectMapper = new ObjectMapper(); - private final MiningParameters miningParameters = MiningParameters.newDefault(); + private final MiningConfiguration miningConfiguration = MiningConfiguration.newDefault(); @TempDir Path tempDir; @@ -179,7 +179,7 @@ public void setup() throws JsonProcessingException { .synchronizerConfiguration(synchronizerConfiguration) .ethProtocolConfiguration(ethProtocolConfiguration) .networkId(networkId) - .miningParameters(miningParameters) + .miningParameters(miningConfiguration) .metricsSystem(observableMetricsSystem) .privacyParameters(privacyParameters) .dataDirectory(tempDir) @@ -228,7 +228,7 @@ public void miningParametersBlockPeriodSecondsIsUpdatedOnTransition() { protocolContext.getBlockchain().appendBlock(block1, List.of()); - assertThat(miningParameters.getBlockPeriodSeconds()).isNotEmpty().hasValue(2); - assertThat(miningParameters.getBlockTxsSelectionMaxTime()).isEqualTo(2000 * 75 / 100); + assertThat(miningConfiguration.getBlockPeriodSeconds()).isNotEmpty().hasValue(2); + assertThat(miningConfiguration.getBlockTxsSelectionMaxTime()).isEqualTo(2000 * 75 / 100); } } diff --git a/besu/src/test/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilderTest.java index 5efeed50b24..aefcda4c231 100644 --- a/besu/src/test/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilderTest.java @@ -32,7 +32,7 @@ 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.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; @@ -135,7 +135,7 @@ public void createsMigratingMiningCoordinator() { protocolSchedule1, mockProtocolContext, mock(TransactionPool.class), - mock(MiningParameters.class), + mock(MiningConfiguration.class), mock(SyncState.class), mock(EthProtocolManager.class)); diff --git a/besu/src/test/java/org/hyperledger/besu/controller/MergeBesuControllerBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/controller/MergeBesuControllerBuilderTest.java index f8c00b20ea7..47971b6442e 100644 --- a/besu/src/test/java/org/hyperledger/besu/controller/MergeBesuControllerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/controller/MergeBesuControllerBuilderTest.java @@ -41,7 +41,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; @@ -95,7 +95,7 @@ public class MergeBesuControllerBuilderTest { @Mock CheckpointConfigOptions checkpointConfigOptions; @Mock(answer = Answers.RETURNS_DEEP_STUBS) - MiningParameters miningParameters; + MiningConfiguration miningConfiguration; @Mock PrivacyParameters privacyParameters; @Mock Clock clock; @@ -167,7 +167,7 @@ public void setup() { lenient() .when(worldStateKeyValueStorage.updater()) .thenReturn(mock(ForestWorldStateKeyValueStorage.Updater.class)); - lenient().when(miningParameters.getTargetGasLimit()).thenReturn(OptionalLong.empty()); + lenient().when(miningConfiguration.getTargetGasLimit()).thenReturn(OptionalLong.empty()); besuControllerBuilder = visitWithMockConfigs(new MergeBesuControllerBuilder()); } @@ -179,7 +179,7 @@ MergeBesuControllerBuilder visitWithMockConfigs(final MergeBesuControllerBuilder .genesisConfigFile(genesisConfigFile) .synchronizerConfiguration(synchronizerConfiguration) .ethProtocolConfiguration(ethProtocolConfiguration) - .miningParameters(miningParameters) + .miningParameters(miningConfiguration) .metricsSystem(observableMetricsSystem) .privacyParameters(privacyParameters) .dataDirectory(tempDir) diff --git a/besu/src/test/java/org/hyperledger/besu/controller/QbftBesuControllerBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/controller/QbftBesuControllerBuilderTest.java index 3b88ae258b7..a448b11f406 100644 --- a/besu/src/test/java/org/hyperledger/besu/controller/QbftBesuControllerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/controller/QbftBesuControllerBuilderTest.java @@ -32,7 +32,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import java.util.List; @@ -107,7 +107,7 @@ public void missingTransactionValidatorProviderThrowsError() { assertThatThrownBy( () -> bftBesuControllerBuilder.createAdditionalJsonRpcMethodFactory( - protocolContext, protocolSchedule, MiningParameters.newDefault())) + protocolContext, protocolSchedule, MiningConfiguration.newDefault())) .isInstanceOf(NullPointerException.class) .hasMessage("transactionValidatorProvider should have been initialised"); } diff --git a/besu/src/test/java/org/hyperledger/besu/controller/TransitionControllerBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/controller/TransitionControllerBuilderTest.java index 40d72e4ed19..24b0133a0f1 100644 --- a/besu/src/test/java/org/hyperledger/besu/controller/TransitionControllerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/controller/TransitionControllerBuilderTest.java @@ -35,10 +35,10 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; @@ -84,7 +84,7 @@ public class TransitionControllerBuilderTest { CliqueBesuControllerBuilder cliqueBuilder = new CliqueBesuControllerBuilder(); BesuControllerBuilder powBuilder = new MainnetBesuControllerBuilder(); MergeBesuControllerBuilder postMergeBuilder = new MergeBesuControllerBuilder(); - MiningParameters miningParameters; + MiningConfiguration miningConfiguration; TransitionProtocolSchedule transitionProtocolSchedule; @@ -118,27 +118,27 @@ public void setup() { .thenReturn(mergeContext); when(ethProtocolManager.ethContext().getScheduler()) .thenReturn(new DeterministicEthScheduler()); - miningParameters = MiningParameters.newDefault(); + miningConfiguration = MiningConfiguration.newDefault(); } @Test public void assertCliqueMiningOverridePreMerge() { - assertThat(miningParameters.isMiningEnabled()).isFalse(); + assertThat(miningConfiguration.isMiningEnabled()).isFalse(); var transCoordinator = buildTransitionCoordinator(cliqueBuilder, postMergeBuilder); assertThat(transCoordinator.isMiningBeforeMerge()).isTrue(); } @Test public void assertPoWIsNotMiningPreMerge() { - assertThat(miningParameters.isMiningEnabled()).isFalse(); + assertThat(miningConfiguration.isMiningEnabled()).isFalse(); var transCoordinator = buildTransitionCoordinator(powBuilder, postMergeBuilder); assertThat(transCoordinator.isMiningBeforeMerge()).isFalse(); } @Test public void assertPowMiningPreMerge() { - miningParameters = - ImmutableMiningParameters.builder() + miningConfiguration = + ImmutableMiningConfiguration.builder() .mutableInitValues(MutableInitValues.builder().isMiningEnabled(true).build()) .build(); var transCoordinator = buildTransitionCoordinator(powBuilder, postMergeBuilder); @@ -273,7 +273,7 @@ TransitionCoordinator buildTransitionCoordinator( transitionProtocolSchedule, protocolContext, transactionPool, - miningParameters, + miningConfiguration, syncState, ethProtocolManager); diff --git a/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java b/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java index ddf68ba14ba..79885115f42 100644 --- a/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java +++ b/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java @@ -36,7 +36,7 @@ import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.core.TransactionTestFixture; @@ -173,7 +173,7 @@ public void setUp() { syncState, txPoolConfig, new BlobCache(), - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); serviceImpl = new BesuEventsImpl( diff --git a/besu/src/test/java/org/hyperledger/besu/services/TraceServiceImplTest.java b/besu/src/test/java/org/hyperledger/besu/services/TraceServiceImplTest.java index 1e734f62312..bcbf1c2fe70 100644 --- a/besu/src/test/java/org/hyperledger/besu/services/TraceServiceImplTest.java +++ b/besu/src/test/java/org/hyperledger/besu/services/TraceServiceImplTest.java @@ -31,7 +31,7 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.evm.log.Log; import org.hyperledger.besu.evm.worldstate.WorldView; @@ -80,7 +80,7 @@ public void setup() { blockchainSetupUtil.getProtocolSchedule(), blockchain, worldStateArchive, - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); traceService = new TraceServiceImpl(blockchainQueries, blockchainSetupUtil.getProtocolSchedule()); } diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueProtocolSchedule.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueProtocolSchedule.java index 551a8c3f442..2ceedb71893 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueProtocolSchedule.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueProtocolSchedule.java @@ -22,7 +22,7 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator; @@ -63,7 +63,7 @@ public class CliqueProtocolSchedule { * @param privacyParameters the privacy parameters * @param isRevertReasonEnabled the is revert reason enabled * @param evmConfiguration the evm configuration - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled * @param metricsSystem A metricSystem instance to be able to expose metrics in the underlying @@ -77,7 +77,7 @@ public static ProtocolSchedule create( final PrivacyParameters privacyParameters, final boolean isRevertReasonEnabled, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -115,7 +115,7 @@ public static ProtocolSchedule create( privacyParameters, isRevertReasonEnabled, evmConfiguration, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem) @@ -130,7 +130,7 @@ public static ProtocolSchedule create( * @param nodeKey the node key * @param isRevertReasonEnabled the is revert reason enabled * @param evmConfiguration the evm configuration - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled * @param metricsSystem A metricSystem instance to be able to expose metrics in the underlying @@ -144,7 +144,7 @@ public static ProtocolSchedule create( final NodeKey nodeKey, final boolean isRevertReasonEnabled, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -155,7 +155,7 @@ public static ProtocolSchedule create( PrivacyParameters.DEFAULT, isRevertReasonEnabled, evmConfiguration, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreator.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreator.java index ed17529a9ff..18d3449ba8d 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreator.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreator.java @@ -29,7 +29,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.SealableBlockHeader; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; @@ -48,7 +48,7 @@ public class CliqueBlockCreator extends AbstractBlockCreator { /** * Instantiates a new Clique block creator. * - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param extraDataCalculator the extra data calculator * @param transactionPool the pending transactions * @param protocolContext the protocol context @@ -58,7 +58,7 @@ public class CliqueBlockCreator extends AbstractBlockCreator { * @param ethScheduler the scheduler for asynchronous block creation tasks */ public CliqueBlockCreator( - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final ExtraDataCalculator extraDataCalculator, final TransactionPool transactionPool, final ProtocolContext protocolContext, @@ -67,7 +67,7 @@ public CliqueBlockCreator( final EpochManager epochManager, final EthScheduler ethScheduler) { super( - miningParameters, + miningConfiguration, __ -> Util.publicKeyToAddress(nodeKey.getPublicKey()), extraDataCalculator, transactionPool, diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutor.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutor.java index ef3d58fbffb..998a237e916 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutor.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutor.java @@ -28,7 +28,7 @@ import org.hyperledger.besu.ethereum.chain.MinedBlockObserver; import org.hyperledger.besu.ethereum.chain.PoWObserver; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; @@ -70,7 +70,7 @@ public CliqueMinerExecutor( final ProtocolSchedule protocolSchedule, final TransactionPool transactionPool, final NodeKey nodeKey, - final MiningParameters miningParams, + final MiningConfiguration miningParams, final AbstractBlockScheduler blockScheduler, final EpochManager epochManager, final ForksSchedule forksSchedule, @@ -97,7 +97,7 @@ public CliqueBlockMiner createMiner( final Function blockCreator = (header) -> new CliqueBlockCreator( - miningParameters, + miningConfiguration, this::calculateExtraData, transactionPool, protocolContext, @@ -119,7 +119,7 @@ public CliqueBlockMiner createMiner( @Override public Optional
getCoinbase() { - return miningParameters.getCoinbase(); + return miningConfiguration.getCoinbase(); } /** @@ -134,7 +134,7 @@ Bytes calculateExtraData(final BlockHeader parentHeader) { final Bytes vanityDataToInsert = ConsensusHelpers.zeroLeftPad( - miningParameters.getExtraData(), CliqueExtraData.EXTRA_VANITY_LENGTH); + miningConfiguration.getExtraData(), CliqueExtraData.EXTRA_VANITY_LENGTH); // Building ON TOP of canonical head, if the next block is epoch, include validators. if (epochManager.isEpochBlock(parentHeader.getNumber() + 1)) { diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/CliqueJsonRpcMethods.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/CliqueJsonRpcMethods.java index 762cce1c569..4e1e75f54c8 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/CliqueJsonRpcMethods.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/CliqueJsonRpcMethods.java @@ -31,7 +31,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.methods.ApiGroupJsonRpcMethods; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; @@ -41,22 +41,22 @@ public class CliqueJsonRpcMethods extends ApiGroupJsonRpcMethods { private final ProtocolContext context; private final ProtocolSchedule protocolSchedule; - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; /** * Instantiates a new Clique json rpc methods. * * @param context the protocol context * @param protocolSchedule the protocol schedule - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters */ public CliqueJsonRpcMethods( final ProtocolContext context, final ProtocolSchedule protocolSchedule, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { this.context = context; this.protocolSchedule = protocolSchedule; - this.miningParameters = miningParameters; + this.miningConfiguration = miningConfiguration; } @Override @@ -69,7 +69,7 @@ protected Map create() { final MutableBlockchain blockchain = context.getBlockchain(); final WorldStateArchive worldStateArchive = context.getWorldStateArchive(); final BlockchainQueries blockchainQueries = - new BlockchainQueries(protocolSchedule, blockchain, worldStateArchive, miningParameters); + new BlockchainQueries(protocolSchedule, blockchain, worldStateArchive, miningConfiguration); final ValidatorProvider validatorProvider = context.getConsensusContext(CliqueContext.class).getValidatorProvider(); diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueProtocolScheduleTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueProtocolScheduleTest.java index 5cbdbb6d06e..083604af6f0 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueProtocolScheduleTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueProtocolScheduleTest.java @@ -32,7 +32,7 @@ import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; @@ -68,7 +68,7 @@ public void protocolSpecsAreCreatedAtBlockDefinedInJson() { NODE_KEY, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -94,7 +94,7 @@ public void parametersAlignWithMainnetWithAdjustments() { NODE_KEY, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) @@ -120,7 +120,7 @@ public void zeroEpochLengthThrowsException() { NODE_KEY, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem())) @@ -142,7 +142,7 @@ public void negativeEpochLengthThrowsException() { NODE_KEY, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem())) @@ -168,7 +168,7 @@ public void shouldValidateBaseFeeMarketTransition() { NODE_KEY, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreatorTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreatorTest.java index ca76517c62c..fdc068ddef7 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreatorTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreatorTest.java @@ -49,9 +49,9 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; @@ -106,7 +106,7 @@ void setup() { proposerNodeKey, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -146,11 +146,11 @@ public void proposerAddressCanBeExtractFromAConstructedBlock() { final Address coinbase = AddressHelpers.ofValue(1); - final MiningParameters miningParameters = createMiningParameters(extraData, coinbase); + final MiningConfiguration miningConfiguration = createMiningParameters(extraData, coinbase); final CliqueBlockCreator blockCreator = new CliqueBlockCreator( - miningParameters, + miningConfiguration, parent -> extraData, createTransactionPool(), protocolContext, @@ -175,11 +175,11 @@ public void insertsValidVoteIntoConstructedBlock() { when(voteProvider.getVoteAfterBlock(any(), any())) .thenReturn(Optional.of(new ValidatorVote(VoteType.ADD, coinbase, a1))); - final MiningParameters miningParameters = createMiningParameters(extraData, coinbase); + final MiningConfiguration miningConfiguration = createMiningParameters(extraData, coinbase); final CliqueBlockCreator blockCreator = new CliqueBlockCreator( - miningParameters, + miningConfiguration, parent -> extraData, createTransactionPool(), protocolContext, @@ -209,11 +209,11 @@ public void insertsNoVoteWhenAtEpoch() { when(mockVoteProvider.getVoteAfterBlock(any(), any())) .thenReturn(Optional.of(new ValidatorVote(VoteType.ADD, coinbase, a1))); - final MiningParameters miningParameters = createMiningParameters(extraData, coinbase); + final MiningConfiguration miningConfiguration = createMiningParameters(extraData, coinbase); final CliqueBlockCreator blockCreator = new CliqueBlockCreator( - miningParameters, + miningConfiguration, parent -> extraData, createTransactionPool(), protocolContext, @@ -252,10 +252,10 @@ private TransactionPool createTransactionPool() { return transactionPool; } - private static MiningParameters createMiningParameters( + private static MiningConfiguration createMiningParameters( final Bytes extraData, final Address coinbase) { - final MiningParameters miningParameters = - ImmutableMiningParameters.builder() + final MiningConfiguration miningConfiguration = + ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .extraData(extraData) @@ -264,6 +264,6 @@ private static MiningParameters createMiningParameters( .coinbase(coinbase) .build()) .build(); - return miningParameters; + return miningConfiguration; } } diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java index 1aa2d75ef3b..3d6dbd77db9 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java @@ -39,9 +39,9 @@ import org.hyperledger.besu.ethereum.core.AddressHelpers; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; @@ -105,7 +105,7 @@ public void setup() { proposerNodeKey, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -117,7 +117,7 @@ public void setup() { public void extraDataCreatedOnEpochBlocksContainsValidators() { final Bytes vanityData = generateRandomVanityData(); - final MiningParameters miningParameters = createMiningParameters(vanityData); + final MiningConfiguration miningConfiguration = createMiningParameters(vanityData); final CliqueMinerExecutor executor = new CliqueMinerExecutor( @@ -125,7 +125,7 @@ public void extraDataCreatedOnEpochBlocksContainsValidators() { cliqueProtocolSchedule, createTransactionPool(), proposerNodeKey, - miningParameters, + miningConfiguration, mock(CliqueBlockScheduler.class), new EpochManager(EPOCH_LENGTH), null, @@ -153,7 +153,7 @@ public void extraDataCreatedOnEpochBlocksContainsValidators() { public void extraDataForNonEpochBlocksDoesNotContainValidaors() { final Bytes vanityData = generateRandomVanityData(); - final MiningParameters miningParameters = createMiningParameters(vanityData); + final MiningConfiguration miningConfiguration = createMiningParameters(vanityData); final CliqueMinerExecutor executor = new CliqueMinerExecutor( @@ -161,7 +161,7 @@ public void extraDataForNonEpochBlocksDoesNotContainValidaors() { cliqueProtocolSchedule, createTransactionPool(), proposerNodeKey, - miningParameters, + miningConfiguration, mock(CliqueBlockScheduler.class), new EpochManager(EPOCH_LENGTH), null, @@ -189,7 +189,7 @@ public void shouldUseLatestVanityData() { final Bytes initialVanityData = generateRandomVanityData(); final Bytes modifiedVanityData = generateRandomVanityData(); - final MiningParameters miningParameters = createMiningParameters(initialVanityData); + final MiningConfiguration miningConfiguration = createMiningParameters(initialVanityData); final CliqueMinerExecutor executor = new CliqueMinerExecutor( @@ -197,13 +197,13 @@ public void shouldUseLatestVanityData() { cliqueProtocolSchedule, createTransactionPool(), proposerNodeKey, - miningParameters, + miningConfiguration, mock(CliqueBlockScheduler.class), new EpochManager(EPOCH_LENGTH), null, ethScheduler); - miningParameters.setExtraData(modifiedVanityData); + miningConfiguration.setExtraData(modifiedVanityData); final Bytes extraDataBytes = executor.calculateExtraData(blockHeaderBuilder.buildHeader()); final CliqueExtraData cliqueExtraData = @@ -253,8 +253,8 @@ private Bytes generateRandomVanityData() { return Bytes.wrap(vanityData); } - private static MiningParameters createMiningParameters(final Bytes vanityData) { - return ImmutableMiningParameters.builder() + private static MiningConfiguration createMiningParameters(final Bytes vanityData) { + return ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .extraData(vanityData) diff --git a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilder.java b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilder.java index 0df63452b34..29ec30d6679 100644 --- a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilder.java +++ b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilder.java @@ -19,7 +19,7 @@ import org.hyperledger.besu.consensus.common.ForksSchedule; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator; import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule; @@ -58,7 +58,7 @@ protected BaseBftProtocolScheduleBuilder() {} * @param isRevertReasonEnabled the is revert reason enabled * @param bftExtraDataCodec the bft extra data codec * @param evmConfiguration the evm configuration - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled. * @param metricsSystem metricsSystem A metricSystem instance to be able to expose metrics in the @@ -72,7 +72,7 @@ public BftProtocolSchedule createProtocolSchedule( final boolean isRevertReasonEnabled, final BftExtraDataCodec bftExtraDataCodec, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -96,7 +96,7 @@ public BftProtocolSchedule createProtocolSchedule( privacyParameters, isRevertReasonEnabled, evmConfiguration, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem) diff --git a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftBlockCreator.java b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftBlockCreator.java index 6bc0254b691..70d18fc3c93 100644 --- a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftBlockCreator.java +++ b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftBlockCreator.java @@ -25,7 +25,7 @@ import org.hyperledger.besu.ethereum.blockcreation.AbstractBlockCreator; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.SealableBlockHeader; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; @@ -46,7 +46,7 @@ public class BftBlockCreator extends AbstractBlockCreator { /** * Instantiates a new Bft block creator. * - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param forksSchedule the forks schedule * @param localAddress the local address * @param extraDataCalculator the extra data calculator @@ -57,7 +57,7 @@ public class BftBlockCreator extends AbstractBlockCreator { * @param ethScheduler the scheduler for asynchronous block creation tasks */ public BftBlockCreator( - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final ForksSchedule forksSchedule, final Address localAddress, final ExtraDataCalculator extraDataCalculator, @@ -67,7 +67,7 @@ public BftBlockCreator( final BftExtraDataCodec bftExtraDataCodec, final EthScheduler ethScheduler) { super( - miningParameters.setCoinbase(localAddress), + miningConfiguration.setCoinbase(localAddress), miningBeneficiaryCalculator(localAddress, forksSchedule), extraDataCalculator, transactionPool, diff --git a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftBlockCreatorFactory.java b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftBlockCreatorFactory.java index 7c679763b60..1349bbf4619 100644 --- a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftBlockCreatorFactory.java +++ b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftBlockCreatorFactory.java @@ -31,7 +31,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.blockcreation.BlockCreator; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; import org.hyperledger.besu.ethereum.mainnet.AbstractGasLimitSpecification; @@ -54,7 +54,7 @@ public class BftBlockCreatorFactory { protected final ForksSchedule forksSchedule; /** The Mining parameters */ - protected final MiningParameters miningParameters; + protected final MiningConfiguration miningConfiguration; private final TransactionPool transactionPool; @@ -89,7 +89,7 @@ public BftBlockCreatorFactory( final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule, final ForksSchedule forksSchedule, - final MiningParameters miningParams, + final MiningConfiguration miningParams, final Address localAddress, final BftExtraDataCodec bftExtraDataCodec, final EthScheduler ethScheduler) { @@ -98,7 +98,7 @@ public BftBlockCreatorFactory( this.protocolSchedule = protocolSchedule; this.forksSchedule = forksSchedule; this.localAddress = localAddress; - this.miningParameters = miningParams; + this.miningConfiguration = miningParams; this.bftExtraDataCodec = bftExtraDataCodec; this.ethScheduler = ethScheduler; } @@ -111,7 +111,7 @@ public BftBlockCreatorFactory( */ public BlockCreator create(final int round) { return new BftBlockCreator( - miningParameters, + miningConfiguration, forksSchedule, localAddress, ph -> createExtraData(round, ph), @@ -128,7 +128,7 @@ public BlockCreator create(final int round) { * @param minTransactionGasPrice the min transaction gas price */ public void setMinTransactionGasPrice(final Wei minTransactionGasPrice) { - miningParameters.setMinTransactionGasPrice(minTransactionGasPrice); + miningConfiguration.setMinTransactionGasPrice(minTransactionGasPrice); } /** @@ -137,7 +137,7 @@ public void setMinTransactionGasPrice(final Wei minTransactionGasPrice) { * @return the min transaction gas price */ public Wei getMinTransactionGasPrice() { - return miningParameters.getMinTransactionGasPrice(); + return miningConfiguration.getMinTransactionGasPrice(); } /** @@ -146,7 +146,7 @@ public Wei getMinTransactionGasPrice() { * @return min priority fee per gas */ public Wei getMinPriorityFeePerGas() { - return miningParameters.getMinPriorityFeePerGas(); + return miningConfiguration.getMinPriorityFeePerGas(); } /** @@ -171,7 +171,7 @@ public Bytes createExtraData(final int round, final BlockHeader parentHeader) { final BftExtraData extraData = new BftExtraData( ConsensusHelpers.zeroLeftPad( - miningParameters.getExtraData(), BftExtraDataCodec.EXTRA_VANITY_LENGTH), + miningConfiguration.getExtraData(), BftExtraDataCodec.EXTRA_VANITY_LENGTH), Collections.emptyList(), toVote(proposal), round, @@ -187,7 +187,7 @@ public Bytes createExtraData(final int round, final BlockHeader parentHeader) { */ public void changeTargetGasLimit(final Long newTargetGasLimit) { if (AbstractGasLimitSpecification.isValidTargetGasLimit(newTargetGasLimit)) { - miningParameters.setTargetGasLimit(newTargetGasLimit); + miningConfiguration.setTargetGasLimit(newTargetGasLimit); } else { throw new UnsupportedOperationException("Specified target gas limit is invalid"); } diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java index 659337bdd2e..02da30f5075 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java @@ -21,7 +21,7 @@ import org.hyperledger.besu.consensus.common.bft.BftProtocolSchedule; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.MilestoneStreamingProtocolSchedule; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; @@ -177,7 +177,7 @@ private BftProtocolSchedule createProtocolSchedule( new PrivacyParameters(), false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilderTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilderTest.java index e23664fd8d3..56a0e33986b 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilderTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilderTest.java @@ -31,7 +31,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.MilestoneStreamingProtocolSchedule; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator; import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule; @@ -245,7 +245,7 @@ protected BlockHeaderValidator.Builder createBlockHeaderRuleset( false, bftExtraDataCodec, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/TestContextBuilder.java b/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/TestContextBuilder.java index 8896733548d..a5d24ff4dbc 100644 --- a/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/TestContextBuilder.java +++ b/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/TestContextBuilder.java @@ -78,9 +78,9 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; @@ -310,8 +310,8 @@ private static ControllerAndState createControllerAndFinalState( final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive(); - final MiningParameters miningParams = - ImmutableMiningParameters.builder() + final MiningConfiguration miningParams = + ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .isMiningEnabled(true) @@ -334,7 +334,7 @@ private static ControllerAndState createControllerAndFinalState( forksSchedule, IBFT_EXTRA_DATA_ENCODER, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleBuilder.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleBuilder.java index 3adf5718955..adc4698e4d5 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleBuilder.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleBuilder.java @@ -21,7 +21,7 @@ import org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec; import org.hyperledger.besu.consensus.common.bft.BftProtocolSchedule; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator; import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket; @@ -46,7 +46,7 @@ protected IbftProtocolScheduleBuilder() {} * @param isRevertReasonEnabled the is revert reason enabled * @param bftExtraDataCodec the bft extra data codec * @param evmConfiguration the evm configuration - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled * @param metricsSystem A metricSystem instance to be able to expose metrics in the underlying @@ -60,7 +60,7 @@ public static BftProtocolSchedule create( final boolean isRevertReasonEnabled, final BftExtraDataCodec bftExtraDataCodec, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -72,7 +72,7 @@ public static BftProtocolSchedule create( isRevertReasonEnabled, bftExtraDataCodec, evmConfiguration, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); @@ -85,7 +85,7 @@ public static BftProtocolSchedule create( * @param forksSchedule the forks schedule * @param bftExtraDataCodec the bft extra data codec * @param evmConfiguration the evm configuration - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled. * @param metricsSystem A metricSystem instance to be able to expose metrics in the underlying @@ -97,7 +97,7 @@ public static BftProtocolSchedule create( final ForksSchedule forksSchedule, final BftExtraDataCodec bftExtraDataCodec, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -108,7 +108,7 @@ public static BftProtocolSchedule create( false, bftExtraDataCodec, evmConfiguration, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/IbftJsonRpcMethods.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/IbftJsonRpcMethods.java index 1afe067867d..a777d7d175e 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/IbftJsonRpcMethods.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/IbftJsonRpcMethods.java @@ -32,7 +32,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.methods.ApiGroupJsonRpcMethods; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import java.util.Map; @@ -42,22 +42,22 @@ public class IbftJsonRpcMethods extends ApiGroupJsonRpcMethods { private final ProtocolContext context; private final ProtocolSchedule protocolSchedule; - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; /** * Instantiates a new Ibft json rpc methods. * * @param context the protocol context * @param protocolSchedule the protocol schedule - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters */ public IbftJsonRpcMethods( final ProtocolContext context, final ProtocolSchedule protocolSchedule, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { this.context = context; this.protocolSchedule = protocolSchedule; - this.miningParameters = miningParameters; + this.miningConfiguration = miningConfiguration; } @Override @@ -70,7 +70,7 @@ protected Map create() { final MutableBlockchain blockchain = context.getBlockchain(); final BlockchainQueries blockchainQueries = new BlockchainQueries( - protocolSchedule, blockchain, context.getWorldStateArchive(), miningParameters); + protocolSchedule, blockchain, context.getWorldStateArchive(), miningConfiguration); final BftContext bftContext = context.getConsensusContext(BftContext.class); final BlockInterface blockInterface = bftContext.getBlockInterface(); final ValidatorProvider validatorProvider = diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleTest.java index a5510ea80a6..9cb760551e0 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleTest.java @@ -39,7 +39,7 @@ import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.MilestoneStreamingProtocolSchedule; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.core.components.EthereumCoreComponent; @@ -127,7 +127,7 @@ private BftProtocolSchedule createProtocolSchedule( false, bftExtraDataCodec, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -191,8 +191,8 @@ interface TestEthCoreComponent extends EthereumCoreComponent { @Module static class NoMiningParamters { @Provides - MiningParameters provideMiningParameters() { - return MiningParameters.MINING_DISABLED; + MiningConfiguration provideMiningParameters() { + return MiningConfiguration.MINING_DISABLED; } } } diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/blockcreation/BftBlockCreatorTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/blockcreation/BftBlockCreatorTest.java index 5469717b13f..df5a313ae77 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/blockcreation/BftBlockCreatorTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/blockcreation/BftBlockCreatorTest.java @@ -42,9 +42,9 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; @@ -122,7 +122,7 @@ public BlockHeaderValidator.Builder createBlockHeaderRuleset( false, bftExtraDataEncoder, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -159,8 +159,8 @@ public BlockHeaderValidator.Builder createBlockHeaderRuleset( transactionPool.setEnabled(); - final MiningParameters miningParameters = - ImmutableMiningParameters.builder() + final MiningConfiguration miningConfiguration = + ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .extraData( @@ -178,7 +178,7 @@ public BlockHeaderValidator.Builder createBlockHeaderRuleset( final BftBlockCreator blockCreator = new BftBlockCreator( - miningParameters, + miningConfiguration, forksSchedule, initialValidatorList.get(0), parent -> diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java index 9ca5b0b8e1e..79022b7d544 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java @@ -70,7 +70,7 @@ import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule; @@ -185,7 +185,7 @@ public void setup() { new PrivacyParameters(), false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/MergeProtocolSchedule.java b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/MergeProtocolSchedule.java index f794152a78b..a8c84d5a093 100644 --- a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/MergeProtocolSchedule.java +++ b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/MergeProtocolSchedule.java @@ -17,7 +17,7 @@ import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; @@ -48,7 +48,7 @@ public class MergeProtocolSchedule { * * @param config the config * @param isRevertReasonEnabled the is revert reason enabled - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled. * @return the protocol schedule @@ -56,7 +56,7 @@ public class MergeProtocolSchedule { public static ProtocolSchedule create( final GenesisConfigOptions config, final boolean isRevertReasonEnabled, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -64,7 +64,7 @@ public static ProtocolSchedule create( config, PrivacyParameters.DEFAULT, isRevertReasonEnabled, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); @@ -76,7 +76,7 @@ public static ProtocolSchedule create( * @param config the config * @param privacyParameters the privacy parameters * @param isRevertReasonEnabled the is revert reason enabled - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled. * @return the protocol schedule @@ -85,7 +85,7 @@ public static ProtocolSchedule create( final GenesisConfigOptions config, final PrivacyParameters privacyParameters, final boolean isRevertReasonEnabled, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -106,7 +106,7 @@ public static ProtocolSchedule create( privacyParameters, isRevertReasonEnabled, EvmConfiguration.DEFAULT, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem) diff --git a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionProtocolSchedule.java b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionProtocolSchedule.java index e733cc800ec..44fd5f8edfc 100644 --- a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionProtocolSchedule.java +++ b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionProtocolSchedule.java @@ -20,7 +20,7 @@ import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PermissionTransactionFilter; import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader; import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule; @@ -65,21 +65,21 @@ public TransitionProtocolSchedule( * * @param genesisConfigOptions {@link GenesisConfigOptions} containing the config options for the * milestone starting points - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled. * @return an initialised TransitionProtocolSchedule using post-merge defaults */ public static TransitionProtocolSchedule fromConfig( final GenesisConfigOptions genesisConfigOptions, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { ProtocolSchedule preMergeProtocolSchedule = MainnetProtocolSchedule.fromConfig( genesisConfigOptions, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); @@ -87,7 +87,7 @@ public static TransitionProtocolSchedule fromConfig( MergeProtocolSchedule.create( genesisConfigOptions, false, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); diff --git a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeBlockCreator.java b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeBlockCreator.java index c56c62d80db..56c78877a67 100644 --- a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeBlockCreator.java +++ b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeBlockCreator.java @@ -19,7 +19,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.SealableBlockHeader; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.Withdrawal; @@ -39,7 +39,7 @@ class MergeBlockCreator extends AbstractBlockCreator { /** * Instantiates a new Merge block creator. * - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param extraDataCalculator the extra data calculator * @param transactionPool the pending transactions * @param protocolContext the protocol context @@ -47,7 +47,7 @@ class MergeBlockCreator extends AbstractBlockCreator { * @param parentHeader the parent header */ public MergeBlockCreator( - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final ExtraDataCalculator extraDataCalculator, final TransactionPool transactionPool, final ProtocolContext protocolContext, @@ -55,8 +55,8 @@ public MergeBlockCreator( final BlockHeader parentHeader, final EthScheduler ethScheduler) { super( - miningParameters, - __ -> miningParameters.getCoinbase().orElseThrow(), + miningConfiguration, + __ -> miningConfiguration.getCoinbase().orElseThrow(), extraDataCalculator, transactionPool, protocolContext, diff --git a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java index 877d7fb9633..7570e97d4d6 100644 --- a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java +++ b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java @@ -33,7 +33,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockWithReceipts; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.Withdrawal; @@ -81,7 +81,7 @@ public class MergeCoordinator implements MergeMiningCoordinator, BadChainListene private static final long DEFAULT_TARGET_GAS_LIMIT = 30000000L; /** The Mining parameters. */ - protected final MiningParameters miningParameters; + protected final MiningConfiguration miningConfiguration; /** The Merge block creator factory. */ protected final MergeBlockCreatorFactory mergeBlockCreatorFactory; @@ -120,7 +120,7 @@ public MergeCoordinator( final ProtocolSchedule protocolSchedule, final EthScheduler ethScheduler, final TransactionPool transactionPool, - final MiningParameters miningParams, + final MiningConfiguration miningParams, final BackwardSyncContext backwardSyncContext, final Optional
depositContractAddress) { this.protocolContext = protocolContext; @@ -137,14 +137,14 @@ public MergeCoordinator( } miningParams.setMinBlockOccupancyRatio(TRY_FILL_BLOCK); - this.miningParameters = miningParams; + this.miningConfiguration = miningParams; this.mergeBlockCreatorFactory = (parentHeader, address) -> { address.ifPresent(miningParams::setCoinbase); return new MergeBlockCreator( - miningParameters, - parent -> miningParameters.getExtraData(), + miningConfiguration, + parent -> miningConfiguration.getExtraData(), transactionPool, protocolContext, protocolSchedule, @@ -169,7 +169,7 @@ public MergeCoordinator( final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule, final EthScheduler ethScheduler, - final MiningParameters miningParams, + final MiningConfiguration miningParams, final BackwardSyncContext backwardSyncContext, final MergeBlockCreatorFactory mergeBlockCreatorFactory) { @@ -182,7 +182,7 @@ public MergeCoordinator( miningParams.setTargetGasLimit(DEFAULT_TARGET_GAS_LIMIT); } miningParams.setMinBlockOccupancyRatio(TRY_FILL_BLOCK); - this.miningParameters = miningParams; + this.miningConfiguration = miningParams; this.mergeBlockCreatorFactory = mergeBlockCreatorFactory; @@ -215,17 +215,17 @@ public boolean isMining() { @Override public Wei getMinTransactionGasPrice() { - return miningParameters.getMinTransactionGasPrice(); + return miningConfiguration.getMinTransactionGasPrice(); } @Override public Wei getMinPriorityFeePerGas() { - return miningParameters.getMinPriorityFeePerGas(); + return miningConfiguration.getMinPriorityFeePerGas(); } @Override public Optional
getCoinbase() { - return miningParameters.getCoinbase(); + return miningConfiguration.getCoinbase(); } @Override @@ -244,7 +244,7 @@ public Optional createBlock(final BlockHeader parentHeader, final long ti @Override public void changeTargetGasLimit(final Long newTargetGasLimit) { if (AbstractGasLimitSpecification.isValidTargetGasLimit(newTargetGasLimit)) { - this.miningParameters.setTargetGasLimit(newTargetGasLimit); + this.miningConfiguration.setTargetGasLimit(newTargetGasLimit); } else { throw new IllegalArgumentException("Specified target gas limit is invalid"); } @@ -383,13 +383,13 @@ private void tryToBuildBetterBlock( LOG.debug( "Block creation started for payload id {}, remaining time is {}ms", payloadIdentifier, - miningParameters.getUnstable().getPosBlockCreationMaxTime()); + miningConfiguration.getUnstable().getPosBlockCreationMaxTime()); ethScheduler .scheduleBlockCreationTask( () -> retryBlockCreationUntilUseful(payloadIdentifier, blockCreator)) .orTimeout( - miningParameters.getUnstable().getPosBlockCreationMaxTime(), TimeUnit.MILLISECONDS) + miningConfiguration.getUnstable().getPosBlockCreationMaxTime(), TimeUnit.MILLISECONDS) .whenComplete( (unused, throwable) -> { if (throwable != null) { @@ -416,7 +416,7 @@ private Void retryBlockCreationUntilUseful( final long waitBeforeRepetition = Math.max( 100, - miningParameters.getUnstable().getPosBlockCreationRepetitionMinDuration() + miningConfiguration.getUnstable().getPosBlockCreationRepetitionMinDuration() - lastDuration); LOG.debug("Waiting {}ms before repeating block creation", waitBeforeRepetition); Thread.sleep(waitBeforeRepetition); @@ -726,7 +726,7 @@ public CompletableFuture appendNewPayloadToSync(final Block newPayload) { @Override public boolean isMiningBeforeMerge() { - return miningParameters.isMiningEnabled(); + return miningConfiguration.isMiningEnabled(); } private Optional findValidAncestor(final Blockchain chain, final Hash parentHash) { diff --git a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/MergeProtocolScheduleTest.java b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/MergeProtocolScheduleTest.java index 0d4aede3a14..ba83f8aad9c 100644 --- a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/MergeProtocolScheduleTest.java +++ b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/MergeProtocolScheduleTest.java @@ -22,7 +22,7 @@ import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockProcessor; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; @@ -51,7 +51,7 @@ public void protocolSpecsAreCreatedAtBlockDefinedInJson() { MergeProtocolSchedule.create( config, false, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -72,7 +72,7 @@ public void mergeSpecificModificationsAreUnappliedForShanghai() { MergeProtocolSchedule.create( config, false, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -113,7 +113,7 @@ public void mergeSpecificModificationsAreUnappliedForCancun_whenShanghaiNotConfi MergeProtocolSchedule.create( config, false, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -146,7 +146,7 @@ public void mergeSpecificModificationsAreUnappliedForAllMainnetForksAfterParis() MergeProtocolSchedule.create( config, false, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -180,7 +180,7 @@ public void parametersAlignWithMainnetWithAdjustments() { MergeProtocolSchedule.create( GenesisConfigFile.DEFAULT.getConfigOptions(), false, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) diff --git a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java index 4efcdc1e0f0..23a5ae16b10 100644 --- a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java +++ b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java @@ -55,10 +55,10 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.Unstable; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.Unstable; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.core.TransactionTestFixture; import org.hyperledger.besu.ethereum.eth.manager.EthContext; @@ -135,8 +135,8 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper { private final Address coinbase = genesisAllocations(getPosGenesisConfigFile()).findFirst().get(); - private MiningParameters miningParameters = - ImmutableMiningParameters.builder() + private MiningConfiguration miningConfiguration = + ImmutableMiningConfiguration.builder() .mutableInitValues(MutableInitValues.builder().coinbase(coinbase).build()) .unstable( Unstable.builder() @@ -228,7 +228,7 @@ public void setUp() { protocolSchedule, ethScheduler, transactionPool, - miningParameters, + miningConfiguration, backwardSyncContext, Optional.empty()); } @@ -273,7 +273,7 @@ public void exceptionDuringBuildingBlockShouldNotBeInvalid() MergeBlockCreator beingSpiedOn = spy( new MergeBlockCreator( - miningParameters, + miningConfiguration, parent -> Bytes.EMPTY, transactionPool, protocolContext, @@ -302,7 +302,7 @@ public void exceptionDuringBuildingBlockShouldNotBeInvalid() protocolContext, protocolSchedule, ethScheduler, - miningParameters, + miningConfiguration, backwardSyncContext, mergeBlockCreatorFactory)); @@ -543,9 +543,9 @@ public void shouldRetryBlockCreationOnRecoverableError() @Test public void shouldStopRetryBlockCreationIfTimeExpired() throws InterruptedException { final AtomicLong retries = new AtomicLong(0); - miningParameters = - ImmutableMiningParameters.builder() - .from(miningParameters) + miningConfiguration = + ImmutableMiningConfiguration.builder() + .from(miningConfiguration) .unstable(Unstable.builder().posBlockCreationMaxTime(100).build()) .build(); doAnswer( @@ -737,8 +737,8 @@ public void shouldCancelPreviousBlockCreationJobIfCalledAgainWithNewPayloadId() public void shouldUseExtraDataFromMiningParameters() { final Bytes extraData = Bytes.fromHexString("0x1234"); - miningParameters = - ImmutableMiningParameters.builder() + miningConfiguration = + ImmutableMiningConfiguration.builder() .mutableInitValues(MutableInitValues.builder().extraData(extraData).build()) .build(); @@ -748,7 +748,7 @@ public void shouldUseExtraDataFromMiningParameters() { protocolSchedule, ethScheduler, transactionPool, - miningParameters, + miningConfiguration, backwardSyncContext, Optional.empty()); diff --git a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeGenesisConfigHelper.java b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeGenesisConfigHelper.java index dcfe5f98e34..582c8c5dd55 100644 --- a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeGenesisConfigHelper.java +++ b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeGenesisConfigHelper.java @@ -19,7 +19,7 @@ import org.hyperledger.besu.consensus.merge.MergeProtocolSchedule; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -56,7 +56,7 @@ default ProtocolSchedule getMergeProtocolSchedule() { return MergeProtocolSchedule.create( getPosGenesisConfigFile().getConfigOptions(), false, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeReorgTest.java b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeReorgTest.java index 7b111268e0f..22153eeceee 100644 --- a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeReorgTest.java +++ b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeReorgTest.java @@ -34,8 +34,8 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.sync.backwardsync.BackwardSyncContext; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; @@ -96,7 +96,7 @@ public void setUp() { mockProtocolSchedule, ethScheduler, mockTransactionPool, - ImmutableMiningParameters.builder() + ImmutableMiningConfiguration.builder() .mutableInitValues(MutableInitValues.builder().coinbase(coinbase).build()) .build(), mock(BackwardSyncContext.class), diff --git a/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/support/TestContextBuilder.java b/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/support/TestContextBuilder.java index d90d5a15277..cc7066f17ee 100644 --- a/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/support/TestContextBuilder.java +++ b/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/support/TestContextBuilder.java @@ -91,9 +91,9 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.eth.manager.EthContext; @@ -387,8 +387,8 @@ private static ControllerAndState createControllerAndFinalState( final boolean useFixedBaseFee, final List qbftForks) { - final MiningParameters miningParams = - ImmutableMiningParameters.builder() + final MiningConfiguration miningParams = + ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .isMiningEnabled(true) @@ -438,7 +438,7 @@ private static ControllerAndState createControllerAndFinalState( forksSchedule, BFT_EXTRA_DATA_ENCODER, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleBuilder.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleBuilder.java index e1cbc134b6f..473b99332ec 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleBuilder.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleBuilder.java @@ -24,7 +24,7 @@ import org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec; import org.hyperledger.besu.consensus.common.bft.BftProtocolSchedule; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; @@ -50,7 +50,7 @@ public class QbftProtocolScheduleBuilder extends BaseBftProtocolScheduleBuilder * @param isRevertReasonEnabled the is revert reason enabled * @param bftExtraDataCodec the bft extra data codec * @param evmConfiguration the evm configuration - * @param miningParameters The mining parameters + * @param miningConfiguration The mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled. * @param metricsSystem A metricSystem instance to be able to expose metrics in the underlying @@ -64,7 +64,7 @@ public static BftProtocolSchedule create( final boolean isRevertReasonEnabled, final BftExtraDataCodec bftExtraDataCodec, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -76,7 +76,7 @@ public static BftProtocolSchedule create( isRevertReasonEnabled, bftExtraDataCodec, evmConfiguration, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); @@ -89,7 +89,7 @@ public static BftProtocolSchedule create( * @param qbftForksSchedule the qbft forks schedule * @param bftExtraDataCodec the bft extra data codec * @param evmConfiguration the evm configuration - * @param miningParameters The mining parameters + * @param miningConfiguration The mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled. * @param metricsSystem A metricSystem instance to be able to expose metrics in the underlying @@ -101,7 +101,7 @@ public static BftProtocolSchedule create( final ForksSchedule qbftForksSchedule, final BftExtraDataCodec bftExtraDataCodec, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -112,7 +112,7 @@ public static BftProtocolSchedule create( false, bftExtraDataCodec, evmConfiguration, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); @@ -125,7 +125,7 @@ public static BftProtocolSchedule create( * @param qbftForksSchedule the qbft forks schedule * @param isRevertReasonEnabled the is revert reason enabled * @param bftExtraDataCodec the bft extra data codec - * @param miningParameters The mining parameters + * @param miningConfiguration The mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled. * @param metricsSystem A metricSystem instance to be able to expose metrics in the underlying @@ -137,7 +137,7 @@ public static ProtocolSchedule create( final ForksSchedule qbftForksSchedule, final boolean isRevertReasonEnabled, final BftExtraDataCodec bftExtraDataCodec, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -148,7 +148,7 @@ public static ProtocolSchedule create( isRevertReasonEnabled, bftExtraDataCodec, EvmConfiguration.DEFAULT, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/blockcreation/QbftBlockCreatorFactory.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/blockcreation/QbftBlockCreatorFactory.java index 10f61713d9e..fc46b6c32fb 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/blockcreation/QbftBlockCreatorFactory.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/blockcreation/QbftBlockCreatorFactory.java @@ -23,7 +23,7 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; @@ -52,7 +52,7 @@ public QbftBlockCreatorFactory( final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule, final ForksSchedule forksSchedule, - final MiningParameters miningParams, + final MiningConfiguration miningParams, final Address localAddress, final BftExtraDataCodec bftExtraDataCodec, final EthScheduler ethScheduler) { @@ -74,7 +74,7 @@ public Bytes createExtraData(final int round, final BlockHeader parentHeader) { final BftExtraData extraData = new BftExtraData( ConsensusHelpers.zeroLeftPad( - miningParameters.getExtraData(), BftExtraDataCodec.EXTRA_VANITY_LENGTH), + miningConfiguration.getExtraData(), BftExtraDataCodec.EXTRA_VANITY_LENGTH), Collections.emptyList(), Optional.empty(), round, diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/QbftJsonRpcMethods.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/QbftJsonRpcMethods.java index ce8ce388f26..a0aaf3a16db 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/QbftJsonRpcMethods.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/jsonrpc/QbftJsonRpcMethods.java @@ -30,7 +30,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.methods.ApiGroupJsonRpcMethods; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import java.util.Map; @@ -41,7 +41,7 @@ public class QbftJsonRpcMethods extends ApiGroupJsonRpcMethods { private final ProtocolContext context; private final ValidatorProvider readOnlyValidatorProvider; private final ProtocolSchedule protocolSchedule; - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; private final BftConfigOptions bftConfig; /** @@ -49,20 +49,20 @@ public class QbftJsonRpcMethods extends ApiGroupJsonRpcMethods { * * @param context the protocol context * @param protocolSchedule the protocol schedule - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param readOnlyValidatorProvider the read only validator provider * @param bftConfig the BFT config options, containing QBFT-specific settings */ public QbftJsonRpcMethods( final ProtocolContext context, final ProtocolSchedule protocolSchedule, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final ValidatorProvider readOnlyValidatorProvider, final BftConfigOptions bftConfig) { this.context = context; this.readOnlyValidatorProvider = readOnlyValidatorProvider; this.protocolSchedule = protocolSchedule; - this.miningParameters = miningParameters; + this.miningConfiguration = miningConfiguration; this.bftConfig = bftConfig; } @@ -78,7 +78,7 @@ protected Map create() { protocolSchedule, context.getBlockchain(), context.getWorldStateArchive(), - miningParameters); + miningConfiguration); final BftContext bftContext = context.getConsensusContext(BftContext.class); final BlockInterface blockInterface = bftContext.getBlockInterface(); final ValidatorProvider validatorProvider = bftContext.getValidatorProvider(); diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleTest.java index 020d6e0e5ae..01783571dce 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleTest.java @@ -36,7 +36,7 @@ import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.MilestoneStreamingProtocolSchedule; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode; @@ -138,7 +138,7 @@ private BftProtocolSchedule createProtocolSchedule( false, bftExtraDataCodec, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/blockcreation/QbftBlockCreatorFactoryTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/blockcreation/QbftBlockCreatorFactoryTest.java index 27c50144531..f3682e2533d 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/blockcreation/QbftBlockCreatorFactoryTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/blockcreation/QbftBlockCreatorFactoryTest.java @@ -30,9 +30,9 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.testutil.DeterministicEthScheduler; @@ -50,8 +50,8 @@ public class QbftBlockCreatorFactoryTest { @BeforeEach @SuppressWarnings("unchecked") public void setUp() { - final MiningParameters miningParams = - ImmutableMiningParameters.builder() + final MiningConfiguration miningParams = + ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .extraData(Bytes.wrap("Qbft tests".getBytes(UTF_8))) diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManagerTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManagerTest.java index 23321f23cc2..b6adcb73e62 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManagerTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManagerTest.java @@ -69,7 +69,7 @@ import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule; @@ -187,7 +187,7 @@ BftContext.class, validators, new QbftExtraDataCodec()), new PrivacyParameters(), false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/BlockchainImporter.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/BlockchainImporter.java index 3e261abf6d7..7e1be90e10e 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/BlockchainImporter.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/BlockchainImporter.java @@ -19,7 +19,7 @@ import org.hyperledger.besu.ethereum.chain.GenesisState; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions; @@ -46,7 +46,7 @@ public BlockchainImporter(final URL blocksUrl, final String genesisJson) throws protocolSchedule = MainnetProtocolSchedule.fromConfig( GenesisConfigFile.fromConfig(genesisJson).getConfigOptions(), - MiningParameters.newDefault(), + MiningConfiguration.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java index c7ba5a4f934..902d2b04870 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java @@ -33,7 +33,7 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockImporter; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.manager.EthPeers; @@ -94,7 +94,7 @@ public JsonRpcTestMethodsFactory(final BlockchainImporter importer) { } this.blockchainQueries = new BlockchainQueries( - protocolSchedule, blockchain, stateArchive, MiningParameters.newDefault()); + protocolSchedule, blockchain, stateArchive, MiningConfiguration.newDefault()); } public JsonRpcTestMethodsFactory( @@ -112,7 +112,7 @@ public JsonRpcTestMethodsFactory( importer.getProtocolSchedule(), blockchain, stateArchive, - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); this.synchronizer = mock(Synchronizer.class); } @@ -133,7 +133,7 @@ public JsonRpcTestMethodsFactory( importer.getProtocolSchedule(), blockchain, stateArchive, - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); } public BlockchainQueries getBlockchainQueries() { @@ -152,7 +152,7 @@ public Map methods() { final P2PNetwork peerDiscovery = mock(P2PNetwork.class); final EthPeers ethPeers = mock(EthPeers.class); final TransactionPool transactionPool = mock(TransactionPool.class); - final MiningParameters miningParameters = mock(MiningParameters.class); + final MiningConfiguration miningConfiguration = mock(MiningConfiguration.class); final PoWMiningCoordinator miningCoordinator = mock(PoWMiningCoordinator.class); final ObservableMetricsSystem metricsSystem = new NoOpMetricsSystem(); final Optional accountWhitelistController = @@ -198,7 +198,7 @@ public Map methods() { context, filterManager, transactionPool, - miningParameters, + miningConfiguration, miningCoordinator, metricsSystem, new HashSet<>(), diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthGetFilterChangesIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthGetFilterChangesIntegrationTest.java index d4de405305b..b238259d66f 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthGetFilterChangesIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthGetFilterChangesIntegrationTest.java @@ -45,7 +45,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthContext; @@ -130,7 +130,7 @@ public void setUp() { executionContext.getProtocolSchedule(), blockchain, protocolContext.getWorldStateArchive(), - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); filterManager = new FilterManagerBuilder() .blockchainQueries(blockchainQueries) diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/london/EthGetFilterChangesIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/london/EthGetFilterChangesIntegrationTest.java index 0c194ad22f2..fc5379f1962 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/london/EthGetFilterChangesIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/london/EthGetFilterChangesIntegrationTest.java @@ -45,7 +45,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthContext; @@ -130,7 +130,7 @@ public void setUp() { executionContext.getProtocolSchedule(), blockchain, protocolContext.getWorldStateArchive(), - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); filterManager = new FilterManagerBuilder() .blockchainQueries(blockchainQueries) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetExtraData.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetExtraData.java index b433ed0b6af..02d7bac98c8 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetExtraData.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetExtraData.java @@ -19,13 +19,13 @@ 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.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; public class MinerGetExtraData implements JsonRpcMethod { - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; - public MinerGetExtraData(final MiningParameters miningParameters) { - this.miningParameters = miningParameters; + public MinerGetExtraData(final MiningConfiguration miningConfiguration) { + this.miningConfiguration = miningConfiguration; } @Override @@ -36,6 +36,6 @@ public String getName() { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { return new JsonRpcSuccessResponse( - requestContext.getRequest().getId(), miningParameters.getExtraData().toShortHexString()); + requestContext.getRequest().getId(), miningConfiguration.getExtraData().toShortHexString()); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinGasPrice.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinGasPrice.java index 07e8fdc9b63..353125f84c7 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinGasPrice.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinGasPrice.java @@ -20,13 +20,13 @@ 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.results.Quantity; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; public class MinerGetMinGasPrice implements JsonRpcMethod { - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; - public MinerGetMinGasPrice(final MiningParameters miningParameters) { - this.miningParameters = miningParameters; + public MinerGetMinGasPrice(final MiningConfiguration miningConfiguration) { + this.miningConfiguration = miningConfiguration; } @Override @@ -38,6 +38,6 @@ public String getName() { public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { return new JsonRpcSuccessResponse( requestContext.getRequest().getId(), - Quantity.create(miningParameters.getMinTransactionGasPrice())); + Quantity.create(miningConfiguration.getMinTransactionGasPrice())); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinPriorityFee.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinPriorityFee.java index d99d13de2ce..e12810b30fc 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinPriorityFee.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinPriorityFee.java @@ -20,13 +20,13 @@ 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.results.Quantity; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; public class MinerGetMinPriorityFee implements JsonRpcMethod { - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; - public MinerGetMinPriorityFee(final MiningParameters miningParameters) { - this.miningParameters = miningParameters; + public MinerGetMinPriorityFee(final MiningConfiguration miningConfiguration) { + this.miningConfiguration = miningConfiguration; } @Override @@ -38,6 +38,6 @@ public String getName() { public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { return new JsonRpcSuccessResponse( requestContext.getRequest().getId(), - Quantity.create(miningParameters.getMinPriorityFeePerGas())); + Quantity.create(miningConfiguration.getMinPriorityFeePerGas())); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetExtraData.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetExtraData.java index 51395e24f77..7d5fa5b2e01 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetExtraData.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetExtraData.java @@ -23,7 +23,7 @@ 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.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import java.nio.charset.StandardCharsets; @@ -35,10 +35,10 @@ public class MinerSetExtraData implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(MinerSetExtraData.class); - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; - public MinerSetExtraData(final MiningParameters miningParameters) { - this.miningParameters = miningParameters; + public MinerSetExtraData(final MiningConfiguration miningConfiguration) { + this.miningConfiguration = miningConfiguration; } @Override @@ -53,7 +53,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { Bytes32.fromHexStringLenient( rawParam); // done for validation, we want a hex string and max 32 bytes final var extraData = Bytes.fromHexStringLenient(rawParam); - miningParameters.setExtraData(extraData); + miningConfiguration.setExtraData(extraData); LOG.atDebug() .setMessage("set extra data, raw=[{}] parsed=[{}], UTF-8=[{}]") .addArgument(rawParam) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinGasPrice.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinGasPrice.java index 733ed3a8f3c..e932669b00d 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinGasPrice.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinGasPrice.java @@ -25,7 +25,7 @@ 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.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,10 +33,10 @@ public class MinerSetMinGasPrice implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(MinerSetMinGasPrice.class); - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; - public MinerSetMinGasPrice(final MiningParameters miningParameters) { - this.miningParameters = miningParameters; + public MinerSetMinGasPrice(final MiningConfiguration miningConfiguration) { + this.miningConfiguration = miningConfiguration; } @Override @@ -49,7 +49,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { try { final Wei minGasPrice = Wei.fromHexString(requestContext.getRequiredParameter(0, String.class)); - miningParameters.setMinTransactionGasPrice(minGasPrice); + miningConfiguration.setMinTransactionGasPrice(minGasPrice); LOG.debug("min gas price changed to {}", minGasPrice.toHumanReadableString()); return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), true); } catch (final IllegalArgumentException invalidJsonRpcParameters) { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinPriorityFee.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinPriorityFee.java index b1bf4338f77..d296f28f928 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinPriorityFee.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinPriorityFee.java @@ -24,7 +24,7 @@ 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.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,10 +32,10 @@ public class MinerSetMinPriorityFee implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(MinerSetMinPriorityFee.class); - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; - public MinerSetMinPriorityFee(final MiningParameters miningParameters) { - this.miningParameters = miningParameters; + public MinerSetMinPriorityFee(final MiningConfiguration miningConfiguration) { + this.miningConfiguration = miningConfiguration; } @Override @@ -48,7 +48,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { try { final Wei minPriorityFeePerGas = Wei.fromHexString(requestContext.getRequiredParameter(0, String.class)); - miningParameters.setMinPriorityFeePerGas(minPriorityFeePerGas); + miningConfiguration.setMinPriorityFeePerGas(minPriorityFeePerGas); LOG.debug( "min priority fee per gas changed to {}", minPriorityFeePerGas.toHumanReadableString()); return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), true); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethodsFactory.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethodsFactory.java index cdf4440bde9..7be34f02290 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethodsFactory.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethodsFactory.java @@ -25,7 +25,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.manager.EthPeers; @@ -67,7 +67,7 @@ public Map methods( final ProtocolContext protocolContext, final FilterManager filterManager, final TransactionPool transactionPool, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final MiningCoordinator miningCoordinator, final ObservableMetricsSystem metricsSystem, final Set supportedCapabilities, @@ -139,7 +139,7 @@ public Map methods( webSocketConfiguration, metricsConfiguration, graphQLConfiguration), - new MinerJsonRpcMethods(miningParameters, miningCoordinator), + new MinerJsonRpcMethods(miningConfiguration, miningCoordinator), new PermJsonRpcMethods(accountsAllowlistController, nodeAllowlistController), new PrivJsonRpcMethods( blockchainQueries, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/MinerJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/MinerJsonRpcMethods.java index c799c23305b..14e74767eef 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/MinerJsonRpcMethods.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/MinerJsonRpcMethods.java @@ -28,18 +28,18 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.miner.MinerStart; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.miner.MinerStop; import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import java.util.Map; public class MinerJsonRpcMethods extends ApiGroupJsonRpcMethods { private final MiningCoordinator miningCoordinator; - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; public MinerJsonRpcMethods( - final MiningParameters miningParameters, final MiningCoordinator miningCoordinator) { - this.miningParameters = miningParameters; + final MiningConfiguration miningConfiguration, final MiningCoordinator miningCoordinator) { + this.miningConfiguration = miningConfiguration; this.miningCoordinator = miningCoordinator; } @@ -57,11 +57,11 @@ protected Map create() { minerSetCoinbase, new MinerSetEtherbase(minerSetCoinbase), new MinerChangeTargetGasLimit(miningCoordinator), - new MinerGetMinPriorityFee(miningParameters), - new MinerSetMinPriorityFee(miningParameters), - new MinerGetMinGasPrice(miningParameters), - new MinerSetMinGasPrice(miningParameters), - new MinerGetExtraData(miningParameters), - new MinerSetExtraData(miningParameters)); + new MinerGetMinPriorityFee(miningConfiguration), + new MinerSetMinPriorityFee(miningConfiguration), + new MinerGetMinGasPrice(miningConfiguration), + new MinerSetMinGasPrice(miningConfiguration), + new MinerGetExtraData(miningConfiguration), + new MinerSetExtraData(miningConfiguration)); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueries.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueries.java index c03bf124c47..7e5a7c6fe04 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueries.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueries.java @@ -30,7 +30,7 @@ import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.LogWithMetadata; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; @@ -77,20 +77,20 @@ public class BlockchainQueries { private final Optional transactionLogBloomCacher; private final Optional ethScheduler; private final ApiConfiguration apiConfig; - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; public BlockchainQueries( final ProtocolSchedule protocolSchedule, final Blockchain blockchain, final WorldStateArchive worldStateArchive, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { this( protocolSchedule, blockchain, worldStateArchive, Optional.empty(), Optional.empty(), - miningParameters); + miningConfiguration); } public BlockchainQueries( @@ -98,14 +98,14 @@ public BlockchainQueries( final Blockchain blockchain, final WorldStateArchive worldStateArchive, final EthScheduler scheduler, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { this( protocolSchedule, blockchain, worldStateArchive, Optional.empty(), Optional.ofNullable(scheduler), - miningParameters); + miningConfiguration); } public BlockchainQueries( @@ -114,7 +114,7 @@ public BlockchainQueries( final WorldStateArchive worldStateArchive, final Optional cachePath, final Optional scheduler, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { this( protocolSchedule, blockchain, @@ -122,7 +122,7 @@ public BlockchainQueries( cachePath, scheduler, ImmutableApiConfiguration.builder().build(), - miningParameters); + miningConfiguration); } public BlockchainQueries( @@ -132,7 +132,7 @@ public BlockchainQueries( final Optional cachePath, final Optional scheduler, final ApiConfiguration apiConfig, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { this.protocolSchedule = protocolSchedule; this.blockchain = blockchain; this.worldStateArchive = worldStateArchive; @@ -144,7 +144,7 @@ public BlockchainQueries( new TransactionLogBloomCacher(blockchain, cachePath.get(), scheduler.get())) : Optional.empty(); this.apiConfig = apiConfig; - this.miningParameters = miningParameters; + this.miningConfiguration = miningConfiguration; } public Blockchain getBlockchain() { @@ -1034,7 +1034,7 @@ public Wei gasPriceLowerBound() { private Wei gasPriceLowerBound( final BlockHeader chainHeadHeader, final FeeMarket nextBlockFeeMarket) { - final var minGasPrice = miningParameters.getMinTransactionGasPrice(); + final var minGasPrice = miningConfiguration.getMinTransactionGasPrice(); if (nextBlockFeeMarket.implementsBaseFee()) { return UInt256s.max( @@ -1070,9 +1070,9 @@ public Wei gasPriorityFee() { .toArray(Wei[]::new); return gasCollection.length == 0 - ? miningParameters.getMinPriorityFeePerGas() + ? miningConfiguration.getMinPriorityFeePerGas() : UInt256s.max( - miningParameters.getMinPriorityFeePerGas(), + miningConfiguration.getMinPriorityFeePerGas(), gasCollection[ Math.min( gasCollection.length - 1, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java index 5a1c23d40ee..2b55b42ba2d 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java @@ -27,7 +27,7 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.core.DefaultSyncStatus; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.eth.EthProtocol; @@ -119,7 +119,7 @@ public void setupTest() throws Exception { Optional.empty(), Optional.empty(), ImmutableApiConfiguration.builder().build(), - MiningParameters.newDefault().setMinTransactionGasPrice(Wei.ZERO)); + MiningConfiguration.newDefault().setMinTransactionGasPrice(Wei.ZERO)); final Set supportedCapabilities = new HashSet<>(); supportedCapabilities.add(EthProtocol.ETH62); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/AbstractJsonRpcHttpServiceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/AbstractJsonRpcHttpServiceTest.java index d504e3bb0d4..db896a94856 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/AbstractJsonRpcHttpServiceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/AbstractJsonRpcHttpServiceTest.java @@ -35,7 +35,7 @@ import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.core.Transaction; @@ -137,7 +137,7 @@ protected Map getRpcMethods( final Synchronizer synchronizerMock = mock(Synchronizer.class); final P2PNetwork peerDiscoveryMock = mock(P2PNetwork.class); final TransactionPool transactionPoolMock = mock(TransactionPool.class); - final MiningParameters miningParameters = mock(MiningParameters.class); + final MiningConfiguration miningConfiguration = mock(MiningConfiguration.class); final PoWMiningCoordinator miningCoordinatorMock = mock(PoWMiningCoordinator.class); when(transactionPoolMock.addTransactionViaApi(any(Transaction.class))) .thenReturn(ValidationResult.valid()); @@ -151,7 +151,7 @@ protected Map getRpcMethods( blockchainSetupUtil.getProtocolSchedule(), blockchainSetupUtil.getBlockchain(), blockchainSetupUtil.getWorldArchive(), - miningParameters); + miningConfiguration); final FilterIdGenerator filterIdGenerator = mock(FilterIdGenerator.class); final FilterRepository filterRepository = new FilterRepository(); when(filterIdGenerator.nextId()).thenReturn("0x1"); @@ -183,7 +183,7 @@ protected Map getRpcMethods( protocolContext, filterManager, transactionPoolMock, - miningParameters, + miningConfiguration, miningCoordinatorMock, new NoOpMetricsSystem(), supportedCapabilities, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceHostAllowlistTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceHostAllowlistTest.java index 022aa244220..9113e15a12d 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceHostAllowlistTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceHostAllowlistTest.java @@ -30,7 +30,7 @@ import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.EthProtocol; @@ -113,14 +113,14 @@ public void initServerAndClient() throws Exception { synchronizer, MainnetProtocolSchedule.fromConfig( new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID), - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()), mock(ProtocolContext.class), mock(FilterManager.class), mock(TransactionPool.class), - mock(MiningParameters.class), + mock(MiningConfiguration.class), mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceLoginTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceLoginTest.java index f9dba0bc260..aacf1157965 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceLoginTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceLoginTest.java @@ -37,7 +37,7 @@ import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.EthProtocol; @@ -144,14 +144,14 @@ public static void initServerAndClient() throws Exception { synchronizer, MainnetProtocolSchedule.fromConfig( genesisConfigOptions, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()), mock(ProtocolContext.class), mock(FilterManager.class), mock(TransactionPool.class), - mock(MiningParameters.class), + mock(MiningConfiguration.class), mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java index 63ae1b8bfb2..ae66f2ac760 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java @@ -36,7 +36,7 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture; import org.hyperledger.besu.ethereum.core.Synchronizer; @@ -217,7 +217,7 @@ private JsonRpcHttpService createJsonRpcHttpServiceWithRpcApis(final JsonRpcConf mock(ProtocolContext.class), mock(FilterManager.class), mock(TransactionPool.class), - mock(MiningParameters.class), + mock(MiningConfiguration.class), mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, @@ -328,7 +328,7 @@ private JsonRpcHttpService createJsonRpcHttpService( mock(ProtocolContext.class), mock(FilterManager.class), mock(TransactionPool.class), - mock(MiningParameters.class), + mock(MiningConfiguration.class), mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTestBase.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTestBase.java index 5a439fa1947..ec4f6c6e2b4 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTestBase.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTestBase.java @@ -30,7 +30,7 @@ import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.ChainHead; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.EthProtocol; @@ -122,14 +122,14 @@ public static void initServerAndClient() throws Exception { MainnetProtocolSchedule.fromConfig( new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID), EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()), mock(ProtocolContext.class), mock(FilterManager.class), mock(TransactionPool.class), - mock(MiningParameters.class), + mock(MiningConfiguration.class), mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsClientAuthTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsClientAuthTest.java index 28474d3c536..fa336169b9a 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsClientAuthTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsClientAuthTest.java @@ -37,7 +37,7 @@ import org.hyperledger.besu.ethereum.api.tls.TlsConfiguration; import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.EthProtocol; @@ -127,14 +127,14 @@ public void initServer() throws Exception { synchronizer, MainnetProtocolSchedule.fromConfig( new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID), - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()), mock(ProtocolContext.class), mock(FilterManager.class), mock(TransactionPool.class), - mock(MiningParameters.class), + mock(MiningConfiguration.class), mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsMisconfigurationTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsMisconfigurationTest.java index 15df60230b6..b675430c49e 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsMisconfigurationTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsMisconfigurationTest.java @@ -36,7 +36,7 @@ import org.hyperledger.besu.ethereum.api.tls.TlsConfiguration; import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.EthProtocol; @@ -115,14 +115,14 @@ public void beforeEach() { synchronizer, MainnetProtocolSchedule.fromConfig( new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID), - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()), mock(ProtocolContext.class), mock(FilterManager.class), mock(TransactionPool.class), - mock(MiningParameters.class), + mock(MiningConfiguration.class), mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsTest.java index 6f7ce4e1d66..de5683ad5c0 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsTest.java @@ -36,7 +36,7 @@ import org.hyperledger.besu.ethereum.api.tls.TlsConfiguration; import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.EthProtocol; @@ -116,14 +116,14 @@ public void initServer() throws Exception { synchronizer, MainnetProtocolSchedule.fromConfig( new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID), - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()), mock(ProtocolContext.class), mock(FilterManager.class), mock(TransactionPool.class), - mock(MiningParameters.class), + mock(MiningConfiguration.class), mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGasPriceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGasPriceTest.java index 8c7cba99c41..c55f9b46547 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGasPriceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGasPriceTest.java @@ -39,7 +39,7 @@ import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; @@ -77,13 +77,13 @@ public class EthGasPriceTest { @Mock private ProtocolSchedule protocolSchedule; @Mock private Blockchain blockchain; private EthGasPrice method; - private MiningParameters miningParameters; + private MiningConfiguration miningConfiguration; @BeforeEach public void setUp() { ApiConfiguration apiConfig = createDefaultApiConfiguration(); - miningParameters = - MiningParameters.newDefault().setMinTransactionGasPrice(DEFAULT_MIN_GAS_PRICE); + miningConfiguration = + MiningConfiguration.newDefault().setMinTransactionGasPrice(DEFAULT_MIN_GAS_PRICE); method = createEthGasPriceMethod(apiConfig); } @@ -96,7 +96,7 @@ public void returnsCorrectMethodName() { public void shouldReturnMinValueWhenNoTransactionsExist() { final JsonRpcRequestContext request = requestWithParams(); final String expectedWei = "0x4d2"; // minGasPrice > nextBlockBaseFee - miningParameters.setMinTransactionGasPrice(Wei.fromHexString(expectedWei)); + miningConfiguration.setMinTransactionGasPrice(Wei.fromHexString(expectedWei)); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getRequest().getId(), expectedWei); @@ -117,7 +117,7 @@ public void shouldReturnBaseFeeAsMinValueOnGenesis() { final JsonRpcRequestContext request = requestWithParams(); final String expectedWei = DEFAULT_BASE_FEE.toShortHexString(); // nextBlockBaseFee > minGasPrice - miningParameters.setMinTransactionGasPrice(Wei.fromHexString(expectedWei)); + miningConfiguration.setMinTransactionGasPrice(Wei.fromHexString(expectedWei)); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getRequest().getId(), expectedWei); @@ -234,7 +234,7 @@ private static Stream ethGasPriceAtGenesis() { @MethodSource("ethGasPriceAtGenesis") public void ethGasPriceAtGenesis( final Wei minGasPrice, final Optional maybeGenesisBaseFee, final Wei expectedGasPrice) { - miningParameters.setMinTransactionGasPrice(minGasPrice); + miningConfiguration.setMinTransactionGasPrice(minGasPrice); if (maybeGenesisBaseFee.isPresent()) { mockBaseFeeMarket(); @@ -267,7 +267,7 @@ private void verifyGasPriceLimit( final Long lowerBoundCoefficient, final Long upperBoundCoefficient, final long expectedGasPrice) { - miningParameters.setMinTransactionGasPrice(Wei.of(100)); + miningConfiguration.setMinTransactionGasPrice(Wei.of(100)); mockBaseFeeMarket(); @@ -423,7 +423,7 @@ private EthGasPrice createEthGasPriceMethod(final ApiConfiguration apiConfig) { Optional.empty(), Optional.empty(), apiConfig, - miningParameters), + miningConfiguration), apiConfig); } } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java index 254d0fbe9e8..fd92b55ba48 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java @@ -35,7 +35,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; @@ -93,7 +93,7 @@ public void setUp() { blockchainQueries = spy( new BlockchainQueries( - protocolSchedule, blockchain, worldStateArchive, MiningParameters.newDefault())); + protocolSchedule, blockchain, worldStateArchive, MiningConfiguration.newDefault())); method = new EthGetBlockByNumber(blockchainQueries, blockResult, synchronizer); } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceiptsTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceiptsTest.java index 545b43a6e70..f25407c86e6 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceiptsTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockReceiptsTest.java @@ -35,7 +35,7 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; @@ -86,7 +86,7 @@ public void setUp() { blockchainQueries = spy( new BlockchainQueries( - protocolSchedule, blockchain, worldStateArchive, MiningParameters.newDefault())); + protocolSchedule, blockchain, worldStateArchive, MiningConfiguration.newDefault())); protocolSchedule = mock(ProtocolSchedule.class); method = new EthGetBlockReceipts(blockchainQueries, protocolSchedule); } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProofTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProofTest.java index 06a4b9d0e7c..a346cd827b2 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProofTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProofTest.java @@ -39,7 +39,7 @@ import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.ChainHead; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.proof.WorldStateProof; import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; @@ -89,7 +89,7 @@ public void setUp() { blockchainQueries = spy( new BlockchainQueries( - protocolSchedule, blockchain, archive, MiningParameters.newDefault())); + protocolSchedule, blockchain, archive, MiningConfiguration.newDefault())); when(blockchainQueries.getBlockchain()).thenReturn(blockchain); when(blockchainQueries.headBlockNumber()).thenReturn(14L); when(blockchain.getChainHead()).thenReturn(chainHead); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java index 884cc504d8e..608577f47b7 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java @@ -42,7 +42,7 @@ import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.mainnet.PoWHasher; @@ -195,7 +195,7 @@ public class EthGetTransactionReceiptTest { protocolSchedule, blockchain, mock(WorldStateArchive.class), - MiningParameters.newDefault())); + MiningConfiguration.newDefault())); private final EthGetTransactionReceipt ethGetTransactionReceipt = new EthGetTransactionReceipt(blockchainQueries, protocolSchedule); private final String receiptString = diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthMaxPriorityFeePerGasTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthMaxPriorityFeePerGasTest.java index d29a10a114f..05b5f8cb0d7 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthMaxPriorityFeePerGasTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthMaxPriorityFeePerGasTest.java @@ -35,7 +35,7 @@ import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.feemarket.CancunFeeMarket; @@ -67,12 +67,12 @@ public class EthMaxPriorityFeePerGasTest { private EthMaxPriorityFeePerGas method; @Mock private ProtocolSchedule protocolSchedule; @Mock private Blockchain blockchain; - private MiningParameters miningParameters; + private MiningConfiguration miningConfiguration; @BeforeEach public void setUp() { - miningParameters = - MiningParameters.newDefault().setMinPriorityFeePerGas(DEFAULT_MIN_PRIORITY_FEE_PER_GAS); + miningConfiguration = + MiningConfiguration.newDefault().setMinPriorityFeePerGas(DEFAULT_MIN_PRIORITY_FEE_PER_GAS); method = createEthMaxPriorityFeePerGasMethod(); } @@ -85,7 +85,7 @@ public void shouldReturnCorrectMethodName() { public void whenNoTransactionsExistReturnMinPriorityFeePerGasPrice() { final JsonRpcRequestContext request = requestWithParams(); final Wei expectedWei = Wei.ONE; - miningParameters.setMinPriorityFeePerGas(expectedWei); + miningConfiguration.setMinPriorityFeePerGas(expectedWei); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getRequest().getId(), expectedWei.toShortHexString()); @@ -111,7 +111,7 @@ public void whenTransactionsExistReturnMedianMaxPriorityFeePerGasPrice() { public void returnMinPriorityFeePerGasWhenMedianValueIsLower() { final JsonRpcRequestContext request = requestWithParams(); final Wei expectedWei = Wei.of(100_000); - miningParameters.setMinPriorityFeePerGas(expectedWei); + miningConfiguration.setMinPriorityFeePerGas(expectedWei); mockBlockchain(100, 1); @@ -128,7 +128,7 @@ public void returnMinPriorityFeePerGasWhenMedianValueIsLower() { public void atGenesisReturnMinPriorityFeePerGas() { final JsonRpcRequestContext request = requestWithParams(); final Wei expectedWei = Wei.ONE; - miningParameters.setMinPriorityFeePerGas(expectedWei); + miningConfiguration.setMinPriorityFeePerGas(expectedWei); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getRequest().getId(), expectedWei.toShortHexString()); @@ -235,6 +235,6 @@ private EthMaxPriorityFeePerGas createEthMaxPriorityFeePerGasMethod() { Optional.empty(), Optional.empty(), ImmutableApiConfiguration.builder().build(), - miningParameters)); + miningConfiguration)); } } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetExtraDataTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetExtraDataTest.java index ebaf817a477..882a0711101 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetExtraDataTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetExtraDataTest.java @@ -20,8 +20,8 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; 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.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.Test; @@ -30,8 +30,8 @@ public class MinerGetExtraDataTest { @Test public void shouldReturnDefaultExtraData() { - final MiningParameters miningParameters = ImmutableMiningParameters.newDefault(); - final MinerGetExtraData method = new MinerGetExtraData(miningParameters); + final MiningConfiguration miningConfiguration = ImmutableMiningConfiguration.newDefault(); + final MinerGetExtraData method = new MinerGetExtraData(miningConfiguration); final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("2.0", method.getName(), new Object[] {})); @@ -43,12 +43,12 @@ public void shouldReturnDefaultExtraData() { @Test public void shouldReturnSetAtRuntimeExtraData() { - final MiningParameters miningParameters = ImmutableMiningParameters.newDefault(); - final MinerGetExtraData method = new MinerGetExtraData(miningParameters); + final MiningConfiguration miningConfiguration = ImmutableMiningConfiguration.newDefault(); + final MinerGetExtraData method = new MinerGetExtraData(miningConfiguration); final var extraData = "0x123456"; final Bytes extraDataAtRuntime = Bytes.fromHexString(extraData); - miningParameters.setExtraData(extraDataAtRuntime); + miningConfiguration.setExtraData(extraDataAtRuntime); final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("2.0", method.getName(), new Object[] {})); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinGasPriceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinGasPriceTest.java index f73229f0e0f..8e036d822d9 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinGasPriceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinGasPriceTest.java @@ -22,8 +22,8 @@ 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.results.Quantity; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.junit.jupiter.api.Test; @@ -31,15 +31,16 @@ public class MinerGetMinGasPriceTest { @Test public void shouldReturnDefaultMinGasPrice() { - final MiningParameters miningParameters = ImmutableMiningParameters.newDefault(); - final MinerGetMinGasPrice method = new MinerGetMinGasPrice(miningParameters); + final MiningConfiguration miningConfiguration = ImmutableMiningConfiguration.newDefault(); + final MinerGetMinGasPrice method = new MinerGetMinGasPrice(miningConfiguration); final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("2.0", method.getName(), new Object[] {})); final JsonRpcResponse expected = new JsonRpcSuccessResponse( request.getRequest().getId(), - Quantity.create(MiningParameters.MutableInitValues.DEFAULT_MIN_TRANSACTION_GAS_PRICE)); + Quantity.create( + MiningConfiguration.MutableInitValues.DEFAULT_MIN_TRANSACTION_GAS_PRICE)); final JsonRpcResponse actual = method.response(request); assertThat(actual).usingRecursiveComparison().isEqualTo(expected); @@ -47,12 +48,12 @@ public void shouldReturnDefaultMinGasPrice() { @Test public void shouldReturnSetAtRuntimeMinGasPrice() { - final MiningParameters miningParameters = ImmutableMiningParameters.newDefault(); - final MinerGetMinGasPrice method = new MinerGetMinGasPrice(miningParameters); + final MiningConfiguration miningConfiguration = ImmutableMiningConfiguration.newDefault(); + final MinerGetMinGasPrice method = new MinerGetMinGasPrice(miningConfiguration); final Wei minGasPriceAtRuntime = Wei.of(2000); - miningParameters.setMinTransactionGasPrice(minGasPriceAtRuntime); + miningConfiguration.setMinTransactionGasPrice(minGasPriceAtRuntime); final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("2.0", method.getName(), new Object[] {})); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinPriorityFeeTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinPriorityFeeTest.java index 78fb85b94b7..07e3e5842f4 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinPriorityFeeTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinPriorityFeeTest.java @@ -23,18 +23,18 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; 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.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; public class MinerGetMinPriorityFeeTest { - MiningParameters miningParameters = mock(MiningParameters.class); + MiningConfiguration miningConfiguration = mock(MiningConfiguration.class); private MinerGetMinPriorityFee method; @BeforeEach public void setUp() { - method = new MinerGetMinPriorityFee(miningParameters); + method = new MinerGetMinPriorityFee(miningConfiguration); } @Test @@ -44,7 +44,8 @@ public void shouldReturnMinPriorityFee() { final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("2.0", method.getName(), new Object[] {})); - when(miningParameters.getMinPriorityFeePerGas()).thenReturn(Wei.fromHexString(minPriorityFee)); + when(miningConfiguration.getMinPriorityFeePerGas()) + .thenReturn(Wei.fromHexString(minPriorityFee)); final JsonRpcResponse expected = new JsonRpcSuccessResponse(request.getRequest().getId(), minPriorityFee); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetExtraDataTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetExtraDataTest.java index b3c7b45d076..e197964081d 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetExtraDataTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetExtraDataTest.java @@ -23,7 +23,7 @@ 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.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import java.nio.charset.StandardCharsets; @@ -32,12 +32,12 @@ import org.junit.jupiter.api.Test; public class MinerSetExtraDataTest { - MiningParameters miningParameters = MiningParameters.newDefault(); + MiningConfiguration miningConfiguration = MiningConfiguration.newDefault(); private MinerSetExtraData method; @BeforeEach public void setUp() { - method = new MinerSetExtraData(miningParameters); + method = new MinerSetExtraData(miningConfiguration); } @Test @@ -49,7 +49,7 @@ public void shouldChangeExtraData() { final JsonRpcResponse actual = method.response(request); assertThat(actual).usingRecursiveComparison().isEqualTo(expected); - final var currExtraData = miningParameters.getExtraData(); + final var currExtraData = miningConfiguration.getExtraData(); assertThat(new String(currExtraData.toArray(), StandardCharsets.UTF_8)).isEqualTo(newExtraData); } @@ -67,7 +67,7 @@ public void shouldNotTrimLeadingZeros() { final JsonRpcResponse actual = method.response(request); assertThat(actual).usingRecursiveComparison().isEqualTo(expected); - final var currExtraData = miningParameters.getExtraData(); + final var currExtraData = miningConfiguration.getExtraData(); assertThat(new String(currExtraData.toArray(), StandardCharsets.UTF_8)) .isEqualTo( new String( diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinGasPriceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinGasPriceTest.java index fb56b573075..860e1967d6c 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinGasPriceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinGasPriceTest.java @@ -24,18 +24,18 @@ 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.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; public class MinerSetMinGasPriceTest { - MiningParameters miningParameters = MiningParameters.newDefault(); + MiningConfiguration miningConfiguration = MiningConfiguration.newDefault(); private MinerSetMinGasPrice method; @BeforeEach public void setUp() { - method = new MinerSetMinGasPrice(miningParameters); + method = new MinerSetMinGasPrice(miningConfiguration); } @Test @@ -64,7 +64,7 @@ public void shouldChangeMinPriorityFee() { final JsonRpcResponse actual = method.response(request); assertThat(actual).usingRecursiveComparison().isEqualTo(expected); - assertThat(miningParameters.getMinTransactionGasPrice()) + assertThat(miningConfiguration.getMinTransactionGasPrice()) .isEqualTo(Wei.fromHexString(newMinGasPrice)); } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinPriorityFeeTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinPriorityFeeTest.java index 7e564ac4259..fb75788d4b5 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinPriorityFeeTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinPriorityFeeTest.java @@ -24,18 +24,18 @@ 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.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; public class MinerSetMinPriorityFeeTest { - MiningParameters miningParameters = MiningParameters.newDefault(); + MiningConfiguration miningConfiguration = MiningConfiguration.newDefault(); private MinerSetMinPriorityFee method; @BeforeEach public void setUp() { - method = new MinerSetMinPriorityFee(miningParameters); + method = new MinerSetMinPriorityFee(miningConfiguration); } @Test @@ -80,7 +80,7 @@ public void shouldReturnTrueWhenChangeMinPriorityFee() { final JsonRpcResponse expected = new JsonRpcSuccessResponse(request.getRequest().getId(), true); final JsonRpcResponse actual = method.response(request); assertThat(actual).usingRecursiveComparison().isEqualTo(expected); - assertThat(miningParameters.getMinPriorityFeePerGas()) + assertThat(miningConfiguration.getMinPriorityFeePerGas()) .isEqualTo(Wei.fromHexString(newMinPriorityFee)); } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketServiceLoginTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketServiceLoginTest.java index 47a16135ffd..53785012d09 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketServiceLoginTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketServiceLoginTest.java @@ -44,7 +44,7 @@ import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.EthProtocol; @@ -180,14 +180,14 @@ public void before() throws URISyntaxException { synchronizer, MainnetProtocolSchedule.fromConfig( genesisConfigOptions, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()), mock(ProtocolContext.class), mock(FilterManager.class), mock(TransactionPool.class), - mock(MiningParameters.class), + mock(MiningConfiguration.class), mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/subscription/blockheaders/NewBlockHeadersSubscriptionServiceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/subscription/blockheaders/NewBlockHeadersSubscriptionServiceTest.java index 8cb33fa714e..aa69a239cc5 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/subscription/blockheaders/NewBlockHeadersSubscriptionServiceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/subscription/blockheaders/NewBlockHeadersSubscriptionServiceTest.java @@ -32,7 +32,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockDataGenerator.BlockOptions; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; @@ -85,7 +85,7 @@ public class NewBlockHeadersSubscriptionServiceTest { protocolSchedule, blockchain, createInMemoryWorldStateArchive(), - MiningParameters.newDefault())); + MiningConfiguration.newDefault())); @BeforeEach public void before() { diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesLogCacheTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesLogCacheTest.java index 4b963173290..7b3d50b2d09 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesLogCacheTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesLogCacheTest.java @@ -28,7 +28,7 @@ import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; @@ -136,7 +136,7 @@ public void setup() { worldStateArchive, Optional.of(cacheDir), Optional.of(scheduler), - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); } /** diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesTest.java index a49b290e4db..a0213a41a80 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesTest.java @@ -28,7 +28,7 @@ import org.hyperledger.besu.ethereum.core.BlockDataGenerator.BlockOptions; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.LogWithMetadata; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; @@ -599,7 +599,7 @@ private BlockchainWithData( blockchain, worldStateArchive, scheduler, - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); } } diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java index ad9489daf83..51cde269e05 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java @@ -30,7 +30,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader; import org.hyperledger.besu.ethereum.core.Request; @@ -84,7 +84,7 @@ public interface ExtraDataCalculator { private final MiningBeneficiaryCalculator miningBeneficiaryCalculator; private final ExtraDataCalculator extraDataCalculator; private final TransactionPool transactionPool; - protected final MiningParameters miningParameters; + protected final MiningConfiguration miningConfiguration; protected final ProtocolContext protocolContext; protected final ProtocolSchedule protocolSchedule; protected final BlockHeaderFunctions blockHeaderFunctions; @@ -92,14 +92,14 @@ public interface ExtraDataCalculator { private final AtomicBoolean isCancelled = new AtomicBoolean(false); protected AbstractBlockCreator( - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final MiningBeneficiaryCalculator miningBeneficiaryCalculator, final ExtraDataCalculator extraDataCalculator, final TransactionPool transactionPool, final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule, final EthScheduler ethScheduler) { - this.miningParameters = miningParameters; + this.miningConfiguration = miningConfiguration; this.miningBeneficiaryCalculator = miningBeneficiaryCalculator; this.extraDataCalculator = extraDataCalculator; this.transactionPool = transactionPool; @@ -219,7 +219,7 @@ protected BlockCreationResult createBlock( throwIfStopped(); final PluginTransactionSelector pluginTransactionSelector = - miningParameters.getTransactionSelectionService().createPluginTransactionSelector(); + miningConfiguration.getTransactionSelectionService().createPluginTransactionSelector(); final BlockAwareOperationTracer operationTracer = pluginTransactionSelector.getOperationTracer(); @@ -377,7 +377,7 @@ private TransactionSelectionResults selectTransactions( final BlockTransactionSelector selector = new BlockTransactionSelector( - miningParameters, + miningConfiguration, transactionProcessor, protocolContext.getBlockchain(), disposableWorldState, @@ -433,7 +433,7 @@ private ProcessableBlockHeader createPendingBlockHeader( .getGasLimitCalculator() .nextGasLimit( parentHeader.getGasLimit(), - miningParameters.getTargetGasLimit().orElse(parentHeader.getGasLimit()), + miningConfiguration.getTargetGasLimit().orElse(parentHeader.getGasLimit()), newBlockNumber); final DifficultyCalculator difficultyCalculator = protocolSpec.getDifficultyCalculator(); @@ -457,7 +457,7 @@ private ProcessableBlockHeader createPendingBlockHeader( final Bytes32 parentBeaconBlockRoot = maybeParentBeaconBlockRoot.orElse(null); return BlockHeaderBuilder.create() .parentHash(parentHeader.getHash()) - .coinbase(miningParameters.getCoinbase().orElseThrow()) + .coinbase(miningConfiguration.getCoinbase().orElseThrow()) .difficulty(Difficulty.of(difficulty)) .number(newBlockNumber) .gasLimit(gasLimit) diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMinerExecutor.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMinerExecutor.java index af71938d1d5..4d2b1274c67 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMinerExecutor.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMinerExecutor.java @@ -20,7 +20,7 @@ import org.hyperledger.besu.ethereum.chain.MinedBlockObserver; import org.hyperledger.besu.ethereum.chain.PoWObserver; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; import org.hyperledger.besu.ethereum.mainnet.AbstractGasLimitSpecification; @@ -47,7 +47,7 @@ public abstract class AbstractMinerExecutor getCoinbase(); diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/NoopMiningCoordinator.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/NoopMiningCoordinator.java index 6eb4927226c..8b5624f847a 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/NoopMiningCoordinator.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/NoopMiningCoordinator.java @@ -18,7 +18,7 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import java.util.List; @@ -26,10 +26,10 @@ public class NoopMiningCoordinator implements MiningCoordinator { - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; - public NoopMiningCoordinator(final MiningParameters miningParameters) { - this.miningParameters = miningParameters; + public NoopMiningCoordinator(final MiningConfiguration miningConfiguration) { + this.miningConfiguration = miningConfiguration; } @Override @@ -58,17 +58,17 @@ public boolean isMining() { @Override public Wei getMinTransactionGasPrice() { - return miningParameters.getMinTransactionGasPrice(); + return miningConfiguration.getMinTransactionGasPrice(); } @Override public Wei getMinPriorityFeePerGas() { - return miningParameters.getMinPriorityFeePerGas(); + return miningConfiguration.getMinPriorityFeePerGas(); } @Override public Optional
getCoinbase() { - return miningParameters.getCoinbase(); + return miningConfiguration.getCoinbase(); } @Override diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreator.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreator.java index d0042a5ad96..173330568fc 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreator.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreator.java @@ -17,7 +17,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.SealableBlockHeader; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; @@ -39,7 +39,7 @@ public class PoWBlockCreator extends AbstractBlockCreator { private final PoWSolver nonceSolver; public PoWBlockCreator( - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final ExtraDataCalculator extraDataCalculator, final TransactionPool transactionPool, final ProtocolContext protocolContext, @@ -47,8 +47,8 @@ public PoWBlockCreator( final PoWSolver nonceSolver, final EthScheduler ethScheduler) { super( - miningParameters, - __ -> miningParameters.getCoinbase().orElseThrow(), + miningConfiguration, + __ -> miningConfiguration.getCoinbase().orElseThrow(), extraDataCalculator, transactionPool, protocolContext, diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutor.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutor.java index b14eb193405..f17b7989d2a 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutor.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutor.java @@ -19,7 +19,7 @@ import org.hyperledger.besu.ethereum.chain.MinedBlockObserver; import org.hyperledger.besu.ethereum.chain.PoWObserver; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; import org.hyperledger.besu.ethereum.mainnet.EpochCalculator; @@ -40,7 +40,7 @@ public PoWMinerExecutor( final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule, final TransactionPool transactionPool, - final MiningParameters miningParams, + final MiningConfiguration miningParams, final AbstractBlockScheduler blockScheduler, final EpochCalculator epochCalculator, final EthScheduler ethScheduler) { @@ -62,7 +62,7 @@ public Optional startAsyncMining( final Subscribers observers, final Subscribers ethHashObservers, final BlockHeader parentHeader) { - if (miningParameters.getCoinbase().isEmpty()) { + if (miningConfiguration.getCoinbase().isEmpty()) { throw new CoinbaseNotSetException("Unable to start mining without a coinbase."); } return super.startAsyncMining(observers, ethHashObservers, parentHeader); @@ -79,7 +79,7 @@ public PoWBlockMiner createMiner( protocolSchedule.getForNextBlockHeader(parentHeader, 0); final PoWSolver solver = new PoWSolver( - miningParameters, + miningConfiguration, nextBlockProtocolSpec.getPoWHasher().get(), stratumMiningEnabled, ethHashObservers, @@ -87,8 +87,8 @@ public PoWBlockMiner createMiner( final Function blockCreator = (header) -> new PoWBlockCreator( - miningParameters, - parent -> miningParameters.getExtraData(), + miningConfiguration, + parent -> miningConfiguration.getExtraData(), transactionPool, protocolContext, protocolSchedule, @@ -103,7 +103,7 @@ public void setCoinbase(final Address coinbase) { if (coinbase == null) { throw new IllegalArgumentException("Coinbase cannot be unset."); } else { - miningParameters.setCoinbase(Address.wrap(coinbase.copy())); + miningConfiguration.setCoinbase(Address.wrap(coinbase.copy())); } } @@ -113,7 +113,7 @@ void setStratumMiningEnabled(final boolean stratumMiningEnabled) { @Override public Optional
getCoinbase() { - return miningParameters.getCoinbase(); + return miningConfiguration.getCoinbase(); } public EpochCalculator getEpochCalculator() { diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/BlockSelectionContext.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/BlockSelectionContext.java index f8bf6d50c5c..99da62ca06e 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/BlockSelectionContext.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/BlockSelectionContext.java @@ -17,7 +17,7 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.GasLimitCalculator; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; import org.hyperledger.besu.ethereum.mainnet.blockhash.BlockHashProcessor; @@ -25,7 +25,7 @@ import org.hyperledger.besu.evm.gascalculator.GasCalculator; public record BlockSelectionContext( - MiningParameters miningParameters, + MiningConfiguration miningConfiguration, GasCalculator gasCalculator, GasLimitCalculator gasLimitCalculator, BlockHashProcessor blockHashProcessor, diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/BlockTransactionSelector.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/BlockTransactionSelector.java index 5370d2ec46c..a9b57a697ae 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/BlockTransactionSelector.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/BlockTransactionSelector.java @@ -31,7 +31,7 @@ import org.hyperledger.besu.ethereum.blockcreation.txselection.selectors.PriceTransactionSelector; import org.hyperledger.besu.ethereum.blockcreation.txselection.selectors.ProcessingResultTransactionSelector; import org.hyperledger.besu.ethereum.chain.Blockchain; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader; import org.hyperledger.besu.ethereum.core.Transaction; @@ -108,7 +108,7 @@ public class BlockTransactionSelector { private volatile TransactionEvaluationContext currTxEvaluationContext; public BlockTransactionSelector( - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final MainnetTransactionProcessor transactionProcessor, final Blockchain blockchain, final MutableWorldState worldState, @@ -132,7 +132,7 @@ public BlockTransactionSelector( this.ethScheduler = ethScheduler; this.blockSelectionContext = new BlockSelectionContext( - miningParameters, + miningConfiguration, gasCalculator, gasLimitCalculator, blockHashProcessor, @@ -146,7 +146,7 @@ public BlockTransactionSelector( this.operationTracer = new InterruptibleOperationTracer(pluginTransactionSelector.getOperationTracer()); blockWorldStateUpdater = worldState.updater(); - blockTxsSelectionMaxTime = miningParameters.getBlockTxsSelectionMaxTime(); + blockTxsSelectionMaxTime = miningConfiguration.getBlockTxsSelectionMaxTime(); } private List createTransactionSelectors( @@ -315,7 +315,7 @@ private TransactionEvaluationContext createTransactionEvaluationContext( pendingTransaction, Stopwatch.createStarted(), transactionGasPriceInBlock, - blockSelectionContext.miningParameters().getMinTransactionGasPrice()); + blockSelectionContext.miningConfiguration().getMinTransactionGasPrice()); } /** diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/BlockSizeTransactionSelector.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/BlockSizeTransactionSelector.java index 2877c4ce139..0da2b1386d8 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/BlockSizeTransactionSelector.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/BlockSizeTransactionSelector.java @@ -112,13 +112,13 @@ private boolean blockOccupancyAboveThreshold( LOG.trace( "Min block occupancy ratio {}, gas used {}, available {}, remaining {}, used/available {}", - context.miningParameters().getMinBlockOccupancyRatio(), + context.miningConfiguration().getMinBlockOccupancyRatio(), gasUsed, gasAvailable, gasRemaining, occupancyRatio); - return occupancyRatio >= context.miningParameters().getMinBlockOccupancyRatio(); + return occupancyRatio >= context.miningConfiguration().getMinBlockOccupancyRatio(); } /** diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/MinPriorityFeePerGasTransactionSelector.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/MinPriorityFeePerGasTransactionSelector.java index 5783c7e5007..c6dae8a144e 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/MinPriorityFeePerGasTransactionSelector.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/MinPriorityFeePerGasTransactionSelector.java @@ -69,7 +69,7 @@ private boolean isPriorityFeePriceBelowMinimum(final PendingTransaction pendingT pendingTransaction .getTransaction() .getEffectivePriorityFeePerGas(context.pendingBlockHeader().getBaseFee()); - return priorityFeePerGas.lessThan(context.miningParameters().getMinPriorityFeePerGas()); + return priorityFeePerGas.lessThan(context.miningConfiguration().getMinPriorityFeePerGas()); } /** diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/PriceTransactionSelector.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/PriceTransactionSelector.java index 707b1c48633..d3c3047f688 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/PriceTransactionSelector.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/PriceTransactionSelector.java @@ -76,7 +76,7 @@ private boolean transactionCurrentPriceBelowMin( if (!pendingTransaction.hasPriority()) { if (context - .miningParameters() + .miningConfiguration() .getMinTransactionGasPrice() .compareTo(evaluationContext.getTransactionGasPrice()) > 0) { @@ -86,7 +86,7 @@ private boolean transactionCurrentPriceBelowMin( .addArgument(pendingTransaction::toTraceLog) .addArgument(evaluationContext.getTransactionGasPrice()::toHumanReadableString) .addArgument( - context.miningParameters().getMinTransactionGasPrice()::toHumanReadableString) + context.miningConfiguration().getMinTransactionGasPrice()::toHumanReadableString) .log(); return true; } diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java index 727cfd440f5..b70c48ad026 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java @@ -47,9 +47,9 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Request; import org.hyperledger.besu.ethereum.core.SealableBlockHeader; @@ -309,7 +309,7 @@ private CreateOn createBlockCreator(final ProtocolSpecAdapters protocolSpecAdapt PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) @@ -342,8 +342,8 @@ private CreateOn createBlockCreator(final ProtocolSpecAdapters protocolSpecAdapt new BlobCache()); transactionPool.setEnabled(); - final MiningParameters miningParameters = - ImmutableMiningParameters.builder() + final MiningConfiguration miningConfiguration = + ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .extraData(Bytes.fromHexString("deadbeef")) @@ -355,7 +355,7 @@ private CreateOn createBlockCreator(final ProtocolSpecAdapters protocolSpecAdapt return new CreateOn( new TestBlockCreator( - miningParameters, + miningConfiguration, __ -> Address.ZERO, __ -> Bytes.fromHexString("deadbeef"), transactionPool, @@ -368,7 +368,7 @@ private CreateOn createBlockCreator(final ProtocolSpecAdapters protocolSpecAdapt static class TestBlockCreator extends AbstractBlockCreator { protected TestBlockCreator( - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final MiningBeneficiaryCalculator miningBeneficiaryCalculator, final ExtraDataCalculator extraDataCalculator, final TransactionPool transactionPool, @@ -376,7 +376,7 @@ protected TestBlockCreator( final ProtocolSchedule protocolSchedule, final EthScheduler ethScheduler) { super( - miningParameters, + miningConfiguration, miningBeneficiaryCalculator, extraDataCalculator, transactionPool, diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockTransactionSelectorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockTransactionSelectorTest.java index 6eb03ece947..2787189ece7 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockTransactionSelectorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockTransactionSelectorTest.java @@ -18,7 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; import static org.awaitility.Awaitility.await; -import static org.hyperledger.besu.ethereum.core.MiningParameters.DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME; import static org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason.EXECUTION_INTERRUPTED; import static org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason.NONCE_TOO_LOW; import static org.hyperledger.besu.plugin.data.TransactionSelectionResult.BLOCK_SELECTION_TIMEOUT; @@ -55,10 +55,10 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader; import org.hyperledger.besu.ethereum.core.Transaction; @@ -138,7 +138,7 @@ public abstract class AbstractBlockTransactionSelectorTest { protected MutableWorldState worldState; protected ProtocolSchedule protocolSchedule; protected TransactionSelectionService transactionSelectionService; - protected MiningParameters defaultTestMiningParameters; + protected MiningConfiguration defaultTestMiningConfiguration; @Mock protected EthScheduler ethScheduler; @@ -155,7 +155,7 @@ public void setup() { genesisConfigFile = getGenesisConfigFile(); protocolSchedule = createProtocolSchedule(); transactionSelectionService = new TransactionSelectionServiceImpl(); - defaultTestMiningParameters = + defaultTestMiningConfiguration = createMiningParameters( transactionSelectionService, Wei.ZERO, @@ -234,7 +234,7 @@ public void emptyPendingTransactionsResultsInEmptyVettingResult() { FixedDifficultyProtocolSchedule.create( GenesisConfigFile.fromResource("/dev.json").getConfigOptions(), EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -248,7 +248,7 @@ public void emptyPendingTransactionsResultsInEmptyVettingResult() { final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - defaultTestMiningParameters, + defaultTestMiningConfiguration, mainnetTransactionProcessor, blockHeader, miningBeneficiary, @@ -269,7 +269,7 @@ public void validPendingTransactionIsIncludedInTheBlock() { final Address miningBeneficiary = AddressHelpers.ofValue(1); final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - defaultTestMiningParameters, + defaultTestMiningConfiguration, transactionProcessor, blockHeader, miningBeneficiary, @@ -296,7 +296,7 @@ public void invalidTransactionsAreSkippedButBlockStillFills() { final Address miningBeneficiary = AddressHelpers.ofValue(1); final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - defaultTestMiningParameters, + defaultTestMiningConfiguration, transactionProcessor, blockHeader, miningBeneficiary, @@ -336,7 +336,7 @@ public void subsetOfPendingTransactionsIncludedWhenBlockGasLimitHit() { final Address miningBeneficiary = AddressHelpers.ofValue(1); final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - defaultTestMiningParameters, + defaultTestMiningConfiguration, transactionProcessor, blockHeader, miningBeneficiary, @@ -377,7 +377,7 @@ public void transactionTooLargeForBlockDoesNotPreventMoreBeingAddedIfBlockOccupa final Address miningBeneficiary = AddressHelpers.ofValue(1); final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - defaultTestMiningParameters, + defaultTestMiningConfiguration, transactionProcessor, blockHeader, miningBeneficiary, @@ -412,7 +412,7 @@ public void transactionSelectionStopsWhenSufficientBlockOccupancyIsReached() { final Address miningBeneficiary = AddressHelpers.ofValue(1); final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - defaultTestMiningParameters, + defaultTestMiningConfiguration, transactionProcessor, blockHeader, miningBeneficiary, @@ -568,7 +568,7 @@ public void shouldDiscardTransactionsThatFailValidation() { final Address miningBeneficiary = AddressHelpers.ofValue(1); final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - defaultTestMiningParameters, + defaultTestMiningConfiguration, transactionProcessor, blockHeader, miningBeneficiary, @@ -643,7 +643,7 @@ public TransactionSelectionResult evaluateTransactionPostProcessing( final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - defaultTestMiningParameters, + defaultTestMiningConfiguration, transactionProcessor, blockHeader, miningBeneficiary, @@ -757,7 +757,7 @@ public void transactionSelectionPluginShouldBeNotifiedWhenTransactionSelectionCo final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - defaultTestMiningParameters, + defaultTestMiningConfiguration, transactionProcessor, createBlock(300_000), AddressHelpers.ofValue(1), @@ -793,7 +793,7 @@ public void transactionWithIncorrectNonceRemainsInPoolAndNotSelected() { final Address miningBeneficiary = AddressHelpers.ofValue(1); final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - defaultTestMiningParameters, + defaultTestMiningConfiguration, transactionProcessor, blockHeader, miningBeneficiary, @@ -824,12 +824,12 @@ public void increaseOfMinGasPriceAtRuntimeExcludeTxFromBeingSelected() { final Address miningBeneficiary = AddressHelpers.ofValue(1); - final MiningParameters miningParameters = - ImmutableMiningParameters.builder().from(defaultTestMiningParameters).build(); + final MiningConfiguration miningConfiguration = + ImmutableMiningConfiguration.builder().from(defaultTestMiningConfiguration).build(); final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - miningParameters, + miningConfiguration, transactionProcessor, blockHeader, miningBeneficiary, @@ -841,7 +841,7 @@ public void increaseOfMinGasPriceAtRuntimeExcludeTxFromBeingSelected() { ensureTransactionIsValid(transaction, 0, 5); // raise the minGasPrice at runtime from 1 wei to 10 wei - miningParameters.setMinTransactionGasPrice(Wei.of(10)); + miningConfiguration.setMinTransactionGasPrice(Wei.of(10)); final TransactionSelectionResults results = selector.buildTransactionListForBlock(); @@ -857,15 +857,15 @@ public void increaseOfMinGasPriceAtRuntimeExcludeTxFromBeingSelected() { @Test public void decreaseOfMinGasPriceAtRuntimeIncludeTxThatWasPreviouslyNotSelected() { final Transaction transaction = createTransaction(0, Wei.of(7L), 100_000); - final MiningParameters miningParameters = - ImmutableMiningParameters.builder().from(defaultTestMiningParameters).build(); + final MiningConfiguration miningConfiguration = + ImmutableMiningConfiguration.builder().from(defaultTestMiningConfiguration).build(); final ProcessableBlockHeader blockHeader = createBlock(500_000); final Address miningBeneficiary = AddressHelpers.ofValue(1); final BlockTransactionSelector selector1 = createBlockSelectorAndSetupTxPool( - miningParameters, + miningConfiguration, transactionProcessor, blockHeader, miningBeneficiary, @@ -876,7 +876,7 @@ public void decreaseOfMinGasPriceAtRuntimeIncludeTxThatWasPreviouslyNotSelected( ensureTransactionIsValid(transaction, 0, 5); // raise the minGasPrice at runtime from 1 wei to 10 wei - miningParameters.setMinTransactionGasPrice(Wei.of(10)); + miningConfiguration.setMinTransactionGasPrice(Wei.of(10)); final TransactionSelectionResults results1 = selector1.buildTransactionListForBlock(); @@ -889,11 +889,11 @@ public void decreaseOfMinGasPriceAtRuntimeIncludeTxThatWasPreviouslyNotSelected( .containsOnly(transaction); // decrease the minGasPrice at runtime from 10 wei to 5 wei - miningParameters.setMinTransactionGasPrice(Wei.of(5)); + miningConfiguration.setMinTransactionGasPrice(Wei.of(5)); final BlockTransactionSelector selector2 = createBlockSelector( - miningParameters, + miningConfiguration, transactionProcessor, blockHeader, miningBeneficiary, @@ -910,9 +910,9 @@ public void decreaseOfMinGasPriceAtRuntimeIncludeTxThatWasPreviouslyNotSelected( @Test public void shouldNotSelectTransactionsWithPriorityFeeLessThanConfig() { ProcessableBlockHeader blockHeader = createBlock(5_000_000, Wei.ONE); - final MiningParameters miningParameters = - ImmutableMiningParameters.builder().from(defaultTestMiningParameters).build(); - miningParameters.setMinPriorityFeePerGas(Wei.of(7)); + final MiningConfiguration miningConfiguration = + ImmutableMiningConfiguration.builder().from(defaultTestMiningConfiguration).build(); + miningConfiguration.setMinPriorityFeePerGas(Wei.of(7)); final Transaction txSelected = createTransaction(1, Wei.of(8), 100_000); ensureTransactionIsValid(txSelected); // transaction txNotSelected should not be selected @@ -921,7 +921,7 @@ public void shouldNotSelectTransactionsWithPriorityFeeLessThanConfig() { final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - miningParameters, + miningConfiguration, transactionProcessor, blockHeader, AddressHelpers.ofValue(1), @@ -1259,7 +1259,7 @@ private void internalBlockSelectionTimeoutSimulationInvalidTxs( } protected BlockTransactionSelector createBlockSelectorAndSetupTxPool( - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final MainnetTransactionProcessor transactionProcessor, final ProcessableBlockHeader blockHeader, final Address miningBeneficiary, @@ -1269,7 +1269,7 @@ protected BlockTransactionSelector createBlockSelectorAndSetupTxPool( transactionPool = createTransactionPool(); return createBlockSelector( - miningParameters, + miningConfiguration, transactionProcessor, blockHeader, miningBeneficiary, @@ -1278,7 +1278,7 @@ protected BlockTransactionSelector createBlockSelectorAndSetupTxPool( } protected BlockTransactionSelector createBlockSelector( - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final MainnetTransactionProcessor transactionProcessor, final ProcessableBlockHeader blockHeader, final Address miningBeneficiary, @@ -1287,7 +1287,7 @@ protected BlockTransactionSelector createBlockSelector( final BlockTransactionSelector selector = new BlockTransactionSelector( - miningParameters, + miningConfiguration, transactionProcessor, blockchain, worldState, @@ -1423,12 +1423,12 @@ private BlockHeader blockHeader(final long number) { return new BlockHeaderTestFixture().number(number).buildHeader(); } - protected MiningParameters createMiningParameters( + protected MiningConfiguration createMiningParameters( final TransactionSelectionService transactionSelectionService, final Wei minGasPrice, final double minBlockOccupancyRatio, final PositiveNumber txsSelectionMaxTime) { - return ImmutableMiningParameters.builder() + return ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .minTransactionGasPrice(minGasPrice) @@ -1439,13 +1439,13 @@ protected MiningParameters createMiningParameters( .build(); } - protected MiningParameters createMiningParameters( + protected MiningConfiguration createMiningParameters( final TransactionSelectionService transactionSelectionService, final Wei minGasPrice, final double minBlockOccupancyRatio, final int genesisBlockPeriodSeconds, final PositiveNumber minBlockTimePercentage) { - return ImmutableMiningParameters.builder() + return ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .minTransactionGasPrice(minGasPrice) diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LegacyFeeMarketBlockTransactionSelectorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LegacyFeeMarketBlockTransactionSelectorTest.java index 731b8b38546..327d4bd37d0 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LegacyFeeMarketBlockTransactionSelectorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LegacyFeeMarketBlockTransactionSelectorTest.java @@ -22,7 +22,7 @@ import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; @@ -62,7 +62,7 @@ protected ProtocolSchedule createProtocolSchedule() { new PrivacyParameters(), false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java index 3bb559550b8..62eaf713c54 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java @@ -16,7 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; -import static org.hyperledger.besu.ethereum.core.MiningParameters.DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME; import static org.mockito.Mockito.mock; import org.hyperledger.besu.config.GenesisConfigFile; @@ -26,8 +26,8 @@ import org.hyperledger.besu.ethereum.blockcreation.txselection.TransactionSelectionResults; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.AddressHelpers; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader; import org.hyperledger.besu.ethereum.core.Transaction; @@ -73,7 +73,7 @@ protected ProtocolSchedule createProtocolSchedule() { new PrivacyParameters(), false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) @@ -222,7 +222,7 @@ public void transactionFromSameSenderWithMixedTypes() { final Address miningBeneficiary = AddressHelpers.ofValue(1); final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - defaultTestMiningParameters, + defaultTestMiningConfiguration, transactionProcessor, blockHeader, miningBeneficiary, @@ -242,9 +242,9 @@ public void transactionFromSameSenderWithMixedTypes() { @Override public void shouldNotSelectTransactionsWithPriorityFeeLessThanConfig() { ProcessableBlockHeader blockHeader = createBlock(5_000_000, Wei.ONE); - final MiningParameters miningParameters = - ImmutableMiningParameters.builder().from(defaultTestMiningParameters).build(); - miningParameters.setMinPriorityFeePerGas(Wei.of(7)); + final MiningConfiguration miningConfiguration = + ImmutableMiningConfiguration.builder().from(defaultTestMiningConfiguration).build(); + miningConfiguration.setMinPriorityFeePerGas(Wei.of(7)); final Transaction txSelected1 = createEIP1559Transaction(1, Wei.of(8), Wei.of(8), 100_000); ensureTransactionIsValid(txSelected1); @@ -263,7 +263,7 @@ public void shouldNotSelectTransactionsWithPriorityFeeLessThanConfig() { final BlockTransactionSelector selector = createBlockSelectorAndSetupTxPool( - miningParameters, + miningConfiguration, transactionProcessor, blockHeader, AddressHelpers.ofValue(1), diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/MinPriorityFeePerGasTransactionSelectorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/MinPriorityFeePerGasTransactionSelectorTest.java index 6f81f4df2c6..29cea9d0893 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/MinPriorityFeePerGasTransactionSelectorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/MinPriorityFeePerGasTransactionSelectorTest.java @@ -24,7 +24,7 @@ import org.hyperledger.besu.ethereum.blockcreation.txselection.TransactionEvaluationContext; import org.hyperledger.besu.ethereum.blockcreation.txselection.selectors.AbstractTransactionSelector; import org.hyperledger.besu.ethereum.blockcreation.txselection.selectors.MinPriorityFeePerGasTransactionSelector; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.eth.transactions.PendingTransaction; @@ -46,11 +46,11 @@ public class MinPriorityFeePerGasTransactionSelectorTest { @BeforeEach public void initialize() { - MiningParameters miningParameters = - MiningParameters.newDefault().setMinPriorityFeePerGas(Wei.of(minPriorityFeeParameter)); + MiningConfiguration miningConfiguration = + MiningConfiguration.newDefault().setMinPriorityFeePerGas(Wei.of(minPriorityFeeParameter)); BlockSelectionContext context = new BlockSelectionContext( - miningParameters, null, null, null, pendingBlockHeader, null, null, null, null); + miningConfiguration, null, null, null, pendingBlockHeader, null, null, null, null); transactionSelector = new MinPriorityFeePerGasTransactionSelector(context); } diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java index 8e7f992ad55..e8b9baa0a73 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java @@ -31,9 +31,9 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader; @@ -87,7 +87,7 @@ class PoWBlockCreatorTest extends AbstractBlockCreatorTest { void createMainnetBlock1() throws IOException { final var genesisConfigFile = GenesisConfigFile.mainnet(); - final MiningParameters miningParameters = createMiningParameters(BLOCK_1_NONCE); + final MiningConfiguration miningConfiguration = createMiningParameters(BLOCK_1_NONCE); final ExecutionContextTestFixture executionContextTestFixture = ExecutionContextTestFixture.builder(genesisConfigFile) @@ -99,7 +99,7 @@ void createMainnetBlock1() throws IOException { PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) @@ -108,7 +108,7 @@ void createMainnetBlock1() throws IOException { final PoWSolver solver = new PoWSolver( - miningParameters, + miningConfiguration, PoWHasher.ETHASH_LIGHT, false, Subscribers.none(), @@ -118,7 +118,7 @@ void createMainnetBlock1() throws IOException { final PoWBlockCreator blockCreator = new PoWBlockCreator( - miningParameters, + miningConfiguration, parent -> BLOCK_1_EXTRA_DATA, transactionPool, executionContextTestFixture.getProtocolContext(), @@ -146,7 +146,7 @@ void createMainnetBlock1_fixedDifficulty1() { final var genesisConfigFile = GenesisConfigFile.fromResource("/block-creation-fixed-difficulty-genesis.json"); - final MiningParameters miningParameters = createMiningParameters(FIXED_DIFFICULTY_NONCE); + final MiningConfiguration miningConfiguration = createMiningParameters(FIXED_DIFFICULTY_NONCE); final ExecutionContextTestFixture executionContextTestFixture = ExecutionContextTestFixture.builder(genesisConfigFile) @@ -163,7 +163,7 @@ void createMainnetBlock1_fixedDifficulty1() { PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) @@ -172,7 +172,7 @@ void createMainnetBlock1_fixedDifficulty1() { final PoWSolver solver = new PoWSolver( - miningParameters, + miningConfiguration, PoWHasher.ETHASH_LIGHT, false, Subscribers.none(), @@ -182,7 +182,7 @@ void createMainnetBlock1_fixedDifficulty1() { final PoWBlockCreator blockCreator = new PoWBlockCreator( - miningParameters, + miningConfiguration, parent -> BLOCK_1_EXTRA_DATA, transactionPool, executionContextTestFixture.getProtocolContext(), @@ -204,7 +204,7 @@ void rewardBeneficiary_zeroReward_skipZeroRewardsFalse() { final var genesisConfigFile = GenesisConfigFile.fromResource("/block-creation-fixed-difficulty-genesis.json"); - final MiningParameters miningParameters = createMiningParameters(FIXED_DIFFICULTY_NONCE); + final MiningConfiguration miningConfiguration = createMiningParameters(FIXED_DIFFICULTY_NONCE); ProtocolSchedule protocolSchedule = new ProtocolScheduleBuilder( @@ -219,7 +219,7 @@ void rewardBeneficiary_zeroReward_skipZeroRewardsFalse() { PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) @@ -231,7 +231,7 @@ void rewardBeneficiary_zeroReward_skipZeroRewardsFalse() { final PoWSolver solver = new PoWSolver( - miningParameters, + miningConfiguration, PoWHasher.ETHASH_LIGHT, false, Subscribers.none(), @@ -241,7 +241,7 @@ void rewardBeneficiary_zeroReward_skipZeroRewardsFalse() { final PoWBlockCreator blockCreator = new PoWBlockCreator( - miningParameters, + miningConfiguration, parent -> BLOCK_1_EXTRA_DATA, transactionPool, executionContextTestFixture.getProtocolContext(), @@ -281,7 +281,7 @@ void rewardBeneficiary_zeroReward_skipZeroRewardsTrue() { final var genesisConfigFile = GenesisConfigFile.fromResource("/block-creation-fixed-difficulty-genesis.json"); - final MiningParameters miningParameters = createMiningParameters(FIXED_DIFFICULTY_NONCE); + final MiningConfiguration miningConfiguration = createMiningParameters(FIXED_DIFFICULTY_NONCE); ProtocolSchedule protocolSchedule = new ProtocolScheduleBuilder( @@ -296,7 +296,7 @@ void rewardBeneficiary_zeroReward_skipZeroRewardsTrue() { PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) @@ -308,7 +308,7 @@ void rewardBeneficiary_zeroReward_skipZeroRewardsTrue() { final PoWSolver solver = new PoWSolver( - miningParameters, + miningConfiguration, PoWHasher.ETHASH_LIGHT, false, Subscribers.none(), @@ -318,7 +318,7 @@ void rewardBeneficiary_zeroReward_skipZeroRewardsTrue() { final PoWBlockCreator blockCreator = new PoWBlockCreator( - miningParameters, + miningConfiguration, parent -> BLOCK_1_EXTRA_DATA, transactionPool, executionContextTestFixture.getProtocolContext(), @@ -382,8 +382,8 @@ private TransactionPool createTransactionPool( return transactionPool; } - private MiningParameters createMiningParameters(final long nonce) { - return ImmutableMiningParameters.builder() + private MiningConfiguration createMiningParameters(final long nonce) { + return ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .nonceGenerator(Lists.newArrayList(nonce)) diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutorTest.java index 8c1e217d759..14e6b543747 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutorTest.java @@ -22,7 +22,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; @@ -51,7 +51,7 @@ public class PoWMinerExecutorTest { @Test public void startingMiningWithoutCoinbaseThrowsException() { - final MiningParameters miningParameters = MiningParameters.newDefault(); + final MiningConfiguration miningConfiguration = MiningConfiguration.newDefault(); final TransactionPool transactionPool = createTransactionPool(); @@ -60,7 +60,7 @@ public void startingMiningWithoutCoinbaseThrowsException() { null, null, transactionPool, - miningParameters, + miningConfiguration, new DefaultBlockScheduler(1L, 10, TestClock.fixed()), new EpochCalculator.DefaultEpochCalculator(), ethScheduler); @@ -72,7 +72,7 @@ public void startingMiningWithoutCoinbaseThrowsException() { @Test public void settingCoinbaseToNullThrowsException() { - final MiningParameters miningParameters = MiningParameters.newDefault(); + final MiningConfiguration miningConfiguration = MiningConfiguration.newDefault(); final TransactionPool transactionPool = createTransactionPool(); @@ -81,7 +81,7 @@ public void settingCoinbaseToNullThrowsException() { null, null, transactionPool, - miningParameters, + miningConfiguration, new DefaultBlockScheduler(1, 10, TestClock.fixed()), new EpochCalculator.DefaultEpochCalculator(), ethScheduler); diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWMiningCoordinatorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWMiningCoordinatorTest.java index 6efd63fbaed..6dd272473fa 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWMiningCoordinatorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWMiningCoordinatorTest.java @@ -15,8 +15,8 @@ package org.hyperledger.besu.ethereum.blockcreation; import static org.assertj.core.api.Assertions.assertThat; -import static org.hyperledger.besu.ethereum.core.MiningParameters.Unstable.DEFAULT_REMOTE_SEALERS_LIMIT; -import static org.hyperledger.besu.ethereum.core.MiningParameters.Unstable.DEFAULT_REMOTE_SEALERS_TTL; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.Unstable.DEFAULT_REMOTE_SEALERS_LIMIT; +import static org.hyperledger.besu.ethereum.core.MiningConfiguration.Unstable.DEFAULT_REMOTE_SEALERS_TTL; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/components/ProtocolScheduleModule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/components/ProtocolScheduleModule.java index 039747db0b0..98575272c73 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/components/ProtocolScheduleModule.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/components/ProtocolScheduleModule.java @@ -16,7 +16,7 @@ import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; @@ -50,7 +50,7 @@ public ProtocolScheduleModule() {} * @param badBlockManager the bad block manager * @param isParallelTxProcessingEnabled whether parallel tx processing is enabled * @param metricsSystem the metrics system - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @return the protocol schedule builder */ @Singleton @@ -64,7 +64,7 @@ public ProtocolScheduleBuilder provideProtocolScheduleBuilder( final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { ProtocolScheduleBuilder builder = new ProtocolScheduleBuilder( @@ -74,7 +74,7 @@ public ProtocolScheduleBuilder provideProtocolScheduleBuilder( privacyParameters, isRevertReasonEnabled, evmConfiguration, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningParameters.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningConfiguration.java similarity index 88% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningParameters.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningConfiguration.java index 1921b3568b1..fb39d164b75 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningParameters.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningConfiguration.java @@ -34,27 +34,29 @@ @Value.Immutable @Value.Enclosing -public abstract class MiningParameters { +public abstract class MiningConfiguration { public static final PositiveNumber DEFAULT_NON_POA_BLOCK_TXS_SELECTION_MAX_TIME = PositiveNumber.fromInt((int) Duration.ofSeconds(5).toMillis()); public static final PositiveNumber DEFAULT_POA_BLOCK_TXS_SELECTION_MAX_TIME = PositiveNumber.fromInt(75); - public static final MiningParameters MINING_DISABLED = - ImmutableMiningParameters.builder() + public static final MiningConfiguration MINING_DISABLED = + ImmutableMiningConfiguration.builder() .mutableInitValues( - ImmutableMiningParameters.MutableInitValues.builder().isMiningEnabled(false).build()) + ImmutableMiningConfiguration.MutableInitValues.builder() + .isMiningEnabled(false) + .build()) .build(); @VisibleForTesting - public static final MiningParameters newDefault() { - return ImmutableMiningParameters.builder().build(); + public static final MiningConfiguration newDefault() { + return ImmutableMiningConfiguration.builder().build(); } public boolean isMiningEnabled() { return getMutableRuntimeValues().miningEnabled; } - public MiningParameters setMiningEnabled(final boolean miningEnabled) { + public MiningConfiguration setMiningEnabled(final boolean miningEnabled) { getMutableRuntimeValues().miningEnabled = miningEnabled; return this; } @@ -63,7 +65,7 @@ public Bytes getExtraData() { return getMutableRuntimeValues().extraData; } - public MiningParameters setExtraData(final Bytes extraData) { + public MiningConfiguration setExtraData(final Bytes extraData) { getMutableRuntimeValues().extraData = extraData; return this; } @@ -72,7 +74,7 @@ public Wei getMinTransactionGasPrice() { return getMutableRuntimeValues().minTransactionGasPrice; } - public MiningParameters setMinTransactionGasPrice(final Wei minTransactionGasPrice) { + public MiningConfiguration setMinTransactionGasPrice(final Wei minTransactionGasPrice) { getMutableRuntimeValues().minTransactionGasPrice = minTransactionGasPrice; return this; } @@ -81,7 +83,7 @@ public Wei getMinPriorityFeePerGas() { return getMutableRuntimeValues().minPriorityFeePerGas; } - public MiningParameters setMinPriorityFeePerGas(final Wei minPriorityFeePerGas) { + public MiningConfiguration setMinPriorityFeePerGas(final Wei minPriorityFeePerGas) { getMutableRuntimeValues().minPriorityFeePerGas = minPriorityFeePerGas; return this; } @@ -90,7 +92,7 @@ public Optional
getCoinbase() { return getMutableRuntimeValues().coinbase; } - public MiningParameters setCoinbase(final Address coinbase) { + public MiningConfiguration setCoinbase(final Address coinbase) { getMutableRuntimeValues().coinbase = Optional.of(coinbase); return this; } @@ -99,7 +101,7 @@ public OptionalLong getTargetGasLimit() { return getMutableRuntimeValues().targetGasLimit; } - public MiningParameters setTargetGasLimit(final long targetGasLimit) { + public MiningConfiguration setTargetGasLimit(final long targetGasLimit) { getMutableRuntimeValues().targetGasLimit = OptionalLong.of(targetGasLimit); return this; } @@ -108,7 +110,7 @@ public double getMinBlockOccupancyRatio() { return getMutableRuntimeValues().minBlockOccupancyRatio; } - public MiningParameters setMinBlockOccupancyRatio(final double minBlockOccupancyRatio) { + public MiningConfiguration setMinBlockOccupancyRatio(final double minBlockOccupancyRatio) { getMutableRuntimeValues().minBlockOccupancyRatio = minBlockOccupancyRatio; return this; } @@ -117,7 +119,7 @@ public Optional> getNonceGenerator() { return getMutableRuntimeValues().nonceGenerator; } - public MiningParameters setNonceGenerator(final Iterable nonceGenerator) { + public MiningConfiguration setNonceGenerator(final Iterable nonceGenerator) { getMutableRuntimeValues().nonceGenerator = Optional.of(nonceGenerator); return this; } @@ -126,12 +128,12 @@ public OptionalInt getBlockPeriodSeconds() { return getMutableRuntimeValues().blockPeriodSeconds; } - public MiningParameters setBlockPeriodSeconds(final int blockPeriodSeconds) { + public MiningConfiguration setBlockPeriodSeconds(final int blockPeriodSeconds) { getMutableRuntimeValues().blockPeriodSeconds = OptionalInt.of(blockPeriodSeconds); return this; } - public MiningParameters setEmptyBlockPeriodSeconds(final int emptyBlockPeriodSeconds) { + public MiningConfiguration setEmptyBlockPeriodSeconds(final int emptyBlockPeriodSeconds) { getMutableRuntimeValues().emptyBlockPeriodSeconds = OptionalInt.of(emptyBlockPeriodSeconds); return this; } @@ -207,7 +209,7 @@ public interface MutableInitValues { Wei DEFAULT_MIN_PRIORITY_FEE_PER_GAS = Wei.ZERO; double DEFAULT_MIN_BLOCK_OCCUPANCY_RATIO = 0.8; - MutableInitValues DEFAULT = ImmutableMiningParameters.MutableInitValues.builder().build(); + MutableInitValues DEFAULT = ImmutableMiningConfiguration.MutableInitValues.builder().build(); @Value.Default default boolean isMiningEnabled() { @@ -335,7 +337,7 @@ public interface Unstable { long DEFAULT_POS_BLOCK_CREATION_MAX_TIME = Duration.ofSeconds(12).toMillis(); long DEFAULT_POS_BLOCK_CREATION_REPETITION_MIN_DURATION = Duration.ofMillis(500).toMillis(); - MiningParameters.Unstable DEFAULT = ImmutableMiningParameters.Unstable.builder().build(); + MiningConfiguration.Unstable DEFAULT = ImmutableMiningConfiguration.Unstable.builder().build(); @Value.Default default int getRemoteSealersLimit() { diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningParametersMetrics.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningParametersMetrics.java index 3b3e3a28dcb..8be0b621a33 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningParametersMetrics.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningParametersMetrics.java @@ -22,18 +22,18 @@ public class MiningParametersMetrics { public static final String MIN_PRIORITY_FEE_GAUGE = "min_priority_fee"; public MiningParametersMetrics( - final MetricsSystem metricsSystem, final MiningParameters miningParameters) { + final MetricsSystem metricsSystem, final MiningConfiguration miningConfiguration) { metricsSystem.createGauge( BesuMetricCategory.ETHEREUM, MIN_GAS_PRICE_GAUGE, "Gauge to measure the runtime value of min-gas-price", - () -> miningParameters.getMinTransactionGasPrice().toBigInteger().doubleValue()); + () -> miningConfiguration.getMinTransactionGasPrice().toBigInteger().doubleValue()); metricsSystem.createGauge( BesuMetricCategory.ETHEREUM, MIN_PRIORITY_FEE_GAUGE, "Gauge to measure the runtime value of min-priority-fee", - () -> miningParameters.getMinPriorityFeePerGas().toBigInteger().doubleValue()); + () -> miningConfiguration.getMinPriorityFeePerGas().toBigInteger().doubleValue()); } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/EthereumCoreComponent.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/EthereumCoreComponent.java index 2b081399a93..84de2cef5d6 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/EthereumCoreComponent.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/EthereumCoreComponent.java @@ -15,7 +15,7 @@ package org.hyperledger.besu.ethereum.core.components; import org.hyperledger.besu.ethereum.components.ProtocolScheduleModule; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import javax.inject.Singleton; @@ -28,5 +28,5 @@ ProtocolScheduleModule.class, }) public interface EthereumCoreComponent { - MiningParameters getMiningParameters(); + MiningConfiguration getMiningParameters(); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/MiningParametersModule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/MiningParametersModule.java index 8551d0e946c..7a36e4d81ab 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/MiningParametersModule.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/components/MiningParametersModule.java @@ -16,8 +16,8 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import javax.inject.Named; @@ -29,36 +29,36 @@ public class MiningParametersModule { @Provides @Named("defaultMiningParameters") - protected MiningParameters createImmutableMiningParams() { - return ImmutableMiningParameters.builder().build(); + protected MiningConfiguration createImmutableMiningParams() { + return ImmutableMiningConfiguration.builder().build(); } @Provides @Named("noMining") - protected MiningParameters createNoMining() { - return ImmutableMiningParameters.builder() + protected MiningConfiguration createNoMining() { + return ImmutableMiningConfiguration.builder() .mutableInitValues( - ImmutableMiningParameters.MutableInitValues.builder().isMiningEnabled(false).build()) + ImmutableMiningConfiguration.MutableInitValues.builder().isMiningEnabled(false).build()) .build(); } @Provides @Named("zeroGas") - MiningParameters createZeroGasMining(final @Named("emptyCoinbase") Address coinbase) { - final MiningParameters miningParameters = - ImmutableMiningParameters.builder() + MiningConfiguration createZeroGasMining(final @Named("emptyCoinbase") Address coinbase) { + final MiningConfiguration miningConfiguration = + ImmutableMiningConfiguration.builder() .mutableInitValues( - ImmutableMiningParameters.MutableInitValues.builder() + ImmutableMiningConfiguration.MutableInitValues.builder() .isMiningEnabled(true) .minTransactionGasPrice(Wei.ZERO) .coinbase(coinbase) .build()) .build(); - return miningParameters; + return miningConfiguration; } @Provides - MiningParameters provideMiningParameters() { + MiningConfiguration provideMiningParameters() { throw new IllegalStateException("unimplemented"); } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyProtocolSchedule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyProtocolSchedule.java index 4290679baec..09ca09ff6a8 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyProtocolSchedule.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyProtocolSchedule.java @@ -16,7 +16,7 @@ import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder; @@ -37,7 +37,7 @@ public static ProtocolSchedule create( final PrivacyParameters privacyParameters, final boolean isRevertReasonEnabled, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -51,7 +51,7 @@ public static ProtocolSchedule create( privacyParameters, isRevertReasonEnabled, evmConfiguration, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem) @@ -62,7 +62,7 @@ public static ProtocolSchedule create( final GenesisConfigOptions config, final boolean isRevertReasonEnabled, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -71,7 +71,7 @@ public static ProtocolSchedule create( PrivacyParameters.DEFAULT, isRevertReasonEnabled, evmConfiguration, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); @@ -80,7 +80,7 @@ public static ProtocolSchedule create( public static ProtocolSchedule create( final GenesisConfigOptions config, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -89,7 +89,7 @@ public static ProtocolSchedule create( PrivacyParameters.DEFAULT, false, evmConfiguration, - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSchedule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSchedule.java index e6c372a6822..9528e2dfb84 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSchedule.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSchedule.java @@ -16,7 +16,7 @@ import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.difficulty.fixed.FixedDifficultyCalculators; import org.hyperledger.besu.ethereum.difficulty.fixed.FixedDifficultyProtocolSchedule; @@ -40,7 +40,7 @@ public class MainnetProtocolSchedule { * @param privacyParameters the parameters set for private transactions * @param isRevertReasonEnabled whether storing the revert reason is for failed transactions * @param evmConfiguration how to configure the EVMs jumpdest cache - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled * @param metricsSystem A metricSystem instance to expose metrics in the underlying calls @@ -51,7 +51,7 @@ public static ProtocolSchedule fromConfig( final Optional privacyParameters, final Optional isRevertReasonEnabled, final Optional evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -61,7 +61,7 @@ public static ProtocolSchedule fromConfig( privacyParameters.orElse(PrivacyParameters.DEFAULT), isRevertReasonEnabled.orElse(false), evmConfiguration.orElse(EvmConfiguration.DEFAULT), - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); @@ -73,7 +73,7 @@ public static ProtocolSchedule fromConfig( privacyParameters.orElse(PrivacyParameters.DEFAULT), isRevertReasonEnabled.orElse(false), evmConfiguration.orElse(EvmConfiguration.DEFAULT), - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem) @@ -87,7 +87,7 @@ public static ProtocolSchedule fromConfig( * starting points * @param isRevertReasonEnabled whether storing the revert reason is for failed transactions * @param evmConfiguration how to configure the EVMs jumpdest cache - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled. * @return A configured mainnet protocol schedule @@ -96,7 +96,7 @@ public static ProtocolSchedule fromConfig( final GenesisConfigOptions config, final boolean isRevertReasonEnabled, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -105,7 +105,7 @@ public static ProtocolSchedule fromConfig( Optional.empty(), Optional.of(isRevertReasonEnabled), Optional.of(evmConfiguration), - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); @@ -117,7 +117,7 @@ public static ProtocolSchedule fromConfig( * @param config {@link GenesisConfigOptions} containing the config options for the milestone * starting points * @param evmConfiguration size of - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled. * @return A configured mainnet protocol schedule @@ -125,7 +125,7 @@ public static ProtocolSchedule fromConfig( public static ProtocolSchedule fromConfig( final GenesisConfigOptions config, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -134,7 +134,7 @@ public static ProtocolSchedule fromConfig( Optional.empty(), Optional.empty(), Optional.of(evmConfiguration), - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); @@ -145,14 +145,14 @@ public static ProtocolSchedule fromConfig( * * @param config {@link GenesisConfigOptions} containing the config options for the milestone * starting points - * @param miningParameters the mining parameters + * @param miningConfiguration the mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled. * @return A configured mainnet protocol schedule */ public static ProtocolSchedule fromConfig( final GenesisConfigOptions config, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -161,7 +161,7 @@ public static ProtocolSchedule fromConfig( Optional.empty(), Optional.empty(), Optional.empty(), - miningParameters, + miningConfiguration, badBlockManager, isParallelTxProcessingEnabled, metricsSystem); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecFactory.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecFactory.java index 615a4762518..770175e6462 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecFactory.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecFactory.java @@ -15,7 +15,7 @@ package org.hyperledger.besu.ethereum.mainnet; import org.hyperledger.besu.config.GenesisConfigOptions; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.plugin.services.MetricsSystem; @@ -29,7 +29,7 @@ public class MainnetProtocolSpecFactory { private final boolean isRevertReasonEnabled; private final OptionalLong ecip1017EraRounds; private final EvmConfiguration evmConfiguration; - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; private final boolean isParallelTxProcessingEnabled; private final MetricsSystem metricsSystem; @@ -38,14 +38,14 @@ public MainnetProtocolSpecFactory( final boolean isRevertReasonEnabled, final OptionalLong ecip1017EraRounds, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { this.chainId = chainId; this.isRevertReasonEnabled = isRevertReasonEnabled; this.ecip1017EraRounds = ecip1017EraRounds; this.evmConfiguration = evmConfiguration; - this.miningParameters = miningParameters; + this.miningConfiguration = miningConfiguration; this.isParallelTxProcessingEnabled = isParallelTxProcessingEnabled; this.metricsSystem = metricsSystem; } @@ -140,7 +140,7 @@ public ProtocolSpecBuilder londonDefinition(final GenesisConfigOptions genesisCo isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); } @@ -152,7 +152,7 @@ public ProtocolSpecBuilder arrowGlacierDefinition( isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); } @@ -164,7 +164,7 @@ public ProtocolSpecBuilder grayGlacierDefinition( isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); } @@ -175,7 +175,7 @@ public ProtocolSpecBuilder parisDefinition(final GenesisConfigOptions genesisCon isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); } @@ -186,7 +186,7 @@ public ProtocolSpecBuilder shanghaiDefinition(final GenesisConfigOptions genesis isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); } @@ -197,7 +197,7 @@ public ProtocolSpecBuilder cancunDefinition(final GenesisConfigOptions genesisCo isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); } @@ -208,7 +208,7 @@ public ProtocolSpecBuilder cancunEOFDefinition(final GenesisConfigOptions genesi isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); } @@ -219,7 +219,7 @@ public ProtocolSpecBuilder pragueDefinition(final GenesisConfigOptions genesisCo isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); } @@ -230,7 +230,7 @@ public ProtocolSpecBuilder osakaDefinition(final GenesisConfigOptions genesisCon isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); } @@ -252,7 +252,7 @@ public ProtocolSpecBuilder futureEipsDefinition(final GenesisConfigOptions genes isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); } @@ -274,7 +274,7 @@ public ProtocolSpecBuilder experimentalEipsDefinition( isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java index 23908664f8c..87396bff3e9 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java @@ -25,7 +25,7 @@ import org.hyperledger.besu.ethereum.MainnetBlockValidator; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; @@ -447,7 +447,7 @@ static ProtocolSpecBuilder londonDefinition( final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { final long londonForkBlockNumber = @@ -458,7 +458,7 @@ static ProtocolSpecBuilder londonDefinition( } else if (genesisConfigOptions.isFixedBaseFee()) { londonFeeMarket = FeeMarket.fixedBaseFee( - londonForkBlockNumber, miningParameters.getMinTransactionGasPrice()); + londonForkBlockNumber, miningConfiguration.getMinTransactionGasPrice()); } else { londonFeeMarket = FeeMarket.london(londonForkBlockNumber, genesisConfigOptions.getBaseFeePerGas()); @@ -533,7 +533,7 @@ static ProtocolSpecBuilder arrowGlacierDefinition( final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { return londonDefinition( @@ -541,7 +541,7 @@ static ProtocolSpecBuilder arrowGlacierDefinition( enableRevertReason, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem) .difficultyCalculator(MainnetDifficultyCalculators.ARROW_GLACIER) @@ -553,7 +553,7 @@ static ProtocolSpecBuilder grayGlacierDefinition( final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { return arrowGlacierDefinition( @@ -561,7 +561,7 @@ static ProtocolSpecBuilder grayGlacierDefinition( enableRevertReason, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem) .difficultyCalculator(MainnetDifficultyCalculators.GRAY_GLACIER) @@ -573,7 +573,7 @@ static ProtocolSpecBuilder parisDefinition( final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -582,7 +582,7 @@ static ProtocolSpecBuilder parisDefinition( enableRevertReason, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem) .evmBuilder( @@ -601,7 +601,7 @@ static ProtocolSpecBuilder shanghaiDefinition( final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { return parisDefinition( @@ -609,7 +609,7 @@ static ProtocolSpecBuilder shanghaiDefinition( enableRevertReason, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem) // gas calculator has new code to support EIP-3860 limit and meter initcode @@ -660,7 +660,7 @@ static ProtocolSpecBuilder cancunDefinition( final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { final long londonForkBlockNumber = genesisConfigOptions.getLondonBlockNumber().orElse(0L); @@ -670,7 +670,7 @@ static ProtocolSpecBuilder cancunDefinition( } else if (genesisConfigOptions.isFixedBaseFee()) { cancunFeeMarket = FeeMarket.fixedBaseFee( - londonForkBlockNumber, miningParameters.getMinTransactionGasPrice()); + londonForkBlockNumber, miningConfiguration.getMinTransactionGasPrice()); } else { cancunFeeMarket = FeeMarket.cancun(londonForkBlockNumber, genesisConfigOptions.getBaseFeePerGas()); @@ -681,7 +681,7 @@ static ProtocolSpecBuilder cancunDefinition( enableRevertReason, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem) .feeMarket(cancunFeeMarket) @@ -741,7 +741,7 @@ static ProtocolSpecBuilder cancunEOFDefinition( final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -751,7 +751,7 @@ static ProtocolSpecBuilder cancunEOFDefinition( enableRevertReason, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); return addEOF(chainId, evmConfiguration, protocolSpecBuilder).name("CancunEOF"); @@ -762,7 +762,7 @@ static ProtocolSpecBuilder pragueDefinition( final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -774,7 +774,7 @@ static ProtocolSpecBuilder pragueDefinition( enableRevertReason, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem) // EIP-3074 AUTH and AUTCALL gas @@ -820,7 +820,7 @@ static ProtocolSpecBuilder osakaDefinition( final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -830,7 +830,7 @@ static ProtocolSpecBuilder osakaDefinition( enableRevertReason, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); return addEOF(chainId, evmConfiguration, protocolSpecBuilder).name("Osaka"); @@ -863,7 +863,7 @@ static ProtocolSpecBuilder futureEipsDefinition( final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { return osakaDefinition( @@ -871,7 +871,7 @@ static ProtocolSpecBuilder futureEipsDefinition( enableRevertReason, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem) // Use Future EIP configured EVM @@ -898,7 +898,7 @@ static ProtocolSpecBuilder experimentalEipsDefinition( final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -907,7 +907,7 @@ static ProtocolSpecBuilder experimentalEipsDefinition( enableRevertReason, genesisConfigOptions, evmConfiguration, - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem) .evmBuilder( diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PoWSolver.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PoWSolver.java index 3161490478e..aafc61e71dc 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PoWSolver.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PoWSolver.java @@ -15,7 +15,7 @@ package org.hyperledger.besu.ethereum.mainnet; import org.hyperledger.besu.ethereum.chain.PoWObserver; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.util.Subscribers; import java.util.Optional; @@ -34,7 +34,7 @@ public class PoWSolver { private static final Logger LOG = LoggerFactory.getLogger(PoWSolver.class); - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; public static class PoWSolverJob { @@ -86,12 +86,12 @@ PoWSolution getSolution() throws InterruptedException, ExecutionException { private final ExpiringMap currentJobs = new ExpiringMap<>(); public PoWSolver( - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final PoWHasher poWHasher, final Boolean stratumMiningEnabled, final Subscribers ethHashObservers, final EpochCalculator epochCalculator) { - this.miningParameters = miningParameters; + this.miningConfiguration = miningConfiguration; this.poWHasher = poWHasher; this.stratumMiningEnabled = stratumMiningEnabled; this.ethHashObservers = ethHashObservers; @@ -105,7 +105,7 @@ public PoWSolution solveFor(final PoWSolverJob job) currentJobs.put( job.getInputs().getPrePowHash(), job, - System.currentTimeMillis() + miningParameters.getUnstable().getPowJobTimeToLive()); + System.currentTimeMillis() + miningConfiguration.getUnstable().getPowJobTimeToLive()); if (stratumMiningEnabled) { LOG.debug( "solving with stratum miner for {} observers", ethHashObservers.getSubscriberCount()); @@ -121,7 +121,7 @@ private void findValidNonce() { final Stopwatch operationTimer = Stopwatch.createStarted(); final PoWSolverJob job = currentJob.get(); long hashesExecuted = 0; - for (final Long n : miningParameters.getNonceGenerator().get()) { + for (final Long n : miningConfiguration.getNonceGenerator().get()) { if (job.isDone()) { return; @@ -181,7 +181,7 @@ public boolean submitSolution(final PoWSolution solution) { solution.getPowHash(), ommerCandidate.getInputs().getBlockNumber(), distanceToHead); - if (distanceToHead <= miningParameters.getUnstable().getMaxOmmerDepth()) { + if (distanceToHead <= miningConfiguration.getUnstable().getMaxOmmerDepth()) { jobToTestWith = ommerCandidate; } else { LOG.debug("Discarded ommer solution as too far from head {}", distanceToHead); @@ -211,6 +211,6 @@ public boolean submitSolution(final PoWSolution solution) { } public Iterable getNonceGenerator() { - return miningParameters.getNonceGenerator().get(); + return miningConfiguration.getNonceGenerator().get(); } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java index fd27ca05742..e957394d85f 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java @@ -18,7 +18,7 @@ import org.hyperledger.besu.datatypes.HardforkId; import org.hyperledger.besu.datatypes.HardforkId.MainnetHardforkId; import org.hyperledger.besu.ethereum.chain.BadBlockManager; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.privacy.PrivateTransactionValidator; import org.hyperledger.besu.evm.internal.EvmConfiguration; @@ -51,7 +51,7 @@ public class ProtocolScheduleBuilder { private final BadBlockManager badBlockManager; private final boolean isParallelTxProcessingEnabled; private final MetricsSystem metricsSystem; - private final MiningParameters miningParameters; + private final MiningConfiguration miningConfiguration; public ProtocolScheduleBuilder( final GenesisConfigOptions config, @@ -60,7 +60,7 @@ public ProtocolScheduleBuilder( final PrivacyParameters privacyParameters, final boolean isRevertReasonEnabled, final EvmConfiguration evmConfiguration, - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final BadBlockManager badBlockManager, final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { @@ -73,7 +73,7 @@ public ProtocolScheduleBuilder( this.badBlockManager = badBlockManager; this.isParallelTxProcessingEnabled = isParallelTxProcessingEnabled; this.metricsSystem = metricsSystem; - this.miningParameters = miningParameters; + this.miningConfiguration = miningConfiguration; } public ProtocolSchedule createProtocolSchedule() { @@ -93,7 +93,7 @@ public void initSchedule( config.getEcip1017EraRounds(), evmConfiguration.overrides( config.getContractSizeLimit(), OptionalInt.empty(), config.getEvmStackSize()), - miningParameters, + miningConfiguration, isParallelTxProcessingEnabled, metricsSystem); diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockchainSetupUtil.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockchainSetupUtil.java index 7be6ad12c44..57f11585857 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockchainSetupUtil.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockchainSetupUtil.java @@ -152,7 +152,7 @@ private static ProtocolSchedule mainnetProtocolScheduleProvider( return MainnetProtocolSchedule.fromConfig( genesisConfigFile.getConfigOptions(), EvmConfiguration.DEFAULT, - MiningParameters.newDefault(), + MiningConfiguration.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java index e05ba212681..b2b979e283c 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java @@ -157,7 +157,7 @@ public ExecutionContextTestFixture build() { new PrivacyParameters(), false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ProtocolScheduleFixture.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ProtocolScheduleFixture.java index 5eec6d61e5e..db1114e832b 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ProtocolScheduleFixture.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ProtocolScheduleFixture.java @@ -39,7 +39,7 @@ public class ProtocolScheduleFixture { Optional.empty(), Optional.empty(), Optional.empty(), - MiningParameters.newDefault(), + MiningConfiguration.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedProtocolScheduleTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedProtocolScheduleTest.java index 7969ab6824a..02bb41feb90 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedProtocolScheduleTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedProtocolScheduleTest.java @@ -20,7 +20,7 @@ import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -36,7 +36,7 @@ public void reportedDifficultyForAllBlocksIsAFixedValue() { FixedDifficultyProtocolSchedule.create( GenesisConfigFile.fromResource("/dev.json").getConfigOptions(), EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/DefaultProtocolScheduleTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/DefaultProtocolScheduleTest.java index e48cd673027..92818e31e72 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/DefaultProtocolScheduleTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/DefaultProtocolScheduleTest.java @@ -22,7 +22,7 @@ import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -61,7 +61,7 @@ public void setup() { privacyParameters, isRevertReasonEnabled, evmConfiguration, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolScheduleTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolScheduleTest.java index c63a9b5ccbd..9ce20cb6267 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolScheduleTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolScheduleTest.java @@ -18,7 +18,7 @@ import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -73,7 +73,7 @@ public void shouldOnlyUseFrontierWhenEmptyJsonConfigIsUsed() { MainnetProtocolSchedule.fromConfig( GenesisConfigFile.fromConfig("{}").getConfigOptions(), EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -90,7 +90,7 @@ public void createFromConfigWithSettings() { MainnetProtocolSchedule.fromConfig( GenesisConfigFile.fromConfig(json).getConfigOptions(), EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -124,7 +124,7 @@ public void outOfOrderConstantinoplesFail() { MainnetProtocolSchedule.fromConfig( GenesisConfigFile.fromConfig(json).getConfigOptions(), EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem())); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/PoWSolverTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/PoWSolverTest.java index 91553afed33..1f0b7828251 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/PoWSolverTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/PoWSolverTest.java @@ -21,9 +21,9 @@ import static org.mockito.Mockito.mock; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.util.Subscribers; import java.util.Arrays; @@ -530,12 +530,12 @@ public void rejectsSolutionsForOldBlocks() powThread1.interrupt(); } - private MiningParameters createMiningParameters( + private MiningConfiguration createMiningParameters( final List nonceToTry, final int powJobTimeToLive, final int maxOmmerDepth) { - return ImmutableMiningParameters.builder() + return ImmutableMiningConfiguration.builder() .mutableInitValues(MutableInitValues.builder().nonceGenerator(nonceToTry).build()) .unstable( - ImmutableMiningParameters.Unstable.builder() + ImmutableMiningConfiguration.Unstable.builder() .maxOmmerDepth(maxOmmerDepth) .powJobTimeToLive(powJobTimeToLive) .build()) diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilderTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilderTest.java index cade5bd6019..8046d7e839d 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilderTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilderTest.java @@ -31,7 +31,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.MilestoneStreamingProtocolSchedule; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -67,7 +67,7 @@ public void setup() { new PrivacyParameters(), false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -262,7 +262,7 @@ private MilestoneStreamingProtocolSchedule createScheduleModifiedAt(final int bl new PrivacyParameters(), false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/AbstractIsolationTests.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/AbstractIsolationTests.java index dd9257441e8..999d33a5c5e 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/AbstractIsolationTests.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/AbstractIsolationTests.java @@ -39,9 +39,9 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.MutableInitValues; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; +import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.SealableBlockHeader; import org.hyperledger.besu.ethereum.core.Transaction; @@ -104,7 +104,7 @@ public abstract class AbstractIsolationTests { protected final ProtocolSchedule protocolSchedule = MainnetProtocolSchedule.fromConfig( GenesisConfigFile.fromResource("/dev.json").getConfigOptions(), - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -138,7 +138,7 @@ public abstract class AbstractIsolationTests { txPoolMetrics, transactionReplacementTester, new BlobCache(), - MiningParameters.newDefault()), + MiningConfiguration.newDefault()), ethScheduler); protected final List accounts = @@ -229,7 +229,7 @@ public DataStorageFormat getDatabaseFormat() { @Override public Wei getMinGasPrice() { - return MiningParameters.newDefault().getMinTransactionGasPrice(); + return MiningConfiguration.newDefault().getMinTransactionGasPrice(); } @Override @@ -254,7 +254,7 @@ public boolean getReceiptCompactionEnabled() { static class TestBlockCreator extends AbstractBlockCreator { private TestBlockCreator( - final MiningParameters miningParameters, + final MiningConfiguration miningConfiguration, final MiningBeneficiaryCalculator miningBeneficiaryCalculator, final ExtraDataCalculator extraDataCalculator, final TransactionPool transactionPool, @@ -262,7 +262,7 @@ private TestBlockCreator( final ProtocolSchedule protocolSchedule, final EthScheduler ethScheduler) { super( - miningParameters, + miningConfiguration, miningBeneficiaryCalculator, extraDataCalculator, transactionPool, @@ -277,8 +277,8 @@ static TestBlockCreator forHeader( final TransactionPool transactionPool, final EthScheduler ethScheduler) { - final MiningParameters miningParameters = - ImmutableMiningParameters.builder() + final MiningConfiguration miningConfiguration = + ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() .extraData(Bytes.fromHexString("deadbeef")) @@ -290,7 +290,7 @@ static TestBlockCreator forHeader( .build(); return new TestBlockCreator( - miningParameters, + miningConfiguration, __ -> Address.ZERO, __ -> Bytes.fromHexString("deadbeef"), transactionPool, diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactory.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactory.java index 79b1298d27d..9f133236302 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactory.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactory.java @@ -17,7 +17,7 @@ import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LAYERED; import org.hyperledger.besu.ethereum.ProtocolContext; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.messages.EthPV62; @@ -56,7 +56,7 @@ public static TransactionPool createTransactionPool( final SyncState syncState, final TransactionPoolConfiguration transactionPoolConfiguration, final BlobCache blobCache, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { final TransactionPoolMetrics metrics = new TransactionPoolMetrics(metricsSystem); @@ -80,7 +80,7 @@ public static TransactionPool createTransactionPool( transactionsMessageSender, newPooledTransactionHashesMessageSender, blobCache, - miningParameters); + miningConfiguration); } static TransactionPool createTransactionPool( @@ -95,7 +95,7 @@ static TransactionPool createTransactionPool( final TransactionsMessageSender transactionsMessageSender, final NewPooledTransactionHashesMessageSender newPooledTransactionHashesMessageSender, final BlobCache blobCache, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { final TransactionPool transactionPool = new TransactionPool( @@ -108,7 +108,7 @@ static TransactionPool createTransactionPool( metrics, transactionPoolConfiguration, blobCache, - miningParameters), + miningConfiguration), protocolSchedule, protocolContext, new TransactionBroadcaster( @@ -241,7 +241,7 @@ private static PendingTransactions createPendingTransactions( final TransactionPoolMetrics metrics, final TransactionPoolConfiguration transactionPoolConfiguration, final BlobCache blobCache, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { boolean isFeeMarketImplementBaseFee = protocolSchedule.anyMatch( @@ -256,7 +256,7 @@ private static PendingTransactions createPendingTransactions( transactionPoolConfiguration, isFeeMarketImplementBaseFee, blobCache, - miningParameters); + miningConfiguration); } else { return createPendingTransactionSorter( protocolContext, @@ -296,7 +296,7 @@ private static PendingTransactions createLayeredPendingTransactions( final TransactionPoolConfiguration transactionPoolConfiguration, final boolean isFeeMarketImplementBaseFee, final BlobCache blobCache, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { final TransactionPoolReplacementHandler transactionReplacementHandler = new TransactionPoolReplacementHandler( @@ -345,7 +345,7 @@ private static PendingTransactions createLayeredPendingTransactions( transactionReplacementTester, feeMarket, blobCache, - miningParameters); + miningConfiguration); } else { pendingTransactionsSorter = new GasPricePrioritizedTransactions( @@ -355,7 +355,7 @@ private static PendingTransactions createLayeredPendingTransactions( metrics, transactionReplacementTester, blobCache, - miningParameters); + miningConfiguration); } return new LayeredPendingTransactions( diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/AbstractPrioritizedTransactions.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/AbstractPrioritizedTransactions.java index fce565a8073..06db1b1edce 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/AbstractPrioritizedTransactions.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/AbstractPrioritizedTransactions.java @@ -16,7 +16,7 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.TransactionType; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; import org.hyperledger.besu.ethereum.eth.transactions.PendingTransaction; @@ -42,7 +42,7 @@ */ public abstract class AbstractPrioritizedTransactions extends AbstractSequentialTransactionsLayer { protected final TreeSet orderByFee; - protected final MiningParameters miningParameters; + protected final MiningConfiguration miningConfiguration; public AbstractPrioritizedTransactions( final TransactionPoolConfiguration poolConfig, @@ -52,7 +52,7 @@ public AbstractPrioritizedTransactions( final BiFunction transactionReplacementTester, final BlobCache blobCache, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { super( poolConfig, ethScheduler, @@ -61,7 +61,7 @@ public AbstractPrioritizedTransactions( metrics, blobCache); this.orderByFee = new TreeSet<>(this::compareByFee); - this.miningParameters = miningParameters; + this.miningConfiguration = miningConfiguration; } @Override diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/BaseFeePrioritizedTransactions.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/BaseFeePrioritizedTransactions.java index df9b1537a33..b168babe639 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/BaseFeePrioritizedTransactions.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/BaseFeePrioritizedTransactions.java @@ -19,7 +19,7 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; import org.hyperledger.besu.ethereum.eth.transactions.PendingTransaction; @@ -51,7 +51,7 @@ public BaseFeePrioritizedTransactions( transactionReplacementTester, final FeeMarket feeMarket, final BlobCache blobCache, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { super( poolConfig, ethScheduler, @@ -59,7 +59,7 @@ public BaseFeePrioritizedTransactions( metrics, transactionReplacementTester, blobCache, - miningParameters); + miningConfiguration); this.nextBlockBaseFee = Optional.of(calculateNextBlockBaseFee(feeMarket, chainHeadHeaderSupplier.get())); } @@ -174,15 +174,15 @@ protected boolean promotionFilter(final PendingTransaction pendingTransaction) { if (pendingTransaction .getTransaction() .getEffectiveGasPrice(nextBlockBaseFee) - .lessThan(miningParameters.getMinTransactionGasPrice())) { + .lessThan(miningConfiguration.getMinTransactionGasPrice())) { return false; } // check if enough priority fee is paid - if (!miningParameters.getMinPriorityFeePerGas().equals(Wei.ZERO)) { + if (!miningConfiguration.getMinPriorityFeePerGas().equals(Wei.ZERO)) { final Wei priorityFeePerGas = pendingTransaction.getTransaction().getEffectivePriorityFeePerGas(nextBlockBaseFee); - if (priorityFeePerGas.lessThan(miningParameters.getMinPriorityFeePerGas())) { + if (priorityFeePerGas.lessThan(miningConfiguration.getMinPriorityFeePerGas())) { return false; } } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/GasPricePrioritizedTransactions.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/GasPricePrioritizedTransactions.java index 504a453fa88..205c02f543c 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/GasPricePrioritizedTransactions.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/GasPricePrioritizedTransactions.java @@ -17,7 +17,7 @@ import static java.util.Comparator.comparing; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; import org.hyperledger.besu.ethereum.eth.transactions.PendingTransaction; @@ -43,7 +43,7 @@ public GasPricePrioritizedTransactions( final BiFunction transactionReplacementTester, final BlobCache blobCache, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { super( poolConfig, ethScheduler, @@ -51,7 +51,7 @@ public GasPricePrioritizedTransactions( metrics, transactionReplacementTester, blobCache, - miningParameters); + miningConfiguration); } @Override @@ -74,7 +74,7 @@ protected boolean promotionFilter(final PendingTransaction pendingTransaction) { || pendingTransaction .getTransaction() .getGasPrice() - .map(miningParameters.getMinTransactionGasPrice()::lessThan) + .map(miningConfiguration.getMinTransactionGasPrice()::lessThan) .orElse(false); } diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTest.java index 3a3331b568f..b7c346af693 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTest.java @@ -36,7 +36,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; @@ -1123,7 +1123,7 @@ public void transactionMessagesGoToTheCorrectExecutor() { new SyncState(blockchain, ethManager.ethContext().getEthPeers()), TransactionPoolConfiguration.DEFAULT, new BlobCache(), - MiningParameters.newDefault()) + MiningConfiguration.newDefault()) .setEnabled(); // Send just a transaction message. diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ethtaskutils/AbstractMessageTaskTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ethtaskutils/AbstractMessageTaskTest.java index 6dbea259cc2..b1691d0af54 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ethtaskutils/AbstractMessageTaskTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ethtaskutils/AbstractMessageTaskTest.java @@ -26,7 +26,7 @@ import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.eth.EthProtocol; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthContext; @@ -144,7 +144,7 @@ public void setupTest() { syncState, TransactionPoolConfiguration.DEFAULT, new BlobCache(), - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); transactionPool.setEnabled(); ethProtocolManager = diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/BlockBodiesMessageTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/BlockBodiesMessageTest.java index b11afeb4c56..2bb1394a1d3 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/BlockBodiesMessageTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/BlockBodiesMessageTest.java @@ -21,7 +21,7 @@ import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.difficulty.fixed.FixedDifficultyProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; @@ -60,7 +60,7 @@ public void setup() { GenesisConfigFile.fromResource("/dev.json").getConfigOptions(), false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/BlockHeadersMessageTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/BlockHeadersMessageTest.java index 72f089a53eb..9173a7af48b 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/BlockHeadersMessageTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/BlockHeadersMessageTest.java @@ -17,7 +17,7 @@ import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.difficulty.fixed.FixedDifficultyProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; @@ -67,7 +67,7 @@ public void blockHeadersRoundTrip() throws IOException { GenesisConfigFile.fromResource("/dev.json").getConfigOptions(), false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem())); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/ChainHeadTrackerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/ChainHeadTrackerTest.java index 5f7baaff418..f97fe91c6f5 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/ChainHeadTrackerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/ChainHeadTrackerTest.java @@ -23,7 +23,7 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.difficulty.fixed.FixedDifficultyProtocolSchedule; import org.hyperledger.besu.ethereum.eth.manager.ChainState; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; @@ -58,7 +58,7 @@ public class ChainHeadTrackerTest { GenesisConfigFile.fromResource("/dev.json").getConfigOptions(), false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncContextTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncContextTest.java index cfc9f9dc123..4cd4d1c6745 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncContextTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncContextTest.java @@ -36,7 +36,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; @@ -95,7 +95,7 @@ public class BackwardSyncContextTest { private ProtocolSchedule protocolSchedule = MainnetProtocolSchedule.fromConfig( new StubGenesisConfigOptions(), - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncStepTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncStepTest.java index 6dc69ea274e..696856c0761 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncStepTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncStepTest.java @@ -29,7 +29,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; @@ -72,7 +72,7 @@ public class BackwardSyncStepTest { private final ProtocolSchedule protocolSchedule = MainnetProtocolSchedule.fromConfig( new StubGenesisConfigOptions(), - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/ForwardSyncStepTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/ForwardSyncStepTest.java index a5d2cf61045..34479bf11fd 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/ForwardSyncStepTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/ForwardSyncStepTest.java @@ -28,7 +28,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; @@ -75,7 +75,7 @@ public class ForwardSyncStepTest { private final ProtocolSchedule protocolSchedule = MainnetProtocolSchedule.fromConfig( new StubGenesisConfigOptions(), - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTestBase.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTestBase.java index 07d4e6ab4b1..e3e8046ba87 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTestBase.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTestBase.java @@ -49,7 +49,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; @@ -183,7 +183,7 @@ protected static ExecutionContextTestFixture createExecutionContextTestFixtureBa new PrivacyParameters(), false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TestNode.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TestNode.java index c679183b0ff..0081dc7d948 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TestNode.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TestNode.java @@ -34,7 +34,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.difficulty.fixed.FixedDifficultyProtocolSchedule; import org.hyperledger.besu.ethereum.eth.EthProtocol; @@ -122,7 +122,7 @@ public TestNode( GenesisConfigFile.fromResource("/dev.json").getConfigOptions(), false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -181,7 +181,7 @@ public boolean isMessagePermitted(final EnodeURL destinationEnode, final int cod syncState, TransactionPoolConfiguration.DEFAULT, new BlobCache(), - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); final EthProtocolManager ethProtocolManager = new EthProtocolManager( diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactoryTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactoryTest.java index d1bafc39699..612a1de9dfb 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactoryTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactoryTest.java @@ -36,7 +36,7 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; @@ -378,7 +378,7 @@ private void setupScheduleWith(final StubGenesisConfigOptions config) { PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) @@ -413,7 +413,7 @@ private TransactionPool createTransactionPool( transactionsMessageSender, newPooledTransactionHashesMessageSender, new BlobCache(), - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); } private TransactionPool createAndEnableTransactionPool( diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/AbstractPrioritizedTransactionsTestBase.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/AbstractPrioritizedTransactionsTestBase.java index 6a0005eec63..69db327013c 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/AbstractPrioritizedTransactionsTestBase.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/AbstractPrioritizedTransactionsTestBase.java @@ -22,7 +22,7 @@ import org.hyperledger.besu.datatypes.TransactionType; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration; import org.hyperledger.besu.ethereum.eth.transactions.PendingTransaction; @@ -47,8 +47,8 @@ public abstract class AbstractPrioritizedTransactionsTestBase extends BaseTransa new EnumMap<>(Map.of(TransactionType.BLOB, 2)); protected final TransactionPoolMetrics txPoolMetrics = new TransactionPoolMetrics(metricsSystem); protected final EvictCollectorLayer evictCollector = new EvictCollectorLayer(txPoolMetrics); - protected final MiningParameters miningParameters = - MiningParameters.newDefault() + protected final MiningConfiguration miningConfiguration = + MiningConfiguration.newDefault() .setMinTransactionGasPrice(DEFAULT_MIN_GAS_PRICE) .setMinPriorityFeePerGas(DEFAULT_MIN_PRIORITY_FEE); protected AbstractPrioritizedTransactions transactions = @@ -58,16 +58,17 @@ public abstract class AbstractPrioritizedTransactionsTestBase extends BaseTransa .maxPrioritizedTransactionsByType(MAX_TRANSACTIONS_BY_TYPE) .maxFutureBySender(MAX_TRANSACTIONS) .build(), - miningParameters); + miningConfiguration); private AbstractPrioritizedTransactions getSorter( - final TransactionPoolConfiguration poolConfig, final MiningParameters miningParameters) { + final TransactionPoolConfiguration poolConfig, + final MiningConfiguration miningConfiguration) { return getSorter( poolConfig, evictCollector, txPoolMetrics, (pt1, pt2) -> transactionReplacementTester(poolConfig, pt1, pt2), - miningParameters); + miningConfiguration); } abstract AbstractPrioritizedTransactions getSorter( @@ -76,7 +77,7 @@ abstract AbstractPrioritizedTransactions getSorter( final TransactionPoolMetrics txPoolMetrics, final BiFunction transactionReplacementTester, - final MiningParameters miningParameters); + final MiningConfiguration miningConfiguration); abstract BlockHeader mockBlockHeader(); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/BaseFeePrioritizedTransactionsTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/BaseFeePrioritizedTransactionsTest.java index b9a675287f9..8d01bd73977 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/BaseFeePrioritizedTransactionsTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/BaseFeePrioritizedTransactionsTest.java @@ -26,7 +26,7 @@ import org.hyperledger.besu.datatypes.TransactionType; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionTestFixture; import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; @@ -60,7 +60,7 @@ AbstractPrioritizedTransactions getSorter( final TransactionPoolMetrics txPoolMetrics, final BiFunction transactionReplacementTester, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { return new BaseFeePrioritizedTransactions( poolConfig, @@ -71,7 +71,7 @@ AbstractPrioritizedTransactions getSorter( transactionReplacementTester, EIP1559_FEE_MARKET, new BlobCache(), - miningParameters); + miningConfiguration); } @Override @@ -164,7 +164,7 @@ public void shouldPrioritizeEffectivePriorityFeeThenTimeAddedToPoolOnMixedTypes( @Test public void txBelowCurrentMineableMinPriorityFeeIsNotPrioritized() { - miningParameters.setMinPriorityFeePerGas(Wei.of(5)); + miningConfiguration.setMinPriorityFeePerGas(Wei.of(5)); final PendingTransaction lowPriorityFeeTx = createRemotePendingTransaction( createTransaction(0, DEFAULT_MIN_GAS_PRICE.subtract(1), KEYS1)); @@ -175,7 +175,7 @@ public void txBelowCurrentMineableMinPriorityFeeIsNotPrioritized() { @Test public void txWithPriorityBelowCurrentMineableMinPriorityFeeIsPrioritized() { - miningParameters.setMinPriorityFeePerGas(Wei.of(5)); + miningConfiguration.setMinPriorityFeePerGas(Wei.of(5)); final PendingTransaction lowGasPriceTx = createRemotePendingTransaction( createTransaction(0, DEFAULT_MIN_GAS_PRICE.subtract(1), KEYS1), true); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/GasPricePrioritizedTransactionsTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/GasPricePrioritizedTransactionsTest.java index 66dcd3c7219..a300ec23b4c 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/GasPricePrioritizedTransactionsTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/GasPricePrioritizedTransactionsTest.java @@ -20,7 +20,7 @@ import org.hyperledger.besu.crypto.KeyPair; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionTestFixture; import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; @@ -44,7 +44,7 @@ AbstractPrioritizedTransactions getSorter( final TransactionPoolMetrics txPoolMetrics, final BiFunction transactionReplacementTester, - final MiningParameters miningParameters) { + final MiningConfiguration miningConfiguration) { return new GasPricePrioritizedTransactions( poolConfig, @@ -53,7 +53,7 @@ AbstractPrioritizedTransactions getSorter( txPoolMetrics, transactionReplacementTester, new BlobCache(), - miningParameters); + miningConfiguration); } @Override diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredPendingTransactionsTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredPendingTransactionsTest.java index 5f6126326d9..28814790a09 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredPendingTransactionsTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredPendingTransactionsTest.java @@ -42,7 +42,7 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration; @@ -158,7 +158,7 @@ private CreatedLayers createLayers(final TransactionPoolConfiguration poolConfig transactionReplacementTester, FeeMarket.london(0L), new BlobCache(), - MiningParameters.newDefault().setMinTransactionGasPrice(DEFAULT_MIN_GAS_PRICE)); + MiningConfiguration.newDefault().setMinTransactionGasPrice(DEFAULT_MIN_GAS_PRICE)); return new CreatedLayers( prioritizedTransactions, readyTransactions, sparseTransactions, evictCollector); } diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredTransactionPoolBaseFeeTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredTransactionPoolBaseFeeTest.java index b3a840e7063..c485ea7878d 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredTransactionPoolBaseFeeTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredTransactionPoolBaseFeeTest.java @@ -19,7 +19,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionTestFixture; import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; @@ -49,7 +49,7 @@ protected AbstractPrioritizedTransactions createPrioritizedTransactions( transactionReplacementTester, FeeMarket.london(0L), new BlobCache(), - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); } @Override diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredTransactionPoolGasPriceTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredTransactionPoolGasPriceTest.java index 0c6f5f0bd2d..305bd9959a6 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredTransactionPoolGasPriceTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredTransactionPoolGasPriceTest.java @@ -19,7 +19,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionTestFixture; import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; @@ -46,7 +46,7 @@ protected AbstractPrioritizedTransactions createPrioritizedTransactions( txPoolMetrics, transactionReplacementTester, new BlobCache(), - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); } @Override diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayersTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayersTest.java index 0decabaaafb..ee900e3dc45 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayersTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayersTest.java @@ -36,7 +36,7 @@ import org.hyperledger.besu.datatypes.TransactionType; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; @@ -1404,7 +1404,7 @@ static class Scenario extends BaseTransactionPoolTest implements Runnable { (pt1, pt2) -> transactionReplacementTester(poolConfig, pt1, pt2), FeeMarket.london(0L), new BlobCache(), - MiningParameters.newDefault().setMinTransactionGasPrice(MIN_GAS_PRICE)); + MiningConfiguration.newDefault().setMinTransactionGasPrice(MIN_GAS_PRICE)); this.pending = new LayeredPendingTransactions(poolConfig, this.prio, ethScheduler); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/ReplayTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/ReplayTest.java index 847f5f2b918..760591a87cf 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/ReplayTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/ReplayTest.java @@ -25,7 +25,7 @@ import org.hyperledger.besu.datatypes.TransactionType; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; @@ -232,7 +232,7 @@ private BaseFeePrioritizedTransactions createLayers( txReplacementTester, baseFeeMarket, new BlobCache(), - MiningParameters.newDefault()); + MiningConfiguration.newDefault()); } // ToDo: commented since not always working, needs fix diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/MainnetGenesisFileModule.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/MainnetGenesisFileModule.java index 8490312d814..1addf8032ed 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/MainnetGenesisFileModule.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/MainnetGenesisFileModule.java @@ -20,7 +20,7 @@ import org.hyperledger.besu.crypto.SignatureAlgorithmType; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule; @@ -81,7 +81,7 @@ ProtocolSchedule provideProtocolSchedule( return MainnetProtocolSchedule.fromConfig( configOptions, evmConfiguration, - MiningParameters.newDefault(), + MiningConfiguration.newDefault(), new BadBlockManager(), false, new NoOpMetricsSystem()); @@ -192,7 +192,7 @@ private static Supplier createSchedule(final GenesisConfigOpti PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) diff --git a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestProtocolSchedules.java b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestProtocolSchedules.java index b9af680fe3d..153f56d636a 100644 --- a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestProtocolSchedules.java +++ b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestProtocolSchedules.java @@ -19,7 +19,7 @@ import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder; @@ -157,7 +157,7 @@ private static ProtocolSchedule createSchedule(final GenesisConfigOptions option PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, - MiningParameters.MINING_DISABLED, + MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) diff --git a/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java index 3a61967044d..3333f02e585 100644 --- a/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java +++ b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java @@ -18,7 +18,6 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.checkerframework.checker.units.qual.N; import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.config.JsonUtil; import org.hyperledger.besu.config.StubGenesisConfigOptions; @@ -28,13 +27,12 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.evm.log.LogsBloomFilter; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.stream.Stream; @@ -61,64 +59,64 @@ public static Stream getTestParametersForConfig() throws IOException MainnetProtocolSchedule.fromConfig( GenesisConfigFile.mainnet() .withOverrides(postMergeOverrides).getConfigOptions(), - EvmConfiguration.DEFAULT, MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem())), + EvmConfiguration.DEFAULT, MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem())), Arguments.of( "/DifficultyTests/dfGrayGlacier/difficultyGrayGlacierForkBlock.json", MainnetProtocolSchedule.fromConfig( - new StubGenesisConfigOptions().grayGlacierBlock(15050000), MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) + new StubGenesisConfigOptions().grayGlacierBlock(15050000), MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfGrayGlacier/difficultyGrayGlacierTimeDiff1.json", MainnetProtocolSchedule.fromConfig( - new StubGenesisConfigOptions().grayGlacierBlock(15050000), MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) + new StubGenesisConfigOptions().grayGlacierBlock(15050000), MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfGrayGlacier/difficultyGrayGlacierTimeDiff2.json", MainnetProtocolSchedule.fromConfig( - new StubGenesisConfigOptions().grayGlacierBlock(15050000), MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) + new StubGenesisConfigOptions().grayGlacierBlock(15050000), MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfArrowGlacier/difficultyArrowGlacierForkBlock.json", MainnetProtocolSchedule.fromConfig( - new StubGenesisConfigOptions().arrowGlacierBlock(13773000), MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) + new StubGenesisConfigOptions().arrowGlacierBlock(13773000), MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfArrowGlacier/difficultyArrowGlacierTimeDiff1.json", MainnetProtocolSchedule.fromConfig( - new StubGenesisConfigOptions().arrowGlacierBlock(13773000), MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) + new StubGenesisConfigOptions().arrowGlacierBlock(13773000), MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfArrowGlacier/difficultyArrowGlacierTimeDiff2.json", MainnetProtocolSchedule.fromConfig( - new StubGenesisConfigOptions().arrowGlacierBlock(13773000), MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) + new StubGenesisConfigOptions().arrowGlacierBlock(13773000), MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfByzantium/difficultyByzantium.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().byzantiumBlock(0), MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().byzantiumBlock(0), MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfConstantinople/difficultyConstantinople.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().constantinopleBlock(0), MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().constantinopleBlock(0), MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfEIP2384/difficultyEIP2384.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().muirGlacierBlock(0), MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().muirGlacierBlock(0), MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfEIP2384/difficultyEIP2384_random.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().muirGlacierBlock(0), MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().muirGlacierBlock(0), MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfEIP2384/difficultyEIP2384_random_to20M.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().muirGlacierBlock(0), MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().muirGlacierBlock(0), MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfFrontier/difficultyFrontier.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions(), MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions(), MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) ), Arguments.of( "/DifficultyTests/dfHomestead/difficultyHomestead.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().homesteadBlock(0), MiningParameters.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().homesteadBlock(0), MiningConfiguration.MINING_DISABLED, new BadBlockManager(), false, new NoOpMetricsSystem()) )); } From 11fc09413205e2b7794e4dd166c00e02f079a479 Mon Sep 17 00:00:00 2001 From: Justin Florentine Date: Sun, 3 Nov 2024 18:36:22 -0500 Subject: [PATCH 11/56] adds issue templates (#7820) * adds issue templates Signed-off-by: jflo * adopts pr suggestions Signed-off-by: jflo --------- Signed-off-by: jflo Co-authored-by: Sally MacFarlane --- .github/ISSUE_TEMPLATE/bug-report.md | 50 +++++++++++++++++++++++ .github/ISSUE_TEMPLATE/feature-request.md | 45 ++++++++++++++++++++ .github/issue_template.md | 22 +--------- 3 files changed, 96 insertions(+), 21 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug-report.md create mode 100644 .github/ISSUE_TEMPLATE/feature-request.md diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md new file mode 100644 index 00000000000..7b88a843790 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -0,0 +1,50 @@ +--- +name: Bug Report +about: necessary information to help us resolve the issue +title: '' +labels: 'bug' +assignees: '' + +--- + + + + + + + + + +### Steps to Reproduce +1. [Step 1] +2. [Step 2] +3. [Step ...] + +**Expected behavior:** [What you expect to happen] + +**Actual behavior:** [What actually happens] + +**Frequency:** [What percentage of the time does it occur?] + +### Logs +Please post relevant logs from Besu (and the consensus client, if running proof of stake) from before and after the issue. + +### Versions (Add all that apply) +* Software version: [`besu --version`] +* Java version: [`java -version`] +* OS Name & Version: [`cat /etc/*release`] +* Kernel Version: [`uname -a`] +* Virtual Machine software & version: [`vmware -v`] +* Docker Version: [`docker version`] +* Cloud VM, type, size: [Amazon Web Services I3-large] +* Consensus Client & Version if using Proof of Stake: [e.g. Teku, Lighthouse, Prysm, Nimbus, Lodestar] + +### Smart contract information (If you're reporting an issue arising from deploying or calling a smart contract, please supply related information) +* Solidity version [`solc --version`] +* Repo with minimal set of deployable/reproducible contract code - please provide a link +* Please include specifics on how you are deploying/calling the contract +* Have you reproduced the issue on other eth clients + +### Additional Information (Add any of the following or anything else that may be relevant) +* Besu setup info - genesis file, config options +* System info - memory, CPU diff --git a/.github/ISSUE_TEMPLATE/feature-request.md b/.github/ISSUE_TEMPLATE/feature-request.md new file mode 100644 index 00000000000..73ebe5f060e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature-request.md @@ -0,0 +1,45 @@ +--- +name: Feature Request +about: suggesting new or altered functionality +title: '' +labels: '' +assignees: '' + +--- + + + + + + + +### Description +As an [Actor], I want [feature] so that [why]. + +### Acceptance Criteria +* [Criteria 1] +* [Criteria 2] +* [Criteria 3...] + +### Logs (if a change in behavior) +Please post relevant logs from Besu (and the consensus client, if running proof of stake) illustrating behavior to be altered + +### Versions (Add all that apply) +* Software version: [`besu --version`] +* Java version: [`java -version`] +* OS Name & Version: [`cat /etc/*release`] +* Kernel Version: [`uname -a`] +* Virtual Machine software & version: [`vmware -v`] +* Docker Version: [`docker version`] +* Cloud VM, type, size: [Amazon Web Services I3-large] +* Consensus Client & Version if using Proof of Stake: [e.g. Teku, Lighthouse, Prysm, Nimbus, Lodestar] + +### Smart contract information (If you're reporting an issue arising from deploying or calling a smart contract, please supply related information) +* Solidity version [`solc --version`] +* Repo with minimal set of deployable/reproducible contract code - please provide a link +* Please include specifics on how you are deploying/calling the contract +* Have you reproduced the issue on other eth clients + +### Additional Information (Add any of the following or anything else that may be relevant) +* Besu setup info - genesis file, config options +* System info - memory, CPU diff --git a/.github/issue_template.md b/.github/issue_template.md index 54acf4c1968..7fe82b4f078 100644 --- a/.github/issue_template.md +++ b/.github/issue_template.md @@ -2,30 +2,10 @@ - - - + -### Description -As an [Actor], I want [feature] so that [why]. -### Acceptance Criteria -* [Criteria 1] - -### Steps to Reproduce (Bug) -1. [Step 1] -2. [Step 2] -3. [Step ...] - -**Expected behavior:** [What you expect to happen] - -**Actual behavior:** [What actually happens] - -**Frequency:** [What percentage of the time does it occur?] - -### Logs (if a bug) -Please post relevant logs from Besu (and the consensus client, if running proof of stake) from before and after the issue. ### Versions (Add all that apply) * Software version: [`besu --version`] From 03a2b92f0011d6cd91e1068436a8abe48a3703cc Mon Sep 17 00:00:00 2001 From: Justin Florentine Date: Mon, 4 Nov 2024 15:36:11 -0500 Subject: [PATCH 12/56] IntelliJ do not fail me (#7855) Signed-off-by: jflo --- .../dsl/node/ProcessBesuNodeRunner.java | 2 +- .../org/hyperledger/besu/RunnerBuilder.java | 2 +- .../org/hyperledger/besu/cli/BesuCommand.java | 52 +++++++++---------- .../{stable => }/ApiConfigurationOptions.java | 2 +- .../{unstable => }/ChainPruningOptions.java | 3 +- .../options/{unstable => }/DnsOptions.java | 3 +- .../{stable => }/EngineRPCConfiguration.java | 2 +- .../{stable => }/EngineRPCOptions.java | 3 +- .../{unstable => }/EthProtocolOptions.java | 4 +- .../options/{stable => }/EthstatsOptions.java | 3 +- .../options/{unstable => }/EvmOptions.java | 3 +- .../options/{stable => }/GraphQlOptions.java | 2 +- .../{unstable => }/InProcessRpcOptions.java | 3 +- .../options/{unstable => }/IpcOptions.java | 2 +- .../{stable => }/JsonRpcHttpOptions.java | 2 +- .../{stable => }/LoggingLevelOption.java | 2 +- .../options/{stable => }/MetricsOptions.java | 3 +- .../options/{unstable => }/NatOptions.java | 2 +- .../{unstable => }/NativeLibraryOptions.java | 2 +- .../{unstable => }/NetworkingOptions.java | 4 +- .../NodePrivateKeyFileOption.java | 2 +- .../{stable => }/P2PDiscoveryOptions.java | 3 +- .../{unstable => }/P2PTLSConfigOptions.java | 2 +- .../{stable => }/PermissionsOptions.java | 2 +- .../PluginsConfigurationOptions.java | 3 +- .../{unstable => }/PrivacyPluginOptions.java | 2 +- .../options/{unstable => }/RPCOptions.java | 2 +- .../{stable => }/RpcWebsocketOptions.java | 2 +- .../{unstable => }/SynchronizerOptions.java | 4 +- .../cli/subcommands/PublicKeySubCommand.java | 2 +- .../besu/components/BesuCommandModule.java | 4 +- .../besu/services/BesuConfigurationImpl.java | 2 +- .../besu/cli/CommandTestAbstract.java | 8 +-- .../cli/options/EthProtocolOptionsTest.java | 1 - .../{stable => }/LoggingLevelOptionTest.java | 2 +- .../besu/cli/options/MetricsOptionsTest.java | 1 - .../cli/options/NetworkingOptionsTest.java | 1 - .../cli/options/SynchronizerOptionsTest.java | 1 - ...onfigDefaultValueProviderStrategyTest.java | 2 +- 39 files changed, 64 insertions(+), 83 deletions(-) rename besu/src/main/java/org/hyperledger/besu/cli/options/{stable => }/ApiConfigurationOptions.java (99%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{unstable => }/ChainPruningOptions.java (98%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{unstable => }/DnsOptions.java (96%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{stable => }/EngineRPCConfiguration.java (96%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{stable => }/EngineRPCOptions.java (96%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{unstable => }/EthProtocolOptions.java (97%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{stable => }/EthstatsOptions.java (96%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{unstable => }/EvmOptions.java (96%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{stable => }/GraphQlOptions.java (98%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{unstable => }/InProcessRpcOptions.java (96%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{unstable => }/IpcOptions.java (98%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{stable => }/JsonRpcHttpOptions.java (99%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{stable => }/LoggingLevelOption.java (97%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{stable => }/MetricsOptions.java (99%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{unstable => }/NatOptions.java (97%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{unstable => }/NativeLibraryOptions.java (98%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{unstable => }/NetworkingOptions.java (96%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{stable => }/NodePrivateKeyFileOption.java (96%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{stable => }/P2PDiscoveryOptions.java (98%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{unstable => }/P2PTLSConfigOptions.java (99%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{stable => }/PermissionsOptions.java (99%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{stable => }/PluginsConfigurationOptions.java (97%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{unstable => }/PrivacyPluginOptions.java (96%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{unstable => }/RPCOptions.java (97%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{stable => }/RpcWebsocketOptions.java (99%) rename besu/src/main/java/org/hyperledger/besu/cli/options/{unstable => }/SynchronizerOptions.java (99%) rename besu/src/test/java/org/hyperledger/besu/cli/options/{stable => }/LoggingLevelOptionTest.java (97%) diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ProcessBesuNodeRunner.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ProcessBesuNodeRunner.java index 75307d95202..ee865a81425 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ProcessBesuNodeRunner.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ProcessBesuNodeRunner.java @@ -17,9 +17,9 @@ import static com.google.common.base.Preconditions.checkState; import static java.nio.charset.StandardCharsets.UTF_8; +import org.hyperledger.besu.cli.options.NetworkingOptions; import org.hyperledger.besu.cli.options.TransactionPoolOptions; import org.hyperledger.besu.cli.options.storage.DataStorageOptions; -import org.hyperledger.besu.cli.options.unstable.NetworkingOptions; import org.hyperledger.besu.ethereum.api.jsonrpc.ipc.JsonRpcIpcConfiguration; import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration; import org.hyperledger.besu.ethereum.p2p.rlpx.connections.netty.TLSConfiguration; diff --git a/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java b/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java index d6619d6c122..06dca6c6f0a 100644 --- a/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java @@ -23,7 +23,7 @@ import org.hyperledger.besu.cli.config.EthNetworkConfig; import org.hyperledger.besu.cli.config.NetworkName; -import org.hyperledger.besu.cli.options.stable.EthstatsOptions; +import org.hyperledger.besu.cli.options.EthstatsOptions; import org.hyperledger.besu.controller.BesuController; import org.hyperledger.besu.cryptoservices.NodeKey; import org.hyperledger.besu.ethereum.ProtocolContext; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index b974dcd3150..8f4a1472fb3 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -40,36 +40,36 @@ import org.hyperledger.besu.cli.custom.JsonRPCAllowlistHostsProperty; import org.hyperledger.besu.cli.error.BesuExecutionExceptionHandler; import org.hyperledger.besu.cli.error.BesuParameterExceptionHandler; +import org.hyperledger.besu.cli.options.ApiConfigurationOptions; +import org.hyperledger.besu.cli.options.ChainPruningOptions; +import org.hyperledger.besu.cli.options.DnsOptions; +import org.hyperledger.besu.cli.options.EngineRPCConfiguration; +import org.hyperledger.besu.cli.options.EngineRPCOptions; +import org.hyperledger.besu.cli.options.EthProtocolOptions; +import org.hyperledger.besu.cli.options.EthstatsOptions; +import org.hyperledger.besu.cli.options.EvmOptions; +import org.hyperledger.besu.cli.options.GraphQlOptions; +import org.hyperledger.besu.cli.options.InProcessRpcOptions; +import org.hyperledger.besu.cli.options.IpcOptions; +import org.hyperledger.besu.cli.options.JsonRpcHttpOptions; +import org.hyperledger.besu.cli.options.LoggingLevelOption; +import org.hyperledger.besu.cli.options.MetricsOptions; import org.hyperledger.besu.cli.options.MiningOptions; +import org.hyperledger.besu.cli.options.NatOptions; +import org.hyperledger.besu.cli.options.NativeLibraryOptions; +import org.hyperledger.besu.cli.options.NetworkingOptions; +import org.hyperledger.besu.cli.options.NodePrivateKeyFileOption; +import org.hyperledger.besu.cli.options.P2PDiscoveryOptions; +import org.hyperledger.besu.cli.options.P2PTLSConfigOptions; +import org.hyperledger.besu.cli.options.PermissionsOptions; +import org.hyperledger.besu.cli.options.PluginsConfigurationOptions; +import org.hyperledger.besu.cli.options.PrivacyPluginOptions; +import org.hyperledger.besu.cli.options.RPCOptions; +import org.hyperledger.besu.cli.options.RpcWebsocketOptions; +import org.hyperledger.besu.cli.options.SynchronizerOptions; import org.hyperledger.besu.cli.options.TransactionPoolOptions; -import org.hyperledger.besu.cli.options.stable.ApiConfigurationOptions; -import org.hyperledger.besu.cli.options.stable.EngineRPCConfiguration; -import org.hyperledger.besu.cli.options.stable.EngineRPCOptions; -import org.hyperledger.besu.cli.options.stable.EthstatsOptions; -import org.hyperledger.besu.cli.options.stable.GraphQlOptions; -import org.hyperledger.besu.cli.options.stable.JsonRpcHttpOptions; -import org.hyperledger.besu.cli.options.stable.LoggingLevelOption; -import org.hyperledger.besu.cli.options.stable.MetricsOptions; -import org.hyperledger.besu.cli.options.stable.NodePrivateKeyFileOption; -import org.hyperledger.besu.cli.options.stable.P2PDiscoveryOptions; -import org.hyperledger.besu.cli.options.stable.PermissionsOptions; -import org.hyperledger.besu.cli.options.stable.PluginsConfigurationOptions; -import org.hyperledger.besu.cli.options.stable.RpcWebsocketOptions; import org.hyperledger.besu.cli.options.storage.DataStorageOptions; import org.hyperledger.besu.cli.options.storage.DiffBasedSubStorageOptions; -import org.hyperledger.besu.cli.options.unstable.ChainPruningOptions; -import org.hyperledger.besu.cli.options.unstable.DnsOptions; -import org.hyperledger.besu.cli.options.unstable.EthProtocolOptions; -import org.hyperledger.besu.cli.options.unstable.EvmOptions; -import org.hyperledger.besu.cli.options.unstable.InProcessRpcOptions; -import org.hyperledger.besu.cli.options.unstable.IpcOptions; -import org.hyperledger.besu.cli.options.unstable.NatOptions; -import org.hyperledger.besu.cli.options.unstable.NativeLibraryOptions; -import org.hyperledger.besu.cli.options.unstable.NetworkingOptions; -import org.hyperledger.besu.cli.options.unstable.P2PTLSConfigOptions; -import org.hyperledger.besu.cli.options.unstable.PrivacyPluginOptions; -import org.hyperledger.besu.cli.options.unstable.RPCOptions; -import org.hyperledger.besu.cli.options.unstable.SynchronizerOptions; import org.hyperledger.besu.cli.presynctasks.PreSynchronizationTaskRunner; import org.hyperledger.besu.cli.presynctasks.PrivateDatabaseMigrationPreSyncTask; import org.hyperledger.besu.cli.subcommands.PasswordSubCommand; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/ApiConfigurationOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/ApiConfigurationOptions.java similarity index 99% rename from besu/src/main/java/org/hyperledger/besu/cli/options/stable/ApiConfigurationOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/ApiConfigurationOptions.java index d6bc17026cd..c5954f50639 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/ApiConfigurationOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/ApiConfigurationOptions.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; import static java.util.Arrays.asList; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/ChainPruningOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/ChainPruningOptions.java similarity index 98% rename from besu/src/main/java/org/hyperledger/besu/cli/options/unstable/ChainPruningOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/ChainPruningOptions.java index 0a59ef9b04e..3f26b676ceb 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/ChainPruningOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/ChainPruningOptions.java @@ -12,9 +12,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.unstable; +package org.hyperledger.besu.cli.options; -import org.hyperledger.besu.cli.options.CLIOptions; import org.hyperledger.besu.ethereum.chain.ChainPrunerConfiguration; import org.hyperledger.besu.util.number.PositiveNumber; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/DnsOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/DnsOptions.java similarity index 96% rename from besu/src/main/java/org/hyperledger/besu/cli/options/unstable/DnsOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/DnsOptions.java index 9f9670e8e66..9a720bebbb0 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/DnsOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/DnsOptions.java @@ -12,9 +12,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.unstable; +package org.hyperledger.besu.cli.options; -import org.hyperledger.besu.cli.options.CLIOptions; import org.hyperledger.besu.ethereum.p2p.peers.EnodeDnsConfiguration; import org.hyperledger.besu.ethereum.p2p.peers.ImmutableEnodeDnsConfiguration; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/EngineRPCConfiguration.java b/besu/src/main/java/org/hyperledger/besu/cli/options/EngineRPCConfiguration.java similarity index 96% rename from besu/src/main/java/org/hyperledger/besu/cli/options/stable/EngineRPCConfiguration.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/EngineRPCConfiguration.java index c0eb9d1be08..ec98204d3bc 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/EngineRPCConfiguration.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/EngineRPCConfiguration.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; import org.hyperledger.besu.cli.custom.JsonRPCAllowlistHostsProperty; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/EngineRPCOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/EngineRPCOptions.java similarity index 96% rename from besu/src/main/java/org/hyperledger/besu/cli/options/stable/EngineRPCOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/EngineRPCOptions.java index 1aa5b3d3263..e660e6c821d 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/EngineRPCOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/EngineRPCOptions.java @@ -12,13 +12,12 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; import static org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration.DEFAULT_ENGINE_JSON_RPC_PORT; import org.hyperledger.besu.cli.DefaultCommandValues; import org.hyperledger.besu.cli.custom.JsonRPCAllowlistHostsProperty; -import org.hyperledger.besu.cli.options.CLIOptions; import org.hyperledger.besu.cli.util.CommandLineUtils; import java.nio.file.Path; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/EthProtocolOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/EthProtocolOptions.java similarity index 97% rename from besu/src/main/java/org/hyperledger/besu/cli/options/unstable/EthProtocolOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/EthProtocolOptions.java index 1d5434ff022..a20403027d7 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/EthProtocolOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/EthProtocolOptions.java @@ -12,10 +12,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.unstable; +package org.hyperledger.besu.cli.options; -import org.hyperledger.besu.cli.options.CLIOptions; -import org.hyperledger.besu.cli.options.OptionParser; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.util.number.PositiveNumber; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/EthstatsOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/EthstatsOptions.java similarity index 96% rename from besu/src/main/java/org/hyperledger/besu/cli/options/stable/EthstatsOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/EthstatsOptions.java index a6e939fdf0e..08e8b49c523 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/EthstatsOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/EthstatsOptions.java @@ -12,9 +12,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; -import org.hyperledger.besu.cli.options.CLIOptions; import org.hyperledger.besu.ethstats.util.EthStatsConnectOptions; import java.nio.file.Path; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/EvmOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/EvmOptions.java similarity index 96% rename from besu/src/main/java/org/hyperledger/besu/cli/options/unstable/EvmOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/EvmOptions.java index 39d95324df2..6a58d6830a9 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/EvmOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/EvmOptions.java @@ -12,9 +12,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.unstable; +package org.hyperledger.besu.cli.options; -import org.hyperledger.besu.cli.options.CLIOptions; import org.hyperledger.besu.evm.internal.EvmConfiguration; import java.util.List; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/GraphQlOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/GraphQlOptions.java similarity index 98% rename from besu/src/main/java/org/hyperledger/besu/cli/options/stable/GraphQlOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/GraphQlOptions.java index 6aac24a6fbc..643ca22e005 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/GraphQlOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/GraphQlOptions.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; import static java.util.Arrays.asList; import static org.hyperledger.besu.ethereum.api.graphql.GraphQLConfiguration.DEFAULT_GRAPHQL_HTTP_PORT; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/InProcessRpcOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/InProcessRpcOptions.java similarity index 96% rename from besu/src/main/java/org/hyperledger/besu/cli/options/unstable/InProcessRpcOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/InProcessRpcOptions.java index 9adeb37db7d..278a55e1870 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/InProcessRpcOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/InProcessRpcOptions.java @@ -12,12 +12,11 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.unstable; +package org.hyperledger.besu.cli.options; import static org.hyperledger.besu.ethereum.api.jsonrpc.InProcessRpcConfiguration.DEFAULT_IN_PROCESS_RPC_APIS; import static org.hyperledger.besu.ethereum.api.jsonrpc.InProcessRpcConfiguration.DEFAULT_IN_PROCESS_RPC_ENABLED; -import org.hyperledger.besu.cli.options.CLIOptions; import org.hyperledger.besu.cli.util.CommandLineUtils; import org.hyperledger.besu.ethereum.api.jsonrpc.ImmutableInProcessRpcConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.InProcessRpcConfiguration; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/IpcOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/IpcOptions.java similarity index 98% rename from besu/src/main/java/org/hyperledger/besu/cli/options/unstable/IpcOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/IpcOptions.java index 19ba2941932..689ac4e9b3b 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/IpcOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/IpcOptions.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.unstable; +package org.hyperledger.besu.cli.options; import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.DEFAULT_RPC_APIS; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/JsonRpcHttpOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/JsonRpcHttpOptions.java similarity index 99% rename from besu/src/main/java/org/hyperledger/besu/cli/options/stable/JsonRpcHttpOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/JsonRpcHttpOptions.java index 7d08a6f9aa6..c8c2c733440 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/JsonRpcHttpOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/JsonRpcHttpOptions.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; import static java.util.Arrays.asList; import static org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration.DEFAULT_JSON_RPC_HOST; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/LoggingLevelOption.java b/besu/src/main/java/org/hyperledger/besu/cli/options/LoggingLevelOption.java similarity index 97% rename from besu/src/main/java/org/hyperledger/besu/cli/options/stable/LoggingLevelOption.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/LoggingLevelOption.java index 39b2a2482b8..1a498fd1962 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/LoggingLevelOption.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/LoggingLevelOption.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; import java.util.Locale; import java.util.Set; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/MetricsOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/MetricsOptions.java similarity index 99% rename from besu/src/main/java/org/hyperledger/besu/cli/options/stable/MetricsOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/MetricsOptions.java index beba20e29b5..1f777286bf5 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/MetricsOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/MetricsOptions.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; import static com.google.common.base.Preconditions.checkState; import static java.util.stream.Collectors.toUnmodifiableSet; @@ -24,7 +24,6 @@ import static org.hyperledger.besu.metrics.prometheus.MetricsConfiguration.DEFAULT_METRICS_PORT; import static org.hyperledger.besu.metrics.prometheus.MetricsConfiguration.DEFAULT_METRICS_PUSH_PORT; -import org.hyperledger.besu.cli.options.CLIOptions; import org.hyperledger.besu.cli.util.CommandLineUtils; import org.hyperledger.besu.metrics.MetricCategoryRegistryImpl; import org.hyperledger.besu.metrics.MetricsProtocol; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NatOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/NatOptions.java similarity index 97% rename from besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NatOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/NatOptions.java index 31716543d51..11e8051d0e3 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NatOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/NatOptions.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.unstable; +package org.hyperledger.besu.cli.options; import static org.hyperledger.besu.nat.kubernetes.KubernetesNatManager.DEFAULT_BESU_SERVICE_NAME_FILTER; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NativeLibraryOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/NativeLibraryOptions.java similarity index 98% rename from besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NativeLibraryOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/NativeLibraryOptions.java index ec7f043b8f1..f3fc9c3ba4a 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NativeLibraryOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/NativeLibraryOptions.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.unstable; +package org.hyperledger.besu.cli.options; import picocli.CommandLine; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NetworkingOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/NetworkingOptions.java similarity index 96% rename from besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NetworkingOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/NetworkingOptions.java index aed7b079d87..dc001d02311 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NetworkingOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/NetworkingOptions.java @@ -12,10 +12,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.unstable; +package org.hyperledger.besu.cli.options; -import org.hyperledger.besu.cli.options.CLIOptions; -import org.hyperledger.besu.cli.options.OptionParser; import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration; import java.util.Arrays; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/NodePrivateKeyFileOption.java b/besu/src/main/java/org/hyperledger/besu/cli/options/NodePrivateKeyFileOption.java similarity index 96% rename from besu/src/main/java/org/hyperledger/besu/cli/options/stable/NodePrivateKeyFileOption.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/NodePrivateKeyFileOption.java index 107ced545d1..781dcb06e8a 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/NodePrivateKeyFileOption.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/NodePrivateKeyFileOption.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; import static org.hyperledger.besu.cli.DefaultCommandValues.MANDATORY_PATH_FORMAT_HELP; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/P2PDiscoveryOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/P2PDiscoveryOptions.java similarity index 98% rename from besu/src/main/java/org/hyperledger/besu/cli/options/stable/P2PDiscoveryOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/P2PDiscoveryOptions.java index a15be99dc74..798d246b52b 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/P2PDiscoveryOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/P2PDiscoveryOptions.java @@ -12,12 +12,11 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; import org.hyperledger.besu.cli.DefaultCommandValues; import org.hyperledger.besu.cli.converter.PercentageConverter; import org.hyperledger.besu.cli.converter.SubnetInfoConverter; -import org.hyperledger.besu.cli.options.CLIOptions; import org.hyperledger.besu.cli.util.CommandLineUtils; import org.hyperledger.besu.ethereum.p2p.discovery.P2PDiscoveryConfiguration; import org.hyperledger.besu.ethereum.p2p.peers.EnodeURLImpl; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/P2PTLSConfigOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/P2PTLSConfigOptions.java similarity index 99% rename from besu/src/main/java/org/hyperledger/besu/cli/options/unstable/P2PTLSConfigOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/P2PTLSConfigOptions.java index 5939eb3d390..ee53a5e96f4 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/P2PTLSConfigOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/P2PTLSConfigOptions.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.unstable; +package org.hyperledger.besu.cli.options; import static java.util.Arrays.asList; import static org.hyperledger.besu.cli.DefaultCommandValues.DEFAULT_KEYSTORE_TYPE; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/PermissionsOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/PermissionsOptions.java similarity index 99% rename from besu/src/main/java/org/hyperledger/besu/cli/options/stable/PermissionsOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/PermissionsOptions.java index 4dc693d36ed..b6c744c98f7 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/PermissionsOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/PermissionsOptions.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; import org.hyperledger.besu.cli.DefaultCommandValues; import org.hyperledger.besu.datatypes.Address; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/PluginsConfigurationOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/PluginsConfigurationOptions.java similarity index 97% rename from besu/src/main/java/org/hyperledger/besu/cli/options/stable/PluginsConfigurationOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/PluginsConfigurationOptions.java index 25893fff895..5a5a0646080 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/PluginsConfigurationOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/PluginsConfigurationOptions.java @@ -12,14 +12,13 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; import static org.hyperledger.besu.cli.DefaultCommandValues.DEFAULT_CONTINUE_ON_PLUGIN_ERROR_OPTION_NAME; import static org.hyperledger.besu.cli.DefaultCommandValues.DEFAULT_PLUGINS_EXTERNAL_ENABLED_OPTION_NAME; import static org.hyperledger.besu.cli.DefaultCommandValues.DEFAULT_PLUGINS_OPTION_NAME; import org.hyperledger.besu.cli.converter.PluginInfoConverter; -import org.hyperledger.besu.cli.options.CLIOptions; import org.hyperledger.besu.cli.util.CommandLineUtils; import org.hyperledger.besu.ethereum.core.plugins.PluginConfiguration; import org.hyperledger.besu.ethereum.core.plugins.PluginInfo; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/PrivacyPluginOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/PrivacyPluginOptions.java similarity index 96% rename from besu/src/main/java/org/hyperledger/besu/cli/options/unstable/PrivacyPluginOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/PrivacyPluginOptions.java index fe2f4df3fe8..9a8c0348e8b 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/PrivacyPluginOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/PrivacyPluginOptions.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.unstable; +package org.hyperledger.besu.cli.options; import static picocli.CommandLine.Option; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/RPCOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/RPCOptions.java similarity index 97% rename from besu/src/main/java/org/hyperledger/besu/cli/options/unstable/RPCOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/RPCOptions.java index 2dd11f428d6..63759af1c63 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/RPCOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/RPCOptions.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.unstable; +package org.hyperledger.besu.cli.options; import org.hyperledger.besu.ethereum.api.handlers.TimeoutOptions; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/RpcWebsocketOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/RpcWebsocketOptions.java similarity index 99% rename from besu/src/main/java/org/hyperledger/besu/cli/options/stable/RpcWebsocketOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/RpcWebsocketOptions.java index 40edeecc0da..d596d4183c7 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/RpcWebsocketOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/RpcWebsocketOptions.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.DEFAULT_RPC_APIS; import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.VALID_APIS; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/SynchronizerOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/SynchronizerOptions.java similarity index 99% rename from besu/src/main/java/org/hyperledger/besu/cli/options/unstable/SynchronizerOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/SynchronizerOptions.java index 816d9df00a1..c7d20c17fb6 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/SynchronizerOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/SynchronizerOptions.java @@ -12,10 +12,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.unstable; +package org.hyperledger.besu.cli.options; -import org.hyperledger.besu.cli.options.CLIOptions; -import org.hyperledger.besu.cli.options.OptionParser; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; import org.hyperledger.besu.ethereum.eth.sync.snapsync.ImmutableSnapSyncConfiguration; import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapSyncConfiguration; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/PublicKeySubCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/PublicKeySubCommand.java index 73916a936ef..593fc6cd778 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/PublicKeySubCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/PublicKeySubCommand.java @@ -20,7 +20,7 @@ import org.hyperledger.besu.cli.BesuCommand; import org.hyperledger.besu.cli.DefaultCommandValues; -import org.hyperledger.besu.cli.options.stable.NodePrivateKeyFileOption; +import org.hyperledger.besu.cli.options.NodePrivateKeyFileOption; import org.hyperledger.besu.cli.subcommands.PublicKeySubCommand.AddressSubCommand; import org.hyperledger.besu.cli.subcommands.PublicKeySubCommand.ExportSubCommand; import org.hyperledger.besu.cli.util.VersionProvider; diff --git a/besu/src/main/java/org/hyperledger/besu/components/BesuCommandModule.java b/besu/src/main/java/org/hyperledger/besu/components/BesuCommandModule.java index e757fd62a2b..ce4f00db737 100644 --- a/besu/src/main/java/org/hyperledger/besu/components/BesuCommandModule.java +++ b/besu/src/main/java/org/hyperledger/besu/components/BesuCommandModule.java @@ -20,8 +20,8 @@ import org.hyperledger.besu.chainimport.JsonBlockImporter; import org.hyperledger.besu.chainimport.RlpBlockImporter; import org.hyperledger.besu.cli.BesuCommand; -import org.hyperledger.besu.cli.options.stable.P2PDiscoveryOptions; -import org.hyperledger.besu.cli.options.unstable.RPCOptions; +import org.hyperledger.besu.cli.options.P2PDiscoveryOptions; +import org.hyperledger.besu.cli.options.RPCOptions; import org.hyperledger.besu.controller.BesuController; import org.hyperledger.besu.ethereum.p2p.discovery.P2PDiscoveryConfiguration; import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; diff --git a/besu/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java b/besu/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java index 39db58ee4d8..f2f5fa53dae 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java @@ -14,7 +14,7 @@ */ package org.hyperledger.besu.services; -import org.hyperledger.besu.cli.options.stable.JsonRpcHttpOptions; +import org.hyperledger.besu.cli.options.JsonRpcHttpOptions; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; diff --git a/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java b/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java index 5c7bf3ce88a..72396593985 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java @@ -34,13 +34,13 @@ import org.hyperledger.besu.chainimport.JsonBlockImporter; import org.hyperledger.besu.chainimport.RlpBlockImporter; import org.hyperledger.besu.cli.config.EthNetworkConfig; +import org.hyperledger.besu.cli.options.EthProtocolOptions; +import org.hyperledger.besu.cli.options.EthstatsOptions; import org.hyperledger.besu.cli.options.MiningOptions; +import org.hyperledger.besu.cli.options.NetworkingOptions; +import org.hyperledger.besu.cli.options.SynchronizerOptions; import org.hyperledger.besu.cli.options.TransactionPoolOptions; -import org.hyperledger.besu.cli.options.stable.EthstatsOptions; import org.hyperledger.besu.cli.options.storage.DataStorageOptions; -import org.hyperledger.besu.cli.options.unstable.EthProtocolOptions; -import org.hyperledger.besu.cli.options.unstable.NetworkingOptions; -import org.hyperledger.besu.cli.options.unstable.SynchronizerOptions; import org.hyperledger.besu.components.BesuComponent; import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.controller.BesuController; diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/EthProtocolOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/EthProtocolOptionsTest.java index 6f7aa637cdd..33c91f2c03f 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/EthProtocolOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/EthProtocolOptionsTest.java @@ -18,7 +18,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.verifyNoInteractions; -import org.hyperledger.besu.cli.options.unstable.EthProtocolOptions; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.junit.jupiter.api.Test; diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/stable/LoggingLevelOptionTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/LoggingLevelOptionTest.java similarity index 97% rename from besu/src/test/java/org/hyperledger/besu/cli/options/stable/LoggingLevelOptionTest.java rename to besu/src/test/java/org/hyperledger/besu/cli/options/LoggingLevelOptionTest.java index b1fb3217c28..78c0f694ad1 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/stable/LoggingLevelOptionTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/LoggingLevelOptionTest.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsOptionsTest.java index cd541759ad8..39e77cbad7e 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsOptionsTest.java @@ -14,7 +14,6 @@ */ package org.hyperledger.besu.cli.options; -import org.hyperledger.besu.cli.options.stable.MetricsOptions; import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.metrics.MetricCategoryRegistryImpl; import org.hyperledger.besu.metrics.StandardMetricCategory; diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/NetworkingOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/NetworkingOptionsTest.java index a645f28b548..191b1a82997 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/NetworkingOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/NetworkingOptionsTest.java @@ -17,7 +17,6 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; -import org.hyperledger.besu.cli.options.unstable.NetworkingOptions; import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration; import java.util.Arrays; diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/SynchronizerOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/SynchronizerOptionsTest.java index 0511279c19f..0a257de6da2 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/SynchronizerOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/SynchronizerOptionsTest.java @@ -14,7 +14,6 @@ */ package org.hyperledger.besu.cli.options; -import org.hyperledger.besu.cli.options.unstable.SynchronizerOptions; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; import org.hyperledger.besu.ethereum.eth.sync.snapsync.ImmutableSnapSyncConfiguration; import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapSyncConfiguration; diff --git a/besu/src/test/java/org/hyperledger/besu/cli/util/ConfigDefaultValueProviderStrategyTest.java b/besu/src/test/java/org/hyperledger/besu/cli/util/ConfigDefaultValueProviderStrategyTest.java index 50eadceb3bb..30eb677e88e 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/util/ConfigDefaultValueProviderStrategyTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/util/ConfigDefaultValueProviderStrategyTest.java @@ -25,7 +25,7 @@ import static org.mockito.Mockito.when; import org.hyperledger.besu.cli.error.BesuParameterExceptionHandler; -import org.hyperledger.besu.cli.options.stable.LoggingLevelOption; +import org.hyperledger.besu.cli.options.LoggingLevelOption; import java.io.File; import java.io.IOException; From 1da0e9f232d568ec899615bd1e51a4b53d2a7cdd Mon Sep 17 00:00:00 2001 From: garyschulte Date: Mon, 4 Nov 2024 13:16:36 -0800 Subject: [PATCH 13/56] remove dangling retesteth references (#7856) Signed-off-by: garyschulte --- besu/build.gradle | 1 - build.gradle | 3 --- settings.gradle | 1 - 3 files changed, 5 deletions(-) diff --git a/besu/build.gradle b/besu/build.gradle index 41a4b11494b..b6e506d9c14 100644 --- a/besu/build.gradle +++ b/besu/build.gradle @@ -49,7 +49,6 @@ dependencies { implementation project(':ethereum:eth') implementation project(':ethereum:p2p') implementation project(':ethereum:permissioning') - implementation project(':ethereum:retesteth') implementation project(':ethereum:rlp') implementation project(':ethereum:trie') implementation project(':ethereum:stratum') diff --git a/build.gradle b/build.gradle index 4fe80600c2c..8b6982cd4a0 100644 --- a/build.gradle +++ b/build.gradle @@ -417,9 +417,6 @@ configure(allprojects - project(':platform')) { '-org.hyperledger.besu.ethereum.permissioning.*,' + // referencetests module '-org.hyperledger.besu.ethereum.referencetests,' + - // retesteth module - '-org.hyperledger.besu.ethereum.retesteth.methods,' + - '-org.hyperledger.besu.ethereum.retesteth,' + //rlp module '-org.hyperledger.besu.ethereum.rlp,' + // stratum module diff --git a/settings.gradle b/settings.gradle index 2860c666d9d..83363f70e49 100644 --- a/settings.gradle +++ b/settings.gradle @@ -51,7 +51,6 @@ include 'ethereum:mock-p2p' include 'ethereum:p2p' include 'ethereum:permissioning' include 'ethereum:referencetests' -include 'ethereum:retesteth' include 'ethereum:rlp' include 'ethereum:stratum' include 'ethereum:ethstats' From d415b7db532a32123cb2c8cc14c6d71f6b988e60 Mon Sep 17 00:00:00 2001 From: garyschulte Date: Mon, 4 Nov 2024 15:05:16 -0800 Subject: [PATCH 14/56] feature: Add optional worldstate move flag to debug_setHead (#7821) * add optional worldstate move to debug_setHead * make state rolling occur incrementally so as not to overwhelm memory and resources Signed-off-by: garyschulte --- .../internal/methods/DebugSetHead.java | 123 ++++++++++- .../internal/methods/DebugSetHeadTest.java | 198 ++++++++++++++++++ 2 files changed, 310 insertions(+), 11 deletions(-) create mode 100644 ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHeadTest.java diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java index 7958f8e7595..c2210f81748 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java @@ -21,22 +21,41 @@ 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.BlockParameterOrBlockHash; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; 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.chain.MutableBlockchain; +import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.trie.diffbased.common.DiffBasedWorldStateProvider; import java.util.Optional; -public class DebugSetHead extends AbstractBlockParameterMethod { +import graphql.VisibleForTesting; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DebugSetHead extends AbstractBlockParameterOrBlockHashMethod { private final ProtocolContext protocolContext; + private static final Logger LOG = LoggerFactory.getLogger(DebugSetHead.class); + private static final int DEFAULT_MAX_TRIE_LOGS_TO_ROLL_AT_ONCE = 512; + + private final long maxTrieLogsToRollAtOnce; public DebugSetHead(final BlockchainQueries blockchain, final ProtocolContext protocolContext) { - super(blockchain); + this(blockchain, protocolContext, DEFAULT_MAX_TRIE_LOGS_TO_ROLL_AT_ONCE); + } + @VisibleForTesting + DebugSetHead( + final BlockchainQueries blockchain, + final ProtocolContext protocolContext, + final long maxTrieLogsToRollAtOnce) { + super(blockchain); this.protocolContext = protocolContext; + this.maxTrieLogsToRollAtOnce = Math.abs(maxTrieLogsToRollAtOnce); } @Override @@ -45,26 +64,108 @@ public String getName() { } @Override - protected BlockParameter blockParameter(final JsonRpcRequestContext request) { + protected BlockParameterOrBlockHash blockParameterOrBlockHash( + final JsonRpcRequestContext requestContext) { try { - return request.getRequiredParameter(0, BlockParameter.class); + return requestContext.getRequiredParameter(0, BlockParameterOrBlockHash.class); } catch (JsonRpcParameterException e) { throw new InvalidJsonRpcParameters( - "Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); + "Invalid block or block hash parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e); } } @Override - protected Object resultByBlockNumber( - final JsonRpcRequestContext request, final long blockNumber) { - final Optional maybeBlockHash = getBlockchainQueries().getBlockHashByNumber(blockNumber); + protected Object resultByBlockHash(final JsonRpcRequestContext request, final Hash blockHash) { + var blockchainQueries = getBlockchainQueries(); + var blockchain = protocolContext.getBlockchain(); + Optional maybeBlockHeader = blockchainQueries.getBlockHeaderByHash(blockHash); + Optional maybeMoveWorldstate = shouldMoveWorldstate(request); - if (maybeBlockHash.isEmpty()) { + if (maybeBlockHeader.isEmpty()) { return new JsonRpcErrorResponse(request.getRequest().getId(), UNKNOWN_BLOCK); } - protocolContext.getBlockchain().rewindToBlock(maybeBlockHash.get()); + // Optionally move the worldstate to the specified blockhash, if it is present in the chain + if (maybeMoveWorldstate.orElse(Boolean.FALSE)) { + var archive = blockchainQueries.getWorldStateArchive(); + + // Only DiffBasedWorldState's need to be moved: + if (archive instanceof DiffBasedWorldStateProvider diffBasedArchive) { + if (rollIncrementally(maybeBlockHeader.get(), blockchain, diffBasedArchive)) { + return JsonRpcSuccessResponse.SUCCESS_RESULT; + } + } + } + + // If we are not rolling incrementally or if there was an error incrementally rolling, + // move the blockchain to the requested hash: + blockchain.rewindToBlock(maybeBlockHeader.get().getBlockHash()); return JsonRpcSuccessResponse.SUCCESS_RESULT; } + + private boolean rollIncrementally( + final BlockHeader target, + final MutableBlockchain blockchain, + final DiffBasedWorldStateProvider archive) { + + try { + if (archive.isWorldStateAvailable(target.getStateRoot(), target.getBlockHash())) { + // WARNING, this can be dangerous for a DiffBasedWorldstate if a concurrent + // process attempts to move or modify the head worldstate. + // Ensure no block processing is occuring when using this feature. + // No engine-api, block import, sync, mining or other rpc calls should be running. + + Optional currentHead = + archive + .getWorldStateKeyValueStorage() + .getWorldStateBlockHash() + .flatMap(blockchain::getBlockHeader); + + while (currentHead.isPresent() + && !target.getStateRoot().equals(currentHead.get().getStateRoot())) { + long delta = currentHead.get().getNumber() - target.getNumber(); + + if (maxTrieLogsToRollAtOnce < Math.abs(delta)) { + // do we need to move forward or backward? + long distanceToMove = (delta > 0) ? -maxTrieLogsToRollAtOnce : maxTrieLogsToRollAtOnce; + + // Add distanceToMove to the current block number to get the interim target header + var interimHead = + blockchain.getBlockHeader(currentHead.get().getNumber() + distanceToMove); + + interimHead.ifPresent( + it -> { + blockchain.rewindToBlock(it.getBlockHash()); + archive.getMutable(it.getStateRoot(), it.getBlockHash()); + LOG.info("incrementally rolled worldstate to {}", it.toLogString()); + }); + currentHead = interimHead; + + } else { + blockchain.rewindToBlock(target.getBlockHash()); + archive.getMutable(target.getStateRoot(), target.getBlockHash()); + currentHead = Optional.of(target); + LOG.info("finished rolling worldstate to {}", target.toLogString()); + } + } + } + + return true; + } catch (Exception ex) { + LOG.error("Failed to incrementally roll blockchain to " + target.toLogString(), ex); + return false; + } + } + + private Optional shouldMoveWorldstate(final JsonRpcRequestContext request) { + try { + return request.getOptionalParameter(1, Boolean.class); + } catch (JsonRpcParameterException e) { + throw new InvalidJsonRpcParameters( + "Invalid should move worldstate boolean parameter (index 1)", + RpcErrorType.INVALID_PARAMS, + e); + } + } } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHeadTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHeadTest.java new file mode 100644 index 00000000000..8d552ee3765 --- /dev/null +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHeadTest.java @@ -0,0 +1,198 @@ +/* + * Copyright contributors to 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.ethereum.api.jsonrpc.internal.methods; + +import static java.lang.Boolean.FALSE; +import static java.lang.Boolean.TRUE; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +import org.hyperledger.besu.crypto.Hash; +import org.hyperledger.besu.ethereum.ProtocolContext; +import org.hyperledger.besu.ethereum.api.jsonrpc.AbstractJsonRpcHttpServiceTest; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameterOrBlockHash; +import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; +import org.hyperledger.besu.ethereum.chain.Blockchain; +import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.core.MiningConfiguration; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; +import org.hyperledger.besu.plugin.services.rpc.RpcResponseType; + +import java.util.Optional; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.apache.tuweni.bytes.Bytes; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +/** + * This test only exercises bonsai worldstate since forest is essentially a no-op for moving the + * worldstate. + */ +public class DebugSetHeadTest extends AbstractJsonRpcHttpServiceTest { + + DebugSetHead debugSetHead; + Blockchain blockchain; + WorldStateArchive archive; + ProtocolContext protocolContext; + ProtocolSchedule protocolSchedule; + + @Override + @BeforeEach + public void setup() throws Exception { + setupBonsaiBlockchain(); + blockchain = blockchainSetupUtil.getBlockchain(); + protocolContext = blockchainSetupUtil.getProtocolContext(); + protocolSchedule = blockchainSetupUtil.getProtocolSchedule(); + ; + archive = blockchainSetupUtil.getWorldArchive(); + debugSetHead = + new DebugSetHead( + new BlockchainQueries( + protocolSchedule, blockchain, archive, MiningConfiguration.MINING_DISABLED), + protocolContext, + // a value of 2 here exercises all the state rolling code paths + 2); + startService(); + } + + @ParameterizedTest + @ValueSource( + strings = {"0x01", "0x4e9a67b663f9abe03e7e9fd5452c9497998337077122f44ee78a466f6a7358de"}) + public void assertOnlyChainHeadMovesWorldParameterAbsent(final String blockParam) { + var chainTip = blockchain.getChainHead().getBlockHeader(); + var blockOne = getBlockHeaderForHashOrNumber(blockParam).orElse(null); + + assertThat(blockOne).isNotNull(); + assertThat(blockOne).isNotEqualTo(chainTip); + + // move the head to param val, number or hash + debugSetHead.response(debugSetHead(blockParam, Optional.empty())); + + // get the new chainTip: + var newChainTip = blockchain.getChainHead().getBlockHeader(); + + // assert the chain moved, and the worldstate did not + assertThat(newChainTip).isEqualTo(blockOne); + assertThat(archive.getMutable().rootHash()).isEqualTo(chainTip.getStateRoot()); + } + + @ParameterizedTest + @ValueSource( + strings = { + "0x01", + "0x02", + "0x3d813a0ffc9cd04436e17e3e9c309f1e80df0407078e50355ce0d570b5424812", + "0x4e9a67b663f9abe03e7e9fd5452c9497998337077122f44ee78a466f6a7358de" + }) + public void assertOnlyChainHeadMoves(final String blockParam) { + var chainTip = blockchain.getChainHead().getBlockHeader(); + var blockOne = getBlockHeaderForHashOrNumber(blockParam).orElse(null); + + assertThat(blockOne).isNotNull(); + assertThat(blockOne).isNotEqualTo(chainTip); + + // move the head to param val, number or hash + debugSetHead.response(debugSetHead(blockParam, Optional.of(FALSE))); + + // get the new chainTip: + var newChainTip = blockchain.getChainHead().getBlockHeader(); + + // assert the chain moved, and the worldstate did not + assertThat(newChainTip).isEqualTo(blockOne); + assertThat(archive.getMutable().rootHash()).isEqualTo(chainTip.getStateRoot()); + } + + @ParameterizedTest + @ValueSource( + strings = { + "0x01", + "0x02", + "0x3d813a0ffc9cd04436e17e3e9c309f1e80df0407078e50355ce0d570b5424812", + "0x4e9a67b663f9abe03e7e9fd5452c9497998337077122f44ee78a466f6a7358de" + }) + public void assertBothChainHeadAndWorldStatByNumber(final String blockParam) { + var chainTip = blockchain.getChainHead().getBlockHeader(); + var blockOne = getBlockHeaderForHashOrNumber(blockParam).orElse(null); + + assertThat(blockOne).isNotNull(); + assertThat(blockOne).isNotEqualTo(chainTip); + + // move the head and worldstate to param val number or hash + debugSetHead.response(debugSetHead(blockParam, Optional.of(TRUE))); + + // get the new chainTip: + var newChainTip = blockchain.getChainHead().getBlockHeader(); + + // assert both the chain and worldstate moved to block one + assertThat(newChainTip).isEqualTo(blockOne); + assertThat(archive.getMutable().rootHash()).isEqualTo(blockOne.getStateRoot()); + } + + @Test + public void assertNotFound() { + var chainTip = blockchain.getChainHead().getBlockHeader(); + + // move the head to number just after chain head + var resp = + debugSetHead.response(debugSetHead("" + chainTip.getNumber() + 1, Optional.of(TRUE))); + assertThat(resp.getType()).isEqualTo(RpcResponseType.ERROR); + + // move the head to some arbitrary hash + var resp2 = + debugSetHead.response( + debugSetHead( + Hash.keccak256(Bytes.fromHexString("0xdeadbeef")).toHexString(), + Optional.of(TRUE))); + assertThat(resp2.getType()).isEqualTo(RpcResponseType.ERROR); + + // get the new chainTip: + var newChainTip = blockchain.getChainHead().getBlockHeader(); + + // assert neither the chain nor the worldstate moved + assertThat(newChainTip).isEqualTo(chainTip); + assertThat(archive.getMutable().rootHash()).isEqualTo(chainTip.getStateRoot()); + } + + private JsonRpcRequestContext debugSetHead( + final String numberOrHash, final Optional moveWorldState) { + if (moveWorldState.isPresent()) { + return new JsonRpcRequestContext( + new JsonRpcRequest( + "2.0", "debug_setHead", new Object[] {numberOrHash, moveWorldState.get()})); + } else { + return new JsonRpcRequestContext( + new JsonRpcRequest("2.0", "debug_setHead", new Object[] {numberOrHash})); + } + } + + private Optional getBlockHeaderForHashOrNumber(final String input) { + try { + var param = new BlockParameterOrBlockHash(input); + if (param.getHash().isPresent()) { + return blockchain.getBlockHeader(param.getHash().get()); + } else if (param.getNumber().isPresent()) { + return blockchain.getBlockHeader(param.getNumber().getAsLong()); + } + } catch (JsonProcessingException ignored) { + // meh + } + return Optional.empty(); + } +} From ef9d1ab38ed82e3eaca1166bdb97da2d06d813d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Bojarski?= <54240434+letypequividelespoubelles@users.noreply.github.com> Date: Tue, 5 Nov 2024 00:47:44 +0100 Subject: [PATCH 15/56] fix(push): right pad if `push parameter + PC +1` exceeds code length (#7834) * fix(push): right pad if push parameter exceeds code length * test: add push operation padding tests * better perf rightPadding thnks to Ameziane Signed-off-by: F Bojarski Co-authored-by: Ameziane H. --- .../besu/evm/operation/PushOperation.java | 12 ++- .../besu/evm/operation/PushOperationTest.java | 83 +++++++++++++++++++ 2 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 evm/src/test/java/org/hyperledger/besu/evm/operation/PushOperationTest.java diff --git a/evm/src/main/java/org/hyperledger/besu/evm/operation/PushOperation.java b/evm/src/main/java/org/hyperledger/besu/evm/operation/PushOperation.java index 006956207b3..0462fb9775e 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/operation/PushOperation.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/operation/PushOperation.java @@ -68,13 +68,21 @@ public OperationResult executeFixedCostOperation(final MessageFrame frame, final */ public static OperationResult staticOperation( final MessageFrame frame, final byte[] code, final int pc, final int pushSize) { - int copyStart = pc + 1; + final int copyStart = pc + 1; Bytes push; if (code.length <= copyStart) { push = Bytes.EMPTY; } else { final int copyLength = Math.min(pushSize, code.length - pc - 1); - push = Bytes.wrap(code, copyStart, copyLength); + final int rightPad = pushSize - copyLength; + if (rightPad == 0) { + push = Bytes.wrap(code, copyStart, copyLength); + } else { + // Right Pad the push with 0s up to pushSize if greater than the copyLength + var bytecodeLocal = new byte[pushSize]; + System.arraycopy(code, copyStart, bytecodeLocal, 0, copyLength); + push = Bytes.wrap(bytecodeLocal); + } } frame.pushStackItem(push); frame.setPC(pc + pushSize); diff --git a/evm/src/test/java/org/hyperledger/besu/evm/operation/PushOperationTest.java b/evm/src/test/java/org/hyperledger/besu/evm/operation/PushOperationTest.java new file mode 100644 index 00000000000..d303cc27d80 --- /dev/null +++ b/evm/src/test/java/org/hyperledger/besu/evm/operation/PushOperationTest.java @@ -0,0 +1,83 @@ +/* + * Copyright ConsenSys AG. + * + * 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.evm.operation; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hyperledger.besu.evm.operation.PushOperation.staticOperation; + +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.evm.code.CodeV0; +import org.hyperledger.besu.evm.frame.MessageFrame; +import org.hyperledger.besu.evm.toy.ToyBlockValues; +import org.hyperledger.besu.evm.toy.ToyWorld; + +import org.apache.tuweni.bytes.Bytes; +import org.apache.tuweni.bytes.Bytes32; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +public class PushOperationTest { + + private static final byte[] byteCode = new byte[] {0x00, 0x01, 0x02, 0x03}; + private static final MessageFrame frame = + MessageFrame.builder() + .worldUpdater(new ToyWorld()) + .originator(Address.ZERO) + .gasPrice(Wei.ONE) + .blobGasPrice(Wei.ONE) + .blockValues(new ToyBlockValues()) + .miningBeneficiary(Address.ZERO) + .blockHashLookup((l) -> Hash.ZERO) + .type(MessageFrame.Type.MESSAGE_CALL) + .initialGas(1) + .address(Address.ZERO) + .contract(Address.ZERO) + .inputData(Bytes32.ZERO) + .sender(Address.ZERO) + .value(Wei.ZERO) + .apparentValue(Wei.ZERO) + .code(CodeV0.EMPTY_CODE) + .completer(messageFrame -> {}) + .build(); + ; + + @Test + void unpaddedPushDoesntReachEndCode() { + staticOperation(frame, byteCode, 0, byteCode.length - 2); + assertThat(frame.getStackItem(0).equals(Bytes.fromHexString("0x0102"))).isTrue(); + } + + @Test + void unpaddedPushUpReachesEndCode() { + staticOperation(frame, byteCode, 0, byteCode.length - 1); + assertThat(frame.getStackItem(0).equals(Bytes.fromHexString("0x010203"))).isTrue(); + } + + @Test + void paddedPush() { + staticOperation(frame, byteCode, 1, byteCode.length - 1); + assertThat(frame.getStackItem(0).equals(Bytes.fromHexString("0x020300"))).isTrue(); + } + + @Test + void oobPush() { + staticOperation(frame, byteCode, byteCode.length, byteCode.length - 1); + assertThat(frame.getStackItem(0).equals(Bytes.EMPTY)).isTrue(); + } +} From 2054e12071bf0b3e10c6bb79634672dcddd1bb94 Mon Sep 17 00:00:00 2001 From: Vaidik Date: Tue, 5 Nov 2024 21:01:07 +0530 Subject: [PATCH 16/56] nonce as integer for preloaded contracts (#7850) * fixes #7749 Signed-off-by: vaidikcode * tests Signed-off-by: vaidikcode * spotless format fix Signed-off-by: vaidikcode --------- Co-authored-by: Sally MacFarlane Co-authored-by: Fabio Di Fabio --- .../hyperledger/besu/config/GenesisReader.java | 4 +++- .../besu/config/GenesisReaderTest.java | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/config/src/main/java/org/hyperledger/besu/config/GenesisReader.java b/config/src/main/java/org/hyperledger/besu/config/GenesisReader.java index 6b42c3c2edf..4ee99f0bd83 100644 --- a/config/src/main/java/org/hyperledger/besu/config/GenesisReader.java +++ b/config/src/main/java/org/hyperledger/besu/config/GenesisReader.java @@ -80,7 +80,9 @@ public Stream streamAllocations() { final var on = normalizeKeys((ObjectNode) entry.getValue()); return new GenesisAccount( Address.fromHexString(entry.getKey()), - JsonUtil.getString(on, "nonce").map(ParserUtils::parseUnsignedLong).orElse(0L), + JsonUtil.getValueAsString(on, "nonce") + .map(ParserUtils::parseUnsignedLong) + .orElse(0L), JsonUtil.getString(on, "balance") .map(ParserUtils::parseBalance) .orElse(Wei.ZERO), diff --git a/config/src/test/java/org/hyperledger/besu/config/GenesisReaderTest.java b/config/src/test/java/org/hyperledger/besu/config/GenesisReaderTest.java index f8327174a33..eab6dfac734 100644 --- a/config/src/test/java/org/hyperledger/besu/config/GenesisReaderTest.java +++ b/config/src/test/java/org/hyperledger/besu/config/GenesisReaderTest.java @@ -17,6 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.config.GenesisReader.ALLOCATION_FIELD; import static org.hyperledger.besu.config.GenesisReader.CONFIG_FIELD; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; @@ -27,6 +28,7 @@ import java.util.Map; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.fasterxml.jackson.databind.node.ObjectNode; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -111,4 +113,17 @@ private ObjectNode generateAllocation(final Wei balance) { entry.put("balance", balance.toShortHexString()); return entry; } + + @Test + void testNonceHandlingAsStringAndInteger() { + ObjectNode accountNode = JsonNodeFactory.instance.objectNode(); + + accountNode.put("nonce", 10); + String nonceAsStringFromInt = JsonUtil.getValueAsString(accountNode, "nonce").orElse(""); + assertEquals("10", nonceAsStringFromInt, "Nonce should convert integer to string correctly"); + + accountNode.put("nonce", "20"); + String nonceAsStringDirect = JsonUtil.getValueAsString(accountNode, "nonce").orElse(""); + assertEquals("20", nonceAsStringDirect, "Nonce should keep string as string correctly"); + } } From d73e815126c4cd3e5d8c054700db3f38a1180c99 Mon Sep 17 00:00:00 2001 From: Justin Florentine Date: Tue, 5 Nov 2024 10:56:07 -0500 Subject: [PATCH 17/56] calling the wrong create() method (#7857) Signed-off-by: jflo --- .../hyperledger/besu/controller/CliqueBesuControllerBuilder.java | 1 + 1 file changed, 1 insertion(+) diff --git a/besu/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java index 19840fb73da..edb55a11265 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java @@ -132,6 +132,7 @@ protected ProtocolSchedule createProtocolSchedule() { genesisConfigOptions, forksSchedule, nodeKey, + privacyParameters, isRevertReasonEnabled, evmConfiguration, miningConfiguration, From a585f1f2f79d1398f5970ccb7cf29f18e321eb55 Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Wed, 6 Nov 2024 07:04:54 +0100 Subject: [PATCH 18/56] Fully initialize MetricCategoryRegistry for acceptance tests (#7860) Signed-off-by: Fabio Di Fabio --- .../besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java index a76a3e6dcb5..fc2a7d372ea 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java @@ -494,6 +494,7 @@ public BesuPluginContextImpl providePluginContext( final RpcEndpointServiceImpl rpcEndpointServiceImpl, final BesuConfiguration commonPluginConfiguration, final PermissioningServiceImpl permissioningService, + final MetricsConfiguration metricsConfiguration, final MetricCategoryRegistryImpl metricCategoryRegistry, final MetricsSystem metricsSystem, final @Named("ExtraCLIOptions") List extraCLIOptions, @@ -512,6 +513,7 @@ public BesuPluginContextImpl providePluginContext( TransactionSimulationService.class, transactionSimulationServiceImpl); besuPluginContext.addService(BlockchainService.class, blockchainServiceImpl); besuPluginContext.addService(BesuConfiguration.class, commonPluginConfiguration); + metricCategoryRegistry.setMetricsConfiguration(metricsConfiguration); besuPluginContext.addService(MetricCategoryRegistry.class, metricCategoryRegistry); besuPluginContext.addService(MetricsSystem.class, metricsSystem); From 4099b3b32222de34754af7d2ffb0bf433434f4c7 Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Wed, 6 Nov 2024 09:14:07 +0100 Subject: [PATCH 19/56] Add more subprojects to BOM (#7859) Signed-off-by: Fabio Di Fabio --- platform/build.gradle | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/platform/build.gradle b/platform/build.gradle index 5b02eb0beeb..d614603f17f 100644 --- a/platform/build.gradle +++ b/platform/build.gradle @@ -43,8 +43,14 @@ dependencies { api project(':acceptance-tests:dsl') api project(':besu') api project(':config') + api project(':consensus:clique') + api project(':consensus:common') + api project(':consensus:ibft') + api project(':consensus:merge') + api project(':consensus:qbft') api project(':crypto:algorithms') api project(':crypto:services') + api project(':datatypes') api project(':ethereum:api') api project(':ethereum:blockcreation') api project(':ethereum:core') @@ -53,9 +59,12 @@ dependencies { api project(':ethereum:permissioning') api project(':ethereum:referencetests') api project(':ethereum:rlp') + api project(':ethereum:trie') api project(':evm') - api project(':datatypes') + api project(':metrics:core') api project(':plugin-api') + api project(':testutil') + api project(':util') api 'com.github.ben-manes.caffeine:caffeine:3.1.8' From deb3fa2727c6924c60374c889031ccdff0028e7a Mon Sep 17 00:00:00 2001 From: Justin Florentine Date: Wed, 6 Nov 2024 14:55:57 -0500 Subject: [PATCH 20/56] adds action to manage stale issues (#7864) Signed-off-by: jflo --- .github/workflows/stale-issues.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/stale-issues.yml diff --git a/.github/workflows/stale-issues.yml b/.github/workflows/stale-issues.yml new file mode 100644 index 00000000000..fe45d91b49f --- /dev/null +++ b/.github/workflows/stale-issues.yml @@ -0,0 +1,27 @@ +name: Close inactive issues +on: + schedule: + - cron: "30 1 * * *" + +jobs: + close-issues: + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + contents: write + steps: + - uses: actions/stale@v5 + with: + days-before-issue-stale: 180 + days-before-issue-close: 14 + stale-issue-label: "stale" + stale-issue-message: "This issue is stale because it has been open for 6 months with no activity." + close-issue-message: "This issue was closed because it has been inactive for 14 days since being marked as stale." + days-before-pr-stale: 30 + days-before-pr-close: 14 + stale-pr-message: "This pr is stale because it has been open for 30 days with no activity." + close-pr-message: "This pr was closed because it has been inactive for 14 days since being marked as stale." + remove-issue-stale-when-updated: true + remove-pr-stale-when-updated: true + repo-token: ${{ secrets.GITHUB_TOKEN }} From 3ebf50ea0ba75e8fc9fee285d4992285992f3442 Mon Sep 17 00:00:00 2001 From: wangjingcun Date: Fri, 8 Nov 2024 17:00:29 +0800 Subject: [PATCH 21/56] chore: fix some typos in comments (#7866) Signed-off-by: wangjingcun --- .../besu/tests/acceptance/plugins/TestMetricsPlugin.java | 2 +- .../rocksdb/segmented/RocksDBColumnarKeyValueStorageTest.java | 2 +- .../java/org/hyperledger/besu/testfuzz/javafuzz/FuzzTarget.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestMetricsPlugin.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestMetricsPlugin.java index 7e1ac2ccdec..af179c57cfe 100644 --- a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestMetricsPlugin.java +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestMetricsPlugin.java @@ -51,7 +51,7 @@ public void start() { .createGauge( TestMetricCategory.TEST_METRIC_CATEGORY, "test_metric", - "Returns 1 on succes", + "Returns 1 on success", () -> 1.0); } diff --git a/plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBColumnarKeyValueStorageTest.java b/plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBColumnarKeyValueStorageTest.java index e28828c396e..4800e82abcd 100644 --- a/plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBColumnarKeyValueStorageTest.java +++ b/plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBColumnarKeyValueStorageTest.java @@ -264,7 +264,7 @@ public void dbWillBeBackwardIncompatibleAfterExperimentalSegmentsAreAdded( List.of()); store.close(); - // Create new db without ignoring experimental colum family will add column to db + // Create new db without ignoring experimental column family will add column to db store = createSegmentedStore( testPath, diff --git a/testfuzz/src/main/java/org/hyperledger/besu/testfuzz/javafuzz/FuzzTarget.java b/testfuzz/src/main/java/org/hyperledger/besu/testfuzz/javafuzz/FuzzTarget.java index 26f3522e116..bee6bca7769 100644 --- a/testfuzz/src/main/java/org/hyperledger/besu/testfuzz/javafuzz/FuzzTarget.java +++ b/testfuzz/src/main/java/org/hyperledger/besu/testfuzz/javafuzz/FuzzTarget.java @@ -25,7 +25,7 @@ public interface FuzzTarget { /** * The target to fuzz * - * @param data data proviced by the fuzzer + * @param data data provided by the fuzzer */ void fuzz(byte[] data); } From e17ebc5e8d8e0f032c6871ad5fc4144524d190cb Mon Sep 17 00:00:00 2001 From: Bhanu Pulluri <59369753+pullurib@users.noreply.github.com> Date: Fri, 8 Nov 2024 05:08:11 -0500 Subject: [PATCH 22/56] Add TLS/mTLS options for websockets (#7854) * Fix incorrect duration for THREE_MINUTES from 1 minute to 3 minutes Signed-off-by: Bhanu Pulluri * Add options to enable TLS/mTLS for websocket connections Signed-off-by: Bhanu Pulluri * Revert an irrelevant change Signed-off-by: Bhanu Pulluri * Update tests, options and option dependencies Signed-off-by: Bhanu Pulluri * Fix CHANGELOG entry Signed-off-by: Bhanu Pulluri * Fix CHANGELOG entry Signed-off-by: Bhanu Pulluri --------- Signed-off-by: Bhanu Pulluri Co-authored-by: Bhanu Pulluri Co-authored-by: Fabio Di Fabio --- CHANGELOG.md | 1 + .../besu/cli/options/RpcWebsocketOptions.java | 133 +++++- .../src/test/resources/everything_config.toml | 13 + .../websocket/WebSocketConfiguration.java | 112 +++++ .../jsonrpc/websocket/WebSocketService.java | 72 ++- .../websocket/WebSocketServiceTLSTest.java | 444 ++++++++++++++++++ 6 files changed, 764 insertions(+), 11 deletions(-) create mode 100644 ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketServiceTLSTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 41aea176def..b78adf6e068 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ### Additions and Improvements - Fine tune already seen txs tracker when a tx is removed from the pool [#7755](https://github.com/hyperledger/besu/pull/7755) +- Support for enabling and configuring TLS/mTLS in WebSocket service. [#7854](https://github.com/hyperledger/besu/pull/7854) - Create and publish Besu BOM (Bill of Materials) [#7615](https://github.com/hyperledger/besu/pull/7615) - Update Java dependencies [#7786](https://github.com/hyperledger/besu/pull/7786) - Add a method to get all the transaction in the pool, to the `TransactionPoolService`, to easily access the transaction pool content from plugins [#7813](https://github.com/hyperledger/besu/pull/7813) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/RpcWebsocketOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/RpcWebsocketOptions.java index d596d4183c7..2dde517ccc7 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/RpcWebsocketOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/RpcWebsocketOptions.java @@ -120,6 +120,71 @@ public class RpcWebsocketOptions { arity = "1") private final File rpcWsAuthenticationPublicKeyFile = null; + @CommandLine.Option( + names = {"--rpc-ws-ssl-enabled"}, + description = "Enable SSL/TLS for the WebSocket RPC service") + private final Boolean isRpcWsSslEnabled = false; + + @CommandLine.Option( + names = {"--rpc-ws-ssl-keystore-file"}, + paramLabel = DefaultCommandValues.MANDATORY_FILE_FORMAT_HELP, + description = "Path to the keystore file for the WebSocket RPC service") + private String rpcWsKeyStoreFile = null; + + @CommandLine.Option( + names = {"--rpc-ws-ssl-keystore-password"}, + paramLabel = "", + description = "Password for the WebSocket RPC keystore file") + private String rpcWsKeyStorePassword = null; + + @CommandLine.Option( + names = {"--rpc-ws-ssl-key-file"}, + paramLabel = DefaultCommandValues.MANDATORY_FILE_FORMAT_HELP, + description = "Path to the PEM key file for the WebSocket RPC service") + private String rpcWsKeyFile = null; + + @CommandLine.Option( + names = {"--rpc-ws-ssl-cert-file"}, + paramLabel = DefaultCommandValues.MANDATORY_FILE_FORMAT_HELP, + description = "Path to the PEM cert file for the WebSocket RPC service") + private String rpcWsCertFile = null; + + @CommandLine.Option( + names = {"--rpc-ws-ssl-keystore-type"}, + paramLabel = "", + description = "Type of the WebSocket RPC keystore (JKS, PKCS12, PEM)") + private String rpcWsKeyStoreType = null; + + // For client authentication (mTLS) + @CommandLine.Option( + names = {"--rpc-ws-ssl-client-auth-enabled"}, + description = "Enable client authentication for the WebSocket RPC service") + private final Boolean isRpcWsClientAuthEnabled = false; + + @CommandLine.Option( + names = {"--rpc-ws-ssl-truststore-file"}, + paramLabel = DefaultCommandValues.MANDATORY_FILE_FORMAT_HELP, + description = "Path to the truststore file for the WebSocket RPC service") + private String rpcWsTrustStoreFile = null; + + @CommandLine.Option( + names = {"--rpc-ws-ssl-truststore-password"}, + paramLabel = "", + description = "Password for the WebSocket RPC truststore file") + private String rpcWsTrustStorePassword = null; + + @CommandLine.Option( + names = {"--rpc-ws-ssl-trustcert-file"}, + paramLabel = DefaultCommandValues.MANDATORY_FILE_FORMAT_HELP, + description = "Path to the PEM trustcert file for the WebSocket RPC service") + private String rpcWsTrustCertFile = null; + + @CommandLine.Option( + names = {"--rpc-ws-ssl-truststore-type"}, + paramLabel = "", + description = "Type of the truststore (JKS, PKCS12, PEM)") + private String rpcWsTrustStoreType = null; + /** Default Constructor. */ public RpcWebsocketOptions() {} @@ -184,7 +249,61 @@ private void checkOptionDependencies(final Logger logger, final CommandLine comm "--rpc-ws-authentication-enabled", "--rpc-ws-authentication-credentials-file", "--rpc-ws-authentication-public-key-file", - "--rpc-ws-authentication-jwt-algorithm")); + "--rpc-ws-authentication-jwt-algorithm", + "--rpc-ws-ssl-enabled")); + + CommandLineUtils.checkOptionDependencies( + logger, + commandLine, + "--rpc-ws-ssl-enabled", + !isRpcWsSslEnabled, + List.of( + "--rpc-ws-ssl-keystore-file", + "--rpc-ws-ssl-keystore-type", + "--rpc-ws-ssl-client-auth-enabled")); + + CommandLineUtils.checkOptionDependencies( + logger, + commandLine, + "--rpc-ws-ssl-client-auth-enabled", + !isRpcWsClientAuthEnabled, + List.of( + "--rpc-ws-ssl-truststore-file", + "--rpc-ws-ssl-truststore-type", + "--rpc-ws-ssl-trustcert-file")); + + if (isRpcWsSslEnabled) { + if ("PEM".equalsIgnoreCase(rpcWsKeyStoreType)) { + CommandLineUtils.checkOptionDependencies( + logger, + commandLine, + "--rpc-ws-ssl-key-file", + rpcWsKeyFile == null, + List.of("--rpc-ws-ssl-cert-file")); + CommandLineUtils.checkOptionDependencies( + logger, + commandLine, + "--rpc-ws-ssl-cert-file", + rpcWsCertFile == null, + List.of("--rpc-ws-ssl-key-file")); + } else { + CommandLineUtils.checkOptionDependencies( + logger, + commandLine, + "--rpc-ws-ssl-keystore-file", + rpcWsKeyStoreFile == null, + List.of("--rpc-ws-ssl-keystore-password")); + } + } + + if (isRpcWsClientAuthEnabled && !"PEM".equalsIgnoreCase(rpcWsTrustStoreType)) { + CommandLineUtils.checkOptionDependencies( + logger, + commandLine, + "--rpc-ws-ssl-truststore-file", + rpcWsTrustStoreFile == null, + List.of("--rpc-ws-ssl-truststore-password")); + } if (isRpcWsAuthenticationEnabled) { CommandLineUtils.checkOptionDependencies( @@ -222,6 +341,18 @@ public WebSocketConfiguration webSocketConfiguration( webSocketConfiguration.setAuthenticationPublicKeyFile(rpcWsAuthenticationPublicKeyFile); webSocketConfiguration.setAuthenticationAlgorithm(rpcWebsocketsAuthenticationAlgorithm); webSocketConfiguration.setTimeoutSec(wsTimoutSec); + webSocketConfiguration.setSslEnabled(isRpcWsSslEnabled); + webSocketConfiguration.setKeyStorePath(rpcWsKeyStoreFile); + webSocketConfiguration.setKeyStorePassword(rpcWsKeyStorePassword); + webSocketConfiguration.setKeyStoreType(rpcWsKeyStoreType); + webSocketConfiguration.setClientAuthEnabled(isRpcWsClientAuthEnabled); + webSocketConfiguration.setTrustStorePath(rpcWsTrustStoreFile); + webSocketConfiguration.setTrustStorePassword(rpcWsTrustStorePassword); + webSocketConfiguration.setTrustStoreType(rpcWsTrustStoreType); + webSocketConfiguration.setKeyPath(rpcWsKeyFile); + webSocketConfiguration.setCertPath(rpcWsCertFile); + webSocketConfiguration.setTrustCertPath(rpcWsTrustCertFile); + return webSocketConfiguration; } diff --git a/besu/src/test/resources/everything_config.toml b/besu/src/test/resources/everything_config.toml index e89442f7f78..960b2b5772c 100644 --- a/besu/src/test/resources/everything_config.toml +++ b/besu/src/test/resources/everything_config.toml @@ -120,6 +120,19 @@ rpc-ws-max-frame-size=65535 rpc-ws-authentication-enabled=false rpc-ws-authentication-credentials-file="none" rpc-ws-authentication-jwt-public-key-file="none" +rpc-ws-ssl-enabled=false +rpc-ws-ssl-keystore-file="none.pfx" +rpc-ws-ssl-keystore-password="none.passwd" +rpc-ws-ssl-keystore-type="none" +rpc-ws-ssl-client-auth-enabled=false +rpc-ws-ssl-truststore-file="none.pfx" +rpc-ws-ssl-truststore-password="none.passwd" +rpc-ws-ssl-truststore-type="none" +rpc-ws-ssl-key-file="none.pfx" +rpc-ws-ssl-cert-file="none.pfx" +rpc-ws-ssl-trustcert-file="none.pfx" + + # API api-gas-price-blocks=100 diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketConfiguration.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketConfiguration.java index e27f7f21cec..42905b96a70 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketConfiguration.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketConfiguration.java @@ -25,6 +25,7 @@ import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.Optional; import com.google.common.base.MoreObjects; @@ -49,6 +50,21 @@ public class WebSocketConfiguration { private int maxActiveConnections; private int maxFrameSize; + private boolean isSslEnabled = false; + private Optional keyStorePath = Optional.empty(); + private Optional keyStorePassword = Optional.empty(); + private Optional keyStoreType = Optional.of("JKS"); // Default to JKS + + private boolean clientAuthEnabled = false; + private Optional trustStorePath = Optional.empty(); + private Optional trustStorePassword = Optional.empty(); + private Optional trustStoreType = Optional.of("JKS"); // Default to JKS + + // For PEM format + private Optional keyPath = Optional.empty(); + private Optional certPath = Optional.empty(); + private Optional trustCertPath = Optional.empty(); + public static WebSocketConfiguration createDefault() { final WebSocketConfiguration config = new WebSocketConfiguration(); config.setEnabled(false); @@ -159,6 +175,102 @@ public void setTimeoutSec(final long timeoutSec) { this.timeoutSec = timeoutSec; } + public boolean isSslEnabled() { + return isSslEnabled; + } + + public void setSslEnabled(final boolean isSslEnabled) { + this.isSslEnabled = isSslEnabled; + } + + public Optional getKeyStorePath() { + return keyStorePath; + } + + public void setKeyStorePath(final String keyStorePath) { + this.keyStorePath = Optional.ofNullable(keyStorePath); + } + + public Optional getKeyStorePassword() { + return keyStorePassword; + } + + public void setKeyStorePassword(final String keyStorePassword) { + this.keyStorePassword = Optional.ofNullable(keyStorePassword); + } + + // Keystore Type + public Optional getKeyStoreType() { + return keyStoreType; + } + + public void setKeyStoreType(final String keyStoreType) { + this.keyStoreType = Optional.ofNullable(keyStoreType); + } + + // Key Path (for PEM) + public Optional getKeyPath() { + return keyPath; + } + + public void setKeyPath(final String keyPath) { + this.keyPath = Optional.ofNullable(keyPath); + } + + // Cert Path (for PEM) + public Optional getCertPath() { + return certPath; + } + + public void setCertPath(final String certPath) { + this.certPath = Optional.ofNullable(certPath); + } + + // Client Authentication Enabled + public boolean isClientAuthEnabled() { + return clientAuthEnabled; + } + + public void setClientAuthEnabled(final boolean clientAuthEnabled) { + this.clientAuthEnabled = clientAuthEnabled; + } + + // Truststore Path + public Optional getTrustStorePath() { + return trustStorePath; + } + + public void setTrustStorePath(final String trustStorePath) { + this.trustStorePath = Optional.ofNullable(trustStorePath); + } + + // Truststore Password + public Optional getTrustStorePassword() { + return trustStorePassword; + } + + public void setTrustStorePassword(final String trustStorePassword) { + this.trustStorePassword = Optional.ofNullable(trustStorePassword); + } + + // Truststore Type + public Optional getTrustStoreType() { + return trustStoreType; + } + + public void setTrustStoreType(final String trustStoreType) { + this.trustStoreType = Optional.ofNullable(trustStoreType); + } + + // Trust Cert Path (for PEM) + public Optional getTrustCertPath() { + return trustCertPath; + } + + public void setTrustCertPath(final String trustCertPath) { + this.trustCertPath = Optional.ofNullable(trustCertPath); + } + @Override public boolean equals(final Object o) { if (this == o) { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketService.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketService.java index 59742836ba8..31c86b18d21 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketService.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketService.java @@ -25,6 +25,7 @@ import org.hyperledger.besu.plugin.services.MetricsSystem; import java.net.InetSocketAddress; +import java.util.Locale; import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicInteger; @@ -34,6 +35,7 @@ import io.vertx.core.Handler; import io.vertx.core.Vertx; import io.vertx.core.buffer.Buffer; +import io.vertx.core.http.ClientAuth; import io.vertx.core.http.HttpConnection; import io.vertx.core.http.HttpServer; import io.vertx.core.http.HttpServerOptions; @@ -41,6 +43,9 @@ import io.vertx.core.http.HttpServerResponse; import io.vertx.core.http.ServerWebSocket; import io.vertx.core.net.HostAndPort; +import io.vertx.core.net.JksOptions; +import io.vertx.core.net.PemKeyCertOptions; +import io.vertx.core.net.PemTrustOptions; import io.vertx.core.net.SocketAddress; import io.vertx.ext.web.Router; import io.vertx.ext.web.RoutingContext; @@ -103,18 +108,65 @@ public CompletableFuture start() { "Starting Websocket service on {}:{}", configuration.getHost(), configuration.getPort()); final CompletableFuture resultFuture = new CompletableFuture<>(); + HttpServerOptions serverOptions = + new HttpServerOptions() + .setHost(configuration.getHost()) + .setPort(configuration.getPort()) + .setHandle100ContinueAutomatically(true) + .setCompressionSupported(true) + .addWebSocketSubProtocol("undefined") + .setMaxWebSocketFrameSize(configuration.getMaxFrameSize()) + .setMaxWebSocketMessageSize(configuration.getMaxFrameSize() * 4) + .setRegisterWebSocketWriteHandlers(true); + + // Check if SSL/TLS is enabled in the configuration + if (configuration.isSslEnabled()) { + serverOptions.setSsl(true); + + String keystorePath = configuration.getKeyStorePath().orElse(null); + String keystorePassword = configuration.getKeyStorePassword().orElse(null); + String keyPath = configuration.getKeyPath().orElse(null); + String certPath = configuration.getCertPath().orElse(null); + + String keystoreType = configuration.getKeyStoreType().orElse("JKS"); + + switch (keystoreType.toUpperCase(Locale.getDefault())) { + case "PEM": + serverOptions.setKeyCertOptions( + new PemKeyCertOptions().setKeyPath(keyPath).setCertPath(certPath)); + break; + case "JKS": + default: + serverOptions.setKeyCertOptions( + new JksOptions().setPath(keystorePath).setPassword(keystorePassword)); + break; + } + } + + // Set up truststore for client authentication (mTLS) + if (configuration.isClientAuthEnabled()) { + serverOptions.setClientAuth(ClientAuth.REQUIRED); + + String truststorePath = configuration.getTrustStorePath().orElse(null); + String truststorePassword = configuration.getTrustStorePassword().orElse(""); + String truststoreType = configuration.getTrustStoreType().orElse("JKS"); + String trustCertPath = configuration.getTrustCertPath().orElse(null); + + switch (truststoreType.toUpperCase(Locale.getDefault())) { + case "PEM": + serverOptions.setTrustOptions(new PemTrustOptions().addCertPath(trustCertPath)); + break; + case "JKS": + default: + serverOptions.setTrustOptions( + new JksOptions().setPath(truststorePath).setPassword(truststorePassword)); + break; + } + } + httpServer = vertx - .createHttpServer( - new HttpServerOptions() - .setHost(configuration.getHost()) - .setPort(configuration.getPort()) - .setHandle100ContinueAutomatically(true) - .setCompressionSupported(true) - .addWebSocketSubProtocol("undefined") - .setMaxWebSocketFrameSize(configuration.getMaxFrameSize()) - .setMaxWebSocketMessageSize(configuration.getMaxFrameSize() * 4) - .setRegisterWebSocketWriteHandlers(true)) + .createHttpServer(serverOptions) .webSocketHandler(websocketHandler()) .connectionHandler(connectionHandler()) .requestHandler(httpHandler()) diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketServiceTLSTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketServiceTLSTest.java new file mode 100644 index 00000000000..9a227dc4326 --- /dev/null +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketServiceTLSTest.java @@ -0,0 +1,444 @@ +/* + * Copyright contributors to 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.ethereum.api.jsonrpc.websocket; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; + +import org.hyperledger.besu.ethereum.api.handlers.TimeoutOptions; +import org.hyperledger.besu.ethereum.api.jsonrpc.execution.BaseJsonRpcProcessor; +import org.hyperledger.besu.ethereum.api.jsonrpc.execution.JsonRpcExecutor; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; +import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.methods.WebSocketMethodsFactory; +import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.SubscriptionManager; +import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; +import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; + +import java.io.File; +import java.io.FileOutputStream; +import java.security.KeyStore; +import java.util.Base64; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import io.netty.handler.ssl.util.SelfSignedCertificate; +import io.vertx.core.Vertx; +import io.vertx.core.http.WebSocketClient; +import io.vertx.core.http.WebSocketClientOptions; +import io.vertx.core.net.JksOptions; +import io.vertx.core.net.PemTrustOptions; +import io.vertx.junit5.VertxExtension; +import io.vertx.junit5.VertxTestContext; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +@ExtendWith(VertxExtension.class) +public class WebSocketServiceTLSTest { + + private Vertx vertx; + private WebSocketConfiguration config; + private WebSocketMessageHandler webSocketMessageHandlerSpy; + + @BeforeEach + public void setUp() { + vertx = Vertx.vertx(); + config = WebSocketConfiguration.createDefault(); + Map websocketMethods; + config.setPort(0); // Use ephemeral port + config.setHost("localhost"); + websocketMethods = + new WebSocketMethodsFactory( + new SubscriptionManager(new NoOpMetricsSystem()), new HashMap<>()) + .methods(); + webSocketMessageHandlerSpy = + spy( + new WebSocketMessageHandler( + vertx, + new JsonRpcExecutor(new BaseJsonRpcProcessor(), websocketMethods), + mock(EthScheduler.class), + TimeoutOptions.defaultOptions().getTimeoutSeconds())); + } + + @Test + public void shouldAcceptSecureWebSocketConnection(final VertxTestContext testContext) + throws Throwable { + // Generate a self-signed certificate + SelfSignedCertificate ssc = new SelfSignedCertificate(); + + // Create a temporary keystore file + File keystoreFile = File.createTempFile("keystore", ".jks"); + keystoreFile.deleteOnExit(); + + // Create a PKCS12 keystore and load the self-signed certificate + KeyStore keyStore = KeyStore.getInstance("JKS"); + keyStore.load(null, null); + keyStore.setKeyEntry( + "alias", + ssc.key(), + "password".toCharArray(), + new java.security.cert.Certificate[] {ssc.cert()}); + + // Save the keystore to the temporary file + try (FileOutputStream fos = new FileOutputStream(keystoreFile)) { + keyStore.store(fos, "password".toCharArray()); + } + + // Configure WebSocket with SSL enabled + config.setSslEnabled(true); + config.setKeyStorePath(keystoreFile.getAbsolutePath()); + config.setKeyStorePassword("password"); + config.setKeyStoreType("JKS"); + + // Create and start WebSocketService + WebSocketService webSocketService = + new WebSocketService(vertx, config, webSocketMessageHandlerSpy, new NoOpMetricsSystem()); + webSocketService.start().join(); + + // Get the actual port + int port = webSocketService.socketAddress().getPort(); + + // Create a temporary truststore file + File truststoreFile = File.createTempFile("truststore", ".jks"); + truststoreFile.deleteOnExit(); + + // Create a PKCS12 truststore and load the server's certificate + KeyStore trustStore = KeyStore.getInstance("JKS"); + trustStore.load(null, null); + trustStore.setCertificateEntry("alias", ssc.cert()); + + // Save the truststore to the temporary file + try (FileOutputStream fos = new FileOutputStream(truststoreFile)) { + trustStore.store(fos, "password".toCharArray()); + } + + // Configure the HTTP client with the truststore + WebSocketClientOptions clientOptions = + new WebSocketClientOptions() + .setSsl(true) + .setTrustOptions( + new JksOptions().setPath(truststoreFile.getAbsolutePath()).setPassword("password")) + .setVerifyHost(true); + + WebSocketClient webSocketClient = vertx.createWebSocketClient(clientOptions); + webSocketClient + .connect(port, "localhost", "/") + .onSuccess( + ws -> { + assertThat(ws.isSsl()).isTrue(); + ws.close(); + testContext.completeNow(); + }) + .onFailure(testContext::failNow); + + assertThat(testContext.awaitCompletion(5, TimeUnit.SECONDS)).isTrue(); + if (testContext.failed()) { + throw testContext.causeOfFailure(); + } + + // Stop the WebSocketService after the test + webSocketService.stop().join(); + } + + @Test + public void shouldAcceptSecureWebSocketConnectionPEM(final VertxTestContext testContext) + throws Throwable { + // Generate a self-signed certificate + SelfSignedCertificate ssc = new SelfSignedCertificate(); + + // Create temporary PEM files for the certificate and key + File certFile = File.createTempFile("cert", ".pem"); + certFile.deleteOnExit(); + File keyFile = File.createTempFile("key", ".pem"); + keyFile.deleteOnExit(); + + // Write the certificate and key to the PEM files + try (FileOutputStream certOut = new FileOutputStream(certFile); + FileOutputStream keyOut = new FileOutputStream(keyFile)) { + certOut.write("-----BEGIN CERTIFICATE-----\n".getBytes(UTF_8)); + certOut.write( + Base64.getMimeEncoder(64, "\n".getBytes(UTF_8)).encode(ssc.cert().getEncoded())); + certOut.write("\n-----END CERTIFICATE-----\n".getBytes(UTF_8)); + + keyOut.write("-----BEGIN PRIVATE KEY-----\n".getBytes(UTF_8)); + keyOut.write(Base64.getMimeEncoder(64, "\n".getBytes(UTF_8)).encode(ssc.key().getEncoded())); + keyOut.write("\n-----END PRIVATE KEY-----\n".getBytes(UTF_8)); + } + + // Configure WebSocket with SSL enabled using PEM files + config.setSslEnabled(true); + config.setKeyPath(keyFile.getAbsolutePath()); + config.setCertPath(certFile.getAbsolutePath()); + config.setKeyStoreType("PEM"); + + // Create and start WebSocketService + WebSocketService webSocketService = + new WebSocketService(vertx, config, webSocketMessageHandlerSpy, new NoOpMetricsSystem()); + webSocketService.start().join(); + + // Get the actual port + int port = webSocketService.socketAddress().getPort(); + + // Create a temporary PEM file for the trust store + File trustCertFile = File.createTempFile("trust-cert", ".pem"); + trustCertFile.deleteOnExit(); + + // Write the server's certificate to the PEM file + try (FileOutputStream trustCertOut = new FileOutputStream(trustCertFile)) { + trustCertOut.write("-----BEGIN CERTIFICATE-----\n".getBytes(UTF_8)); + trustCertOut.write( + Base64.getMimeEncoder(64, "\n".getBytes(UTF_8)).encode(ssc.cert().getEncoded())); + trustCertOut.write("\n-----END CERTIFICATE-----\n".getBytes(UTF_8)); + } + + // Configure the HTTP client with the trust store using PEM files + WebSocketClientOptions clientOptions = + new WebSocketClientOptions() + .setSsl(true) + .setTrustOptions(new PemTrustOptions().addCertPath(trustCertFile.getAbsolutePath())) + .setVerifyHost(true); + + WebSocketClient webSocketClient = vertx.createWebSocketClient(clientOptions); + webSocketClient + .connect(port, "localhost", "/") + .onSuccess( + ws -> { + assertThat(ws.isSsl()).isTrue(); + ws.close(); + testContext.completeNow(); + }) + .onFailure(testContext::failNow); + + assertThat(testContext.awaitCompletion(5, TimeUnit.SECONDS)).isTrue(); + if (testContext.failed()) { + throw testContext.causeOfFailure(); + } + + // Stop the WebSocketService after the test + webSocketService.stop().join(); + } + + @Test + public void shouldFailConnectionWithWrongCertificateInTrustStore( + final VertxTestContext testContext) throws Throwable { + // Generate a self-signed certificate for the server + SelfSignedCertificate serverCert = new SelfSignedCertificate(); + + // Create a temporary keystore file for the server + File keystoreFile = File.createTempFile("keystore", ".p12"); + keystoreFile.deleteOnExit(); + + // Create a PKCS12 keystore and load the server's self-signed certificate + KeyStore keyStore = KeyStore.getInstance("PKCS12"); + keyStore.load(null, null); + keyStore.setKeyEntry( + "alias", + serverCert.key(), + "password".toCharArray(), + new java.security.cert.Certificate[] {serverCert.cert()}); + + // Save the keystore to the temporary file + try (FileOutputStream fos = new FileOutputStream(keystoreFile)) { + keyStore.store(fos, "password".toCharArray()); + } + + // Configure WebSocket with SSL enabled + config.setSslEnabled(true); + config.setKeyStorePath(keystoreFile.getAbsolutePath()); + config.setKeyStorePassword("password"); + config.setKeyStoreType("PKCS12"); + + // Create and start WebSocketService + WebSocketService webSocketService = + new WebSocketService(vertx, config, webSocketMessageHandlerSpy, new NoOpMetricsSystem()); + webSocketService.start().join(); + + // Get the actual port + int port = webSocketService.socketAddress().getPort(); + + // Generate a different self-signed certificate for the trust store + SelfSignedCertificate wrongCert = new SelfSignedCertificate(); + + // Create a temporary truststore file + File truststoreFile = File.createTempFile("truststore", ".p12"); + truststoreFile.deleteOnExit(); + + // Create a PKCS12 truststore and load the wrong certificate + KeyStore trustStore = KeyStore.getInstance("PKCS12"); + trustStore.load(null, null); + trustStore.setCertificateEntry("alias", wrongCert.cert()); + + // Save the truststore to the temporary file + try (FileOutputStream fos = new FileOutputStream(truststoreFile)) { + trustStore.store(fos, "password".toCharArray()); + } + + // Configure the HTTP client with the truststore containing the wrong certificate + WebSocketClientOptions clientOptions = + new WebSocketClientOptions() + .setSsl(true) + .setTrustOptions( + new JksOptions().setPath(truststoreFile.getAbsolutePath()).setPassword("password")) + .setVerifyHost(true); + + WebSocketClient webSocketClient = vertx.createWebSocketClient(clientOptions); + webSocketClient + .connect(port, "localhost", "/") + .onSuccess( + ws -> { + testContext.failNow(new AssertionError("Connection should have been rejected")); + }) + .onFailure( + throwable -> { + assertThat(throwable).isInstanceOf(Exception.class); + testContext.completeNow(); + }); + + assertThat(testContext.awaitCompletion(5, TimeUnit.SECONDS)).isTrue(); + if (testContext.failed()) { + throw testContext.causeOfFailure(); + } + + // Stop the WebSocketService after the test + webSocketService.stop().join(); + } + + @Test + public void shouldAuthenticateClient(final VertxTestContext testContext) throws Throwable { + // Generate a self-signed certificate for the server + SelfSignedCertificate serverCert = new SelfSignedCertificate(); + + // Generate a self-signed certificate for the client + SelfSignedCertificate clientCert = new SelfSignedCertificate(); + + // Create a temporary keystore file for the server + File serverKeystoreFile = File.createTempFile("keystore", ".p12"); + serverKeystoreFile.deleteOnExit(); + + // Create a temporary truststore file for the server + File serverTruststoreFile = File.createTempFile("truststore", ".p12"); + serverTruststoreFile.deleteOnExit(); + + // Create a temporary keystore file for the client + File clientKeystoreFile = File.createTempFile("client-keystore", ".p12"); + clientKeystoreFile.deleteOnExit(); + + // Create a temporary truststore file for the client + File clientTruststoreFile = File.createTempFile("truststore", ".p12"); + clientTruststoreFile.deleteOnExit(); + + // Create a PKCS12 keystore and load the server's self-signed certificate + KeyStore serverKeyStore = KeyStore.getInstance("PKCS12"); + serverKeyStore.load(null, null); + serverKeyStore.setKeyEntry( + "alias", + serverCert.key(), + "password".toCharArray(), + new java.security.cert.Certificate[] {serverCert.cert()}); + + // Save the keystore to the temporary file + try (FileOutputStream fos = new FileOutputStream(serverKeystoreFile)) { + serverKeyStore.store(fos, "password".toCharArray()); + } + + // Create a PKCS12 truststore and load the client's self-signed certificate + KeyStore serverTrustStore = KeyStore.getInstance("PKCS12"); + serverTrustStore.load(null, null); + serverTrustStore.setCertificateEntry("alias", clientCert.cert()); + + // Save the truststore to the temporary file + try (FileOutputStream fos = new FileOutputStream(serverTruststoreFile)) { + serverTrustStore.store(fos, "password".toCharArray()); + } + + // Create a PKCS12 keystore and load the client's self-signed certificate + KeyStore clientKeyStore = KeyStore.getInstance("PKCS12"); + clientKeyStore.load(null, null); + clientKeyStore.setKeyEntry( + "alias", + clientCert.key(), + "password".toCharArray(), + new java.security.cert.Certificate[] {clientCert.cert()}); + + // Save the client keystore to the temporary file + try (FileOutputStream fos = new FileOutputStream(clientKeystoreFile)) { + clientKeyStore.store(fos, "password".toCharArray()); + } + + // Create a PKCS12 truststore and load the server's self-signed certificate + KeyStore clientTrustStore = KeyStore.getInstance("PKCS12"); + clientTrustStore.load(null, null); + clientTrustStore.setCertificateEntry("alias", serverCert.cert()); + + // Save the truststore to the temporary file + try (FileOutputStream fos = new FileOutputStream(clientTruststoreFile)) { + clientTrustStore.store(fos, "password".toCharArray()); + } + + // Configure WebSocket with SSL and client authentication enabled + config.setSslEnabled(true); + config.setKeyStorePath(serverKeystoreFile.getAbsolutePath()); + config.setKeyStorePassword("password"); + config.setKeyStoreType("PKCS12"); + config.setClientAuthEnabled(true); + config.setTrustStorePath(serverTruststoreFile.getAbsolutePath()); + config.setTrustStorePassword("password"); + config.setTrustStoreType("PKCS12"); + + // Create and start WebSocketService + WebSocketService webSocketService = + new WebSocketService(vertx, config, webSocketMessageHandlerSpy, new NoOpMetricsSystem()); + webSocketService.start().join(); + + // Get the actual port + int port = webSocketService.socketAddress().getPort(); + + // Configure the HTTP client with the client certificate + WebSocketClientOptions clientOptions = + new WebSocketClientOptions() + .setSsl(true) + .setKeyStoreOptions( + new JksOptions() + .setPath(clientKeystoreFile.getAbsolutePath()) + .setPassword("password")) + .setTrustOptions( + new JksOptions() + .setPath(clientTruststoreFile.getAbsolutePath()) + .setPassword("password")) + .setVerifyHost(true); + + WebSocketClient webSocketClient = vertx.createWebSocketClient(clientOptions); + webSocketClient + .connect(port, "localhost", "/") + .onSuccess( + ws -> { + assertThat(ws.isSsl()).isTrue(); + ws.close(); + testContext.completeNow(); + }) + .onFailure(testContext::failNow); + + assertThat(testContext.awaitCompletion(5, TimeUnit.SECONDS)).isTrue(); + if (testContext.failed()) { + throw testContext.causeOfFailure(); + } + + // Stop the WebSocketService after the test + webSocketService.stop().join(); + } +} From 62b2c500c4baeb02674cd5568cb3e02bcb26e8ec Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Fri, 8 Nov 2024 12:25:59 +0100 Subject: [PATCH 23/56] Fix missing registration of PeerTransactionTracker to dropped tx notifications (#7858) Signed-off-by: Fabio Di Fabio --- .../ethereum/eth/transactions/TransactionBroadcaster.java | 8 +++++++- .../besu/ethereum/eth/transactions/TransactionPool.java | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionBroadcaster.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionBroadcaster.java index c60c064c4c2..35f438d4191 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionBroadcaster.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionBroadcaster.java @@ -37,7 +37,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class TransactionBroadcaster implements TransactionBatchAddedListener { +public class TransactionBroadcaster + implements TransactionBatchAddedListener, PendingTransactionDroppedListener { private static final Logger LOG = LoggerFactory.getLogger(TransactionBroadcaster.class); private static final EnumSet ANNOUNCE_HASH_ONLY_TX_TYPES = EnumSet.of(BLOB); @@ -219,4 +220,9 @@ private void movePeersBetweenLists( destinationList.add(sourceList.remove(i)); } } + + @Override + public void onTransactionDropped(final Transaction transaction, final RemovalReason reason) { + transactionTracker.onTransactionDropped(transaction, reason); + } } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java index 19bcfe0b36e..3acf49894a3 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java @@ -139,6 +139,7 @@ public TransactionPool( subscribePendingTransactions(this::mapBlobsOnTransactionAdded); subscribeDroppedTransactions( (transaction, reason) -> unmapBlobsOnTransactionDropped(transaction)); + subscribeDroppedTransactions(transactionBroadcaster); } private void initLogForReplay() { From 62b8b4e1d87d07107085a037c1e99ad951b47a0e Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Fri, 8 Nov 2024 13:44:28 +0100 Subject: [PATCH 24/56] Make healing an action of the WorldStateArchive (#7862) Signed-off-by: Fabio Di Fabio --- .../controller/BesuControllerBuilder.java | 17 ++++++-- .../besu/ethereum/MainnetBlockValidator.java | 2 +- .../bonsai/BonsaiWorldStateProvider.java | 15 ++++++- .../trie/forest/ForestWorldStateArchive.java | 5 +++ .../worldstate/WorldStateArchive.java | 20 ++++++++++ .../core/InMemoryKeyValueStorageProvider.java | 5 ++- .../ethereum/core/WorldStateHealerHelper.java | 39 +++++++++++++++++++ .../bonsai/AbstractIsolationTests.java | 4 +- .../bonsai/BonsaiWorldStateProviderTest.java | 22 +++++++---- 9 files changed, 114 insertions(+), 15 deletions(-) create mode 100644 ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/WorldStateHealerHelper.java diff --git a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java index 5eb5e1214da..a2e1a1b6c59 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java @@ -93,6 +93,7 @@ import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; import org.hyperledger.besu.ethereum.worldstate.DiffBasedSubStorageConfiguration; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; +import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive.WorldStateHealer; import org.hyperledger.besu.ethereum.worldstate.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStatePreimageStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; @@ -113,6 +114,7 @@ import java.util.Map; import java.util.Optional; import java.util.OptionalLong; +import java.util.concurrent.atomic.AtomicReference; import java.util.function.Supplier; import org.slf4j.Logger; @@ -589,9 +591,14 @@ public BesuController build() { .map(BesuComponent::getCachedMerkleTrieLoader) .orElseGet(() -> new BonsaiCachedMerkleTrieLoader(metricsSystem)); + final var worldStateHealerSupplier = new AtomicReference(); + final WorldStateArchive worldStateArchive = createWorldStateArchive( - worldStateStorageCoordinator, blockchain, bonsaiCachedMerkleTrieLoader); + worldStateStorageCoordinator, + blockchain, + bonsaiCachedMerkleTrieLoader, + worldStateHealerSupplier::get); if (maybeStoredGenesisBlockHash.isEmpty()) { genesisState.writeStateTo(worldStateArchive.getMutable()); @@ -713,6 +720,8 @@ public BesuController build() { ethProtocolManager, pivotBlockSelector); + worldStateHealerSupplier.set(synchronizer::healWorldState); + ethPeers.setTrailingPeerRequirementsSupplier(synchronizer::calculateTrailingPeerRequirements); if (syncConfig.getSyncMode() == SyncMode.SNAP @@ -1101,7 +1110,8 @@ private Optional createSnapProtocolManager( WorldStateArchive createWorldStateArchive( final WorldStateStorageCoordinator worldStateStorageCoordinator, final Blockchain blockchain, - final BonsaiCachedMerkleTrieLoader bonsaiCachedMerkleTrieLoader) { + final BonsaiCachedMerkleTrieLoader bonsaiCachedMerkleTrieLoader, + final Supplier worldStateHealerSupplier) { return switch (dataStorageConfiguration.getDataStorageFormat()) { case BONSAI -> { final BonsaiWorldStateKeyValueStorage worldStateKeyValueStorage = @@ -1116,7 +1126,8 @@ yield new BonsaiWorldStateProvider( .getMaxLayersToLoad()), bonsaiCachedMerkleTrieLoader, besuComponent.map(BesuComponent::getBesuPluginContext).orElse(null), - evmConfiguration); + evmConfiguration, + worldStateHealerSupplier); } case FOREST -> { final WorldStatePreimageStorage preimageStorage = diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/MainnetBlockValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/MainnetBlockValidator.java index b218982c092..39f5cb0f66f 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/MainnetBlockValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/MainnetBlockValidator.java @@ -181,7 +181,7 @@ public BlockProcessingResult validateAndProcessBlock( Optional.of(new BlockProcessingOutputs(worldState, receipts, maybeRequests))); } } catch (MerkleTrieException ex) { - context.getSynchronizer().healWorldState(ex.getMaybeAddress(), ex.getLocation()); + context.getWorldStateArchive().heal(ex.getMaybeAddress(), ex.getLocation()); return new BlockProcessingResult(Optional.empty(), ex); } catch (StorageException ex) { var retval = new BlockProcessingResult(Optional.empty(), ex); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProvider.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProvider.java index e4b7ea991f3..96a56da6e20 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProvider.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProvider.java @@ -34,6 +34,7 @@ import java.util.Optional; import java.util.Set; import java.util.function.Function; +import java.util.function.Supplier; import com.google.common.annotations.VisibleForTesting; import org.apache.tuweni.bytes.Bytes; @@ -44,6 +45,7 @@ public class BonsaiWorldStateProvider extends DiffBasedWorldStateProvider { private static final Logger LOG = LoggerFactory.getLogger(BonsaiWorldStateProvider.class); private final BonsaiCachedMerkleTrieLoader bonsaiCachedMerkleTrieLoader; + private final Supplier worldStateHealerSupplier; public BonsaiWorldStateProvider( final BonsaiWorldStateKeyValueStorage worldStateKeyValueStorage, @@ -51,9 +53,11 @@ public BonsaiWorldStateProvider( final Optional maxLayersToLoad, final BonsaiCachedMerkleTrieLoader bonsaiCachedMerkleTrieLoader, final BesuContext pluginContext, - final EvmConfiguration evmConfiguration) { + final EvmConfiguration evmConfiguration, + final Supplier worldStateHealerSupplier) { super(worldStateKeyValueStorage, blockchain, maxLayersToLoad, pluginContext); this.bonsaiCachedMerkleTrieLoader = bonsaiCachedMerkleTrieLoader; + this.worldStateHealerSupplier = worldStateHealerSupplier; provideCachedWorldStorageManager( new BonsaiCachedWorldStorageManager( this, worldStateKeyValueStorage, this::cloneBonsaiWorldStateConfig)); @@ -69,9 +73,11 @@ public BonsaiWorldStateProvider( final BonsaiWorldStateKeyValueStorage worldStateKeyValueStorage, final Blockchain blockchain, final BonsaiCachedMerkleTrieLoader bonsaiCachedMerkleTrieLoader, - final EvmConfiguration evmConfiguration) { + final EvmConfiguration evmConfiguration, + final Supplier worldStateHealerSupplier) { super(worldStateKeyValueStorage, blockchain, trieLogManager); this.bonsaiCachedMerkleTrieLoader = bonsaiCachedMerkleTrieLoader; + this.worldStateHealerSupplier = worldStateHealerSupplier; provideCachedWorldStorageManager(bonsaiCachedWorldStorageManager); loadPersistedState( new BonsaiWorldState( @@ -151,4 +157,9 @@ public void prepareStateHealing(final Address address, final Bytes location) { private DiffBasedWorldStateConfig cloneBonsaiWorldStateConfig() { return new DiffBasedWorldStateConfig(defaultWorldStateConfig); } + + @Override + public void heal(final Optional
maybeAccountToRepair, final Bytes location) { + worldStateHealerSupplier.get().heal(maybeAccountToRepair, location); + } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/ForestWorldStateArchive.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/ForestWorldStateArchive.java index 1cdd079e15a..800d2c98343 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/ForestWorldStateArchive.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/ForestWorldStateArchive.java @@ -112,6 +112,11 @@ public Optional getAccountProof( blockHeader.getStateRoot(), accountAddress, accountStorageKeys)); } + @Override + public void heal(final Optional
maybeAccountToRepair, final Bytes location) { + // no heal needed for Forest + } + @Override public void close() { // no op diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/WorldStateArchive.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/WorldStateArchive.java index 23859ac3961..9856a200b21 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/WorldStateArchive.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/WorldStateArchive.java @@ -64,4 +64,24 @@ Optional getAccountProof( final Address accountAddress, final List accountStorageKeys, final Function, ? extends Optional> mapper); + + /** + * Heal the world state to fix inconsistency + * + * @param maybeAccountToRepair the optional account to repair + * @param location the location of the inconsistency + */ + void heal(Optional
maybeAccountToRepair, Bytes location); + + /** A world state healer */ + @FunctionalInterface + interface WorldStateHealer { + /** + * Heal the world state to fix inconsistency + * + * @param maybeAccountToRepair the optional account to repair + * @param location the location of the inconsistency + */ + void heal(Optional
maybeAccountToRepair, Bytes location); + } } diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/InMemoryKeyValueStorageProvider.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/InMemoryKeyValueStorageProvider.java index 9bac9254940..aa32ee2b05f 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/InMemoryKeyValueStorageProvider.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/InMemoryKeyValueStorageProvider.java @@ -14,6 +14,8 @@ */ package org.hyperledger.besu.ethereum.core; +import static org.hyperledger.besu.ethereum.core.WorldStateHealerHelper.throwingWorldStateHealerSupplier; + import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.DefaultBlockchain; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; @@ -105,7 +107,8 @@ public static BonsaiWorldStateProvider createBonsaiInMemoryWorldStateArchive( Optional.empty(), bonsaiCachedMerkleTrieLoader, null, - evmConfiguration); + evmConfiguration, + throwingWorldStateHealerSupplier()); } public static MutableWorldState createInMemoryWorldState() { diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/WorldStateHealerHelper.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/WorldStateHealerHelper.java new file mode 100644 index 00000000000..a94ce247932 --- /dev/null +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/WorldStateHealerHelper.java @@ -0,0 +1,39 @@ +/* + * Copyright contributors to 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.ethereum.core; + +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive.WorldStateHealer; + +import java.util.Optional; +import java.util.function.Supplier; + +import org.apache.tuweni.bytes.Bytes; + +public class WorldStateHealerHelper { + + public static WorldStateHealer throwingHealer( + final Optional
maybeAccountToRepair, final Bytes location) { + throw new RuntimeException( + "World state needs to be healed: " + + maybeAccountToRepair.map(address -> "account to repair: " + address).orElse("") + + " location: " + + location.toHexString()); + } + + public static Supplier throwingWorldStateHealerSupplier() { + return () -> WorldStateHealerHelper::throwingHealer; + } +} diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/AbstractIsolationTests.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/AbstractIsolationTests.java index 999d33a5c5e..cfb3094726c 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/AbstractIsolationTests.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/AbstractIsolationTests.java @@ -15,6 +15,7 @@ package org.hyperledger.besu.ethereum.trie.diffbased.bonsai; import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain; +import static org.hyperledger.besu.ethereum.core.WorldStateHealerHelper.throwingWorldStateHealerSupplier; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; @@ -167,7 +168,8 @@ public void createStorage() { Optional.of(16L), new BonsaiCachedMerkleTrieLoader(new NoOpMetricsSystem()), null, - EvmConfiguration.DEFAULT); + EvmConfiguration.DEFAULT, + throwingWorldStateHealerSupplier()); var ws = archive.getMutable(); genesisState.writeStateTo(ws); protocolContext = new ProtocolContext(blockchain, archive, null, new BadBlockManager()); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProviderTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProviderTest.java index 4ac99377ef0..87cc16c23c3 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProviderTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProviderTest.java @@ -15,6 +15,7 @@ package org.hyperledger.besu.ethereum.trie.diffbased.bonsai; import static org.assertj.core.api.Assertions.assertThat; +import static org.hyperledger.besu.ethereum.core.WorldStateHealerHelper.throwingWorldStateHealerSupplier; import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.BLOCKCHAIN; import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.TRIE_BRANCH_STORAGE; import static org.hyperledger.besu.ethereum.trie.diffbased.common.storage.DiffBasedWorldStateKeyValueStorage.WORLD_BLOCK_HASH_KEY; @@ -111,7 +112,8 @@ void testGetMutableReturnPersistedStateWhenNeeded() { DataStorageConfiguration.DEFAULT_BONSAI_CONFIG), blockchain, new BonsaiCachedMerkleTrieLoader(new NoOpMetricsSystem()), - EvmConfiguration.DEFAULT); + EvmConfiguration.DEFAULT, + throwingWorldStateHealerSupplier()); assertThat(bonsaiWorldStateArchive.getMutable(chainHead, true)) .containsInstanceOf(BonsaiWorldState.class); @@ -129,7 +131,8 @@ void testGetMutableReturnEmptyWhenLoadMoreThanLimitLayersBack() { Optional.of(512L), new BonsaiCachedMerkleTrieLoader(new NoOpMetricsSystem()), null, - EvmConfiguration.DEFAULT); + EvmConfiguration.DEFAULT, + throwingWorldStateHealerSupplier()); final BlockHeader blockHeader = blockBuilder.number(0).buildHeader(); final BlockHeader chainHead = blockBuilder.number(512).buildHeader(); when(blockchain.getChainHeadHeader()).thenReturn(chainHead); @@ -150,7 +153,8 @@ void testGetMutableWhenLoadLessThanLimitLayersBack() { DataStorageConfiguration.DEFAULT_BONSAI_CONFIG), blockchain, new BonsaiCachedMerkleTrieLoader(new NoOpMetricsSystem()), - EvmConfiguration.DEFAULT); + EvmConfiguration.DEFAULT, + throwingWorldStateHealerSupplier()); final BlockHeader blockHeader = blockBuilder.number(0).buildHeader(); final BlockHeader chainHead = blockBuilder.number(511).buildHeader(); final BonsaiWorldState mockWorldState = mock(BonsaiWorldState.class); @@ -185,7 +189,8 @@ void testGetMutableWithStorageInconsistencyRollbackTheState() { worldStateKeyValueStorage, blockchain, new BonsaiCachedMerkleTrieLoader(new NoOpMetricsSystem()), - EvmConfiguration.DEFAULT)); + EvmConfiguration.DEFAULT, + throwingWorldStateHealerSupplier())); final BlockHeader blockHeader = blockBuilder.number(0).buildHeader(); when(blockchain.getBlockHeader(blockHeader.getHash())).thenReturn(Optional.of(blockHeader)); @@ -214,7 +219,8 @@ void testGetMutableWithStorageConsistencyNotRollbackTheState() { worldStateKeyValueStorage, blockchain, new BonsaiCachedMerkleTrieLoader(new NoOpMetricsSystem()), - EvmConfiguration.DEFAULT)); + EvmConfiguration.DEFAULT, + throwingWorldStateHealerSupplier())); final BlockHeader blockHeader = blockBuilder.number(0).buildHeader(); @@ -254,7 +260,8 @@ void testGetMutableWithStorageConsistencyToRollbackAndRollForwardTheState() { worldStateKeyValueStorage, blockchain, new BonsaiCachedMerkleTrieLoader(new NoOpMetricsSystem()), - EvmConfiguration.DEFAULT)); + EvmConfiguration.DEFAULT, + throwingWorldStateHealerSupplier())); // initial persisted state hash key when(blockchain.getBlockHeader(Hash.ZERO)).thenReturn(Optional.of(blockHeaderChainA)); @@ -297,7 +304,8 @@ void testGetMutableWithRollbackNotOverrideTrieLogLayer() { DataStorageConfiguration.DEFAULT_BONSAI_CONFIG), blockchain, new BonsaiCachedMerkleTrieLoader(new NoOpMetricsSystem()), - EvmConfiguration.DEFAULT)); + EvmConfiguration.DEFAULT, + throwingWorldStateHealerSupplier())); // initial persisted state hash key when(blockchain.getBlockHeader(Hash.ZERO)).thenReturn(Optional.of(blockHeaderChainA)); From 1c75afbab99646cc9c8c7a6207d4b8c886e25db5 Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Fri, 8 Nov 2024 15:40:02 +0100 Subject: [PATCH 25/56] Remove the Synchronizer from ProtocolContext (#7863) Signed-off-by: Fabio Di Fabio --- .../controller/BesuControllerBuilder.java | 11 +++++----- .../blockcreation/MergeCoordinatorTest.java | 2 -- .../besu/ethereum/ProtocolContext.java | 20 ------------------- .../ethereum/core/BlockchainSetupUtil.java | 1 - .../ethereum/MainnetBlockValidatorTest.java | 2 -- .../eth/manager/snap/SnapProtocolManager.java | 7 +++++-- .../ethereum/eth/manager/snap/SnapServer.java | 6 ++++-- .../snap/SnapServerGetAccountRangeTest.java | 5 ++++- 8 files changed, 19 insertions(+), 35 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java index a2e1a1b6c59..9059d2209bd 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java @@ -45,6 +45,7 @@ import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.PrivacyParameters; +import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.EthProtocol; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.SnapProtocol; @@ -732,11 +733,9 @@ public BesuController build() { ethPeers.snapServerPeersNeeded(false); } - protocolContext.setSynchronizer(synchronizer); - final Optional maybeSnapProtocolManager = createSnapProtocolManager( - protocolContext, worldStateStorageCoordinator, ethPeers, snapMessages); + protocolContext, worldStateStorageCoordinator, ethPeers, snapMessages, synchronizer); final MiningCoordinator miningCoordinator = createMiningCoordinator( @@ -1097,14 +1096,16 @@ private Optional createSnapProtocolManager( final ProtocolContext protocolContext, final WorldStateStorageCoordinator worldStateStorageCoordinator, final EthPeers ethPeers, - final EthMessages snapMessages) { + final EthMessages snapMessages, + final Synchronizer synchronizer) { return Optional.of( new SnapProtocolManager( worldStateStorageCoordinator, syncConfig.getSnapSyncConfiguration(), ethPeers, snapMessages, - protocolContext)); + protocolContext, + synchronizer)); } WorldStateArchive createWorldStateArchive( diff --git a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java index 23a5ae16b10..90c4b6866e4 100644 --- a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java +++ b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java @@ -59,7 +59,6 @@ import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.Unstable; import org.hyperledger.besu.ethereum.core.MiningConfiguration; -import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.core.TransactionTestFixture; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; @@ -190,7 +189,6 @@ public void setUp() { protocolContext = new ProtocolContext(blockchain, worldStateArchive, mergeContext, badBlockManager); - protocolContext.setSynchronizer(mock(Synchronizer.class)); var mutable = worldStateArchive.getMutable(); genesisState.writeStateTo(mutable); mutable.persist(null); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ProtocolContext.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ProtocolContext.java index 4ca40bc0a9d..53197ea9c56 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ProtocolContext.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ProtocolContext.java @@ -16,7 +16,6 @@ import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; -import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; @@ -32,7 +31,6 @@ public class ProtocolContext { private final WorldStateArchive worldStateArchive; private final BadBlockManager badBlockManager; private final ConsensusContext consensusContext; - private Synchronizer synchronizer; /** * Constructs a new ProtocolContext with the given blockchain, world state archive, consensus @@ -78,24 +76,6 @@ public static ProtocolContext init( badBlockManager); } - /** - * Gets the synchronizer of the protocol context. - * - * @return the synchronizer of the protocol context - */ - public Synchronizer getSynchronizer() { - return synchronizer; - } - - /** - * Sets the synchronizer of the protocol context. - * - * @param synchronizer the synchronizer to set - */ - public void setSynchronizer(final Synchronizer synchronizer) { - this.synchronizer = synchronizer; - } - /** * Gets the blockchain of the protocol context. * diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockchainSetupUtil.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockchainSetupUtil.java index 57f11585857..b7608bb5de6 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockchainSetupUtil.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockchainSetupUtil.java @@ -194,7 +194,6 @@ private static BlockchainSetupUtil create( genesisState.writeStateTo(worldArchive.getMutable()); final ProtocolContext protocolContext = protocolContextProvider.get(blockchain, worldArchive); - protocolContext.setSynchronizer(new DummySynchronizer()); final Path blocksPath = Path.of(chainResources.getBlocksURL().toURI()); final List blocks = new ArrayList<>(); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/MainnetBlockValidatorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/MainnetBlockValidatorTest.java index 013adae51ea..255ea778395 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/MainnetBlockValidatorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/MainnetBlockValidatorTest.java @@ -31,7 +31,6 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.core.MutableWorldState; -import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.mainnet.BlockBodyValidator; import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator; import org.hyperledger.besu.ethereum.mainnet.BlockProcessor; @@ -91,7 +90,6 @@ public void setup() { when(protocolContext.getBlockchain()).thenReturn(blockchain); when(protocolContext.getWorldStateArchive()).thenReturn(worldStateArchive); - when(protocolContext.getSynchronizer()).thenReturn(mock(Synchronizer.class)); when(worldStateArchive.getMutable(any(BlockHeader.class), anyBoolean())) .thenReturn(Optional.of(worldState)); when(worldStateArchive.getMutable(any(Hash.class), any(Hash.class))) diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapProtocolManager.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapProtocolManager.java index ce639a7a9a0..2e49eba3538 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapProtocolManager.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapProtocolManager.java @@ -15,6 +15,7 @@ package org.hyperledger.besu.ethereum.eth.manager.snap; import org.hyperledger.besu.ethereum.ProtocolContext; +import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.SnapProtocol; import org.hyperledger.besu.ethereum.eth.manager.EthMessage; import org.hyperledger.besu.ethereum.eth.manager.EthMessages; @@ -53,11 +54,13 @@ public SnapProtocolManager( final SnapSyncConfiguration snapConfig, final EthPeers ethPeers, final EthMessages snapMessages, - final ProtocolContext protocolContext) { + final ProtocolContext protocolContext, + final Synchronizer synchronizer) { this.ethPeers = ethPeers; this.snapMessages = snapMessages; this.supportedCapabilities = calculateCapabilities(); - new SnapServer(snapConfig, snapMessages, worldStateStorageCoordinator, protocolContext); + new SnapServer( + snapConfig, snapMessages, worldStateStorageCoordinator, protocolContext, synchronizer); } private List calculateCapabilities() { diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServer.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServer.java index 56c3ae0a4a8..35cc63cde83 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServer.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServer.java @@ -16,6 +16,7 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.ProtocolContext; +import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.manager.EthMessages; import org.hyperledger.besu.ethereum.eth.messages.snap.AccountRangeMessage; import org.hyperledger.besu.ethereum.eth.messages.snap.ByteCodesMessage; @@ -98,7 +99,8 @@ class SnapServer implements BesuEvents.InitialSyncCompletionListener { final SnapSyncConfiguration snapConfig, final EthMessages snapMessages, final WorldStateStorageCoordinator worldStateStorageCoordinator, - final ProtocolContext protocolContext) { + final ProtocolContext protocolContext, + final Synchronizer synchronizer) { this.snapServerEnabled = Optional.ofNullable(snapConfig) .map(SnapSyncConfiguration::isSnapServerEnabled) @@ -110,7 +112,7 @@ class SnapServer implements BesuEvents.InitialSyncCompletionListener { // subscribe to initial sync completed events to start/stop snap server, // not saving the listenerId since we never need to unsubscribe. - protocolContext.getSynchronizer().subscribeInitialSync(this); + synchronizer.subscribeInitialSync(this); } /** diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServerGetAccountRangeTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServerGetAccountRangeTest.java index 6d8180c8c0e..eb97419967b 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServerGetAccountRangeTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServerGetAccountRangeTest.java @@ -15,10 +15,12 @@ package org.hyperledger.besu.ethereum.eth.manager.snap; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.mockito.Mockito.mock; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; +import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.manager.EthMessages; import org.hyperledger.besu.ethereum.eth.messages.snap.AccountRangeMessage; import org.hyperledger.besu.ethereum.eth.messages.snap.GetAccountRangeMessage; @@ -70,7 +72,8 @@ public void setupTest() { snapSyncConfiguration, new EthMessages(), worldStateStorageCoordinator, - protocolContext) + protocolContext, + mock(Synchronizer.class)) .start(); initAccounts(); } From 1895d44415f4cb8db97a0804bb2002b2a1c4d4a8 Mon Sep 17 00:00:00 2001 From: Dmitry <98899785+mdqst@users.noreply.github.com> Date: Fri, 8 Nov 2024 18:03:43 +0300 Subject: [PATCH 26/56] Typo Update trace_rpc_apis.md (#7868) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "ope.ex.mem" should be "op.ex.mem" — The abbreviation for "opcode execution" should be "op" rather than "ope." Corrected. Signed-off-by: Dmitry <98899785+mdqst@users.noreply.github.com> Co-authored-by: Sally MacFarlane --- docs/trace_rpc_apis.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/trace_rpc_apis.md b/docs/trace_rpc_apis.md index e8db0bcbc5c..7f04d497a7b 100644 --- a/docs/trace_rpc_apis.md +++ b/docs/trace_rpc_apis.md @@ -16,7 +16,7 @@ implementations of Besu might track gas refunds separately. ### Returned Memory from Calls -In the `vmTrace` `ope.ex.mem` fields Besu only reports actual data returned +In the `vmTrace` `op.ex.mem` fields Besu only reports actual data returned from a `RETURN` opcode. Other implementations return the contents of the reserved output space for the call operations. Note two major differences: From c15afb915bdb2fa53e41807c8794b80151e9c5d3 Mon Sep 17 00:00:00 2001 From: amsmota Date: Wed, 13 Nov 2024 08:50:56 +0000 Subject: [PATCH 27/56] control jemalloc reporting and loading (#7424) * Implementing Issue #7047 - Optionally load jemalloc Signed-off-by: Antonio Mota * Implementing Issue #7047 - Optionally load jemalloc Signed-off-by: Antonio Mota * Implementing Issue #7047 - Optionally load jemalloc: fixes after review Signed-off-by: Antonio Mota * Implementing Issue #7047 - Optionally load jemalloc: added entry to CHANGELOG Signed-off-by: Antonio Mota * Changes after review Signed-off-by: Antonio Mota * Added env var check in unix script Signed-off-by: Antonio Mota * Improved code and script, build and tested Signed-off-by: amsmota * Improved code and script, build and tested Signed-off-by: amsmota --------- Signed-off-by: Antonio Mota Signed-off-by: amsmota --- CHANGELOG.md | 1 + .../cli/ConfigurationOverviewBuilder.java | 14 +++++++---- besu/src/main/scripts/unixStartScript.txt | 24 +++++++++---------- .../hyperledger/besu/cli/BesuCommandTest.java | 12 ++++++---- 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b78adf6e068..7b02f812706 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -103,6 +103,7 @@ This release version has been deprecated release due to CI bug - Remove long-deprecated `perm*whitelist*` methods [#7401](https://github.com/hyperledger/besu/pull/7401) ### Additions and Improvements +- Allow optional loading of `jemalloc` (if installed) by setting the environment variable `BESU_USING_JEMALLOC` to true/false. It that env is not set at all it will behave as if it is set to `true` - 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) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java b/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java index b3dfa2a054c..a7b43d0d9e5 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java @@ -433,14 +433,18 @@ public String build() { private void detectJemalloc(final List lines) { Optional.ofNullable(Objects.isNull(environment) ? null : environment.get("BESU_USING_JEMALLOC")) .ifPresentOrElse( - t -> { + jemallocEnabled -> { try { - final String version = PlatformDetector.getJemalloc(); - lines.add("jemalloc: " + version); + if (Boolean.parseBoolean(jemallocEnabled)) { + final String version = PlatformDetector.getJemalloc(); + lines.add("jemalloc: " + version); + } else { + logger.warn( + "besu_using_jemalloc is present but is not set to true, jemalloc library not loaded"); + } } catch (final Throwable throwable) { logger.warn( - "BESU_USING_JEMALLOC is present but we failed to load jemalloc library to get the version", - throwable); + "besu_using_jemalloc is present but we failed to load jemalloc library to get the version"); } }, () -> { diff --git a/besu/src/main/scripts/unixStartScript.txt b/besu/src/main/scripts/unixStartScript.txt index 3302b9c2fe1..9e5c5a300b0 100644 --- a/besu/src/main/scripts/unixStartScript.txt +++ b/besu/src/main/scripts/unixStartScript.txt @@ -182,19 +182,19 @@ APP_ARGS=`save "\$@"` # Collect all arguments for the java command, following the shell quoting and substitution rules eval set -- \$DEFAULT_JVM_OPTS \$JAVA_OPTS \$${optsEnvironmentVar} <% if ( appNameSystemProperty ) { %>"\"-D${appNameSystemProperty}=\$APP_BASE_NAME\"" <% } %>-classpath "\"\$CLASSPATH\"" <% if ( mainClassName.startsWith('--module ') ) { %>--module-path "\"\$MODULE_PATH\"" <% } %>${mainClassName} "\$APP_ARGS" -unset BESU_USING_JEMALLOC if [ "\$darwin" = "false" -a "\$msys" = "false" ]; then - # check if jemalloc is available - TEST_JEMALLOC=\$(LD_PRELOAD=libjemalloc.so sh -c true 2>&1) - - # if jemalloc is available the output is empty, otherwise the output has an error line - if [ -z "\$TEST_JEMALLOC" ]; then - export LD_PRELOAD=libjemalloc.so - export BESU_USING_JEMALLOC=true - else - # jemalloc not available, as fallback limit malloc to 2 arenas - export MALLOC_ARENA_MAX=2 - fi + if [ "\$BESU_USING_JEMALLOC" != "FALSE" -a "\$BESU_USING_JEMALLOC" != "false" ]; then + # check if jemalloc is available + TEST_JEMALLOC=\$(LD_PRELOAD=libjemalloc.so sh -c true 2>&1) + + # if jemalloc is available the output is empty, otherwise the output has an error line + if [ -z "\$TEST_JEMALLOC" ]; then + export LD_PRELOAD=libjemalloc.so + else + # jemalloc not available, as fallback limit malloc to 2 arenas + export MALLOC_ARENA_MAX=2 + fi + fi fi exec "\$JAVACMD" "\$@" diff --git a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java index ea06f406ed9..eb789478b9a 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java @@ -37,6 +37,7 @@ import static org.mockito.ArgumentMatchers.contains; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNotNull; +import static org.mockito.Mockito.argThat; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; @@ -2412,13 +2413,16 @@ public void nativeLibrariesAreEnabledByDefault() { @Test public void logsWarningWhenFailToLoadJemalloc() { assumeTrue(PlatformDetector.getOSType().equals("linux")); - setEnvironmentVariable("BESU_USING_JEMALLOC", "true"); + setEnvironmentVariable("BESU_USING_JEMALLOC", "false"); parseCommand(); verify(mockLogger) .warn( - eq( - "BESU_USING_JEMALLOC is present but we failed to load jemalloc library to get the version"), - any(Throwable.class)); + argThat( + arg -> + arg.equals( + "besu_using_jemalloc is present but is not set to true, jemalloc library not loaded") + || arg.equals( + "besu_using_jemalloc is present but we failed to load jemalloc library to get the version"))); } @Test From f156a17d3fb207a348533967b18f56ab96b4dbba Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Thu, 14 Nov 2024 04:58:05 +0100 Subject: [PATCH 28/56] Fix registration of RocksDB metrics categories (#7879) Signed-off-by: Fabio Di Fabio --- .../besu/cli/options/MetricsOptionsTest.java | 24 +++++++++++++++++++ .../metrics/MetricCategoryRegistryImpl.java | 3 ++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsOptionsTest.java index 39e77cbad7e..f68a87643bd 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsOptionsTest.java @@ -14,12 +14,18 @@ */ package org.hyperledger.besu.cli.options; +import static org.assertj.core.api.Assertions.assertThat; + import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.metrics.MetricCategoryRegistryImpl; import org.hyperledger.besu.metrics.StandardMetricCategory; import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; +import java.util.EnumSet; +import java.util.stream.Collectors; + import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; @@ -64,4 +70,22 @@ protected MetricsOptions getOptionsFromBesuCommand(final TestBesuCommand besuCom protected String[] getNonOptionFields() { return new String[] {"metricCategoryRegistry"}; } + + @Test + public void enableRocksDbCategories() { + final var rocksDbMetricsCategories = + EnumSet.of( + BesuMetricCategory.KVSTORE_ROCKSDB, + BesuMetricCategory.KVSTORE_ROCKSDB_STATS, + BesuMetricCategory.KVSTORE_PRIVATE_ROCKSDB, + BesuMetricCategory.KVSTORE_PRIVATE_ROCKSDB_STATS); + + internalTestSuccess( + metricsConfBuilder -> { + assertThat(metricsConfBuilder.build().getMetricCategories()) + .containsExactlyInAnyOrderElementsOf(rocksDbMetricsCategories); + }, + "--metrics-categories", + rocksDbMetricsCategories.stream().map(Enum::name).collect(Collectors.joining(","))); + } } diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImpl.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImpl.java index 6596268acb7..43feef12ac5 100644 --- a/metrics/core/src/main/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImpl.java +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImpl.java @@ -40,7 +40,8 @@ public MetricCategoryRegistryImpl() {} * @param categoryEnum the category enum */ public & MetricCategory> void addCategories(final Class categoryEnum) { - EnumSet.allOf(categoryEnum).forEach(this::addMetricCategory); + EnumSet.allOf(categoryEnum) + .forEach(category -> metricCategories.put(category.name(), category)); } /** From e548cdc487789ae2e38fc15daab7b6fdf9fb1480 Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Thu, 14 Nov 2024 15:44:40 +1100 Subject: [PATCH 29/56] MAINTAINERS - Add Matilda Clerke (#7829) Signed-off-by: Gabriel-Trintinalia --- MAINTAINERS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS.md b/MAINTAINERS.md index afb82b6fc59..6c17df88239 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -22,6 +22,7 @@ | Luis Pinto | lu-pinto | lu-pinto | | Lucas Saldanha | lucassaldanha | lucassaldanha | | Sally MacFarlane | macfarla | macfarla | +| Matilda Clerke | Matilda-Clerke | MatildaClerke | | Karim Taam | matkt | matkt | | Matthew Whitehead| matthew1001 | matthew.whitehead | | Meredith Baxter | mbaxter | mbaxter | From 40b27a15d2c4ee2f4f8442dbcc6da2c0d9a9c051 Mon Sep 17 00:00:00 2001 From: Matt Whitehead Date: Thu, 14 Nov 2024 14:45:34 +0700 Subject: [PATCH 30/56] Upgrade netty to 4.1.115 (latest version) to resolve CVE (#7878) * Upgrade netty to 4.1.115 (latest version) to resolve CVE Signed-off-by: Matthew Whitehead * Update changelog Signed-off-by: Matthew Whitehead --------- Signed-off-by: Matthew Whitehead --- CHANGELOG.md | 1 + gradle/verification-metadata.xml | 297 +++++++++++++++++++++++++++++++ platform/build.gradle | 2 +- 3 files changed, 299 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b02f812706..a0a53280feb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ ### Bug fixes - Fix registering new metric categories from plugins [#7825](https://github.com/hyperledger/besu/pull/7825) +- Fix CVE-2024-47535 [7878](https://github.com/hyperledger/besu/pull/7878) ## 24.10.0 diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index d4407855f09..5c143f63a6b 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -1932,6 +1932,14 @@ + + + + + + + + @@ -1942,6 +1950,11 @@ + + + + + @@ -1955,6 +1968,14 @@ + + + + + + + + @@ -1963,6 +1984,14 @@ + + + + + + + + @@ -1971,6 +2000,14 @@ + + + + + + + + @@ -1979,6 +2016,14 @@ + + + + + + + + @@ -1992,6 +2037,14 @@ + + + + + + + + @@ -2005,6 +2058,14 @@ + + + + + + + + @@ -2013,6 +2074,14 @@ + + + + + + + + @@ -2021,6 +2090,14 @@ + + + + + + + + @@ -2029,6 +2106,14 @@ + + + + + + + + @@ -2037,6 +2122,14 @@ + + + + + + + + @@ -2045,6 +2138,14 @@ + + + + + + + + @@ -2053,6 +2154,14 @@ + + + + + + + + @@ -2061,6 +2170,14 @@ + + + + + + + + @@ -2074,6 +2191,14 @@ + + + + + + + + @@ -2087,6 +2212,14 @@ + + + + + + + + @@ -2100,6 +2233,14 @@ + + + + + + + + @@ -2108,6 +2249,14 @@ + + + + + + + + @@ -2118,6 +2267,11 @@ + + + + + @@ -2131,6 +2285,14 @@ + + + + + + + + @@ -2144,6 +2306,14 @@ + + + + + + + + @@ -2152,6 +2322,14 @@ + + + + + + + + @@ -2163,6 +2341,17 @@ + + + + + + + + + + + @@ -2176,6 +2365,14 @@ + + + + + + + + @@ -2184,11 +2381,24 @@ + + + + + + + + + + + + + @@ -2202,6 +2412,14 @@ + + + + + + + + @@ -2210,6 +2428,14 @@ + + + + + + + + @@ -2218,6 +2444,14 @@ + + + + + + + + @@ -2240,6 +2474,23 @@ + + + + + + + + + + + + + + + + + @@ -2259,6 +2510,20 @@ + + + + + + + + + + + + + + @@ -2272,6 +2537,14 @@ + + + + + + + + @@ -2280,6 +2553,14 @@ + + + + + + + + @@ -2288,6 +2569,14 @@ + + + + + + + + @@ -2296,6 +2585,14 @@ + + + + + + + + diff --git a/platform/build.gradle b/platform/build.gradle index d614603f17f..dad2d8e1a09 100644 --- a/platform/build.gradle +++ b/platform/build.gradle @@ -28,7 +28,7 @@ javaPlatform { dependencies { api platform('com.fasterxml.jackson:jackson-bom:2.18.0') api platform('io.grpc:grpc-bom:1.68.0') - api platform('io.netty:netty-bom:4.1.114.Final') + api platform('io.netty:netty-bom:4.1.115.Final') api platform('io.opentelemetry:opentelemetry-bom:1.43.0') api platform('io.prometheus:simpleclient_bom:0.16.0') api platform('io.vertx:vertx-stack-depchain:4.5.10') From 37ea0282de17f393531a6ee7be2dbfe92d0910ac Mon Sep 17 00:00:00 2001 From: Dmitry <98899785+mdqst@users.noreply.github.com> Date: Tue, 19 Nov 2024 09:33:06 +0300 Subject: [PATCH 31/56] Typo Update Private-Txns-Migration.md (#7870) The phrase "private transaction created using v1.3.4" should be in the plural form: "private transactions created using v1.3.4". Corrected. Signed-off-by: Dmitry <98899785+mdqst@users.noreply.github.com> Co-authored-by: Sally MacFarlane --- docs/Private-Txns-Migration.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/Private-Txns-Migration.md b/docs/Private-Txns-Migration.md index 0ae06dae3ce..042e83c8dd1 100644 --- a/docs/Private-Txns-Migration.md +++ b/docs/Private-Txns-Migration.md @@ -12,7 +12,7 @@ state storage when upgrading to v1.4. It is not possible to upgrade to v1.4 with ## Private transactions created using v1.3.4 or earlier A critical issue for privacy users with private transactions created using Hyperledger Besu v1.3.4 -or earlier has been identified. If you have a network with private transaction created using v1.3.4 +or earlier has been identified. If you have a network with private transactions created using v1.3.4 or earlier, please read the following and take the appropriate steps: https://wiki.hyperledger.org/display/BESU/Critical+Issue+for+Privacy+Users @@ -41,4 +41,4 @@ your Besu database from backup and restart the migration process. ## Migration support If you have a long running network with a large volume of private transactions and/or would like to discuss -the migration process with us before upgrading, contact us at support@pegasys.tech \ No newline at end of file +the migration process with us before upgrading, contact us at support@pegasys.tech From dc81641c5832175b560579b144873267c71ef4cd Mon Sep 17 00:00:00 2001 From: Justin Florentine Date: Tue, 19 Nov 2024 08:15:09 -0500 Subject: [PATCH 32/56] narrows dependencies of BlockchainService (#7882) Signed-off-by: jflo --- .../dsl/node/ThreadBesuNodeRunner.java | 4 +++- .../org/hyperledger/besu/cli/BesuCommand.java | 2 +- .../besu/services/BlockchainServiceImpl.java | 18 +++++++----------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java index fc2a7d372ea..4544872d5c0 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java @@ -327,7 +327,9 @@ RpcEndpointServiceImpl provideRpcEndpointService() { @Singleton BlockchainServiceImpl provideBlockchainService(final BesuController besuController) { BlockchainServiceImpl retval = new BlockchainServiceImpl(); - retval.init(besuController.getProtocolContext(), besuController.getProtocolSchedule()); + retval.init( + besuController.getProtocolContext().getBlockchain(), + besuController.getProtocolSchedule()); return retval; } diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index 8f4a1472fb3..9126bc8a2a7 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -1233,7 +1233,7 @@ private Runner buildRunner() { private void startPlugins(final Runner runner) { blockchainServiceImpl.init( - besuController.getProtocolContext(), besuController.getProtocolSchedule()); + besuController.getProtocolContext().getBlockchain(), besuController.getProtocolSchedule()); transactionSimulationServiceImpl.init( besuController.getProtocolContext().getBlockchain(), new TransactionSimulator( diff --git a/besu/src/main/java/org/hyperledger/besu/services/BlockchainServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/BlockchainServiceImpl.java index e981a3e78d6..76b4d7e1509 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/BlockchainServiceImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/BlockchainServiceImpl.java @@ -16,7 +16,6 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; @@ -40,7 +39,6 @@ @Unstable public class BlockchainServiceImpl implements BlockchainService { - private ProtocolContext protocolContext; private ProtocolSchedule protocolSchedule; private MutableBlockchain blockchain; @@ -50,13 +48,12 @@ public BlockchainServiceImpl() {} /** * Initialize the Blockchain service. * - * @param protocolContext the protocol context + * @param blockchain the blockchain * @param protocolSchedule the protocol schedule */ - public void init(final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule) { - this.protocolContext = protocolContext; + public void init(final MutableBlockchain blockchain, final ProtocolSchedule protocolSchedule) { this.protocolSchedule = protocolSchedule; - this.blockchain = protocolContext.getBlockchain(); + this.blockchain = blockchain; } /** @@ -67,25 +64,24 @@ public void init(final ProtocolContext protocolContext, final ProtocolSchedule p */ @Override public Optional getBlockByNumber(final long number) { - return protocolContext - .getBlockchain() + return blockchain .getBlockByNumber(number) .map(block -> blockContext(block::getHeader, block::getBody)); } @Override public Hash getChainHeadHash() { - return protocolContext.getBlockchain().getChainHeadHash(); + return blockchain.getChainHeadHash(); } @Override public BlockHeader getChainHeadHeader() { - return protocolContext.getBlockchain().getChainHeadHeader(); + return blockchain.getChainHeadHeader(); } @Override public Optional getNextBlockBaseFee() { - final var chainHeadHeader = protocolContext.getBlockchain().getChainHeadHeader(); + final var chainHeadHeader = blockchain.getChainHeadHeader(); final var protocolSpec = protocolSchedule.getForNextBlockHeader(chainHeadHeader, System.currentTimeMillis()); return Optional.of(protocolSpec.getFeeMarket()) From 833a5ce5ddcb56c1ca67544a3d9f968128fb45bc Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Tue, 19 Nov 2024 15:51:04 +0100 Subject: [PATCH 33/56] Simplify ProtocolContext creation (#7792) Signed-off-by: Fabio Di Fabio --- .../controller/BesuControllerBuilder.java | 24 ++++++------ ...onsensusScheduleBesuControllerBuilder.java | 17 +++++---- .../controller/QbftBesuControllerBuilder.java | 5 +-- .../TransitionBesuControllerBuilder.java | 7 +--- ...nsusScheduleBesuControllerBuilderTest.java | 17 ++++----- .../blockcreation/CliqueBlockCreatorTest.java | 17 +++++---- .../CliqueMinerExecutorTest.java | 2 + ...xt.java => MigratingConsensusContext.java} | 4 +- .../common/MigratingProtocolContext.java | 36 ++---------------- .../common/MigratingProtocolContextTest.java | 6 ++- .../jsonrpc/JsonRpcTestMethodsFactory.java | 5 ++- ...ckByNumberLatestDesyncIntegrationTest.java | 4 +- .../AbstractEthGraphQLHttpServiceTest.java | 6 ++- .../blockcreation/BlockMinerTest.java | 7 ++-- .../ethereum/ConsensusContextFactory.java | 38 ------------------- .../besu/ethereum/ProtocolContext.java | 29 +------------- .../ethereum/core/BlockchainSetupUtil.java | 11 +----- .../core/ConsensusContextFixture.java | 24 ++++++++++++ .../core/ExecutionContextTestFixture.java | 3 +- .../bonsai/AbstractIsolationTests.java | 5 ++- .../fullsync/FullSyncTargetManagerTest.java | 4 +- ...neCommonAncestorTaskParameterizedTest.java | 7 +++- .../DetermineCommonAncestorTaskTest.java | 7 +++- .../ethereum/eth/transactions/TestNode.java | 4 +- .../BlockchainReferenceTestCaseSpec.java | 7 +++- 25 files changed, 127 insertions(+), 169 deletions(-) rename consensus/common/src/main/java/org/hyperledger/besu/consensus/common/{MigratingContext.java => MigratingConsensusContext.java} (88%) delete mode 100644 ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ConsensusContextFactory.java create mode 100644 ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ConsensusContextFixture.java diff --git a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java index 9059d2209bd..b3cbab5cc93 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java @@ -26,7 +26,6 @@ import org.hyperledger.besu.cryptoservices.NodeKey; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.ConsensusContext; -import org.hyperledger.besu.ethereum.ConsensusContextFactory; import org.hyperledger.besu.ethereum.GasLimitCalculator; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethods; @@ -605,9 +604,11 @@ public BesuController build() { genesisState.writeStateTo(worldStateArchive.getMutable()); } + final var consensusContext = + createConsensusContext(blockchain, worldStateArchive, protocolSchedule); + final ProtocolContext protocolContext = - createProtocolContext( - blockchain, worldStateArchive, protocolSchedule, this::createConsensusContext); + createProtocolContext(blockchain, worldStateArchive, consensusContext); validateContext(protocolContext); protocolSchedule.setPublicWorldStateArchiveForPrivacyBlockProcessor( @@ -976,7 +977,7 @@ protected SubProtocolConfiguration createSubProtocolConfiguration( } /** - * Create mining coordinator mining coordinator. + * Create mining coordinator. * * @param protocolSchedule the protocol schedule * @param protocolContext the protocol context @@ -1017,9 +1018,9 @@ protected void validateContext(final ProtocolContext context) {} * @return the consensus context */ protected abstract ConsensusContext createConsensusContext( - Blockchain blockchain, - WorldStateArchive worldStateArchive, - ProtocolSchedule protocolSchedule); + final Blockchain blockchain, + final WorldStateArchive worldStateArchive, + final ProtocolSchedule protocolSchedule); /** * Gets supported protocol. @@ -1079,17 +1080,14 @@ protected EthProtocolManager createEthProtocolManager( * * @param blockchain the blockchain * @param worldStateArchive the world state archive - * @param protocolSchedule the protocol schedule - * @param consensusContextFactory the consensus context factory + * @param consensusContext the consensus context * @return the protocol context */ protected ProtocolContext createProtocolContext( final MutableBlockchain blockchain, final WorldStateArchive worldStateArchive, - final ProtocolSchedule protocolSchedule, - final ConsensusContextFactory consensusContextFactory) { - return ProtocolContext.init( - blockchain, worldStateArchive, protocolSchedule, consensusContextFactory, badBlockManager); + final ConsensusContext consensusContext) { + return new ProtocolContext(blockchain, worldStateArchive, consensusContext, badBlockManager); } private Optional createSnapProtocolManager( diff --git a/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java index 3ecd5a6c413..c70367aed62 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java @@ -20,13 +20,12 @@ import org.hyperledger.besu.consensus.common.CombinedProtocolScheduleFactory; import org.hyperledger.besu.consensus.common.ForkSpec; import org.hyperledger.besu.consensus.common.ForksSchedule; -import org.hyperledger.besu.consensus.common.MigratingContext; +import org.hyperledger.besu.consensus.common.MigratingConsensusContext; import org.hyperledger.besu.consensus.common.MigratingMiningCoordinator; import org.hyperledger.besu.consensus.common.MigratingProtocolContext; import org.hyperledger.besu.cryptoservices.NodeKey; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.ConsensusContext; -import org.hyperledger.besu.ethereum.ConsensusContextFactory; import org.hyperledger.besu.ethereum.GasLimitCalculator; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethods; @@ -168,10 +167,12 @@ protected ProtocolSchedule createProtocolSchedule() { protected ProtocolContext createProtocolContext( final MutableBlockchain blockchain, final WorldStateArchive worldStateArchive, - final ProtocolSchedule protocolSchedule, - final ConsensusContextFactory consensusContextFactory) { - return MigratingProtocolContext.init( - blockchain, worldStateArchive, protocolSchedule, consensusContextFactory, badBlockManager); + final ConsensusContext consensusContext) { + return new MigratingProtocolContext( + blockchain, + worldStateArchive, + consensusContext.as(MigratingConsensusContext.class), + badBlockManager); } @Override @@ -188,10 +189,10 @@ protected ConsensusContext createConsensusContext( e.getValue() .createConsensusContext( blockchain, worldStateArchive, protocolSchedule))) - .collect(Collectors.toList()); + .toList(); final ForksSchedule consensusContextsSchedule = new ForksSchedule<>(consensusContextSpecs); - return new MigratingContext(consensusContextsSchedule); + return new MigratingConsensusContext(consensusContextsSchedule); } @Override diff --git a/besu/src/main/java/org/hyperledger/besu/controller/QbftBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/QbftBesuControllerBuilder.java index 75aff308714..b6f579ea68e 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/QbftBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/QbftBesuControllerBuilder.java @@ -112,10 +112,7 @@ public QbftBesuControllerBuilder() {} @Override protected Supplier bftExtraDataCodec() { - return Suppliers.memoize( - () -> { - return new QbftExtraDataCodec(); - }); + return Suppliers.memoize(QbftExtraDataCodec::new); } @Override diff --git a/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java index 3530621fc6a..75abca6a574 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java @@ -24,7 +24,6 @@ import org.hyperledger.besu.cryptoservices.NodeKey; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.ConsensusContext; -import org.hyperledger.besu.ethereum.ConsensusContextFactory; import org.hyperledger.besu.ethereum.GasLimitCalculator; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; @@ -193,11 +192,9 @@ protected ProtocolSchedule createProtocolSchedule() { protected ProtocolContext createProtocolContext( final MutableBlockchain blockchain, final WorldStateArchive worldStateArchive, - final ProtocolSchedule protocolSchedule, - final ConsensusContextFactory consensusContextFactory) { + final ConsensusContext consensusContext) { final ProtocolContext protocolContext = - super.createProtocolContext( - blockchain, worldStateArchive, protocolSchedule, consensusContextFactory); + super.createProtocolContext(blockchain, worldStateArchive, consensusContext); transitionProtocolSchedule.setProtocolContext(protocolContext); return protocolContext; } diff --git a/besu/src/test/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilderTest.java index aefcda4c231..4e38e03c062 100644 --- a/besu/src/test/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilderTest.java @@ -24,7 +24,7 @@ import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.consensus.common.ForkSpec; import org.hyperledger.besu.consensus.common.ForksSchedule; -import org.hyperledger.besu.consensus.common.MigratingContext; +import org.hyperledger.besu.consensus.common.MigratingConsensusContext; import org.hyperledger.besu.consensus.common.MigratingMiningCoordinator; import org.hyperledger.besu.consensus.common.bft.blockcreation.BftMiningCoordinator; import org.hyperledger.besu.ethereum.ConsensusContext; @@ -166,8 +166,8 @@ public void createsMigratingMiningCoordinator() { @Test public void createsMigratingContext() { - final ConsensusContext context1 = Mockito.mock(ConsensusContext.class); - final ConsensusContext context2 = Mockito.mock(ConsensusContext.class); + final ConsensusContext context1 = mock(ConsensusContext.class); + final ConsensusContext context2 = mock(ConsensusContext.class); final Map besuControllerBuilderSchedule = new TreeMap<>(); besuControllerBuilderSchedule.put(0L, besuControllerBuilder1); @@ -180,15 +180,14 @@ public void createsMigratingContext() { new ConsensusScheduleBesuControllerBuilder(besuControllerBuilderSchedule); final ConsensusContext consensusContext = controllerBuilder.createConsensusContext( - Mockito.mock(Blockchain.class), - Mockito.mock(WorldStateArchive.class), - Mockito.mock(ProtocolSchedule.class)); + mock(Blockchain.class), mock(WorldStateArchive.class), mock(ProtocolSchedule.class)); - assertThat(consensusContext).isInstanceOf(MigratingContext.class); - final MigratingContext migratingContext = (MigratingContext) consensusContext; + assertThat(consensusContext).isInstanceOf(MigratingConsensusContext.class); + final MigratingConsensusContext migratingConsensusContext = + (MigratingConsensusContext) consensusContext; final ForksSchedule contextSchedule = - migratingContext.getConsensusContextSchedule(); + migratingConsensusContext.getConsensusContextSchedule(); final NavigableSet> expectedConsensusContextSpecs = new TreeSet<>(ForkSpec.COMPARATOR); diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreatorTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreatorTest.java index fdc068ddef7..12467cda4ee 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreatorTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreatorTest.java @@ -52,6 +52,7 @@ import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; import org.hyperledger.besu.ethereum.core.MiningConfiguration; +import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; @@ -99,11 +100,20 @@ public class CliqueBlockCreatorTest { @BeforeEach void setup() { + final Address otherAddress = Util.publicKeyToAddress(otherKeyPair.getPublicKey()); + validatorList.add(otherAddress); + + validatorProvider = mock(ValidatorProvider.class); + voteProvider = mock(VoteProvider.class); + when(validatorProvider.getVoteProviderAtHead()).thenReturn(Optional.of(voteProvider)); + when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); + protocolSchedule = CliqueProtocolSchedule.create( GenesisConfigFile.DEFAULT.getConfigOptions(), new ForksSchedule<>(List.of()), proposerNodeKey, + PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, MiningConfiguration.MINING_DISABLED, @@ -111,13 +121,6 @@ void setup() { false, new NoOpMetricsSystem()); - final Address otherAddress = Util.publicKeyToAddress(otherKeyPair.getPublicKey()); - validatorList.add(otherAddress); - - validatorProvider = mock(ValidatorProvider.class); - voteProvider = mock(VoteProvider.class); - when(validatorProvider.getVoteProviderAtHead()).thenReturn(Optional.of(voteProvider)); - when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface); final Block genesis = diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java index 3d6dbd77db9..7000d145b6b 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java @@ -42,6 +42,7 @@ import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration; import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues; import org.hyperledger.besu.ethereum.core.MiningConfiguration; +import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; @@ -103,6 +104,7 @@ public void setup() { GENESIS_CONFIG_OPTIONS, new ForksSchedule<>(List.of()), proposerNodeKey, + PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, MiningConfiguration.MINING_DISABLED, diff --git a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingContext.java b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingConsensusContext.java similarity index 88% rename from consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingContext.java rename to consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingConsensusContext.java index f71e3ac7f36..91ace1a04b3 100644 --- a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingContext.java +++ b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingConsensusContext.java @@ -17,7 +17,7 @@ import org.hyperledger.besu.ethereum.ConsensusContext; /** The Migrating context. */ -public class MigratingContext implements ConsensusContext { +public class MigratingConsensusContext implements ConsensusContext { private final ForksSchedule consensusContextSchedule; @@ -26,7 +26,7 @@ public class MigratingContext implements ConsensusContext { * * @param consensusContextSchedule the consensus context schedule */ - public MigratingContext(final ForksSchedule consensusContextSchedule) { + public MigratingConsensusContext(final ForksSchedule consensusContextSchedule) { this.consensusContextSchedule = consensusContextSchedule; } diff --git a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingProtocolContext.java b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingProtocolContext.java index c0557485f3e..27cce3157b2 100644 --- a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingProtocolContext.java +++ b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingProtocolContext.java @@ -15,11 +15,9 @@ package org.hyperledger.besu.consensus.common; import org.hyperledger.besu.ethereum.ConsensusContext; -import org.hyperledger.besu.ethereum.ConsensusContextFactory; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; /** The Migrating protocol context. */ @@ -32,42 +30,16 @@ public class MigratingProtocolContext extends ProtocolContext { * * @param blockchain the blockchain * @param worldStateArchive the world state archive - * @param consensusContextSchedule the consensus context schedule + * @param migratingConsensusContext the consensus context * @param badBlockManager the cache to use to keep invalid blocks */ public MigratingProtocolContext( final MutableBlockchain blockchain, final WorldStateArchive worldStateArchive, - final ForksSchedule consensusContextSchedule, + final MigratingConsensusContext migratingConsensusContext, final BadBlockManager badBlockManager) { - super(blockchain, worldStateArchive, null, badBlockManager); - this.consensusContextSchedule = consensusContextSchedule; - } - - /** - * Init protocol context. - * - * @param blockchain the blockchain - * @param worldStateArchive the world state archive - * @param protocolSchedule the protocol schedule - * @param consensusContextFactory the consensus context factory - * @param badBlockManager the cache to use to keep invalid blocks - * @return the protocol context - */ - public static ProtocolContext init( - final MutableBlockchain blockchain, - final WorldStateArchive worldStateArchive, - final ProtocolSchedule protocolSchedule, - final ConsensusContextFactory consensusContextFactory, - final BadBlockManager badBlockManager) { - final ConsensusContext consensusContext = - consensusContextFactory.create(blockchain, worldStateArchive, protocolSchedule); - final MigratingContext migratingContext = consensusContext.as(MigratingContext.class); - return new MigratingProtocolContext( - blockchain, - worldStateArchive, - migratingContext.getConsensusContextSchedule(), - badBlockManager); + super(blockchain, worldStateArchive, migratingConsensusContext, badBlockManager); + this.consensusContextSchedule = migratingConsensusContext.getConsensusContextSchedule(); } @Override diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java index d62de57eac9..39ab9f8cb28 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java @@ -43,9 +43,13 @@ public void returnsContextForSpecificChainHeight() { final ForksSchedule contextSchedule = new ForksSchedule<>(List.of(new ForkSpec<>(0L, context1), new ForkSpec<>(10L, context2))); + final MigratingProtocolContext migratingProtocolContext = new MigratingProtocolContext( - blockchain, worldStateArchive, contextSchedule, new BadBlockManager()); + blockchain, + worldStateArchive, + new MigratingConsensusContext(contextSchedule), + new BadBlockManager()); assertThat(migratingProtocolContext.getConsensusContext(ConsensusContext.class)) .isSameAs(context1); diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java index 902d2b04870..2a65b1e7cb0 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java @@ -19,6 +19,7 @@ import static org.mockito.Mockito.mock; import org.hyperledger.besu.config.StubGenesisConfigOptions; +import org.hyperledger.besu.ethereum.ConsensusContext; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.api.ImmutableApiConfiguration; import org.hyperledger.besu.ethereum.api.graphql.GraphQLConfiguration; @@ -82,7 +83,9 @@ public JsonRpcTestMethodsFactory(final BlockchainImporter importer) { this.blockchain = createInMemoryBlockchain(importer.getGenesisBlock()); this.stateArchive = createInMemoryWorldStateArchive(); this.importer.getGenesisState().writeStateTo(stateArchive.getMutable()); - this.context = new ProtocolContext(blockchain, stateArchive, null, new BadBlockManager()); + this.context = + new ProtocolContext( + blockchain, stateArchive, mock(ConsensusContext.class), new BadBlockManager()); this.protocolSchedule = importer.getProtocolSchedule(); this.synchronizer = mock(Synchronizer.class); diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetBlockByNumberLatestDesyncIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetBlockByNumberLatestDesyncIntegrationTest.java index 088eff85007..7e26a4d8126 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetBlockByNumberLatestDesyncIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetBlockByNumberLatestDesyncIntegrationTest.java @@ -20,6 +20,7 @@ import static org.mockito.Mockito.when; import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.ethereum.ConsensusContext; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.api.jsonrpc.BlockchainImporter; import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcTestMethodsFactory; @@ -67,7 +68,8 @@ public static void setUpOnce() throws Exception { InMemoryKeyValueStorageProvider.createInMemoryBlockchain(importer.getGenesisBlock()); WorldStateArchive state = InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive(); importer.getGenesisState().writeStateTo(state.getMutable()); - ProtocolContext context = new ProtocolContext(chain, state, null, new BadBlockManager()); + ProtocolContext context = + new ProtocolContext(chain, state, mock(ConsensusContext.class), new BadBlockManager()); for (final Block block : importer.getBlocks()) { final ProtocolSchedule protocolSchedule = importer.getProtocolSchedule(); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java index 2b55b42ba2d..08cfc3d7bd4 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java @@ -19,6 +19,7 @@ import org.hyperledger.besu.datatypes.TransactionType; import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.ConsensusContext; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.api.ImmutableApiConfiguration; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -110,7 +111,10 @@ public void setupTest() throws Exception { final MutableBlockchain blockchain = blockchainSetupUtil.getBlockchain(); ProtocolContext context = new ProtocolContext( - blockchain, blockchainSetupUtil.getWorldArchive(), null, new BadBlockManager()); + blockchain, + blockchainSetupUtil.getWorldArchive(), + mock(ConsensusContext.class), + new BadBlockManager()); final BlockchainQueries blockchainQueries = new BlockchainQueries( blockchainSetupUtil.getProtocolSchedule(), diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockMinerTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockMinerTest.java index e5b46925aad..5b893d11f24 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockMinerTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockMinerTest.java @@ -22,6 +22,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import org.hyperledger.besu.ethereum.ConsensusContext; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.blockcreation.BlockCreator.BlockCreationResult; import org.hyperledger.besu.ethereum.blockcreation.txselection.TransactionSelectionResults; @@ -58,7 +59,7 @@ public void blockCreatedIsAddedToBlockChain() throws InterruptedException { headerBuilder.buildHeader(), new BlockBody(Lists.newArrayList(), Lists.newArrayList())); final ProtocolContext protocolContext = - new ProtocolContext(null, null, null, new BadBlockManager()); + new ProtocolContext(null, null, mock(ConsensusContext.class), new BadBlockManager()); final PoWBlockCreator blockCreator = mock(PoWBlockCreator.class); final Function blockCreatorSupplier = @@ -102,7 +103,7 @@ public void failureToImportDoesNotTriggerObservers() throws InterruptedException headerBuilder.buildHeader(), new BlockBody(Lists.newArrayList(), Lists.newArrayList())); final ProtocolContext protocolContext = - new ProtocolContext(null, null, null, new BadBlockManager()); + new ProtocolContext(null, null, mock(ConsensusContext.class), new BadBlockManager()); final PoWBlockCreator blockCreator = mock(PoWBlockCreator.class); final Function blockCreatorSupplier = @@ -150,7 +151,7 @@ public void blockValidationFailureBeforeImportDoesNotImportBlock() throws Interr headerBuilder.buildHeader(), new BlockBody(Lists.newArrayList(), Lists.newArrayList())); final ProtocolContext protocolContext = - new ProtocolContext(null, null, null, new BadBlockManager()); + new ProtocolContext(null, null, mock(ConsensusContext.class), new BadBlockManager()); final PoWBlockCreator blockCreator = mock(PoWBlockCreator.class); final Function blockCreatorSupplier = diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ConsensusContextFactory.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ConsensusContextFactory.java deleted file mode 100644 index a9381fa199f..00000000000 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ConsensusContextFactory.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * 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.ethereum; - -import org.hyperledger.besu.ethereum.chain.Blockchain; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; -import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; - -/** The ConsensusContextFactory interface defines a method for creating a consensus context. */ -@FunctionalInterface -public interface ConsensusContextFactory { - - /** - * Creates a consensus context with the given blockchain, world state archive, and protocol - * schedule. - * - * @param blockchain the blockchain - * @param worldStateArchive the world state archive - * @param protocolSchedule the protocol schedule - * @return the created consensus context - */ - ConsensusContext create( - Blockchain blockchain, - WorldStateArchive worldStateArchive, - ProtocolSchedule protocolSchedule); -} diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ProtocolContext.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ProtocolContext.java index 53197ea9c56..33897c3e1ec 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ProtocolContext.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ProtocolContext.java @@ -16,7 +16,6 @@ import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import java.util.Optional; @@ -29,8 +28,8 @@ public class ProtocolContext { private final MutableBlockchain blockchain; private final WorldStateArchive worldStateArchive; - private final BadBlockManager badBlockManager; private final ConsensusContext consensusContext; + private final BadBlockManager badBlockManager; /** * Constructs a new ProtocolContext with the given blockchain, world state archive, consensus @@ -38,7 +37,7 @@ public class ProtocolContext { * * @param blockchain the blockchain of the protocol context * @param worldStateArchive the world state archive of the protocol context - * @param consensusContext the consensus context of the protocol context + * @param consensusContext the consensus context * @param badBlockManager the bad block manager of the protocol context */ public ProtocolContext( @@ -52,30 +51,6 @@ public ProtocolContext( this.badBlockManager = badBlockManager; } - /** - * Initializes a new ProtocolContext with the given blockchain, world state archive, protocol - * schedule, consensus context factory, and bad block manager. - * - * @param blockchain the blockchain of the protocol context - * @param worldStateArchive the world state archive of the protocol context - * @param protocolSchedule the protocol schedule of the protocol context - * @param consensusContextFactory the consensus context factory of the protocol context - * @param badBlockManager the bad block manager of the protocol context - * @return the initialized ProtocolContext - */ - public static ProtocolContext init( - final MutableBlockchain blockchain, - final WorldStateArchive worldStateArchive, - final ProtocolSchedule protocolSchedule, - final ConsensusContextFactory consensusContextFactory, - final BadBlockManager badBlockManager) { - return new ProtocolContext( - blockchain, - worldStateArchive, - consensusContextFactory.create(blockchain, worldStateArchive, protocolSchedule), - badBlockManager); - } - /** * Gets the blockchain of the protocol context. * diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockchainSetupUtil.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockchainSetupUtil.java index b7608bb5de6..3391a0e162c 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockchainSetupUtil.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockchainSetupUtil.java @@ -21,7 +21,6 @@ import static org.mockito.Mockito.mock; import org.hyperledger.besu.config.GenesisConfigFile; -import org.hyperledger.besu.ethereum.ConsensusContext; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.chain.Blockchain; @@ -161,15 +160,7 @@ private static ProtocolSchedule mainnetProtocolScheduleProvider( private static ProtocolContext mainnetProtocolContextProvider( final MutableBlockchain blockchain, final WorldStateArchive worldStateArchive) { return new ProtocolContext( - blockchain, - worldStateArchive, - new ConsensusContext() { - @Override - public C as(final Class klass) { - return null; - } - }, - new BadBlockManager()); + blockchain, worldStateArchive, new ConsensusContextFixture(), new BadBlockManager()); } private static BlockchainSetupUtil create( diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ConsensusContextFixture.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ConsensusContextFixture.java new file mode 100644 index 00000000000..198b3ab8138 --- /dev/null +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ConsensusContextFixture.java @@ -0,0 +1,24 @@ +/* + * Copyright contributors to 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.ethereum.core; + +import org.hyperledger.besu.ethereum.ConsensusContext; + +public class ConsensusContextFixture implements ConsensusContext { + @Override + public C as(final Class klass) { + return klass.cast(this); + } +} diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java index b2b979e283c..b4eaec04d3e 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java @@ -76,7 +76,8 @@ private ExecutionContextTestFixture( else this.stateArchive = createInMemoryWorldStateArchive(); this.protocolSchedule = protocolSchedule; this.protocolContext = - new ProtocolContext(blockchain, stateArchive, null, new BadBlockManager()); + new ProtocolContext( + blockchain, stateArchive, new ConsensusContextFixture(), new BadBlockManager()); genesisState.writeStateTo(stateArchive.getMutable()); } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/AbstractIsolationTests.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/AbstractIsolationTests.java index cfb3094726c..275adc9ff43 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/AbstractIsolationTests.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/AbstractIsolationTests.java @@ -30,6 +30,7 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.BlockProcessingResult; +import org.hyperledger.besu.ethereum.ConsensusContext; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.blockcreation.AbstractBlockCreator; import org.hyperledger.besu.ethereum.chain.BadBlockManager; @@ -172,7 +173,9 @@ public void createStorage() { throwingWorldStateHealerSupplier()); var ws = archive.getMutable(); genesisState.writeStateTo(ws); - protocolContext = new ProtocolContext(blockchain, archive, null, new BadBlockManager()); + protocolContext = + new ProtocolContext( + blockchain, archive, mock(ConsensusContext.class), new BadBlockManager()); ethContext = mock(EthContext.class, RETURNS_DEEP_STUBS); when(ethContext.getEthPeers().subscribeConnect(any())).thenReturn(1L); transactionPool = diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java index 027bd270d29..9132842ccbf 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java @@ -18,6 +18,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import org.hyperledger.besu.ethereum.ConsensusContext; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.chain.Blockchain; @@ -77,7 +78,8 @@ public void setup(final DataStorageFormat storageFormat) { final ProtocolSchedule protocolSchedule = ProtocolScheduleFixture.MAINNET; final ProtocolContext protocolContext = - new ProtocolContext(localBlockchain, localWorldState, null, new BadBlockManager()); + new ProtocolContext( + localBlockchain, localWorldState, mock(ConsensusContext.class), new BadBlockManager()); ethProtocolManager = EthProtocolManagerTestUtil.create( protocolSchedule, diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java index 73d5e5138b4..5686b4ae90d 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java @@ -19,6 +19,7 @@ import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive; import static org.mockito.Mockito.mock; +import org.hyperledger.besu.ethereum.ConsensusContext; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; @@ -151,7 +152,11 @@ public void searchesAgainstNetwork(final int headerRequestSize, final int common final EthContext ethContext = ethProtocolManager.ethContext(); final ProtocolContext protocolContext = - new ProtocolContext(localBlockchain, worldStateArchive, null, new BadBlockManager()); + new ProtocolContext( + localBlockchain, + worldStateArchive, + mock(ConsensusContext.class), + new BadBlockManager()); final EthTask task = DetermineCommonAncestorTask.create( diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java index 1b19a076d2c..f85e4dd31c1 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java @@ -27,6 +27,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import org.hyperledger.besu.ethereum.ConsensusContext; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.chain.Blockchain; @@ -88,7 +89,11 @@ public void setup() { EthProtocolConfiguration.defaultConfig()); ethContext = ethProtocolManager.ethContext(); protocolContext = - new ProtocolContext(localBlockchain, worldStateArchive, null, new BadBlockManager()); + new ProtocolContext( + localBlockchain, + worldStateArchive, + mock(ConsensusContext.class), + new BadBlockManager()); } @Test diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TestNode.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TestNode.java index 0081dc7d948..d042996ce7a 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TestNode.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TestNode.java @@ -27,6 +27,7 @@ import org.hyperledger.besu.crypto.KeyPair; import org.hyperledger.besu.cryptoservices.NodeKey; import org.hyperledger.besu.cryptoservices.NodeKeyUtils; +import org.hyperledger.besu.ethereum.ConsensusContext; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.chain.GenesisState; @@ -135,7 +136,8 @@ public TestNode( final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive(); genesisState.writeStateTo(worldStateArchive.getMutable()); final ProtocolContext protocolContext = - new ProtocolContext(blockchain, worldStateArchive, null, new BadBlockManager()); + new ProtocolContext( + blockchain, worldStateArchive, mock(ConsensusContext.class), new BadBlockManager()); final SyncState syncState = mock(SyncState.class); final SynchronizerConfiguration syncConfig = mock(SynchronizerConfiguration.class); diff --git a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/BlockchainReferenceTestCaseSpec.java b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/BlockchainReferenceTestCaseSpec.java index 7ab0091090b..771ae4672a0 100644 --- a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/BlockchainReferenceTestCaseSpec.java +++ b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/BlockchainReferenceTestCaseSpec.java @@ -27,6 +27,7 @@ import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; +import org.hyperledger.besu.ethereum.core.ConsensusContextFixture; import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; import org.hyperledger.besu.ethereum.core.MutableWorldState; @@ -108,7 +109,11 @@ public BlockchainReferenceTestCaseSpec( this.blockchain = buildBlockchain(genesisBlockHeader); this.sealEngine = sealEngine; this.protocolContext = - new ProtocolContext(this.blockchain, this.worldStateArchive, null, new BadBlockManager()); + new ProtocolContext( + this.blockchain, + this.worldStateArchive, + new ConsensusContextFixture(), + new BadBlockManager()); } public String getNetwork() { From 02722bcd8a71527fd28b600433a4606368d6aa16 Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Tue, 19 Nov 2024 17:10:03 +0100 Subject: [PATCH 34/56] Consolidate all metric collectors into the metrics system (#7877) * Consolidate all metric collectors into the metrics system Signed-off-by: Fabio Di Fabio * Fixes Signed-off-by: Fabio Di Fabio * Do not recreate the Prometheus metric system Signed-off-by: Fabio Di Fabio --------- Signed-off-by: Fabio Di Fabio --- .../jsonrpc/internal/methods/TraceBlock.java | 37 ++--- .../jsonrpc/internal/methods/TraceFilter.java | 28 ++-- .../methods/TraceReplayBlockTransactions.java | 25 ++-- .../methods/JsonRpcMethodsFactory.java | 6 +- .../jsonrpc/methods/TraceJsonRpcMethods.java | 15 +- .../internal/methods/TraceFilterTest.java | 4 +- ethereum/core/build.gradle | 2 - .../ethereum/chain/DefaultBlockchain.java | 32 ++--- .../cache/BonsaiCachedMerkleTrieLoader.java | 13 +- ethereum/p2p/build.gradle | 1 - metrics/core/build.gradle | 1 + .../besu/metrics/ObservableMetricsSystem.java | 31 +---- .../besu/metrics/noop/NoOpMetricsSystem.java | 17 +++ .../opentelemetry/OpenTelemetrySystem.java | 15 ++ .../prometheus/PrometheusMetricsSystem.java | 130 +++++++++++++----- .../besu/metrics/StubMetricsSystem.java | 21 +++ metrics/rocksdb/build.gradle | 2 - .../besu/metrics/rocksdb/RocksDBStats.java | 87 +++++------- plugin-api/build.gradle | 2 +- .../besu/plugin/services/MetricsSystem.java | 46 +++++++ .../services/metrics/ExternalSummary.java | 36 +++++ plugins/rocksdb/build.gradle | 1 - .../rocksdb/RocksDBMetricsFactory.java | 6 +- 23 files changed, 349 insertions(+), 209 deletions(-) create mode 100644 plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/ExternalSummary.java diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceBlock.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceBlock.java index adacf01e764..16798160d8e 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceBlock.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceBlock.java @@ -25,7 +25,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer; 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.tracing.flat.FlatTraceGenerator; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.flat.RewardTraceGenerator; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.api.util.ArrayNodeWrapper; @@ -41,12 +40,11 @@ import org.hyperledger.besu.evm.worldstate.WorldUpdater; import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; -import org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem; +import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; import org.hyperledger.besu.services.pipeline.Pipeline; -import java.util.List; import java.util.Optional; import java.util.concurrent.ExecutionException; @@ -58,10 +56,21 @@ public class TraceBlock extends AbstractBlockParameterMethod { private static final Logger LOG = LoggerFactory.getLogger(TraceBlock.class); private static final ObjectMapper MAPPER = new ObjectMapper(); protected final ProtocolSchedule protocolSchedule; + private final LabelledMetric outputCounter; - public TraceBlock(final ProtocolSchedule protocolSchedule, final BlockchainQueries queries) { + public TraceBlock( + final ProtocolSchedule protocolSchedule, + final BlockchainQueries queries, + final MetricsSystem metricsSystem) { super(queries); this.protocolSchedule = protocolSchedule; + this.outputCounter = + metricsSystem.createLabelledCounter( + BesuMetricCategory.BLOCKCHAIN, + "transactions_traceblock_pipeline_processed_total", + "Number of transactions processed for each block", + "step", + "action"); } @Override @@ -115,14 +124,6 @@ protected ArrayNodeWrapper traceBlock( final ChainUpdater chainUpdater = new ChainUpdater(traceableState); TransactionSource transactionSource = new TransactionSource(block); - final LabelledMetric outputCounter = - new PrometheusMetricsSystem(BesuMetricCategory.DEFAULT_METRIC_CATEGORIES, false) - .createLabelledCounter( - BesuMetricCategory.BLOCKCHAIN, - "transactions_traceblock_pipeline_processed_total", - "Number of transactions processed for each block", - "step", - "action"); DebugOperationTracer debugOperationTracer = new DebugOperationTracer(new TraceOptions(false, false, true), false); ExecuteTransactionStep executeTransactionStep = @@ -173,18 +174,6 @@ protected ArrayNodeWrapper traceBlock( .orElse(emptyResult()); } - protected void generateTracesFromTransactionTraceAndBlock( - final Optional filterParameter, - final List transactionTraces, - final Block block, - final ArrayNodeWrapper resultArrayNode) { - transactionTraces.forEach( - transactionTrace -> - FlatTraceGenerator.generateFromTransactionTraceAndBlock( - protocolSchedule, transactionTrace, block) - .forEachOrdered(resultArrayNode::addPOJO)); - } - protected void generateRewardsFromBlock( final Optional maybeFilterParameter, final Block block, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceFilter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceFilter.java index 74bfec87c29..6be65149cb9 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceFilter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceFilter.java @@ -23,7 +23,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.FilterParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException; -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.processor.TransactionTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; @@ -45,7 +44,7 @@ import org.hyperledger.besu.ethereum.vm.DebugOperationTracer; import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; -import org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem; +import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; import org.hyperledger.besu.services.pipeline.Pipeline; @@ -58,7 +57,6 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.function.Function; -import java.util.function.Supplier; import java.util.stream.Stream; import javax.annotation.Nonnull; @@ -68,17 +66,24 @@ import org.slf4j.LoggerFactory; public class TraceFilter extends TraceBlock { - private static final Logger LOG = LoggerFactory.getLogger(TraceFilter.class); private final Long maxRange; + private final LabelledMetric outputCounter; public TraceFilter( - final Supplier blockTracerSupplier, final ProtocolSchedule protocolSchedule, final BlockchainQueries blockchainQueries, - final Long maxRange) { - super(protocolSchedule, blockchainQueries); + final Long maxRange, + final MetricsSystem metricsSystem) { + super(protocolSchedule, blockchainQueries, metricsSystem); this.maxRange = maxRange; + this.outputCounter = + metricsSystem.createLabelledCounter( + BesuMetricCategory.BLOCKCHAIN, + "transactions_tracefilter_pipeline_processed_total", + "Number of transactions processed for trace_filter", + "step", + "action"); } @Override @@ -157,15 +162,6 @@ private JsonRpcResponse traceFilterWithPipeline( final MainnetTransactionProcessor transactionProcessor = protocolSpec.getTransactionProcessor(); final ChainUpdater chainUpdater = new ChainUpdater(traceableState); - final LabelledMetric outputCounter = - new PrometheusMetricsSystem( - BesuMetricCategory.DEFAULT_METRIC_CATEGORIES, false) - .createLabelledCounter( - BesuMetricCategory.BLOCKCHAIN, - "transactions_tracefilter_pipeline_processed_total", - "Number of transactions processed for trace_filter", - "step", - "action"); DebugOperationTracer debugOperationTracer = new DebugOperationTracer(new TraceOptions(false, false, true), false); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceReplayBlockTransactions.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceReplayBlockTransactions.java index 202d2ddbbbc..51eeebb9592 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceReplayBlockTransactions.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceReplayBlockTransactions.java @@ -39,7 +39,7 @@ import org.hyperledger.besu.ethereum.vm.DebugOperationTracer; import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; -import org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem; +import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; import org.hyperledger.besu.services.pipeline.Pipeline; @@ -57,13 +57,23 @@ public class TraceReplayBlockTransactions extends AbstractBlockParameterMethod { private static final Logger LOG = LoggerFactory.getLogger(TraceReplayBlockTransactions.class); - private final ProtocolSchedule protocolSchedule; private static final ObjectMapper MAPPER = new ObjectMapper(); + private final ProtocolSchedule protocolSchedule; + private final LabelledMetric outputCounter; public TraceReplayBlockTransactions( - final ProtocolSchedule protocolSchedule, final BlockchainQueries queries) { + final ProtocolSchedule protocolSchedule, + final BlockchainQueries queries, + final MetricsSystem metricsSystem) { super(queries); this.protocolSchedule = protocolSchedule; + this.outputCounter = + metricsSystem.createLabelledCounter( + BesuMetricCategory.BLOCKCHAIN, + "transactions_tracereplayblock_pipeline_processed_total", + "Number of transactions processed for each block", + "step", + "action"); } @Override @@ -131,14 +141,7 @@ private ArrayNode traceBlock(final Block block, final TraceTypeParameter traceTy final ChainUpdater chainUpdater = new ChainUpdater(traceableState); final TransactionSource transactionSource = new TransactionSource(block); - final LabelledMetric outputCounter = - new PrometheusMetricsSystem(BesuMetricCategory.DEFAULT_METRIC_CATEGORIES, false) - .createLabelledCounter( - BesuMetricCategory.BLOCKCHAIN, - "transactions_tracereplayblock_pipeline_processed_total", - "Number of transactions processed for each block", - "step", - "action"); + final DebugOperationTracer debugOperationTracer = new DebugOperationTracer(new TraceOptions(false, false, true), false); final ExecuteTransactionStep executeTransactionStep = diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethodsFactory.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethodsFactory.java index 7be34f02290..2e68576fca7 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethodsFactory.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethodsFactory.java @@ -151,7 +151,11 @@ public Map methods( blockchainQueries, protocolSchedule, transactionPool, privacyParameters), new Web3JsonRpcMethods(clientNodeName), new TraceJsonRpcMethods( - blockchainQueries, protocolSchedule, protocolContext, apiConfiguration), + blockchainQueries, + protocolSchedule, + protocolContext, + apiConfiguration, + metricsSystem), new TxPoolJsonRpcMethods(transactionPool), new PluginsJsonRpcMethods(namedPlugins)); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/TraceJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/TraceJsonRpcMethods.java index 6a36bebfcd5..4638e90a625 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/TraceJsonRpcMethods.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/TraceJsonRpcMethods.java @@ -31,6 +31,7 @@ import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.transaction.TransactionSimulator; +import org.hyperledger.besu.plugin.services.MetricsSystem; import java.util.Map; @@ -38,19 +39,21 @@ public class TraceJsonRpcMethods extends ApiGroupJsonRpcMethods { private final BlockchainQueries blockchainQueries; private final ProtocolSchedule protocolSchedule; - private final ApiConfiguration apiConfiguration; private final ProtocolContext protocolContext; + private final MetricsSystem metricsSystem; TraceJsonRpcMethods( final BlockchainQueries blockchainQueries, final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, - final ApiConfiguration apiConfiguration) { + final ApiConfiguration apiConfiguration, + final MetricsSystem metricsSystem) { this.blockchainQueries = blockchainQueries; this.protocolSchedule = protocolSchedule; this.protocolContext = protocolContext; this.apiConfiguration = apiConfiguration; + this.metricsSystem = metricsSystem; } @Override @@ -63,16 +66,16 @@ protected Map create() { final BlockReplay blockReplay = new BlockReplay(protocolSchedule, protocolContext, blockchainQueries.getBlockchain()); return mapOf( - new TraceReplayBlockTransactions(protocolSchedule, blockchainQueries), + new TraceReplayBlockTransactions(protocolSchedule, blockchainQueries, metricsSystem), new TraceFilter( - () -> new BlockTracer(blockReplay), protocolSchedule, blockchainQueries, - apiConfiguration.getMaxTraceFilterRange()), + apiConfiguration.getMaxTraceFilterRange(), + metricsSystem), new TraceGet(() -> new BlockTracer(blockReplay), blockchainQueries, protocolSchedule), new TraceTransaction( () -> new BlockTracer(blockReplay), protocolSchedule, blockchainQueries), - new TraceBlock(protocolSchedule, blockchainQueries), + new TraceBlock(protocolSchedule, blockchainQueries, metricsSystem), new TraceCall( blockchainQueries, protocolSchedule, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceFilterTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceFilterTest.java index c5c03f6b114..8f64d2cb0bd 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceFilterTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceFilterTest.java @@ -26,6 +26,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import java.util.function.Supplier; @@ -69,7 +70,8 @@ public void shouldFailIfParamsExceedMaxRange( new JsonRpcRequest("2.0", "trace_filter", new Object[] {filterParameter})); method = - new TraceFilter(blockTracerSupplier, protocolSchedule, blockchainQueries, maxFilterRange); + new TraceFilter( + protocolSchedule, blockchainQueries, maxFilterRange, new NoOpMetricsSystem()); final JsonRpcResponse response = method.response(request); assertThat(response).isInstanceOf(JsonRpcErrorResponse.class); diff --git a/ethereum/core/build.gradle b/ethereum/core/build.gradle index c5ab4462669..c0f04a76441 100644 --- a/ethereum/core/build.gradle +++ b/ethereum/core/build.gradle @@ -65,8 +65,6 @@ dependencies { implementation 'org.immutables:value-annotations' implementation 'tech.pegasys:jc-kzg-4844' - implementation 'io.prometheus:simpleclient_guava' - implementation 'org.xerial.snappy:snappy-java' annotationProcessor 'org.immutables:value' diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchain.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchain.java index bce94a19153..f6e06f82d2e 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchain.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchain.java @@ -19,6 +19,7 @@ import static java.util.Collections.emptyList; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; +import static org.hyperledger.besu.metrics.BesuMetricCategory.BLOCKCHAIN; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.chain.BlockchainStorage.Updater; @@ -32,7 +33,6 @@ import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; -import org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; import org.hyperledger.besu.util.InvalidConfigurationException; @@ -56,7 +56,6 @@ import com.google.common.cache.CacheBuilder; import com.google.common.collect.Lists; import com.google.common.collect.Streams; -import io.prometheus.client.guava.cache.CacheMetricsCollector; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -134,13 +133,12 @@ private DefaultBlockchain( totalDifficultyCache = Optional.of( CacheBuilder.newBuilder().recordStats().maximumSize(numberOfBlocksToCache).build()); - CacheMetricsCollector cacheMetrics = new CacheMetricsCollector(); - cacheMetrics.addCache("blockHeaders", blockHeadersCache.get()); - cacheMetrics.addCache("blockBodies", blockBodiesCache.get()); - cacheMetrics.addCache("transactionReceipts", transactionReceiptsCache.get()); - cacheMetrics.addCache("totalDifficulty", totalDifficultyCache.get()); - if (metricsSystem instanceof PrometheusMetricsSystem prometheusMetricsSystem) - prometheusMetricsSystem.addCollector(BesuMetricCategory.BLOCKCHAIN, () -> cacheMetrics); + metricsSystem.createGuavaCacheCollector(BLOCKCHAIN, "blockHeaders", blockHeadersCache.get()); + metricsSystem.createGuavaCacheCollector(BLOCKCHAIN, "blockBodies", blockBodiesCache.get()); + metricsSystem.createGuavaCacheCollector( + BLOCKCHAIN, "transactionReceipts", transactionReceiptsCache.get()); + metricsSystem.createGuavaCacheCollector( + BLOCKCHAIN, "totalDifficulty", totalDifficultyCache.get()); } else { blockHeadersCache = Optional.empty(); blockBodiesCache = Optional.empty(); @@ -155,11 +153,11 @@ private DefaultBlockchain( private void createCounters(final MetricsSystem metricsSystem) { gasUsedCounter = metricsSystem.createCounter( - BesuMetricCategory.BLOCKCHAIN, "chain_head_gas_used_counter", "Counter for Gas used"); + BLOCKCHAIN, "chain_head_gas_used_counter", "Counter for Gas used"); numberOfTransactionsCounter = metricsSystem.createCounter( - BesuMetricCategory.BLOCKCHAIN, + BLOCKCHAIN, "chain_head_transaction_count_counter", "Counter for the number of transactions"); } @@ -184,37 +182,37 @@ private void createGauges(final MetricsSystem metricsSystem) { this::getSafeBlockNumber); metricsSystem.createGauge( - BesuMetricCategory.BLOCKCHAIN, + BLOCKCHAIN, "difficulty_total", "Total difficulty of the chainhead", () -> this.getChainHead().getTotalDifficulty().toBigInteger().doubleValue()); metricsSystem.createLongGauge( - BesuMetricCategory.BLOCKCHAIN, + BLOCKCHAIN, "chain_head_timestamp", "Timestamp from the current chain head", () -> getChainHeadHeader().getTimestamp()); metricsSystem.createLongGauge( - BesuMetricCategory.BLOCKCHAIN, + BLOCKCHAIN, "chain_head_gas_used", "Gas used by the current chain head block", () -> getChainHeadHeader().getGasUsed()); metricsSystem.createLongGauge( - BesuMetricCategory.BLOCKCHAIN, + BLOCKCHAIN, "chain_head_gas_limit", "Block gas limit of the current chain head block", () -> getChainHeadHeader().getGasLimit()); metricsSystem.createIntegerGauge( - BesuMetricCategory.BLOCKCHAIN, + BLOCKCHAIN, "chain_head_transaction_count", "Number of transactions in the current chain head block", () -> chainHeadTransactionCount); metricsSystem.createIntegerGauge( - BesuMetricCategory.BLOCKCHAIN, + BLOCKCHAIN, "chain_head_ommer_count", "Number of ommers in the current chain head block", () -> chainHeadOmmerCount); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/cache/BonsaiCachedMerkleTrieLoader.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/cache/BonsaiCachedMerkleTrieLoader.java index 9b9960b5c67..402402bc069 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/cache/BonsaiCachedMerkleTrieLoader.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/cache/BonsaiCachedMerkleTrieLoader.java @@ -14,6 +14,8 @@ */ package org.hyperledger.besu.ethereum.trie.diffbased.bonsai.cache; +import static org.hyperledger.besu.metrics.BesuMetricCategory.BLOCKCHAIN; + import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.StorageSlotKey; @@ -22,9 +24,7 @@ import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.diffbased.common.StorageSubscriber; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; -import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.metrics.ObservableMetricsSystem; -import org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem; import java.util.Optional; import java.util.concurrent.CompletableFuture; @@ -33,7 +33,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; -import io.prometheus.client.guava.cache.CacheMetricsCollector; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; @@ -47,12 +46,8 @@ public class BonsaiCachedMerkleTrieLoader implements StorageSubscriber { CacheBuilder.newBuilder().recordStats().maximumSize(STORAGE_CACHE_SIZE).build(); public BonsaiCachedMerkleTrieLoader(final ObservableMetricsSystem metricsSystem) { - - CacheMetricsCollector cacheMetrics = new CacheMetricsCollector(); - cacheMetrics.addCache("accountsNodes", accountNodes); - cacheMetrics.addCache("storageNodes", storageNodes); - if (metricsSystem instanceof PrometheusMetricsSystem prometheusMetricsSystem) - prometheusMetricsSystem.addCollector(BesuMetricCategory.BLOCKCHAIN, () -> cacheMetrics); + metricsSystem.createGuavaCacheCollector(BLOCKCHAIN, "accountsNodes", accountNodes); + metricsSystem.createGuavaCacheCollector(BLOCKCHAIN, "storageNodes", storageNodes); } public void preLoadAccount( diff --git a/ethereum/p2p/build.gradle b/ethereum/p2p/build.gradle index 971504a25af..7cfcf2f8d58 100644 --- a/ethereum/p2p/build.gradle +++ b/ethereum/p2p/build.gradle @@ -43,7 +43,6 @@ dependencies { implementation 'com.google.guava:guava' implementation 'dnsjava:dnsjava' implementation 'io.netty:netty-transport-native-unix-common' - implementation 'io.prometheus:simpleclient' implementation 'io.vertx:vertx-core' implementation 'io.tmio:tuweni-bytes' diff --git a/metrics/core/build.gradle b/metrics/core/build.gradle index 1438a198ae5..160093c7490 100644 --- a/metrics/core/build.gradle +++ b/metrics/core/build.gradle @@ -57,6 +57,7 @@ dependencies { implementation 'io.prometheus:simpleclient' implementation 'io.prometheus:simpleclient_common' + implementation 'io.prometheus:simpleclient_guava' implementation 'io.prometheus:simpleclient_hotspot' implementation 'io.prometheus:simpleclient_pushgateway' implementation 'io.vertx:vertx-core' diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/ObservableMetricsSystem.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/ObservableMetricsSystem.java index 8090d28fc1d..98e7a8b634f 100644 --- a/metrics/core/src/main/java/org/hyperledger/besu/metrics/ObservableMetricsSystem.java +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/ObservableMetricsSystem.java @@ -17,42 +17,25 @@ import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; -import java.util.Set; import java.util.stream.Stream; -/** The interface Observable metrics system. */ +/** The observable metrics system is used to inspect metrics for debug reasons */ public interface ObservableMetricsSystem extends MetricsSystem { - /** - * Stream observations. + * Stream observations by category * * @param category the category - * @return the stream + * @return the observations stream */ Stream streamObservations(MetricCategory category); /** - * Stream observations. + * Stream observations * - * @return the stream + * @return the observations stream */ Stream streamObservations(); - /** - * Provides an immutable view into the metric categories enabled for metric collection. - * - * @return the set of enabled metric categories. - */ - Set getEnabledCategories(); - - /** - * Checks if a particular category of metrics is enabled. - * - * @param category the category to check - * @return true if the category is enabled, false otherwise - */ - default boolean isCategoryEnabled(final MetricCategory category) { - return getEnabledCategories().stream() - .anyMatch(metricCategory -> metricCategory.getName().equals(category.getName())); - } + /** Unregister all the collectors and perform other cleanup tasks */ + void shutdown(); } diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/noop/NoOpMetricsSystem.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/noop/NoOpMetricsSystem.java index 5f876fa4d80..d3b6c4aadc5 100644 --- a/metrics/core/src/main/java/org/hyperledger/besu/metrics/noop/NoOpMetricsSystem.java +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/noop/NoOpMetricsSystem.java @@ -17,6 +17,7 @@ import org.hyperledger.besu.metrics.ObservableMetricsSystem; import org.hyperledger.besu.metrics.Observation; import org.hyperledger.besu.plugin.services.metrics.Counter; +import org.hyperledger.besu.plugin.services.metrics.ExternalSummary; import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; @@ -27,9 +28,11 @@ import java.util.List; import java.util.Set; import java.util.function.DoubleSupplier; +import java.util.function.Supplier; import java.util.stream.Stream; import com.google.common.base.Preconditions; +import com.google.common.cache.Cache; /** The NoOp metrics system. */ public class NoOpMetricsSystem implements ObservableMetricsSystem { @@ -113,6 +116,13 @@ public LabelledMetric createSimpleLabelledTimer( return getOperationTimerLabelledMetric(labelNames.length); } + @Override + public void trackExternalSummary( + final MetricCategory category, + final String name, + final String help, + final Supplier summarySupplier) {} + @Override public LabelledMetric createLabelledTimer( final MetricCategory category, @@ -144,6 +154,10 @@ public void createGauge( final String help, final DoubleSupplier valueSupplier) {} + @Override + public void createGuavaCacheCollector( + final MetricCategory category, final String name, final Cache cache) {} + @Override public LabelledGauge createLabelledGauge( final MetricCategory category, @@ -187,6 +201,9 @@ public Set getEnabledCategories() { return Collections.emptySet(); } + @Override + public void shutdown() {} + /** * The Label counting NoOp metric. * diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetrySystem.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetrySystem.java index a399b283734..a17c773813c 100644 --- a/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetrySystem.java +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetrySystem.java @@ -20,6 +20,7 @@ import org.hyperledger.besu.metrics.StandardMetricCategory; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; +import org.hyperledger.besu.plugin.services.metrics.ExternalSummary; import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; @@ -40,9 +41,11 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import java.util.function.DoubleSupplier; +import java.util.function.Supplier; import java.util.stream.Stream; import javax.inject.Singleton; +import com.google.common.cache.Cache; import com.google.common.collect.ImmutableSet; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; @@ -242,6 +245,13 @@ public LabelledMetric createSimpleLabelledTimer( return createLabelledTimer(category, name, help, labelNames); } + @Override + public void trackExternalSummary( + final MetricCategory category, + final String name, + final String help, + final Supplier summarySupplier) {} + @Override public LabelledMetric createLabelledTimer( final MetricCategory category, @@ -277,6 +287,10 @@ public void createGauge( } } + @Override + public void createGuavaCacheCollector( + final MetricCategory category, final String name, final Cache cache) {} + @Override public LabelledGauge createLabelledGauge( final MetricCategory category, @@ -376,6 +390,7 @@ private void collectGC() { } /** Shuts down the OpenTelemetry exporters, blocking until they have completed orderly. */ + @Override public void shutdown() { final CompletableResultCode result = CompletableResultCode.ofAll( diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystem.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystem.java index 653f448311f..b001eb0b3be 100644 --- a/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystem.java +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystem.java @@ -18,6 +18,7 @@ import org.hyperledger.besu.metrics.Observation; import org.hyperledger.besu.metrics.StandardMetricCategory; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; +import org.hyperledger.besu.plugin.services.metrics.ExternalSummary; import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; @@ -34,6 +35,7 @@ import java.util.function.Supplier; import java.util.stream.Stream; +import com.google.common.cache.Cache; import com.google.common.collect.ImmutableSet; import io.prometheus.client.Collector; import io.prometheus.client.Collector.MetricFamilySamples; @@ -42,6 +44,7 @@ import io.prometheus.client.Counter; import io.prometheus.client.Histogram; import io.prometheus.client.Summary; +import io.prometheus.client.guava.cache.CacheMetricsCollector; import io.prometheus.client.hotspot.BufferPoolsExports; import io.prometheus.client.hotspot.ClassLoadingExports; import io.prometheus.client.hotspot.GarbageCollectorExports; @@ -52,6 +55,7 @@ /** The Prometheus metrics system. */ public class PrometheusMetricsSystem implements ObservableMetricsSystem { + private static final List EXTERNAL_SUMMARY_LABELS = List.of("quantile"); private final Map> collectors = new ConcurrentHashMap<>(); private final CollectorRegistry registry = new CollectorRegistry(true); @@ -60,6 +64,9 @@ public class PrometheusMetricsSystem implements ObservableMetricsSystem { private final Map> cachedTimers = new ConcurrentHashMap<>(); private final Set totalSuffixedCounters = new ConcurrentHashSet<>(); + private final Map guavaCacheCollectors = + new ConcurrentHashMap<>(); + private final Set guavaCacheNames = new ConcurrentHashSet<>(); private final Set enabledCategories; private final boolean timersEnabled; @@ -78,12 +85,16 @@ public PrometheusMetricsSystem( /** Init. */ public void init() { - addCollector(StandardMetricCategory.PROCESS, StandardExports::new); - addCollector(StandardMetricCategory.JVM, MemoryPoolsExports::new); - addCollector(StandardMetricCategory.JVM, BufferPoolsExports::new); - addCollector(StandardMetricCategory.JVM, GarbageCollectorExports::new); - addCollector(StandardMetricCategory.JVM, ThreadExports::new); - addCollector(StandardMetricCategory.JVM, ClassLoadingExports::new); + if (isCategoryEnabled(StandardMetricCategory.PROCESS)) { + registerCollector(StandardMetricCategory.PROCESS, new StandardExports()); + } + if (isCategoryEnabled(StandardMetricCategory.JVM)) { + registerCollector(StandardMetricCategory.JVM, new MemoryPoolsExports()); + registerCollector(StandardMetricCategory.JVM, new BufferPoolsExports()); + registerCollector(StandardMetricCategory.JVM, new GarbageCollectorExports()); + registerCollector(StandardMetricCategory.JVM, new ThreadExports()); + registerCollector(StandardMetricCategory.JVM, new ClassLoadingExports()); + } } @Override @@ -103,7 +114,7 @@ public LabelledMetric crea (k) -> { if (isCategoryEnabled(category)) { final Counter counter = Counter.build(metricName, help).labelNames(labelNames).create(); - addCollectorUnchecked(category, counter); + registerCollector(category, counter); return new PrometheusCounter(counter); } else { return NoOpMetricsSystem.getCounterLabelledMetric(labelNames.length); @@ -132,7 +143,7 @@ public LabelledMetric createLabelledTimer( .quantile(1.0, 0) .labelNames(labelNames) .create(); - addCollectorUnchecked(category, summary); + registerCollector(category, summary); return new PrometheusTimer(summary); } else { return NoOpMetricsSystem.getOperationTimerLabelledMetric(labelNames.length); @@ -153,7 +164,7 @@ public LabelledMetric createSimpleLabelledTimer( if (timersEnabled && isCategoryEnabled(category)) { final Histogram histogram = Histogram.build(metricName, help).labelNames(labelNames).buckets(1D).create(); - addCollectorUnchecked(category, histogram); + registerCollector(category, histogram); return new PrometheusSimpleTimer(histogram); } else { return NoOpMetricsSystem.getOperationTimerLabelledMetric(labelNames.length); @@ -170,7 +181,61 @@ public void createGauge( final String metricName = convertToPrometheusName(category, name); if (isCategoryEnabled(category)) { final Collector collector = new CurrentValueCollector(metricName, help, valueSupplier); - addCollectorUnchecked(category, collector); + registerCollector(category, collector); + } + } + + @Override + public void trackExternalSummary( + final MetricCategory category, + final String name, + final String help, + final Supplier summarySupplier) { + if (isCategoryEnabled(category)) { + final var externalSummaryCollector = + new Collector() { + @Override + public List collect() { + final var externalSummary = summarySupplier.get(); + + final var quantileValues = + externalSummary.quantiles().stream() + .map( + quantile -> + new Sample( + name, + EXTERNAL_SUMMARY_LABELS, + List.of(Double.toString(quantile.quantile())), + quantile.value())) + .toList(); + + return List.of( + new MetricFamilySamples( + name, Type.SUMMARY, "RocksDB histogram for " + name, quantileValues)); + } + }; + + registerCollector(category, externalSummaryCollector); + } + } + + @Override + public void createGuavaCacheCollector( + final MetricCategory category, final String name, final Cache cache) { + if (isCategoryEnabled(category)) { + if (guavaCacheNames.contains(name)) { + throw new IllegalStateException("Cache already registered: " + name); + } + guavaCacheNames.add(name); + final var guavaCacheCollector = + guavaCacheCollectors.computeIfAbsent( + category, + unused -> { + final var cmc = new CacheMetricsCollector(); + registerCollector(category, cmc); + return cmc; + }); + guavaCacheCollector.addCache(name, cache); } } @@ -183,46 +248,33 @@ public LabelledGauge createLabelledGauge( final String metricName = convertToPrometheusName(category, name); if (isCategoryEnabled(category)) { final PrometheusGauge gauge = new PrometheusGauge(metricName, help, List.of(labelNames)); - addCollectorUnchecked(category, gauge); + registerCollector(category, gauge); return gauge; } return NoOpMetricsSystem.getLabelledGauge(labelNames.length); } - /** - * Add collector. - * - * @param category the category - * @param metricSupplier the metric supplier - */ - public void addCollector( - final MetricCategory category, final Supplier metricSupplier) { - if (isCategoryEnabled(category)) { - addCollectorUnchecked(category, metricSupplier.get()); - } - } - - private void addCollectorUnchecked(final MetricCategory category, final Collector metric) { - final Collection metrics = + private void registerCollector(final MetricCategory category, final Collector collector) { + final Collection categoryCollectors = this.collectors.computeIfAbsent( category, key -> Collections.newSetFromMap(new ConcurrentHashMap<>())); final List newSamples = - metric.collect().stream().map(metricFamilySamples -> metricFamilySamples.name).toList(); + collector.collect().stream().map(metricFamilySamples -> metricFamilySamples.name).toList(); - metrics.stream() + categoryCollectors.stream() .filter( - collector -> - collector.collect().stream() + c -> + c.collect().stream() .anyMatch(metricFamilySamples -> newSamples.contains(metricFamilySamples.name))) .findFirst() .ifPresent( - collector -> { - metrics.remove(collector); - registry.unregister(collector); + c -> { + categoryCollectors.remove(c); + registry.unregister(c); }); - metrics.add(metric.register(registry)); + categoryCollectors.add(collector.register(registry)); } @Override @@ -237,6 +289,16 @@ public Stream streamObservations() { return collectors.keySet().stream().flatMap(this::streamObservations); } + @Override + public void shutdown() { + registry.clear(); + collectors.clear(); + cachedCounters.clear(); + cachedTimers.clear(); + guavaCacheCollectors.clear(); + guavaCacheNames.clear(); + } + private Stream convertSamplesToObservations( final MetricCategory category, final MetricFamilySamples familySamples) { return familySamples.samples.stream() diff --git a/metrics/core/src/test-support/java/org/hyperledger/besu/metrics/StubMetricsSystem.java b/metrics/core/src/test-support/java/org/hyperledger/besu/metrics/StubMetricsSystem.java index 2e0ea006db0..13f16ef0a0c 100644 --- a/metrics/core/src/test-support/java/org/hyperledger/besu/metrics/StubMetricsSystem.java +++ b/metrics/core/src/test-support/java/org/hyperledger/besu/metrics/StubMetricsSystem.java @@ -18,6 +18,7 @@ import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; +import org.hyperledger.besu.plugin.services.metrics.ExternalSummary; import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; @@ -29,8 +30,11 @@ import java.util.Map; import java.util.Set; import java.util.function.DoubleSupplier; +import java.util.function.Supplier; import java.util.stream.Stream; +import com.google.common.cache.Cache; + public class StubMetricsSystem implements ObservableMetricsSystem { private final Map counters = new HashMap<>(); @@ -84,6 +88,13 @@ public LabelledMetric createSimpleLabelledTimer( return labelValues -> NoOpMetricsSystem.NO_OP_OPERATION_TIMER; } + @Override + public void trackExternalSummary( + final MetricCategory category, + final String name, + final String help, + final Supplier summarySupplier) {} + @Override public void createGauge( final MetricCategory category, @@ -93,6 +104,10 @@ public void createGauge( gauges.put(name, valueSupplier); } + @Override + public void createGuavaCacheCollector( + final MetricCategory category, final String name, final Cache cache) {} + public double getGaugeValue(final String name) { final DoubleSupplier gauge = gauges.get(name); if (gauge == null) { @@ -116,6 +131,12 @@ public Set getEnabledCategories() { return Collections.emptySet(); } + @Override + public void shutdown() { + counters.clear(); + gauges.clear(); + } + public static class StubLabelledCounter implements LabelledMetric { private final Map, StubCounter> metrics = new HashMap<>(); diff --git a/metrics/rocksdb/build.gradle b/metrics/rocksdb/build.gradle index d46488daf8f..de312ab708a 100644 --- a/metrics/rocksdb/build.gradle +++ b/metrics/rocksdb/build.gradle @@ -40,7 +40,5 @@ dependencies { implementation project(':metrics:core') implementation project(':plugin-api') - implementation 'com.google.guava:guava' - implementation 'io.prometheus:simpleclient' implementation 'org.rocksdb:rocksdbjni' } diff --git a/metrics/rocksdb/src/main/java/org/hyperledger/besu/metrics/rocksdb/RocksDBStats.java b/metrics/rocksdb/src/main/java/org/hyperledger/besu/metrics/rocksdb/RocksDBStats.java index edb837985dd..c3c5fef2c11 100644 --- a/metrics/rocksdb/src/main/java/org/hyperledger/besu/metrics/rocksdb/RocksDBStats.java +++ b/metrics/rocksdb/src/main/java/org/hyperledger/besu/metrics/rocksdb/RocksDBStats.java @@ -16,15 +16,14 @@ import static org.hyperledger.besu.metrics.BesuMetricCategory.KVSTORE_ROCKSDB_STATS; -import org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem; +import org.hyperledger.besu.plugin.services.MetricsSystem; +import org.hyperledger.besu.plugin.services.metrics.ExternalSummary; +import org.hyperledger.besu.plugin.services.metrics.ExternalSummary.Quantile; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Locale; -import io.prometheus.client.Collector; import org.rocksdb.HistogramData; import org.rocksdb.HistogramType; import org.rocksdb.Statistics; @@ -32,22 +31,9 @@ /** The Rocks db stats. */ public class RocksDBStats { - - /** The Labels. */ - static final List LABELS = Collections.singletonList("quantile"); - - /** The Label 50. */ - static final List LABEL_50 = Collections.singletonList("0.5"); - - /** The Label 95. */ - static final List LABEL_95 = Collections.singletonList("0.95"); - - /** The Label 99. */ - static final List LABEL_99 = Collections.singletonList("0.99"); - - /** The constant TICKERS. */ + /** The constant TICKER_TYPES. */ // Tickers - RocksDB equivalent of counters - static final TickerType[] TICKERS = { + static final TickerType[] TICKER_TYPES = { TickerType.BLOCK_CACHE_ADD, TickerType.BLOCK_CACHE_HIT, TickerType.BLOCK_CACHE_ADD_FAILURES, @@ -133,9 +119,9 @@ public class RocksDBStats { TickerType.NUMBER_MULTIGET_KEYS_FOUND, }; - /** The constant HISTOGRAMS. */ + /** The constant HISTOGRAM_TYPES. */ // Histograms - treated as prometheus summaries - static final HistogramType[] HISTOGRAMS = { + static final HistogramType[] HISTOGRAM_TYPES = { HistogramType.DB_GET, HistogramType.DB_WRITE, HistogramType.COMPACTION_TIME, @@ -175,47 +161,40 @@ private RocksDBStats() {} * @param category the category */ public static void registerRocksDBMetrics( - final Statistics stats, - final PrometheusMetricsSystem metricsSystem, - final MetricCategory category) { - if (!metricsSystem.isCategoryEnabled(category)) { - return; - } - for (final TickerType ticker : TICKERS) { - final String promCounterName = ticker.name().toLowerCase(Locale.ROOT); + final Statistics stats, final MetricsSystem metricsSystem, final MetricCategory category) { + + for (final var tickerType : TICKER_TYPES) { + final String promCounterName = tickerType.name().toLowerCase(Locale.ROOT); metricsSystem.createLongGauge( category, promCounterName, - "RocksDB reported statistics for " + ticker.name(), - () -> stats.getTickerCount(ticker)); + "RocksDB reported statistics for " + tickerType.name(), + () -> stats.getTickerCount(tickerType)); } - for (final HistogramType histogram : HISTOGRAMS) { - metricsSystem.addCollector(category, () -> histogramToCollector(stats, histogram)); + for (final var histogramType : HISTOGRAM_TYPES) { + + metricsSystem.trackExternalSummary( + KVSTORE_ROCKSDB_STATS, + KVSTORE_ROCKSDB_STATS.getName() + "_" + histogramType.name().toLowerCase(Locale.ROOT), + "RocksDB histogram for " + histogramType.name(), + () -> provideExternalSummary(stats, histogramType)); } } - private static Collector histogramToCollector( - final Statistics stats, final HistogramType histogram) { - return new Collector() { - final String metricName = - KVSTORE_ROCKSDB_STATS.getName() + "_" + histogram.name().toLowerCase(Locale.ROOT); + private static ExternalSummary provideExternalSummary( + final Statistics stats, final HistogramType histogramType) { + + final HistogramData data = stats.getHistogramData(histogramType); - @Override - public List collect() { - final HistogramData data = stats.getHistogramData(histogram); - return Collections.singletonList( - new MetricFamilySamples( - metricName, - Type.SUMMARY, - "RocksDB histogram for " + metricName, - Arrays.asList( - new MetricFamilySamples.Sample(metricName, LABELS, LABEL_50, data.getMedian()), - new MetricFamilySamples.Sample( - metricName, LABELS, LABEL_95, data.getPercentile95()), - new MetricFamilySamples.Sample( - metricName, LABELS, LABEL_99, data.getPercentile99())))); - } - }; + return new ExternalSummary( + data.getCount(), + data.getSum(), + List.of( + new Quantile(0.0, data.getMin()), + new Quantile(0.5, data.getMedian()), + new Quantile(0.95, data.getPercentile95()), + new Quantile(0.99, data.getPercentile99()), + new Quantile(1.0, data.getMax()))); } } diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index c7ec6728674..2d3d5191df4 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -71,7 +71,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = '8rPIE3fYl48RPRQXxYhMk559e/r+wHSKU9bGSJmruKQ=' + knownHash = 'aYWbsgPoKTGDgq9d4QUBvQEaZYbKNJGMiBufzyKnusA=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/MetricsSystem.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/MetricsSystem.java index 80e02a6dba7..744bca4eb3e 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/MetricsSystem.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/MetricsSystem.java @@ -15,14 +15,19 @@ package org.hyperledger.besu.plugin.services; import org.hyperledger.besu.plugin.services.metrics.Counter; +import org.hyperledger.besu.plugin.services.metrics.ExternalSummary; import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; import org.hyperledger.besu.plugin.services.metrics.OperationTimer; +import java.util.Set; import java.util.function.DoubleSupplier; import java.util.function.IntSupplier; import java.util.function.LongSupplier; +import java.util.function.Supplier; + +import com.google.common.cache.Cache; /** An interface for creating various Metrics components. */ public interface MetricsSystem extends BesuService { @@ -159,4 +164,45 @@ default void createLongGauge( final LongSupplier valueSupplier) { createGauge(category, name, help, () -> (double) valueSupplier.getAsLong()); } + + /** + * Track a summary that is computed externally to this metric system. Useful when existing + * libraries calculate the summary data on their own, and we want to export that summary via the + * configured metric system. A notable example are RocksDB statistics. + * + * @param category The {@link MetricCategory} this external summary is assigned to. + * @param name A name for the metric. + * @param help A human readable description of the metric. + * @param summarySupplier A supplier to retrieve the summary data when needed. + */ + void trackExternalSummary( + MetricCategory category, String name, String help, Supplier summarySupplier); + + /** + * Collect metrics from Guava cache. + * + * @param category The {@link MetricCategory} this Guava cache is assigned to. + * @param name the name to identify this Guava cache, must be unique. + * @param cache the Guava cache + */ + void createGuavaCacheCollector(MetricCategory category, String name, Cache cache); + + /** + * Provides an immutable view into the metric categories enabled for metric collection. + * + * @return the set of enabled metric categories. + */ + Set getEnabledCategories(); + + /** + * Checks if a particular category of metrics is enabled. + * + * @param category the category to check + * @return true if the category is enabled, false otherwise + */ + default boolean isCategoryEnabled(final MetricCategory category) { + return getEnabledCategories().stream() + .map(MetricCategory::getName) + .anyMatch(category.getName()::equals); + } } diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/ExternalSummary.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/ExternalSummary.java new file mode 100644 index 00000000000..5e7e38b76af --- /dev/null +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/ExternalSummary.java @@ -0,0 +1,36 @@ +/* + * Copyright contributors to 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.plugin.services.metrics; + +import java.util.List; + +/** + * Record of summary data the is kept outside the metric system. Useful when existing libraries + * calculate the summary data on their own, and we want to export that summary via the configured + * metric system. A notable example are RocksDB statistics. + * + * @param count the number of observations + * @param sum the sum of all the observations + * @param quantiles a list of quantiles with values + */ +public record ExternalSummary(long count, double sum, List quantiles) { + /** + * Represent a single quantile and its value + * + * @param quantile the quantile + * @param value the value + */ + public record Quantile(double quantile, double value) {} +} diff --git a/plugins/rocksdb/build.gradle b/plugins/rocksdb/build.gradle index d487cf9824c..a2315398e13 100644 --- a/plugins/rocksdb/build.gradle +++ b/plugins/rocksdb/build.gradle @@ -46,7 +46,6 @@ dependencies { implementation 'com.google.guava:guava' implementation 'info.picocli:picocli' implementation 'io.opentelemetry:opentelemetry-api' - implementation 'io.prometheus:simpleclient' implementation 'io.tmio:tuweni-bytes' implementation 'org.rocksdb:rocksdbjni' implementation project(path: ':ethereum:core') diff --git a/plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/RocksDBMetricsFactory.java b/plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/RocksDBMetricsFactory.java index bf781d300a7..f5c666184b6 100644 --- a/plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/RocksDBMetricsFactory.java +++ b/plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/RocksDBMetricsFactory.java @@ -15,7 +15,6 @@ package org.hyperledger.besu.plugin.services.storage.rocksdb; import org.hyperledger.besu.metrics.BesuMetricCategory; -import org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem; import org.hyperledger.besu.metrics.rocksdb.RocksDBStats; import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; @@ -107,10 +106,7 @@ public RocksDBMetrics create( "database") .labels(rocksDbConfiguration.getLabel()); - if (metricsSystem instanceof PrometheusMetricsSystem) { - RocksDBStats.registerRocksDBMetrics( - stats, (PrometheusMetricsSystem) metricsSystem, statsDbMetricCategory); - } + RocksDBStats.registerRocksDBMetrics(stats, metricsSystem, statsDbMetricCategory); metricsSystem.createLongGauge( rocksDbMetricCategory, From 58acfcea78164714d19dfbd373f240e6de10f68f Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Tue, 19 Nov 2024 18:19:53 +0100 Subject: [PATCH 35/56] Add support for TransactionPoolService in acceptance tests (#7861) Signed-off-by: Fabio Di Fabio --- .../besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java index 4544872d5c0..6f9ed42828a 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java @@ -75,6 +75,7 @@ import org.hyperledger.besu.plugin.services.TransactionSimulationService; import org.hyperledger.besu.plugin.services.metrics.MetricCategoryRegistry; import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBPlugin; +import org.hyperledger.besu.plugin.services.transactionpool.TransactionPoolService; import org.hyperledger.besu.services.BesuConfigurationImpl; import org.hyperledger.besu.services.BesuEventsImpl; import org.hyperledger.besu.services.BesuPluginContextImpl; @@ -85,6 +86,7 @@ import org.hyperledger.besu.services.RpcEndpointServiceImpl; import org.hyperledger.besu.services.SecurityModuleServiceImpl; import org.hyperledger.besu.services.StorageServiceImpl; +import org.hyperledger.besu.services.TransactionPoolServiceImpl; import org.hyperledger.besu.services.TransactionPoolValidatorServiceImpl; import org.hyperledger.besu.services.TransactionSelectionServiceImpl; import org.hyperledger.besu.services.TransactionSimulationServiceImpl; @@ -215,6 +217,9 @@ public void startNode(final BesuNode node) { besuController.getTransactionPool(), besuController.getSyncState(), besuController.getProtocolContext().getBadBlockManager())); + besuPluginContext.addService( + TransactionPoolService.class, + new TransactionPoolServiceImpl(besuController.getTransactionPool())); component.rpcEndpointService().init(runner.getInProcessRpcMethods()); From 2384c09a82b0b6ef69a54cbe6a1c935d666a7f1b Mon Sep 17 00:00:00 2001 From: Vaidik Date: Wed, 20 Nov 2024 02:14:55 +0530 Subject: [PATCH 36/56] Fix #7810 (#7867) * fix-#7810 Signed-off-by: vaidikcode * fix-#7810 Signed-off-by: vaidikcode --------- Co-authored-by: Sally MacFarlane --- .../besu/controller/BesuControllerBuilder.java | 11 +---------- .../ConsensusScheduleBesuControllerBuilder.java | 5 ----- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java index b3cbab5cc93..831429a02f6 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java @@ -625,7 +625,7 @@ public BesuController build() { ethereumWireProtocolConfiguration.isLegacyEth64ForkIdEnabled()); final EthPeers ethPeers = new EthPeers( - getSupportedProtocol(), + EthProtocol.NAME, currentProtocolSpecSupplier, clock, metricsSystem, @@ -1022,15 +1022,6 @@ protected abstract ConsensusContext createConsensusContext( final WorldStateArchive worldStateArchive, final ProtocolSchedule protocolSchedule); - /** - * Gets supported protocol. - * - * @return the supported protocol - */ - protected String getSupportedProtocol() { - return EthProtocol.NAME; - } - /** * Create eth protocol manager eth protocol manager. * diff --git a/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java index c70367aed62..31f84b6ae04 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java @@ -228,11 +228,6 @@ protected void validateContext(final ProtocolContext context) { besuControllerBuilderSchedule.get(GENESIS_BLOCK_NUMBER).validateContext(context); } - @Override - protected String getSupportedProtocol() { - return besuControllerBuilderSchedule.get(0L).getSupportedProtocol(); - } - @Override protected EthProtocolManager createEthProtocolManager( final ProtocolContext protocolContext, From 8b7ca2017697f08bbf49edef2c80e10513bdd3a7 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Wed, 20 Nov 2024 08:16:33 +1000 Subject: [PATCH 37/56] eth_call overrides (#7801) * add state and account overrides Signed-off-by: Sally MacFarlane --------- Signed-off-by: Sally MacFarlane Co-authored-by: Fabio Di Fabio --- CHANGELOG.md | 1 + .../api/jsonrpc/internal/methods/EthCall.java | 20 ++ .../internal/methods/TraceCallMany.java | 7 +- .../jsonrpc/internal/methods/EthCallTest.java | 81 ++++++-- .../jsonrpc/eth/eth_call_overrides_empty.json | 24 +++ .../jsonrpc/eth/eth_call_stateOverride.json | 32 +++ ...all_stateOverride_insufficientBalance.json | 34 ++++ .../transaction/TransactionSimulator.java | 66 +++++- .../besu/ethereum/util/AccountOverride.java | 147 ++++++++++++++ .../ethereum/util/AccountOverrideMap.java | 27 +++ .../transaction/TransactionSimulatorTest.java | 41 ++++ .../util/AccountOverrideParameterTest.java | 188 ++++++++++++++++++ 12 files changed, 647 insertions(+), 21 deletions(-) create mode 100644 ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_overrides_empty.json create mode 100644 ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_stateOverride.json create mode 100644 ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_stateOverride_insufficientBalance.json create mode 100644 ethereum/core/src/main/java/org/hyperledger/besu/ethereum/util/AccountOverride.java create mode 100644 ethereum/core/src/main/java/org/hyperledger/besu/ethereum/util/AccountOverrideMap.java create mode 100644 ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/AccountOverrideParameterTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index a0a53280feb..2efa312d263 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - Update Java dependencies [#7786](https://github.com/hyperledger/besu/pull/7786) - Add a method to get all the transaction in the pool, to the `TransactionPoolService`, to easily access the transaction pool content from plugins [#7813](https://github.com/hyperledger/besu/pull/7813) - Add a method to check if a metric category is enabled to the plugin API [#7832](https://github.com/hyperledger/besu/pull/7832) +- Add account and state overrides to `eth_call` and `eth_estimateGas` [#7801](https://github.com/hyperledger/besu/pull/7801) ### Bug fixes - Fix registering new metric categories from plugins [#7825](https://github.com/hyperledger/besu/pull/7825) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java index 0e0318f9c2b..5f736e8d5a9 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java @@ -23,6 +23,7 @@ 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.exception.InvalidJsonRpcRequestException; 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.parameters.JsonRpcParameter.JsonRpcParameterException; @@ -40,8 +41,13 @@ import org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason; import org.hyperledger.besu.ethereum.transaction.TransactionSimulator; import org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult; +import org.hyperledger.besu.ethereum.util.AccountOverrideMap; import org.hyperledger.besu.evm.tracing.OperationTracer; +import java.util.Optional; + +import com.google.common.annotations.VisibleForTesting; + public class EthCall extends AbstractBlockParameterOrBlockHashMethod { private final TransactionSimulator transactionSimulator; @@ -81,10 +87,13 @@ protected Object resultByBlockHash(final JsonRpcRequestContext request, final Ha protected Object resultByBlockHeader( final JsonRpcRequestContext request, final BlockHeader header) { JsonCallParameter callParams = JsonCallParameterUtil.validateAndGetCallParams(request); + Optional maybeStateOverrides = getAddressAccountOverrideMap(request); + // TODO implement for block overrides return transactionSimulator .process( callParams, + maybeStateOverrides, buildTransactionValidationParams(header, callParams), OperationTracer.NO_TRACING, (mutableWorldState, transactionSimulatorResult) -> @@ -108,6 +117,17 @@ protected Object resultByBlockHeader( .orElse(errorResponse(request, INTERNAL_ERROR)); } + @VisibleForTesting + protected Optional getAddressAccountOverrideMap( + final JsonRpcRequestContext request) { + try { + return request.getOptionalParameter(2, AccountOverrideMap.class); + } catch (JsonRpcParameterException e) { + throw new InvalidJsonRpcRequestException( + "Invalid account overrides parameter (index 2)", RpcErrorType.INVALID_CALL_PARAMS, e); + } + } + @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { return (JsonRpcResponse) handleParamTypes(requestContext); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java index 10d4018bce2..1601241db62 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java @@ -160,7 +160,12 @@ private JsonNode getSingleCallResult( new DebugOperationTracer(buildTraceOptions(traceTypes), false); final Optional maybeSimulatorResult = transactionSimulator.processWithWorldUpdater( - callParameter, buildTransactionValidationParams(), tracer, header, worldUpdater); + callParameter, + Optional.empty(), + buildTransactionValidationParams(), + tracer, + header, + worldUpdater); LOG.trace("Executing {} call for transaction {}", traceTypeParameter, callParameter); if (maybeSimulatorResult.isEmpty()) { diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java index 8b8ff67cd81..1ba9839b66d 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java @@ -51,6 +51,8 @@ import org.hyperledger.besu.ethereum.transaction.PreCloseStateHandler; import org.hyperledger.besu.ethereum.transaction.TransactionSimulator; import org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult; +import org.hyperledger.besu.ethereum.util.AccountOverride; +import org.hyperledger.besu.ethereum.util.AccountOverrideMap; import java.util.Optional; @@ -92,6 +94,33 @@ public void shouldReturnCorrectMethodName() { assertThat(method.getName()).isEqualTo("eth_call"); } + @Test + public void noAccountOverrides() { + final JsonRpcRequestContext request = ethCallRequest(callParameter(), "latest"); + Optional overrideMap = method.getAddressAccountOverrideMap(request); + assertThat(overrideMap.isPresent()).isFalse(); + } + + @Test + public void someAccountOverrides() { + AccountOverrideMap expectedOverrides = new AccountOverrideMap(); + AccountOverride override = new AccountOverride.Builder().withNonce(88L).build(); + final Address address = Address.fromHexString("0xd9c9cd5f6779558b6e0ed4e6acf6b1947e7fa1f3"); + expectedOverrides.put(address, override); + + final JsonRpcRequestContext request = + ethCallRequestWithStateOverrides(callParameter(), "latest", expectedOverrides); + + Optional maybeOverrideMap = method.getAddressAccountOverrideMap(request); + assertThat(maybeOverrideMap.isPresent()).isTrue(); + AccountOverrideMap overrideMap = maybeOverrideMap.get(); + assertThat(overrideMap.keySet()).hasSize(1); + assertThat(overrideMap.values()).hasSize(1); + + assertThat(overrideMap).containsKey(address); + assertThat(overrideMap).containsValue(override); + } + @Test public void shouldReturnInternalErrorWhenProcessorReturnsEmpty() { final JsonRpcRequestContext request = ethCallRequest(callParameter(), "latest"); @@ -99,7 +128,7 @@ public void shouldReturnInternalErrorWhenProcessorReturnsEmpty() { when(blockchainQueries.getBlockchain()).thenReturn(blockchain); when(blockchain.getChainHead()).thenReturn(chainHead); - when(transactionSimulator.process(any(), any(), any(), any(), any())) + when(transactionSimulator.process(any(), any(), any(), any(), any(), any())) .thenReturn(Optional.empty()); final BlockHeader blockHeader = mock(BlockHeader.class); @@ -109,7 +138,7 @@ public void shouldReturnInternalErrorWhenProcessorReturnsEmpty() { final JsonRpcResponse response = method.response(request); assertThat(response).usingRecursiveComparison().isEqualTo(expectedResponse); - verify(transactionSimulator).process(any(), any(), any(), any(), any()); + verify(transactionSimulator).process(any(), any(), any(), any(), any(), any()); } @Test @@ -130,12 +159,13 @@ public void shouldAcceptRequestWhenMissingOptionalFields() { when(result.isSuccessful()).thenReturn(true); when(result.getValidationResult()).thenReturn(ValidationResult.valid()); when(result.getOutput()).thenReturn(Bytes.of()); - verify(transactionSimulator).process(any(), any(), any(), mapperCaptor.capture(), any()); + verify(transactionSimulator) + .process( + eq(callParameter), eq(Optional.empty()), any(), any(), mapperCaptor.capture(), any()); assertThat(mapperCaptor.getValue().apply(mock(MutableWorldState.class), Optional.of(result))) .isEqualTo(Optional.of(expectedResponse)); assertThat(response).usingRecursiveComparison().isEqualTo(expectedResponse); - verify(transactionSimulator).process(eq(callParameter), any(), any(), any(), any()); } @Test @@ -158,7 +188,8 @@ public void shouldReturnExecutionResultWhenExecutionIsSuccessful() { when(result.getValidationResult()).thenReturn(ValidationResult.valid()); when(result.getOutput()).thenReturn(Bytes.of(1)); verify(transactionSimulator) - .process(eq(callParameter()), any(), any(), mapperCaptor.capture(), any()); + .process( + eq(callParameter()), eq(Optional.empty()), any(), any(), mapperCaptor.capture(), any()); assertThat(mapperCaptor.getValue().apply(mock(MutableWorldState.class), Optional.of(result))) .isEqualTo(Optional.of(expectedResponse)); @@ -196,7 +227,8 @@ public void shouldReturnBasicExecutionRevertErrorWithoutReason() { when(result.isSuccessful()).thenReturn(false); when(result.getValidationResult()).thenReturn(ValidationResult.valid()); when(result.result()).thenReturn(processingResult); - verify(transactionSimulator).process(any(), any(), any(), mapperCaptor.capture(), any()); + verify(transactionSimulator) + .process(any(), eq(Optional.empty()), any(), any(), mapperCaptor.capture(), any()); assertThat(mapperCaptor.getValue().apply(mock(MutableWorldState.class), Optional.of(result))) .isEqualTo(Optional.of(expectedResponse)); @@ -235,7 +267,8 @@ public void shouldReturnExecutionRevertErrorWithABIParseError() { when(result.isSuccessful()).thenReturn(false); when(result.getValidationResult()).thenReturn(ValidationResult.valid()); when(result.result()).thenReturn(processingResult); - verify(transactionSimulator).process(any(), any(), any(), mapperCaptor.capture(), any()); + verify(transactionSimulator) + .process(any(), eq(Optional.empty()), any(), any(), mapperCaptor.capture(), any()); assertThat(mapperCaptor.getValue().apply(mock(MutableWorldState.class), Optional.of(result))) .isEqualTo(Optional.of(expectedResponse)); @@ -277,7 +310,8 @@ public void shouldReturnExecutionRevertErrorWithParsedABI() { when(result.getValidationResult()).thenReturn(ValidationResult.valid()); when(result.result()).thenReturn(processingResult); - verify(transactionSimulator).process(any(), any(), any(), mapperCaptor.capture(), any()); + verify(transactionSimulator) + .process(any(), eq(Optional.empty()), any(), any(), mapperCaptor.capture(), any()); assertThat(mapperCaptor.getValue().apply(mock(MutableWorldState.class), Optional.of(result))) .isEqualTo(Optional.of(expectedResponse)); @@ -291,7 +325,7 @@ public void shouldUseCorrectBlockNumberWhenLatest() { final JsonRpcRequestContext request = ethCallRequest(callParameter(), "latest"); when(blockchainQueries.getBlockchain()).thenReturn(blockchain); when(blockchain.getChainHead()).thenReturn(chainHead); - when(transactionSimulator.process(any(), any(), any(), any(), any())) + when(transactionSimulator.process(any(), eq(Optional.empty()), any(), any(), any(), any())) .thenReturn(Optional.empty()); final BlockHeader blockHeader = mock(BlockHeader.class); @@ -301,7 +335,7 @@ public void shouldUseCorrectBlockNumberWhenLatest() { method.response(request); verify(blockchainQueries, atLeastOnce()).getBlockchain(); - verify(transactionSimulator).process(any(), any(), any(), any(), any()); + verify(transactionSimulator).process(any(), eq(Optional.empty()), any(), any(), any(), any()); } @Test @@ -315,7 +349,7 @@ public void shouldUseCorrectBlockNumberWhenEarliest() { method.response(request); verify(blockchainQueries).getBlockHeaderByHash(eq(Hash.ZERO)); - verify(transactionSimulator).process(any(), any(), any(), any(), any()); + verify(transactionSimulator).process(any(), eq(Optional.empty()), any(), any(), any(), any()); } @Test @@ -323,13 +357,13 @@ public void shouldUseCorrectBlockNumberWhenSafe() { final JsonRpcRequestContext request = ethCallRequest(callParameter(), "safe"); when(blockchainQueries.getBlockHeaderByHash(Hash.ZERO)).thenReturn(Optional.of(blockHeader)); when(blockchainQueries.safeBlockHeader()).thenReturn(Optional.of(blockHeader)); - when(transactionSimulator.process(any(), any(), any(), any(), any())) + when(transactionSimulator.process(any(), eq(Optional.empty()), any(), any(), any(), any())) .thenReturn(Optional.empty()); method.response(request); verify(blockchainQueries).getBlockHeaderByHash(Hash.ZERO); verify(blockchainQueries).safeBlockHeader(); - verify(transactionSimulator).process(any(), any(), any(), any(), any()); + verify(transactionSimulator).process(any(), eq(Optional.empty()), any(), any(), any(), any()); } @Test @@ -337,13 +371,13 @@ public void shouldUseCorrectBlockNumberWhenFinalized() { final JsonRpcRequestContext request = ethCallRequest(callParameter(), "finalized"); when(blockchainQueries.getBlockHeaderByHash(Hash.ZERO)).thenReturn(Optional.of(blockHeader)); when(blockchainQueries.finalizedBlockHeader()).thenReturn(Optional.of(blockHeader)); - when(transactionSimulator.process(any(), any(), any(), any(), any())) + when(transactionSimulator.process(any(), eq(Optional.empty()), any(), any(), any(), any())) .thenReturn(Optional.empty()); method.response(request); verify(blockchainQueries).getBlockHeaderByHash(Hash.ZERO); verify(blockchainQueries).finalizedBlockHeader(); - verify(transactionSimulator).process(any(), any(), any(), any(), any()); + verify(transactionSimulator).process(any(), eq(Optional.empty()), any(), any(), any(), any()); } @Test @@ -353,13 +387,13 @@ public void shouldUseCorrectBlockNumberWhenSpecified() { when(blockchainQueries.getBlockHashByNumber(anyLong())).thenReturn(Optional.of(Hash.ZERO)); when(blockchainQueries.getBlockHeaderByHash(Hash.ZERO)) .thenReturn(Optional.of(mock(BlockHeader.class))); - when(transactionSimulator.process(any(), any(), any(), any(), any())) + when(transactionSimulator.process(any(), eq(Optional.empty()), any(), any(), any(), any())) .thenReturn(Optional.empty()); method.response(request); verify(blockchainQueries).getBlockHeaderByHash(eq(Hash.ZERO)); - verify(transactionSimulator).process(any(), any(), any(), any(), any()); + verify(transactionSimulator).process(any(), eq(Optional.empty()), any(), any(), any(), any()); } @Test @@ -431,7 +465,7 @@ private void internalAutoSelectIsAllowedExceedingBalance( .build(); verify(transactionSimulator) - .process(any(), eq(transactionValidationParams), any(), any(), any()); + .process(any(), eq(Optional.empty()), eq(transactionValidationParams), any(), any(), any()); } private JsonCallParameter callParameter() { @@ -458,8 +492,17 @@ private JsonRpcRequestContext ethCallRequest( new JsonRpcRequest("2.0", "eth_call", new Object[] {callParameter, blockNumberInHex})); } + private JsonRpcRequestContext ethCallRequestWithStateOverrides( + final CallParameter callParameter, + final String blockNumberInHex, + final AccountOverrideMap overrides) { + return new JsonRpcRequestContext( + new JsonRpcRequest( + "2.0", "eth_call", new Object[] {callParameter, blockNumberInHex, overrides})); + } + private void mockTransactionProcessorSuccessResult(final JsonRpcResponse jsonRpcResponse) { - when(transactionSimulator.process(any(), any(), any(), any(), any())) + when(transactionSimulator.process(any(), eq(Optional.empty()), any(), any(), any(), any())) .thenReturn(Optional.of(jsonRpcResponse)); } } diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_overrides_empty.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_overrides_empty.json new file mode 100644 index 00000000000..6280773f3d0 --- /dev/null +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_overrides_empty.json @@ -0,0 +1,24 @@ +{ + "request": { + "id": 3, + "jsonrpc": "2.0", + "method": "eth_call", + "params": [ + { + "to": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f", + "from": "a94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "data": "0x12a7b914" + }, + "latest", + { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b": {} + } + ] + }, + "response": { + "jsonrpc": "2.0", + "id": 3, + "result": "0x0000000000000000000000000000000000000000000000000000000000000001" + }, + "statusCode": 200 +} \ No newline at end of file diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_stateOverride.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_stateOverride.json new file mode 100644 index 00000000000..762202f96b2 --- /dev/null +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_stateOverride.json @@ -0,0 +1,32 @@ +{ + "request": { + "id": 3, + "jsonrpc": "2.0", + "method": "eth_call", + "params": [ + { + "to": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f", + "from": "a94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "data": "0x12a7b914" + }, + "latest", + { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0xde0b6b3a7640000", + "nonce": 88 + }, + "0xb9741079a300Cb3B8f324CdDB847c0d1d273a05E": { + "stateDiff": { + "0x1cf7945003fc5b59d2f6736f0704557aa805c4f2844084ccd1173b8d56946962": "0x000000000000000000000000000000000000000000000000000000110ed03bf7" + } + } + } + ] + }, + "response": { + "jsonrpc": "2.0", + "id": 3, + "result": "0x0000000000000000000000000000000000000000000000000000000000000001" + }, + "statusCode": 200 +} \ No newline at end of file diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_stateOverride_insufficientBalance.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_stateOverride_insufficientBalance.json new file mode 100644 index 00000000000..c3832c5689a --- /dev/null +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_stateOverride_insufficientBalance.json @@ -0,0 +1,34 @@ +{ + "request": { + "id": 3, + "jsonrpc": "2.0", + "method": "eth_call", + "params": [ + { + "to": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f", + "from": "a94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "value": "0x000002" + }, + "latest", + { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x000001" + }, + "0xb9741079a300Cb3B8f324CdDB847c0d1d273a05E": { + "stateDiff": { + "0x1cf7945003fc5b59d2f6736f0704557aa805c4f2844084ccd1173b8d56946962": "0x000000000000000000000000000000000000000000000000000000110ed03bf7" + } + } + } + ] + }, + "response": { + "jsonrpc": "2.0", + "id": 3, + "error" : { + "code" : -32004, + "message" : "Upfront cost exceeds account balance" + } + }, + "statusCode": 200 +} \ No newline at end of file diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java index 321dc965ecd..b0a7fa43257 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java @@ -34,10 +34,13 @@ import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams; import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; +import org.hyperledger.besu.ethereum.util.AccountOverride; +import org.hyperledger.besu.ethereum.util.AccountOverrideMap; import org.hyperledger.besu.ethereum.vm.CachingBlockHashLookup; import org.hyperledger.besu.ethereum.vm.DebugOperationTracer; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.evm.account.Account; +import org.hyperledger.besu.evm.account.MutableAccount; import org.hyperledger.besu.evm.tracing.OperationTracer; import org.hyperledger.besu.evm.worldstate.WorldUpdater; @@ -46,8 +49,10 @@ import java.util.function.Supplier; import javax.annotation.Nonnull; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Suppliers; import org.apache.tuweni.bytes.Bytes; +import org.apache.tuweni.units.bigints.UInt256; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -152,6 +157,35 @@ public Optional process( final OperationTracer operationTracer, final PreCloseStateHandler preWorldStateCloseGuard, final BlockHeader header) { + return process( + callParams, + Optional.empty(), + transactionValidationParams, + operationTracer, + preWorldStateCloseGuard, + header); + } + + /** + * Processes a transaction simulation with the provided parameters and executes pre-worldstate + * close actions. + * + * @param callParams The call parameters for the transaction. + * @param maybeStateOverrides The map of state overrides to apply to the state for this + * transaction. + * @param transactionValidationParams The validation parameters for the transaction. + * @param operationTracer The tracer for capturing operations during processing. + * @param preWorldStateCloseGuard The pre-worldstate close guard for executing pre-close actions. + * @param header The block header. + * @return An Optional containing the result of the processing. + */ + public Optional process( + final CallParameter callParams, + final Optional maybeStateOverrides, + final TransactionValidationParams transactionValidationParams, + final OperationTracer operationTracer, + final PreCloseStateHandler preWorldStateCloseGuard, + final BlockHeader header) { if (header == null) { return Optional.empty(); } @@ -169,7 +203,12 @@ public Optional process( return preWorldStateCloseGuard.apply( ws, processWithWorldUpdater( - callParams, transactionValidationParams, operationTracer, header, updater)); + callParams, + maybeStateOverrides, + transactionValidationParams, + operationTracer, + header, + updater)); } catch (final Exception e) { return Optional.empty(); @@ -208,6 +247,7 @@ private MutableWorldState getWorldState(final BlockHeader header) { @Nonnull public Optional processWithWorldUpdater( final CallParameter callParams, + final Optional maybeStateOverrides, final TransactionValidationParams transactionValidationParams, final OperationTracer operationTracer, final BlockHeader header, @@ -226,6 +266,12 @@ public Optional processWithWorldUpdater( .blockHeaderFunctions(protocolSpec.getBlockHeaderFunctions()) .buildBlockHeader(); } + if (maybeStateOverrides.isPresent()) { + for (Address accountToOverride : maybeStateOverrides.get().keySet()) { + final AccountOverride overrides = maybeStateOverrides.get().get(accountToOverride); + applyOverrides(updater.getOrCreate(accountToOverride), overrides); + } + } final Account sender = updater.get(senderAddress); final long nonce = sender != null ? sender.getNonce() : 0L; @@ -284,6 +330,24 @@ public Optional processWithWorldUpdater( return Optional.of(new TransactionSimulatorResult(transaction, result)); } + @VisibleForTesting + protected void applyOverrides(final MutableAccount account, final AccountOverride override) { + LOG.debug("applying overrides to state for account {}", account.getAddress()); + override.getNonce().ifPresent(account::setNonce); + if (override.getBalance().isPresent()) { + account.setBalance(override.getBalance().get()); + } + override.getCode().ifPresent(n -> account.setCode(Bytes.fromHexString(n))); + override + .getStateDiff() + .ifPresent( + d -> + d.forEach( + (key, value) -> + account.setStorageValue( + UInt256.fromHexString(key), UInt256.fromHexString(value)))); + } + private long calculateSimulationGasCap( final long userProvidedGasLimit, final long blockGasLimit) { final long simulationGasCap; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/util/AccountOverride.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/util/AccountOverride.java new file mode 100644 index 00000000000..3bae4af1d84 --- /dev/null +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/util/AccountOverride.java @@ -0,0 +1,147 @@ +/* + * Copyright contributors to 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.ethereum.util; + +import org.hyperledger.besu.datatypes.Wei; + +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +// similar to AccountDiff +// BUT +// there are more fields that need to be added +// stateDiff +// movePrecompileToAddress +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonDeserialize(builder = AccountOverride.Builder.class) +public class AccountOverride { + private static final Logger LOG = LoggerFactory.getLogger(AccountOverride.class); + + private final Optional balance; + private final Optional nonce; + private final Optional code; + private final Optional> stateDiff; + + private AccountOverride( + final Optional balance, + final Optional nonce, + final Optional code, + final Optional> stateDiff) { + this.balance = balance; + this.nonce = nonce; + this.code = code; + this.stateDiff = stateDiff; + } + + public Optional getBalance() { + return balance; + } + + public Optional getNonce() { + return nonce; + } + + public Optional getCode() { + return code; + } + + public Optional> getStateDiff() { + return stateDiff; + } + + public static class Builder { + private Optional balance = Optional.empty(); + private Optional nonce = Optional.empty(); + private Optional code = Optional.empty(); + private Optional> stateDiff = Optional.empty(); + + /** Default constructor. */ + public Builder() {} + + public Builder withBalance(final Wei balance) { + this.balance = Optional.ofNullable(balance); + return this; + } + + public Builder withNonce(final Long nonce) { + this.nonce = Optional.ofNullable(nonce); + return this; + } + + public Builder withCode(final String code) { + this.code = Optional.ofNullable(code); + return this; + } + + public Builder withStateDiff(final Map stateDiff) { + this.stateDiff = Optional.ofNullable(stateDiff); + return this; + } + + public AccountOverride build() { + return new AccountOverride(balance, nonce, code, stateDiff); + } + } + + @JsonAnySetter + public void withUnknownProperties(final String key, final Object value) { + LOG.debug( + "unknown property - {} with value - {} and type - {} caught during serialization", + key, + value, + value != null ? value.getClass() : "NULL"); + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final AccountOverride accountOverride = (AccountOverride) o; + return balance.equals(accountOverride.balance) + && nonce.equals(accountOverride.nonce) + && code.equals(accountOverride.code) + && stateDiff.equals(accountOverride.stateDiff); + } + + @Override + public int hashCode() { + return Objects.hash(balance, nonce, code, stateDiff); + } + + @Override + public String toString() { + return "AccountOverride{" + + "balance=" + + balance + + ", nonce=" + + nonce + + ", code=" + + code + + ", stateDiff=" + + stateDiff + + '}'; + } +} diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/util/AccountOverrideMap.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/util/AccountOverrideMap.java new file mode 100644 index 00000000000..30fc808c9bb --- /dev/null +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/util/AccountOverrideMap.java @@ -0,0 +1,27 @@ +/* + * Copyright contributors to 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.ethereum.util; + +import org.hyperledger.besu.datatypes.Address; + +import java.util.HashMap; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class AccountOverrideMap extends HashMap { + + public AccountOverrideMap() {} +} diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulatorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulatorTest.java index c6c676c4151..0dfa7e924fa 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulatorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulatorTest.java @@ -20,6 +20,7 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; import org.hyperledger.besu.crypto.SECPSignature; @@ -47,17 +48,21 @@ import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket; import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult.Status; +import org.hyperledger.besu.ethereum.util.AccountOverride; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.evm.account.Account; +import org.hyperledger.besu.evm.account.MutableAccount; import org.hyperledger.besu.evm.tracing.OperationTracer; import org.hyperledger.besu.evm.worldstate.WorldUpdater; import java.math.BigInteger; +import java.util.Map; import java.util.Optional; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; import org.apache.tuweni.bytes.Bytes; +import org.apache.tuweni.units.bigints.UInt256; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -100,6 +105,42 @@ public void setUp() { new TransactionSimulator(blockchain, worldStateArchive, protocolSchedule, GAS_CAP); } + @Test + public void testOverrides_whenNoOverrides_noUpdates() { + MutableAccount mutableAccount = mock(MutableAccount.class); + when(mutableAccount.getAddress()).thenReturn(DEFAULT_FROM); // called from logging + AccountOverride.Builder builder = new AccountOverride.Builder(); + AccountOverride override = builder.build(); + transactionSimulator.applyOverrides(mutableAccount, override); + verify(mutableAccount).getAddress(); + verifyNoMoreInteractions(mutableAccount); + } + + @Test + public void testOverrides_whenBalanceOverrides_balanceIsUpdated() { + MutableAccount mutableAccount = mock(MutableAccount.class); + when(mutableAccount.getAddress()).thenReturn(DEFAULT_FROM); + AccountOverride.Builder builder = new AccountOverride.Builder().withBalance(Wei.of(99)); + AccountOverride override = builder.build(); + transactionSimulator.applyOverrides(mutableAccount, override); + verify(mutableAccount).setBalance(eq(Wei.of(99))); + } + + @Test + public void testOverrides_whenStateDiffOverrides_stateIsUpdated() { + MutableAccount mutableAccount = mock(MutableAccount.class); + when(mutableAccount.getAddress()).thenReturn(DEFAULT_FROM); + final String storageKey = "0x01a2"; + final String storageValue = "0x00ff"; + AccountOverride.Builder builder = + new AccountOverride.Builder().withStateDiff(Map.of(storageKey, storageValue)); + AccountOverride override = builder.build(); + transactionSimulator.applyOverrides(mutableAccount, override); + verify(mutableAccount) + .setStorageValue( + eq(UInt256.fromHexString(storageKey)), eq(UInt256.fromHexString(storageValue))); + } + @Test public void shouldReturnEmptyWhenBlockDoesNotExist() { when(blockchain.getBlockHeader(eq(1L))).thenReturn(Optional.empty()); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/AccountOverrideParameterTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/AccountOverrideParameterTest.java new file mode 100644 index 00000000000..8e7b5c3f0eb --- /dev/null +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/AccountOverrideParameterTest.java @@ -0,0 +1,188 @@ +/* + * Copyright contributors to 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.ethereum.util; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; + +import java.util.Optional; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; + +public class AccountOverrideParameterTest { + + private static final String ADDRESS_HEX1 = "0xd9c9cd5f6779558b6e0ed4e6acf6b1947e7fa1f3"; + private static final String ADDRESS_HEX2 = "0xd5E23607D5d73ff2293152f464C3caB005f87696"; + private static final String STORAGE_KEY = + "0x1cf7945003fc5b59d2f6736f0704557aa805c4f2844084ccd1173b8d56946962"; + private static final String STORAGE_VALUE = + "0x000000000000000000000000000000000000000000000000000000110ed03bf7"; + private static final String CODE_STRING = + "0xdbf4257000000000000000000000000000000000000000000000000000000000"; + + @Test + public void jsonDeserializesCorrectly() throws Exception { + final String json = + "{\"jsonrpc\":\"2.0\",\"method\":\"eth_call\",\"params\":[{" + + "\"from\":\"0x0\", \"to\": \"0x0\"}, " + + "\"latest\"," + + "{\"" + + ADDRESS_HEX1 + + "\":" + + "{" + + "\"balance\": \"0x01\"," + + "\"nonce\": 88" + + "}}],\"id\":1}"; + + final JsonRpcRequestContext request = new JsonRpcRequestContext(readJsonAsJsonRpcRequest(json)); + final AccountOverrideMap accountOverrideParam = + request.getRequiredParameter(2, AccountOverrideMap.class); + + final AccountOverride accountOverride = + accountOverrideParam.get(Address.fromHexString(ADDRESS_HEX1)); + + assertThat(accountOverride.getNonce()).isEqualTo(Optional.of(88L)); + assertThat(accountOverride.getBalance()).isEqualTo(Optional.of(Wei.of(1))); + assertFalse(accountOverride.getStateDiff().isPresent()); + } + + @Test + public void jsonWithCodeDeserializesCorrectly() throws Exception { + final String json = + "{\"jsonrpc\":\"2.0\",\"method\":\"eth_call\",\"params\":[{" + + "\"from\":\"0x0\", \"to\": \"0x0\"}, " + + "\"latest\"," + + "{\"" + + ADDRESS_HEX1 + + "\":" + + "{" + + "\"balance\": \"0x01\"," + + "\"code\": \"" + + CODE_STRING + + "\"" + + "}}],\"id\":1}"; + + final JsonRpcRequestContext request = new JsonRpcRequestContext(readJsonAsJsonRpcRequest(json)); + final AccountOverrideMap accountOverrideParam = + request.getRequiredParameter(2, AccountOverrideMap.class); + + final AccountOverride accountOverride = + accountOverrideParam.get(Address.fromHexString(ADDRESS_HEX1)); + + assertFalse(accountOverride.getNonce().isPresent()); + assertThat(accountOverride.getBalance()).isEqualTo(Optional.of(Wei.of(1))); + assertThat(accountOverride.getCode()).isEqualTo(Optional.of(CODE_STRING)); + assertFalse(accountOverride.getStateDiff().isPresent()); + } + + @Test + public void jsonWithStorageOverridesDeserializesCorrectly() throws Exception { + final String json = + "{\"jsonrpc\":\"2.0\",\"method\":\"eth_call\",\"params\":[{" + + "\"from\":\"0x0\", \"to\": \"0x0\"}, " + + "\"latest\"," + + "{\"" + + ADDRESS_HEX1 + + "\":" + + "{" + + "\"balance\": \"0x01\"," + + "\"nonce\": 88," + + "\"stateDiff\": {" + + "\"" + + STORAGE_KEY + + "\": \"" + + STORAGE_VALUE + + "\"" + + "}}}],\"id\":1}"; + + final JsonRpcRequestContext request = new JsonRpcRequestContext(readJsonAsJsonRpcRequest(json)); + + final AccountOverrideMap accountOverrideParam = + request.getRequiredParameter(2, AccountOverrideMap.class); + assertThat(accountOverrideParam.size()).isEqualTo(1); + + final AccountOverride accountOverride = + accountOverrideParam.get(Address.fromHexString(ADDRESS_HEX1)); + assertThat(accountOverride.getNonce()).isEqualTo(Optional.of(88L)); + + assertTrue(accountOverride.getStateDiff().isPresent()); + assertThat(accountOverride.getStateDiff().get().get(STORAGE_KEY)).isEqualTo(STORAGE_VALUE); + } + + @Test + public void jsonWithMultipleAccountOverridesDeserializesCorrectly() throws Exception { + final String json = + "{\"jsonrpc\":\"2.0\",\"method\":\"eth_call\",\"params\":[{" + + "\"from\":\"0x0\", \"to\": \"0x0\"}, " + + "\"latest\"," + + "{\"" + + ADDRESS_HEX1 + + "\":" + + "{" + + "\"balance\": \"0x01\"," + + "\"nonce\": 88," + + "\"stateDiff\": {" + + "\"" + + STORAGE_KEY + + "\": \"" + + STORAGE_VALUE + + "\"" + + "}}," + + "\"" + + ADDRESS_HEX2 + + "\":" + + "{" + + "\"balance\": \"0xFF\"," + + "\"nonce\": 99," + + "\"stateDiff\": {" + + "\"" + + STORAGE_KEY + + "\": \"" + + STORAGE_VALUE + + "\"" + + "}}}],\"id\":1}"; + + final JsonRpcRequestContext request = new JsonRpcRequestContext(readJsonAsJsonRpcRequest(json)); + + final AccountOverrideMap accountOverrideParam = + request.getRequiredParameter(2, AccountOverrideMap.class); + assertThat(accountOverrideParam.size()).isEqualTo(2); + + final AccountOverride accountOverride1 = + accountOverrideParam.get(Address.fromHexString(ADDRESS_HEX1)); + assertThat(accountOverride1.getNonce()).isEqualTo(Optional.of(88L)); + assertThat(accountOverride1.getBalance()).isEqualTo(Optional.of(Wei.fromHexString("0x01"))); + assertTrue(accountOverride1.getStateDiff().isPresent()); + assertThat(accountOverride1.getStateDiff().get().get(STORAGE_KEY)).isEqualTo(STORAGE_VALUE); + + final AccountOverride accountOverride2 = + accountOverrideParam.get(Address.fromHexString(ADDRESS_HEX2)); + assertThat(accountOverride2.getNonce()).isEqualTo(Optional.of(99L)); + assertThat(accountOverride2.getBalance()).isEqualTo(Optional.of(Wei.fromHexString("0xFF"))); + assertTrue(accountOverride2.getStateDiff().isPresent()); + assertThat(accountOverride2.getStateDiff().get().get(STORAGE_KEY)).isEqualTo(STORAGE_VALUE); + } + + private JsonRpcRequest readJsonAsJsonRpcRequest(final String json) throws java.io.IOException { + return new ObjectMapper().readValue(json, JsonRpcRequest.class); + } +} From 46f3d649b651e5a736c971499f8699bbe340c01d Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Wed, 20 Nov 2024 17:23:56 +0700 Subject: [PATCH 38/56] Pass correct evmUpdater to trace end transaction (#7886) Signed-off-by: Gabriel-Trintinalia --- .../besu/ethereum/mainnet/MainnetTransactionProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java index 30a1ea8e762..5ff2129972f 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java @@ -537,7 +537,7 @@ public TransactionProcessingResult processTransaction( coinbase.incrementBalance(coinbaseWeiDelta); operationTracer.traceEndTransaction( - worldUpdater, + evmWorldUpdater.updater(), transaction, initialFrame.getState() == MessageFrame.State.COMPLETED_SUCCESS, initialFrame.getOutputData(), From e85a436032caab7abf022fe3fefbb00da495fa06 Mon Sep 17 00:00:00 2001 From: Matt Whitehead Date: Wed, 20 Nov 2024 13:27:28 +0000 Subject: [PATCH 39/56] Don't create reward account if no reward (#7826) * Don't create reward account if no reward Signed-off-by: Matthew Whitehead * Remove unnecessary test stub Signed-off-by: Matthew Whitehead * Extra check to only create 0 balance accounts if clearEmptyAccounts isn't set Signed-off-by: Matthew Whitehead --------- Signed-off-by: Matthew Whitehead --- .../besu/ethereum/mainnet/MainnetTransactionProcessor.java | 7 ++++--- .../ethereum/mainnet/MainnetTransactionProcessorTest.java | 1 - 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java index 5ff2129972f..c662c188644 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java @@ -532,9 +532,10 @@ public TransactionProcessingResult processTransaction( coinbaseCalculator.price(usedGas, transactionGasPrice, blockHeader.getBaseFee()); operationTracer.traceBeforeRewardTransaction(worldUpdater, transaction, coinbaseWeiDelta); - - final var coinbase = evmWorldUpdater.getOrCreate(miningBeneficiary); - coinbase.incrementBalance(coinbaseWeiDelta); + if (!coinbaseWeiDelta.isZero() || !clearEmptyAccounts) { + final var coinbase = evmWorldUpdater.getOrCreate(miningBeneficiary); + coinbase.incrementBalance(coinbaseWeiDelta); + } operationTracer.traceEndTransaction( evmWorldUpdater.updater(), diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessorTest.java index d8d9f3777ea..c40da7210e2 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessorTest.java @@ -108,7 +108,6 @@ void shouldWarmCoinbaseIfRequested() { .thenReturn(ValidationResult.valid()); when(transactionValidatorFactory.get().validateForSender(any(), any(), any())) .thenReturn(ValidationResult.valid()); - when(worldState.getOrCreate(any())).thenReturn(senderAccount); when(worldState.getOrCreateSenderAccount(any())).thenReturn(senderAccount); when(worldState.updater()).thenReturn(worldState); From 73a1e5beeecf8be2a09a48234ae3c278c079fe2b Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Wed, 20 Nov 2024 17:38:39 +0100 Subject: [PATCH 40/56] Simplify difficulty calculator interface (#7893) Signed-off-by: Fabio Di Fabio --- .../CliqueBesuControllerBuilder.java | 6 +-- .../clique/CliqueDifficultyCalculator.java | 8 +--- .../besu/consensus/clique/CliqueHelpers.java | 18 ++++++-- .../consensus/clique/CliqueMiningTracker.java | 5 +-- .../clique/CliqueProtocolSchedule.java | 43 +------------------ .../CliqueDifficultyValidationRule.java | 3 +- .../CliqueDifficultyCalculatorTest.java | 14 ++---- .../clique/CliqueProtocolScheduleTest.java | 6 +++ .../blockcreation/CliqueBlockCreatorTest.java | 9 ++-- .../CliqueMinerExecutorTest.java | 10 +++-- .../CliqueMiningCoordinatorTest.java | 2 + .../CliqueDifficultyValidationRuleTest.java | 2 + .../bft/BaseBftProtocolScheduleBuilder.java | 2 +- .../merge/MergeProtocolSchedule.java | 2 +- .../merge/MergeProtocolScheduleTest.java | 3 +- .../blockcreation/AbstractBlockCreator.java | 3 +- .../fixed/FixedDifficultyCalculators.java | 2 +- .../mainnet/ClassicDifficultyCalculators.java | 8 ++-- .../mainnet/DifficultyCalculator.java | 4 +- .../mainnet/MainnetDifficultyCalculators.java | 25 ++++------- .../CalculatedDifficultyValidationRule.java | 2 +- .../fixed/FixedProtocolScheduleTest.java | 6 +-- .../referencetests/ReferenceTestEnv.java | 3 +- .../mainnet/DifficultyCalculatorTests.java | 2 +- 24 files changed, 71 insertions(+), 117 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java index edb55a11265..ccd4363412d 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java @@ -14,12 +14,11 @@ */ package org.hyperledger.besu.controller; -import static org.hyperledger.besu.consensus.clique.CliqueHelpers.installCliqueBlockChoiceRule; - import org.hyperledger.besu.config.CliqueConfigOptions; import org.hyperledger.besu.consensus.clique.CliqueBlockInterface; import org.hyperledger.besu.consensus.clique.CliqueContext; import org.hyperledger.besu.consensus.clique.CliqueForksSchedulesFactory; +import org.hyperledger.besu.consensus.clique.CliqueHelpers; import org.hyperledger.besu.consensus.clique.CliqueMiningTracker; import org.hyperledger.besu.consensus.clique.CliqueProtocolSchedule; import org.hyperledger.besu.consensus.clique.blockcreation.CliqueBlockScheduler; @@ -167,7 +166,8 @@ protected CliqueContext createConsensusContext( blockchain, epochManager, blockInterface), epochManager, blockInterface); - installCliqueBlockChoiceRule(blockchain, cliqueContext); + CliqueHelpers.setCliqueContext(cliqueContext); + CliqueHelpers.installCliqueBlockChoiceRule(blockchain, cliqueContext); return cliqueContext; } diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculator.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculator.java index a5771238d2a..b0869feb23c 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculator.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculator.java @@ -15,7 +15,6 @@ package org.hyperledger.besu.consensus.clique; import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.mainnet.DifficultyCalculator; @@ -39,12 +38,9 @@ public CliqueDifficultyCalculator(final Address localAddress) { } @Override - public BigInteger nextDifficulty( - final long time, final BlockHeader parent, final ProtocolContext context) { + public BigInteger nextDifficulty(final long time, final BlockHeader parent) { - final Address nextProposer = - CliqueHelpers.getProposerForBlockAfter( - parent, context.getConsensusContext(CliqueContext.class).getValidatorProvider()); + final Address nextProposer = CliqueHelpers.getProposerForBlockAfter(parent); return nextProposer.equals(localAddress) ? IN_TURN_DIFFICULTY : OUT_OF_TURN_DIFFICULTY; } } diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueHelpers.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueHelpers.java index cba98a5a5eb..d64fe899a66 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueHelpers.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueHelpers.java @@ -27,9 +27,20 @@ /** The Clique helpers. */ public class CliqueHelpers { + private static CliqueContext cliqueContext; + /** Default constructor. */ CliqueHelpers() {} + /** + * Set the clique consensus context + * + * @param cliqueContext the clique consensus context + */ + public static void setCliqueContext(final CliqueContext cliqueContext) { + CliqueHelpers.cliqueContext = cliqueContext; + } + /** * Gets proposer of block. * @@ -45,12 +56,11 @@ public static Address getProposerOfBlock(final BlockHeader header) { * Gets proposer for block after. * * @param parent the parent - * @param validatorProvider the validator provider * @return the proposer for block after */ - static Address getProposerForBlockAfter( - final BlockHeader parent, final ValidatorProvider validatorProvider) { - final CliqueProposerSelector proposerSelector = new CliqueProposerSelector(validatorProvider); + static Address getProposerForBlockAfter(final BlockHeader parent) { + final CliqueProposerSelector proposerSelector = + new CliqueProposerSelector(cliqueContext.getValidatorProvider()); return proposerSelector.selectProposerForNextBlock(parent); } diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueMiningTracker.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueMiningTracker.java index d6362122835..8f350609dc8 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueMiningTracker.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueMiningTracker.java @@ -42,10 +42,7 @@ public CliqueMiningTracker(final Address localAddress, final ProtocolContext pro * @return the boolean */ public boolean isProposerAfter(final BlockHeader header) { - final Address nextProposer = - CliqueHelpers.getProposerForBlockAfter( - header, - protocolContext.getConsensusContext(CliqueContext.class).getValidatorProvider()); + final Address nextProposer = CliqueHelpers.getProposerForBlockAfter(header); return localAddress.equals(nextProposer); } diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueProtocolSchedule.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueProtocolSchedule.java index 2ceedb71893..a60fcc58125 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueProtocolSchedule.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueProtocolSchedule.java @@ -44,8 +44,6 @@ import java.util.Optional; import java.util.function.Function; -import com.google.common.annotations.VisibleForTesting; - /** Defines the protocol behaviours for a blockchain using Clique. */ public class CliqueProtocolSchedule { @@ -63,7 +61,7 @@ public class CliqueProtocolSchedule { * @param privacyParameters the privacy parameters * @param isRevertReasonEnabled the is revert reason enabled * @param evmConfiguration the evm configuration - * @param miningConfiguration the mining parameters + * @param miningConfiguration the mining configuration * @param badBlockManager the cache to use to keep invalid blocks * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled * @param metricsSystem A metricSystem instance to be able to expose metrics in the underlying @@ -122,45 +120,6 @@ public static ProtocolSchedule create( .createProtocolSchedule(); } - /** - * Create protocol schedule. - * - * @param config the config - * @param forksSchedule the transitions - * @param nodeKey the node key - * @param isRevertReasonEnabled the is revert reason enabled - * @param evmConfiguration the evm configuration - * @param miningConfiguration the mining parameters - * @param badBlockManager the cache to use to keep invalid blocks - * @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled - * @param metricsSystem A metricSystem instance to be able to expose metrics in the underlying - * calls - * @return the protocol schedule - */ - @VisibleForTesting - public static ProtocolSchedule create( - final GenesisConfigOptions config, - final ForksSchedule forksSchedule, - final NodeKey nodeKey, - final boolean isRevertReasonEnabled, - final EvmConfiguration evmConfiguration, - final MiningConfiguration miningConfiguration, - final BadBlockManager badBlockManager, - final boolean isParallelTxProcessingEnabled, - final MetricsSystem metricsSystem) { - return create( - config, - forksSchedule, - nodeKey, - PrivacyParameters.DEFAULT, - isRevertReasonEnabled, - evmConfiguration, - miningConfiguration, - badBlockManager, - isParallelTxProcessingEnabled, - metricsSystem); - } - private static ProtocolSpecBuilder applyCliqueSpecificModifications( final EpochManager epochManager, final long secondsBetweenBlocks, diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRule.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRule.java index a14b5187ef7..87c83b2cb08 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRule.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRule.java @@ -38,10 +38,9 @@ public CliqueDifficultyValidationRule() {} public boolean validate( final BlockHeader header, final BlockHeader parent, final ProtocolContext protocolContext) { final Address actualBlockCreator = CliqueHelpers.getProposerOfBlock(header); - final CliqueDifficultyCalculator diffCalculator = new CliqueDifficultyCalculator(actualBlockCreator); - final BigInteger expectedDifficulty = diffCalculator.nextDifficulty(0, parent, protocolContext); + final BigInteger expectedDifficulty = diffCalculator.nextDifficulty(0, parent); final BigInteger actualDifficulty = header.getDifficulty().toBigInteger(); diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculatorTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculatorTest.java index 3c9da2520d9..74537b2ad1a 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculatorTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculatorTest.java @@ -23,8 +23,6 @@ import org.hyperledger.besu.crypto.KeyPair; import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.ethereum.ProtocolContext; -import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.AddressHelpers; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; @@ -43,9 +41,7 @@ public class CliqueDifficultyCalculatorTest { private Address localAddr; private final List
validatorList = Lists.newArrayList(); - private ProtocolContext cliqueProtocolContext; private BlockHeaderTestFixture blockHeaderBuilder; - private final CliqueBlockInterface blockInterface = new CliqueBlockInterface(); @BeforeEach public void setup() { @@ -56,9 +52,7 @@ public void setup() { final ValidatorProvider validatorProvider = mock(ValidatorProvider.class); when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); - - final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface); - cliqueProtocolContext = new ProtocolContext(null, null, cliqueContext, new BadBlockManager()); + CliqueHelpers.setCliqueContext(new CliqueContext(validatorProvider, null, null)); blockHeaderBuilder = new BlockHeaderTestFixture(); } @@ -68,8 +62,7 @@ public void inTurnValidatorProducesDifficultyOfTwo() { final BlockHeader parentHeader = blockHeaderBuilder.number(1).buildHeader(); - assertThat(calculator.nextDifficulty(0, parentHeader, cliqueProtocolContext)) - .isEqualTo(BigInteger.valueOf(2)); + assertThat(calculator.nextDifficulty(0, parentHeader)).isEqualTo(BigInteger.valueOf(2)); } @Test @@ -78,7 +71,6 @@ public void outTurnValidatorProducesDifficultyOfOne() { final BlockHeader parentHeader = blockHeaderBuilder.number(2).buildHeader(); - assertThat(calculator.nextDifficulty(0, parentHeader, cliqueProtocolContext)) - .isEqualTo(BigInteger.valueOf(1)); + assertThat(calculator.nextDifficulty(0, parentHeader)).isEqualTo(BigInteger.valueOf(1)); } } diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueProtocolScheduleTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueProtocolScheduleTest.java index 083604af6f0..47741206229 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueProtocolScheduleTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueProtocolScheduleTest.java @@ -33,6 +33,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.MiningConfiguration; +import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; @@ -66,6 +67,7 @@ public void protocolSpecsAreCreatedAtBlockDefinedInJson() { config, new ForksSchedule<>(List.of()), NODE_KEY, + PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, MiningConfiguration.MINING_DISABLED, @@ -92,6 +94,7 @@ public void parametersAlignWithMainnetWithAdjustments() { GenesisConfigFile.DEFAULT.getConfigOptions(), forksSchedule, NODE_KEY, + PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, MiningConfiguration.MINING_DISABLED, @@ -118,6 +121,7 @@ public void zeroEpochLengthThrowsException() { genesisConfig, new ForksSchedule<>(List.of()), NODE_KEY, + PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, MiningConfiguration.MINING_DISABLED, @@ -140,6 +144,7 @@ public void negativeEpochLengthThrowsException() { genesisConfig, new ForksSchedule<>(List.of()), NODE_KEY, + PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, MiningConfiguration.MINING_DISABLED, @@ -166,6 +171,7 @@ public void shouldValidateBaseFeeMarketTransition() { config, forksSchedule, NODE_KEY, + PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, MiningConfiguration.MINING_DISABLED, diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreatorTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreatorTest.java index 12467cda4ee..0ece2823327 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreatorTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreatorTest.java @@ -122,6 +122,7 @@ void setup() { new NoOpMetricsSystem()); final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface); + CliqueHelpers.setCliqueContext(cliqueContext); final Block genesis = GenesisState.fromConfig(GenesisConfigFile.mainnet(), protocolSchedule).getBlock(); @@ -149,7 +150,7 @@ public void proposerAddressCanBeExtractFromAConstructedBlock() { final Address coinbase = AddressHelpers.ofValue(1); - final MiningConfiguration miningConfiguration = createMiningParameters(extraData, coinbase); + final MiningConfiguration miningConfiguration = createMiningConfiguration(extraData, coinbase); final CliqueBlockCreator blockCreator = new CliqueBlockCreator( @@ -178,7 +179,7 @@ public void insertsValidVoteIntoConstructedBlock() { when(voteProvider.getVoteAfterBlock(any(), any())) .thenReturn(Optional.of(new ValidatorVote(VoteType.ADD, coinbase, a1))); - final MiningConfiguration miningConfiguration = createMiningParameters(extraData, coinbase); + final MiningConfiguration miningConfiguration = createMiningConfiguration(extraData, coinbase); final CliqueBlockCreator blockCreator = new CliqueBlockCreator( @@ -212,7 +213,7 @@ public void insertsNoVoteWhenAtEpoch() { when(mockVoteProvider.getVoteAfterBlock(any(), any())) .thenReturn(Optional.of(new ValidatorVote(VoteType.ADD, coinbase, a1))); - final MiningConfiguration miningConfiguration = createMiningParameters(extraData, coinbase); + final MiningConfiguration miningConfiguration = createMiningConfiguration(extraData, coinbase); final CliqueBlockCreator blockCreator = new CliqueBlockCreator( @@ -255,7 +256,7 @@ private TransactionPool createTransactionPool() { return transactionPool; } - private static MiningConfiguration createMiningParameters( + private static MiningConfiguration createMiningConfiguration( final Bytes extraData, final Address coinbase) { final MiningConfiguration miningConfiguration = ImmutableMiningConfiguration.builder() diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java index 7000d145b6b..9c2bf04bce7 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java @@ -26,6 +26,7 @@ import org.hyperledger.besu.consensus.clique.CliqueBlockInterface; import org.hyperledger.besu.consensus.clique.CliqueContext; import org.hyperledger.besu.consensus.clique.CliqueExtraData; +import org.hyperledger.besu.consensus.clique.CliqueHelpers; import org.hyperledger.besu.consensus.clique.CliqueProtocolSchedule; import org.hyperledger.besu.consensus.common.EpochManager; import org.hyperledger.besu.consensus.common.ForksSchedule; @@ -98,6 +99,7 @@ public void setup() { when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface); + CliqueHelpers.setCliqueContext(cliqueContext); cliqueProtocolContext = new ProtocolContext(null, null, cliqueContext, new BadBlockManager()); cliqueProtocolSchedule = CliqueProtocolSchedule.create( @@ -119,7 +121,7 @@ public void setup() { public void extraDataCreatedOnEpochBlocksContainsValidators() { final Bytes vanityData = generateRandomVanityData(); - final MiningConfiguration miningConfiguration = createMiningParameters(vanityData); + final MiningConfiguration miningConfiguration = createMiningConfiguration(vanityData); final CliqueMinerExecutor executor = new CliqueMinerExecutor( @@ -155,7 +157,7 @@ public void extraDataCreatedOnEpochBlocksContainsValidators() { public void extraDataForNonEpochBlocksDoesNotContainValidaors() { final Bytes vanityData = generateRandomVanityData(); - final MiningConfiguration miningConfiguration = createMiningParameters(vanityData); + final MiningConfiguration miningConfiguration = createMiningConfiguration(vanityData); final CliqueMinerExecutor executor = new CliqueMinerExecutor( @@ -191,7 +193,7 @@ public void shouldUseLatestVanityData() { final Bytes initialVanityData = generateRandomVanityData(); final Bytes modifiedVanityData = generateRandomVanityData(); - final MiningConfiguration miningConfiguration = createMiningParameters(initialVanityData); + final MiningConfiguration miningConfiguration = createMiningConfiguration(initialVanityData); final CliqueMinerExecutor executor = new CliqueMinerExecutor( @@ -255,7 +257,7 @@ private Bytes generateRandomVanityData() { return Bytes.wrap(vanityData); } - private static MiningConfiguration createMiningParameters(final Bytes vanityData) { + private static MiningConfiguration createMiningConfiguration(final Bytes vanityData) { return ImmutableMiningConfiguration.builder() .mutableInitValues( MutableInitValues.builder() diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMiningCoordinatorTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMiningCoordinatorTest.java index 543d110ef45..fd39a46cfcf 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMiningCoordinatorTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMiningCoordinatorTest.java @@ -25,6 +25,7 @@ import org.hyperledger.besu.consensus.clique.CliqueBlockInterface; import org.hyperledger.besu.consensus.clique.CliqueContext; +import org.hyperledger.besu.consensus.clique.CliqueHelpers; import org.hyperledger.besu.consensus.clique.CliqueMiningTracker; import org.hyperledger.besu.consensus.clique.TestHelpers; import org.hyperledger.besu.consensus.common.validator.ValidatorProvider; @@ -258,6 +259,7 @@ private void setupCliqueContextAndBlockchain() { when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validators); final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface); + CliqueHelpers.setCliqueContext(cliqueContext); when(protocolContext.getConsensusContext(CliqueContext.class)).thenReturn(cliqueContext); when(protocolContext.getBlockchain()).thenReturn(blockChain); diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRuleTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRuleTest.java index d970d83d80e..d7e4d074091 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRuleTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRuleTest.java @@ -21,6 +21,7 @@ import org.hyperledger.besu.consensus.clique.CliqueBlockInterface; import org.hyperledger.besu.consensus.clique.CliqueContext; +import org.hyperledger.besu.consensus.clique.CliqueHelpers; import org.hyperledger.besu.consensus.clique.TestHelpers; import org.hyperledger.besu.consensus.common.validator.ValidatorProvider; import org.hyperledger.besu.crypto.KeyPair; @@ -58,6 +59,7 @@ public void setup() { when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList); final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface); + CliqueHelpers.setCliqueContext(cliqueContext); cliqueProtocolContext = new ProtocolContext(null, null, cliqueContext, new BadBlockManager()); blockHeaderBuilder = new BlockHeaderTestFixture(); } diff --git a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilder.java b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilder.java index 29ec30d6679..f92b58bbfa6 100644 --- a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilder.java +++ b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilder.java @@ -133,7 +133,7 @@ private ProtocolSpecBuilder applyBftChanges( .blockBodyValidatorBuilder(MainnetBlockBodyValidator::new) .blockValidatorBuilder(MainnetProtocolSpecs.blockValidatorBuilder()) .blockImporterBuilder(MainnetBlockImporter::new) - .difficultyCalculator((time, parent, protocolContext) -> BigInteger.ONE) + .difficultyCalculator((time, parent) -> BigInteger.ONE) .skipZeroBlockRewards(true) .blockHeaderFunctions(BftBlockHeaderFunctions.forOnchainBlock(bftExtraDataCodec)) .blockReward(Wei.of(configOptions.getBlockRewardWei())) diff --git a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/MergeProtocolSchedule.java b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/MergeProtocolSchedule.java index a8c84d5a093..66e177efeef 100644 --- a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/MergeProtocolSchedule.java +++ b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/MergeProtocolSchedule.java @@ -129,7 +129,7 @@ private static ProtocolSpecBuilder applyParisSpecificModifications( gasCalculator, chainId.orElse(BigInteger.ZERO), EvmConfiguration.DEFAULT)) .blockHeaderValidatorBuilder(MergeProtocolSchedule::getBlockHeaderValidator) .blockReward(Wei.ZERO) - .difficultyCalculator((a, b, c) -> BigInteger.ZERO) + .difficultyCalculator((a, b) -> BigInteger.ZERO) .skipZeroBlockRewards(true) .isPoS(true) .name("Paris"); diff --git a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/MergeProtocolScheduleTest.java b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/MergeProtocolScheduleTest.java index ba83f8aad9c..2fff61a8299 100644 --- a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/MergeProtocolScheduleTest.java +++ b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/MergeProtocolScheduleTest.java @@ -193,8 +193,7 @@ public void parametersAlignWithMainnetWithAdjustments() { private static void assertProofOfStakeConfigIsEnabled(final ProtocolSpec spec) { assertThat(spec.isPoS()).isTrue(); assertThat(spec.getEvm().getOperationsUnsafe()[0x44]).isInstanceOf(PrevRanDaoOperation.class); - assertThat(spec.getDifficultyCalculator().nextDifficulty(-1, null, null)) - .isEqualTo(BigInteger.ZERO); + assertThat(spec.getDifficultyCalculator().nextDifficulty(-1, null)).isEqualTo(BigInteger.ZERO); assertThat(spec.getBlockReward()).isEqualTo(Wei.ZERO); assertThat(spec.isSkipZeroBlockRewards()).isTrue(); assertThat(spec.getBlockProcessor()).isInstanceOf(MainnetBlockProcessor.class); diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java index 51cde269e05..c4a3f89aaa3 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java @@ -437,8 +437,7 @@ private ProcessableBlockHeader createPendingBlockHeader( newBlockNumber); final DifficultyCalculator difficultyCalculator = protocolSpec.getDifficultyCalculator(); - final BigInteger difficulty = - difficultyCalculator.nextDifficulty(timestamp, parentHeader, protocolContext); + final BigInteger difficulty = difficultyCalculator.nextDifficulty(timestamp, parentHeader); final Wei baseFee = Optional.of(protocolSpec.getFeeMarket()) diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyCalculators.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyCalculators.java index ceaf06e3530..692d3810c31 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyCalculators.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyCalculators.java @@ -34,6 +34,6 @@ public static boolean isFixedDifficultyInConfig(final GenesisConfigOptions confi public static DifficultyCalculator calculator(final GenesisConfigOptions config) { long difficulty = config.getEthashConfigOptions().getFixedDifficulty().getAsLong(); - return (time, parent, context) -> BigInteger.valueOf(difficulty); + return (time, parent) -> BigInteger.valueOf(difficulty); } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicDifficultyCalculators.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicDifficultyCalculators.java index 9a8f30d01f4..6e15eb87e09 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicDifficultyCalculators.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicDifficultyCalculators.java @@ -32,7 +32,7 @@ public abstract class ClassicDifficultyCalculators { private static final long DELAY = (CONTINUE_BLOCK - PAUSE_BLOCK) / EXPONENTIAL_DIFF_PERIOD; public static DifficultyCalculator DIFFICULTY_BOMB_PAUSED = - (time, parent, protocolContext) -> { + (time, parent) -> { final BigInteger parentDifficulty = difficulty(parent.getDifficulty()); final BigInteger difficulty = ensureMinimumDifficulty( @@ -43,7 +43,7 @@ public abstract class ClassicDifficultyCalculators { }; public static DifficultyCalculator DIFFICULTY_BOMB_DELAYED = - (time, parent, protocolContext) -> { + (time, parent) -> { final BigInteger parentDifficulty = difficulty(parent.getDifficulty()); final BigInteger difficulty = ensureMinimumDifficulty( @@ -55,7 +55,7 @@ public abstract class ClassicDifficultyCalculators { }; public static DifficultyCalculator DIFFICULTY_BOMB_REMOVED = - (time, parent, protocolContext) -> { + (time, parent) -> { final BigInteger parentDifficulty = difficulty(parent.getDifficulty()); final BigInteger difficulty = ensureMinimumDifficulty( @@ -66,7 +66,7 @@ public abstract class ClassicDifficultyCalculators { }; public static DifficultyCalculator EIP100 = - (time, parent, protocolContext) -> { + (time, parent) -> { final BigInteger parentDifficulty = difficulty(parent.getDifficulty()); final boolean hasOmmers = !parent.getOmmersHash().equals(Hash.EMPTY_LIST_HASH); final BigInteger difficulty = diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculator.java index d03bede977d..408f83cb510 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculator.java @@ -14,7 +14,6 @@ */ package org.hyperledger.besu.ethereum.mainnet; -import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.BlockHeader; import java.math.BigInteger; @@ -28,8 +27,7 @@ public interface DifficultyCalculator { * * @param time the time the block was generated * @param parent the block's parent block header - * @param context the context in which the difficulty calculator should operate * @return the block difficulty */ - BigInteger nextDifficulty(long time, BlockHeader parent, ProtocolContext context); + BigInteger nextDifficulty(long time, BlockHeader parent); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetDifficultyCalculators.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetDifficultyCalculators.java index 46f0a05e5dc..2129b10d5d0 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetDifficultyCalculators.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetDifficultyCalculators.java @@ -45,7 +45,7 @@ public abstract class MainnetDifficultyCalculators { private MainnetDifficultyCalculators() {} static final DifficultyCalculator FRONTIER = - (time, parent, protocolContext) -> { + (time, parent) -> { final BigInteger parentDifficulty = difficulty(parent.getDifficulty()); final BigInteger adjust = parentDifficulty.divide(DIFFICULTY_BOUND_DIVISOR); BigInteger difficulty; @@ -60,7 +60,7 @@ private MainnetDifficultyCalculators() {} }; static final DifficultyCalculator HOMESTEAD = - (time, parent, protocolContext) -> { + (time, parent) -> { final BigInteger parentDifficulty = difficulty(parent.getDifficulty()); final BigInteger difficulty = ensureMinimumDifficulty( @@ -72,35 +72,28 @@ private MainnetDifficultyCalculators() {} }; static final DifficultyCalculator BYZANTIUM = - (time, parent, protocolContext) -> - calculateThawedDifficulty(time, parent, BYZANTIUM_FAKE_BLOCK_OFFSET); + (time, parent) -> calculateThawedDifficulty(time, parent, BYZANTIUM_FAKE_BLOCK_OFFSET); static final DifficultyCalculator CONSTANTINOPLE = - (time, parent, protocolContext) -> - calculateThawedDifficulty(time, parent, CONSTANTINOPLE_FAKE_BLOCK_OFFSET); + (time, parent) -> calculateThawedDifficulty(time, parent, CONSTANTINOPLE_FAKE_BLOCK_OFFSET); static final DifficultyCalculator MUIR_GLACIER = - (time, parent, protocolContext) -> - calculateThawedDifficulty(time, parent, MUIR_GLACIER_FAKE_BLOCK_OFFSET); + (time, parent) -> calculateThawedDifficulty(time, parent, MUIR_GLACIER_FAKE_BLOCK_OFFSET); // As per https://eips.ethereum.org/EIPS/eip-3554 static final DifficultyCalculator LONDON = - (time, parent, protocolContext) -> - calculateThawedDifficulty(time, parent, LONDON_FAKE_BLOCK_OFFSET); + (time, parent) -> calculateThawedDifficulty(time, parent, LONDON_FAKE_BLOCK_OFFSET); // As per https://eips.ethereum.org/EIPS/eip-4345 static final DifficultyCalculator ARROW_GLACIER = - (time, parent, protocolContext) -> - calculateThawedDifficulty(time, parent, ARROW_GLACIER_FAKE_BLOCK_OFFSET); + (time, parent) -> calculateThawedDifficulty(time, parent, ARROW_GLACIER_FAKE_BLOCK_OFFSET); // As per https://eips.ethereum.org/EIPS/eip-5133 static final DifficultyCalculator GRAY_GLACIER = - (time, parent, protocolContext) -> - calculateThawedDifficulty(time, parent, GRAY_GLACIER_FAKE_BLOCK_OFFSET); + (time, parent) -> calculateThawedDifficulty(time, parent, GRAY_GLACIER_FAKE_BLOCK_OFFSET); // Proof-of-Stake difficulty must not be altered - static final DifficultyCalculator PROOF_OF_STAKE_DIFFICULTY = - (time, parent, protocolContext) -> BigInteger.ZERO; + static final DifficultyCalculator PROOF_OF_STAKE_DIFFICULTY = (time, parent) -> BigInteger.ZERO; private static BigInteger calculateThawedDifficulty( final long time, final BlockHeader parent, final long fakeBlockOffset) { diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/CalculatedDifficultyValidationRule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/CalculatedDifficultyValidationRule.java index bcc4e213586..1eb4f044c2f 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/CalculatedDifficultyValidationRule.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/CalculatedDifficultyValidationRule.java @@ -39,7 +39,7 @@ public boolean validate( final BigInteger actualDifficulty = new BigInteger(1, header.getDifficulty().toArray()); final BigInteger expectedDifficulty = - difficultyCalculator.nextDifficulty(header.getTimestamp(), parent, context); + difficultyCalculator.nextDifficulty(header.getTimestamp(), parent); if (actualDifficulty.compareTo(expectedDifficulty) != 0) { LOG.info( diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedProtocolScheduleTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedProtocolScheduleTest.java index 02bb41feb90..9a6ddeaeb73 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedProtocolScheduleTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedProtocolScheduleTest.java @@ -49,21 +49,21 @@ public void reportedDifficultyForAllBlocksIsAFixedValue() { schedule .getByBlockHeader(blockHeader(0)) .getDifficultyCalculator() - .nextDifficulty(1, parentHeader, null)) + .nextDifficulty(1, parentHeader)) .isEqualTo(FixedDifficultyCalculators.DEFAULT_DIFFICULTY); assertThat( schedule .getByBlockHeader(blockHeader(500)) .getDifficultyCalculator() - .nextDifficulty(1, parentHeader, null)) + .nextDifficulty(1, parentHeader)) .isEqualTo(FixedDifficultyCalculators.DEFAULT_DIFFICULTY); assertThat( schedule .getByBlockHeader(blockHeader(500_000)) .getDifficultyCalculator() - .nextDifficulty(1, parentHeader, null)) + .nextDifficulty(1, parentHeader)) .isEqualTo(FixedDifficultyCalculators.DEFAULT_DIFFICULTY); } diff --git a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestEnv.java b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestEnv.java index 25c0cd24841..5c571986698 100644 --- a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestEnv.java +++ b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestEnv.java @@ -224,8 +224,7 @@ public BlockHeader parentBlockHeader(final ProtocolSpec protocolSpec) { BlockHeaderBuilder.createDefault() .difficulty(Difficulty.fromHexOrDecimalString(parentDifficulty)) .number(number - 1) - .buildBlockHeader(), - null))); + .buildBlockHeader()))); } if (parentExcessBlobGas != null && parentBlobGasUsed != null) { builder.excessBlobGas(BlobGas.of(Long.decode(parentExcessBlobGas))); diff --git a/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java index 3333f02e585..ea09a1eb983 100644 --- a/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java +++ b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java @@ -181,7 +181,7 @@ private void testDifficulty( UInt256.fromHexString(value.get("currentDifficulty").asText()); final var spec = protocolSchedule.getByBlockHeader(testHeader); final var calculator = spec.getDifficultyCalculator(); - assertThat(UInt256.valueOf(calculator.nextDifficulty(currentTime, testHeader, null))) + assertThat(UInt256.valueOf(calculator.nextDifficulty(currentTime, testHeader))) .describedAs("File %s Test %s", testFile, entry.getKey()) .isEqualTo(currentDifficulty); } From fe462896d293e878721318389aae18c2ed06030a Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Wed, 20 Nov 2024 18:42:36 +0100 Subject: [PATCH 41/56] Add support for counter metric with external supplied value (#7894) * Add support for counter metric with external supplied value Signed-off-by: Fabio Di Fabio * Update CHANGELOG Signed-off-by: Fabio Di Fabio --------- Signed-off-by: Fabio Di Fabio --- CHANGELOG.md | 3 +- .../org/hyperledger/besu/cli/BesuCommand.java | 2 +- .../eth/manager/MonitoredExecutors.java | 4 +- .../manager/peertask/PeerTaskExecutor.java | 6 +- .../transactions/TransactionPoolMetrics.java | 18 ++--- .../besu/metrics/noop/NoOpMetricsSystem.java | 51 +++++++------- .../besu/metrics/noop/NoOpValueCollector.java | 10 +-- .../opentelemetry/OpenTelemetryGauge.java | 50 ++------------ .../OpenTelemetryLabelledSuppliedMetric.java | 67 +++++++++++++++++++ .../OpenTelemetrySuppliedCounter.java | 43 ++++++++++++ .../opentelemetry/OpenTelemetrySystem.java | 20 +++++- .../prometheus/PrometheusMetricsSystem.java | 31 +++++++-- ... => PrometheusSuppliedValueCollector.java} | 26 +++---- .../besu/metrics/StubMetricsSystem.java | 15 ++++- .../OpenTelemetryMetricsSystemTest.java | 6 +- .../PrometheusMetricsSystemTest.java | 10 +-- plugin-api/build.gradle | 2 +- .../besu/plugin/services/MetricsSystem.java | 57 +++++++++++++++- .../services/metrics/LabelledGauge.java | 30 ++------- .../metrics/LabelledSuppliedMetric.java | 28 ++++++++ 20 files changed, 326 insertions(+), 153 deletions(-) create mode 100644 metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryLabelledSuppliedMetric.java create mode 100644 metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetrySuppliedCounter.java rename metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/{PrometheusGauge.java => PrometheusSuppliedValueCollector.java} (76%) create mode 100644 plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/LabelledSuppliedMetric.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 2efa312d263..28d0a874427 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,12 @@ # Changelog ## [Unreleased] -- Added isLabelsObserved to LabelledGauge in plugin-api. Default implementation returns false. ### Breaking Changes - Removed Retesteth rpc service and commands [#7833](https://github.com/hyperledger/besu/pull/7783) ### Upcoming Breaking Changes +- `MetricSystem::createLabelledGauge` is deprecated and will be removed in a future release, replace it with `MetricSystem::createLabelledSuppliedGauge` ### Additions and Improvements - Fine tune already seen txs tracker when a tx is removed from the pool [#7755](https://github.com/hyperledger/besu/pull/7755) @@ -16,6 +16,7 @@ - Add a method to get all the transaction in the pool, to the `TransactionPoolService`, to easily access the transaction pool content from plugins [#7813](https://github.com/hyperledger/besu/pull/7813) - Add a method to check if a metric category is enabled to the plugin API [#7832](https://github.com/hyperledger/besu/pull/7832) - Add account and state overrides to `eth_call` and `eth_estimateGas` [#7801](https://github.com/hyperledger/besu/pull/7801) +- Add a new metric collector for counters which get their value from suppliers [#7894](https://github.com/hyperledger/besu/pull/7894) ### Bug fixes - Fix registering new metric categories from plugins [#7825](https://github.com/hyperledger/besu/pull/7825) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index 9126bc8a2a7..f817dfb8a69 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -1332,7 +1332,7 @@ private void validatePrivacyPluginOptions() { private void setReleaseMetrics() { besuComponent .getMetricsSystem() - .createLabelledGauge( + .createLabelledSuppliedGauge( StandardMetricCategory.PROCESS, "release", "Release information", "version") .labels(() -> 1, BesuInfo.version()); } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/MonitoredExecutors.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/MonitoredExecutors.java index bf2389c1a85..02514db1e7b 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/MonitoredExecutors.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/MonitoredExecutors.java @@ -153,13 +153,13 @@ private static T newMonitoredExecutor( "Current number of threads in the thread pool", executor::getPoolSize); - metricsSystem.createLongGauge( + metricsSystem.createCounter( BesuMetricCategory.EXECUTORS, metricName + "_completed_tasks_total", "Total number of tasks executed", executor::getCompletedTaskCount); - metricsSystem.createLongGauge( + metricsSystem.createCounter( BesuMetricCategory.EXECUTORS, metricName + "_submitted_tasks_total", "Total number of tasks executed", diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutor.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutor.java index a2ae0455263..c8eed6e1f1f 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutor.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutor.java @@ -20,8 +20,8 @@ import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; -import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; +import org.hyperledger.besu.plugin.services.metrics.LabelledSuppliedMetric; import org.hyperledger.besu.plugin.services.metrics.OperationTimer; import java.util.Collection; @@ -43,7 +43,7 @@ public class PeerTaskExecutor { private final LabelledMetric timeoutCounter; private final LabelledMetric invalidResponseCounter; private final LabelledMetric internalExceptionCounter; - private final LabelledGauge inflightRequestGauge; + private final LabelledSuppliedMetric inflightRequestGauge; private final Map inflightRequestCountByClassName; public PeerTaskExecutor( @@ -77,7 +77,7 @@ public PeerTaskExecutor( "Counter of the number of internal exceptions occurred", "taskName"); inflightRequestGauge = - metricsSystem.createLabelledGauge( + metricsSystem.createLabelledSuppliedGauge( BesuMetricCategory.PEERS, "inflight_request_gauge", "Gauge of the number of inflight requests", diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolMetrics.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolMetrics.java index fac9b3174d0..6f116d3b88f 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolMetrics.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolMetrics.java @@ -22,8 +22,8 @@ import org.hyperledger.besu.metrics.RunnableCounter; import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; -import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; +import org.hyperledger.besu.plugin.services.metrics.LabelledSuppliedMetric; import java.util.HashMap; import java.util.Map; @@ -47,10 +47,10 @@ public class TransactionPoolMetrics { private final LabelledMetric removedCounter; private final LabelledMetric rejectedCounter; private final LabelledMetric penalizedCounter; - private final LabelledGauge spaceUsed; - private final LabelledGauge transactionCount; - private final LabelledGauge transactionCountByType; - private final LabelledGauge uniqueSenderCount; + private final LabelledSuppliedMetric spaceUsed; + private final LabelledSuppliedMetric transactionCount; + private final LabelledSuppliedMetric transactionCountByType; + private final LabelledSuppliedMetric uniqueSenderCount; private final LabelledMetric expiredMessagesCounter; private final Map expiredMessagesRunnableCounters = new HashMap<>(); private final LabelledMetric alreadySeenTransactionsCounter; @@ -103,21 +103,21 @@ public TransactionPoolMetrics(final MetricsSystem metricsSystem) { "layer"); spaceUsed = - metricsSystem.createLabelledGauge( + metricsSystem.createLabelledSuppliedGauge( BesuMetricCategory.TRANSACTION_POOL, "space_used", "The amount of space used by the transactions in the layer", "layer"); transactionCount = - metricsSystem.createLabelledGauge( + metricsSystem.createLabelledSuppliedGauge( BesuMetricCategory.TRANSACTION_POOL, "number_of_transactions", "The number of transactions currently present in the layer", "layer"); transactionCountByType = - metricsSystem.createLabelledGauge( + metricsSystem.createLabelledSuppliedGauge( BesuMetricCategory.TRANSACTION_POOL, "number_of_transactions_by_type", "The number of transactions, of a specified type, currently present in the layer", @@ -125,7 +125,7 @@ public TransactionPoolMetrics(final MetricsSystem metricsSystem) { "type"); uniqueSenderCount = - metricsSystem.createLabelledGauge( + metricsSystem.createLabelledSuppliedGauge( BesuMetricCategory.TRANSACTION_POOL, "unique_senders", "The number of senders with at least one transaction currently present in the layer", diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/noop/NoOpMetricsSystem.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/noop/NoOpMetricsSystem.java index d3b6c4aadc5..68b5d52ffa3 100644 --- a/metrics/core/src/main/java/org/hyperledger/besu/metrics/noop/NoOpMetricsSystem.java +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/noop/NoOpMetricsSystem.java @@ -20,6 +20,7 @@ import org.hyperledger.besu.plugin.services.metrics.ExternalSummary; import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; +import org.hyperledger.besu.plugin.services.metrics.LabelledSuppliedMetric; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; import org.hyperledger.besu.plugin.services.metrics.OperationTimer; @@ -41,7 +42,7 @@ public class NoOpMetricsSystem implements ObservableMetricsSystem { public static final Counter NO_OP_COUNTER = new NoOpCounter(); /** The constant NO_OP_GAUGE. */ - public static final LabelledGauge NO_OP_GAUGE = new NoOpValueCollector(); + public static final LabelledSuppliedMetric NO_OP_GAUGE = new NoOpValueCollector(); private static final OperationTimer.TimingContext NO_OP_TIMING_CONTEXT = () -> 0; @@ -65,16 +66,16 @@ public class NoOpMetricsSystem implements ObservableMetricsSystem { new LabelCountingNoOpMetric<>(1, NO_OP_OPERATION_TIMER); /** The constant NO_OP_LABELLED_1_GAUGE. */ - public static final LabelledGauge NO_OP_LABELLED_1_GAUGE = - new LabelledGaugeNoOpMetric(1, NO_OP_GAUGE); + public static final LabelledSuppliedMetric NO_OP_LABELLED_1_GAUGE = + new LabelledSuppliedNoOpMetric(1, NO_OP_GAUGE); /** The constant NO_OP_LABELLED_2_GAUGE. */ - public static final LabelledGauge NO_OP_LABELLED_2_GAUGE = - new LabelledGaugeNoOpMetric(2, NO_OP_GAUGE); + public static final LabelledSuppliedMetric NO_OP_LABELLED_2_GAUGE = + new LabelledSuppliedNoOpMetric(2, NO_OP_GAUGE); /** The constant NO_OP_LABELLED_3_GAUGE. */ - public static final LabelledGauge NO_OP_LABELLED_3_GAUGE = - new LabelledGaugeNoOpMetric(3, NO_OP_GAUGE); + public static final LabelledSuppliedMetric NO_OP_LABELLED_3_GAUGE = + new LabelledSuppliedNoOpMetric(3, NO_OP_GAUGE); /** Default constructor */ public NoOpMetricsSystem() {} @@ -159,12 +160,21 @@ public void createGuavaCacheCollector( final MetricCategory category, final String name, final Cache cache) {} @Override - public LabelledGauge createLabelledGauge( + public LabelledSuppliedMetric createLabelledSuppliedCounter( final MetricCategory category, final String name, final String help, final String... labelNames) { - return getLabelledGauge(labelNames.length); + return getLabelledSuppliedMetric(labelNames.length); + } + + @Override + public LabelledSuppliedMetric createLabelledSuppliedGauge( + final MetricCategory category, + final String name, + final String help, + final String... labelNames) { + return getLabelledSuppliedMetric(labelNames.length); } /** @@ -173,7 +183,7 @@ public LabelledGauge createLabelledGauge( * @param labelCount the label count * @return the labelled gauge */ - public static LabelledGauge getLabelledGauge(final int labelCount) { + public static LabelledSuppliedMetric getLabelledSuppliedMetric(final int labelCount) { switch (labelCount) { case 1: return NO_OP_LABELLED_1_GAUGE; @@ -182,7 +192,7 @@ public static LabelledGauge getLabelledGauge(final int labelCount) { case 3: return NO_OP_LABELLED_3_GAUGE; default: - return new LabelledGaugeNoOpMetric(labelCount, NO_OP_GAUGE); + return new LabelledSuppliedNoOpMetric(labelCount, NO_OP_GAUGE); } } @@ -237,8 +247,9 @@ public T labels(final String... labels) { } } - /** The Labelled gauge NoOp metric. */ - public static class LabelledGaugeNoOpMetric implements LabelledGauge { + /** The Labelled supplied NoOp metric. */ + @SuppressWarnings("removal") // remove when deprecated LabelledGauge is removed + public static class LabelledSuppliedNoOpMetric implements LabelledSuppliedMetric, LabelledGauge { /** The Label count. */ final int labelCount; @@ -251,13 +262,14 @@ public static class LabelledGaugeNoOpMetric implements LabelledGauge { * @param labelCount the label count * @param fakeMetric the fake metric */ - public LabelledGaugeNoOpMetric(final int labelCount, final LabelledGauge fakeMetric) { + public LabelledSuppliedNoOpMetric( + final int labelCount, final LabelledSuppliedMetric fakeMetric) { this.labelCount = labelCount; this.fakeMetric = fakeMetric; } /** The Fake metric. */ - final LabelledGauge fakeMetric; + final LabelledSuppliedMetric fakeMetric; @Override public void labels(final DoubleSupplier valueSupplier, final String... labelValues) { @@ -270,14 +282,5 @@ public void labels(final DoubleSupplier valueSupplier, final String... labelValu "The count of labels used must match the count of labels expected."); Preconditions.checkNotNull(valueSupplier, "No valueSupplier specified"); } - - @Override - public boolean isLabelsObserved(final String... labelValues) { - Preconditions.checkArgument( - labelValues.length == labelCount, - "The count of labels used must match the count of labels expected."); - final String labelValuesString = String.join(",", labelValues); - return labelValuesCache.contains(labelValuesString); - } } } diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/noop/NoOpValueCollector.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/noop/NoOpValueCollector.java index 6f36f10d2c7..3db34babe42 100644 --- a/metrics/core/src/main/java/org/hyperledger/besu/metrics/noop/NoOpValueCollector.java +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/noop/NoOpValueCollector.java @@ -14,14 +14,14 @@ */ package org.hyperledger.besu.metrics.noop; -import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; +import org.hyperledger.besu.plugin.services.metrics.LabelledSuppliedMetric; import java.util.ArrayList; import java.util.List; import java.util.function.DoubleSupplier; /** The NoOp value collector. */ -public class NoOpValueCollector implements LabelledGauge { +public class NoOpValueCollector implements LabelledSuppliedMetric { private final List labelValuesCreated = new ArrayList<>(); /** Default constructor */ @@ -36,10 +36,4 @@ public synchronized void labels(final DoubleSupplier valueSupplier, final String } labelValuesCreated.add(labelValuesString); } - - @Override - public boolean isLabelsObserved(final String... labelValues) { - final String labelValuesString = String.join(",", labelValues); - return labelValuesCreated.contains(labelValuesString); - } } diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryGauge.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryGauge.java index e1d785c68ec..4f250cbd92d 100644 --- a/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryGauge.java +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryGauge.java @@ -16,23 +16,14 @@ import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; -import java.util.Arrays; import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.function.DoubleSupplier; -import com.google.common.base.Preconditions; -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.api.metrics.Meter; -import io.opentelemetry.api.metrics.ObservableDoubleMeasurement; /** The Open telemetry gauge. */ -public class OpenTelemetryGauge implements LabelledGauge { - private final List labelNames; - private final Map observationsMap = new ConcurrentHashMap<>(); - +@SuppressWarnings("removal") // remove when deprecated LabelledGauge is removed +public class OpenTelemetryGauge extends OpenTelemetryLabelledSuppliedMetric + implements LabelledGauge { /** * Instantiates a new Open telemetry gauge. * @@ -46,41 +37,8 @@ public OpenTelemetryGauge( final String help, final Meter meter, final List labelNames) { - this.labelNames = labelNames; + super(labelNames); meter.gaugeBuilder(metricName).setDescription(help).buildWithCallback(this::updater); } - - @Override - public void labels(final DoubleSupplier valueSupplier, final String... labelValues) { - Preconditions.checkArgument( - labelValues.length == labelNames.size(), - "label values and label names need the same number of elements"); - final Attributes labels = getLabels(labelValues); - if (observationsMap.putIfAbsent(labels, valueSupplier) != null) { - throw new IllegalStateException( - "Already registered a gauge with labels " + Arrays.toString(labelValues)); - } - } - - @Override - public boolean isLabelsObserved(final String... labelValues) { - Preconditions.checkArgument( - labelValues.length == labelNames.size(), - "label values and label names need the same number of elements"); - return observationsMap.containsKey(getLabels(labelValues)); - } - - private Attributes getLabels(final String... labelValues) { - final AttributesBuilder labelsBuilder = Attributes.builder(); - for (int i = 0; i < labelNames.size(); i++) { - labelsBuilder.put(labelNames.get(i), labelValues[i]); - } - return labelsBuilder.build(); - } - - private void updater(final ObservableDoubleMeasurement measurement) { - observationsMap.forEach( - (labels, valueSupplier) -> measurement.record(valueSupplier.getAsDouble(), labels)); - } } diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryLabelledSuppliedMetric.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryLabelledSuppliedMetric.java new file mode 100644 index 00000000000..db48ee9b312 --- /dev/null +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryLabelledSuppliedMetric.java @@ -0,0 +1,67 @@ +/* + * Copyright contributors to 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.metrics.opentelemetry; + +import org.hyperledger.besu.plugin.services.metrics.LabelledSuppliedMetric; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.DoubleSupplier; + +import com.google.common.base.Preconditions; +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.api.metrics.ObservableDoubleMeasurement; + +abstract class OpenTelemetryLabelledSuppliedMetric implements LabelledSuppliedMetric { + private final List labelNames; + private final Map observationsMap = new ConcurrentHashMap<>(); + + public OpenTelemetryLabelledSuppliedMetric(final List labelNames) { + this.labelNames = labelNames; + } + + @Override + public void labels(final DoubleSupplier valueSupplier, final String... labelValues) { + Preconditions.checkArgument( + labelValues.length == labelNames.size(), + "label values and label names need the same number of elements"); + final Attributes labels = getLabels(labelValues); + if (observationsMap.putIfAbsent(labels, valueSupplier) != null) { + throw new IllegalStateException( + "Already registered a collector with label values " + Arrays.toString(labelValues)); + } + } + + private Attributes getLabels(final String... labelValues) { + final AttributesBuilder labelsBuilder = Attributes.builder(); + for (int i = 0; i < labelNames.size(); i++) { + labelsBuilder.put(labelNames.get(i), labelValues[i]); + } + return labelsBuilder.build(); + } + + /** + * Callback to record the supplied values + * + * @param measurement where to record the values + */ + protected void updater(final ObservableDoubleMeasurement measurement) { + observationsMap.forEach( + (labels, valueSupplier) -> measurement.record(valueSupplier.getAsDouble(), labels)); + } +} diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetrySuppliedCounter.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetrySuppliedCounter.java new file mode 100644 index 00000000000..7bfadcdc2d9 --- /dev/null +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetrySuppliedCounter.java @@ -0,0 +1,43 @@ +/* + * Copyright contributors to 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.metrics.opentelemetry; + +import java.util.List; + +import io.opentelemetry.api.metrics.Meter; + +/** The Open telemetry supplied counter. */ +public class OpenTelemetrySuppliedCounter extends OpenTelemetryLabelledSuppliedMetric { + /** + * Instantiates a new Open telemetry supplied counter. + * + * @param metricName the metric name + * @param help the help + * @param meter the meter + * @param labelNames the label names + */ + public OpenTelemetrySuppliedCounter( + final String metricName, + final String help, + final Meter meter, + final List labelNames) { + super(labelNames); + meter + .counterBuilder(metricName) + .setDescription(help) + .ofDoubles() + .buildWithCallback(this::updater); + } +} diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetrySystem.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetrySystem.java index a17c773813c..cc2174dff53 100644 --- a/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetrySystem.java +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetrySystem.java @@ -21,8 +21,8 @@ import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; import org.hyperledger.besu.plugin.services.metrics.ExternalSummary; -import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; +import org.hyperledger.besu.plugin.services.metrics.LabelledSuppliedMetric; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; import org.hyperledger.besu.plugin.services.metrics.OperationTimer; @@ -292,7 +292,21 @@ public void createGuavaCacheCollector( final MetricCategory category, final String name, final Cache cache) {} @Override - public LabelledGauge createLabelledGauge( + public LabelledSuppliedMetric createLabelledSuppliedCounter( + final MetricCategory category, + final String name, + final String help, + final String... labelNames) { + LOG.trace("Creating a labelled supplied counter {}", name); + if (isCategoryEnabled(category)) { + return new OpenTelemetrySuppliedCounter( + name, help, sdkMeterProvider.get(category.getName()), List.of(labelNames)); + } + return NoOpMetricsSystem.getLabelledSuppliedMetric(labelNames.length); + } + + @Override + public LabelledSuppliedMetric createLabelledSuppliedGauge( final MetricCategory category, final String name, final String help, @@ -302,7 +316,7 @@ public LabelledGauge createLabelledGauge( return new OpenTelemetryGauge( name, help, sdkMeterProvider.get(category.getName()), List.of(labelNames)); } - return NoOpMetricsSystem.getLabelledGauge(labelNames.length); + return NoOpMetricsSystem.getLabelledSuppliedMetric(labelNames.length); } @Override diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystem.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystem.java index b001eb0b3be..9263383b8f0 100644 --- a/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystem.java +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystem.java @@ -19,8 +19,8 @@ import org.hyperledger.besu.metrics.StandardMetricCategory; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.metrics.ExternalSummary; -import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; +import org.hyperledger.besu.plugin.services.metrics.LabelledSuppliedMetric; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; import org.hyperledger.besu.plugin.services.metrics.OperationTimer; @@ -240,18 +240,37 @@ public void createGuavaCacheCollector( } @Override - public LabelledGauge createLabelledGauge( + public LabelledSuppliedMetric createLabelledSuppliedCounter( final MetricCategory category, final String name, final String help, final String... labelNames) { + return createLabelledSuppliedMetric(category, Collector.Type.COUNTER, name, help, labelNames); + } + + @Override + public LabelledSuppliedMetric createLabelledSuppliedGauge( + final MetricCategory category, + final String name, + final String help, + final String... labelNames) { + return createLabelledSuppliedMetric(category, Collector.Type.GAUGE, name, help, labelNames); + } + + private LabelledSuppliedMetric createLabelledSuppliedMetric( + final MetricCategory category, + final Collector.Type type, + final String name, + final String help, + final String... labelNames) { final String metricName = convertToPrometheusName(category, name); if (isCategoryEnabled(category)) { - final PrometheusGauge gauge = new PrometheusGauge(metricName, help, List.of(labelNames)); - registerCollector(category, gauge); - return gauge; + final PrometheusSuppliedValueCollector suppliedValueCollector = + new PrometheusSuppliedValueCollector(type, metricName, help, List.of(labelNames)); + registerCollector(category, suppliedValueCollector); + return suppliedValueCollector; } - return NoOpMetricsSystem.getLabelledGauge(labelNames.length); + return NoOpMetricsSystem.getLabelledSuppliedMetric(labelNames.length); } private void registerCollector(final MetricCategory category, final Collector collector) { diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusGauge.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusSuppliedValueCollector.java similarity index 76% rename from metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusGauge.java rename to metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusSuppliedValueCollector.java index b69e3f90626..47394ffed4d 100644 --- a/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusGauge.java +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusSuppliedValueCollector.java @@ -1,5 +1,5 @@ /* - * Copyright ConsenSys AG. + * Copyright contributors to 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 @@ -15,6 +15,7 @@ package org.hyperledger.besu.metrics.prometheus; import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; +import org.hyperledger.besu.plugin.services.metrics.LabelledSuppliedMetric; import java.util.ArrayList; import java.util.List; @@ -24,22 +25,27 @@ import io.prometheus.client.Collector; -/** The Prometheus gauge. */ -public class PrometheusGauge extends Collector implements LabelledGauge { +/** The Prometheus supplied value collector. */ +@SuppressWarnings("removal") // remove when deprecated LabelledGauge is removed +public class PrometheusSuppliedValueCollector extends Collector + implements LabelledSuppliedMetric, LabelledGauge { + private final Type type; private final String metricName; private final String help; private final List labelNames; private final Map, DoubleSupplier> observationsMap = new ConcurrentHashMap<>(); /** - * Instantiates a new Prometheus gauge. + * Instantiates a new Prometheus supplied value collector. * + * @param type the type of the collector * @param metricName the metric name * @param help the help * @param labelNames the label names */ - public PrometheusGauge( - final String metricName, final String help, final List labelNames) { + public PrometheusSuppliedValueCollector( + final Type type, final String metricName, final String help, final List labelNames) { + this.type = type; this.metricName = metricName; this.help = help; this.labelNames = labelNames; @@ -55,12 +61,6 @@ public synchronized void labels(final DoubleSupplier valueSupplier, final String } } - @Override - public boolean isLabelsObserved(final String... labelValues) { - validateLabelsCardinality(labelValues); - return observationsMap.containsKey(List.of(labelValues)); - } - @Override public List collect() { final List samples = new ArrayList<>(); @@ -69,7 +69,7 @@ public List collect() { samples.add( new MetricFamilySamples.Sample( metricName, labelNames, labels, valueSupplier.getAsDouble()))); - return List.of(new MetricFamilySamples(metricName, Type.GAUGE, help, samples)); + return List.of(new MetricFamilySamples(metricName, type, help, samples)); } private void validateLabelsCardinality(final String... labelValues) { diff --git a/metrics/core/src/test-support/java/org/hyperledger/besu/metrics/StubMetricsSystem.java b/metrics/core/src/test-support/java/org/hyperledger/besu/metrics/StubMetricsSystem.java index 13f16ef0a0c..c10c62132c1 100644 --- a/metrics/core/src/test-support/java/org/hyperledger/besu/metrics/StubMetricsSystem.java +++ b/metrics/core/src/test-support/java/org/hyperledger/besu/metrics/StubMetricsSystem.java @@ -19,8 +19,8 @@ import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; import org.hyperledger.besu.plugin.services.metrics.ExternalSummary; -import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; +import org.hyperledger.besu.plugin.services.metrics.LabelledSuppliedMetric; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; import org.hyperledger.besu.plugin.services.metrics.OperationTimer; @@ -50,12 +50,21 @@ public LabelledMetric createLabelledCounter( } @Override - public LabelledGauge createLabelledGauge( + public LabelledSuppliedMetric createLabelledSuppliedCounter( final MetricCategory category, final String name, final String help, final String... labelNames) { - return NoOpMetricsSystem.getLabelledGauge(labelNames.length); + return NoOpMetricsSystem.getLabelledSuppliedMetric(labelNames.length); + } + + @Override + public LabelledSuppliedMetric createLabelledSuppliedGauge( + final MetricCategory category, + final String name, + final String help, + final String... labelNames) { + return NoOpMetricsSystem.getLabelledSuppliedMetric(labelNames.length); } public long getCounterValue(final String name, final String... labels) { diff --git a/metrics/core/src/test/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryMetricsSystemTest.java b/metrics/core/src/test/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryMetricsSystemTest.java index f1bff33e555..8c6dd8261d5 100644 --- a/metrics/core/src/test/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryMetricsSystemTest.java +++ b/metrics/core/src/test/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetryMetricsSystemTest.java @@ -31,8 +31,8 @@ import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; -import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; +import org.hyperledger.besu.plugin.services.metrics.LabelledSuppliedMetric; import org.hyperledger.besu.plugin.services.metrics.OperationTimer; import java.util.Collections; @@ -231,8 +231,8 @@ public void shouldCreateObservationFromGauge() { @Test public void shouldCreateLabelledGauge() { - LabelledGauge labelledGauge = - metricsSystem.createLabelledGauge(RPC, "gaugeName", "help", "a", "b"); + LabelledSuppliedMetric labelledGauge = + metricsSystem.createLabelledSuppliedGauge(RPC, "gaugeName", "help", "a", "b"); labelledGauge.labels(() -> 1.0, "a1", "b1"); labelledGauge.labels(() -> 11.0, "a2", "b2"); labelledGauge.labels(() -> 21.0, "a3", "b3"); diff --git a/metrics/core/src/test/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystemTest.java b/metrics/core/src/test/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystemTest.java index 2ddf86d347b..ba875ab79b1 100644 --- a/metrics/core/src/test/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystemTest.java +++ b/metrics/core/src/test/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystemTest.java @@ -33,8 +33,8 @@ import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; -import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; +import org.hyperledger.besu.plugin.services.metrics.LabelledSuppliedMetric; import org.hyperledger.besu.plugin.services.metrics.OperationTimer; import java.util.Collections; @@ -129,8 +129,8 @@ public void shouldCreateSeparateObservationsForEachCounterLabelValue() { @Test public void shouldCreateSeparateObservationsForEachLabelledGaugeValue() { - final LabelledGauge gauge = - metricsSystem.createLabelledGauge(PEERS, "test", "test help", "a", "b", "c"); + final LabelledSuppliedMetric gauge = + metricsSystem.createLabelledSuppliedGauge(PEERS, "test", "test help", "a", "b", "c"); final double value1 = 1.0; final double value2 = 11.0; @@ -145,8 +145,8 @@ public void shouldCreateSeparateObservationsForEachLabelledGaugeValue() { @Test public void shouldNotUseSameLabelsTwiceOnSameGauge() { - final LabelledGauge gauge = - metricsSystem.createLabelledGauge(PEERS, "test", "test help", "a", "b", "c"); + final LabelledSuppliedMetric gauge = + metricsSystem.createLabelledSuppliedGauge(PEERS, "test", "test help", "a", "b", "c"); final double value1 = 1.0; gauge.labels(() -> value1, "a1", "b1", "c1"); diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 2d3d5191df4..8242189db71 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -71,7 +71,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'aYWbsgPoKTGDgq9d4QUBvQEaZYbKNJGMiBufzyKnusA=' + knownHash = 'ktVrmQXU7LMQi1ieb9OQ2vJNqZ0SVQ7Usauh1LMvUXY=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/MetricsSystem.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/MetricsSystem.java index 744bca4eb3e..f3d3f91d0a5 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/MetricsSystem.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/MetricsSystem.java @@ -18,6 +18,7 @@ import org.hyperledger.besu.plugin.services.metrics.ExternalSummary; import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; +import org.hyperledger.besu.plugin.services.metrics.LabelledSuppliedMetric; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; import org.hyperledger.besu.plugin.services.metrics.OperationTimer; @@ -45,6 +46,23 @@ default Counter createCounter( return createLabelledCounter(category, name, help, new String[0]).labels(); } + /** + * Creates a Counter that gets its value from the specified supplier. To be used when the value of + * the counter is calculated outside the metric system. + * + * @param category The {@link MetricCategory} this counter is assigned to. + * @param name A name for this metric. + * @param help A human readable description of the metric. + * @param valueSupplier The supplier of the value. + */ + default void createCounter( + final MetricCategory category, + final String name, + final String help, + final DoubleSupplier valueSupplier) { + createLabelledSuppliedCounter(category, name, help).labels(valueSupplier); + } + /** * Creates a Counter with assigned labels. * @@ -58,7 +76,42 @@ LabelledMetric createLabelledCounter( MetricCategory category, String name, String help, String... labelNames); /** - * Creates a Gauge with assigned labels. + * Creates a Counter with assigned labels, that gets its values from suppliers. To be used when + * the values of the counter are calculated outside the metric system. + * + * @param category The {@link MetricCategory} this counter is assigned to. + * @param name A name for this metric. + * @param help A human readable description of the metric. + * @param labelNames An array of labels to assign to the Counter. + * @return The created LabelledSupplierMetric instance. + */ + LabelledSuppliedMetric createLabelledSuppliedCounter( + MetricCategory category, String name, String help, String... labelNames); + + /** + * Creates a Gauge with assigned labels, that gets its values from suppliers. To be used when the + * values of the gauge are calculated outside the metric system. + * + * @param category The {@link MetricCategory} this gauge is assigned to. + * @param name A name for this metric. + * @param help A human readable description of the metric. + * @param labelNames An array of labels to assign to the Gauge. + * @return The created LabelledGauge instance. + * @deprecated Use {@link #createLabelledSuppliedGauge(MetricCategory, String, String, String...)} + */ + @Deprecated(forRemoval = true) + @SuppressWarnings("removal") // remove when deprecated LabelledGauge is removed + default LabelledGauge createLabelledGauge( + final MetricCategory category, + final String name, + final String help, + final String... labelNames) { + return (LabelledGauge) createLabelledSuppliedGauge(category, name, help, labelNames); + } + + /** + * Creates a Gauge with assigned labels, that gets its values from suppliers. To be used when the + * values of the gauge are calculated outside the metric system. * * @param category The {@link MetricCategory} this gauge is assigned to. * @param name A name for this metric. @@ -66,7 +119,7 @@ LabelledMetric createLabelledCounter( * @param labelNames An array of labels to assign to the Gauge. * @return The created LabelledGauge instance. */ - LabelledGauge createLabelledGauge( + LabelledSuppliedMetric createLabelledSuppliedGauge( MetricCategory category, String name, String help, String... labelNames); /** diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/LabelledGauge.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/LabelledGauge.java index 5357c6505ae..f94e5231840 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/LabelledGauge.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/LabelledGauge.java @@ -14,26 +14,10 @@ */ package org.hyperledger.besu.plugin.services.metrics; -import java.util.function.DoubleSupplier; - -/** The interface Labelled gauge. */ -public interface LabelledGauge { - /** - * Labels. - * - * @param valueSupplier the value supplier - * @param labelValues the label values - */ - void labels(final DoubleSupplier valueSupplier, final String... labelValues); - - /** - * Checks whether the supplied labelValues are already observed by this LabelledGauge - * - * @param labelValues The labelValues to check - * @return true if the supplied labelValues are already observed by this LabelledGauge, false - * otherwise - */ - default boolean isLabelsObserved(final String... labelValues) { - return false; - } -} +/** + * The interface Labelled gauge. + * + * @deprecated Use {@link LabelledSuppliedMetric} + */ +@Deprecated(forRemoval = true) +public interface LabelledGauge extends LabelledSuppliedMetric {} diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/LabelledSuppliedMetric.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/LabelledSuppliedMetric.java new file mode 100644 index 00000000000..755bd6787e3 --- /dev/null +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/LabelledSuppliedMetric.java @@ -0,0 +1,28 @@ +/* + * Copyright contributors to 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.plugin.services.metrics; + +import java.util.function.DoubleSupplier; + +/** The interface Labelled gauge. */ +public interface LabelledSuppliedMetric { + /** + * Labels. + * + * @param valueSupplier the value supplier + * @param labelValues the label values + */ + void labels(final DoubleSupplier valueSupplier, final String... labelValues); +} From 9718fd58e7e62fc50209e0b6204b5ffd489d94f4 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Thu, 21 Nov 2024 07:48:11 +1000 Subject: [PATCH 42/56] eth_estimateGas state overrides (#7890) * parse account overrides parameter for eth_estimateGas Signed-off-by: Sally MacFarlane * changelog Signed-off-by: Sally MacFarlane --------- Signed-off-by: Sally MacFarlane --- CHANGELOG.md | 2 +- .../internal/methods/EthEstimateGas.java | 25 +++++++++- .../jsonrpc/internal/methods/EthCallTest.java | 3 +- .../internal/methods/EthEstimateGasTest.java | 47 +++++++++++++++++++ .../transaction/TransactionSimulator.java | 15 ++++++ 5 files changed, 89 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28d0a874427..d9d69f5ef72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,8 +15,8 @@ - Update Java dependencies [#7786](https://github.com/hyperledger/besu/pull/7786) - Add a method to get all the transaction in the pool, to the `TransactionPoolService`, to easily access the transaction pool content from plugins [#7813](https://github.com/hyperledger/besu/pull/7813) - Add a method to check if a metric category is enabled to the plugin API [#7832](https://github.com/hyperledger/besu/pull/7832) -- Add account and state overrides to `eth_call` and `eth_estimateGas` [#7801](https://github.com/hyperledger/besu/pull/7801) - Add a new metric collector for counters which get their value from suppliers [#7894](https://github.com/hyperledger/besu/pull/7894) +- Add account and state overrides to `eth_call` [#7801](https://github.com/hyperledger/besu/pull/7801) and `eth_estimateGas` [#7890](https://github.com/hyperledger/besu/pull/7890) ### Bug fixes - Fix registering new metric categories from plugins [#7825](https://github.com/hyperledger/besu/pull/7825) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java index c713ea20a7b..ab758dadec7 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java @@ -16,7 +16,9 @@ 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.InvalidJsonRpcRequestException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; 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.Quantity; @@ -27,10 +29,12 @@ import org.hyperledger.besu.ethereum.transaction.CallParameter; import org.hyperledger.besu.ethereum.transaction.TransactionSimulator; import org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult; +import org.hyperledger.besu.ethereum.util.AccountOverrideMap; import org.hyperledger.besu.evm.tracing.EstimateGasOperationTracer; import java.util.Optional; +import com.google.common.annotations.VisibleForTesting; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,6 +59,8 @@ protected Object resultByBlockHeader( final CallParameter modifiedCallParams = overrideGasLimitAndPrice(callParams, blockHeader.getGasLimit()); + Optional maybeStateOverrides = getAddressAccountOverrideMap(requestContext); + // TODO implement for block overrides final boolean isAllowExceedingBalance = !callParams.isMaybeStrict().orElse(Boolean.FALSE); @@ -68,7 +74,11 @@ protected Object resultByBlockHeader( LOG.debug("Processing transaction with params: {}", modifiedCallParams); final var maybeResult = transactionSimulator.process( - modifiedCallParams, transactionValidationParams, operationTracer, blockHeader); + modifiedCallParams, + maybeStateOverrides, + transactionValidationParams, + operationTracer, + blockHeader); final Optional maybeErrorResponse = validateSimulationResult(requestContext, maybeResult); @@ -81,6 +91,7 @@ protected Object resultByBlockHeader( final var lowResult = transactionSimulator.process( overrideGasLimitAndPrice(callParams, low), + maybeStateOverrides, transactionValidationParams, operationTracer, blockHeader); @@ -97,6 +108,7 @@ protected Object resultByBlockHeader( var binarySearchResult = transactionSimulator.process( overrideGasLimitAndPrice(callParams, mid), + maybeStateOverrides, transactionValidationParams, operationTracer, blockHeader); @@ -127,4 +139,15 @@ private Optional validateSimulationResult( } return Optional.empty(); } + + @VisibleForTesting + protected Optional getAddressAccountOverrideMap( + final JsonRpcRequestContext request) { + try { + return request.getOptionalParameter(2, AccountOverrideMap.class); + } catch (JsonRpcParameter.JsonRpcParameterException e) { + throw new InvalidJsonRpcRequestException( + "Invalid account overrides parameter (index 2)", RpcErrorType.INVALID_CALL_PARAMS, e); + } + } } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java index 1ba9839b66d..d16de7d9943 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java @@ -342,7 +342,8 @@ public void shouldUseCorrectBlockNumberWhenLatest() { public void shouldUseCorrectBlockNumberWhenEarliest() { final JsonRpcRequestContext request = ethCallRequest(callParameter(), "earliest"); when(blockchainQueries.getBlockHashByNumber(anyLong())).thenReturn(Optional.of(Hash.ZERO)); - when(transactionSimulator.process(any(), any(), any(), any(), any())) + when(transactionSimulator.process( + any(), any(), any(TransactionValidationParams.class), any(), any(BlockHeader.class))) .thenReturn(Optional.empty()); when(blockchainQueries.getBlockHeaderByHash(Hash.ZERO)) .thenReturn(Optional.of(mock(BlockHeader.class))); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java index f85a0813efd..9f321e00502 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java @@ -44,6 +44,8 @@ import org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason; import org.hyperledger.besu.ethereum.transaction.TransactionSimulator; import org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult; +import org.hyperledger.besu.ethereum.util.AccountOverride; +import org.hyperledger.besu.ethereum.util.AccountOverrideMap; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.evm.tracing.OperationTracer; @@ -99,12 +101,44 @@ public void shouldReturnCorrectMethodName() { assertThat(method.getName()).isEqualTo("eth_estimateGas"); } + @Test + public void noAccountOverrides() { + final Wei gasPrice = Wei.of(1000); + final JsonRpcRequestContext request = + ethEstimateGasRequest(defaultLegacyTransactionCallParameter(gasPrice), "latest"); + Optional overrideMap = method.getAddressAccountOverrideMap(request); + assertThat(overrideMap.isPresent()).isFalse(); + } + + @Test + public void someAccountOverrides() { + AccountOverrideMap expectedOverrides = new AccountOverrideMap(); + AccountOverride override = new AccountOverride.Builder().withNonce(88L).build(); + final Address address = Address.fromHexString("0xd9c9cd5f6779558b6e0ed4e6acf6b1947e7fa1f3"); + expectedOverrides.put(address, override); + + final Wei gasPrice = Wei.of(1000); + final JsonRpcRequestContext request = + ethEstimateGasRequestWithStateOverrides( + defaultLegacyTransactionCallParameter(gasPrice), "latest", expectedOverrides); + + Optional maybeOverrideMap = method.getAddressAccountOverrideMap(request); + assertThat(maybeOverrideMap.isPresent()).isTrue(); + AccountOverrideMap overrideMap = maybeOverrideMap.get(); + assertThat(overrideMap.keySet()).hasSize(1); + assertThat(overrideMap.values()).hasSize(1); + + assertThat(overrideMap).containsKey(address); + assertThat(overrideMap).containsValue(override); + } + @Test public void shouldReturnErrorWhenTransientLegacyTransactionProcessorReturnsEmpty() { final JsonRpcRequestContext request = ethEstimateGasRequest(defaultLegacyTransactionCallParameter(Wei.ZERO)); when(transactionSimulator.process( eq(modifiedLegacyTransactionCallParameter(Wei.ZERO)), + eq(Optional.empty()), // no account overrides any(TransactionValidationParams.class), any(OperationTracer.class), eq(latestBlockHeader))) @@ -341,6 +375,7 @@ public void shouldIgnoreSenderBalanceAccountWhenStrictModeDisabled() { verify(transactionSimulator) .process( eq(modifiedLegacyTransactionCallParameter(Wei.ZERO)), + eq(Optional.empty()), // no account overrides eq( ImmutableTransactionValidationParams.builder() .from(TransactionValidationParams.transactionSimulator()) @@ -361,6 +396,7 @@ public void shouldNotIgnoreSenderBalanceAccountWhenStrictModeEnabled() { verify(transactionSimulator) .process( eq(modifiedLegacyTransactionCallParameter(Wei.ZERO)), + eq(Optional.empty()), // no account overrides eq( ImmutableTransactionValidationParams.builder() .from(TransactionValidationParams.transactionSimulator()) @@ -461,12 +497,14 @@ private TransactionSimulatorResult getMockTransactionSimulatorResult( final TransactionSimulatorResult mockTxSimResult = mock(TransactionSimulatorResult.class); when(transactionSimulator.process( eq(modifiedLegacyTransactionCallParameter(gasPrice)), + eq(Optional.empty()), // no account overrides any(TransactionValidationParams.class), any(OperationTracer.class), eq(blockHeader))) .thenReturn(Optional.of(mockTxSimResult)); when(transactionSimulator.process( eq(modifiedEip1559TransactionCallParameter()), + eq(Optional.empty()), // no account overrides any(TransactionValidationParams.class), any(OperationTracer.class), eq(blockHeader))) @@ -551,4 +589,13 @@ private JsonRpcRequestContext ethEstimateGasRequest( return new JsonRpcRequestContext( new JsonRpcRequest("2.0", "eth_estimateGas", new Object[] {callParameter, blockParam})); } + + private JsonRpcRequestContext ethEstimateGasRequestWithStateOverrides( + final CallParameter callParameter, + final String blockParam, + final AccountOverrideMap overrides) { + return new JsonRpcRequestContext( + new JsonRpcRequest( + "2.0", "eth_estimateGas", new Object[] {callParameter, blockParam, overrides})); + } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java index b0a7fa43257..3f35492b2b4 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java @@ -124,6 +124,21 @@ public Optional process( blockHeader); } + public Optional process( + final CallParameter callParams, + final Optional maybeStateOverrides, + final TransactionValidationParams transactionValidationParams, + final OperationTracer operationTracer, + final BlockHeader blockHeader) { + return process( + callParams, + maybeStateOverrides, + transactionValidationParams, + operationTracer, + (mutableWorldState, transactionSimulatorResult) -> transactionSimulatorResult, + blockHeader); + } + public Optional processAtHead(final CallParameter callParams) { final var chainHeadHash = blockchain.getChainHeadHash(); return process( From c127f9c1d7b63630a71c1d636bef0b3ed146ee34 Mon Sep 17 00:00:00 2001 From: Justin Florentine Date: Wed, 20 Nov 2024 17:23:49 -0500 Subject: [PATCH 43/56] naming things is important (#7895) BesuContext was not a helpful name for an interface that only manipulates services to be used by plugins. --------- Signed-off-by: jflo --- CHANGELOG.md | 1 + .../plugins/BadCLIOptionsPlugin.java | 4 +- .../plugins/TestBesuEventsPlugin.java | 6 +- .../TestBlockchainServiceFinalizedPlugin.java | 8 +-- .../TestInProcessRpcServicePlugin.java | 4 +- .../acceptance/plugins/TestMetricsPlugin.java | 10 ++-- .../plugins/TestPermissioningPlugin.java | 4 +- .../acceptance/plugins/TestPicoCLIPlugin.java | 4 +- .../plugins/TestPrivacyServicePlugin.java | 6 +- .../plugins/TestRpcEndpointServicePlugin.java | 4 +- .../besu/services/BesuPluginContextImpl.java | 4 +- .../bonsai/BonsaiWorldStateProvider.java | 4 +- .../common/DiffBasedWorldStateProvider.java | 4 +- .../common/trielog/TrieLogManager.java | 6 +- plugin-api/build.gradle | 2 +- .../hyperledger/besu/plugin/BesuContext.java | 42 +------------- .../hyperledger/besu/plugin/BesuPlugin.java | 2 +- .../besu/plugin/ServiceManager.java | 55 +++++++++++++++++++ .../besu/plugin/services/BesuService.java | 6 +- .../storage/rocksdb/RocksDBPlugin.java | 6 +- .../kvstore/InMemoryStoragePlugin.java | 6 +- 21 files changed, 104 insertions(+), 84 deletions(-) create mode 100644 plugin-api/src/main/java/org/hyperledger/besu/plugin/ServiceManager.java diff --git a/CHANGELOG.md b/CHANGELOG.md index d9d69f5ef72..4cbda780979 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Removed Retesteth rpc service and commands [#7833](https://github.com/hyperledger/besu/pull/7783) ### Upcoming Breaking Changes +- Plugin API will be deprecating the BesuContext interface to be replaced with the ServiceManager interface. - `MetricSystem::createLabelledGauge` is deprecated and will be removed in a future release, replace it with `MetricSystem::createLabelledSuppliedGauge` ### Additions and Improvements diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/BadCLIOptionsPlugin.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/BadCLIOptionsPlugin.java index d9bde19b1ea..ec048ea0d32 100644 --- a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/BadCLIOptionsPlugin.java +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/BadCLIOptionsPlugin.java @@ -16,8 +16,8 @@ import static java.nio.charset.StandardCharsets.UTF_8; -import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.services.PicoCLIOptions; import java.io.File; @@ -39,7 +39,7 @@ public class BadCLIOptionsPlugin implements BesuPlugin { private File callbackDir; @Override - public void register(final BesuContext context) { + public void register(final ServiceManager context) { LOG.info("Registering BadCliOptionsPlugin"); callbackDir = new File(System.getProperty("besu.plugins.dir", "plugins")); writeStatus("init"); diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestBesuEventsPlugin.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestBesuEventsPlugin.java index 44e728010cb..7a4a17cf711 100644 --- a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestBesuEventsPlugin.java +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestBesuEventsPlugin.java @@ -14,8 +14,8 @@ */ package org.hyperledger.besu.tests.acceptance.plugins; -import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.data.BlockHeader; import org.hyperledger.besu.plugin.data.PropagatedBlockContext; import org.hyperledger.besu.plugin.services.BesuEvents; @@ -35,14 +35,14 @@ public class TestBesuEventsPlugin implements BesuPlugin { private static final Logger LOG = LoggerFactory.getLogger(TestBesuEventsPlugin.class); - private BesuContext context; + private ServiceManager context; private Optional subscriptionId; private final AtomicInteger blockCounter = new AtomicInteger(); private File callbackDir; @Override - public void register(final BesuContext context) { + public void register(final ServiceManager context) { this.context = context; LOG.info("Registered"); callbackDir = new File(System.getProperty("besu.plugins.dir", "plugins")); diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestBlockchainServiceFinalizedPlugin.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestBlockchainServiceFinalizedPlugin.java index a61b80ab8e4..4984e7a00e8 100644 --- a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestBlockchainServiceFinalizedPlugin.java +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestBlockchainServiceFinalizedPlugin.java @@ -17,8 +17,8 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.data.BlockContext; import org.hyperledger.besu.plugin.services.BlockchainService; import org.hyperledger.besu.plugin.services.RpcEndpointService; @@ -40,11 +40,11 @@ public class TestBlockchainServiceFinalizedPlugin implements BesuPlugin { private static final String RPC_METHOD_SAFE_BLOCK = "updateSafeBlockV1"; @Override - public void register(final BesuContext besuContext) { + public void register(final ServiceManager serviceManager) { LOG.trace("Registering plugin ..."); final RpcEndpointService rpcEndpointService = - besuContext + serviceManager .getService(RpcEndpointService.class) .orElseThrow( () -> @@ -52,7 +52,7 @@ public void register(final BesuContext besuContext) { "Failed to obtain RpcEndpointService from the BesuContext.")); final BlockchainService blockchainService = - besuContext + serviceManager .getService(BlockchainService.class) .orElseThrow( () -> diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestInProcessRpcServicePlugin.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestInProcessRpcServicePlugin.java index 3ebced0df91..adbc1a35792 100644 --- a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestInProcessRpcServicePlugin.java +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestInProcessRpcServicePlugin.java @@ -15,8 +15,8 @@ package org.hyperledger.besu.tests.acceptance.plugins; import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.services.PicoCLIOptions; import org.hyperledger.besu.plugin.services.RpcEndpointService; import org.hyperledger.besu.plugin.services.rpc.RpcResponseType; @@ -36,7 +36,7 @@ public class TestInProcessRpcServicePlugin implements BesuPlugin { long minGasPrice = -1; @Override - public void register(final BesuContext context) { + public void register(final ServiceManager context) { final PicoCLIOptions cmdlineOptions = context .getService(PicoCLIOptions.class) diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestMetricsPlugin.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestMetricsPlugin.java index af179c57cfe..9400fb4bccd 100644 --- a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestMetricsPlugin.java +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestMetricsPlugin.java @@ -14,8 +14,8 @@ */ package org.hyperledger.besu.tests.acceptance.plugins; -import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; import org.hyperledger.besu.plugin.services.metrics.MetricCategoryRegistry; @@ -30,12 +30,12 @@ @AutoService(BesuPlugin.class) public class TestMetricsPlugin implements BesuPlugin { private static final Logger LOG = LoggerFactory.getLogger(TestMetricsPlugin.class); - private BesuContext besuContext; + private ServiceManager serviceManager; @Override - public void register(final BesuContext context) { + public void register(final ServiceManager context) { LOG.info("Registering TestMetricsPlugin"); - besuContext = context; + serviceManager = context; context .getService(MetricCategoryRegistry.class) .orElseThrow() @@ -45,7 +45,7 @@ public void register(final BesuContext context) { @Override public void start() { LOG.info("Starting TestMetricsPlugin"); - besuContext + serviceManager .getService(MetricsSystem.class) .orElseThrow() .createGauge( diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java index 44afeeadaa5..c2503ed8112 100644 --- a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java @@ -14,8 +14,8 @@ */ package org.hyperledger.besu.tests.acceptance.plugins; -import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.services.PermissioningService; import org.hyperledger.besu.plugin.services.PicoCLIOptions; @@ -40,7 +40,7 @@ public class TestPermissioningPlugin implements BesuPlugin { PermissioningService service; @Override - public void register(final BesuContext context) { + public void register(final ServiceManager context) { context.getService(PicoCLIOptions.class).orElseThrow().addPicoCLIOptions("permissioning", this); service = context.getService(PermissioningService.class).orElseThrow(); } diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPicoCLIPlugin.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPicoCLIPlugin.java index 375fbd490ec..bb83ba676db 100644 --- a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPicoCLIPlugin.java +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPicoCLIPlugin.java @@ -14,8 +14,8 @@ */ package org.hyperledger.besu.tests.acceptance.plugins; -import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.services.PicoCLIOptions; import java.io.File; @@ -57,7 +57,7 @@ public class TestPicoCLIPlugin implements BesuPlugin { private File callbackDir; @Override - public void register(final BesuContext context) { + public void register(final ServiceManager context) { LOG.info("Registering. Test Option is '{}'", testOption); state = "registering"; diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPrivacyServicePlugin.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPrivacyServicePlugin.java index 4cdd35e8dc4..698653f356f 100644 --- a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPrivacyServicePlugin.java +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPrivacyServicePlugin.java @@ -14,8 +14,8 @@ */ package org.hyperledger.besu.tests.acceptance.plugins; -import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.services.PicoCLIOptions; import org.hyperledger.besu.plugin.services.PrivacyPluginService; import org.hyperledger.besu.tests.acceptance.plugins.privacy.TestPrivacyGroupGenesisProvider; @@ -32,7 +32,7 @@ public class TestPrivacyServicePlugin implements BesuPlugin { private static final Logger LOG = LoggerFactory.getLogger(TestPrivacyServicePlugin.class); PrivacyPluginService pluginService; - BesuContext context; + ServiceManager context; TestPrivacyGroupGenesisProvider privacyGroupGenesisProvider = new TestPrivacyGroupGenesisProvider(); @@ -40,7 +40,7 @@ public class TestPrivacyServicePlugin implements BesuPlugin { new TestSigningPrivateMarkerTransactionFactory(); @Override - public void register(final BesuContext context) { + public void register(final ServiceManager context) { this.context = context; context diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestRpcEndpointServicePlugin.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestRpcEndpointServicePlugin.java index 67980373ea2..75d72473bf1 100644 --- a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestRpcEndpointServicePlugin.java +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestRpcEndpointServicePlugin.java @@ -16,8 +16,8 @@ import static com.google.common.base.Preconditions.checkArgument; -import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.services.RpcEndpointService; import org.hyperledger.besu.plugin.services.rpc.PluginRpcRequest; @@ -51,7 +51,7 @@ private String throwException(final PluginRpcRequest request) { } @Override - public void register(final BesuContext context) { + public void register(final ServiceManager context) { context .getService(RpcEndpointService.class) .ifPresent( diff --git a/besu/src/main/java/org/hyperledger/besu/services/BesuPluginContextImpl.java b/besu/src/main/java/org/hyperledger/besu/services/BesuPluginContextImpl.java index ad4dbd44819..fbee90edef9 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/BesuPluginContextImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/BesuPluginContextImpl.java @@ -18,8 +18,8 @@ import static com.google.common.base.Preconditions.checkState; import org.hyperledger.besu.ethereum.core.plugins.PluginConfiguration; -import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.services.BesuService; import org.hyperledger.besu.plugin.services.PluginVersionsProvider; @@ -49,7 +49,7 @@ import org.slf4j.LoggerFactory; /** The Besu plugin context implementation. */ -public class BesuPluginContextImpl implements BesuContext, PluginVersionsProvider { +public class BesuPluginContextImpl implements ServiceManager, PluginVersionsProvider { private static final Logger LOG = LoggerFactory.getLogger(BesuPluginContextImpl.class); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProvider.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProvider.java index 96a56da6e20..1e2f62addbb 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProvider.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProvider.java @@ -28,7 +28,7 @@ import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.evm.internal.EvmConfiguration; -import org.hyperledger.besu.plugin.BesuContext; +import org.hyperledger.besu.plugin.ServiceManager; import java.util.HashSet; import java.util.Optional; @@ -52,7 +52,7 @@ public BonsaiWorldStateProvider( final Blockchain blockchain, final Optional maxLayersToLoad, final BonsaiCachedMerkleTrieLoader bonsaiCachedMerkleTrieLoader, - final BesuContext pluginContext, + final ServiceManager pluginContext, final EvmConfiguration evmConfiguration, final Supplier worldStateHealerSupplier) { super(worldStateKeyValueStorage, blockchain, maxLayersToLoad, pluginContext); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/DiffBasedWorldStateProvider.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/DiffBasedWorldStateProvider.java index 75b370c1cd0..70e077a41b8 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/DiffBasedWorldStateProvider.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/DiffBasedWorldStateProvider.java @@ -31,7 +31,7 @@ import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; import org.hyperledger.besu.evm.worldstate.WorldState; -import org.hyperledger.besu.plugin.BesuContext; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.services.trielogs.TrieLog; import java.util.ArrayList; @@ -61,7 +61,7 @@ public DiffBasedWorldStateProvider( final DiffBasedWorldStateKeyValueStorage worldStateKeyValueStorage, final Blockchain blockchain, final Optional maxLayersToLoad, - final BesuContext pluginContext) { + final ServiceManager pluginContext) { this.worldStateKeyValueStorage = worldStateKeyValueStorage; // TODO: de-dup constructors diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/trielog/TrieLogManager.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/trielog/TrieLogManager.java index 70d45f546db..903a4a5f3ed 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/trielog/TrieLogManager.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/trielog/TrieLogManager.java @@ -21,7 +21,7 @@ import org.hyperledger.besu.ethereum.trie.diffbased.common.storage.DiffBasedWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.diffbased.common.worldview.DiffBasedWorldState; import org.hyperledger.besu.ethereum.trie.diffbased.common.worldview.accumulator.DiffBasedWorldStateUpdateAccumulator; -import org.hyperledger.besu.plugin.BesuContext; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.services.TrieLogService; import org.hyperledger.besu.plugin.services.trielogs.TrieLog; import org.hyperledger.besu.plugin.services.trielogs.TrieLogEvent; @@ -53,7 +53,7 @@ public TrieLogManager( final Blockchain blockchain, final DiffBasedWorldStateKeyValueStorage worldStateKeyValueStorage, final long maxLayersToLoad, - final BesuContext pluginContext) { + final ServiceManager pluginContext) { this.blockchain = blockchain; this.rootWorldStateStorage = worldStateKeyValueStorage; this.maxLayersToLoad = maxLayersToLoad; @@ -133,7 +133,7 @@ public synchronized void unsubscribe(final long id) { trieLogObservers.unsubscribe(id); } - private TrieLogFactory setupTrieLogFactory(final BesuContext pluginContext) { + private TrieLogFactory setupTrieLogFactory(final ServiceManager pluginContext) { // if we have a TrieLogService from pluginContext, use it. var trieLogServicez = Optional.ofNullable(pluginContext) diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 8242189db71..333cac59268 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -71,7 +71,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'ktVrmQXU7LMQi1ieb9OQ2vJNqZ0SVQ7Usauh1LMvUXY=' + knownHash = 'wOjR3/uPElPs1GonuLMBWStn1zukFMyy/GfQ9OYChpI=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/BesuContext.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/BesuContext.java index 71b3612e51e..2f1d0e9ac3c 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/BesuContext.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/BesuContext.java @@ -14,42 +14,6 @@ */ package org.hyperledger.besu.plugin; -import org.hyperledger.besu.plugin.services.BesuService; - -import java.util.Optional; - -/** Allows plugins to access Besu services. */ -public interface BesuContext { - - /** - * Add service. - * - * @param the type parameter - * @param serviceType the service type - * @param service the service - */ - void addService(final Class serviceType, final T service); - - /** - * Get the requested service, if it is available. There are a number of reasons that a service may - * not be available: - * - *
    - *
  • The service may not have started yet. Most services are not available before the {@link - * BesuPlugin#start()} method is called - *
  • The service is not supported by this version of Besu - *
  • The service may not be applicable to the current configuration. For example some services - * may only be available when a proof of authority network is in use - *
- * - *

Since plugins are automatically loaded, unless the user has specifically requested - * functionality provided by the plugin, no error should be raised if required services are - * unavailable. - * - * @param serviceType the class defining the requested service. - * @param the service type - * @return an optional containing the instance of the requested service, or empty if the service - * is unavailable - */ - Optional getService(Class serviceType); -} +/** Deprecated in favor of the more precisely named ServiceManager interface. */ +@Deprecated(since = "24.11.0", forRemoval = true) +public interface BesuContext extends ServiceManager {} diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/BesuPlugin.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/BesuPlugin.java index 1d7acf3a3ee..b05fbf83c09 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/BesuPlugin.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/BesuPlugin.java @@ -48,7 +48,7 @@ default Optional getName() { * * @param context the context that provides access to Besu services. */ - void register(BesuContext context); + void register(ServiceManager context); /** * Called once when besu has loaded configuration but before external services have been started diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/ServiceManager.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/ServiceManager.java new file mode 100644 index 00000000000..99630f27390 --- /dev/null +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/ServiceManager.java @@ -0,0 +1,55 @@ +/* + * Copyright ConsenSys AG. + * + * 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.plugin; + +import org.hyperledger.besu.plugin.services.BesuService; + +import java.util.Optional; + +/** Adds and accesses BesuServices for plugins to provide or use. */ +public interface ServiceManager { + + /** + * Add service. Used by core besu or other plugins to add services to the service manager. + * + * @param the type parameter + * @param serviceType the service type + * @param service the service + */ + void addService(final Class serviceType, final T service); + + /** + * Get the requested service, if it is available. There are a number of reasons that a service may + * not be available: + * + *

    + *
  • The service may not have started yet. Most services are not available before the {@link + * BesuPlugin#start()} method is called + *
  • The service is not supported by this version of Besu + *
  • The service may not be applicable to the current configuration. For example some services + * may only be available when a proof of authority network is in use, or when user provided. + *
+ * + *

Since plugins are automatically loaded, unless the user has specifically requested + * functionality provided by the plugin, no error should be raised if required services are + * unavailable. + * + * @param serviceType the class defining the requested service. + * @param the service type + * @return an optional containing the instance of the requested service, or empty if the service + * is unavailable + */ + Optional getService(Class serviceType); +} diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/BesuService.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/BesuService.java index 62340dd59d6..bb9c5e1cdae 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/BesuService.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/BesuService.java @@ -14,10 +14,10 @@ */ package org.hyperledger.besu.plugin.services; -import org.hyperledger.besu.plugin.BesuContext; +import org.hyperledger.besu.plugin.ServiceManager; /** - * All services that can be resolved via {@link BesuContext#getService(Class)} must implement {@link - * BesuService} + * All services that can be resolved via {@link ServiceManager#getService(Class)} must implement + * {@link BesuService} */ public interface BesuService {} diff --git a/plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/RocksDBPlugin.java b/plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/RocksDBPlugin.java index 9e11bd634b8..91e6e427bc3 100644 --- a/plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/RocksDBPlugin.java +++ b/plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/RocksDBPlugin.java @@ -14,8 +14,8 @@ */ package org.hyperledger.besu.plugin.services.storage.rocksdb; -import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.services.PicoCLIOptions; import org.hyperledger.besu.plugin.services.StorageService; import org.hyperledger.besu.plugin.services.storage.SegmentIdentifier; @@ -40,7 +40,7 @@ public class RocksDBPlugin implements BesuPlugin { private final RocksDBCLIOptions options; private final List ignorableSegments = new ArrayList<>(); - private BesuContext context; + private ServiceManager context; private RocksDBKeyValueStorageFactory factory; private RocksDBKeyValuePrivacyStorageFactory privacyFactory; @@ -59,7 +59,7 @@ public void addIgnorableSegmentIdentifier(final SegmentIdentifier ignorable) { } @Override - public void register(final BesuContext context) { + public void register(final ServiceManager context) { LOG.debug("Registering plugin"); this.context = context; diff --git a/services/kvstore/src/main/java/org/hyperledger/besu/services/kvstore/InMemoryStoragePlugin.java b/services/kvstore/src/main/java/org/hyperledger/besu/services/kvstore/InMemoryStoragePlugin.java index 6783a82c1c4..11e7656dfb7 100644 --- a/services/kvstore/src/main/java/org/hyperledger/besu/services/kvstore/InMemoryStoragePlugin.java +++ b/services/kvstore/src/main/java/org/hyperledger/besu/services/kvstore/InMemoryStoragePlugin.java @@ -14,8 +14,8 @@ */ package org.hyperledger.besu.services.kvstore; -import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; +import org.hyperledger.besu.plugin.ServiceManager; import org.hyperledger.besu.plugin.services.BesuConfiguration; import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.StorageService; @@ -36,7 +36,7 @@ public class InMemoryStoragePlugin implements BesuPlugin { private static final Logger LOG = LoggerFactory.getLogger(InMemoryStoragePlugin.class); - private BesuContext context; + private ServiceManager context; private InMemoryKeyValueStorageFactory factory; private InMemoryKeyValueStorageFactory privacyFactory; @@ -44,7 +44,7 @@ public class InMemoryStoragePlugin implements BesuPlugin { public InMemoryStoragePlugin() {} @Override - public void register(final BesuContext context) { + public void register(final ServiceManager context) { LOG.debug("Registering plugin"); this.context = context; From 55920e002a28bdd553faa5c4f781bf4b029c05f6 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Thu, 21 Nov 2024 08:53:54 +1000 Subject: [PATCH 44/56] add Tx simulate method that accepts state override (#7892) * move AccountOverrides into plugin datatypes; add simulate method that accepts this param Signed-off-by: Sally MacFarlane --------- Signed-off-by: Sally MacFarlane --- .../TransactionSimulationServiceImpl.java | 13 ++++ .../besu/datatypes}/AccountOverride.java | 66 ++++++++++++++++--- .../besu/datatypes}/AccountOverrideMap.java | 6 +- .../api/jsonrpc/internal/methods/EthCall.java | 2 +- .../internal/methods/EthEstimateGas.java | 2 +- .../jsonrpc/internal/methods/EthCallTest.java | 4 +- .../internal/methods/EthEstimateGasTest.java | 4 +- .../transaction/TransactionSimulator.java | 6 +- .../transaction/TransactionSimulatorTest.java | 2 +- .../util/AccountOverrideParameterTest.java | 2 + plugin-api/build.gradle | 2 +- .../TransactionSimulationService.java | 18 +++++ 12 files changed, 106 insertions(+), 21 deletions(-) rename {ethereum/core/src/main/java/org/hyperledger/besu/ethereum/util => datatypes/src/main/java/org/hyperledger/besu/datatypes}/AccountOverride.java (76%) rename {ethereum/core/src/main/java/org/hyperledger/besu/ethereum/util => datatypes/src/main/java/org/hyperledger/besu/datatypes}/AccountOverrideMap.java (87%) diff --git a/besu/src/main/java/org/hyperledger/besu/services/TransactionSimulationServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/TransactionSimulationServiceImpl.java index 54cce205a36..4dc411ee0be 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/TransactionSimulationServiceImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/TransactionSimulationServiceImpl.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.services; +import org.hyperledger.besu.datatypes.AccountOverrideMap; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.ethereum.chain.Blockchain; @@ -62,6 +63,17 @@ public Optional simulate( final Hash blockHash, final OperationTracer operationTracer, final boolean isAllowExceedingBalance) { + return simulate( + transaction, Optional.empty(), blockHash, operationTracer, isAllowExceedingBalance); + } + + @Override + public Optional simulate( + final Transaction transaction, + final Optional maybeAccountOverrides, + final Hash blockHash, + final OperationTracer operationTracer, + final boolean isAllowExceedingBalance) { final CallParameter callParameter = CallParameter.fromTransaction(transaction); @@ -79,6 +91,7 @@ public Optional simulate( return transactionSimulator .process( callParameter, + maybeAccountOverrides, isAllowExceedingBalance ? SIMULATOR_ALLOWING_EXCEEDING_BALANCE : TransactionValidationParams.transactionSimulator(), diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/util/AccountOverride.java b/datatypes/src/main/java/org/hyperledger/besu/datatypes/AccountOverride.java similarity index 76% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/util/AccountOverride.java rename to datatypes/src/main/java/org/hyperledger/besu/datatypes/AccountOverride.java index 3bae4af1d84..e414e97eb5d 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/util/AccountOverride.java +++ b/datatypes/src/main/java/org/hyperledger/besu/datatypes/AccountOverride.java @@ -12,9 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.util; - -import org.hyperledger.besu.datatypes.Wei; +package org.hyperledger.besu.datatypes; import java.util.Map; import java.util.Objects; @@ -26,11 +24,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -// similar to AccountDiff -// BUT -// there are more fields that need to be added -// stateDiff -// movePrecompileToAddress +/** Account Override parameter class */ @JsonIgnoreProperties(ignoreUnknown = true) @JsonDeserialize(builder = AccountOverride.Builder.class) public class AccountOverride { @@ -52,22 +46,43 @@ private AccountOverride( this.stateDiff = stateDiff; } + /** + * Gets the balance override + * + * @return the balance if present + */ public Optional getBalance() { return balance; } + /** + * Gets the nonce override + * + * @return the nonce if present + */ public Optional getNonce() { return nonce; } + /** + * Gets the code override + * + * @return the code if present + */ public Optional getCode() { return code; } + /** + * Gets the state override map + * + * @return the state override map if present + */ public Optional> getStateDiff() { return stateDiff; } + /** Builder class for Account overrides */ public static class Builder { private Optional balance = Optional.empty(); private Optional nonce = Optional.empty(); @@ -77,31 +92,66 @@ public static class Builder { /** Default constructor. */ public Builder() {} + /** + * Sets the balance override + * + * @param balance the balance override + * @return the builder + */ public Builder withBalance(final Wei balance) { this.balance = Optional.ofNullable(balance); return this; } + /** + * Sets the nonce override + * + * @param nonce the nonce override + * @return the builder + */ public Builder withNonce(final Long nonce) { this.nonce = Optional.ofNullable(nonce); return this; } + /** + * Sets the code override + * + * @param code the code override + * @return the builder + */ public Builder withCode(final String code) { this.code = Optional.ofNullable(code); return this; } + /** + * Sets the state diff override + * + * @param stateDiff the map of state overrides + * @return the builder + */ public Builder withStateDiff(final Map stateDiff) { this.stateDiff = Optional.ofNullable(stateDiff); return this; } + /** + * build the account override from the builder + * + * @return account override + */ public AccountOverride build() { return new AccountOverride(balance, nonce, code, stateDiff); } } + /** + * utility method to log unknown properties + * + * @param key key for the unrecognized value + * @param value the unrecognized value + */ @JsonAnySetter public void withUnknownProperties(final String key, final Object value) { LOG.debug( diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/util/AccountOverrideMap.java b/datatypes/src/main/java/org/hyperledger/besu/datatypes/AccountOverrideMap.java similarity index 87% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/util/AccountOverrideMap.java rename to datatypes/src/main/java/org/hyperledger/besu/datatypes/AccountOverrideMap.java index 30fc808c9bb..20aee461859 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/util/AccountOverrideMap.java +++ b/datatypes/src/main/java/org/hyperledger/besu/datatypes/AccountOverrideMap.java @@ -12,16 +12,16 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.util; - -import org.hyperledger.besu.datatypes.Address; +package org.hyperledger.besu.datatypes; import java.util.HashMap; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +/** Map of account overrides, indexed by address */ @JsonIgnoreProperties(ignoreUnknown = true) public class AccountOverrideMap extends HashMap { + /** Default constructor */ public AccountOverrideMap() {} } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java index 5f736e8d5a9..ef5c8c7a6cf 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java @@ -17,6 +17,7 @@ import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType.BLOCK_NOT_FOUND; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType.INTERNAL_ERROR; +import org.hyperledger.besu.datatypes.AccountOverrideMap; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcErrorConverter; @@ -41,7 +42,6 @@ import org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason; import org.hyperledger.besu.ethereum.transaction.TransactionSimulator; import org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult; -import org.hyperledger.besu.ethereum.util.AccountOverrideMap; import org.hyperledger.besu.evm.tracing.OperationTracer; import java.util.Optional; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java index ab758dadec7..2352a5a8c37 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods; +import org.hyperledger.besu.datatypes.AccountOverrideMap; 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.InvalidJsonRpcRequestException; @@ -29,7 +30,6 @@ import org.hyperledger.besu.ethereum.transaction.CallParameter; import org.hyperledger.besu.ethereum.transaction.TransactionSimulator; import org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult; -import org.hyperledger.besu.ethereum.util.AccountOverrideMap; import org.hyperledger.besu.evm.tracing.EstimateGasOperationTracer; import java.util.Optional; diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java index d16de7d9943..7de6f65aae2 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java @@ -27,6 +27,8 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; +import org.hyperledger.besu.datatypes.AccountOverride; +import org.hyperledger.besu.datatypes.AccountOverrideMap; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; @@ -51,8 +53,6 @@ import org.hyperledger.besu.ethereum.transaction.PreCloseStateHandler; import org.hyperledger.besu.ethereum.transaction.TransactionSimulator; import org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult; -import org.hyperledger.besu.ethereum.util.AccountOverride; -import org.hyperledger.besu.ethereum.util.AccountOverrideMap; import java.util.Optional; diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java index 9f321e00502..7c770f08a2d 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java @@ -21,6 +21,8 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import org.hyperledger.besu.datatypes.AccountOverride; +import org.hyperledger.besu.datatypes.AccountOverrideMap; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; @@ -44,8 +46,6 @@ import org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason; import org.hyperledger.besu.ethereum.transaction.TransactionSimulator; import org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult; -import org.hyperledger.besu.ethereum.util.AccountOverride; -import org.hyperledger.besu.ethereum.util.AccountOverrideMap; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.evm.tracing.OperationTracer; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java index 3f35492b2b4..1c6140f1d1f 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java @@ -19,6 +19,8 @@ import org.hyperledger.besu.crypto.SECPSignature; import org.hyperledger.besu.crypto.SignatureAlgorithm; import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; +import org.hyperledger.besu.datatypes.AccountOverride; +import org.hyperledger.besu.datatypes.AccountOverrideMap; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.BlobGas; import org.hyperledger.besu.datatypes.Hash; @@ -34,8 +36,6 @@ import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams; import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; -import org.hyperledger.besu.ethereum.util.AccountOverride; -import org.hyperledger.besu.ethereum.util.AccountOverrideMap; import org.hyperledger.besu.ethereum.vm.CachingBlockHashLookup; import org.hyperledger.besu.ethereum.vm.DebugOperationTracer; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; @@ -105,6 +105,7 @@ public Optional process( final BlockHeader header = blockchain.getBlockHeader(blockNumber).orElse(null); return process( callParams, + Optional.empty(), transactionValidationParams, operationTracer, (mutableWorldState, transactionSimulatorResult) -> transactionSimulatorResult, @@ -118,6 +119,7 @@ public Optional process( final BlockHeader blockHeader) { return process( callParams, + Optional.empty(), transactionValidationParams, operationTracer, (mutableWorldState, transactionSimulatorResult) -> transactionSimulatorResult, diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulatorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulatorTest.java index 0dfa7e924fa..e0715e58477 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulatorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulatorTest.java @@ -26,6 +26,7 @@ import org.hyperledger.besu.crypto.SECPSignature; import org.hyperledger.besu.crypto.SignatureAlgorithm; import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; +import org.hyperledger.besu.datatypes.AccountOverride; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.BlobsWithCommitments; import org.hyperledger.besu.datatypes.Hash; @@ -48,7 +49,6 @@ import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket; import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult.Status; -import org.hyperledger.besu.ethereum.util.AccountOverride; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.account.MutableAccount; diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/AccountOverrideParameterTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/AccountOverrideParameterTest.java index 8e7b5c3f0eb..1b6d8c1cbe3 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/AccountOverrideParameterTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/AccountOverrideParameterTest.java @@ -18,6 +18,8 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import org.hyperledger.besu.datatypes.AccountOverride; +import org.hyperledger.besu.datatypes.AccountOverrideMap; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 333cac59268..dfdf20bff21 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -71,7 +71,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'wOjR3/uPElPs1GonuLMBWStn1zukFMyy/GfQ9OYChpI=' + knownHash = 'IPpTJJxjDbjW08c3Cm8GbBhULYFy0jq9m3BzliGzrf8=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/TransactionSimulationService.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/TransactionSimulationService.java index dffdb0cfe51..d5fc0a34979 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/TransactionSimulationService.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/TransactionSimulationService.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.plugin.services; +import org.hyperledger.besu.datatypes.AccountOverrideMap; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.tracing.OperationTracer; @@ -39,4 +40,21 @@ Optional simulate( Hash blockHash, OperationTracer operationTracer, boolean isAllowExceedingBalance); + + /** + * Simulate transaction execution at the block identified by the hash + * + * @param transaction tx + * @param accountOverrides state overrides to apply to this simulation + * @param blockHash the hash of the block + * @param operationTracer the tracer + * @param isAllowExceedingBalance should ignore the sender balance during the simulation? + * @return the result of the simulation + */ + Optional simulate( + Transaction transaction, + Optional accountOverrides, + Hash blockHash, + OperationTracer operationTracer, + boolean isAllowExceedingBalance); } From ab12657f32923e3f2eedea56b41c40011c3aa008 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Thu, 21 Nov 2024 09:16:59 +1000 Subject: [PATCH 45/56] [CHANGELOG] Deprecation warnings for privacy, permissioning, PoW, fast sync (#7891) * typo * added deprecation for sunset group Signed-off-by: Sally MacFarlane --------- Signed-off-by: Sally MacFarlane --- CHANGELOG.md | 7 +++++++ docs/README.md | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cbda780979..ea2535d6ba0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,13 @@ ### Upcoming Breaking Changes - Plugin API will be deprecating the BesuContext interface to be replaced with the ServiceManager interface. - `MetricSystem::createLabelledGauge` is deprecated and will be removed in a future release, replace it with `MetricSystem::createLabelledSuppliedGauge` +- k8s (KUBERNETES) Nat method is now deprecated and will be removed in a future release +- `--host-whitelist` has been deprecated in favor of `--host-allowlist` since 2020 and will be removed in a future release +- Sunsetting features - for more context on the reasoning behind the deprecation of these features, including alternative options, read [this blog post](https://www.lfdecentralizedtrust.org/blog/sunsetting-tessera-and-simplifying-hyperledger-besu) + - Tessera privacy + - Smart-contract-based permissioning + - Proof of Work consensus + - Fast Sync ### Additions and Improvements - Fine tune already seen txs tracker when a tx is removed from the pool [#7755](https://github.com/hyperledger/besu/pull/7755) diff --git a/docs/README.md b/docs/README.md index c9584bfadca..5b22a3c3b5f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,4 +1,4 @@ -Besu user documentation was moved to as separate repository to help manage versions and releases. +Besu user documentation was moved to a separate repository to help manage versions and releases. If you want to contribute to the doc site, make a pull request against https://github.com/hyperledger/besu-docs From 7bb2cf390f2c5e0c349e36bb64df751a62c2e3eb Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Fri, 22 Nov 2024 08:39:27 +0700 Subject: [PATCH 46/56] Refactor Body Validation logic (#7896) Signed-off-by: Gabriel-Trintinalia --- .../besu/ethereum/MainnetBlockValidator.java | 20 +++- .../mainnet/BaseFeeBlockBodyValidator.java | 6 +- .../ethereum/mainnet/BlockBodyValidator.java | 15 +-- .../ethereum/mainnet/BodyValidationMode.java | 3 + .../mainnet/MainnetBlockBodyValidator.java | 67 ++++++----- .../BlockImportExceptionHandlingTest.java | 9 +- .../ethereum/MainnetBlockValidatorTest.java | 38 ++++--- .../MainnetBlockBodyValidatorTest.java | 106 +++++++++--------- .../FastSyncDownloadPipelineFactory.java | 9 +- .../eth/sync/fastsync/ImportBlocksStep.java | 8 +- .../sync/fastsync/ImportBlocksStepTest.java | 7 +- 11 files changed, 162 insertions(+), 126 deletions(-) diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/MainnetBlockValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/MainnetBlockValidator.java index 39f5cb0f66f..00766cdf574 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/MainnetBlockValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/MainnetBlockValidator.java @@ -171,7 +171,12 @@ public BlockProcessingResult validateAndProcessBlock( Optional> maybeRequests = result.getYield().flatMap(BlockProcessingOutputs::getRequests); if (!blockBodyValidator.validateBody( - context, block, receipts, worldState.rootHash(), ommerValidationMode)) { + context, + block, + receipts, + worldState.rootHash(), + ommerValidationMode, + BodyValidationMode.FULL)) { result = new BlockProcessingResult("failed to validate output of imported block"); handleFailedBlockProcessing(block, result, shouldRecordBadBlock); return result; @@ -246,6 +251,12 @@ public boolean validateBlockForSyncing( final HeaderValidationMode headerValidationMode, final HeaderValidationMode ommerValidationMode, final BodyValidationMode bodyValidationMode) { + + if (bodyValidationMode == BodyValidationMode.FULL) { + throw new UnsupportedOperationException( + "Full body validation is not supported for syncing blocks"); + } + final BlockHeader header = block.getHeader(); if (!blockHeaderValidator.validateHeader(header, context, headerValidationMode)) { String description = String.format("Failed header validation (%s)", headerValidationMode); @@ -253,8 +264,11 @@ public boolean validateBlockForSyncing( return false; } - if (!blockBodyValidator.validateBodyLight( - context, block, receipts, ommerValidationMode, bodyValidationMode)) { + if (bodyValidationMode == BodyValidationMode.NONE) { + return true; + } + + if (!blockBodyValidator.validateBodyLight(context, block, receipts, ommerValidationMode)) { badBlockManager.addBadBlock( block, BadBlockCause.fromValidationFailure("Failed body validation (light)")); return false; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BaseFeeBlockBodyValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BaseFeeBlockBodyValidator.java index 0d43a470228..62629dde665 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BaseFeeBlockBodyValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BaseFeeBlockBodyValidator.java @@ -41,11 +41,9 @@ public boolean validateBodyLight( final ProtocolContext context, final Block block, final List receipts, - final HeaderValidationMode ommerValidationMode, - final BodyValidationMode bodyValidationMode) { + final HeaderValidationMode ommerValidationMode) { - return super.validateBodyLight( - context, block, receipts, ommerValidationMode, bodyValidationMode) + return super.validateBodyLight(context, block, receipts, ommerValidationMode) && validateTransactionGasPrice(block); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BlockBodyValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BlockBodyValidator.java index 32000d12b96..53fb0f42432 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BlockBodyValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BlockBodyValidator.java @@ -33,14 +33,16 @@ public interface BlockBodyValidator { * @param worldStateRootHash The rootHash defining the world state after processing this block and * all of its transactions. * @param ommerValidationMode The validation mode to use for ommer headers + * @param bodyValidationMode The validation mode to use for the body * @return {@code true} if valid; otherwise {@code false} */ boolean validateBody( - ProtocolContext context, - Block block, - List receipts, - Hash worldStateRootHash, - final HeaderValidationMode ommerValidationMode); + final ProtocolContext context, + final Block block, + final List receipts, + final Hash worldStateRootHash, + final HeaderValidationMode ommerValidationMode, + final BodyValidationMode bodyValidationMode); /** * Validates that the block body is valid, but skips state root validation. @@ -55,6 +57,5 @@ boolean validateBodyLight( ProtocolContext context, Block block, List receipts, - final HeaderValidationMode ommerValidationMode, - final BodyValidationMode bodyValidationMode); + final HeaderValidationMode ommerValidationMode); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BodyValidationMode.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BodyValidationMode.java index 344a950e365..b8f7ca6028a 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BodyValidationMode.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BodyValidationMode.java @@ -21,6 +21,9 @@ public enum BodyValidationMode { /** Skip receipts and transactions root validation */ LIGHT, + /** Validate transactions, state, and receipts root */ + ROOT_ONLY, + /** Fully validate the body */ FULL; } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidator.java index 1423183e945..ccb16a587ad 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidator.java @@ -50,10 +50,39 @@ public boolean validateBody( final Block block, final List receipts, final Hash worldStateRootHash, - final HeaderValidationMode ommerValidationMode) { + final HeaderValidationMode ommerValidationMode, + final BodyValidationMode bodyValidationMode) { + if (bodyValidationMode == BodyValidationMode.NONE) { + return true; + } + + if (bodyValidationMode == BodyValidationMode.LIGHT + || bodyValidationMode == BodyValidationMode.FULL) { + if (!validateBodyLight(context, block, receipts, ommerValidationMode)) { + return false; + } + } + + if (bodyValidationMode == BodyValidationMode.ROOT_ONLY + || bodyValidationMode == BodyValidationMode.FULL) { + return validateBodyRoots(block, receipts, worldStateRootHash); + } + return true; + } + + @VisibleForTesting + protected boolean validateBodyRoots( + final Block block, final List receipts, final Hash worldStateRootHash) { + final BlockHeader header = block.getHeader(); + final BlockBody body = block.getBody(); + + final Bytes32 transactionsRoot = BodyValidation.transactionsRoot(body.getTransactions()); + if (!validateTransactionsRoot(header, header.getTransactionsRoot(), transactionsRoot)) { + return false; + } - if (!validateBodyLight( - context, block, receipts, ommerValidationMode, BodyValidationMode.FULL)) { + final Bytes32 receiptsRoot = BodyValidation.receiptsRoot(receipts); + if (!validateReceiptsRoot(header, header.getReceiptsRoot(), receiptsRoot)) { return false; } @@ -65,7 +94,6 @@ public boolean validateBody( LOG.warn("Transaction receipt found in the invalid block {}", receipt.toString())); return false; } - return true; } @@ -74,27 +102,9 @@ public boolean validateBodyLight( final ProtocolContext context, final Block block, final List receipts, - final HeaderValidationMode ommerValidationMode, - final BodyValidationMode bodyValidationMode) { - if (bodyValidationMode == BodyValidationMode.NONE) { - return true; - } + final HeaderValidationMode ommerValidationMode) { final BlockHeader header = block.getHeader(); - final BlockBody body = block.getBody(); - - // these checks are only needed for full validation and can be skipped for light validation - if (bodyValidationMode == BodyValidationMode.FULL) { - final Bytes32 transactionsRoot = BodyValidation.transactionsRoot(body.getTransactions()); - if (!validateTransactionsRoot(header, header.getTransactionsRoot(), transactionsRoot)) { - return false; - } - - final Bytes32 receiptsRoot = BodyValidation.receiptsRoot(receipts); - if (!validateReceiptsRoot(header, header.getReceiptsRoot(), receiptsRoot)) { - return false; - } - } final long gasUsed = receipts.isEmpty() ? 0 : receipts.get(receipts.size() - 1).getCumulativeGasUsed(); @@ -113,15 +123,13 @@ public boolean validateBodyLight( if (!validateWithdrawals(block)) { return false; } - return true; } - @VisibleForTesting - protected boolean validateTransactionsRoot( + private boolean validateTransactionsRoot( final BlockHeader header, final Bytes32 expected, final Bytes32 actual) { if (!expected.equals(actual)) { - LOG.info( + LOG.warn( "Invalid block {}: transaction root mismatch (expected={}, actual={})", header.toLogString(), expected, @@ -160,8 +168,7 @@ private static boolean validateGasUsed( return true; } - @VisibleForTesting - protected boolean validateReceiptsRoot( + private boolean validateReceiptsRoot( final BlockHeader header, final Bytes32 expected, final Bytes32 actual) { if (!expected.equals(actual)) { LOG.warn( @@ -175,7 +182,7 @@ protected boolean validateReceiptsRoot( return true; } - private static boolean validateStateRoot( + private boolean validateStateRoot( final BlockHeader header, final Bytes32 expected, final Bytes32 actual) { if (!expected.equals(actual)) { LOG.warn( diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/BlockImportExceptionHandlingTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/BlockImportExceptionHandlingTest.java index f9a325f3d7e..06580ad4dea 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/BlockImportExceptionHandlingTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/BlockImportExceptionHandlingTest.java @@ -153,7 +153,8 @@ void shouldNotBadBlockWhenInternalErrorDuringPersisting() { eq(goodBlock), any(), any(), - eq(HeaderValidationMode.DETACHED_ONLY))) + eq(HeaderValidationMode.DETACHED_ONLY), + any())) .thenReturn(true); assertThat(badBlockManager.getBadBlocks()).isEmpty(); mainnetBlockValidator.validateAndProcessBlock( @@ -189,7 +190,8 @@ void shouldNotBadBlockWhenInternalErrorOnBlockLookup() { eq(goodBlock), any(), any(), - eq(HeaderValidationMode.DETACHED_ONLY))) + eq(HeaderValidationMode.DETACHED_ONLY), + any())) .thenReturn(true); assertThat(badBlockManager.getBadBlocks()).isEmpty(); mainnetBlockValidator.validateAndProcessBlock( @@ -257,7 +259,8 @@ void shouldNotBadBlockWhenInternalErrorDuringValidateBody() { eq(goodBlock), any(), any(), - eq(HeaderValidationMode.DETACHED_ONLY))) + eq(HeaderValidationMode.DETACHED_ONLY), + any())) .thenThrow(new StorageException("database problem")); assertThat(badBlockManager.getBadBlocks()).isEmpty(); mainnetBlockValidator.validateAndProcessBlock( diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/MainnetBlockValidatorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/MainnetBlockValidatorTest.java index 255ea778395..96e8cafe191 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/MainnetBlockValidatorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/MainnetBlockValidatorTest.java @@ -15,6 +15,7 @@ package org.hyperledger.besu.ethereum; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.eq; @@ -97,8 +98,9 @@ public void setup() { when(worldStateArchive.getMutable()).thenReturn(worldState); when(blockHeaderValidator.validateHeader(any(), any(), any())).thenReturn(true); when(blockHeaderValidator.validateHeader(any(), any(), any(), any())).thenReturn(true); - when(blockBodyValidator.validateBody(any(), any(), any(), any(), any())).thenReturn(true); - when(blockBodyValidator.validateBodyLight(any(), any(), any(), any(), any())).thenReturn(true); + when(blockBodyValidator.validateBody(any(), any(), any(), any(), any(), any())) + .thenReturn(true); + when(blockBodyValidator.validateBodyLight(any(), any(), any(), any())).thenReturn(true); when(blockProcessor.processBlock(any(), any(), any())).thenReturn(successfulProcessingResult); when(blockProcessor.processBlock(any(), any(), any(), any())) .thenReturn(successfulProcessingResult); @@ -163,7 +165,8 @@ public void validateAndProcessBlock_whenHeaderInvalid() { @Test public void validateAndProcessBlock_whenBlockBodyInvalid() { - when(blockBodyValidator.validateBody(any(), eq(block), any(), any(), any())).thenReturn(false); + when(blockBodyValidator.validateBody(any(), eq(block), any(), any(), any(), any())) + .thenReturn(false); BlockProcessingResult result = mainnetBlockValidator.validateAndProcessBlock( @@ -350,7 +353,7 @@ public void validateBlockForSyncing_onSuccess() { Collections.emptyList(), HeaderValidationMode.FULL, HeaderValidationMode.FULL, - BodyValidationMode.FULL); + BodyValidationMode.LIGHT); assertThat(isValid).isTrue(); assertNoBadBlocks(); @@ -362,7 +365,6 @@ public void validateBlockValidation_onFailedHeaderForSyncing() { when(blockHeaderValidator.validateHeader( any(BlockHeader.class), eq(protocolContext), eq(headerValidationMode))) .thenReturn(false); - final BodyValidationMode bodyValidationMode = BodyValidationMode.FULL; final boolean isValid = mainnetBlockValidator.validateBlockForSyncing( @@ -371,7 +373,7 @@ public void validateBlockValidation_onFailedHeaderForSyncing() { Collections.emptyList(), headerValidationMode, headerValidationMode, - bodyValidationMode); + BodyValidationMode.LIGHT); assertThat(isValid).isFalse(); assertBadBlockIsTracked(block); @@ -380,13 +382,8 @@ public void validateBlockValidation_onFailedHeaderForSyncing() { @Test public void validateBlockValidation_onFailedBodyForSyncing() { final HeaderValidationMode headerValidationMode = HeaderValidationMode.FULL; - final BodyValidationMode bodyValidationMode = BodyValidationMode.FULL; when(blockBodyValidator.validateBodyLight( - eq(protocolContext), - eq(block), - any(), - eq(headerValidationMode), - eq(bodyValidationMode))) + eq(protocolContext), eq(block), any(), eq(headerValidationMode))) .thenReturn(false); final boolean isValid = @@ -396,12 +393,27 @@ public void validateBlockValidation_onFailedBodyForSyncing() { Collections.emptyList(), headerValidationMode, headerValidationMode, - bodyValidationMode); + BodyValidationMode.LIGHT); assertThat(isValid).isFalse(); assertBadBlockIsTracked(block); } + @Test + public void shouldThrowIfValidateForSyncingWithFullBodyValidation() { + final HeaderValidationMode headerValidationMode = HeaderValidationMode.FULL; + assertThrows( + UnsupportedOperationException.class, + () -> + mainnetBlockValidator.validateBlockForSyncing( + protocolContext, + block, + Collections.emptyList(), + headerValidationMode, + headerValidationMode, + BodyValidationMode.FULL)); + } + private void assertNoBadBlocks() { assertThat(badBlockManager.getBadBlocks()).isEmpty(); } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidatorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidatorTest.java index 8c25d4f58ed..8665cb70ac3 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidatorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidatorTest.java @@ -95,11 +95,7 @@ void validatesWithdrawals() { assertThat( new MainnetBlockBodyValidator(protocolSchedule) .validateBodyLight( - blockchainSetupUtil.getProtocolContext(), - block, - emptyList(), - NONE, - BodyValidationMode.FULL)) + blockchainSetupUtil.getProtocolContext(), block, emptyList(), NONE)) .isTrue(); } @@ -123,11 +119,7 @@ void validationFailsIfWithdrawalsValidationFails() { assertThat( new MainnetBlockBodyValidator(protocolSchedule) .validateBodyLight( - blockchainSetupUtil.getProtocolContext(), - block, - emptyList(), - NONE, - BodyValidationMode.FULL)) + blockchainSetupUtil.getProtocolContext(), block, emptyList(), NONE)) .isFalse(); } @@ -151,11 +143,7 @@ void validationFailsIfWithdrawalsRootValidationFails() { assertThat( new MainnetBlockBodyValidator(protocolSchedule) .validateBodyLight( - blockchainSetupUtil.getProtocolContext(), - block, - emptyList(), - NONE, - BodyValidationMode.FULL)) + blockchainSetupUtil.getProtocolContext(), block, emptyList(), NONE)) .isFalse(); } @@ -168,10 +156,11 @@ public void noneValidationModeDoesNothing() { final MainnetBlockBodyValidator bodyValidator = new MainnetBlockBodyValidator(protocolSchedule); assertThat( - bodyValidator.validateBodyLight( + bodyValidator.validateBody( blockchainSetupUtil.getProtocolContext(), block, receipts, + Hash.ZERO, NONE, BodyValidationMode.NONE)) .isTrue(); @@ -180,66 +169,79 @@ public void noneValidationModeDoesNothing() { } @Test - public void lightValidationDoesNotCheckTransactionRootOrReceiptRoot() { - final Block block = - blockDataGenerator.block( - new BlockOptions() - .setBlockNumber(1) - .setGasUsed(0) - .hasTransactions(false) - .hasOmmers(false) - .setReceiptsRoot(BodyValidation.receiptsRoot(emptyList())) - .setLogsBloom(LogsBloomFilter.empty()) - .setParentHash(blockchainSetupUtil.getBlockchain().getChainHeadHash()) - .setWithdrawals(Optional.of(withdrawals))); - blockchainSetupUtil.getBlockchain().appendBlock(block, Collections.emptyList()); + public void lightValidationDoesNotCheckRoots() { + final Block block = setupBlock(); final MainnetBlockBodyValidator bodyValidator = new MainnetBlockBodyValidator(protocolSchedule); final MainnetBlockBodyValidator bodyValidatorSpy = spy(bodyValidator); assertThat( - bodyValidatorSpy.validateBodyLight( + bodyValidatorSpy.validateBody( blockchainSetupUtil.getProtocolContext(), block, emptyList(), + Hash.ZERO, NONE, BodyValidationMode.LIGHT)) .isTrue(); - verify(bodyValidatorSpy, never()).validateReceiptsRoot(any(), any(), any()); - verify(bodyValidatorSpy, never()).validateTransactionsRoot(any(), any(), any()); + verify(bodyValidatorSpy, times(1)).validateBodyLight(any(), any(), any(), any()); + verify(bodyValidatorSpy, never()).validateBodyRoots(any(), any(), any()); } @Test - public void fullValidationChecksTransactionRootAndReceiptRoot() { - final Block block = - blockDataGenerator.block( - new BlockOptions() - .setBlockNumber(1) - .setGasUsed(0) - .hasTransactions(false) - .hasOmmers(false) - .setReceiptsRoot(BodyValidation.receiptsRoot(emptyList())) - .setLogsBloom(LogsBloomFilter.empty()) - .setParentHash(blockchainSetupUtil.getBlockchain().getChainHeadHash()) - .setWithdrawals(Optional.of(withdrawals))); - blockchainSetupUtil.getBlockchain().appendBlock(block, Collections.emptyList()); + public void hashOnlyValidationChecksOnlyRoots() { + final Block block = setupBlock(); final MainnetBlockBodyValidator bodyValidator = new MainnetBlockBodyValidator(protocolSchedule); final MainnetBlockBodyValidator bodyValidatorSpy = spy(bodyValidator); assertThat( - bodyValidatorSpy.validateBodyLight( + bodyValidatorSpy.validateBody( blockchainSetupUtil.getProtocolContext(), block, emptyList(), + block.getHeader().getStateRoot(), + NONE, + BodyValidationMode.ROOT_ONLY)) + .isTrue(); + + verify(bodyValidatorSpy, never()).validateBodyLight(any(), any(), any(), any()); + verify(bodyValidatorSpy, times(1)).validateBodyRoots(any(), any(), any()); + } + + @Test + public void fullValidationChecksRootsAndContent() { + final Block block = setupBlock(); + + final MainnetBlockBodyValidator bodyValidator = new MainnetBlockBodyValidator(protocolSchedule); + final MainnetBlockBodyValidator bodyValidatorSpy = spy(bodyValidator); + + assertThat( + bodyValidatorSpy.validateBody( + blockchainSetupUtil.getProtocolContext(), + block, + emptyList(), + block.getHeader().getStateRoot(), NONE, BodyValidationMode.FULL)) .isTrue(); - final Hash receiptsRoot = BodyValidation.receiptsRoot(emptyList()); - final Hash transactionsRoot = BodyValidation.transactionsRoot(emptyList()); - verify(bodyValidatorSpy, times(1)) - .validateReceiptsRoot(block.getHeader(), receiptsRoot, receiptsRoot); - verify(bodyValidatorSpy, times(1)) - .validateTransactionsRoot(block.getHeader(), transactionsRoot, transactionsRoot); + verify(bodyValidatorSpy, times(1)).validateBodyLight(any(), any(), any(), any()); + verify(bodyValidatorSpy, times(1)).validateBodyRoots(any(), any(), any()); + } + + private Block setupBlock() { + Block block = + blockDataGenerator.block( + new BlockOptions() + .setBlockNumber(1) + .setGasUsed(0) + .hasTransactions(false) + .hasOmmers(false) + .setReceiptsRoot(BodyValidation.receiptsRoot(emptyList())) + .setLogsBloom(LogsBloomFilter.empty()) + .setParentHash(blockchainSetupUtil.getBlockchain().getChainHeadHash()) + .setWithdrawals(Optional.of(withdrawals))); + blockchainSetupUtil.getBlockchain().appendBlock(block, Collections.emptyList()); + return block; } } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java index ac562608873..67085252e8f 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java @@ -38,7 +38,6 @@ import org.hyperledger.besu.ethereum.eth.sync.range.SyncTargetRangeSource; import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; import org.hyperledger.besu.ethereum.eth.sync.state.SyncTarget; -import org.hyperledger.besu.ethereum.mainnet.BodyValidationMode; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.plugin.services.MetricsSystem; @@ -122,10 +121,7 @@ public Pipeline createDownloadPipelineForSyncTarget(final SyncT final int downloaderParallelism = syncConfig.getDownloaderParallelism(); final int headerRequestSize = syncConfig.getDownloaderHeaderRequestSize(); final int singleHeaderBufferSize = headerRequestSize * downloaderParallelism; - final BodyValidationMode bodyValidationMode = - protocolSchedule.anyMatch(scheduledProtocolSpec -> scheduledProtocolSpec.spec().isPoS()) - ? BodyValidationMode.NONE - : BodyValidationMode.LIGHT; + final SyncTargetRangeSource checkpointRangeSource = new SyncTargetRangeSource( new RangeHeadersFetcher( @@ -158,8 +154,7 @@ public Pipeline createDownloadPipelineForSyncTarget(final SyncT attachedValidationPolicy, ommerValidationPolicy, ethContext, - fastSyncState.getPivotBlockHeader().get(), - bodyValidationMode); + fastSyncState.getPivotBlockHeader().get()); return PipelineBuilder.createPipelineFrom( "fetchCheckpoints", diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/ImportBlocksStep.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/ImportBlocksStep.java index 20b9d84916a..4397ed011c7 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/ImportBlocksStep.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/ImportBlocksStep.java @@ -54,15 +54,17 @@ public ImportBlocksStep( final ValidationPolicy headerValidationPolicy, final ValidationPolicy ommerValidationPolicy, final EthContext ethContext, - final BlockHeader pivotHeader, - final BodyValidationMode bodyValidationMode) { + final BlockHeader pivotHeader) { this.protocolSchedule = protocolSchedule; this.protocolContext = protocolContext; this.headerValidationPolicy = headerValidationPolicy; this.ommerValidationPolicy = ommerValidationPolicy; this.ethContext = ethContext; this.pivotHeader = pivotHeader; - this.bodyValidationMode = bodyValidationMode; + bodyValidationMode = + protocolSchedule.anyMatch(scheduledProtocolSpec -> scheduledProtocolSpec.spec().isPoS()) + ? BodyValidationMode.NONE + : BodyValidationMode.LIGHT; } @Override diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/ImportBlocksStepTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/ImportBlocksStepTest.java index af4f45f6901..c26e730aa38 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/ImportBlocksStepTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/ImportBlocksStepTest.java @@ -73,8 +73,7 @@ public void setUp() { validationPolicy, ommerValidationPolicy, null, - pivotHeader, - BodyValidationMode.FULL); + pivotHeader); } @Test @@ -92,7 +91,7 @@ public void shouldImportBlocks() { blockWithReceipts.getReceipts(), FULL, LIGHT, - BodyValidationMode.FULL)) + BodyValidationMode.LIGHT)) .thenReturn(new BlockImportResult(true)); } importBlocksStep.accept(blocksWithReceipts); @@ -114,7 +113,7 @@ public void shouldThrowExceptionWhenValidationFails() { blockWithReceipts.getReceipts(), FULL, LIGHT, - BodyValidationMode.FULL)) + BodyValidationMode.LIGHT)) .thenReturn(new BlockImportResult(false)); assertThatThrownBy(() -> importBlocksStep.accept(singletonList(blockWithReceipts))) .isInstanceOf(InvalidBlockException.class); From 302999aa18568f4e001b86fffcf57231a6fd4f65 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Fri, 22 Nov 2024 12:08:04 +1000 Subject: [PATCH 47/56] Privacy deprecation warnings on CLI (#7897) * add deprecation notice to help descriptions for all privacy options * log deprecation warning for privacy enabled options * added @Deprecation annotations to privacy plugin classes Signed-off-by: Sally MacFarlane --------- Signed-off-by: Sally MacFarlane --- .../TestPrivacyPluginPayloadProvider.java | 1 + .../org/hyperledger/besu/cli/BesuCommand.java | 47 ++++++++++++++----- .../cli/options/PrivacyPluginOptions.java | 3 +- .../services/PrivacyPluginServiceImpl.java | 1 + .../PrivacyPluginPrecompiledContract.java | 1 + plugin-api/build.gradle | 2 +- .../plugin/services/PrivacyPluginService.java | 1 + .../privacy/PrivacyPluginPayloadProvider.java | 1 + 8 files changed, 42 insertions(+), 15 deletions(-) diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/privacy/TestPrivacyPluginPayloadProvider.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/privacy/TestPrivacyPluginPayloadProvider.java index c375946c98b..c4044fc4324 100644 --- a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/privacy/TestPrivacyPluginPayloadProvider.java +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/privacy/TestPrivacyPluginPayloadProvider.java @@ -28,6 +28,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public class TestPrivacyPluginPayloadProvider implements PrivacyPluginPayloadProvider { private static final Logger LOG = LoggerFactory.getLogger(TestPrivacyPluginPayloadProvider.class); private String prefix; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index f817dfb8a69..c12b405e53f 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -505,77 +505,95 @@ void setUserName(final String userName) { @CommandLine.ArgGroup(validate = false, heading = "@|bold In-Process RPC Options|@%n") InProcessRpcOptions inProcessRpcOptions = InProcessRpcOptions.create(); + private static final String PRIVACY_DEPRECATION_PREFIX = + "Deprecated. Tessera-based privacy is deprecated. See CHANGELOG for alternative options. "; + // Privacy Options Group - @CommandLine.ArgGroup(validate = false, heading = "@|bold Privacy Options|@%n") + @CommandLine.ArgGroup(validate = false, heading = "@|bold (Deprecated) Privacy Options |@%n") PrivacyOptionGroup privacyOptionGroup = new PrivacyOptionGroup(); static class PrivacyOptionGroup { @Option( names = {"--privacy-tls-enabled"}, paramLabel = MANDATORY_FILE_FORMAT_HELP, - description = "Enable TLS for connecting to privacy enclave (default: ${DEFAULT-VALUE})") + description = + PRIVACY_DEPRECATION_PREFIX + + "Enable TLS for connecting to privacy enclave (default: ${DEFAULT-VALUE})") private final Boolean isPrivacyTlsEnabled = false; @Option( names = "--privacy-tls-keystore-file", paramLabel = MANDATORY_FILE_FORMAT_HELP, description = - "Path to a PKCS#12 formatted keystore; used to enable TLS on inbound connections.") + PRIVACY_DEPRECATION_PREFIX + + "Path to a PKCS#12 formatted keystore; used to enable TLS on inbound connections.") private final Path privacyKeyStoreFile = null; @Option( names = "--privacy-tls-keystore-password-file", paramLabel = MANDATORY_FILE_FORMAT_HELP, - description = "Path to a file containing the password used to decrypt the keystore.") + description = + PRIVACY_DEPRECATION_PREFIX + + "Path to a file containing the password used to decrypt the keystore.") private final Path privacyKeyStorePasswordFile = null; @Option( names = "--privacy-tls-known-enclave-file", paramLabel = MANDATORY_FILE_FORMAT_HELP, description = - "Path to a file containing the fingerprints of the authorized privacy enclave.") + PRIVACY_DEPRECATION_PREFIX + + "Path to a file containing the fingerprints of the authorized privacy enclave.") private final Path privacyTlsKnownEnclaveFile = null; @Option( names = {"--privacy-enabled"}, - description = "Enable private transactions (default: ${DEFAULT-VALUE})") + description = + PRIVACY_DEPRECATION_PREFIX + "Enable private transactions (default: ${DEFAULT-VALUE})") private final Boolean isPrivacyEnabled = false; @Option( names = {"--privacy-multi-tenancy-enabled"}, - description = "Enable multi-tenant private transactions (default: ${DEFAULT-VALUE})") + description = + PRIVACY_DEPRECATION_PREFIX + + "Enable multi-tenant private transactions (default: ${DEFAULT-VALUE})") private final Boolean isPrivacyMultiTenancyEnabled = false; @Option( names = {"--privacy-url"}, - description = "The URL on which the enclave is running") + description = PRIVACY_DEPRECATION_PREFIX + "The URL on which the enclave is running") private final URI privacyUrl = PrivacyParameters.DEFAULT_ENCLAVE_URL; @Option( names = {"--privacy-public-key-file"}, - description = "The enclave's public key file") + description = PRIVACY_DEPRECATION_PREFIX + "The enclave's public key file") private final File privacyPublicKeyFile = null; @Option( names = {"--privacy-marker-transaction-signing-key-file"}, description = - "The name of a file containing the private key used to sign privacy marker transactions. If unset, each will be signed with a random key.") + PRIVACY_DEPRECATION_PREFIX + + "The name of a file containing the private key used to sign privacy marker transactions. If unset, each will be signed with a random key.") private final Path privateMarkerTransactionSigningKeyPath = null; @Option( names = {"--privacy-enable-database-migration"}, - description = "Enable private database metadata migration (default: ${DEFAULT-VALUE})") + description = + PRIVACY_DEPRECATION_PREFIX + + "Enable private database metadata migration (default: ${DEFAULT-VALUE})") private final Boolean migratePrivateDatabase = false; @Option( names = {"--privacy-flexible-groups-enabled"}, - description = "Enable flexible privacy groups (default: ${DEFAULT-VALUE})") + description = + PRIVACY_DEPRECATION_PREFIX + + "Enable flexible privacy groups (default: ${DEFAULT-VALUE})") private final Boolean isFlexiblePrivacyGroupsEnabled = false; @Option( names = {"--privacy-nonce-always-increments"}, description = - "Enable private nonce " + PRIVACY_DEPRECATION_PREFIX + + "Enable private nonce " + "incrementation even if the transaction didn't succeeded (default: ${DEFAULT-VALUE})") private final Boolean isPrivateNonceAlwaysIncrementsEnabled = false; } @@ -1293,6 +1311,8 @@ private void validatePrivacyPluginOptions() { // after start has been called on plugins if (Boolean.TRUE.equals(privacyOptionGroup.isPrivacyEnabled)) { + logger.warn( + "--Xprivacy-plugin-enabled and related options are " + PRIVACY_DEPRECATION_PREFIX); if (privacyOptionGroup.privateMarkerTransactionSigningKeyPath != null && privacyPluginService != null @@ -1922,6 +1942,7 @@ private PrivacyParameters privacyParameters() { final PrivacyParameters.Builder privacyParametersBuilder = new PrivacyParameters.Builder(); if (Boolean.TRUE.equals(privacyOptionGroup.isPrivacyEnabled)) { + logger.warn("--privacy-enabled and related options are " + PRIVACY_DEPRECATION_PREFIX); final String errorSuffix = "cannot be enabled with privacy."; if (syncMode == SyncMode.FAST) { throw new ParameterException(commandLine, String.format("%s %s", "Fast sync", errorSuffix)); diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/PrivacyPluginOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/PrivacyPluginOptions.java index 9a8c0348e8b..7842c09923f 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/PrivacyPluginOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/PrivacyPluginOptions.java @@ -17,6 +17,7 @@ import static picocli.CommandLine.Option; /** The Privacy plugin Cli options. */ +@Deprecated(since = "24.11.0") public class PrivacyPluginOptions { /** Default Constructor. */ PrivacyPluginOptions() {} @@ -33,7 +34,7 @@ public static PrivacyPluginOptions create() { @Option( names = "--Xprivacy-plugin-enabled", description = - "Enables the use of a plugin to implement your own privacy strategy (default: ${DEFAULT-VALUE})", + "Deprecated. Tessera-based privacy is deprecated. See CHANGELOG for alternative options. Enables the use of a plugin to implement your own privacy strategy (default: ${DEFAULT-VALUE})", hidden = true) private final Boolean isPrivacyPluginEnabled = false; diff --git a/besu/src/main/java/org/hyperledger/besu/services/PrivacyPluginServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/PrivacyPluginServiceImpl.java index 4592753b9ce..fe61c7a4507 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/PrivacyPluginServiceImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/PrivacyPluginServiceImpl.java @@ -24,6 +24,7 @@ import org.slf4j.LoggerFactory; /** The Privacy plugin service implementation. */ +@Deprecated(since = "24.11.0") public class PrivacyPluginServiceImpl implements PrivacyPluginService { private static final Logger LOG = LoggerFactory.getLogger(PrivacyPluginServiceImpl.class); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/PrivacyPluginPrecompiledContract.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/PrivacyPluginPrecompiledContract.java index 723af2efa4f..708aa118f09 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/PrivacyPluginPrecompiledContract.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/PrivacyPluginPrecompiledContract.java @@ -34,6 +34,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public class PrivacyPluginPrecompiledContract extends PrivacyPrecompiledContract { private static final Logger LOG = LoggerFactory.getLogger(PrivacyPluginPrecompiledContract.class); private final PrivacyParameters privacyParameters; diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index dfdf20bff21..57f0987bcb6 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -71,7 +71,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'IPpTJJxjDbjW08c3Cm8GbBhULYFy0jq9m3BzliGzrf8=' + knownHash = 'vI9RTAGD6sRzAaMp1BMJY7x4cB3wh7FA4rYvDGYRceg=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PrivacyPluginService.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PrivacyPluginService.java index 7652e3ade9a..52c43cb6b4c 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PrivacyPluginService.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PrivacyPluginService.java @@ -26,6 +26,7 @@ * optionally register a {@link PrivateMarkerTransactionFactory} and a {@link * PrivacyGroupGenesisProvider}* */ +@Deprecated(since = "24.11.0") public interface PrivacyPluginService extends BesuService { /** diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/privacy/PrivacyPluginPayloadProvider.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/privacy/PrivacyPluginPayloadProvider.java index 6604cba8b5a..babbf8fd72c 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/privacy/PrivacyPluginPayloadProvider.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/privacy/PrivacyPluginPayloadProvider.java @@ -25,6 +25,7 @@ * Allows you to register a provider that will dictate how the payload of a privacy marker * transaction is handled. */ +@Deprecated(since = "24.11.0") public interface PrivacyPluginPayloadProvider { /** From 35b138db940539abffa818f03843592aad7d3969 Mon Sep 17 00:00:00 2001 From: Donny <130464015+defitricks@users.noreply.github.com> Date: Fri, 22 Nov 2024 06:42:33 +0200 Subject: [PATCH 48/56] Fix minor stylistic issue in tracing documentation (#7901) This pull request addresses a minor stylistic improvement in the documentation. Signed-off-by: Donny <130464015+defitricks@users.noreply.github.com> Co-authored-by: Sally MacFarlane --- docs/tracing/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tracing/README.md b/docs/tracing/README.md index 3a3f9fa435f..798496cfd48 100644 --- a/docs/tracing/README.md +++ b/docs/tracing/README.md @@ -2,7 +2,7 @@ Hyperledger Besu integrates with the [open-telemetry](https://opentelemetry.io/) project to integrate tracing reporting. -This allows to report all JSON-RPC traffic as traces. +This allows reporting all JSON-RPC traffic as traces. To try out this example, start the Open Telemetry Collector and the Zipkin service with: From 4a629dac1a3a41a6a39bb2393c5520d873f6d2d6 Mon Sep 17 00:00:00 2001 From: garyschulte Date: Sun, 24 Nov 2024 12:41:53 -0800 Subject: [PATCH 49/56] shorten rolling increment to 32 (#7909) Signed-off-by: garyschulte --- .../ethereum/api/jsonrpc/internal/methods/DebugSetHead.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java index c2210f81748..444fc8cf93f 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java @@ -40,7 +40,7 @@ public class DebugSetHead extends AbstractBlockParameterOrBlockHashMethod { private final ProtocolContext protocolContext; private static final Logger LOG = LoggerFactory.getLogger(DebugSetHead.class); - private static final int DEFAULT_MAX_TRIE_LOGS_TO_ROLL_AT_ONCE = 512; + private static final int DEFAULT_MAX_TRIE_LOGS_TO_ROLL_AT_ONCE = 32; private final long maxTrieLogsToRollAtOnce; From 6a2f4c9b861c311d7cf26d2f7f0178797db807a9 Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Sun, 24 Nov 2024 22:54:26 +0100 Subject: [PATCH 50/56] Correct other counters that were created as gauges (#7908) Signed-off-by: Fabio Di Fabio Co-authored-by: Sally MacFarlane --- .../eth/sync/snapsync/SnapSyncMetricsManager.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapSyncMetricsManager.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapSyncMetricsManager.java index 1091c766bd7..ddd4f781b12 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapSyncMetricsManager.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapSyncMetricsManager.java @@ -91,37 +91,37 @@ public SnapSyncMetricsManager(final MetricsSystem metricsSystem, final EthContex nbFlatAccountsHealed = new AtomicLong(0); nbFlatSlotsHealed = new AtomicLong(0); nbTrieNodesHealed = new AtomicLong(0); - metricsSystem.createLongGauge( + metricsSystem.createCounter( BesuMetricCategory.SYNCHRONIZER, "snap_world_state_generated_nodes_total", "Total number of data nodes generated as part of snap sync world state download", nbTrieNodesGenerated::get); - metricsSystem.createLongGauge( + metricsSystem.createCounter( BesuMetricCategory.SYNCHRONIZER, "snap_world_state_healed_nodes_total", "Total number of data nodes healed as part of snap sync world state heal process", nbTrieNodesHealed::get); - metricsSystem.createLongGauge( + metricsSystem.createCounter( BesuMetricCategory.SYNCHRONIZER, "snap_world_state_accounts_total", "Total number of accounts downloaded as part of snap sync world state", nbAccountsDownloaded::get); - metricsSystem.createLongGauge( + metricsSystem.createCounter( BesuMetricCategory.SYNCHRONIZER, "snap_world_state_slots_total", "Total number of slots downloaded as part of snap sync world state", nbSlotsDownloaded::get); - metricsSystem.createLongGauge( + metricsSystem.createCounter( BesuMetricCategory.SYNCHRONIZER, "snap_world_state_flat_accounts_healed_total", "Total number of accounts healed in the flat database as part of snap sync world state", nbFlatAccountsHealed::get); - metricsSystem.createLongGauge( + metricsSystem.createCounter( BesuMetricCategory.SYNCHRONIZER, "snap_world_state_flat_slots_healed_total", "Total number of slots healed in the flat database as part of snap sync world state", nbFlatSlotsHealed::get); - metricsSystem.createLongGauge( + metricsSystem.createCounter( BesuMetricCategory.SYNCHRONIZER, "snap_world_state_codes_total", "Total number of codes downloaded as part of snap sync world state", From 40648511cb2c6e6db7a0617b1c0c4fc33ad71c61 Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Mon, 25 Nov 2024 12:59:14 +1100 Subject: [PATCH 51/56] Add mining service (#7913) Signed-off-by: Gabriel-Trintinalia --- .../dsl/node/ThreadBesuNodeRunner.java | 4 ++ .../org/hyperledger/besu/cli/BesuCommand.java | 5 ++ .../besu/services/MiningServiceImpl.java | 49 +++++++++++++++++++ plugin-api/build.gradle | 2 +- .../plugin/services/mining/MiningService.java | 27 ++++++++++ 5 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 besu/src/main/java/org/hyperledger/besu/services/MiningServiceImpl.java create mode 100644 plugin-api/src/main/java/org/hyperledger/besu/plugin/services/mining/MiningService.java diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java index 6f9ed42828a..9effaff4d44 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java @@ -74,12 +74,14 @@ import org.hyperledger.besu.plugin.services.TransactionSelectionService; import org.hyperledger.besu.plugin.services.TransactionSimulationService; import org.hyperledger.besu.plugin.services.metrics.MetricCategoryRegistry; +import org.hyperledger.besu.plugin.services.mining.MiningService; import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBPlugin; import org.hyperledger.besu.plugin.services.transactionpool.TransactionPoolService; import org.hyperledger.besu.services.BesuConfigurationImpl; import org.hyperledger.besu.services.BesuEventsImpl; import org.hyperledger.besu.services.BesuPluginContextImpl; import org.hyperledger.besu.services.BlockchainServiceImpl; +import org.hyperledger.besu.services.MiningServiceImpl; import org.hyperledger.besu.services.PermissioningServiceImpl; import org.hyperledger.besu.services.PicoCLIOptionsImpl; import org.hyperledger.besu.services.PrivacyPluginServiceImpl; @@ -220,6 +222,8 @@ public void startNode(final BesuNode node) { besuPluginContext.addService( TransactionPoolService.class, new TransactionPoolServiceImpl(besuController.getTransactionPool())); + besuPluginContext.addService( + MiningService.class, new MiningServiceImpl(besuController.getMiningCoordinator())); component.rpcEndpointService().init(runner.getInProcessRpcMethods()); diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index c12b405e53f..1a842acc589 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -169,6 +169,7 @@ import org.hyperledger.besu.plugin.services.TransactionSimulationService; import org.hyperledger.besu.plugin.services.exception.StorageException; import org.hyperledger.besu.plugin.services.metrics.MetricCategoryRegistry; +import org.hyperledger.besu.plugin.services.mining.MiningService; import org.hyperledger.besu.plugin.services.p2p.P2PService; import org.hyperledger.besu.plugin.services.rlp.RlpConverterService; import org.hyperledger.besu.plugin.services.securitymodule.SecurityModule; @@ -181,6 +182,7 @@ import org.hyperledger.besu.services.BesuEventsImpl; import org.hyperledger.besu.services.BesuPluginContextImpl; import org.hyperledger.besu.services.BlockchainServiceImpl; +import org.hyperledger.besu.services.MiningServiceImpl; import org.hyperledger.besu.services.P2PServiceImpl; import org.hyperledger.besu.services.PermissioningServiceImpl; import org.hyperledger.besu.services.PicoCLIOptionsImpl; @@ -1301,6 +1303,9 @@ private void startPlugins(final Runner runner) { miningParametersSupplier.get()), besuController.getProtocolSchedule())); + besuPluginContext.addService( + MiningService.class, new MiningServiceImpl(besuController.getMiningCoordinator())); + besuController.getAdditionalPluginServices().appendPluginServices(besuPluginContext); besuPluginContext.startPlugins(); } diff --git a/besu/src/main/java/org/hyperledger/besu/services/MiningServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/MiningServiceImpl.java new file mode 100644 index 00000000000..1ee4355066f --- /dev/null +++ b/besu/src/main/java/org/hyperledger/besu/services/MiningServiceImpl.java @@ -0,0 +1,49 @@ +/* + * Copyright contributors to 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.services; + +import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; +import org.hyperledger.besu.plugin.services.mining.MiningService; + +/** + * Implementation of the {@link MiningService} interface. This class provides methods to start and + * stop the mining process using a {@link MiningCoordinator}. + */ +public class MiningServiceImpl implements MiningService { + + private final MiningCoordinator miningCoordinator; + + /** + * Constructs a new {@code MiningServiceImpl} with the specified {@link MiningCoordinator}. + * + * @param miningCoordinator the mining coordinator to be used for starting and stopping the mining + * process + */ + public MiningServiceImpl(final MiningCoordinator miningCoordinator) { + this.miningCoordinator = miningCoordinator; + } + + /** Stops the mining process by delegating to the {@link MiningCoordinator}. */ + @Override + public void stop() { + miningCoordinator.stop(); + } + + /** Starts the mining process by delegating to the {@link MiningCoordinator}. */ + @Override + public void start() { + miningCoordinator.start(); + } +} diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 57f0987bcb6..b4cc9ce71e7 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -71,7 +71,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'vI9RTAGD6sRzAaMp1BMJY7x4cB3wh7FA4rYvDGYRceg=' + knownHash = '3DEeEv1YPoZvRCrmkUygP1tuXZ5YKnY0mIRFNhHPUoc=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/mining/MiningService.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/mining/MiningService.java new file mode 100644 index 00000000000..396d011cb06 --- /dev/null +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/mining/MiningService.java @@ -0,0 +1,27 @@ +/* + * Copyright contributors to 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.plugin.services.mining; + +import org.hyperledger.besu.plugin.services.BesuService; + +/** The MiningService interface provides methods to start and stop the mining process. */ +public interface MiningService extends BesuService { + + /** Starts the mining process. */ + void start(); + + /** Stops the mining process. */ + void stop(); +} From a0fa599f95858d10d93c0938805b50dceb7e02a8 Mon Sep 17 00:00:00 2001 From: Jason Frame Date: Mon, 25 Nov 2024 16:28:05 +1000 Subject: [PATCH 52/56] remove unused dependencies from qbft (#7915) Signed-off-by: Jason Frame --- consensus/qbft/build.gradle | 2 -- 1 file changed, 2 deletions(-) diff --git a/consensus/qbft/build.gradle b/consensus/qbft/build.gradle index 9675c4df89e..23e5576ebac 100644 --- a/consensus/qbft/build.gradle +++ b/consensus/qbft/build.gradle @@ -40,8 +40,6 @@ dependencies { implementation project(':ethereum:p2p') implementation project(':ethereum:rlp') implementation project(':evm') - implementation project(':pki') - implementation project(':services:kvstore') implementation 'com.google.guava:guava' implementation 'io.vertx:vertx-core' From 788b29f4828b5b61cf85d7808e61eed399413908 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Mon, 25 Nov 2024 16:58:37 +1000 Subject: [PATCH 53/56] deprecate RPC methods related to privacy (#7903) Signed-off-by: Sally MacFarlane --- .../internal/privacy/methods/DisabledPrivacyRpcMethod.java | 1 + .../privacy/methods/MultiTenancyRpcMethodDecorator.java | 1 + .../jsonrpc/internal/privacy/methods/MultiTenancyUserUtil.java | 1 + .../jsonrpc/internal/privacy/methods/PrivGetFilterChanges.java | 1 + .../api/jsonrpc/internal/privacy/methods/PrivGetFilterLogs.java | 1 + .../jsonrpc/internal/privacy/methods/PrivUninstallFilter.java | 1 + .../api/jsonrpc/internal/privacy/methods/PrivacyIdProvider.java | 1 + .../privacy/methods/eea/AbstractEeaSendRawTransaction.java | 1 + .../privacy/methods/eea/JsonRpcErrorResponseException.java | 1 + .../privacy/methods/eea/PluginEeaSendRawTransaction.java | 1 + .../methods/eea/RestrictedFlexibleEeaSendRawTransaction.java | 1 + .../methods/eea/RestrictedOffchainEeaSendRawTransaction.java | 1 + .../privacy/methods/priv/AbstractPrivateTraceByHash.java | 1 + .../api/jsonrpc/internal/privacy/methods/priv/PrivCall.java | 1 + .../internal/privacy/methods/priv/PrivCreatePrivacyGroup.java | 1 + .../internal/privacy/methods/priv/PrivDebugGetStateRoot.java | 1 + .../internal/privacy/methods/priv/PrivDeletePrivacyGroup.java | 1 + .../privacy/methods/priv/PrivDistributeRawTransaction.java | 1 + .../internal/privacy/methods/priv/PrivFindPrivacyGroup.java | 1 + .../api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java | 1 + .../privacy/methods/priv/PrivGetEeaTransactionCount.java | 1 + .../api/jsonrpc/internal/privacy/methods/priv/PrivGetLogs.java | 1 + .../privacy/methods/priv/PrivGetPrivacyPrecompileAddress.java | 1 + .../privacy/methods/priv/PrivGetPrivateTransaction.java | 1 + .../internal/privacy/methods/priv/PrivGetTransactionCount.java | 1 + .../privacy/methods/priv/PrivGetTransactionReceipt.java | 1 + .../jsonrpc/internal/privacy/methods/priv/PrivNewFilter.java | 1 + .../internal/privacy/methods/priv/PrivTraceTransaction.java | 1 + .../api/jsonrpc/internal/privacy/methods/priv/PrivUtil.java | 1 + .../privacy/methods/privx/PrivxFindFlexiblePrivacyGroup.java | 1 + .../privacy/methods/privx/PrivxFindOnchainPrivacyGroup.java | 2 +- .../privacy/parameters/CreatePrivacyGroupParameter.java | 1 + .../besu/ethereum/api/jsonrpc/methods/PrivJsonRpcMethods.java | 1 + .../api/jsonrpc/methods/PrivacyApiGroupJsonRpcMethods.java | 1 + 34 files changed, 34 insertions(+), 1 deletion(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/DisabledPrivacyRpcMethod.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/DisabledPrivacyRpcMethod.java index d51d32a1d4b..04e7dd4067b 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/DisabledPrivacyRpcMethod.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/DisabledPrivacyRpcMethod.java @@ -20,6 +20,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; +@Deprecated(since = "24.11.0") public class DisabledPrivacyRpcMethod implements JsonRpcMethod { private final String methodName; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/MultiTenancyRpcMethodDecorator.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/MultiTenancyRpcMethodDecorator.java index 823c8b13cfa..3f7a87c7f45 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/MultiTenancyRpcMethodDecorator.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/MultiTenancyRpcMethodDecorator.java @@ -27,6 +27,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public class MultiTenancyRpcMethodDecorator implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(MultiTenancyRpcMethodDecorator.class); private final JsonRpcMethod rpcMethod; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/MultiTenancyUserUtil.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/MultiTenancyUserUtil.java index 871d3fa577c..54daee347dc 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/MultiTenancyUserUtil.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/MultiTenancyUserUtil.java @@ -18,6 +18,7 @@ import io.vertx.ext.auth.User; +@Deprecated(since = "24.11.0") public class MultiTenancyUserUtil { private static final String PRIVACY_USER_ID_CLAIM = "privacyUserId"; private static final String ENCLAVE_PRIVACY_PUBLIC_KEY_CLAIM = "privacyPublicKey"; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterChanges.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterChanges.java index 4ef7e0aa1c3..9175464fe2e 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterChanges.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterChanges.java @@ -31,6 +31,7 @@ import java.util.List; +@Deprecated(since = "24.11.0") public class PrivGetFilterChanges implements JsonRpcMethod { private final PrivacyController privacyController; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterLogs.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterLogs.java index ea6a5894a33..bf497d41aab 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterLogs.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivGetFilterLogs.java @@ -31,6 +31,7 @@ import java.util.List; +@Deprecated(since = "24.11.0") public class PrivGetFilterLogs implements JsonRpcMethod { private final PrivacyController privacyController; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivUninstallFilter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivUninstallFilter.java index eb41a1dad4e..aeaa2613b08 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivUninstallFilter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivUninstallFilter.java @@ -26,6 +26,7 @@ import org.hyperledger.besu.ethereum.privacy.MultiTenancyPrivacyController; import org.hyperledger.besu.ethereum.privacy.PrivacyController; +@Deprecated(since = "24.11.0") public class PrivUninstallFilter implements JsonRpcMethod { private final FilterManager filterManager; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivacyIdProvider.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivacyIdProvider.java index 5f01bae059b..d59a64b0bab 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivacyIdProvider.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivacyIdProvider.java @@ -23,6 +23,7 @@ import io.vertx.ext.auth.User; @FunctionalInterface +@Deprecated(since = "24.11.0") public interface PrivacyIdProvider { String getPrivacyUserId(Optional user); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/AbstractEeaSendRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/AbstractEeaSendRawTransaction.java index e96a08eb7d4..b8e78621ef2 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/AbstractEeaSendRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/AbstractEeaSendRawTransaction.java @@ -48,6 +48,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public abstract class AbstractEeaSendRawTransaction implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(AbstractEeaSendRawTransaction.class); private final TransactionPool transactionPool; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/JsonRpcErrorResponseException.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/JsonRpcErrorResponseException.java index 79d006f48e6..7b22ebcef1d 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/JsonRpcErrorResponseException.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/JsonRpcErrorResponseException.java @@ -16,6 +16,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; +@Deprecated(since = "24.11.0") public class JsonRpcErrorResponseException extends RuntimeException { private final RpcErrorType jsonRpcError; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/PluginEeaSendRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/PluginEeaSendRawTransaction.java index c81c0852e0a..513d0fa351f 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/PluginEeaSendRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/PluginEeaSendRawTransaction.java @@ -33,6 +33,7 @@ import io.vertx.ext.auth.User; import org.apache.tuweni.bytes.Bytes; +@Deprecated(since = "24.11.0") public class PluginEeaSendRawTransaction extends AbstractEeaSendRawTransaction { private final PrivacyController privacyController; private final PrivacyIdProvider privacyIdProvider; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedFlexibleEeaSendRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedFlexibleEeaSendRawTransaction.java index 3fa12563c03..6c300fbc301 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedFlexibleEeaSendRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedFlexibleEeaSendRawTransaction.java @@ -37,6 +37,7 @@ import io.vertx.ext.auth.User; import org.apache.tuweni.bytes.Bytes; +@Deprecated(since = "24.11.0") public class RestrictedFlexibleEeaSendRawTransaction extends AbstractEeaSendRawTransaction { private final PrivacyController privacyController; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedOffchainEeaSendRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedOffchainEeaSendRawTransaction.java index 34b46973913..de467e31bcc 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedOffchainEeaSendRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedOffchainEeaSendRawTransaction.java @@ -35,6 +35,7 @@ import io.vertx.ext.auth.User; import org.apache.tuweni.bytes.Bytes; +@Deprecated(since = "24.11.0") public class RestrictedOffchainEeaSendRawTransaction extends AbstractEeaSendRawTransaction { final PrivacyController privacyController; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/AbstractPrivateTraceByHash.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/AbstractPrivateTraceByHash.java index 01398868624..209d5bf3bf4 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/AbstractPrivateTraceByHash.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/AbstractPrivateTraceByHash.java @@ -41,6 +41,7 @@ import java.util.function.Supplier; import java.util.stream.Stream; +@Deprecated(since = "24.11.0") public abstract class AbstractPrivateTraceByHash implements JsonRpcMethod { protected final Supplier blockTracerSupplier; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java index 5d9edc63b9d..5be9a9f2ab6 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java @@ -33,6 +33,7 @@ import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; import org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason; +@Deprecated(since = "24.11.0") public class PrivCall extends AbstractBlockParameterMethod { private final PrivacyIdProvider privacyIdProvider; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroup.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroup.java index 568125a2762..09ff5b19f96 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroup.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroup.java @@ -32,6 +32,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public class PrivCreatePrivacyGroup implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(PrivCreatePrivacyGroup.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDebugGetStateRoot.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDebugGetStateRoot.java index dc0fc90f661..d8c411c0853 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDebugGetStateRoot.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDebugGetStateRoot.java @@ -39,6 +39,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public class PrivDebugGetStateRoot extends AbstractBlockParameterMethod { private static final Logger LOG = LoggerFactory.getLogger(PrivDebugGetStateRoot.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDeletePrivacyGroup.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDeletePrivacyGroup.java index 61b7791b3c0..73849eb92e5 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDeletePrivacyGroup.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDeletePrivacyGroup.java @@ -32,6 +32,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public class PrivDeletePrivacyGroup implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(PrivDeletePrivacyGroup.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDistributeRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDistributeRawTransaction.java index aac4df3d2c9..7375590d55c 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDistributeRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDistributeRawTransaction.java @@ -48,6 +48,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public class PrivDistributeRawTransaction implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(PrivDistributeRawTransaction.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivFindPrivacyGroup.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivFindPrivacyGroup.java index 7e823232237..e41728b044e 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivFindPrivacyGroup.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivFindPrivacyGroup.java @@ -37,6 +37,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings("MockNotUsedInProduction") +@Deprecated(since = "24.11.0") public class PrivFindPrivacyGroup implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(PrivFindPrivacyGroup.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java index 7042d357f12..da3179834f0 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetCode.java @@ -28,6 +28,7 @@ import org.apache.tuweni.bytes.Bytes; +@Deprecated(since = "24.11.0") public class PrivGetCode extends AbstractBlockParameterMethod { private final PrivacyController privacyController; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetEeaTransactionCount.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetEeaTransactionCount.java index 9f231f41c06..e35ad79da77 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetEeaTransactionCount.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetEeaTransactionCount.java @@ -42,6 +42,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public class PrivGetEeaTransactionCount implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(PrivGetEeaTransactionCount.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetLogs.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetLogs.java index 6947ea5e546..735eb9bf9d9 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetLogs.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetLogs.java @@ -38,6 +38,7 @@ import java.util.List; import java.util.Optional; +@Deprecated(since = "24.11.0") public class PrivGetLogs implements JsonRpcMethod { private final BlockchainQueries blockchainQueries; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetPrivacyPrecompileAddress.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetPrivacyPrecompileAddress.java index 816ed1c5da8..46e52525bea 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetPrivacyPrecompileAddress.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetPrivacyPrecompileAddress.java @@ -22,6 +22,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; import org.hyperledger.besu.ethereum.core.PrivacyParameters; +@Deprecated(since = "24.11.0") public class PrivGetPrivacyPrecompileAddress implements JsonRpcMethod { private final Address privacyAddress; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetPrivateTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetPrivateTransaction.java index 8779181599e..4419b82d50e 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetPrivateTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetPrivateTransaction.java @@ -38,6 +38,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public class PrivGetPrivateTransaction implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(PrivGetPrivateTransaction.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionCount.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionCount.java index d8757dc2fbd..fc547e88640 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionCount.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionCount.java @@ -34,6 +34,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public class PrivGetTransactionCount implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(PrivGetTransactionCount.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionReceipt.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionReceipt.java index 287793ddc01..b7c7f25b4dd 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionReceipt.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionReceipt.java @@ -43,6 +43,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public class PrivGetTransactionReceipt implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(PrivGetTransactionReceipt.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivNewFilter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivNewFilter.java index 49fc11f4b82..bd2ece37b94 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivNewFilter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivNewFilter.java @@ -29,6 +29,7 @@ import org.hyperledger.besu.ethereum.privacy.MultiTenancyPrivacyController; import org.hyperledger.besu.ethereum.privacy.PrivacyController; +@Deprecated(since = "24.11.0") public class PrivNewFilter implements JsonRpcMethod { private final FilterManager filterManager; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivTraceTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivTraceTransaction.java index 07d663bef55..f044b39f774 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivTraceTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivTraceTransaction.java @@ -43,6 +43,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public class PrivTraceTransaction extends AbstractPrivateTraceByHash implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(TraceTransaction.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivUtil.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivUtil.java index 8db4b73bdb4..a3ca662fd12 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivUtil.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivUtil.java @@ -20,6 +20,7 @@ import java.util.Optional; +@Deprecated(since = "24.11.0") public class PrivUtil { public static void checkMembershipForAuthenticatedUser( diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindFlexiblePrivacyGroup.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindFlexiblePrivacyGroup.java index 0a66d1aa73b..925dc4ec65d 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindFlexiblePrivacyGroup.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindFlexiblePrivacyGroup.java @@ -36,6 +36,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated(since = "24.11.0") public class PrivxFindFlexiblePrivacyGroup implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(PrivxFindFlexiblePrivacyGroup.class); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindOnchainPrivacyGroup.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindOnchainPrivacyGroup.java index e09c72464e2..015c7728596 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindOnchainPrivacyGroup.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/privx/PrivxFindOnchainPrivacyGroup.java @@ -19,7 +19,7 @@ import org.hyperledger.besu.ethereum.privacy.PrivacyController; // Use PrivxFindFlexiblePrivacyGroup instead -@Deprecated +@Deprecated(since = "21.10.3") public class PrivxFindOnchainPrivacyGroup extends PrivxFindFlexiblePrivacyGroup { public PrivxFindOnchainPrivacyGroup( diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/parameters/CreatePrivacyGroupParameter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/parameters/CreatePrivacyGroupParameter.java index f826ef179d4..c66f754d203 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/parameters/CreatePrivacyGroupParameter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/parameters/CreatePrivacyGroupParameter.java @@ -20,6 +20,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +@Deprecated(since = "24.11.0") public class CreatePrivacyGroupParameter { private final List addresses; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivJsonRpcMethods.java index 8ae62741b94..48d1dccee90 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivJsonRpcMethods.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivJsonRpcMethods.java @@ -46,6 +46,7 @@ import java.util.Map; +@Deprecated(since = "24.11.0") public class PrivJsonRpcMethods extends PrivacyApiGroupJsonRpcMethods { private final FilterManager filterManager; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivacyApiGroupJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivacyApiGroupJsonRpcMethods.java index 304a36a677b..e648febc379 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivacyApiGroupJsonRpcMethods.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivacyApiGroupJsonRpcMethods.java @@ -42,6 +42,7 @@ import java.util.Optional; import java.util.stream.Collectors; +@Deprecated(since = "24.11.0") public abstract class PrivacyApiGroupJsonRpcMethods extends ApiGroupJsonRpcMethods { private final BlockchainQueries blockchainQueries; From 46204773d319a2c6c17ed8971e3e127553d136f1 Mon Sep 17 00:00:00 2001 From: Karim Taam Date: Mon, 25 Nov 2024 17:51:12 +0700 Subject: [PATCH 54/56] renaming state trie account for verkle integration (#7907) Signed-off-by: Karim Taam --- .../subcommands/operator/RestoreState.java | 6 +- .../results/proof/GetProofResult.java | 5 +- .../api/query/StateBackupService.java | 6 +- .../internal/methods/EthGetProofTest.java | 4 +- .../besu/ethereum/proof/WorldStateProof.java | 8 +- .../proof/WorldStateProofProvider.java | 6 +- .../common/AbstractStateTrieAccountValue.java | 81 +++++++++++++++++++ .../common/PmtStateTrieAccountValue.java} | 63 +++------------ .../bonsai/BonsaiWorldStateProvider.java | 4 +- .../BonsaiWorldStateKeyValueStorage.java | 4 +- .../bonsai/trielog/TrieLogFactoryImpl.java | 8 +- .../worldview/ForestMutableWorldState.java | 14 ++-- .../besu/ethereum/core/TrieGenerator.java | 7 +- .../proof/WorldStateProofProviderTest.java | 7 +- .../BonsaiCachedMerkleTrieLoaderTest.java | 10 +-- .../BonsaiWorldStateKeyValueStorageTest.java | 6 +- .../bonsai/trielog/TrieLogFactoryTests.java | 4 +- .../common/trielog/TrieLogLayerTests.java | 17 ++-- .../worldstate/StateTrieAccountValueTest.java | 7 +- .../messages/snap/AccountRangeMessage.java | 6 +- .../AccountTrieNodeDataRequest.java | 5 +- .../request/AccountRangeDataRequest.java | 6 +- ...ccountFlatDatabaseHealingRangeRequest.java | 6 +- .../heal/AccountTrieNodeHealingRequest.java | 7 +- .../eth/manager/snap/SnapServerTest.java | 8 +- .../snap/AccountRangeMessageTest.java | 14 ++-- .../FastWorldStateDownloaderTest.java | 6 +- .../snapsync/AccountHealingTrackingTest.java | 32 +++++--- .../eth/sync/snapsync/TaskGenerator.java | 6 +- ...geFlatDatabaseHealingRangeRequestTest.java | 6 +- .../StorageTrieNodeHealingRequestTest.java | 6 +- 31 files changed, 218 insertions(+), 157 deletions(-) create mode 100644 ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/common/AbstractStateTrieAccountValue.java rename ethereum/core/src/main/java/org/hyperledger/besu/ethereum/{worldstate/StateTrieAccountValue.java => trie/common/PmtStateTrieAccountValue.java} (64%) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/operator/RestoreState.java b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/operator/RestoreState.java index 64803802405..47a6c2294a5 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/operator/RestoreState.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/operator/RestoreState.java @@ -34,9 +34,9 @@ import org.hyperledger.besu.ethereum.trie.Node; import org.hyperledger.besu.ethereum.trie.PersistVisitor; import org.hyperledger.besu.ethereum.trie.RestoreVisitor; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.forest.ForestWorldStateArchive; import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.util.io.RollingFileReader; import java.io.IOException; @@ -192,8 +192,8 @@ private void restoreAccounts() throws IOException { final Bytes accountRlp = accountInput.readBytes(); final Bytes code = accountInput.readBytes(); - final StateTrieAccountValue trieAccount = - StateTrieAccountValue.readFrom(new BytesValueRLPInput(accountRlp, false, true)); + final PmtStateTrieAccountValue trieAccount = + PmtStateTrieAccountValue.readFrom(new BytesValueRLPInput(accountRlp, false, true)); if (!trieAccount.getCodeHash().equals(Hash.hash(code))) { throw new RuntimeException("Code hash doesn't match"); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/proof/GetProofResult.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/proof/GetProofResult.java index f4adb7b0fed..e2ec8df4bac 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/proof/GetProofResult.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/proof/GetProofResult.java @@ -18,7 +18,7 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity; import org.hyperledger.besu.ethereum.proof.WorldStateProof; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import java.util.ArrayList; import java.util.List; @@ -64,7 +64,8 @@ public GetProofResult( public static GetProofResult buildGetProofResult( final Address address, final WorldStateProof worldStateProof) { - final StateTrieAccountValue stateTrieAccountValue = worldStateProof.getStateTrieAccountValue(); + final PmtStateTrieAccountValue stateTrieAccountValue = + worldStateProof.getStateTrieAccountValue(); final List storageEntries = new ArrayList<>(); worldStateProof diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/StateBackupService.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/StateBackupService.java index 63f51016498..27d96a1be93 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/StateBackupService.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/StateBackupService.java @@ -29,9 +29,9 @@ import org.hyperledger.besu.ethereum.trie.Node; import org.hyperledger.besu.ethereum.trie.TrieIterator; import org.hyperledger.besu.ethereum.trie.TrieIterator.State; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.util.io.RollingFileWriter; import java.io.IOException; @@ -241,8 +241,8 @@ private TrieIterator.State visitAccount(final Bytes32 nodeKey, final Node backupStatus.currentAccount = nodeKey; final Bytes nodeValue = node.getValue().orElse(Hash.EMPTY); - final StateTrieAccountValue account = - StateTrieAccountValue.readFrom(new BytesValueRLPInput(nodeValue, false)); + final PmtStateTrieAccountValue account = + PmtStateTrieAccountValue.readFrom(new BytesValueRLPInput(nodeValue, false)); final Bytes code = worldStateKeyValueStorage.getCode(account.getCodeHash()).orElse(Bytes.EMPTY); backupStatus.codeSize.addAndGet(code.size()); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProofTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProofTest.java index a346cd827b2..69af2b85ac0 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProofTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProofTest.java @@ -42,7 +42,7 @@ import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.proof.WorldStateProof; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import java.util.Collections; @@ -202,7 +202,7 @@ private GetProofResult generateWorldState() { when(blockchainQueries.getWorldStateArchive()).thenReturn(archive); - final StateTrieAccountValue stateTrieAccountValue = mock(StateTrieAccountValue.class); + final PmtStateTrieAccountValue stateTrieAccountValue = mock(PmtStateTrieAccountValue.class); when(stateTrieAccountValue.getBalance()).thenReturn(balance); when(stateTrieAccountValue.getCodeHash()).thenReturn(codeHash); when(stateTrieAccountValue.getNonce()).thenReturn(nonce); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/proof/WorldStateProof.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/proof/WorldStateProof.java index 91c492e69c1..8853dc23716 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/proof/WorldStateProof.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/proof/WorldStateProof.java @@ -16,7 +16,7 @@ import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.trie.Proof; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import java.util.ArrayList; import java.util.List; @@ -29,14 +29,14 @@ public class WorldStateProof { - private final StateTrieAccountValue stateTrieAccountValue; + private final PmtStateTrieAccountValue stateTrieAccountValue; private final Proof accountProof; private final Map> storageProofs; public WorldStateProof( - final StateTrieAccountValue stateTrieAccountValue, + final PmtStateTrieAccountValue stateTrieAccountValue, final Proof accountProof, final SortedMap> storageProofs) { this.stateTrieAccountValue = stateTrieAccountValue; @@ -44,7 +44,7 @@ public WorldStateProof( this.storageProofs = storageProofs; } - public StateTrieAccountValue getStateTrieAccountValue() { + public PmtStateTrieAccountValue getStateTrieAccountValue() { return stateTrieAccountValue; } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/proof/WorldStateProofProvider.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/proof/WorldStateProofProvider.java index 1f49dea273c..a858f1a9029 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/proof/WorldStateProofProvider.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/proof/WorldStateProofProvider.java @@ -22,10 +22,10 @@ import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.MerkleTrieException; import org.hyperledger.besu.ethereum.trie.Proof; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.patricia.RemoveVisitor; import org.hyperledger.besu.ethereum.trie.patricia.SimpleMerklePatriciaTrie; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; import java.util.Comparator; @@ -73,7 +73,7 @@ public Optional getAccountProof( return accountProof .getValue() .map(RLP::input) - .map(StateTrieAccountValue::readFrom) + .map(PmtStateTrieAccountValue::readFrom) .map( account -> { final SortedMap> storageProofs = @@ -85,7 +85,7 @@ public Optional getAccountProof( private SortedMap> getStorageProofs( final Hash accountHash, - final StateTrieAccountValue account, + final PmtStateTrieAccountValue account, final List accountStorageKeys) { final MerkleTrie storageTrie = newAccountStorageTrie(accountHash, account.getStorageRoot()); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/common/AbstractStateTrieAccountValue.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/common/AbstractStateTrieAccountValue.java new file mode 100644 index 00000000000..805aef9b44d --- /dev/null +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/common/AbstractStateTrieAccountValue.java @@ -0,0 +1,81 @@ +/* + * Copyright ConsenSys AG. + * + * 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.ethereum.trie.common; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.hyperledger.besu.datatypes.AccountValue; +import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.rlp.RLPOutput; + +/** Represents the raw values associated with an account in the world state trie. */ +public abstract class AbstractStateTrieAccountValue implements AccountValue { + + protected final long nonce; + protected final Wei balance; + protected final Hash codeHash; + + public AbstractStateTrieAccountValue(final long nonce, final Wei balance, final Hash codeHash) { + checkNotNull(balance, "balance cannot be null"); + checkNotNull(codeHash, "codeHash cannot be null"); + this.nonce = nonce; + this.balance = balance; + this.codeHash = codeHash; + } + + /** + * The account nonce, that is the number of transactions sent from that account. + * + * @return the account nonce. + */ + @Override + public long getNonce() { + return nonce; + } + + /** + * The available balance of that account. + * + * @return the balance, in Wei, of the account. + */ + @Override + public Wei getBalance() { + return balance; + } + + /** + * The hash of the EVM bytecode associated with this account. + * + * @return the hash of the account code (which may be {@link Hash#EMPTY}). + */ + @Override + public Hash getCodeHash() { + return codeHash; + } + + /** + * The hash of the root of the storage trie associated with this account. + * + * @return the hash of the root node of the storage trie. + */ + @Override + public Hash getStorageRoot() { + return Hash.EMPTY_TRIE_HASH; + } + + @Override + public abstract void writeTo(final RLPOutput out); +} diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/StateTrieAccountValue.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/common/PmtStateTrieAccountValue.java similarity index 64% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/StateTrieAccountValue.java rename to ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/common/PmtStateTrieAccountValue.java index 40c420f7518..5a291846eab 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/StateTrieAccountValue.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/common/PmtStateTrieAccountValue.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.worldstate; +package org.hyperledger.besu.ethereum.trie.common; import static com.google.common.base.Preconditions.checkNotNull; @@ -26,43 +26,17 @@ import org.apache.tuweni.bytes.Bytes32; -/** Represents the raw values associated with an account in the world state trie. */ -public class StateTrieAccountValue implements AccountValue { +/** Represents the raw values associated with an account in the world state patricia merkle trie. */ +public class PmtStateTrieAccountValue extends AbstractStateTrieAccountValue + implements AccountValue { - protected final long nonce; - protected final Wei balance; protected final Hash storageRoot; - protected final Hash codeHash; - public StateTrieAccountValue( + public PmtStateTrieAccountValue( final long nonce, final Wei balance, final Hash storageRoot, final Hash codeHash) { - checkNotNull(balance, "balance cannot be null"); + super(nonce, balance, codeHash); checkNotNull(storageRoot, "storageRoot cannot be null"); - checkNotNull(codeHash, "codeHash cannot be null"); - this.nonce = nonce; - this.balance = balance; this.storageRoot = storageRoot; - this.codeHash = codeHash; - } - - /** - * The account nonce, that is the number of transactions sent from that account. - * - * @return the account nonce. - */ - @Override - public long getNonce() { - return nonce; - } - - /** - * The available balance of that account. - * - * @return the balance, in Wei, of the account. - */ - @Override - public Wei getBalance() { - return balance; } /** @@ -75,25 +49,15 @@ public Hash getStorageRoot() { return storageRoot; } - /** - * The hash of the EVM bytecode associated with this account. - * - * @return the hash of the account code (which may be {@link Hash#EMPTY}). - */ - @Override - public Hash getCodeHash() { - return codeHash; - } - @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - final StateTrieAccountValue that = (StateTrieAccountValue) o; + PmtStateTrieAccountValue that = (PmtStateTrieAccountValue) o; return nonce == that.nonce - && balance.equals(that.balance) - && storageRoot.equals(that.storageRoot) - && codeHash.equals(that.codeHash); + && Objects.equals(balance, that.balance) + && Objects.equals(storageRoot, that.storageRoot) + && Objects.equals(codeHash, that.codeHash); } @Override @@ -109,11 +73,10 @@ public void writeTo(final RLPOutput out) { out.writeUInt256Scalar(balance); out.writeBytes(storageRoot); out.writeBytes(codeHash); - out.endList(); } - public static StateTrieAccountValue readFrom(final RLPInput in) { + public static PmtStateTrieAccountValue readFrom(final RLPInput in) { in.enterList(); final long nonce = in.readLongScalar(); @@ -132,9 +95,9 @@ public static StateTrieAccountValue readFrom(final RLPInput in) { } else { codeHash = in.readBytes32(); } - in.leaveList(); - return new StateTrieAccountValue(nonce, balance, Hash.wrap(storageRoot), Hash.wrap(codeHash)); + return new PmtStateTrieAccountValue( + nonce, balance, Hash.wrap(storageRoot), Hash.wrap(codeHash)); } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProvider.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProvider.java index 1e2f62addbb..afbb1e05816 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProvider.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProvider.java @@ -18,6 +18,7 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.rlp.RLP; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.cache.BonsaiCachedMerkleTrieLoader; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.cache.BonsaiCachedWorldStorageManager; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.BonsaiWorldStateKeyValueStorage; @@ -26,7 +27,6 @@ import org.hyperledger.besu.ethereum.trie.diffbased.common.trielog.TrieLogManager; import org.hyperledger.besu.ethereum.trie.diffbased.common.worldview.DiffBasedWorldStateConfig; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.plugin.ServiceManager; @@ -120,7 +120,7 @@ public void prepareStateHealing(final Address address, final Bytes location) { accountTrie .get(accountHash) .map(RLP::input) - .map(StateTrieAccountValue::readFrom) + .map(PmtStateTrieAccountValue::readFrom) .ifPresent( account -> { final StoredMerklePatriciaTrie storageTrie = diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/storage/BonsaiWorldStateKeyValueStorage.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/storage/BonsaiWorldStateKeyValueStorage.java index 07ded9ddf61..e712c66eadc 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/storage/BonsaiWorldStateKeyValueStorage.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/storage/BonsaiWorldStateKeyValueStorage.java @@ -24,13 +24,13 @@ import org.hyperledger.besu.ethereum.storage.StorageProvider; import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier; import org.hyperledger.besu.ethereum.trie.MerkleTrie; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.flat.BonsaiFlatDbStrategy; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.flat.BonsaiFlatDbStrategyProvider; import org.hyperledger.besu.ethereum.trie.diffbased.common.storage.DiffBasedWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.diffbased.common.storage.flat.FlatDbStrategy; import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; import org.hyperledger.besu.ethereum.worldstate.FlatDbMode; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateKeyValueStorage; import org.hyperledger.besu.evm.account.AccountStorageEntry; import org.hyperledger.besu.plugin.services.MetricsSystem; @@ -135,7 +135,7 @@ public Optional getStorageValueByStorageSlotKey( getAccount(accountHash) .map( b -> - StateTrieAccountValue.readFrom( + PmtStateTrieAccountValue.readFrom( org.hyperledger.besu.ethereum.rlp.RLP.input(b)) .getStorageRoot()), accountHash, diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/trielog/TrieLogFactoryImpl.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/trielog/TrieLogFactoryImpl.java index e99b5109649..d528373d24d 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/trielog/TrieLogFactoryImpl.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/trielog/TrieLogFactoryImpl.java @@ -22,9 +22,9 @@ import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; import org.hyperledger.besu.ethereum.rlp.RLPInput; import org.hyperledger.besu.ethereum.rlp.RLPOutput; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.diffbased.common.DiffBasedValue; import org.hyperledger.besu.ethereum.trie.diffbased.common.trielog.TrieLogLayer; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.plugin.data.BlockHeader; import org.hyperledger.besu.plugin.services.trielogs.TrieLog; import org.hyperledger.besu.plugin.services.trielogs.TrieLogAccumulator; @@ -160,8 +160,10 @@ public static TrieLogLayer readFrom(final RLPInput input) { input.skipNext(); } else { input.enterList(); - final StateTrieAccountValue oldValue = nullOrValue(input, StateTrieAccountValue::readFrom); - final StateTrieAccountValue newValue = nullOrValue(input, StateTrieAccountValue::readFrom); + final PmtStateTrieAccountValue oldValue = + nullOrValue(input, PmtStateTrieAccountValue::readFrom); + final PmtStateTrieAccountValue newValue = + nullOrValue(input, PmtStateTrieAccountValue::readFrom); final boolean isCleared = getOptionalIsCleared(input); input.leaveList(); newLayer diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/worldview/ForestMutableWorldState.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/worldview/ForestMutableWorldState.java index d94f3564126..360dabb0c6d 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/worldview/ForestMutableWorldState.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/forest/worldview/ForestMutableWorldState.java @@ -23,9 +23,9 @@ import org.hyperledger.besu.ethereum.rlp.RLPException; import org.hyperledger.besu.ethereum.rlp.RLPInput; import org.hyperledger.besu.ethereum.trie.MerkleTrie; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStatePreimageStorage; import org.hyperledger.besu.evm.account.Account; @@ -137,7 +137,7 @@ public Account get(final Address address) { private WorldStateAccount deserializeAccount( final Address address, final Hash addressHash, final Bytes encoded) throws RLPException { final RLPInput in = RLP.input(encoded); - final StateTrieAccountValue accountValue = StateTrieAccountValue.readFrom(in); + final PmtStateTrieAccountValue accountValue = PmtStateTrieAccountValue.readFrom(in); return new WorldStateAccount(address, addressHash, accountValue); } @@ -224,13 +224,15 @@ protected class WorldStateAccount implements Account { private final Address address; private final Hash addressHash; - final StateTrieAccountValue accountValue; + final PmtStateTrieAccountValue accountValue; // Lazily initialized since we don't always access storage. private volatile MerkleTrie storageTrie; private WorldStateAccount( - final Address address, final Hash addressHash, final StateTrieAccountValue accountValue) { + final Address address, + final Hash addressHash, + final PmtStateTrieAccountValue accountValue) { this.address = address; this.addressHash = addressHash; @@ -454,8 +456,8 @@ public void commit() { private static Bytes serializeAccount( final long nonce, final Wei balance, final Hash storageRoot, final Hash codeHash) { - final StateTrieAccountValue accountValue = - new StateTrieAccountValue(nonce, balance, storageRoot, codeHash); + final PmtStateTrieAccountValue accountValue = + new PmtStateTrieAccountValue(nonce, balance, storageRoot, codeHash); return RLP.encode(accountValue::writeTo); } } diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/TrieGenerator.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/TrieGenerator.java index 9a9108aa042..3e416a2879d 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/TrieGenerator.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/TrieGenerator.java @@ -20,9 +20,9 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.trie.MerkleTrie; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; @@ -74,8 +74,9 @@ public static MerkleTrie generateTrie( }); final Bytes code = Bytes32.leftPad(Bytes.of(i + 10)); final Hash codeHash = Hash.hash(code); - final StateTrieAccountValue accountValue = - new StateTrieAccountValue(1L, Wei.of(2L), Hash.wrap(storageTrie.getRootHash()), codeHash); + final PmtStateTrieAccountValue accountValue = + new PmtStateTrieAccountValue( + 1L, Wei.of(2L), Hash.wrap(storageTrie.getRootHash()), codeHash); accountStateTrie.put(accounts.get(i), RLP.encode(accountValue::writeTo)); applyForStrategy( updater, diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/proof/WorldStateProofProviderTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/proof/WorldStateProofProviderTest.java index 95b39197ea0..f7085e31e96 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/proof/WorldStateProofProviderTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/proof/WorldStateProofProviderTest.java @@ -21,9 +21,9 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.trie.MerkleTrie; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage; @@ -82,8 +82,9 @@ public void getProofWhenWorldStateAvailable() { // Define account value final Hash codeHash = Hash.hash(Bytes.fromHexString("0x1122")); - final StateTrieAccountValue accountValue = - new StateTrieAccountValue(1L, Wei.of(2L), Hash.wrap(storageTrie.getRootHash()), codeHash); + final PmtStateTrieAccountValue accountValue = + new PmtStateTrieAccountValue( + 1L, Wei.of(2L), Hash.wrap(storageTrie.getRootHash()), codeHash); // Save to storage worldStateTrie.put(addressHash, RLP.encode(accountValue::writeTo)); worldStateTrie.commit((location, hash, value) -> updater.putAccountStateTrieNode(hash, value)); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiCachedMerkleTrieLoaderTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiCachedMerkleTrieLoaderTest.java index 06b377ad83a..1552c341f33 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiCachedMerkleTrieLoaderTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiCachedMerkleTrieLoaderTest.java @@ -25,11 +25,11 @@ import org.hyperledger.besu.ethereum.storage.StorageProvider; import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.TrieIterator; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.cache.BonsaiCachedMerkleTrieLoader; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -96,8 +96,8 @@ void shouldAddAccountNodesInCacheDuringPreload() { @Test void shouldAddStorageNodesInCacheDuringPreload() { final Hash hashAccountZero = accounts.get(0).addressHash(); - final StateTrieAccountValue stateTrieAccountValue = - StateTrieAccountValue.readFrom(RLP.input(trie.get(hashAccountZero).orElseThrow())); + final PmtStateTrieAccountValue stateTrieAccountValue = + PmtStateTrieAccountValue.readFrom(RLP.input(trie.get(hashAccountZero).orElseThrow())); final StoredMerklePatriciaTrie storageTrie = new StoredMerklePatriciaTrie<>( (location, hash) -> @@ -154,8 +154,8 @@ void shouldFallbackWhenAccountNodesIsNotInCache() { @Test void shouldFallbackWhenStorageNodesIsNotInCache() { final Hash hashAccountZero = accounts.get(0).addressHash(); - final StateTrieAccountValue stateTrieAccountValue = - StateTrieAccountValue.readFrom(RLP.input(trie.get(hashAccountZero).orElseThrow())); + final PmtStateTrieAccountValue stateTrieAccountValue = + PmtStateTrieAccountValue.readFrom(RLP.input(trie.get(hashAccountZero).orElseThrow())); final StoredMerklePatriciaTrie storageTrie = new StoredMerklePatriciaTrie<>( (location, hash) -> diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/storage/BonsaiWorldStateKeyValueStorageTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/storage/BonsaiWorldStateKeyValueStorageTest.java index 464f35bae71..81e158bef76 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/storage/BonsaiWorldStateKeyValueStorageTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/storage/BonsaiWorldStateKeyValueStorageTest.java @@ -36,12 +36,12 @@ import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier; import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.StorageEntriesCollector; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; import org.hyperledger.besu.ethereum.worldstate.FlatDbMode; import org.hyperledger.besu.ethereum.worldstate.ImmutableDataStorageConfiguration; import org.hyperledger.besu.ethereum.worldstate.ImmutableDiffBasedSubStorageConfiguration; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; @@ -316,8 +316,8 @@ void getStorage_loadFromTrieWhenEmptyWithPartialMode(final FlatDbMode flatDbMode (TreeMap) trie.entriesFrom(root -> StorageEntriesCollector.collectEntries(root, Hash.ZERO, 1)); - final StateTrieAccountValue stateTrieAccountValue = - StateTrieAccountValue.readFrom(RLP.input(accounts.firstEntry().getValue())); + final PmtStateTrieAccountValue stateTrieAccountValue = + PmtStateTrieAccountValue.readFrom(RLP.input(accounts.firstEntry().getValue())); final StoredMerklePatriciaTrie storageTrie = new StoredMerklePatriciaTrie<>( diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/trielog/TrieLogFactoryTests.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/trielog/TrieLogFactoryTests.java index 5173df717fc..ae685f0d009 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/trielog/TrieLogFactoryTests.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/trielog/TrieLogFactoryTests.java @@ -23,8 +23,8 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.diffbased.common.trielog.TrieLogLayer; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; import org.hyperledger.besu.plugin.services.trielogs.TrieLog; import org.hyperledger.besu.plugin.services.trielogs.TrieLogFactory; @@ -54,7 +54,7 @@ public class TrieLogFactoryTests { .addAccountChange( accountFixture, null, - new StateTrieAccountValue(0, Wei.fromEth(1), Hash.EMPTY, Hash.EMPTY)) + new PmtStateTrieAccountValue(0, Wei.fromEth(1), Hash.EMPTY, Hash.EMPTY)) .addCodeChange( Address.ZERO, null, diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/common/trielog/TrieLogLayerTests.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/common/trielog/TrieLogLayerTests.java index 85534de1b06..0aa00160fdb 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/common/trielog/TrieLogLayerTests.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/common/trielog/TrieLogLayerTests.java @@ -19,7 +19,7 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.StorageSlotKey; import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import java.util.Optional; @@ -51,15 +51,16 @@ public void testStorageSlotKeyEquivalence() { @Test public void testAddAccountChange() { Address address = Address.fromHexString("0x00"); - StateTrieAccountValue oldValue = new StateTrieAccountValue(0, Wei.ZERO, Hash.EMPTY, Hash.EMPTY); - StateTrieAccountValue newValue = - new StateTrieAccountValue(1, Wei.fromEth(1), Hash.EMPTY, Hash.EMPTY); + PmtStateTrieAccountValue oldValue = + new PmtStateTrieAccountValue(0, Wei.ZERO, Hash.EMPTY, Hash.EMPTY); + PmtStateTrieAccountValue newValue = + new PmtStateTrieAccountValue(1, Wei.fromEth(1), Hash.EMPTY, Hash.EMPTY); Address otherAddress = Address.fromHexString("0x000000"); - StateTrieAccountValue otherOldValue = - new StateTrieAccountValue(0, Wei.ZERO, Hash.EMPTY, Hash.EMPTY); - StateTrieAccountValue otherNewValue = - new StateTrieAccountValue(1, Wei.fromEth(1), Hash.EMPTY, Hash.EMPTY); + PmtStateTrieAccountValue otherOldValue = + new PmtStateTrieAccountValue(0, Wei.ZERO, Hash.EMPTY, Hash.EMPTY); + PmtStateTrieAccountValue otherNewValue = + new PmtStateTrieAccountValue(1, Wei.fromEth(1), Hash.EMPTY, Hash.EMPTY); trieLogLayer.addAccountChange(address, oldValue, newValue); otherTrieLogLayer.addAccountChange(otherAddress, otherOldValue, otherNewValue); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/StateTrieAccountValueTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/StateTrieAccountValueTest.java index 5ce385570c3..827900ef0c1 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/StateTrieAccountValueTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/worldstate/StateTrieAccountValueTest.java @@ -20,6 +20,7 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.rlp.RLPInput; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.Test; @@ -41,11 +42,11 @@ public void roundTripMainNetAccountValue() { private void roundTripMainNetAccountValue( final long nonce, final Wei balance, final Hash storageRoot, final Hash codeHash) { - StateTrieAccountValue accountValue = - new StateTrieAccountValue(nonce, balance, storageRoot, codeHash); + PmtStateTrieAccountValue accountValue = + new PmtStateTrieAccountValue(nonce, balance, storageRoot, codeHash); Bytes encoded = RLP.encode(accountValue::writeTo); final RLPInput in = RLP.input(encoded); - StateTrieAccountValue roundTripAccountValue = StateTrieAccountValue.readFrom(in); + PmtStateTrieAccountValue roundTripAccountValue = PmtStateTrieAccountValue.readFrom(in); assertThat(nonce).isEqualTo(roundTripAccountValue.getNonce()); assertThat(balance).isEqualTo(roundTripAccountValue.getBalance()); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/snap/AccountRangeMessage.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/snap/AccountRangeMessage.java index 71d04295925..9c6e1f93997 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/snap/AccountRangeMessage.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/snap/AccountRangeMessage.java @@ -20,7 +20,7 @@ import org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; import org.hyperledger.besu.ethereum.rlp.RLPInput; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import java.math.BigInteger; import java.util.List; @@ -121,7 +121,7 @@ public AccountRangeData accountData(final boolean withRequestId) { @VisibleForTesting public static Bytes toFullAccount(final RLPInput rlpInput) { - final StateTrieAccountValue accountValue = StateTrieAccountValue.readFrom(rlpInput); + final PmtStateTrieAccountValue accountValue = PmtStateTrieAccountValue.readFrom(rlpInput); final BytesValueRLPOutput rlpOutput = new BytesValueRLPOutput(); rlpOutput.startList(); @@ -135,7 +135,7 @@ public static Bytes toFullAccount(final RLPInput rlpInput) { } public static Bytes toSlimAccount(final RLPInput rlpInput) { - StateTrieAccountValue accountValue = StateTrieAccountValue.readFrom(rlpInput); + PmtStateTrieAccountValue accountValue = PmtStateTrieAccountValue.readFrom(rlpInput); var rlpOutput = new BytesValueRLPOutput(); rlpOutput.startList(); rlpOutput.writeLongScalar(accountValue.getNonce()); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/AccountTrieNodeDataRequest.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/AccountTrieNodeDataRequest.java index 366cfd50f51..28ac75e52f7 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/AccountTrieNodeDataRequest.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/AccountTrieNodeDataRequest.java @@ -21,7 +21,7 @@ import org.hyperledger.besu.ethereum.rlp.RLPOutput; import org.hyperledger.besu.ethereum.trie.CompactEncoding; import org.hyperledger.besu.ethereum.trie.MerkleTrie; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; @@ -73,7 +73,8 @@ protected Stream getRequestsFromTrieNodeValue( final Bytes path, final Bytes value) { final Stream.Builder builder = Stream.builder(); - final StateTrieAccountValue accountValue = StateTrieAccountValue.readFrom(RLP.input(value)); + final PmtStateTrieAccountValue accountValue = + PmtStateTrieAccountValue.readFrom(RLP.input(value)); final Optional accountHash = Optional.of( diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/AccountRangeDataRequest.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/AccountRangeDataRequest.java index 21a707e9a63..c7e76edc3f3 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/AccountRangeDataRequest.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/AccountRangeDataRequest.java @@ -31,9 +31,9 @@ import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.rlp.RLPInput; import org.hyperledger.besu.ethereum.trie.NodeUpdater; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.FlatDbMode; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; @@ -210,8 +210,8 @@ public Stream getChildRequests( // find missing storages and code for (Map.Entry account : taskElement.keys().entrySet()) { - final StateTrieAccountValue accountValue = - StateTrieAccountValue.readFrom(RLP.input(account.getValue())); + final PmtStateTrieAccountValue accountValue = + PmtStateTrieAccountValue.readFrom(RLP.input(account.getValue())); if (!accountValue.getStorageRoot().equals(Hash.EMPTY_TRIE_HASH)) { childRequests.add( createStorageRangeDataRequest( diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountFlatDatabaseHealingRangeRequest.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountFlatDatabaseHealingRangeRequest.java index 7e66fa7d88a..195cd85a576 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountFlatDatabaseHealingRangeRequest.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountFlatDatabaseHealingRangeRequest.java @@ -31,9 +31,9 @@ import org.hyperledger.besu.ethereum.trie.RangeManager; import org.hyperledger.besu.ethereum.trie.RangeStorageEntriesCollector; import org.hyperledger.besu.ethereum.trie.TrieIterator; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; @@ -104,8 +104,8 @@ public Stream getChildRequests( if (downloadState .getAccountsHealingList() .contains(CompactEncoding.bytesToPath(account.getKey()))) { - final StateTrieAccountValue accountValue = - StateTrieAccountValue.readFrom(RLP.input(account.getValue())); + final PmtStateTrieAccountValue accountValue = + PmtStateTrieAccountValue.readFrom(RLP.input(account.getValue())); childRequests.add( createStorageFlatHealingRangeRequest( getRootHash(), diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountTrieNodeHealingRequest.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountTrieNodeHealingRequest.java index be6060d52ef..70929f7dd93 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountTrieNodeHealingRequest.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountTrieNodeHealingRequest.java @@ -25,8 +25,8 @@ import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.trie.CompactEncoding; import org.hyperledger.besu.ethereum.trie.MerkleTrie; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; @@ -120,7 +120,7 @@ public Stream getRootStorageRequests( getLocation().size(), account.size() - getLocation().size())) .map(RLP::input) - .map(StateTrieAccountValue::readFrom) + .map(PmtStateTrieAccountValue::readFrom) .filter( stateTrieAccountValue -> // We need to ensure that the accounts to be healed do not have empty storage. @@ -152,7 +152,8 @@ protected Stream getRequestsFromTrieNodeValue( final Bytes path, final Bytes value) { final Stream.Builder builder = Stream.builder(); - final StateTrieAccountValue accountValue = StateTrieAccountValue.readFrom(RLP.input(value)); + final PmtStateTrieAccountValue accountValue = + PmtStateTrieAccountValue.readFrom(RLP.input(value)); // Retrieve account hash final Hash accountHash = diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServerTest.java index 28446034296..1d43a5af9b9 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServerTest.java @@ -37,13 +37,13 @@ import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.trie.CompactEncoding; import org.hyperledger.besu.ethereum.trie.MerkleTrie; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.flat.BonsaiFlatDbStrategyProvider; import org.hyperledger.besu.ethereum.trie.patricia.SimpleMerklePatriciaTrie; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; import org.hyperledger.besu.ethereum.worldstate.FlatDbMode; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; import org.hyperledger.besu.metrics.ObservableMetricsSystem; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -71,7 +71,7 @@ public class SnapServerTest { record SnapTestAccount( Hash addressHash, - StateTrieAccountValue accountValue, + PmtStateTrieAccountValue accountValue, MerkleTrie storage, Bytes code) { Bytes accountRLP() { @@ -722,7 +722,7 @@ public void assertCodeLimitRequest_atLeastOneByteCode() { static SnapTestAccount createTestAccount(final String hexAddr) { return new SnapTestAccount( Hash.wrap(Bytes32.rightPad(Bytes.fromHexString(hexAddr))), - new StateTrieAccountValue( + new PmtStateTrieAccountValue( rand.nextInt(0, 1), Wei.of(rand.nextLong(0L, 1L)), Hash.EMPTY_TRIE_HASH, Hash.EMPTY), new SimpleMerklePatriciaTrie<>(a -> a), Bytes.EMPTY); @@ -768,7 +768,7 @@ static SnapTestAccount createTestContractAccount( updater.commit(); return new SnapTestAccount( acctHash, - new StateTrieAccountValue( + new PmtStateTrieAccountValue( rand.nextInt(0, 1), Wei.of(rand.nextLong(0L, 1L)), Hash.wrap(trie.getRootHash()), Hash.hash(mockCode)), trie, diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/snap/AccountRangeMessageTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/snap/AccountRangeMessageTest.java index c7e5bf74c42..4c2bad0f639 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/snap/AccountRangeMessageTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/snap/AccountRangeMessageTest.java @@ -23,7 +23,7 @@ import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.rlp.RLPInput; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import java.util.ArrayList; import java.util.HashMap; @@ -39,8 +39,8 @@ public final class AccountRangeMessageTest { @Test public void roundTripTest() { final Map keys = new HashMap<>(); - final StateTrieAccountValue accountValue = - new StateTrieAccountValue(1L, Wei.of(2L), Hash.EMPTY_TRIE_HASH, Hash.EMPTY); + final PmtStateTrieAccountValue accountValue = + new PmtStateTrieAccountValue(1L, Wei.of(2L), Hash.EMPTY_TRIE_HASH, Hash.EMPTY); keys.put(Hash.wrap(Bytes32.leftPad(Bytes.of(1))), RLP.encode(accountValue::writeTo)); final List proofs = new ArrayList<>(); @@ -65,8 +65,8 @@ public void toSlimAccountTest() { Wei balance = Wei.of(2L); // Create a StateTrieAccountValue with the given nonce and balance - final StateTrieAccountValue accountValue = - new StateTrieAccountValue(nonce, balance, Hash.EMPTY_TRIE_HASH, Hash.EMPTY); + final PmtStateTrieAccountValue accountValue = + new PmtStateTrieAccountValue(nonce, balance, Hash.EMPTY_TRIE_HASH, Hash.EMPTY); // Encode the account value to RLP final BytesValueRLPOutput rlpOut = new BytesValueRLPOutput(); @@ -104,8 +104,8 @@ public void toFullAccountTest() { Wei balance = Wei.of(2L); // Create a StateTrieAccountValue with the given nonce and balance - final StateTrieAccountValue accountValue = - new StateTrieAccountValue(nonce, balance, Hash.EMPTY_TRIE_HASH, Hash.EMPTY); + final PmtStateTrieAccountValue accountValue = + new PmtStateTrieAccountValue(nonce, balance, Hash.EMPTY_TRIE_HASH, Hash.EMPTY); // Encode the account value to RLP final BytesValueRLPOutput rlpOut = new BytesValueRLPOutput(); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastWorldStateDownloaderTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastWorldStateDownloaderTest.java index 75fe892aebd..323f0ae9f10 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastWorldStateDownloaderTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastWorldStateDownloaderTest.java @@ -51,11 +51,11 @@ import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStatePreimageKeyValueStorage; import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.Node; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.forest.ForestWorldStateArchive; import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.ethereum.trie.patricia.TrieNodeDecoder; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.ethereum.worldstate.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStatePreimageStorage; @@ -589,8 +589,8 @@ void doesNotRequestKnownStorageTrieNodesFromNetwork() { Function.identity()) .entriesFrom(Bytes32.ZERO, 5).values().stream() .map(RLP::input) - .map(StateTrieAccountValue::readFrom) - .map(StateTrieAccountValue::getStorageRoot) + .map(PmtStateTrieAccountValue::readFrom) + .map(PmtStateTrieAccountValue::getStorageRoot) .collect(Collectors.toList()); final Map allTrieNodes = new HashMap<>(); final Set knownNodes = new HashSet<>(); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/AccountHealingTrackingTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/AccountHealingTrackingTest.java index 8e4e40311f3..ecb704ba89e 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/AccountHealingTrackingTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/AccountHealingTrackingTest.java @@ -31,11 +31,11 @@ import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.RangeStorageEntriesCollector; import org.hyperledger.besu.ethereum.trie.TrieIterator; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.ethereum.trie.patricia.StoredNodeFactory; import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -82,8 +82,9 @@ public void setup() { @Test void shouldMarkAccountForHealingWhenStorageProofIsReceived() { final Hash accountHash = Hash.hash(accounts.get(0)); - final StateTrieAccountValue stateTrieAccountValue = - StateTrieAccountValue.readFrom(RLP.input(accountStateTrie.get(accountHash).orElseThrow())); + final PmtStateTrieAccountValue stateTrieAccountValue = + PmtStateTrieAccountValue.readFrom( + RLP.input(accountStateTrie.get(accountHash).orElseThrow())); final StoredMerklePatriciaTrie storageTrie = new StoredMerklePatriciaTrie<>( @@ -130,8 +131,9 @@ void shouldMarkAccountForHealingWhenStorageProofIsReceived() { @Test void shouldNotMarkAccountForHealingWhenAllStorageIsReceivedWithoutProof() { final Hash accountHash = Hash.hash(accounts.get(0)); - final StateTrieAccountValue stateTrieAccountValue = - StateTrieAccountValue.readFrom(RLP.input(accountStateTrie.get(accountHash).orElseThrow())); + final PmtStateTrieAccountValue stateTrieAccountValue = + PmtStateTrieAccountValue.readFrom( + RLP.input(accountStateTrie.get(accountHash).orElseThrow())); final StoredMerklePatriciaTrie storageTrie = new StoredMerklePatriciaTrie<>( @@ -171,8 +173,9 @@ void shouldNotMarkAccountForHealingWhenAllStorageIsReceivedWithoutProof() { @Test void shouldMarkAccountForHealingOnInvalidStorageProof() { final Hash accountHash = Hash.hash(accounts.get(0)); - final StateTrieAccountValue stateTrieAccountValue = - StateTrieAccountValue.readFrom(RLP.input(accountStateTrie.get(accountHash).orElseThrow())); + final PmtStateTrieAccountValue stateTrieAccountValue = + PmtStateTrieAccountValue.readFrom( + RLP.input(accountStateTrie.get(accountHash).orElseThrow())); final List proofs = List.of( @@ -197,8 +200,9 @@ void shouldMarkAccountForHealingOnInvalidStorageProof() { @Test void shouldMarkAccountForHealingOnInvalidStorageWithoutProof() { final Hash accountHash = Hash.hash(accounts.get(0)); - final StateTrieAccountValue stateTrieAccountValue = - StateTrieAccountValue.readFrom(RLP.input(accountStateTrie.get(accountHash).orElseThrow())); + final PmtStateTrieAccountValue stateTrieAccountValue = + PmtStateTrieAccountValue.readFrom( + RLP.input(accountStateTrie.get(accountHash).orElseThrow())); final StoredMerklePatriciaTrie storageTrie = new StoredMerklePatriciaTrie<>( @@ -236,8 +240,9 @@ void shouldMarkAccountForHealingOnInvalidStorageWithoutProof() { @Test void shouldMarkAccountForHealingOnPartialStorageRange() { final Hash accountHash = Hash.hash(accounts.get(0)); - final StateTrieAccountValue stateTrieAccountValue = - StateTrieAccountValue.readFrom(RLP.input(accountStateTrie.get(accountHash).orElseThrow())); + final PmtStateTrieAccountValue stateTrieAccountValue = + PmtStateTrieAccountValue.readFrom( + RLP.input(accountStateTrie.get(accountHash).orElseThrow())); final StoredMerklePatriciaTrie storageTrie = new StoredMerklePatriciaTrie<>( @@ -286,8 +291,9 @@ void shouldMarkAccountForHealingOnPartialStorageRange() { @Test void shouldNotMarkAccountForHealingOnValidStorageTrieNodeDetection() { final Hash accountHash = Hash.hash(accounts.get(0)); - final StateTrieAccountValue stateTrieAccountValue = - StateTrieAccountValue.readFrom(RLP.input(accountStateTrie.get(accountHash).orElseThrow())); + final PmtStateTrieAccountValue stateTrieAccountValue = + PmtStateTrieAccountValue.readFrom( + RLP.input(accountStateTrie.get(accountHash).orElseThrow())); final StorageTrieNodeHealingRequest storageTrieNodeHealingRequest = SnapDataRequest.createStorageTrieNodeDataRequest( stateTrieAccountValue.getStorageRoot(), diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/TaskGenerator.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/TaskGenerator.java index 0b3a17cccff..2031e7a2a7b 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/TaskGenerator.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/TaskGenerator.java @@ -27,10 +27,10 @@ import org.hyperledger.besu.ethereum.trie.RangeManager; import org.hyperledger.besu.ethereum.trie.RangeStorageEntriesCollector; import org.hyperledger.besu.ethereum.trie.TrieIterator; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.services.tasks.Task; @@ -81,8 +81,8 @@ public static List> createAccountRequest( accountRangeDataRequest.addResponse(worldStateProofProvider, accounts, new ArrayDeque<>()); } - final StateTrieAccountValue stateTrieAccountValue = - StateTrieAccountValue.readFrom(RLP.input(accounts.firstEntry().getValue())); + final PmtStateTrieAccountValue stateTrieAccountValue = + PmtStateTrieAccountValue.readFrom(RLP.input(accounts.firstEntry().getValue())); final Hash accountHash = Hash.wrap(accounts.firstKey()); final StorageRangeDataRequest storageRangeDataRequest = diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageFlatDatabaseHealingRangeRequestTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageFlatDatabaseHealingRangeRequestTest.java index fb8dd742857..5eb88521ae9 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageFlatDatabaseHealingRangeRequestTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageFlatDatabaseHealingRangeRequestTest.java @@ -31,10 +31,10 @@ import org.hyperledger.besu.ethereum.trie.RangeManager; import org.hyperledger.besu.ethereum.trie.RangeStorageEntriesCollector; import org.hyperledger.besu.ethereum.trie.TrieIterator; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -97,8 +97,8 @@ public void setup() { account0StorageRoot = trie.get(account0Hash) .map(RLP::input) - .map(StateTrieAccountValue::readFrom) - .map(StateTrieAccountValue::getStorageRoot) + .map(PmtStateTrieAccountValue::readFrom) + .map(PmtStateTrieAccountValue::getStorageRoot) .orElseThrow(); } diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageTrieNodeHealingRequestTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageTrieNodeHealingRequestTest.java index 4f8299f9acd..114399a66a1 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageTrieNodeHealingRequestTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/StorageTrieNodeHealingRequestTest.java @@ -23,10 +23,10 @@ import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.storage.StorageProvider; import org.hyperledger.besu.ethereum.trie.MerkleTrie; +import org.hyperledger.besu.ethereum.trie.common.PmtStateTrieAccountValue; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.BonsaiWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; -import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; @@ -92,8 +92,8 @@ public void setup(final DataStorageFormat storageFormat) { account0StorageRoot = trie.get(account0Hash) .map(RLP::input) - .map(StateTrieAccountValue::readFrom) - .map(StateTrieAccountValue::getStorageRoot) + .map(PmtStateTrieAccountValue::readFrom) + .map(PmtStateTrieAccountValue::getStorageRoot) .orElseThrow(); } From 674a7bae583f8f2ac62bdba62b896e9bccba6dbe Mon Sep 17 00:00:00 2001 From: ahamlat Date: Mon, 25 Nov 2024 13:33:26 +0100 Subject: [PATCH 55/56] Upgrade rocksdb jni lib from 8.3.2 to 9.7.3 (#7817) * Upgrade rocksdb jni lib from 8.3.2 to 9.7.3 * Remove deprecated metrics * Add changelog entry Signed-off-by: Ameziane H. --- CHANGELOG.md | 1 + gradle/verification-metadata.xml | 10 +++++----- .../hyperledger/besu/metrics/rocksdb/RocksDBStats.java | 3 --- platform/build.gradle | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea2535d6ba0..5472920ef59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ - Create and publish Besu BOM (Bill of Materials) [#7615](https://github.com/hyperledger/besu/pull/7615) - Update Java dependencies [#7786](https://github.com/hyperledger/besu/pull/7786) - Add a method to get all the transaction in the pool, to the `TransactionPoolService`, to easily access the transaction pool content from plugins [#7813](https://github.com/hyperledger/besu/pull/7813) +- Upgrade RocksDB JNI library from version 8.3.2 to 9.7.3 [#7817](https://github.com/hyperledger/besu/pull/7817) - Add a method to check if a metric category is enabled to the plugin API [#7832](https://github.com/hyperledger/besu/pull/7832) - Add a new metric collector for counters which get their value from suppliers [#7894](https://github.com/hyperledger/besu/pull/7894) - Add account and state overrides to `eth_call` [#7801](https://github.com/hyperledger/besu/pull/7801) and `eth_estimateGas` [#7890](https://github.com/hyperledger/besu/pull/7890) diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 5c143f63a6b..652bbb9e3d6 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -6533,12 +6533,12 @@ - - - + + + - - + + diff --git a/metrics/rocksdb/src/main/java/org/hyperledger/besu/metrics/rocksdb/RocksDBStats.java b/metrics/rocksdb/src/main/java/org/hyperledger/besu/metrics/rocksdb/RocksDBStats.java index c3c5fef2c11..3af876945dd 100644 --- a/metrics/rocksdb/src/main/java/org/hyperledger/besu/metrics/rocksdb/RocksDBStats.java +++ b/metrics/rocksdb/src/main/java/org/hyperledger/besu/metrics/rocksdb/RocksDBStats.java @@ -107,7 +107,6 @@ public class RocksDBStats { TickerType.NUMBER_SUPERVERSION_CLEANUPS, TickerType.NUMBER_BLOCK_COMPRESSED, TickerType.NUMBER_BLOCK_DECOMPRESSED, - TickerType.NUMBER_BLOCK_NOT_COMPRESSED, TickerType.MERGE_OPERATION_TOTAL_TIME, TickerType.FILTER_OPERATION_TOTAL_TIME, TickerType.ROW_CACHE_HIT, @@ -143,8 +142,6 @@ public class RocksDBStats { HistogramType.BYTES_PER_READ, HistogramType.BYTES_PER_WRITE, HistogramType.BYTES_PER_MULTIGET, - HistogramType.BYTES_COMPRESSED, - HistogramType.BYTES_DECOMPRESSED, HistogramType.COMPRESSION_TIMES_NANOS, HistogramType.DECOMPRESSION_TIMES_NANOS, HistogramType.READ_NUM_MERGE_OPERANDS, diff --git a/platform/build.gradle b/platform/build.gradle index dad2d8e1a09..4e3703ddd4c 100644 --- a/platform/build.gradle +++ b/platform/build.gradle @@ -163,7 +163,7 @@ dependencies { api 'org.owasp.encoder:encoder:1.3.1' - api 'org.rocksdb:rocksdbjni:8.3.2' + api 'org.rocksdb:rocksdbjni:9.7.3' api 'org.springframework.security:spring-security-crypto:6.3.3' From e01f0ffade1813908cc796bb337313f4ecd36647 Mon Sep 17 00:00:00 2001 From: Karim Taam Date: Wed, 27 Nov 2024 14:17:39 +0100 Subject: [PATCH 56/56] spotless and fix after review Signed-off-by: Karim Taam --- .../engine/EngineNewPayloadV2Test.java | 5 +- .../mainnet/MainnetTransactionProcessor.java | 3 +- .../bonsai/BonsaiWorldStateProvider.java | 10 ++- .../common/DiffBasedWorldStateProvider.java | 2 +- .../common/trielog/TrieLogManager.java | 3 +- .../verkle/VerkleWorldStateProvider.java | 2 - .../verkle/trielog/TrieLogFactoryImpl.java | 6 +- .../besu/evm/operation/PushOperation.java | 76 +++++++++---------- 8 files changed, 55 insertions(+), 52 deletions(-) diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2Test.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2Test.java index 4a5c5e05120..899e2c98720 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2Test.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2Test.java @@ -162,14 +162,11 @@ public void shouldValidateExcessBlobGasCorrectly() { @Test public void shouldReturnInvalidIfWithdrawalsIsNull_WhenWithdrawalsAllowed() { - final List withdrawals = null; when(protocolSpec.getWithdrawalsValidator()) .thenReturn(new WithdrawalsValidator.AllowedWithdrawals()); var resp = - resp( - mockEnginePayload( - createBlockHeader(Optional.empty()), Collections.emptyList())); + resp(mockEnginePayload(createBlockHeader(Optional.empty()), Collections.emptyList())); assertThat(fromErrorResp(resp).getCode()).isEqualTo(INVALID_PARAMS.getCode()); verify(engineCallListener, times(1)).executionEngineCalled(); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java index fc94fdabe60..2948f6d7225 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java @@ -546,7 +546,8 @@ public TransactionProcessingResult processTransaction( coinbaseCalculator.price(usedGas, transactionGasPrice, blockHeader.getBaseFee()); operationTracer.traceBeforeRewardTransaction(worldUpdater, transaction, coinbaseWeiDelta); - if (!coinbaseWeiDelta.isZero() || !clearEmptyAccountStrategy.clearEmptyAccountAllowed(miningBeneficiary)) { + if (!coinbaseWeiDelta.isZero() + || !clearEmptyAccountStrategy.clearEmptyAccountAllowed(miningBeneficiary)) { final var coinbase = evmWorldUpdater.getOrCreate(miningBeneficiary); coinbase.incrementBalance(coinbaseWeiDelta); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProvider.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProvider.java index e2f2db7700f..c2c892fb3e3 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProvider.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiWorldStateProvider.java @@ -25,11 +25,10 @@ import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.worldview.BonsaiWorldState; import org.hyperledger.besu.ethereum.trie.diffbased.common.DiffBasedWorldStateProvider; import org.hyperledger.besu.ethereum.trie.diffbased.common.trielog.TrieLogManager; -import org.hyperledger.besu.ethereum.trie.diffbased.common.worldview.DiffBasedWorldStateConfig; import org.hyperledger.besu.ethereum.trie.patricia.StoredMerklePatriciaTrie; import org.hyperledger.besu.evm.internal.EvmConfiguration; -import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; import org.hyperledger.besu.plugin.ServiceManager; +import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; import java.util.HashSet; import java.util.Optional; @@ -56,7 +55,12 @@ public BonsaiWorldStateProvider( final ServiceManager pluginContext, final EvmConfiguration evmConfiguration, final Supplier worldStateHealerSupplier) { - super( DataStorageFormat.BONSAI, worldStateKeyValueStorage, blockchain, maxLayersToLoad, pluginContext); + super( + DataStorageFormat.BONSAI, + worldStateKeyValueStorage, + blockchain, + maxLayersToLoad, + pluginContext); this.bonsaiCachedMerkleTrieLoader = bonsaiCachedMerkleTrieLoader; this.worldStateHealerSupplier = worldStateHealerSupplier; provideCachedWorldStorageManager( diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/DiffBasedWorldStateProvider.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/DiffBasedWorldStateProvider.java index 77895902ead..f33a72137c4 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/DiffBasedWorldStateProvider.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/DiffBasedWorldStateProvider.java @@ -31,8 +31,8 @@ import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; import org.hyperledger.besu.evm.worldstate.WorldState; -import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; import org.hyperledger.besu.plugin.ServiceManager; +import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; import org.hyperledger.besu.plugin.services.trielogs.TrieLog; import java.util.ArrayList; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/trielog/TrieLogManager.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/trielog/TrieLogManager.java index 4d9202dc918..c3e84833176 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/trielog/TrieLogManager.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/trielog/TrieLogManager.java @@ -135,7 +135,8 @@ public synchronized void unsubscribe(final long id) { trieLogObservers.unsubscribe(id); } - private TrieLogFactory setupTrieLogFactory(final DataStorageFormat dataStorageFormat,final ServiceManager pluginContext) { + private TrieLogFactory setupTrieLogFactory( + final DataStorageFormat dataStorageFormat, final ServiceManager pluginContext) { // if we have a TrieLogService from pluginContext, use it. var trieLogServicez = Optional.ofNullable(pluginContext) diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/verkle/VerkleWorldStateProvider.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/verkle/VerkleWorldStateProvider.java index f7af740b2fb..9b332b31be8 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/verkle/VerkleWorldStateProvider.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/verkle/VerkleWorldStateProvider.java @@ -14,8 +14,6 @@ */ package org.hyperledger.besu.ethereum.trie.diffbased.verkle; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.trie.diffbased.common.DiffBasedWorldStateProvider; import org.hyperledger.besu.ethereum.trie.diffbased.common.trielog.TrieLogManager; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/verkle/trielog/TrieLogFactoryImpl.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/verkle/trielog/TrieLogFactoryImpl.java index 55b13726e98..6db8f1fc428 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/verkle/trielog/TrieLogFactoryImpl.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/verkle/trielog/TrieLogFactoryImpl.java @@ -162,8 +162,10 @@ public static TrieLogLayer readFrom(final RLPInput input) { input.skipNext(); } else { input.enterList(); - final VerkleStateTrieAccountValue oldValue = nullOrValue(input, VerkleStateTrieAccountValue::readFrom); - final VerkleStateTrieAccountValue newValue = nullOrValue(input, VerkleStateTrieAccountValue::readFrom); + final VerkleStateTrieAccountValue oldValue = + nullOrValue(input, VerkleStateTrieAccountValue::readFrom); + final VerkleStateTrieAccountValue newValue = + nullOrValue(input, VerkleStateTrieAccountValue::readFrom); final boolean isCleared = getOptionalIsCleared(input); input.leaveList(); newLayer diff --git a/evm/src/main/java/org/hyperledger/besu/evm/operation/PushOperation.java b/evm/src/main/java/org/hyperledger/besu/evm/operation/PushOperation.java index c1250ab4643..171b742f7c8 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/operation/PushOperation.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/operation/PushOperation.java @@ -23,48 +23,48 @@ /** The Push operation. */ public class PushOperation extends AbstractOperation { - /** The constant PUSH_BASE. */ - public static final int PUSH_BASE = 0x5F; + /** The constant PUSH_BASE. */ + public static final int PUSH_BASE = 0x5F; - private final int length; + private final int length; - /** - * Instantiates a new Push operation. - * - * @param length the length - * @param gasCalculator the gas calculator - */ - public PushOperation(final int length, final GasCalculator gasCalculator) { - super(PUSH_BASE + length, "PUSH" + length, 0, 1, gasCalculator); - this.length = length; - } + /** + * Instantiates a new Push operation. + * + * @param length the length + * @param gasCalculator the gas calculator + */ + public PushOperation(final int length, final GasCalculator gasCalculator) { + super(PUSH_BASE + length, "PUSH" + length, 0, 1, gasCalculator); + this.length = length; + } - @Override - public OperationResult execute(final MessageFrame frame, final EVM evm) { + @Override + public OperationResult execute(final MessageFrame frame, final EVM evm) { - final byte[] code = frame.getCode().getBytes().toArrayUnsafe(); - int pc = frame.getPC(); - final int copyStart = pc + 1; + final byte[] code = frame.getCode().getBytes().toArrayUnsafe(); + int pc = frame.getPC(); + final int copyStart = pc + 1; - long gasCost = gasCalculator().pushOperationGasCost(frame, copyStart, length, code.length); + long gasCost = gasCalculator().pushOperationGasCost(frame, copyStart, length, code.length); - Bytes push; - if (code.length <= copyStart) { - push = Bytes.EMPTY; - } else { - final int copyLength = Math.min(length, code.length - pc - 1); - final int rightPad = length - copyLength; - if (rightPad == 0) { - push = Bytes.wrap(code, copyStart, copyLength); - } else { - // Right Pad the push with 0s up to pushSize if greater than the copyLength - var bytecodeLocal = new byte[length]; - System.arraycopy(code, copyStart, bytecodeLocal, 0, copyLength); - push = Bytes.wrap(bytecodeLocal); - } - } - frame.pushStackItem(push); - frame.setPC(pc + length); - return new OperationResult(gasCost, null); + Bytes push; + if (code.length <= copyStart) { + push = Bytes.EMPTY; + } else { + final int copyLength = Math.min(length, code.length - copyStart); + final int rightPad = length - copyLength; + if (rightPad == 0) { + push = Bytes.wrap(code, copyStart, copyLength); + } else { + // Right Pad the push with 0s up to pushSize if greater than the copyLength + var bytecodeLocal = new byte[length]; + System.arraycopy(code, copyStart, bytecodeLocal, 0, copyLength); + push = Bytes.wrap(bytecodeLocal); + } } -} \ No newline at end of file + frame.pushStackItem(push); + frame.setPC(pc + length); + return new OperationResult(gasCost, null); + } +}