From 214cc1bf3a9b45e6850291c88b6d72fa87c55523 Mon Sep 17 00:00:00 2001 From: Marlene Marz Date: Sat, 2 Nov 2024 11:55:12 +0100 Subject: [PATCH 01/39] remove --host-whitelist option Signed-off-by: Marlene Marz remove --host-whitelist option --- benchmark/docker-compose.yml | 82 ++++++++++--------- .../org/hyperledger/besu/cli/BesuCommand.java | 8 -- .../cli/subcommands/RetestethSubCommand.java | 2 +- .../besu/cli/HostAllowlistOptionsTest.java | 35 -------- 4 files changed, 44 insertions(+), 83 deletions(-) diff --git a/benchmark/docker-compose.yml b/benchmark/docker-compose.yml index a62afa7b151..c16ba4cb263 100644 --- a/benchmark/docker-compose.yml +++ b/benchmark/docker-compose.yml @@ -1,7 +1,6 @@ -version: '2' +version: "2" -x-besu: - &besu +x-besu: &besu container_name: besu image: "hyperledger/besu:develop" cpuset: 4-5 @@ -14,8 +13,7 @@ x-besu: volumes: - ./config:/config:ro -x-caliper: - &caliper +x-caliper: &caliper container_name: caliper # TODO: this image is build using the custom branch # https://github.com/taccatisid/caliper/tree/besu-performance-benchmark-container. Once @@ -30,7 +28,7 @@ x-caliper: services: caliper-offchain: - << : *caliper + <<: *caliper environment: - CALIPER_PROJECTCONFIG=/config/caliper-offchain.yaml - CALIPER_BIND_SUT=besu:latest @@ -43,7 +41,7 @@ services: condition: service_healthy caliper-onchain: - << : *caliper + <<: *caliper environment: - CALIPER_PROJECTCONFIG=/config/caliper-onchain.yaml - CALIPER_BIND_SUT=besu:latest @@ -56,46 +54,52 @@ services: condition: service_healthy besu-offchain: - << : *besu + <<: *besu entrypoint: - - /opt/besu/bin/besu - - --genesis-file=/config/genesis.json - - --node-private-key-file=/config/besu-keystore/key - - --min-gas-price=0 - - --revert-reason-enabled - - --rpc-ws-enabled - - --rpc-ws-apis=admin,eth,miner,web3,net,priv,eea - - --rpc-ws-host=0.0.0.0 - - --host-whitelist=* - - --graphql-http-enabled - - --discovery-enabled=false - - --privacy-enabled=true - - --privacy-url=http://tessera:9101 - - --privacy-public-key-file=/config/orion/key/orion.pub + - /opt/besu/bin/besu + - --genesis-file=/config/genesis.json + - --node-private-key-file=/config/besu-keystore/key + - --min-gas-price=0 + - --revert-reason-enabled + - --rpc-ws-enabled + - --rpc-ws-apis=admin,eth,miner,web3,net,priv,eea + - --rpc-ws-host=0.0.0.0 + - --graphql-http-enabled + - --discovery-enabled=false + - --privacy-enabled=true + - --privacy-url=http://tessera:9101 + - --privacy-public-key-file=/config/orion/key/orion.pub besu-onchain: - << : *besu + <<: *besu entrypoint: - - /opt/besu/bin/besu - - --genesis-file=/config/genesis.json - - --node-private-key-file=/config/besu-keystore/key - - --min-gas-price=0 - - --revert-reason-enabled - - --rpc-ws-enabled - - --rpc-ws-apis=admin,eth,miner,web3,net,priv,eea - - --rpc-ws-host=0.0.0.0 - - --host-whitelist=* - - --graphql-http-enabled - - --discovery-enabled=false - - --privacy-enabled=true - - --privacy-url=http://tessera:9101 - - --privacy-public-key-file=/config/orion/key/orion.pub - - --privacy-flexible-groups-enabled + - /opt/besu/bin/besu + - --genesis-file=/config/genesis.json + - --node-private-key-file=/config/besu-keystore/key + - --min-gas-price=0 + - --revert-reason-enabled + - --rpc-ws-enabled + - --rpc-ws-apis=admin,eth,miner,web3,net,priv,eea + - --rpc-ws-host=0.0.0.0 + - --graphql-http-enabled + - --discovery-enabled=false + - --privacy-enabled=true + - --privacy-url=http://tessera:9101 + - --privacy-public-key-file=/config/orion/key/orion.pub + - --privacy-flexible-groups-enabled tessera: container_name: tessera image: quorumengineering/tessera:latest healthcheck: - test: ["CMD", "wget", "--spider", "--proxy", "off", "http://localhost:9000/upcheck"] + test: + [ + "CMD", + "wget", + "--spider", + "--proxy", + "off", + "http://localhost:9000/upcheck", + ] interval: 1s timeout: 1s retries: 10 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..0ecfc8776ca 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -596,14 +596,6 @@ static class PrivacyOptionGroup { defaultValue = "localhost,127.0.0.1") private final JsonRPCAllowlistHostsProperty hostsAllowlist = new JsonRPCAllowlistHostsProperty(); - @Option( - names = {"--host-whitelist"}, - hidden = true, - paramLabel = "[,...]... or * or all", - description = - "Deprecated in favor of --host-allowlist. Comma separated list of hostnames to allow for RPC access, or * to accept any host (default: ${DEFAULT-VALUE})") - private final JsonRPCAllowlistHostsProperty hostsWhitelist = new JsonRPCAllowlistHostsProperty(); - @SuppressWarnings({"FieldCanBeFinal", "FieldMayBeFinal"}) @Option( names = {"--color-enabled"}, 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 index 67af49c400e..9b5cb7a3a71 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/RetestethSubCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/RetestethSubCommand.java @@ -80,7 +80,7 @@ public class RetestethSubCommand implements Runnable { private final Integer rpcHttpPort = RETESTETH_PORT; @Option( - names = {"--host-allowlist", "--host-whitelist"}, + names = {"--host-allowlist"}, paramLabel = "[,...]... or * or all", description = "Comma separated list of hostnames to allow for RPC access, or * to accept any host (default: ${DEFAULT-VALUE})", diff --git a/besu/src/test/java/org/hyperledger/besu/cli/HostAllowlistOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/HostAllowlistOptionsTest.java index c1f867f4892..21dd587ce7f 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/HostAllowlistOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/HostAllowlistOptionsTest.java @@ -23,24 +23,6 @@ public class HostAllowlistOptionsTest extends CommandTestAbstract { - /** test deprecated CLI option * */ - @Deprecated - @Test - public void rpcHttpHostWhitelistAcceptsSingleArgument() { - parseCommand("--host-whitelist", "a"); - - verify(mockRunnerBuilder).jsonRpcConfiguration(jsonRpcConfigArgumentCaptor.capture()); - verify(mockRunnerBuilder).build(); - - assertThat(jsonRpcConfigArgumentCaptor.getValue().getHostsAllowlist().size()).isEqualTo(1); - assertThat(jsonRpcConfigArgumentCaptor.getValue().getHostsAllowlist()).contains("a"); - assertThat(jsonRpcConfigArgumentCaptor.getValue().getHostsAllowlist()) - .doesNotContain("localhost"); - - assertThat(commandOutput.toString(UTF_8)).isEmpty(); - assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); - } - @Test public void rpcHttpHostAllowlistAcceptsSingleArgument() { parseCommand("--host-allowlist", "a"); @@ -89,23 +71,6 @@ public void rpcHttpHostAllowlistAcceptsDoubleComma() { assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); } - @Deprecated - @Test - public void rpcHttpHostWhitelistAllowlistAcceptsMultipleFlags() { - parseCommand("--host-whitelist=a", "--host-allowlist=b"); - - verify(mockRunnerBuilder).jsonRpcConfiguration(jsonRpcConfigArgumentCaptor.capture()); - verify(mockRunnerBuilder).build(); - - assertThat(jsonRpcConfigArgumentCaptor.getValue().getHostsAllowlist().size()).isEqualTo(2); - assertThat(jsonRpcConfigArgumentCaptor.getValue().getHostsAllowlist()).contains("a", "b"); - assertThat(jsonRpcConfigArgumentCaptor.getValue().getHostsAllowlist()) - .doesNotContain("*", "localhost"); - - assertThat(commandOutput.toString(UTF_8)).isEmpty(); - assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); - } - @Test public void rpcHttpHostAllowlistAcceptsMultipleFlags() { parseCommand("--host-allowlist=a", "--host-allowlist=b"); From 694f161f71d7b54aea1b655a4a78950b88954cd1 Mon Sep 17 00:00:00 2001 From: Marlene Marz Date: Sat, 9 Nov 2024 14:16:45 +0100 Subject: [PATCH 02/39] restore docker.compose.yml Signed-off-by: Marlene Marz --- benchmark/docker-compose.yml | 82 +++++++++++++++++------------------- 1 file changed, 39 insertions(+), 43 deletions(-) diff --git a/benchmark/docker-compose.yml b/benchmark/docker-compose.yml index c16ba4cb263..a62afa7b151 100644 --- a/benchmark/docker-compose.yml +++ b/benchmark/docker-compose.yml @@ -1,6 +1,7 @@ -version: "2" +version: '2' -x-besu: &besu +x-besu: + &besu container_name: besu image: "hyperledger/besu:develop" cpuset: 4-5 @@ -13,7 +14,8 @@ x-besu: &besu volumes: - ./config:/config:ro -x-caliper: &caliper +x-caliper: + &caliper container_name: caliper # TODO: this image is build using the custom branch # https://github.com/taccatisid/caliper/tree/besu-performance-benchmark-container. Once @@ -28,7 +30,7 @@ x-caliper: &caliper services: caliper-offchain: - <<: *caliper + << : *caliper environment: - CALIPER_PROJECTCONFIG=/config/caliper-offchain.yaml - CALIPER_BIND_SUT=besu:latest @@ -41,7 +43,7 @@ services: condition: service_healthy caliper-onchain: - <<: *caliper + << : *caliper environment: - CALIPER_PROJECTCONFIG=/config/caliper-onchain.yaml - CALIPER_BIND_SUT=besu:latest @@ -54,52 +56,46 @@ services: condition: service_healthy besu-offchain: - <<: *besu + << : *besu entrypoint: - - /opt/besu/bin/besu - - --genesis-file=/config/genesis.json - - --node-private-key-file=/config/besu-keystore/key - - --min-gas-price=0 - - --revert-reason-enabled - - --rpc-ws-enabled - - --rpc-ws-apis=admin,eth,miner,web3,net,priv,eea - - --rpc-ws-host=0.0.0.0 - - --graphql-http-enabled - - --discovery-enabled=false - - --privacy-enabled=true - - --privacy-url=http://tessera:9101 - - --privacy-public-key-file=/config/orion/key/orion.pub + - /opt/besu/bin/besu + - --genesis-file=/config/genesis.json + - --node-private-key-file=/config/besu-keystore/key + - --min-gas-price=0 + - --revert-reason-enabled + - --rpc-ws-enabled + - --rpc-ws-apis=admin,eth,miner,web3,net,priv,eea + - --rpc-ws-host=0.0.0.0 + - --host-whitelist=* + - --graphql-http-enabled + - --discovery-enabled=false + - --privacy-enabled=true + - --privacy-url=http://tessera:9101 + - --privacy-public-key-file=/config/orion/key/orion.pub besu-onchain: - <<: *besu + << : *besu entrypoint: - - /opt/besu/bin/besu - - --genesis-file=/config/genesis.json - - --node-private-key-file=/config/besu-keystore/key - - --min-gas-price=0 - - --revert-reason-enabled - - --rpc-ws-enabled - - --rpc-ws-apis=admin,eth,miner,web3,net,priv,eea - - --rpc-ws-host=0.0.0.0 - - --graphql-http-enabled - - --discovery-enabled=false - - --privacy-enabled=true - - --privacy-url=http://tessera:9101 - - --privacy-public-key-file=/config/orion/key/orion.pub - - --privacy-flexible-groups-enabled + - /opt/besu/bin/besu + - --genesis-file=/config/genesis.json + - --node-private-key-file=/config/besu-keystore/key + - --min-gas-price=0 + - --revert-reason-enabled + - --rpc-ws-enabled + - --rpc-ws-apis=admin,eth,miner,web3,net,priv,eea + - --rpc-ws-host=0.0.0.0 + - --host-whitelist=* + - --graphql-http-enabled + - --discovery-enabled=false + - --privacy-enabled=true + - --privacy-url=http://tessera:9101 + - --privacy-public-key-file=/config/orion/key/orion.pub + - --privacy-flexible-groups-enabled tessera: container_name: tessera image: quorumengineering/tessera:latest healthcheck: - test: - [ - "CMD", - "wget", - "--spider", - "--proxy", - "off", - "http://localhost:9000/upcheck", - ] + test: ["CMD", "wget", "--spider", "--proxy", "off", "http://localhost:9000/upcheck"] interval: 1s timeout: 1s retries: 10 From dd11a900f76a740a1833bdde362cc286f0945f43 Mon Sep 17 00:00:00 2001 From: Marlene Marz Date: Sat, 9 Nov 2024 14:20:23 +0100 Subject: [PATCH 03/39] remove --host-whitelist from docker-compose Signed-off-by: Marlene Marz --- benchmark/docker-compose.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/benchmark/docker-compose.yml b/benchmark/docker-compose.yml index a62afa7b151..c4054e1a21c 100644 --- a/benchmark/docker-compose.yml +++ b/benchmark/docker-compose.yml @@ -66,7 +66,6 @@ services: - --rpc-ws-enabled - --rpc-ws-apis=admin,eth,miner,web3,net,priv,eea - --rpc-ws-host=0.0.0.0 - - --host-whitelist=* - --graphql-http-enabled - --discovery-enabled=false - --privacy-enabled=true @@ -84,7 +83,6 @@ services: - --rpc-ws-enabled - --rpc-ws-apis=admin,eth,miner,web3,net,priv,eea - --rpc-ws-host=0.0.0.0 - - --host-whitelist=* - --graphql-http-enabled - --discovery-enabled=false - --privacy-enabled=true From 94e162ca988e5e64048d8dd9c910d94f8ffbdf65 Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Mon, 28 Oct 2024 00:40:33 +0100 Subject: [PATCH 04/39] Add getPendingTransactions to TransactionPoolService (#7813) Signed-off-by: Fabio Di Fabio Signed-off-by: Marlene Marz --- CHANGELOG.md | 1 + .../besu/services/TransactionPoolServiceImpl.java | 8 ++++++++ plugin-api/build.gradle | 2 +- .../transactionpool/TransactionPoolService.java | 10 ++++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f862ed866fe..8bfb4ebd3ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Fine tune already seen txs tracker when a tx is removed from the pool [#7755](https://github.com/hyperledger/besu/pull/7755) - 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) ### Bug fixes diff --git a/besu/src/main/java/org/hyperledger/besu/services/TransactionPoolServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/TransactionPoolServiceImpl.java index 16d033ac9e4..b720b60b7c1 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/TransactionPoolServiceImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/TransactionPoolServiceImpl.java @@ -14,9 +14,12 @@ */ package org.hyperledger.besu.services; +import org.hyperledger.besu.datatypes.PendingTransaction; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; import org.hyperledger.besu.plugin.services.transactionpool.TransactionPoolService; +import java.util.Collection; + /** Service to enable and disable the transaction pool. */ public class TransactionPoolServiceImpl implements TransactionPoolService { @@ -40,4 +43,9 @@ public void disableTransactionPool() { public void enableTransactionPool() { transactionPool.setEnabled(); } + + @Override + public Collection getPendingTransactions() { + return transactionPool.getPendingTransactions(); + } } diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index d400e5abe22..0dbca077ab4 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 = '1VIGlJuGiaEVUksIjTTHDt7SIjjJE9+DU8rYk/ze3XM=' + knownHash = 'G3cpM0HGYp4G1u6dN2CRZiEEsgce6jy9rkIlT1blUb4=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/transactionpool/TransactionPoolService.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/transactionpool/TransactionPoolService.java index 01b1f5768b3..ba30fa80fff 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/transactionpool/TransactionPoolService.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/transactionpool/TransactionPoolService.java @@ -14,8 +14,11 @@ */ package org.hyperledger.besu.plugin.services.transactionpool; +import org.hyperledger.besu.datatypes.PendingTransaction; import org.hyperledger.besu.plugin.services.BesuService; +import java.util.Collection; + /** Service to enable and disable the transaction pool. */ public interface TransactionPoolService extends BesuService { /** Enables the transaction pool. */ @@ -23,4 +26,11 @@ public interface TransactionPoolService extends BesuService { /** Disables the transaction pool. */ void enableTransactionPool(); + + /** + * Returns the collection of pending transactions. + * + * @return a collection of pending transactions + */ + Collection getPendingTransactions(); } From cb7c1d4b5cb768967df659e9d4333f0cd3f5b565 Mon Sep 17 00:00:00 2001 From: Preeti <35308865+pr9t@users.noreply.github.com> Date: Mon, 28 Oct 2024 05:32:53 +0530 Subject: [PATCH 05/39] chore:Removed Dupicate AcceptanceTestBase (#7815) * chore:Removed Dupicate AcceptanceTestBase Signed-off-by: Preeti <35308865+pr9t@users.noreply.github.com> * formatting Signed-off-by: Sally MacFarlane --------- Signed-off-by: Preeti <35308865+pr9t@users.noreply.github.com> Signed-off-by: Sally MacFarlane Co-authored-by: Sally MacFarlane Signed-off-by: Marlene Marz --- .../acceptance/dsl/AcceptanceTestBase.java | 20 +- .../dsl/AcceptanceTestBaseJunit5.java | 200 ------------------ .../bft/ParameterizedBftTestBase.java | 4 +- .../bft/qbft/QbftContractAcceptanceTest.java | 4 +- .../CliqueDiscardRpcAcceptanceTest.java | 4 +- .../CliqueGetSignersRpcAcceptanceTest.java | 4 +- .../clique/CliqueMiningAcceptanceTest.java | 4 +- .../CliqueProposalRpcAcceptanceTest.java | 4 +- .../CliqueProposeRpcAcceptanceTest.java | 4 +- .../CliqueZeroValidatorsAcceptanceTest.java | 4 +- .../plugins/BadCLIOptionsPluginTest.java | 4 +- .../plugins/BesuEventsPluginTest.java | 4 +- .../plugins/PermissioningPluginTest.java | 4 +- 13 files changed, 38 insertions(+), 226 deletions(-) delete mode 100644 acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/AcceptanceTestBaseJunit5.java diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/AcceptanceTestBase.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/AcceptanceTestBase.java index 5256e71ee30..72233adbb8b 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/AcceptanceTestBase.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/AcceptanceTestBase.java @@ -49,13 +49,15 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; -import java.lang.ProcessBuilder.Redirect; import java.math.BigInteger; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import org.junit.After; +import org.apache.logging.log4j.ThreadContext; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.junit.jupiter.api.extension.ExtendWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -125,7 +127,15 @@ protected AcceptanceTestBase() { exitedSuccessfully = new ExitedWithCode(0); } - @After + @BeforeEach + public void setUp(final TestInfo testInfo) { + // log4j is configured to create a file per test + // build/acceptanceTestLogs/${ctx:class}.${ctx:test}.log + ThreadContext.put("class", this.getClass().getSimpleName()); + ThreadContext.put("test", testInfo.getTestMethod().get().getName()); + } + + @AfterEach public void tearDownAcceptanceTestBase() { reportMemory(); cluster.close(); @@ -143,7 +153,9 @@ public void reportMemory() { if (command != null) { LOG.info("Memory usage at end of test:"); final ProcessBuilder processBuilder = - new ProcessBuilder(command).redirectErrorStream(true).redirectInput(Redirect.INHERIT); + new ProcessBuilder(command) + .redirectErrorStream(true) + .redirectInput(ProcessBuilder.Redirect.INHERIT); try { final Process memInfoProcess = processBuilder.start(); outputProcessorExecutor.execute(() -> printOutput(memInfoProcess)); diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/AcceptanceTestBaseJunit5.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/AcceptanceTestBaseJunit5.java deleted file mode 100644 index 4f3046c1abf..00000000000 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/AcceptanceTestBaseJunit5.java +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright contributors to Hyperledger Besu. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.tests.acceptance.dsl; - -import static java.nio.charset.StandardCharsets.UTF_8; -import static org.assertj.core.api.Assertions.assertThat; - -import org.hyperledger.besu.tests.acceptance.dsl.account.Accounts; -import org.hyperledger.besu.tests.acceptance.dsl.blockchain.Blockchain; -import org.hyperledger.besu.tests.acceptance.dsl.condition.admin.AdminConditions; -import org.hyperledger.besu.tests.acceptance.dsl.condition.bft.BftConditions; -import org.hyperledger.besu.tests.acceptance.dsl.condition.clique.CliqueConditions; -import org.hyperledger.besu.tests.acceptance.dsl.condition.eth.EthConditions; -import org.hyperledger.besu.tests.acceptance.dsl.condition.login.LoginConditions; -import org.hyperledger.besu.tests.acceptance.dsl.condition.net.NetConditions; -import org.hyperledger.besu.tests.acceptance.dsl.condition.perm.PermissioningConditions; -import org.hyperledger.besu.tests.acceptance.dsl.condition.process.ExitedWithCode; -import org.hyperledger.besu.tests.acceptance.dsl.condition.txpool.TxPoolConditions; -import org.hyperledger.besu.tests.acceptance.dsl.condition.web3.Web3Conditions; -import org.hyperledger.besu.tests.acceptance.dsl.contract.ContractVerifier; -import org.hyperledger.besu.tests.acceptance.dsl.node.Node; -import org.hyperledger.besu.tests.acceptance.dsl.node.cluster.Cluster; -import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.BesuNodeFactory; -import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.permissioning.PermissionedNodeBuilder; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.account.AccountTransactions; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.admin.AdminTransactions; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.bft.BftTransactions; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.clique.CliqueTransactions; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.contract.ContractTransactions; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.eth.EthTransactions; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.miner.MinerTransactions; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.net.NetTransactions; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.perm.PermissioningTransactions; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.txpool.TxPoolTransactions; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.web3.Web3Transactions; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.math.BigInteger; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import org.apache.logging.log4j.ThreadContext; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInfo; -import org.junit.jupiter.api.extension.ExtendWith; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Superclass for acceptance tests. For now (transition to junit5 is ongoing) this class supports - * junit5 format. Once the transition is complete, this class can be removed and recombined with - * AcceptanceTestBase (original). - */ -@ExtendWith(AcceptanceTestBaseTestWatcher.class) -public class AcceptanceTestBaseJunit5 { - - private static final Logger LOG = LoggerFactory.getLogger(AcceptanceTestBaseJunit5.class); - - protected final Accounts accounts; - protected final AccountTransactions accountTransactions; - protected final AdminConditions admin; - protected final AdminTransactions adminTransactions; - protected final Blockchain blockchain; - protected final CliqueConditions clique; - protected final CliqueTransactions cliqueTransactions; - protected final Cluster cluster; - protected final ContractVerifier contractVerifier; - protected final ContractTransactions contractTransactions; - protected final EthConditions eth; - protected final EthTransactions ethTransactions; - protected final BftTransactions bftTransactions; - protected final BftConditions bft; - protected final LoginConditions login; - protected final NetConditions net; - protected final BesuNodeFactory besu; - protected final PermissioningConditions perm; - protected final PermissionedNodeBuilder permissionedNodeBuilder; - protected final PermissioningTransactions permissioningTransactions; - protected final MinerTransactions minerTransactions; - protected final Web3Conditions web3; - protected final TxPoolConditions txPoolConditions; - protected final TxPoolTransactions txPoolTransactions; - protected final ExitedWithCode exitedSuccessfully; - - private final ExecutorService outputProcessorExecutor = Executors.newCachedThreadPool(); - - protected AcceptanceTestBaseJunit5() { - ethTransactions = new EthTransactions(); - accounts = new Accounts(ethTransactions); - adminTransactions = new AdminTransactions(); - cliqueTransactions = new CliqueTransactions(); - bftTransactions = new BftTransactions(); - accountTransactions = new AccountTransactions(accounts); - permissioningTransactions = new PermissioningTransactions(); - contractTransactions = new ContractTransactions(); - minerTransactions = new MinerTransactions(); - blockchain = new Blockchain(ethTransactions); - clique = new CliqueConditions(ethTransactions, cliqueTransactions); - eth = new EthConditions(ethTransactions); - bft = new BftConditions(bftTransactions); - login = new LoginConditions(); - net = new NetConditions(new NetTransactions()); - cluster = new Cluster(net); - perm = new PermissioningConditions(permissioningTransactions); - admin = new AdminConditions(adminTransactions); - web3 = new Web3Conditions(new Web3Transactions()); - besu = new BesuNodeFactory(); - txPoolTransactions = new TxPoolTransactions(); - txPoolConditions = new TxPoolConditions(txPoolTransactions); - contractVerifier = new ContractVerifier(accounts.getPrimaryBenefactor()); - permissionedNodeBuilder = new PermissionedNodeBuilder(); - exitedSuccessfully = new ExitedWithCode(0); - } - - @BeforeEach - public void setUp(final TestInfo testInfo) { - // log4j is configured to create a file per test - // build/acceptanceTestLogs/${ctx:class}.${ctx:test}.log - ThreadContext.put("class", this.getClass().getSimpleName()); - ThreadContext.put("test", testInfo.getTestMethod().get().getName()); - } - - @AfterEach - public void tearDownAcceptanceTestBase() { - reportMemory(); - cluster.close(); - } - - public void reportMemory() { - String os = System.getProperty("os.name"); - String[] command = null; - if (os.contains("Linux")) { - command = new String[] {"/usr/bin/top", "-n", "1", "-o", "%MEM", "-b", "-c", "-w", "180"}; - } - if (os.contains("Mac")) { - command = new String[] {"/usr/bin/top", "-l", "1", "-o", "mem", "-n", "20"}; - } - if (command != null) { - LOG.info("Memory usage at end of test:"); - final ProcessBuilder processBuilder = - new ProcessBuilder(command) - .redirectErrorStream(true) - .redirectInput(ProcessBuilder.Redirect.INHERIT); - try { - final Process memInfoProcess = processBuilder.start(); - outputProcessorExecutor.execute(() -> printOutput(memInfoProcess)); - memInfoProcess.waitFor(); - LOG.debug("Memory info process exited with code {}", memInfoProcess.exitValue()); - } catch (final Exception e) { - LOG.warn("Error running memory information process", e); - } - } else { - LOG.info("Don't know how to report memory for OS {}", os); - } - } - - private void printOutput(final Process process) { - try (final BufferedReader in = - new BufferedReader(new InputStreamReader(process.getInputStream(), UTF_8))) { - String line = in.readLine(); - while (line != null) { - LOG.info(line); - line = in.readLine(); - } - } catch (final IOException e) { - LOG.warn("Failed to read output from memory information process: ", e); - } - } - - protected void waitForBlockHeight(final Node node, final long blockchainHeight) { - WaitUtils.waitFor( - 120, - () -> - assertThat(node.execute(ethTransactions.blockNumber())) - .isGreaterThanOrEqualTo(BigInteger.valueOf(blockchainHeight))); - } - - @Test - void dryRunDetector() { - assertThat(true) - .withFailMessage("This test is here so gradle --dry-run executes this class") - .isTrue(); - } -} diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/ParameterizedBftTestBase.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/ParameterizedBftTestBase.java index b3d1e321aea..76a1a4a6bcc 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/ParameterizedBftTestBase.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/ParameterizedBftTestBase.java @@ -14,7 +14,7 @@ */ package org.hyperledger.besu.tests.acceptance.bft; -import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBaseJunit5; +import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase; import java.util.stream.Stream; @@ -22,7 +22,7 @@ import org.junit.jupiter.params.provider.Arguments; @Disabled("This is not a test class, it offers BFT parameterization only.") -public abstract class ParameterizedBftTestBase extends AcceptanceTestBaseJunit5 { +public abstract class ParameterizedBftTestBase extends AcceptanceTestBase { protected String bftType; protected BftAcceptanceTestParameterization nodeFactory; diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/qbft/QbftContractAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/qbft/QbftContractAcceptanceTest.java index b62eb96e195..038f2be16c1 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/qbft/QbftContractAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/qbft/QbftContractAcceptanceTest.java @@ -14,13 +14,13 @@ */ package org.hyperledger.besu.tests.acceptance.bft.qbft; -import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBaseJunit5; +import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase; import org.hyperledger.besu.tests.acceptance.dsl.account.Account; import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; import org.junit.jupiter.api.Test; -public class QbftContractAcceptanceTest extends AcceptanceTestBaseJunit5 { +public class QbftContractAcceptanceTest extends AcceptanceTestBase { @Test public void shouldMineOnMultipleNodesEvenWhenClusterContainsNonValidator() throws Exception { diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/clique/CliqueDiscardRpcAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/clique/CliqueDiscardRpcAcceptanceTest.java index 6ea274b6991..3ac42cb056c 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/clique/CliqueDiscardRpcAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/clique/CliqueDiscardRpcAcceptanceTest.java @@ -14,14 +14,14 @@ */ package org.hyperledger.besu.tests.acceptance.clique; -import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBaseJunit5; +import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase; import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; import java.io.IOException; import org.junit.jupiter.api.Test; -public class CliqueDiscardRpcAcceptanceTest extends AcceptanceTestBaseJunit5 { +public class CliqueDiscardRpcAcceptanceTest extends AcceptanceTestBase { @Test public void shouldDiscardVotes() throws IOException { diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/clique/CliqueGetSignersRpcAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/clique/CliqueGetSignersRpcAcceptanceTest.java index ba848b0052c..25a1d335105 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/clique/CliqueGetSignersRpcAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/clique/CliqueGetSignersRpcAcceptanceTest.java @@ -16,7 +16,7 @@ import static org.hyperledger.besu.tests.acceptance.dsl.transaction.clique.CliqueTransactions.LATEST; -import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBaseJunit5; +import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase; import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; import org.junit.jupiter.api.BeforeEach; @@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test; @Disabled("flaky test due to hardcoded block numbers") -public class CliqueGetSignersRpcAcceptanceTest extends AcceptanceTestBaseJunit5 { +public class CliqueGetSignersRpcAcceptanceTest extends AcceptanceTestBase { private BesuNode minerNode1; private BesuNode minerNode2; diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/clique/CliqueMiningAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/clique/CliqueMiningAcceptanceTest.java index f6718b4ded1..f2bae445806 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/clique/CliqueMiningAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/clique/CliqueMiningAcceptanceTest.java @@ -18,7 +18,7 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.data.Percentage.withPercentage; -import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBaseJunit5; +import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase; import org.hyperledger.besu.tests.acceptance.dsl.account.Account; import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.genesis.GenesisConfigurationFactory.CliqueOptions; @@ -32,7 +32,7 @@ import org.junit.jupiter.api.Test; import org.web3j.protocol.core.DefaultBlockParameter; -public class CliqueMiningAcceptanceTest extends AcceptanceTestBaseJunit5 { +public class CliqueMiningAcceptanceTest extends AcceptanceTestBase { @Test public void shouldMineTransactionsOnSingleNode() throws IOException { diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/clique/CliqueProposalRpcAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/clique/CliqueProposalRpcAcceptanceTest.java index a7e8ebb9c9c..6cbfbbda0f0 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/clique/CliqueProposalRpcAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/clique/CliqueProposalRpcAcceptanceTest.java @@ -14,14 +14,14 @@ */ package org.hyperledger.besu.tests.acceptance.clique; -import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBaseJunit5; +import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase; import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; import java.io.IOException; import org.junit.jupiter.api.Test; -public class CliqueProposalRpcAcceptanceTest extends AcceptanceTestBaseJunit5 { +public class CliqueProposalRpcAcceptanceTest extends AcceptanceTestBase { @Test public void shouldReturnProposals() throws IOException { diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/clique/CliqueProposeRpcAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/clique/CliqueProposeRpcAcceptanceTest.java index d4fb71c36b4..1674c551a4b 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/clique/CliqueProposeRpcAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/clique/CliqueProposeRpcAcceptanceTest.java @@ -14,7 +14,7 @@ */ package org.hyperledger.besu.tests.acceptance.clique; -import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBaseJunit5; +import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase; import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; import org.hyperledger.besu.tests.acceptance.dsl.condition.clique.ExpectNonceVote.CLIQUE_NONCE_VOTE; import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; @@ -23,7 +23,7 @@ import org.junit.jupiter.api.Test; -public class CliqueProposeRpcAcceptanceTest extends AcceptanceTestBaseJunit5 { +public class CliqueProposeRpcAcceptanceTest extends AcceptanceTestBase { @Test public void shouldAddValidators() throws IOException { diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/clique/CliqueZeroValidatorsAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/clique/CliqueZeroValidatorsAcceptanceTest.java index b0c6afd93fc..e124e669d92 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/clique/CliqueZeroValidatorsAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/clique/CliqueZeroValidatorsAcceptanceTest.java @@ -14,14 +14,14 @@ */ package org.hyperledger.besu.tests.acceptance.clique; -import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBaseJunit5; +import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase; import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; import java.io.IOException; import org.junit.jupiter.api.Test; -public class CliqueZeroValidatorsAcceptanceTest extends AcceptanceTestBaseJunit5 { +public class CliqueZeroValidatorsAcceptanceTest extends AcceptanceTestBase { @Test public void zeroValidatorsFormValidCluster() throws IOException { diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/BadCLIOptionsPluginTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/BadCLIOptionsPluginTest.java index fb35aaacf54..91c70439da9 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/BadCLIOptionsPluginTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/BadCLIOptionsPluginTest.java @@ -16,7 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBaseJunit5; +import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase; import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; import java.io.File; @@ -34,7 +34,7 @@ import org.junit.jupiter.api.condition.DisabledOnOs; import org.junit.jupiter.api.condition.OS; -public class BadCLIOptionsPluginTest extends AcceptanceTestBaseJunit5 { +public class BadCLIOptionsPluginTest extends AcceptanceTestBase { private BesuNode node; @BeforeEach diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/BesuEventsPluginTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/BesuEventsPluginTest.java index a35309ef6f0..4906193362c 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/BesuEventsPluginTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/BesuEventsPluginTest.java @@ -14,7 +14,7 @@ */ package org.hyperledger.besu.tests.acceptance.plugins; -import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBaseJunit5; +import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase; import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; import java.io.File; @@ -28,7 +28,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -public class BesuEventsPluginTest extends AcceptanceTestBaseJunit5 { +public class BesuEventsPluginTest extends AcceptanceTestBase { private BesuNode pluginNode; private BesuNode minerNode; diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java index 86756a42082..c469802fc1e 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java @@ -15,7 +15,7 @@ package org.hyperledger.besu.tests.acceptance.plugins; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBaseJunit5; +import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase; 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; @@ -27,7 +27,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -public class PermissioningPluginTest extends AcceptanceTestBaseJunit5 { +public class PermissioningPluginTest extends AcceptanceTestBase { private BesuNode minerNode; private BesuNode aliceNode; From 4db0007c116589b3ebd13c0e2f23a16936a4220c Mon Sep 17 00:00:00 2001 From: 7at <44062322+itfat@users.noreply.github.com> Date: Mon, 28 Oct 2024 10:19:28 +0500 Subject: [PATCH 06/39] Fix evmtool JSON Error Field to Return Hex String Instead of Long Null String on REVERT (#7774) Signed-off-by: 7at Co-authored-by: Sally MacFarlane Signed-off-by: Marlene Marz --- .../besu/evmtool/EvmToolCommand.java | 4 +-- .../besu/evmtool/trace/revert.json | 2 +- .../besu/evm/tracing/StandardJsonTracer.java | 35 +------------------ .../besu/evm/toy/EvmToyCommand.java | 5 +-- 4 files changed, 4 insertions(+), 42 deletions(-) diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommand.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommand.java index f9d7c0db476..2574d4b8e39 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommand.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommand.java @@ -529,9 +529,7 @@ public void run() { messageFrame .getExceptionalHaltReason() .ifPresent(haltReason -> out.println(haltReason)); - messageFrame - .getRevertReason() - .ifPresent(bytes -> out.println(new String(bytes.toArrayUnsafe(), UTF_8))); + messageFrame.getRevertReason().ifPresent(bytes -> out.println(bytes.toHexString())); } } } diff --git a/ethereum/evmtool/src/test/resources/org/hyperledger/besu/evmtool/trace/revert.json b/ethereum/evmtool/src/test/resources/org/hyperledger/besu/evmtool/trace/revert.json index 4798d5da706..32ee526fdd9 100644 --- a/ethereum/evmtool/src/test/resources/org/hyperledger/besu/evmtool/trace/revert.json +++ b/ethereum/evmtool/src/test/resources/org/hyperledger/besu/evmtool/trace/revert.json @@ -12,7 +12,7 @@ {"pc":7,"op":82,"gas":"0x2540be3fa","gasCost":"0x6","memSize":0,"stack":["0x4e6f7065","0x0"],"depth":1,"refund":0,"opName":"MSTORE"}, {"pc":8,"op":96,"gas":"0x2540be3f4","gasCost":"0x3","memSize":32,"stack":[],"depth":1,"refund":0,"opName":"PUSH1"}, {"pc":10,"op":96,"gas":"0x2540be3f1","gasCost":"0x3","memSize":32,"stack":["0x4"],"depth":1,"refund":0,"opName":"PUSH1"}, - {"pc":12,"op":253,"gas":"0x2540be3ee","gasCost":"0x0","memSize":32,"stack":["0x4","0x1c"],"depth":1,"refund":0,"opName":"REVERT","error":"Nope"}, + {"pc":12,"op":253,"gas":"0x2540be3ee","gasCost":"0x0","memSize":32,"stack":["0x4","0x1c"],"depth":1,"refund":0,"opName":"REVERT","error":"0x4e6f7065"}, {"stateRoot":"0x405bbd98da2aca6dff77f79e0b270270c48d6a3e07b76db675b20e454b50bbcb","output":"0x4e6f7065","gasUsed":"0x12","pass":true,"fork":"Cancun"} ] } \ No newline at end of file diff --git a/evm/src/main/java/org/hyperledger/besu/evm/tracing/StandardJsonTracer.java b/evm/src/main/java/org/hyperledger/besu/evm/tracing/StandardJsonTracer.java index baf052ba4eb..8071fa942f1 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/tracing/StandardJsonTracer.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/tracing/StandardJsonTracer.java @@ -14,8 +14,6 @@ */ package org.hyperledger.besu.evm.tracing; -import static com.google.common.base.Strings.padStart; - import org.hyperledger.besu.evm.code.OpcodeInfo; import org.hyperledger.besu.evm.frame.ExceptionalHaltReason; import org.hyperledger.besu.evm.frame.MessageFrame; @@ -224,7 +222,7 @@ public void tracePostExecution( .append("\""); } else if (messageFrame.getRevertReason().isPresent()) { sb.append(",\"error\":\"") - .append(quoteEscape(messageFrame.getRevertReason().orElse(Bytes.EMPTY))) + .append(messageFrame.getRevertReason().get().toHexString()) .append("\""); } @@ -232,37 +230,6 @@ public void tracePostExecution( out.println(sb); } - private static String quoteEscape(final Bytes bytes) { - final StringBuilder result = new StringBuilder(bytes.size()); - for (final byte b : bytes.toArrayUnsafe()) { - final int c = Byte.toUnsignedInt(b); - // list from RFC-4627 section 2 - if (c == '"') { - result.append("\\\""); - } else if (c == '\\') { - result.append("\\\\"); - } else if (c == '/') { - result.append("\\/"); - } else if (c == '\b') { - result.append("\\b"); - } else if (c == '\f') { - result.append("\\f"); - } else if (c == '\n') { - result.append("\\n"); - } else if (c == '\r') { - result.append("\\r"); - } else if (c == '\t') { - result.append("\\t"); - } else if (c <= 0x1F) { - result.append("\\u"); - result.append(padStart(Integer.toHexString(c), 4, '0')); - } else { - result.append((char) b); - } - } - return result.toString(); - } - @Override public void tracePrecompileCall( final MessageFrame frame, final long gasRequirement, final Bytes output) { diff --git a/evm/src/test/java/org/hyperledger/besu/evm/toy/EvmToyCommand.java b/evm/src/test/java/org/hyperledger/besu/evm/toy/EvmToyCommand.java index fcf26c3c569..9a5c3cd1eaf 100644 --- a/evm/src/test/java/org/hyperledger/besu/evm/toy/EvmToyCommand.java +++ b/evm/src/test/java/org/hyperledger/besu/evm/toy/EvmToyCommand.java @@ -32,7 +32,6 @@ import java.io.PrintStream; import java.math.BigInteger; -import java.nio.charset.StandardCharsets; import java.util.Deque; import java.util.List; @@ -208,9 +207,7 @@ public void run() { out.println(messageFrame.getExceptionalHaltReason().get()); } if (messageFrame.getRevertReason().isPresent()) { - out.println( - new String( - messageFrame.getRevertReason().get().toArrayUnsafe(), StandardCharsets.UTF_8)); + out.println(messageFrame.getRevertReason().get().toHexString()); } } if (messageFrameStack.isEmpty()) { From e39cf9796409e4e9243abd27cfde1a60ad4a3f38 Mon Sep 17 00:00:00 2001 From: Simon Dudley Date: Tue, 29 Oct 2024 10:30:33 +1000 Subject: [PATCH 07/39] EIP-7742: Add target_blob_count to block header (#7808) Signed-off-by: Simon Dudley Signed-off-by: Marlene Marz --- .../besu/tests/acceptance/dsl/BlockUtils.java | 1 + .../ExecutionEnginePragueAcceptanceTest.java | 3 +++ .../AbstractBftBesuControllerBuilderTest.java | 1 + .../CliqueBesuControllerBuilderTest.java | 1 + .../besu/services/BesuEventsImplTest.java | 2 +- .../besu/config/GenesisConfigFile.java | 11 ++++++++++ .../api/jsonrpc/JsonRpcResponseKey.java | 3 ++- .../api/jsonrpc/JsonRpcResponseUtils.java | 6 ++++++ .../engine/AbstractEngineNewPayload.java | 1 + .../jsonrpc/internal/results/BlockResult.java | 7 +++++++ .../internal/methods/EthGasPriceTest.java | 1 + .../methods/EthMaxPriorityFeePerGasTest.java | 1 + ...neExchangeTransitionConfigurationTest.java | 1 + .../query/BlockchainQueriesLogCacheTest.java | 1 + .../cache/TransactionLogBloomCacherTest.java | 2 ++ .../besu/ethereum/chain/GenesisState.java | 7 +++++++ .../besu/ethereum/core/BlockHeader.java | 14 ++++++++++++- .../ethereum/core/BlockHeaderBuilder.java | 20 ++++++++++++++++--- .../ethereum/core/ProcessableBlockHeader.java | 17 +++++++++++++++- .../ethereum/core/SealableBlockHeader.java | 7 +++++-- .../ethereum/core/BlockHeaderTestFixture.java | 8 ++++++++ .../besu/ethereum/chain/GenesisStateTest.java | 12 +++++++---- .../diffbased/bonsai/LogRollingTests.java | 2 ++ .../besu/ethereum/chain/genesis_prague.json | 3 ++- .../eth/messages/MessageWrapperTest.java | 1 + .../backwardsync/ChainForTestCreator.java | 3 +++ .../BlockchainReferenceTestCaseSpec.java | 1 + .../referencetests/ReferenceTestEnv.java | 1 + plugin-api/build.gradle | 2 +- .../plugin/data/ProcessableBlockHeader.java | 12 +++++++++++ 30 files changed, 137 insertions(+), 15 deletions(-) diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/BlockUtils.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/BlockUtils.java index 3a4ca71002b..29f60dd74a6 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/BlockUtils.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/BlockUtils.java @@ -58,6 +58,7 @@ public static BlockHeader createBlockHeader( null, null, null, + null, blockHeaderFunctions); } } diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEnginePragueAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEnginePragueAcceptanceTest.java index 966c02bebde..f38a192d4df 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEnginePragueAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEnginePragueAcceptanceTest.java @@ -20,8 +20,11 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.params.provider.Arguments; +// TODO SLD +@Disabled("TODO SLD - Enable when Prague spec is finalized") public class ExecutionEnginePragueAcceptanceTest extends AbstractJsonRpcTest { private static final String GENESIS_FILE = "/jsonrpc/engine/prague/genesis.json"; private static final String TEST_CASE_PATH = "/jsonrpc/engine/prague/test-cases/"; 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 621ae8a98c7..1d9843dc5df 100644 --- a/besu/src/test/java/org/hyperledger/besu/controller/AbstractBftBesuControllerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/controller/AbstractBftBesuControllerBuilderTest.java @@ -193,6 +193,7 @@ public void miningParametersBlockPeriodSecondsIsUpdatedOnTransition() { null, null, null, + null, getBlockHeaderFunctions()); final Block block1 = new Block(header1, BlockBody.empty()); 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 e9e93de9b9d..d73907ced7a 100644 --- a/besu/src/test/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilderTest.java @@ -222,6 +222,7 @@ public void miningParametersBlockPeriodSecondsIsUpdatedOnTransition() { null, null, null, + null, new CliqueBlockHeaderFunctions()); final Block block1 = new Block(header1, BlockBody.empty()); 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 478ce4ebc42..ddf68ba14ba 100644 --- a/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java +++ b/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java @@ -219,7 +219,7 @@ private void setSyncTarget() { mock(EthPeer.class), new org.hyperledger.besu.ethereum.core.BlockHeader( null, null, null, null, null, null, null, null, 1, 1, 1, 1, null, null, null, 1, null, - null, null, null, null, null)); + null, null, null, null, null, null)); } private void clearSyncTarget() { diff --git a/config/src/main/java/org/hyperledger/besu/config/GenesisConfigFile.java b/config/src/main/java/org/hyperledger/besu/config/GenesisConfigFile.java index 8938e5143c2..eae9bc3d109 100644 --- a/config/src/main/java/org/hyperledger/besu/config/GenesisConfigFile.java +++ b/config/src/main/java/org/hyperledger/besu/config/GenesisConfigFile.java @@ -265,6 +265,17 @@ public String getParentBeaconBlockRoot() { "0x0000000000000000000000000000000000000000000000000000000000000000"); } + /** + * Gets target blob count. + * + * @return the target blob count + */ + public Optional getTargetBlobCount() { + // TODO SLD EIP-7742 not sure if we should use a default value here or enforce any + // "pragueAtGenesis" genesis file (used in devnets) to have this value + return JsonUtil.getValueAsString(genesisRoot, "targetblobcount"); + } + /** * Gets coinbase. * diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcResponseKey.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcResponseKey.java index bf5d12804b9..045b4ad02d3 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcResponseKey.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcResponseKey.java @@ -38,5 +38,6 @@ public enum JsonRpcResponseKey { TRANSACTION_ROOT, BASEFEE, WITHDRAWALS_ROOT, - REQUESTS_HASH + REQUESTS_HASH, + TARGET_BLOB_COUNT } diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcResponseUtils.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcResponseUtils.java index d72db974b0a..7e5e08aa7bb 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcResponseUtils.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcResponseUtils.java @@ -63,6 +63,7 @@ import com.fasterxml.jackson.databind.JsonNode; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.units.bigints.UInt256; +import org.apache.tuweni.units.bigints.UInt64; public class JsonRpcResponseUtils { @@ -106,6 +107,10 @@ public JsonRpcResponse response( values.containsKey(WITHDRAWALS_ROOT) ? hash(values.get(WITHDRAWALS_ROOT)) : null; final Hash requestsHash = values.containsKey(REQUESTS_HASH) ? hash(values.get(REQUESTS_HASH)) : null; + final UInt64 targetBlobCount = + values.containsKey(JsonRpcResponseKey.TARGET_BLOB_COUNT) + ? UInt64.fromHexString(values.get(JsonRpcResponseKey.TARGET_BLOB_COUNT)) + : null; final List ommers = new ArrayList<>(); final BlockHeader header = @@ -131,6 +136,7 @@ public JsonRpcResponse response( null, // ToDo 4844: set with the value of excess_blob_gas field null, // TODO 4788: set with the value of the parent beacon block root field requestsHash, + targetBlobCount, blockHeaderFunctions); return new JsonRpcSuccessResponse( diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayload.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayload.java index 308940f16aa..8562e140f56 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayload.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayload.java @@ -279,6 +279,7 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext) : BlobGas.fromHexString(blockParam.getExcessBlobGas()), maybeParentBeaconBlockRoot.orElse(null), maybeRequests.map(BodyValidation::requestsHash).orElse(null), + null, // TODO SLD EIP-7742 wiring in future PR headerFunctions); // ensure the block hash matches the blockParam hash diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlockResult.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlockResult.java index ed0b64d742a..25e6763edac 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlockResult.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlockResult.java @@ -88,6 +88,7 @@ public class BlockResult implements JsonRpcResult { private final String blobGasUsed; private final String excessBlobGas; private final String parentBeaconBlockRoot; + private final String targetBlobCount; public BlockResult( final BlockHeader header, @@ -138,6 +139,7 @@ public BlockResult( this.excessBlobGas = header.getExcessBlobGas().map(Quantity::create).orElse(null); this.parentBeaconBlockRoot = header.getParentBeaconBlockRoot().map(Bytes32::toHexString).orElse(null); + this.targetBlobCount = header.getTargetBlobCount().map(Quantity::create).orElse(null); } @JsonGetter(value = "number") @@ -275,4 +277,9 @@ public String getExcessBlobGas() { public String getParentBeaconBlockRoot() { return parentBeaconBlockRoot; } + + @JsonGetter(value = "targetBlobCount") + public String getTargetBlobCount() { + return targetBlobCount; + } } 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 e4282864447..8c7cba99c41 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 @@ -372,6 +372,7 @@ private Block createFakeBlock( null, null, null, + null, null), new BlockBody( IntStream.range(0, txsNum) 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 886c8a1d038..d29a10a114f 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 @@ -207,6 +207,7 @@ private Block createFakeBlock( null, null, null, + null, null), new BlockBody( IntStream.range(0, txsNum) diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeTransitionConfigurationTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeTransitionConfigurationTest.java index f1575f81ab4..4c9dbef7d2d 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeTransitionConfigurationTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeTransitionConfigurationTest.java @@ -254,6 +254,7 @@ private BlockHeader createBlockHeader(final Hash blockHash, final long blockNumb null, null, null, + null, new BlockHeaderFunctions() { @Override public Hash hash(final BlockHeader header) { 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 c0420163de8..4b963173290 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 @@ -120,6 +120,7 @@ public void setup() { null, null, null, + null, new MainnetBlockHeaderFunctions()); testHash = fakeHeader.getHash(); final BlockBody fakeBody = new BlockBody(Collections.emptyList(), Collections.emptyList()); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/cache/TransactionLogBloomCacherTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/cache/TransactionLogBloomCacherTest.java index 5772a04a49d..293c0b176ea 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/cache/TransactionLogBloomCacherTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/cache/TransactionLogBloomCacherTest.java @@ -108,6 +108,7 @@ public void setup() throws IOException { null, null, null, + null, new MainnetBlockHeaderFunctions()); testHash = fakeHeader.getHash(); when(blockchain.getBlockHeader(anyLong())).thenReturn(Optional.of(fakeHeader)); @@ -283,6 +284,7 @@ private BlockHeader createBlock(final long number, final Optional messag null, null, null, + null, new MainnetBlockHeaderFunctions()); testHash = fakeHeader.getHash(); when(blockchain.getBlockHeader(number)).thenReturn(Optional.of(fakeHeader)); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/GenesisState.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/GenesisState.java index 2ee997f8ccd..b27023776f6 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/GenesisState.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/GenesisState.java @@ -48,6 +48,7 @@ import com.google.common.base.MoreObjects; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; +import org.apache.tuweni.units.bigints.UInt64; public final class GenesisState { @@ -218,6 +219,12 @@ private static BlockHeader buildHeader( .parentBeaconBlockRoot( (isCancunAtGenesis(genesis) ? parseParentBeaconBlockRoot(genesis) : null)) .requestsHash(isPragueAtGenesis(genesis) ? Hash.EMPTY_REQUESTS_HASH : null) + .targetBlobCount( + isPragueAtGenesis(genesis) + // TODO SLD EIP-7742 Currently defaulting to null due to dependency on web3j + // BlockHeader in CodeDelegationTransactionAcceptanceTest + ? genesis.getTargetBlobCount().map(UInt64::fromHexString).orElse(null) + : null) .buildBlockHeader(); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeader.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeader.java index 6bd1a2aa588..830a80ccceb 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeader.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeader.java @@ -28,6 +28,7 @@ import com.google.common.base.Suppliers; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; +import org.apache.tuweni.units.bigints.UInt64; /** A mined Ethereum block header. */ public class BlockHeader extends SealableBlockHeader @@ -65,6 +66,7 @@ public BlockHeader( final BlobGas excessBlobGas, final Bytes32 parentBeaconBlockRoot, final Hash requestsHash, + final UInt64 targetBlobCount, final BlockHeaderFunctions blockHeaderFunctions) { super( parentHash, @@ -86,7 +88,8 @@ public BlockHeader( blobGasUsed, excessBlobGas, parentBeaconBlockRoot, - requestsHash); + requestsHash, + targetBlobCount); this.nonce = nonce; this.hash = Suppliers.memoize(() -> blockHeaderFunctions.hash(this)); this.parsedExtraData = Suppliers.memoize(() -> blockHeaderFunctions.parseExtraData(this)); @@ -187,6 +190,9 @@ public void writeTo(final RLPOutput out) { if (requestsHash == null) break; out.writeBytes(requestsHash); + + if (targetBlobCount == null) break; + out.writeUInt64Scalar(targetBlobCount); } while (false); out.endList(); } @@ -219,6 +225,7 @@ public static BlockHeader readFrom( !input.isEndOfCurrentList() ? BlobGas.of(input.readUInt64Scalar()) : null; final Bytes32 parentBeaconBlockRoot = !input.isEndOfCurrentList() ? input.readBytes32() : null; final Hash requestsHash = !input.isEndOfCurrentList() ? Hash.wrap(input.readBytes32()) : null; + final UInt64 targetBlobCount = !input.isEndOfCurrentList() ? input.readUInt64Scalar() : null; input.leaveList(); return new BlockHeader( parentHash, @@ -242,6 +249,7 @@ public static BlockHeader readFrom( excessBlobGas, parentBeaconBlockRoot, requestsHash, + targetBlobCount, blockHeaderFunctions); } @@ -295,6 +303,9 @@ public String toString() { if (requestsHash != null) { sb.append("requestsHash=").append(requestsHash); } + if (targetBlobCount != null) { + sb.append("targetBlobCount=").append(targetBlobCount); + } return sb.append("}").toString(); } @@ -329,6 +340,7 @@ public static org.hyperledger.besu.ethereum.core.BlockHeader convertPluginBlockH .getRequestsHash() .map(h -> Hash.fromHexString(h.toHexString())) .orElse(null), + pluginBlockHeader.getTargetBlobCount().orElse(null), blockHeaderFunctions); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeaderBuilder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeaderBuilder.java index a024d53cd2f..b98f8201121 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeaderBuilder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeaderBuilder.java @@ -30,6 +30,7 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; +import org.apache.tuweni.units.bigints.UInt64; /** A utility class for building block headers. */ public class BlockHeaderBuilder { @@ -76,6 +77,7 @@ public class BlockHeaderBuilder { private Long blobGasUsed = null; private BlobGas excessBlobGas = null; private Bytes32 parentBeaconBlockRoot = null; + private UInt64 targetBlobCount = null; public static BlockHeaderBuilder create() { return new BlockHeaderBuilder(); @@ -124,7 +126,8 @@ public static BlockHeaderBuilder fromHeader(final BlockHeader header) { .blobGasUsed(header.getBlobGasUsed().orElse(null)) .excessBlobGas(header.getExcessBlobGas().orElse(null)) .parentBeaconBlockRoot(header.getParentBeaconBlockRoot().orElse(null)) - .requestsHash(header.getRequestsHash().orElse(null)); + .requestsHash(header.getRequestsHash().orElse(null)) + .targetBlobCount(header.getTargetBlobCount().orElse(null)); } public static BlockHeaderBuilder fromBuilder(final BlockHeaderBuilder fromBuilder) { @@ -149,6 +152,7 @@ public static BlockHeaderBuilder fromBuilder(final BlockHeaderBuilder fromBuilde .excessBlobGas(fromBuilder.excessBlobGas) .parentBeaconBlockRoot(fromBuilder.parentBeaconBlockRoot) .requestsHash(fromBuilder.requestsHash) + .targetBlobCount(fromBuilder.targetBlobCount) .blockHeaderFunctions(fromBuilder.blockHeaderFunctions); toBuilder.nonce = fromBuilder.nonce; return toBuilder; @@ -179,6 +183,7 @@ public BlockHeader buildBlockHeader() { excessBlobGas, parentBeaconBlockRoot, requestsHash, + targetBlobCount, blockHeaderFunctions); } @@ -194,7 +199,8 @@ public ProcessableBlockHeader buildProcessableBlockHeader() { timestamp, baseFee, mixHashOrPrevRandao, - parentBeaconBlockRoot); + parentBeaconBlockRoot, + targetBlobCount); } public SealableBlockHeader buildSealableBlockHeader() { @@ -220,7 +226,8 @@ public SealableBlockHeader buildSealableBlockHeader() { blobGasUsed, excessBlobGas, parentBeaconBlockRoot, - requestsHash); + requestsHash, + targetBlobCount); } private void validateBlockHeader() { @@ -260,6 +267,7 @@ public BlockHeaderBuilder populateFrom(final ProcessableBlockHeader processableB baseFee(processableBlockHeader.getBaseFee().orElse(null)); processableBlockHeader.getPrevRandao().ifPresent(this::prevRandao); processableBlockHeader.getParentBeaconBlockRoot().ifPresent(this::parentBeaconBlockRoot); + processableBlockHeader.getTargetBlobCount().ifPresent(this::targetBlobCount); return this; } @@ -285,6 +293,7 @@ public BlockHeaderBuilder populateFrom(final SealableBlockHeader sealableBlockHe sealableBlockHeader.getExcessBlobGas().ifPresent(this::excessBlobGas); sealableBlockHeader.getParentBeaconBlockRoot().ifPresent(this::parentBeaconBlockRoot); requestsHash(sealableBlockHeader.getRequestsHash().orElse(null)); + sealableBlockHeader.getTargetBlobCount().ifPresent(this::targetBlobCount); return this; } @@ -418,4 +427,9 @@ public BlockHeaderBuilder parentBeaconBlockRoot(final Bytes32 parentBeaconBlockR this.parentBeaconBlockRoot = parentBeaconBlockRoot; return this; } + + public BlockHeaderBuilder targetBlobCount(final UInt64 targetBlobCount) { + this.targetBlobCount = targetBlobCount; + return this; + } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/ProcessableBlockHeader.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/ProcessableBlockHeader.java index 036a33af97a..7e037dff3a7 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/ProcessableBlockHeader.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/ProcessableBlockHeader.java @@ -23,6 +23,7 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; +import org.apache.tuweni.units.bigints.UInt64; /** A block header capable of being processed. */ public class ProcessableBlockHeader @@ -46,6 +47,8 @@ public class ProcessableBlockHeader protected final Bytes32 mixHashOrPrevRandao; // parentBeaconBlockRoot is included for Cancun protected final Bytes32 parentBeaconBlockRoot; + // TODO SLD Quantity or UInt64Value instead? + protected final UInt64 targetBlobCount; protected ProcessableBlockHeader( final Hash parentHash, @@ -56,7 +59,8 @@ protected ProcessableBlockHeader( final long timestamp, final Wei baseFee, final Bytes32 mixHashOrPrevRandao, - final Bytes32 parentBeaconBlockRoot) { + final Bytes32 parentBeaconBlockRoot, + final UInt64 targetBlobCount) { this.parentHash = parentHash; this.coinbase = coinbase; this.difficulty = difficulty; @@ -66,6 +70,7 @@ protected ProcessableBlockHeader( this.baseFee = baseFee; this.mixHashOrPrevRandao = mixHashOrPrevRandao; this.parentBeaconBlockRoot = parentBeaconBlockRoot; + this.targetBlobCount = targetBlobCount; } /** @@ -178,6 +183,16 @@ public Optional getParentBeaconBlockRoot() { return Optional.ofNullable(parentBeaconBlockRoot); } + /** + * Returns the target blob count if available. + * + * @return the target blob count if available. + */ + @Override + public Optional getTargetBlobCount() { + return Optional.ofNullable(targetBlobCount); + } + public String toLogString() { return getNumber() + " (time: " + getTimestamp() + ")"; } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/SealableBlockHeader.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/SealableBlockHeader.java index 1934c8f8c0e..962178e5041 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/SealableBlockHeader.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/SealableBlockHeader.java @@ -24,6 +24,7 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; +import org.apache.tuweni.units.bigints.UInt64; /** A block header capable of being sealed. */ public class SealableBlockHeader extends ProcessableBlockHeader { @@ -69,7 +70,8 @@ protected SealableBlockHeader( final Long blobGasUsed, final BlobGas excessBlobGas, final Bytes32 parentBeaconBlockRoot, - final Hash requestsHash) { + final Hash requestsHash, + final UInt64 targetBlobCount) { super( parentHash, coinbase, @@ -79,7 +81,8 @@ protected SealableBlockHeader( timestamp, baseFee, mixHashOrPrevRandao, - parentBeaconBlockRoot); + parentBeaconBlockRoot, + targetBlobCount); this.ommersHash = ommersHash; this.stateRoot = stateRoot; this.transactionsRoot = transactionsRoot; diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockHeaderTestFixture.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockHeaderTestFixture.java index 99cf2407b8d..b0b9aa6497e 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockHeaderTestFixture.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockHeaderTestFixture.java @@ -25,6 +25,7 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; +import org.apache.tuweni.units.bigints.UInt64; public class BlockHeaderTestFixture { @@ -55,6 +56,7 @@ public class BlockHeaderTestFixture { private Optional excessBlobGas = Optional.empty(); private Optional blobGasUsed = Optional.empty(); private Optional parentBeaconBlockRoot = Optional.empty(); + private Optional targetBlobCount = Optional.empty(); public BlockHeader buildHeader() { final BlockHeaderBuilder builder = BlockHeaderBuilder.create(); @@ -80,6 +82,7 @@ public BlockHeader buildHeader() { blobGasUsed.ifPresent(builder::blobGasUsed); requestsHash.ifPresent(builder::requestsHash); parentBeaconBlockRoot.ifPresent(builder::parentBeaconBlockRoot); + targetBlobCount.ifPresent(builder::targetBlobCount); builder.blockHeaderFunctions(blockHeaderFunctions); return builder.buildBlockHeader(); @@ -201,4 +204,9 @@ public BlockHeaderTestFixture parentBeaconBlockRoot( this.parentBeaconBlockRoot = parentBeaconBlockRoot; return this; } + + public BlockHeaderTestFixture targetBlobCount(final UInt64 targetBlobCount) { + this.targetBlobCount = Optional.of(targetBlobCount); + return this; + } } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/chain/GenesisStateTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/chain/GenesisStateTest.java index ba036347085..83c0f1a4c46 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/chain/GenesisStateTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/chain/GenesisStateTest.java @@ -31,6 +31,7 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.units.bigints.UInt256; +import org.apache.tuweni.units.bigints.UInt64; import org.bouncycastle.util.encoders.Hex; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtensionContext; @@ -287,10 +288,6 @@ void genesisFromPrague(final DataStorageConfiguration dataStorageConfiguration) GenesisStateTest.class.getResource("genesis_prague.json"), ProtocolScheduleFixture.MAINNET); final BlockHeader header = genesisState.getBlock().getHeader(); - assertThat(header.getHash()) - .isEqualTo( - Hash.fromHexString( - "0x554807b22674e6d335f734485993857bbad7a9543affb0663a10c14d78135ec7")); assertThat(header.getGasLimit()).isEqualTo(0x2fefd8); assertThat(header.getGasUsed()).isZero(); assertThat(header.getNumber()).isZero(); @@ -331,6 +328,13 @@ void genesisFromPrague(final DataStorageConfiguration dataStorageConfiguration) .isEqualTo( Hash.fromHexString( "0x6036c41849da9c076ed79654d434017387a88fb833c2856b32e18218b3341c5f")); + assertThat(header.getTargetBlobCount().isPresent()).isTrue(); + assertThat(header.getTargetBlobCount().get()).isEqualTo(UInt64.ONE); + + assertThat(header.getHash()) + .isEqualTo( + Hash.fromHexString( + "0xdbc64edecb3a432e48cbd270b4a248ffc611b5f3dd666c8a10d546672cae17bd")); } @Test diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/LogRollingTests.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/LogRollingTests.java index e43d464474c..6a70cb20e28 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/LogRollingTests.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/LogRollingTests.java @@ -99,6 +99,7 @@ class LogRollingTests { null, null, null, + null, new MainnetBlockHeaderFunctions()); private static final BlockHeader headerTwo = new BlockHeader( @@ -123,6 +124,7 @@ class LogRollingTests { null, null, null, + null, new MainnetBlockHeaderFunctions()); @BeforeEach diff --git a/ethereum/core/src/test/resources/org/hyperledger/besu/ethereum/chain/genesis_prague.json b/ethereum/core/src/test/resources/org/hyperledger/besu/ethereum/chain/genesis_prague.json index d99071b328d..f9aa3ff4663 100644 --- a/ethereum/core/src/test/resources/org/hyperledger/besu/ethereum/chain/genesis_prague.json +++ b/ethereum/core/src/test/resources/org/hyperledger/besu/ethereum/chain/genesis_prague.json @@ -4073,5 +4073,6 @@ "number": "0x0", "gasUsed": "0x0", "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "baseFeePerGas": "0x3b9aca00" + "baseFeePerGas": "0x3b9aca00", + "targetBlobCount": "0x1" } diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/MessageWrapperTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/MessageWrapperTest.java index 2b020cd4ac8..0256b096532 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/MessageWrapperTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/MessageWrapperTest.java @@ -398,6 +398,7 @@ public TestBlockHeader( null, null, null, + null, new MainnetBlockHeaderFunctions()); } } diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/ChainForTestCreator.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/ChainForTestCreator.java index c15f3aa1dcd..e6fab811024 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/ChainForTestCreator.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/ChainForTestCreator.java @@ -61,6 +61,7 @@ public static BlockHeader prepareHeader(final long number, final Optional getBaseFee() { */ @Unstable Optional getParentBeaconBlockRoot(); + + /** + * The target_blob_count of this header. + * + * @return The target blob count of this header. + */ + @Unstable + // TODO SLD should be Quantity or new subclass of Quantity? + default Optional getTargetBlobCount() { + return Optional.empty(); + } } From 6e29444432736c5366227df188f7b0888a69abca Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Tue, 29 Oct 2024 13:33:46 +1000 Subject: [PATCH 08/39] [TESTING] Remove dependency on test containers (#7790) * removed dep for testcontainers Signed-off-by: Sally MacFarlane --------- Signed-off-by: Sally MacFarlane Signed-off-by: Marlene Marz --- acceptance-tests/dsl/build.gradle | 1 - .../account/TransferTransactionBuilder.java | 2 +- acceptance-tests/tests/build.gradle | 1 - besu/build.gradle | 1 - enclave/build.gradle | 1 - ethereum/api/build.gradle | 1 - ethereum/core/build.gradle | 1 - gradle/versions.gradle | 0 platform/build.gradle | 2 - testutil/build.gradle | 2 - .../enclave/testutil/TesseraTestHarness.java | 290 ------------------ .../testutil/TesseraTestHarnessFactory.java | 126 -------- 12 files changed, 1 insertion(+), 427 deletions(-) create mode 100644 gradle/versions.gradle delete mode 100644 testutil/src/main/java/org/hyperledger/enclave/testutil/TesseraTestHarness.java delete mode 100644 testutil/src/main/java/org/hyperledger/enclave/testutil/TesseraTestHarnessFactory.java diff --git a/acceptance-tests/dsl/build.gradle b/acceptance-tests/dsl/build.gradle index aa5db9ce1e7..0b664c52556 100644 --- a/acceptance-tests/dsl/build.gradle +++ b/acceptance-tests/dsl/build.gradle @@ -45,6 +45,5 @@ dependencies { implementation 'org.web3j:crypto' implementation 'org.wiremock:wiremock' - implementation 'org.testcontainers:testcontainers' implementation 'org.junit.jupiter:junit-jupiter' } diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/account/TransferTransactionBuilder.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/account/TransferTransactionBuilder.java index 1d859694440..bb5fd5c4ed3 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/account/TransferTransactionBuilder.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/account/TransferTransactionBuilder.java @@ -14,7 +14,7 @@ */ package org.hyperledger.besu.tests.acceptance.dsl.transaction.account; -import static org.testcontainers.shaded.com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkNotNull; import org.hyperledger.besu.crypto.SECP256K1; import org.hyperledger.besu.crypto.SignatureAlgorithm; diff --git a/acceptance-tests/tests/build.gradle b/acceptance-tests/tests/build.gradle index e9724151abd..fdc77354522 100644 --- a/acceptance-tests/tests/build.gradle +++ b/acceptance-tests/tests/build.gradle @@ -74,7 +74,6 @@ dependencies { testImplementation 'org.assertj:assertj-core' testImplementation 'org.awaitility:awaitility' testImplementation 'org.junit.jupiter:junit-jupiter' - testImplementation 'org.testcontainers:testcontainers' testImplementation 'org.web3j:abi' testImplementation 'org.web3j:besu' testImplementation 'org.web3j:core' diff --git a/besu/build.gradle b/besu/build.gradle index fb9aeef9e67..41a4b11494b 100644 --- a/besu/build.gradle +++ b/besu/build.gradle @@ -104,7 +104,6 @@ dependencies { testImplementation 'org.awaitility:awaitility' testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' - testImplementation 'org.testcontainers:testcontainers' testImplementation 'tech.pegasys.discovery:discovery' testImplementation 'com.google.dagger:dagger' diff --git a/enclave/build.gradle b/enclave/build.gradle index 25aeb466d77..24aa1b2e64d 100644 --- a/enclave/build.gradle +++ b/enclave/build.gradle @@ -24,5 +24,4 @@ dependencies { integrationTestImplementation 'org.awaitility:awaitility' integrationTestImplementation 'org.junit.jupiter:junit-jupiter-api' integrationTestImplementation 'org.mockito:mockito-core' - integrationTestImplementation 'org.testcontainers:testcontainers' } diff --git a/ethereum/api/build.gradle b/ethereum/api/build.gradle index 7f5e3d40a9c..6bbfa531a99 100644 --- a/ethereum/api/build.gradle +++ b/ethereum/api/build.gradle @@ -121,7 +121,6 @@ dependencies { integrationTestImplementation 'org.junit.jupiter:junit-jupiter' integrationTestImplementation 'org.mockito:mockito-core' integrationTestImplementation 'org.mockito:mockito-junit-jupiter' - integrationTestImplementation 'org.testcontainers:testcontainers' integrationTestRuntimeOnly 'org.junit.jupiter:junit-jupiter' } diff --git a/ethereum/core/build.gradle b/ethereum/core/build.gradle index 24c794e298e..912d8673a58 100644 --- a/ethereum/core/build.gradle +++ b/ethereum/core/build.gradle @@ -96,7 +96,6 @@ dependencies { integrationTestImplementation 'org.assertj:assertj-core' integrationTestImplementation 'org.junit.jupiter:junit-jupiter-api' integrationTestImplementation 'org.mockito:mockito-core' - integrationTestImplementation 'org.testcontainers:testcontainers' integrationTestImplementation 'io.tmio:tuweni-bytes' integrationTestRuntimeOnly 'org.junit.jupiter:junit-jupiter' diff --git a/gradle/versions.gradle b/gradle/versions.gradle new file mode 100644 index 00000000000..e69de29bb2d diff --git a/platform/build.gradle b/platform/build.gradle index 307c54dc1a8..5b02eb0beeb 100644 --- a/platform/build.gradle +++ b/platform/build.gradle @@ -158,8 +158,6 @@ dependencies { api 'org.springframework.security:spring-security-crypto:6.3.3' - api 'org.testcontainers:testcontainers:1.20.2' - api 'org.wiremock:wiremock:3.9.1' api 'org.web3j:abi:4.12.2' diff --git a/testutil/build.gradle b/testutil/build.gradle index e77a763bdae..1663c366507 100644 --- a/testutil/build.gradle +++ b/testutil/build.gradle @@ -49,6 +49,4 @@ dependencies { implementation 'org.assertj:assertj-core' implementation 'org.mockito:mockito-core' implementation 'org.web3j:core' - - implementation 'org.testcontainers:testcontainers' } diff --git a/testutil/src/main/java/org/hyperledger/enclave/testutil/TesseraTestHarness.java b/testutil/src/main/java/org/hyperledger/enclave/testutil/TesseraTestHarness.java deleted file mode 100644 index f27224fa1d5..00000000000 --- a/testutil/src/main/java/org/hyperledger/enclave/testutil/TesseraTestHarness.java +++ /dev/null @@ -1,290 +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.enclave.testutil; - -import static com.google.common.io.Files.readLines; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Path; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - -import com.google.common.base.Charsets; -import io.vertx.core.json.JsonArray; -import org.assertj.core.util.Files; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.utility.MountableFile; - -/** The Tessera test harness. */ -public class TesseraTestHarness implements EnclaveTestHarness { - private static final Logger LOG = LoggerFactory.getLogger(TesseraTestHarness.class); - - private final EnclaveConfiguration enclaveConfiguration; - - private boolean isRunning; - private URI nodeURI; - private URI q2TUri; - private URI thirdPartyUri; - - /** The constant TESSERA_VERSION. */ - public static final String TESSERA_VERSION = "22.10.0"; - - private final int thirdPartyPort = 9081; - private final int q2TPort = 9082; - - /** The constant p2pPort. */ - public static final int p2pPort = 9001; - - private final String containerKeyDir = "/tmp/keys/"; - - @SuppressWarnings("rawtypes") - private GenericContainer tesseraContainer; - - private final Optional containerNetwork; - private final String containerName; - - /** - * Instantiates a new Tessera test harness. - * - * @param enclaveConfiguration the enclave configuration - * @param containerNetwork the container network - */ - protected TesseraTestHarness( - final EnclaveConfiguration enclaveConfiguration, final Optional containerNetwork) { - this.enclaveConfiguration = enclaveConfiguration; - this.containerNetwork = containerNetwork; - this.containerName = enclaveConfiguration.getName(); - Runtime.getRuntime().addShutdownHook(new Thread(this::stop)); - } - - @Override - public void start() { - if (!isRunning) { - final File tempFolder = Files.newTemporaryFolder(); - LOG.info("Temporary directory: " + tempFolder.getAbsolutePath()); - final String configFile = createConfigFile(enclaveConfiguration.getName()); - - tesseraContainer = buildTesseraContainer(configFile); - containerNetwork.ifPresent(network -> addNetwork(tesseraContainer, containerName, network)); - tesseraContainer.start(); - isRunning = true; - - try { - final String host = "http://" + tesseraContainer.getHost(); - nodeURI = new URI(host + ":" + tesseraContainer.getMappedPort(p2pPort)); - LOG.info("Tessera node URI: {}", nodeURI); - q2TUri = new URI(host + ':' + tesseraContainer.getMappedPort(q2TPort)); - LOG.info("Tessera client URI: {}", q2TUri); - thirdPartyUri = new URI(host + ':' + tesseraContainer.getMappedPort(thirdPartyPort)); - LOG.info("Tessera thirdParty URI: {}", thirdPartyUri); - } catch (final URISyntaxException e) { - throw new RuntimeException(e); - } - } - } - - @Override - public void stop() { - if (isRunning) { - tesseraContainer.stop(); - isRunning = false; - } - } - - @Override - public void close() { - stop(); - } - - @Override - public List getPublicKeyPaths() { - return Arrays.asList(enclaveConfiguration.getPublicKeys()); - } - - @Override - public String getDefaultPublicKey() { - return readFile(enclaveConfiguration.getPublicKeys()[0]); - } - - @Override - public List getPublicKeys() { - return Arrays.stream(enclaveConfiguration.getPublicKeys()) - .map(TesseraTestHarness::readFile) - .collect(Collectors.toList()); - } - - private static String readFile(final Path path) { - try { - return readLines(path.toFile(), Charsets.UTF_8).get(0); - } catch (final IOException e) { - e.printStackTrace(); - return ""; - } - } - - @Override - public URI clientUrl() { - return q2TUri; - } - - @Override - public URI nodeUrl() { - return nodeURI; - } - - @Override - public void addOtherNode(final URI otherNode) { - enclaveConfiguration.addOtherNode(otherNode.toString()); - } - - @Override - public EnclaveType getEnclaveType() { - return EnclaveType.TESSERA; - } - - private String createConfigFile(final String nodeName) { - // create a config file - - // @formatter:off - String confString = - "{\n" - + " \"mode\" : \"orion\",\n" - + enclaveConfiguration.getEnclaveEncryptorType().toTesseraEncryptorConfigJSON() - + " \"useWhiteList\": false,\n" - + " \"jdbc\": {\n" - + " \"username\": \"sa\",\n" - + " \"password\": \"\",\n" - + " \"url\": \"jdbc:h2:/tmp/db;MODE=Oracle;TRACE_LEVEL_SYSTEM_OUT=0\",\n" - + " \"autoCreateTables\": true\n" - + " },\n" - + " \"serverConfigs\":[\n" - + " {\n" - + " \"app\":\"ThirdParty\",\n" - + " \"enabled\": true,\n" - + " \"serverAddress\": \"http://" - + nodeName - + ":" - + thirdPartyPort - + "\",\n" - + " \"cors\" : {\n" - + " \"allowedMethods\" : [\"GET\", \"OPTIONS\"],\n" - + " \"allowedOrigins\" : [\"*\"]\n" - + " },\n" - + " \"communicationType\" : \"REST\"\n" - + " },\n" - + " {\n" - + " \"app\":\"Q2T\",\n" - + " \"enabled\": true,\n" - + " \"serverAddress\":\"http://" - + nodeName - + ":" - + q2TPort - + "\",\n" - + " \"communicationType\" : \"REST\"\n" - + " },\n" - + " {\n" - + " \"app\":\"P2P\",\n" - + " \"enabled\": true,\n" - + " \"serverAddress\":\"http://" - + nodeName - + ":" - + p2pPort - + "\",\n" - + " \"communicationType\" : \"REST\"\n" - + " }\n" - + " ],\n" - + " \"keys\": {\n" - + " \"passwords\": [],\n" - + " \"keyData\": " - + buildKeyConfig() - + "\n" - + " },\n" - + " \"alwaysSendTo\": []"; - - if (enclaveConfiguration.getOtherNodes().size() != 0) { - confString += - ",\n" - + " \"peer\": [\n" - + " {\n" - + " \"url\": \"" - + enclaveConfiguration.getOtherNodes().get(0) - + "\"\n" - + " }\n" - + " ]"; - } else { - confString += ",\n" + " \"peer\": []"; - } - - confString += "\n}"; - - final File configFile = Files.newTemporaryFile(); - try { - final FileWriter fw = new FileWriter(configFile, StandardCharsets.UTF_8); - fw.write(confString); - fw.close(); - } catch (final IOException e) { - throw new RuntimeException(e); - } - - return configFile.getAbsolutePath(); - } - - private String buildKeyConfig() { - final JsonArray keyArray = new JsonArray(); - final List pubKeysPaths = Arrays.asList(enclaveConfiguration.getPublicKeys()); - final List privKeyPaths = Arrays.asList(enclaveConfiguration.getPrivateKeys()); - - for (int count = 0; count < pubKeysPaths.size(); count++) { - final HashMap stringStringHashMap = new HashMap<>(); - stringStringHashMap.put( - "publicKeyPath", containerKeyDir + pubKeysPaths.get(count).getFileName()); - stringStringHashMap.put( - "privateKeyPath", containerKeyDir + privKeyPaths.get(count).getFileName()); - keyArray.add(stringStringHashMap); - } - - return keyArray.toString(); - } - - @SuppressWarnings("rawtypes") - private GenericContainer buildTesseraContainer(final String configFilePath) { - final String containerConfigFilePath = "/tmp/config.json"; - final String keyDir = enclaveConfiguration.getTempDir().toString(); - return new GenericContainer<>("quorumengineering/tessera:" + TESSERA_VERSION) - .withCopyFileToContainer(MountableFile.forHostPath(configFilePath), containerConfigFilePath) - .withFileSystemBind(keyDir, containerKeyDir) - .withCommand("--configfile " + containerConfigFilePath) - .withExposedPorts(p2pPort, q2TPort, thirdPartyPort) - .waitingFor(Wait.forHttp("/upcheck").withMethod("GET").forStatusCode(200)); - } - - @SuppressWarnings("rawtypes") - private void addNetwork( - final GenericContainer container, final String containerName, final Network network) { - container.withNetwork(network).withNetworkAliases(containerName); - } -} diff --git a/testutil/src/main/java/org/hyperledger/enclave/testutil/TesseraTestHarnessFactory.java b/testutil/src/main/java/org/hyperledger/enclave/testutil/TesseraTestHarnessFactory.java deleted file mode 100644 index 0cfe8b76c9b..00000000000 --- a/testutil/src/main/java/org/hyperledger/enclave/testutil/TesseraTestHarnessFactory.java +++ /dev/null @@ -1,126 +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.enclave.testutil; - -import static org.apache.tuweni.io.file.Files.copyResource; - -import java.io.IOException; -import java.nio.file.Path; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import javax.annotation.Nonnull; - -import org.testcontainers.containers.Network; - -/** The Tessera test harness factory. */ -public class TesseraTestHarnessFactory { - private static final String storage = "memory"; - - /** Default constructor */ - private TesseraTestHarnessFactory() {} - - /** - * Create tessera test harness. - * - * @param name the name - * @param tempDir the temp dir - * @param enclaveConfig the enclave config - * @param containerNetwork the container network - * @return the tessera test harness - */ - public static TesseraTestHarness create( - final String name, - final Path tempDir, - final EnclaveKeyConfiguration enclaveConfig, - final Optional containerNetwork) { - return create( - name, - tempDir, - enclaveConfig.getPubKeyPaths(), - enclaveConfig.getPrivKeyPaths(), - enclaveConfig.getEnclaveEncryptorType(), - Collections.emptyList(), - containerNetwork); - } - - /** - * Create tessera test harness. - * - * @param name the name - * @param tempDir the temp dir - * @param pubKeyPaths the pub key paths - * @param privKeyPaths the priv key paths - * @param enclaveEncryptorType the enclave encryptor type - * @param othernodes the othernodes - * @param containerNetwork the container network - * @return the tessera test harness - */ - public static TesseraTestHarness create( - final String name, - final Path tempDir, - final String[] pubKeyPaths, - final String[] privKeyPaths, - final EnclaveEncryptorType enclaveEncryptorType, - final List othernodes, - final Optional containerNetwork) { - final Path[] pubKeys = stringArrayToPathArray(tempDir, pubKeyPaths); - final Path[] privKeys = stringArrayToPathArray(tempDir, privKeyPaths); - - return create( - name, tempDir, pubKeys, privKeys, enclaveEncryptorType, othernodes, containerNetwork); - } - - /** - * Create tessera test harness. - * - * @param name the name - * @param tempDir the temp dir - * @param key1pubs the key 1 pubs - * @param key1keys the key 1 keys - * @param enclaveEncryptorType the enclave encryptor type - * @param othernodes the othernodes - * @param containerNetwork the container network - * @return the tessera test harness - */ - public static TesseraTestHarness create( - final String name, - final Path tempDir, - final Path[] key1pubs, - final Path[] key1keys, - final EnclaveEncryptorType enclaveEncryptorType, - final List othernodes, - final Optional containerNetwork) { - return new TesseraTestHarness( - new EnclaveConfiguration( - name, key1pubs, key1keys, enclaveEncryptorType, tempDir, othernodes, false, storage), - containerNetwork); - } - - @Nonnull - private static Path[] stringArrayToPathArray(final Path tempDir, final String[] privKeyPaths) { - return Arrays.stream(privKeyPaths) - .map( - (pk) -> { - try { - return copyResource(pk, tempDir.resolve(pk)); - } catch (final IOException e) { - throw new RuntimeException(e); - } - }) - .toArray(Path[]::new); - } -} From e01e6636913343cede93fd03f4e54e87ce3899b3 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Tue, 29 Oct 2024 13:56:19 +1000 Subject: [PATCH 09/39] updated links in README to new wiki (#7722) Signed-off-by: Sally MacFarlane Signed-off-by: Marlene Marz --- README.md | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 00aad005ac7..7139df85805 100644 --- a/README.md +++ b/README.md @@ -14,15 +14,15 @@ Besu is an Apache 2.0 licensed, MainNet compatible, Ethereum client written in J * [Besu User Documentation] * [Besu Issues] -* [Besu Wiki](https://wiki.hyperledger.org/display/BESU/Besu) -* [How to Contribute to Besu](https://wiki.hyperledger.org/display/BESU/How+to+Contribute) -* [Besu Roadmap & Planning](https://wiki.hyperledger.org/pages/viewpage.action?pageId=24781786) +* [Besu Wiki](https://lf-hyperledger.atlassian.net/wiki/spaces/BESU/) +* [How to Contribute to Besu](https://lf-hyperledger.atlassian.net/wiki/spaces/BESU/pages/22156850/How+to+Contribute) +* [Besu Roadmap & Planning](https://lf-hyperledger.atlassian.net/wiki/spaces/BESU/pages/22154278/Besu+Roadmap+Planning) ## Issues Besu issues are tracked [in the github issues tab][Besu Issues]. -See our [guidelines](https://wiki.hyperledger.org/display/BESU/Issues) for more details on searching and creating issues. +See our [guidelines](https://lf-hyperledger.atlassian.net/wiki/spaces/BESU/pages/22154243/Issues) for more details on searching and creating issues. If you have any questions, queries or comments, [Besu channel on Discord] is the place to find us. @@ -34,20 +34,19 @@ To install the Besu binary, follow [these instructions](https://besu.hyperledger ## Besu Developers * [Contributing Guidelines] -* [Coding Conventions](https://wiki.hyperledger.org/display/BESU/Coding+Conventions) -* [Command Line Interface (CLI) Style Guide](https://wiki.hyperledger.org/display/BESU/Besu+CLI+Style+Guide) +* [Coding Conventions](https://lf-hyperledger.atlassian.net/wiki/spaces/BESU/pages/22154259/Coding+Conventions) +* [Command Line Interface (CLI) Style Guide](https://lf-hyperledger.atlassian.net/wiki/spaces/BESU/pages/22154260/Besu+CLI+Style+Guide) * [Besu User Documentation] for running and using Besu ### Development Instructions for how to get started with developing on the Besu codebase. Please also read the -[wiki](https://wiki.hyperledger.org/display/BESU/Pull+Requests) for more details on how to submit a pull request (PR). +[wiki](https://lf-hyperledger.atlassian.net/wiki/spaces/BESU/pages/22154251/Pull+Requests) for more details on how to submit a pull request (PR). -* [Checking Out and Building](https://wiki.hyperledger.org/display/BESU/Building+from+source) -* [Running Developer Builds](https://wiki.hyperledger.org/display/BESU/Building+from+source#running-developer-builds) -* [Code Coverage](https://wiki.hyperledger.org/display/BESU/Code+coverage) -* [Logging](https://wiki.hyperledger.org/display/BESU/Logging) or the [Documentation's Logging section](https://besu.hyperledger.org/public-networks/how-to/monitor/logging) +* [Checking Out and Building](https://lf-hyperledger.atlassian.net/wiki/spaces/BESU/pages/22154264/Building+from+source) +* [Code Coverage](https://lf-hyperledger.atlassian.net/wiki/spaces/BESU/pages/22154288/Code+coverage) +* [Logging](https://lf-hyperledger.atlassian.net/wiki/spaces/BESU/pages/22154291/Logging) or the [Documentation's Logging section](https://besu.hyperledger.org/public-networks/how-to/monitor/logging) ## Release Notes From 65e66c97ad6afbd59ade043c3a563daace9c7295 Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Wed, 30 Oct 2024 16:21:10 +0100 Subject: [PATCH 10/39] Fix registering new metric categories from plugins (#7825) Signed-off-by: Fabio Di Fabio Signed-off-by: Marlene Marz --- 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 0ecfc8776ca..88579a628a6 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(); @@ -1128,10 +1125,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() { @@ -1166,6 +1159,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); @@ -1183,10 +1179,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)); @@ -1883,6 +1875,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 02660fc5468ffc8751aa73e2f7b9b99c9e754e94 Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Wed, 30 Oct 2024 18:12:10 +0100 Subject: [PATCH 11/39] Add a method to check if a metric category is enabled to the plugin API (#7832) Signed-off-by: Fabio Di Fabio Signed-off-by: Marlene Marz --- 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 88579a628a6..167c910c828 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -1891,7 +1891,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 e5d73689e2c994c61d991d9c97849e3287b551e7 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 12/39] 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 Signed-off-by: Marlene Marz --- .../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 cc5ec7c10325948fab66e45e5e6725b0b0137051 Mon Sep 17 00:00:00 2001 From: Matilda-Clerke Date: Thu, 31 Oct 2024 09:29:46 +1100 Subject: [PATCH 13/39] 7311: add GetReceiptsFromPeerTask (#7638) Signed-off-by: Matilda Clerke Signed-off-by: Marlene Marz --- .../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 6eaea37dd96ccc59c7bdbf8134e099b88f0e4754 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 14/39] Update DCO.md (#7827) Signed-off-by: monem <119044801+pucedoteth@users.noreply.github.com> Co-authored-by: Sally MacFarlane Signed-off-by: Marlene Marz --- 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 3229a87cde106bc4632650d61df72bf68b4a881f Mon Sep 17 00:00:00 2001 From: Simon Dudley Date: Thu, 31 Oct 2024 15:54:32 +1000 Subject: [PATCH 15/39] Test against EngineNewPayloadV4 in EngineNewPayloadV4Test (#7837) Also change "Missing" -> "Unexpected" message when V3 blob params sent to V2 Signed-off-by: Simon Dudley Signed-off-by: Marlene Marz --- .../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 76d3e931e7f31e45e7b983de3a839ab28023f753 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Thu, 31 Oct 2024 18:09:22 +1000 Subject: [PATCH 16/39] update discord invite link (#7836) Signed-off-by: Sally MacFarlane Signed-off-by: Marlene Marz --- 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 3bfe61a2c5c4b18741bf6ff64ac9b79687ba5009 Mon Sep 17 00:00:00 2001 From: garyschulte Date: Thu, 31 Oct 2024 12:18:27 -0700 Subject: [PATCH 17/39] 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 | 1 + 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, 2 insertions(+), 1694 deletions(-) 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 167c910c828..597de9999ff 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; @@ -1097,7 +1096,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 index 9b5cb7a3a71..0074775f459 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/RetestethSubCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/RetestethSubCommand.java @@ -147,3 +147,4 @@ public void run() { } } } + 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 520f6062e61246c6aa73d738cb3387bb0cdbde06 Mon Sep 17 00:00:00 2001 From: Justin Florentine Date: Thu, 31 Oct 2024 19:26:41 -0400 Subject: [PATCH 18/39] 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 Signed-off-by: Marlene Marz --- .../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 c6afe4c7ad828e42c48a0700a63210e1c7c5cadd Mon Sep 17 00:00:00 2001 From: Justin Florentine Date: Sun, 3 Nov 2024 18:12:00 -0500 Subject: [PATCH 19/39] IntelliJ do not fail me (#7846) Signed-off-by: jflo Signed-off-by: Marlene Marz --- .../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 597de9999ff..ec8f8a55e5d 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; @@ -2109,7 +2109,7 @@ private TransactionPoolConfiguration buildTransactionPoolConfiguration() { return txPoolConfBuilder.build(); } - private MiningParameters getMiningParameters() { + private MiningConfiguration getMiningParameters() { miningOptions.setTransactionSelectionService(transactionSelectionServiceImpl); final var miningParameters = miningOptions.toDomainObject(); getGenesisBlockPeriodSeconds(genesisConfigOptionsSupplier.get()) @@ -2161,8 +2161,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 b2164df29a75472c65fabe02fb7ec5d798ba6167 Mon Sep 17 00:00:00 2001 From: Justin Florentine Date: Sun, 3 Nov 2024 18:36:22 -0500 Subject: [PATCH 20/39] 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 Signed-off-by: Marlene Marz --- .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 bec65e8eaf98b0a5b14278af77f197b9008e8ca0 Mon Sep 17 00:00:00 2001 From: Justin Florentine Date: Mon, 4 Nov 2024 15:36:11 -0500 Subject: [PATCH 21/39] IntelliJ do not fail me (#7855) Signed-off-by: jflo Signed-off-by: Marlene Marz --- .../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 ec8f8a55e5d..6ecc22cecdb 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 4ddab7379dc647ade5952ea373790a168ff44abb Mon Sep 17 00:00:00 2001 From: garyschulte Date: Mon, 4 Nov 2024 13:16:36 -0800 Subject: [PATCH 22/39] remove dangling retesteth references (#7856) Signed-off-by: garyschulte Signed-off-by: Marlene Marz --- 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 3f1d42cfa3268d868adf256b4d12a560c312d8a8 Mon Sep 17 00:00:00 2001 From: garyschulte Date: Mon, 4 Nov 2024 15:05:16 -0800 Subject: [PATCH 23/39] 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 Signed-off-by: Marlene Marz --- .../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 04129628d87b4b6caa31803e1f0e659332080827 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 24/39] 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. Signed-off-by: Marlene Marz --- .../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 75000121661e8c243209b042e3a66966392354ee Mon Sep 17 00:00:00 2001 From: Vaidik Date: Tue, 5 Nov 2024 21:01:07 +0530 Subject: [PATCH 25/39] 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 Signed-off-by: Marlene Marz --- .../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 1bc5f94faae8f9e5c63fa01e4da0a97f2e9bd1e4 Mon Sep 17 00:00:00 2001 From: Justin Florentine Date: Tue, 5 Nov 2024 10:56:07 -0500 Subject: [PATCH 26/39] calling the wrong create() method (#7857) Signed-off-by: jflo Signed-off-by: Marlene Marz --- .../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 c64ad7a29793a7d86778857791254020148d327c Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Wed, 6 Nov 2024 07:04:54 +0100 Subject: [PATCH 27/39] Fully initialize MetricCategoryRegistry for acceptance tests (#7860) Signed-off-by: Fabio Di Fabio Signed-off-by: Marlene Marz --- .../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 2f7bf9444978e26b54566ad3859432ff11079fa4 Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Wed, 6 Nov 2024 09:14:07 +0100 Subject: [PATCH 28/39] Add more subprojects to BOM (#7859) Signed-off-by: Fabio Di Fabio Signed-off-by: Marlene Marz --- 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 aae365c2379649485093eb14be5c26c370103dfc Mon Sep 17 00:00:00 2001 From: Justin Florentine Date: Wed, 6 Nov 2024 14:55:57 -0500 Subject: [PATCH 29/39] adds action to manage stale issues (#7864) Signed-off-by: jflo Signed-off-by: Marlene Marz --- .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 ab5d1f5dc27bfc20bdad4e9762cda6c7df463240 Mon Sep 17 00:00:00 2001 From: wangjingcun Date: Fri, 8 Nov 2024 17:00:29 +0800 Subject: [PATCH 30/39] chore: fix some typos in comments (#7866) Signed-off-by: wangjingcun Signed-off-by: Marlene Marz --- .../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 f4c3960179ae10c0fbdc9815320ddc1c0b911fdb 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 31/39] 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 Signed-off-by: Marlene Marz --- 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 dde2988031b955aaff5274c9fedb6dca8c7f751d Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Fri, 8 Nov 2024 12:25:59 +0100 Subject: [PATCH 32/39] Fix missing registration of PeerTransactionTracker to dropped tx notifications (#7858) Signed-off-by: Fabio Di Fabio Signed-off-by: Marlene Marz --- .../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 f1802d8f5885b4a9876715d093887e503f215e2b Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Fri, 8 Nov 2024 13:44:28 +0100 Subject: [PATCH 33/39] Make healing an action of the WorldStateArchive (#7862) Signed-off-by: Fabio Di Fabio Signed-off-by: Marlene Marz --- .../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 37eb73494eeafe25c38c88a1d506c1e9cb939fee Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Fri, 8 Nov 2024 15:40:02 +0100 Subject: [PATCH 34/39] Remove the Synchronizer from ProtocolContext (#7863) Signed-off-by: Fabio Di Fabio Signed-off-by: Marlene Marz --- .../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 c9142ad78ebb691ba85c74b7986051ed7636b96b 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 35/39] 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 Signed-off-by: Marlene Marz --- 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 28d7971b0cb948cb0fb534c7d5b82a22bd307b71 Mon Sep 17 00:00:00 2001 From: amsmota Date: Wed, 13 Nov 2024 08:50:56 +0000 Subject: [PATCH 36/39] 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 Signed-off-by: Marlene Marz --- 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 0e6c8be33d08e7f8a6bb5ffc3cc78d6023fd2f75 Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Thu, 14 Nov 2024 04:58:05 +0100 Subject: [PATCH 37/39] Fix registration of RocksDB metrics categories (#7879) Signed-off-by: Fabio Di Fabio Signed-off-by: Marlene Marz --- .../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 a927eb8f6bbdd435c260900665625750a3b07959 Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Thu, 14 Nov 2024 15:44:40 +1100 Subject: [PATCH 38/39] MAINTAINERS - Add Matilda Clerke (#7829) Signed-off-by: Gabriel-Trintinalia Signed-off-by: Marlene Marz --- 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 103fbe8cef1cfe5274b7b266081a8fb4651f9388 Mon Sep 17 00:00:00 2001 From: Matt Whitehead Date: Thu, 14 Nov 2024 14:45:34 +0700 Subject: [PATCH 39/39] 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 Signed-off-by: Marlene Marz --- 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')