From 39a356f82431d0c54d22a07208ce26a032e36433 Mon Sep 17 00:00:00 2001 From: garyschulte Date: Wed, 13 Mar 2024 10:52:41 -0700 Subject: [PATCH 01/22] proposed "develop" build versions (#6699) * proposed "develop" build versions Signed-off-by: garyschulte --- build.gradle | 58 +++++++++++++++++++++++++++-------------------- gradle.properties | 2 -- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/build.gradle b/build.gradle index 6ad1bee41d5..17d2d317ffd 100644 --- a/build.gradle +++ b/build.gradle @@ -119,7 +119,7 @@ allprojects { apply plugin: 'net.ltgt.errorprone' apply from: "${rootDir}/gradle/versions.gradle" - version = rootProject.version + version = calculateVersion() jacoco { toolVersion = '0.8.8' @@ -1038,42 +1038,50 @@ def buildTime() { return df.format(new Date()) } -// Takes the version, and if -SNAPSHOT is part of it replaces SNAPSHOT -// with the git commit version. @Memoized def calculateVersion() { - String version = rootProject.version - if (version.endsWith("-SNAPSHOT")) { - version = version.replace("-SNAPSHOT", "-dev-" + getCheckedOutGitCommitHash()) + // Regex pattern for basic calendar versioning, with provision to omit patch rev + def calVerPattern = ~/\d+\.\d+(\.\d+)?(-.*)?/ + + if (project.hasProperty('version') && (project.version =~ calVerPattern)) { + return "${project.version}" + } else { + // If no version is supplied or it doesn't match the semantic versioning, calculate from git + println("Generating project version as supplied is version not semver: ${project.version}") + def gitDetails = getGitCommitDetails(10) // Adjust length as needed + return "${gitDetails.date}-develop-${gitDetails.hash}" } - return version } -def getCheckedOutGitCommitHash(length = 8) { +def getGitCommitDetails(length = 8) { try { def gitFolder = "$projectDir/.git/" if (!file(gitFolder).isDirectory()) { - // We are in a submodule. The file's contents are `gitdir: \n`. - // Read the file, cut off the front, and trim the whitespace. gitFolder = file(gitFolder).text.substring(length).trim() + "/" } def takeFromHash = length - /* - * '.git/HEAD' contains either - * in case of detached head: the currently checked out commit hash - * otherwise: a reference to a file containing the current commit hash - */ - def head = new File(gitFolder + "HEAD").text.split(":") // .git/HEAD - def isCommit = head.length == 1 // e5a7c79edabbf7dd39888442df081b1c9d8e88fd - - if (isCommit) return head[0].trim().take(takeFromHash) // e5a7c79edabb - - def refHead = new File(gitFolder + head[1].trim()) // .git/refs/heads/master - refHead.text.trim().take takeFromHash + def head = new File(gitFolder + "HEAD").text.split(":") + def isCommit = head.length == 1 + + def commitHash, refHeadFile + if (isCommit) { + commitHash = head[0].trim().take(takeFromHash) + refHeadFile = new File(gitFolder + "HEAD") + } else { + refHeadFile = new File(gitFolder + head[1].trim()) + commitHash = refHeadFile.text.trim().take(takeFromHash) + } + + // Use head file modification time as a proxy for the build date + def lastModified = new Date(refHeadFile.lastModified()) + // Format the date as "yy.M" (e.g. 24.3 for March 2024) + def formattedDate = new SimpleDateFormat("yy.M").format(lastModified) + + return [hash: commitHash, date: formattedDate] } catch (Exception e) { - logger.warn('Could not calculate git commit, using "xxxxxxxx" (run with --info for stacktrace)') - logger.info('Error retrieving git commit', e) - return "xxxxxxxx" + logger.warn('Could not calculate git commit details, using defaults (run with --info for stacktrace)') + logger.info('Error retrieving git commit details', e) + return [hash: "xxxxxxxx", date: "00.0"] } } diff --git a/gradle.properties b/gradle.properties index cc51c2b730f..265507cea43 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,3 @@ -version=24.2.0-SNAPSHOT - org.gradle.welcome=never # Set exports/opens flags required by Google Java Format and ErrorProne plugins. (JEP-396) org.gradle.jvmargs=-Xmx4g \ From 3db07568aef9c2ddc1f9b305368cb45b8e3ec66c Mon Sep 17 00:00:00 2001 From: Usman Saleem Date: Thu, 14 Mar 2024 12:24:06 +1000 Subject: [PATCH 02/22] Refactor PluginPrivacyController (#6725) fix parameter name to match overridden method Signed-off-by: Usman Saleem --- .../besu/ethereum/privacy/PluginPrivacyController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PluginPrivacyController.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PluginPrivacyController.java index 22cb76d4503..93c04c4954b 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PluginPrivacyController.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PluginPrivacyController.java @@ -124,7 +124,7 @@ public String deletePrivacyGroup(final String privacyGroupId, final String priva @Override public Optional findPrivacyGroupByGroupId( final String privacyGroupId, final String privacyUserId) { - verifyPrivacyGroupContainsPrivacyUserId(privacyUserId, privacyGroupId); + verifyPrivacyGroupContainsPrivacyUserId(privacyGroupId, privacyUserId); return Optional.of( new PrivacyGroup( @@ -155,7 +155,7 @@ public void verifyPrivacyGroupContainsPrivacyUserId( @Override public void verifyPrivacyGroupContainsPrivacyUserId( - final String privacyUserId, final String privacyGroupId) { - verifyPrivacyGroupContainsPrivacyUserId(privacyUserId, privacyGroupId, Optional.empty()); + final String privacyGroupId, final String privacyUserId) { + verifyPrivacyGroupContainsPrivacyUserId(privacyGroupId, privacyUserId, Optional.empty()); } } From 6dd3c840523bbc23f5ef97ab2e38e5a7a5a706c8 Mon Sep 17 00:00:00 2001 From: Simon Dudley Date: Thu, 14 Mar 2024 15:48:07 +1000 Subject: [PATCH 03/22] Move potentially spammy peer discovery warn log to debug (#6728) Signed-off-by: Simon Dudley --- .../p2p/discovery/VertxPeerDiscoveryAgent.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/VertxPeerDiscoveryAgent.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/VertxPeerDiscoveryAgent.java index ef098896a61..0c989021638 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/VertxPeerDiscoveryAgent.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/VertxPeerDiscoveryAgent.java @@ -220,12 +220,14 @@ protected void handleOutgoingPacketError( .addArgument(err) .log(); } else { - LOG.warn( - "Sending to peer {} failed, native error code {}, packet: {}, stacktrace: {}", - peer, - nativeErr.expectedErr(), - wrapBuffer(packet.encode()), - err); + LOG.atDebug() + .setMessage( + "Sending to peer {} failed, native error code {}, packet: {}, stacktrace: {}") + .addArgument(peer) + .addArgument(nativeErr.expectedErr()) + .addArgument(wrapBuffer(packet.encode())) + .addArgument(err) + .log(); } } else if (err instanceof SocketException && err.getMessage().contains("unreachable")) { LOG.atDebug() From 9bf542732b1bc85ff00d576a13cb5914517a78e0 Mon Sep 17 00:00:00 2001 From: MASDXI <31649128+MASDXI@users.noreply.github.com> Date: Thu, 14 Mar 2024 16:40:05 +0700 Subject: [PATCH 04/22] Change`txpool_beusPendingTransactions`:`numResults` from a required parameter to an optional parameter (#6708) Signed-off-by: MASDXI --- CHANGELOG.md | 1 + .../TxPoolBesuPendingTransactions.java | 8 +++-- .../TxPoolBesuPendingTransactionsTest.java | 32 ++++++++++++++++++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33d5d447852..6ef8654d9f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ ### Deprecations ### Additions and Improvements +- `txpool_besuPendingTransactions`change parameter `numResults` to optional parameter [#6708](https://github.com/hyperledger/besu/pull/6708) - Extend `Blockchain` service [#6592](https://github.com/hyperledger/besu/pull/6592) - Add bft-style blockperiodseconds transitions to Clique [#6596](https://github.com/hyperledger/besu/pull/6596) - Add createemptyblocks transitions to Clique [#6608](https://github.com/hyperledger/besu/pull/6608) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TxPoolBesuPendingTransactions.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TxPoolBesuPendingTransactions.java index 067daa7a11e..c1d224e1f14 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TxPoolBesuPendingTransactions.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TxPoolBesuPendingTransactions.java @@ -23,6 +23,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.transaction.pool.PendingTransactionFilter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.transaction.pool.PendingTransactionFilter.Filter; import org.hyperledger.besu.ethereum.core.Transaction; +import org.hyperledger.besu.ethereum.eth.transactions.PendingTransaction; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; import java.util.Collection; @@ -49,7 +50,10 @@ public String getName() { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { - final Integer limit = requestContext.getRequiredParameter(0, Integer.class); + final Collection pendingTransactions = + transactionPool.getPendingTransactions(); + final Integer limit = + requestContext.getOptionalParameter(0, Integer.class).orElse(pendingTransactions.size()); final List filters = requestContext .getOptionalParameter(1, PendingTransactionsParams.class) @@ -57,7 +61,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { .orElse(Collections.emptyList()); final Collection pendingTransactionsFiltered = - pendingTransactionFilter.reduce(transactionPool.getPendingTransactions(), filters, limit); + pendingTransactionFilter.reduce(pendingTransactions, filters, limit); return new JsonRpcSuccessResponse( requestContext.getRequest().getId(), diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TxPoolBesuPendingTransactionsTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TxPoolBesuPendingTransactionsTest.java index 738cae30970..1eef04fb93a 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TxPoolBesuPendingTransactionsTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TxPoolBesuPendingTransactionsTest.java @@ -70,7 +70,7 @@ public void shouldReturnPendingTransactions() { final JsonRpcRequestContext request = new JsonRpcRequestContext( new JsonRpcRequest( - JSON_RPC_VERSION, TXPOOL_PENDING_TRANSACTIONS_METHOD, new Object[] {100})); + JSON_RPC_VERSION, TXPOOL_PENDING_TRANSACTIONS_METHOD, new Object[] {})); final JsonRpcSuccessResponse actualResponse = (JsonRpcSuccessResponse) method.response(request); final Set result = @@ -120,6 +120,36 @@ public void shouldReturnPendingTransactionsWithLimit() { @Test public void shouldReturnPendingTransactionsWithFilter() { + final Map fromFilter = new HashMap<>(); + fromFilter.put( + "eq", listTrx.stream().findAny().get().getTransaction().getSender().toHexString()); + + final JsonRpcRequestContext request = + new JsonRpcRequestContext( + new JsonRpcRequest( + JSON_RPC_VERSION, + TXPOOL_PENDING_TRANSACTIONS_METHOD, + new Object[] { + null, + new PendingTransactionsParams( + fromFilter, + new HashMap<>(), + new HashMap<>(), + new HashMap<>(), + new HashMap<>(), + new HashMap<>()) + })); + + final JsonRpcSuccessResponse actualResponse = (JsonRpcSuccessResponse) method.response(request); + + final Set result = + (Set) actualResponse.getResult(); + assertThat(result.size()).isEqualTo(1); + } + + @Test + public void shouldReturnPendingTransactionsWithLimitAndFilter() { + final Map fromFilter = new HashMap<>(); fromFilter.put( "eq", listTrx.stream().findAny().get().getTransaction().getSender().toHexString()); From 2ce2a5546ebab668ea2eebce6fe137de6d79bde4 Mon Sep 17 00:00:00 2001 From: wellweek <148746285+wellweek@users.noreply.github.com> Date: Fri, 15 Mar 2024 08:17:44 +0800 Subject: [PATCH 05/22] chore: remove repetitive words (#6730) Signed-off-by: wellweek Co-authored-by: Sally MacFarlane --- CHANGELOG.md | 2 +- .../src/main/java/org/hyperledger/besu/datatypes/Address.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ef8654d9f8..7d95944227b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2508,7 +2508,7 @@ Early access features are available features that are not recommended for produc have unstable interfaces. * [Onchain privacy groups](https://besu.hyperledger.org/en/latest/Concepts/Privacy/Onchain-PrivacyGroups/) with add and remove members. - Not being able to to re-add a member to an onchain privacy group is a [known issue](https://github.com/hyperledger/besu/issues/455) + Not being able to re-add a member to an onchain privacy group is a [known issue](https://github.com/hyperledger/besu/issues/455) with the add and remove functionality. ### Known Issues diff --git a/datatypes/src/main/java/org/hyperledger/besu/datatypes/Address.java b/datatypes/src/main/java/org/hyperledger/besu/datatypes/Address.java index 5d1fad698f7..50b3cc07811 100644 --- a/datatypes/src/main/java/org/hyperledger/besu/datatypes/Address.java +++ b/datatypes/src/main/java/org/hyperledger/besu/datatypes/Address.java @@ -188,7 +188,7 @@ public static Address fromHexStringStrict(final String str) { final Bytes value = Bytes.fromHexString(str); checkArgument( value.size() == SIZE, - "An account address must be be %s bytes long, got %s", + "An account address must be %s bytes long, got %s", SIZE, value.size()); return new Address(value); From b239fb6099c9b743aea1a9ff6aac411860ebfb9c Mon Sep 17 00:00:00 2001 From: Matt Whitehead Date: Fri, 15 Mar 2024 01:22:13 +0000 Subject: [PATCH 06/22] Add comments to a couple of the the EthPeer methods to clarify their behaviour (#6733) Signed-off-by: Matthew Whitehead Co-authored-by: Sally MacFarlane --- .../besu/ethereum/eth/manager/EthPeer.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeer.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeer.java index 7ac7e98dd61..a7e2043c232 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeer.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeer.java @@ -401,6 +401,18 @@ private RequestManager.ResponseStream sendRequest( messageData); } + /** + * Determines the validity of a message received from a peer. A message is considered valid if + * either of the following conditions are met: 1) The message is a request type message (e.g. + * GET_BLOCK_HEADERS), or 2) The message is a response type message (e.g. BLOCK_HEADERS), the node + * has made at least 1 request for that type of message (i.e. it has sent at least 1 + * GET_BLOCK_HEADERS request), and it has at least 1 outstanding request of that type which it + * expects to receive a response for. + * + * @param message The message being validated + * @param protocolName The protocol type of the message + * @return true if the message is valid as per the above logic, otherwise false. + */ public boolean validateReceivedMessage(final EthMessage message, final String protocolName) { checkArgument(message.getPeer().equals(this), "Mismatched message sent to peer for dispatch"); return getRequestManager(protocolName, message.getData().getCode()) @@ -442,6 +454,16 @@ void dispatch(final EthMessage ethMessage) { dispatch(ethMessage, protocolName); } + /** + * Attempt to get a request manager for a received response-type message e.g. BLOCK_HEADERS. If + * the message is a request-type message e.g. GET_BLOCK_HEADERS no request manager will exist so + * Optional.empty() will be returned. + * + * @param protocolName the type of protocol the message is for + * @param code the message code + * @return a request manager for the received response messsage, or Optional.empty() if this is a + * request message + */ private Optional getRequestManager(final String protocolName, final int code) { if (requestManagers.containsKey(protocolName)) { final Map managers = requestManagers.get(protocolName); From 22daf346eef430a2b029a9bc833c1818452b31d9 Mon Sep 17 00:00:00 2001 From: Usman Saleem Date: Fri, 15 Mar 2024 13:55:39 +1000 Subject: [PATCH 07/22] Refactor StorageRangeDataRequest to fix nodes saved variable (#6726) * Refactor StorageRangeDataRequest -- Remove ununsed nbNodesSaved Signed-off-by: Usman Saleem * Fix import Signed-off-by: Usman Saleem * fix: Increment nodes saved variable Signed-off-by: Usman Saleem --------- Signed-off-by: Usman Saleem --- .../sync/snapsync/request/StorageRangeDataRequest.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/StorageRangeDataRequest.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/StorageRangeDataRequest.java index 751d8e3ac2d..0cb70b54635 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/StorageRangeDataRequest.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/StorageRangeDataRequest.java @@ -100,12 +100,9 @@ protected int doPersist( (location, hash, value) -> { applyForStrategy( updater, - onBonsai -> { - onBonsai.putAccountStorageTrieNode(accountHash, location, hash, value); - }, - onForest -> { - onForest.putAccountStorageTrieNode(hash, value); - }); + onBonsai -> onBonsai.putAccountStorageTrieNode(accountHash, location, hash, value), + onForest -> onForest.putAccountStorageTrieNode(hash, value)); + nbNodesSaved.incrementAndGet(); }; final AtomicReference flatDatabaseUpdater = From 9881e201df52dea8abe700e9dbffe64e0adc386d Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Fri, 15 Mar 2024 17:27:38 +1100 Subject: [PATCH 08/22] Fix permissioning plugin test (#6737) Signed-off-by: Gabriel-Trintinalia --- .../dsl/node/ThreadBesuNodeRunner.java | 17 +++++++----- .../plugins/PermissioningPluginTest.java | 27 ++++++++++--------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java index 896a615dee7..0f943ea0797 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 @@ -106,7 +106,8 @@ private BesuPluginContextImpl buildPluginContext( final TransactionPoolValidatorServiceImpl transactionPoolValidatorServiceImpl, final BlockchainServiceImpl blockchainServiceImpl, final RpcEndpointServiceImpl rpcEndpointServiceImpl, - final BesuConfiguration commonPluginConfiguration) { + final BesuConfiguration commonPluginConfiguration, + final PermissioningServiceImpl permissioningService) { final CommandLine commandLine = new CommandLine(CommandSpec.create()); final BesuPluginContextImpl besuPluginContext = new BesuPluginContextImpl(); besuPluginContext.addService(StorageService.class, storageService); @@ -137,7 +138,7 @@ private BesuPluginContextImpl buildPluginContext( } besuPluginContext.addService(BesuConfiguration.class, commonPluginConfiguration); - besuPluginContext.addService(PermissioningService.class, new PermissioningServiceImpl()); + besuPluginContext.addService(PermissioningService.class, permissioningService); besuPluginContext.addService(PrivacyPluginService.class, new PrivacyPluginServiceImpl()); besuPluginContext.registerPlugins(pluginsPath); @@ -172,6 +173,8 @@ public void startNode(final BesuNode node) { final RpcEndpointServiceImpl rpcEndpointServiceImpl = new RpcEndpointServiceImpl(); final Path dataDir = node.homeDirectory(); final BesuConfigurationImpl commonPluginConfiguration = new BesuConfigurationImpl(); + final PermissioningServiceImpl permissioningService = new PermissioningServiceImpl(); + final var miningParameters = ImmutableMiningParameters.builder() .from(node.getMiningParameters()) @@ -195,7 +198,8 @@ public void startNode(final BesuNode node) { transactionPoolValidatorServiceImpl, blockchainServiceImpl, rpcEndpointServiceImpl, - commonPluginConfiguration)); + commonPluginConfiguration, + permissioningService)); GlobalOpenTelemetry.resetForTest(); final ObservableMetricsSystem metricsSystem = @@ -283,7 +287,7 @@ public void startNode(final BesuNode node) { .jsonRpcIpcConfiguration(node.jsonRpcIpcConfiguration()) .dataDir(node.homeDirectory()) .metricsSystem(metricsSystem) - .permissioningService(new PermissioningServiceImpl()) + .permissioningService(permissioningService) .metricsConfiguration(node.getMetricsConfiguration()) .p2pEnabled(node.isP2pEnabled()) .p2pTLSConfiguration(node.getTLSConfiguration()) @@ -292,15 +296,14 @@ public void startNode(final BesuNode node) { node.getStaticNodes().stream() .map(EnodeURLImpl::fromString) .collect(Collectors.toList())) - .besuPluginContext(new BesuPluginContextImpl()) + .besuPluginContext(besuPluginContext) .autoLogBloomCaching(false) .storageProvider(storageProvider) .rpcEndpointService(rpcEndpointServiceImpl); node.engineRpcConfiguration().ifPresent(runnerBuilder::engineJsonRpcConfiguration); - final Runner runner = runnerBuilder.build(); - besuPluginContext.beforeExternalServices(); + final Runner runner = runnerBuilder.build(); runner.startExternalServices(); 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 146110237da..60047c16579 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 @@ -37,22 +37,13 @@ public class PermissioningPluginTest extends AcceptanceTestBaseJunit5 { @BeforeEach public void setUp() throws Exception { - final BesuNodeConfigurationBuilder builder = - new BesuNodeConfigurationBuilder() - .miningEnabled(false) - .plugins(List.of("testPlugins")) - .extraCLIOptions(List.of("--plugin-permissioning-test-enabled=true")) - .jsonRpcEnabled() - .jsonRpcTxPool() - .jsonRpcAdmin(); + minerNode = besu.create(createNodeBuilder().name("miner").build()); - minerNode = besu.create(builder.name("miner").build()); + aliceNode = besu.create(createNodeBuilder().name("alice").keyFilePath("key").build()); - aliceNode = besu.create(builder.name("alice").keyFilePath("key").build()); + bobNode = besu.create(createNodeBuilder().name("bob").keyFilePath("key1").build()); - bobNode = besu.create(builder.name("bob").keyFilePath("key1").build()); - - charlieNode = besu.create(builder.name("charlie").keyFilePath("key2").build()); + charlieNode = besu.create(createNodeBuilder().name("charlie").keyFilePath("key2").build()); cluster.start(minerNode, charlieNode); @@ -63,6 +54,16 @@ public void setUp() throws Exception { bobNode.awaitPeerDiscovery(net.awaitPeerCount(2)); } + private BesuNodeConfigurationBuilder createNodeBuilder() { + return new BesuNodeConfigurationBuilder() + .miningEnabled(false) + .plugins(List.of("testPlugins")) + .extraCLIOptions(List.of("--plugin-permissioning-test-enabled=true")) + .jsonRpcEnabled() + .jsonRpcTxPool() + .jsonRpcAdmin(); + } + @Test public void blockedConnectionNodeCanOnlyConnectToTransactionNode() { minerNode.verify(admin.hasPeer(aliceNode)); From de0704afbfd36c886d01290847d6a936a3a3c119 Mon Sep 17 00:00:00 2001 From: Justin Florentine Date: Fri, 15 Mar 2024 15:59:35 -0400 Subject: [PATCH 09/22] PR Annotations removed (#6735) * pull_req instead of target * updates template to put description first * compensate for changes to versioning on interim builds --------- Signed-off-by: Justin Florentine Co-authored-by: Sally MacFarlane --- .github/pull_request_template.md | 13 ++++++------ .github/workflows/acceptance-tests.yml | 8 +------- .github/workflows/develop.yml | 22 ++++++-------------- .github/workflows/integration-tests.yml | 8 +------- .github/workflows/pre-review.yml | 27 +++++++++++++++++++------ .github/workflows/reference-tests.yml | 8 +------- 6 files changed, 37 insertions(+), 49 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index f78582311ce..6dd62ca8b86 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,3 +1,10 @@ +## PR description + +## Fixed Issue(s) + + + + ### Thanks for sending a pull request! Have you done the following? - [ ] Checked out our [contribution guidelines](https://github.com/hyperledger/besu/blob/main/CONTRIBUTING.md)? @@ -12,9 +19,3 @@ - [ ] locally run all integration tests via: `./gradlew integrationTest` - [ ] locally run all reference tests via: `./gradlew ethereum:referenceTests:referenceTests` - -## PR description - -## Fixed Issue(s) - - \ No newline at end of file diff --git a/.github/workflows/acceptance-tests.yml b/.github/workflows/acceptance-tests.yml index bd89270942e..0d241424944 100644 --- a/.github/workflows/acceptance-tests.yml +++ b/.github/workflows/acceptance-tests.yml @@ -1,7 +1,7 @@ name: acceptance-tests on: workflow_dispatch: - pull_request_target: + pull_request: branches: - main - release-* @@ -70,12 +70,6 @@ jobs: with: name: acceptance-node-${{matrix.runner_index}}-test-results path: 'acceptance-tests/tests/build/test-results/**/TEST-*.xml' - - name: Publish Test Report - uses: mikepenz/action-junit-report@5f47764eec0e1c1f19f40c8e60a5ba47e47015c5 - if: (success() || failure()) # always run even if the build step fails - with: - report_paths: 'acceptance-tests/tests/build/test-results/**/TEST-*.xml' - annotate_only: true accepttests-passed: name: "accepttests-passed" runs-on: ubuntu-22.04 diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml index fbafc9e4f23..0e0cd11c78c 100644 --- a/.github/workflows/develop.yml +++ b/.github/workflows/develop.yml @@ -28,24 +28,14 @@ jobs: - name: assemble release run: ./gradlew assemble - - name: upload tarball - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 - with: - path: 'build/distributions/besu*.tar.gz' - name: besu-develop.tar.gz - compression-level: 0 - - name: hashes - id: hashes + - name: rename and hash files run: | cd build/distributions + mv besu*.zip besu-develop.zip + mv besu*.tar.gz besu-develop.tar.gz echo "zipSha=$(shasum -a 256 besu*.zip)" >> $GITHUB_OUTPUT echo "tarSha=$(shasum -a 256 besu*.tar.gz)" >> $GITHUB_OUTPUT - - name: upload zipfile - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 - with: - path: 'build/distributions/besu*.zip' - name: besu-develop.zip - compression-level: 0 + cd ../.. - name: Upload Release assets uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 with: @@ -55,8 +45,8 @@ jobs: fail_on_unmatched_files: true append_body: false files: | - build/distributions/besu*.tar.gz - build/distributions/besu*.zip + build/distributions/besu-develop.tar.gz + build/distributions/besu-develop.zip body: | This is an automated, bleeding edge build from the tip of ${{ github.ref_name }}. No promises. YOLO. diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 944422cbdf8..8a60d09017d 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -1,7 +1,7 @@ name: integration-tests on: workflow_dispatch: - pull_request_target: + pull_request: branches: - main - release-* @@ -36,11 +36,5 @@ jobs: cache-disabled: true - name: run integration tests run: ./gradlew integrationTest compileJmh - - name: Publish Test Report - uses: mikepenz/action-junit-report@5f47764eec0e1c1f19f40c8e60a5ba47e47015c5 - if: (success() || failure()) - with: - report_paths: '**/build/test-results/integrationTest/TEST-*.xml' - annotate_only: true diff --git a/.github/workflows/pre-review.yml b/.github/workflows/pre-review.yml index b3adc7c42cd..a7b2faf6e81 100644 --- a/.github/workflows/pre-review.yml +++ b/.github/workflows/pre-review.yml @@ -1,7 +1,7 @@ name: pre-review on: - pull_request_target: + pull_request: branches: - main - release-* @@ -91,6 +91,22 @@ jobs: - "ethereum:api:testRemainder" - "ethereum:eth:test" - "ethereum:core:test" + #includes will need exact strings from gradle args above + include: + - gradle_args: "test -x besu:test -x consensus:test -x crypto:test -x ethereum:eth:test -x ethereum:api:test -x ethereum:core:test" + filename: "everythingElse" + - gradle_args: "besu:test consensus:test crypto:test" + filename: "consensusCrypto" + - gradle_args: "ethereum:api:testBonsai" + filename: "apiBonsai" + - gradle_args: "ethereum:api:testRemainder" + filename: "apiForest" + - gradle_args: "ethereum:api:testRemainder" + filename: "apiRemainder" + - gradle_args: "ethereum:eth:test" + filename: "eth" + - gradle_args: "ethereum:core:test" + filename: "core" steps: - name: Checkout Repo uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 @@ -108,12 +124,11 @@ jobs: - name: run unit tests id: unitTest run: ./gradlew $GRADLEW_UNIT_TEST_ARGS - - name: Publish Test Report - uses: mikepenz/action-junit-report@5f47764eec0e1c1f19f40c8e60a5ba47e47015c5 - if: success() || failure() # always run even if the build step fails + - name: Upload Acceptance Test Results + uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 with: - report_paths: '**/test-results/**/TEST-*.xml' - annotate_only: true + name: unit-${{matrix.filename}}-test-results + path: '**/test-results/**/TEST-*.xml' unittests-passed: name: "unittests-passed" runs-on: ubuntu-22.04 diff --git a/.github/workflows/reference-tests.yml b/.github/workflows/reference-tests.yml index f9dd87c4589..c83022526e4 100644 --- a/.github/workflows/reference-tests.yml +++ b/.github/workflows/reference-tests.yml @@ -1,7 +1,7 @@ name: reference-tests on: workflow_dispatch: - pull_request_target: + pull_request: branches: - main - release-* @@ -62,12 +62,6 @@ jobs: with: name: reference-test-node-${{matrix.runner_index}}-results path: '**/build/test-results/referenceTests/TEST-*.xml' - - name: Publish Test Report - uses: mikepenz/action-junit-report@5f47764eec0e1c1f19f40c8e60a5ba47e47015c5 - if: success() || failure() # always run even if the build step fails - with: - report_paths: '**/build/test-results/referenceTests/TEST-*.xml' - annotate_only: true reftests-passed: name: "reftests-passed" runs-on: ubuntu-22.04 From feb17641998214285b8b4ad6c9773ff6748930d8 Mon Sep 17 00:00:00 2001 From: Suraneti Date: Sat, 16 Mar 2024 07:42:53 +0700 Subject: [PATCH 10/22] feat: add fixed basefee options (#6562) * feat: add fixed basefee options Signed-off-by: Suraneti Rodsuwan * Refactor zero base fee to be extension of fixed base fee Signed-off-by: Matthew Whitehead * feat: use MiningParameters to fixed base fee Signed-off-by: Suraneti Rodsuwan * feat: add mining parameters arg on protocol schedule builder * feat: add miningParameters on gray glacier and prague Signed-off-by: Suraneti Rodsuwan * feat: add miningParameters on gray glacier and prague Signed-off-by: Suraneti Rodsuwan * feat: add miningParameters on paris,shanghai,future,experimental Signed-off-by: Suraneti Rodsuwan --------- Signed-off-by: Suraneti Rodsuwan Signed-off-by: Matthew Whitehead Signed-off-by: Suraneti Co-authored-by: Matthew Whitehead Co-authored-by: Sally MacFarlane --- .../CliqueBesuControllerBuilder.java | 1 + .../controller/IbftBesuControllerBuilder.java | 1 + .../MainnetBesuControllerBuilder.java | 1 + .../MergeBesuControllerBuilder.java | 6 +- .../controller/QbftBesuControllerBuilder.java | 1 + .../besu/ForkIdsNetworkConfigTest.java | 7 +- .../besu/config/GenesisConfigOptions.java | 7 + .../besu/config/JsonGenesisConfigOptions.java | 10 ++ .../besu/config/StubGenesisConfigOptions.java | 17 ++ .../besu/config/GenesisConfigOptionsTest.java | 21 +++ .../clique/CliqueProtocolSchedule.java | 7 + .../clique/CliqueProtocolScheduleTest.java | 6 + .../blockcreation/CliqueBlockCreatorTest.java | 1 + .../CliqueMinerExecutorTest.java | 1 + .../bft/BaseBftProtocolScheduleBuilder.java | 4 + .../CombinedProtocolScheduleFactoryTest.java | 2 + .../BaseBftProtocolScheduleBuilderTest.java | 2 + .../ibft/support/TestContextBuilder.java | 1 + .../ibft/IbftProtocolScheduleBuilder.java | 7 + .../ibft/IbftProtocolScheduleTest.java | 2 + .../blockcreation/BftBlockCreatorTest.java | 1 + .../IbftBlockHeightManagerTest.java | 2 + .../merge/MergeProtocolSchedule.java | 13 +- .../merge/TransitionProtocolSchedule.java | 11 +- .../merge/MergeProtocolScheduleTest.java | 18 ++- .../MergeGenesisConfigHelper.java | 6 +- .../qbft/support/TestContextBuilder.java | 12 ++ .../qbft/test/ValidatorContractTest.java | 51 ++++++ .../qbft/QbftProtocolScheduleBuilder.java | 10 ++ .../qbft/QbftProtocolScheduleTest.java | 2 + .../QbftBlockHeightManagerTest.java | 2 + .../api/jsonrpc/BlockchainImporter.java | 5 +- .../JsonRpcHttpServiceHostAllowlistTest.java | 1 + .../jsonrpc/JsonRpcHttpServiceLoginTest.java | 3 +- .../jsonrpc/JsonRpcHttpServiceTestBase.java | 1 + .../JsonRpcHttpServiceTlsClientAuthTest.java | 1 + ...RpcHttpServiceTlsMisconfigurationTest.java | 1 + .../jsonrpc/JsonRpcHttpServiceTlsTest.java | 1 + .../websocket/WebSocketServiceLoginTest.java | 5 +- .../AbstractBlockCreatorTest.java | 1 + .../AbstractBlockTransactionSelectorTest.java | 1 + ...FeeMarketBlockTransactionSelectorTest.java | 2 + ...FeeMarketBlockTransactionSelectorTest.java | 1 + .../blockcreation/PoWBlockCreatorTest.java | 4 + .../FixedDifficultyProtocolSchedule.java | 14 +- .../mainnet/MainnetProtocolSchedule.java | 36 ++++- .../mainnet/MainnetProtocolSpecFactory.java | 33 ++-- .../mainnet/MainnetProtocolSpecs.java | 62 ++++--- .../mainnet/ProtocolScheduleBuilder.java | 11 +- .../ethereum/mainnet/feemarket/FeeMarket.java | 4 + .../mainnet/feemarket/FixedBaseFeeMarket.java | 41 +++++ .../mainnet/feemarket/LondonFeeMarket.java | 2 +- .../mainnet/feemarket/ZeroBaseFeeMarket.java | 16 +- .../ethereum/core/BlockchainSetupUtil.java | 5 +- .../core/ExecutionContextTestFixture.java | 1 + .../core/ProtocolScheduleFixture.java | 1 + .../fixed/FixedProtocolScheduleTest.java | 2 + .../mainnet/DefaultProtocolScheduleTest.java | 2 + .../mainnet/MainnetProtocolScheduleTest.java | 5 + .../mainnet/ProtocolScheduleBuilderTest.java | 3 + .../feemarket/FixedBaseFeeMarketTest.java | 152 ++++++++++++++++++ ...BlockHeaderGasPriceValidationRuleTest.java | 25 +++ ...yValidationRuleFixedBaseFeeMarketTest.java | 75 +++++++++ .../trie/bonsai/AbstractIsolationTests.java | 4 +- .../eth/messages/BlockBodiesMessageTest.java | 2 + .../eth/messages/BlockHeadersMessageTest.java | 2 + .../eth/sync/ChainHeadTrackerTest.java | 2 + .../backwardsync/BackwardSyncContextTest.java | 4 +- .../backwardsync/BackwardSyncStepTest.java | 4 +- .../backwardsync/ForwardSyncStepTest.java | 4 +- .../AbstractTransactionPoolTest.java | 2 + .../ethereum/eth/transactions/TestNode.java | 1 + .../TransactionPoolFactoryTest.java | 1 + .../evmtool/MainnetGenesisFileModule.java | 4 +- .../ReferenceTestProtocolSchedules.java | 2 + .../mainnet/DifficultyCalculatorTests.java | 29 ++-- .../ethereum/retesteth/RetestethContext.java | 2 +- 77 files changed, 726 insertions(+), 87 deletions(-) create mode 100644 ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/feemarket/FixedBaseFeeMarket.java create mode 100644 ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/feemarket/FixedBaseFeeMarketTest.java create mode 100644 ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/GasLimitElasticityValidationRuleFixedBaseFeeMarketTest.java 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 88a675d4f10..7b13a211a70 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java @@ -130,6 +130,7 @@ protected ProtocolSchedule createProtocolSchedule() { privacyParameters, isRevertReasonEnabled, evmConfiguration, + miningParameters, badBlockManager); } 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 c4a412e4dc8..6ab517efd6c 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/IbftBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/IbftBesuControllerBuilder.java @@ -286,6 +286,7 @@ protected ProtocolSchedule createProtocolSchedule() { isRevertReasonEnabled, bftExtraDataCodec().get(), evmConfiguration, + miningParameters, badBlockManager); } 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 fc258583092..4c2e0ee47a3 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/MainnetBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/MainnetBesuControllerBuilder.java @@ -95,6 +95,7 @@ protected ProtocolSchedule createProtocolSchedule() { privacyParameters, isRevertReasonEnabled, evmConfiguration, + miningParameters, badBlockManager); } 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 62bce6ac69b..623aa2918f5 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/MergeBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/MergeBesuControllerBuilder.java @@ -173,7 +173,11 @@ protected MiningCoordinator createTransitionMiningCoordinator( @Override protected ProtocolSchedule createProtocolSchedule() { return MergeProtocolSchedule.create( - configOptionsSupplier.get(), privacyParameters, isRevertReasonEnabled, badBlockManager); + configOptionsSupplier.get(), + privacyParameters, + isRevertReasonEnabled, + miningParameters, + badBlockManager); } @Override diff --git a/besu/src/main/java/org/hyperledger/besu/controller/QbftBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/QbftBesuControllerBuilder.java index a622001ef89..747949aac12 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/QbftBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/QbftBesuControllerBuilder.java @@ -326,6 +326,7 @@ protected ProtocolSchedule createProtocolSchedule() { isRevertReasonEnabled, bftExtraDataCodec().get(), evmConfiguration, + miningParameters, badBlockManager); } diff --git a/besu/src/test/java/org/hyperledger/besu/ForkIdsNetworkConfigTest.java b/besu/src/test/java/org/hyperledger/besu/ForkIdsNetworkConfigTest.java index ea82011bb53..bd396228ade 100644 --- a/besu/src/test/java/org/hyperledger/besu/ForkIdsNetworkConfigTest.java +++ b/besu/src/test/java/org/hyperledger/besu/ForkIdsNetworkConfigTest.java @@ -33,6 +33,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.forkid.ForkId; import org.hyperledger.besu.ethereum.forkid.ForkIdManager; import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule; @@ -188,11 +189,13 @@ private static MilestoneStreamingTransitionProtocolSchedule createSchedule( MilestoneStreamingProtocolSchedule preMergeProtocolSchedule = new MilestoneStreamingProtocolSchedule( (DefaultProtocolSchedule) - MainnetProtocolSchedule.fromConfig(configOptions, new BadBlockManager())); + MainnetProtocolSchedule.fromConfig( + configOptions, MiningParameters.MINING_DISABLED, new BadBlockManager())); MilestoneStreamingProtocolSchedule postMergeProtocolSchedule = new MilestoneStreamingProtocolSchedule( (DefaultProtocolSchedule) - MergeProtocolSchedule.create(configOptions, false, new BadBlockManager())); + MergeProtocolSchedule.create( + configOptions, false, MiningParameters.MINING_DISABLED, new BadBlockManager())); final MilestoneStreamingTransitionProtocolSchedule schedule = new MilestoneStreamingTransitionProtocolSchedule( preMergeProtocolSchedule, postMergeProtocolSchedule); diff --git a/config/src/main/java/org/hyperledger/besu/config/GenesisConfigOptions.java b/config/src/main/java/org/hyperledger/besu/config/GenesisConfigOptions.java index e3c935eca69..1645688f098 100644 --- a/config/src/main/java/org/hyperledger/besu/config/GenesisConfigOptions.java +++ b/config/src/main/java/org/hyperledger/besu/config/GenesisConfigOptions.java @@ -504,6 +504,13 @@ default boolean isConsensusMigration() { */ boolean isZeroBaseFee(); + /** + * Force a Base Fee as Gas Price network to used with London/EIP-1559. + * + * @return true, if you want the next block to use the base fee as gas price. + */ + boolean isFixedBaseFee(); + /** * The deposit contract address that should be in the logger field in Receipt of Deposit * transaction diff --git a/config/src/main/java/org/hyperledger/besu/config/JsonGenesisConfigOptions.java b/config/src/main/java/org/hyperledger/besu/config/JsonGenesisConfigOptions.java index d2ce8401fc6..5c1a2037017 100644 --- a/config/src/main/java/org/hyperledger/besu/config/JsonGenesisConfigOptions.java +++ b/config/src/main/java/org/hyperledger/besu/config/JsonGenesisConfigOptions.java @@ -47,6 +47,7 @@ public class JsonGenesisConfigOptions implements GenesisConfigOptions { private static final String DISCOVERY_CONFIG_KEY = "discovery"; private static final String CHECKPOINT_CONFIG_KEY = "checkpoint"; private static final String ZERO_BASE_FEE_KEY = "zerobasefee"; + private static final String FIXED_BASE_FEE_KEY = "fixedbasefee"; private static final String DEPOSIT_CONTRACT_ADDRESS_KEY = "depositcontractaddress"; private final ObjectNode configRoot; @@ -421,6 +422,11 @@ public boolean isZeroBaseFee() { return getOptionalBoolean(ZERO_BASE_FEE_KEY).orElse(false); } + @Override + public boolean isFixedBaseFee() { + return getOptionalBoolean(FIXED_BASE_FEE_KEY).orElse(false); + } + @Override public Optional
getDepositContractAddress() { Optional inputAddress = JsonUtil.getString(configRoot, DEPOSIT_CONTRACT_ADDRESS_KEY); @@ -492,6 +498,10 @@ public Map asMap() { builder.put("zeroBaseFee", true); } + if (isFixedBaseFee()) { + builder.put("fixedBaseFee", true); + } + return builder.build(); } diff --git a/config/src/main/java/org/hyperledger/besu/config/StubGenesisConfigOptions.java b/config/src/main/java/org/hyperledger/besu/config/StubGenesisConfigOptions.java index d3705487cd4..3b8562533bb 100644 --- a/config/src/main/java/org/hyperledger/besu/config/StubGenesisConfigOptions.java +++ b/config/src/main/java/org/hyperledger/besu/config/StubGenesisConfigOptions.java @@ -78,6 +78,7 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions, Cloneable private TransitionsConfigOptions transitions = TransitionsConfigOptions.DEFAULT; private static final DiscoveryOptions DISCOVERY_OPTIONS = DiscoveryOptions.DEFAULT; private boolean zeroBaseFee = false; + private boolean fixedBaseFee = false; @Override public StubGenesisConfigOptions clone() { @@ -424,6 +425,11 @@ public boolean isZeroBaseFee() { return zeroBaseFee; } + @Override + public boolean isFixedBaseFee() { + return fixedBaseFee; + } + @Override public List getForkBlockNumbers() { return Collections.emptyList(); @@ -704,6 +710,17 @@ public StubGenesisConfigOptions zeroBaseFee(final boolean zeroBaseFee) { return this; } + /** + * Fixed base fee per gas stub genesis config options. + * + * @param fixedBaseFee the zero base fee override + * @return the stub genesis config options + */ + public StubGenesisConfigOptions fixedBaseFee(final boolean fixedBaseFee) { + this.fixedBaseFee = fixedBaseFee; + return this; + } + /** * Classic fork block stub genesis config options. * diff --git a/config/src/test/java/org/hyperledger/besu/config/GenesisConfigOptionsTest.java b/config/src/test/java/org/hyperledger/besu/config/GenesisConfigOptionsTest.java index 03007233592..bb4a8f94a96 100644 --- a/config/src/test/java/org/hyperledger/besu/config/GenesisConfigOptionsTest.java +++ b/config/src/test/java/org/hyperledger/besu/config/GenesisConfigOptionsTest.java @@ -295,6 +295,27 @@ void asMapIncludesZeroBaseFee() { assertThat(config.asMap()).containsOnlyKeys("zeroBaseFee").containsValue(true); } + @Test + void isFixedBaseFeeShouldDefaultToFalse() { + final GenesisConfigOptions config = GenesisConfigFile.fromConfig("{}").getConfigOptions(); + + assertThat(config.isFixedBaseFee()).isFalse(); + } + + @Test + void isFixedBaseFeeParsedCorrectly() { + final GenesisConfigOptions config = fromConfigOptions(Map.of("fixedbasefee", true)); + + assertThat(config.isFixedBaseFee()).isTrue(); + } + + @Test + void asMapIncludesFixedBaseFee() { + final GenesisConfigOptions config = fromConfigOptions(Map.of("fixedbasefee", true)); + + assertThat(config.asMap()).containsOnlyKeys("fixedBaseFee").containsValue(true); + } + @Test void shouldGetDepositContractAddress() { final GenesisConfigOptions config = 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 5f1351c40a9..18bd44f440d 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,6 +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.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator; @@ -58,6 +59,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 badBlockManager the cache to use to keep invalid blocks * @return the protocol schedule */ @@ -68,6 +70,7 @@ public static ProtocolSchedule create( final PrivacyParameters privacyParameters, final boolean isRevertReasonEnabled, final EvmConfiguration evmConfiguration, + final MiningParameters miningParameters, final BadBlockManager badBlockManager) { final CliqueConfigOptions cliqueConfig = config.getCliqueConfigOptions(); @@ -103,6 +106,7 @@ public static ProtocolSchedule create( privacyParameters, isRevertReasonEnabled, evmConfiguration, + miningParameters, badBlockManager) .createProtocolSchedule(); } @@ -115,6 +119,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 badBlockManager the cache to use to keep invalid blocks * @return the protocol schedule */ @@ -125,6 +130,7 @@ public static ProtocolSchedule create( final NodeKey nodeKey, final boolean isRevertReasonEnabled, final EvmConfiguration evmConfiguration, + final MiningParameters miningParameters, final BadBlockManager badBlockManager) { return create( config, @@ -133,6 +139,7 @@ public static ProtocolSchedule create( PrivacyParameters.DEFAULT, isRevertReasonEnabled, evmConfiguration, + miningParameters, badBlockManager); } 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 a6eefb94115..30a3967da9c 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,6 +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.mainnet.HeaderValidationMode; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; @@ -66,6 +67,7 @@ public void protocolSpecsAreCreatedAtBlockDefinedInJson() { NODE_KEY, false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()); final ProtocolSpec homesteadSpec = protocolSchedule.getByBlockHeader(blockHeader(1)); @@ -89,6 +91,7 @@ public void parametersAlignWithMainnetWithAdjustments() { NODE_KEY, false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()) .getByBlockHeader(blockHeader(0)); @@ -112,6 +115,7 @@ public void zeroEpochLengthThrowsException() { NODE_KEY, false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager())) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Epoch length in config must be greater than zero"); @@ -131,6 +135,7 @@ public void negativeEpochLengthThrowsException() { NODE_KEY, false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager())) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Epoch length in config must be greater than zero"); @@ -154,6 +159,7 @@ public void shouldValidateBaseFeeMarketTransition() { NODE_KEY, false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()); BlockHeader emptyFrontierParent = 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 b6edc930477..7dcbfa34bac 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 @@ -106,6 +106,7 @@ public void setup() { proposerNodeKey, false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()); final Address otherAddress = Util.publicKeyToAddress(otherKeyPair.getPublicKey()); 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 185674aa90c..9ff2b713ce8 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 @@ -104,6 +104,7 @@ public void setup() { proposerNodeKey, false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()); cliqueEthContext = mock(EthContext.class, RETURNS_DEEP_STUBS); blockHeaderBuilder = new BlockHeaderTestFixture(); diff --git a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilder.java b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilder.java index 2a334f8b030..2578a805686 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,6 +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.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator; import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule; @@ -52,6 +53,7 @@ public abstract class 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 badBlockManager the cache to use to keep invalid blocks * @return the protocol schedule */ @@ -62,6 +64,7 @@ public BftProtocolSchedule createProtocolSchedule( final boolean isRevertReasonEnabled, final BftExtraDataCodec bftExtraDataCodec, final EvmConfiguration evmConfiguration, + final MiningParameters miningParameters, final BadBlockManager badBlockManager) { final Map> specMap = new HashMap<>(); @@ -83,6 +86,7 @@ public BftProtocolSchedule createProtocolSchedule( privacyParameters, isRevertReasonEnabled, evmConfiguration, + miningParameters, badBlockManager) .createProtocolSchedule(); return new BftProtocolSchedule((DefaultProtocolSchedule) protocolSchedule); 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 f310912c595..1d1d21e33f7 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,6 +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.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; @@ -175,6 +176,7 @@ private BftProtocolSchedule createProtocolSchedule( new PrivacyParameters(), false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()); return new BftProtocolSchedule( 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 9734468e06f..9b05bd7a365 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,6 +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.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator; import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule; @@ -243,6 +244,7 @@ protected BlockHeaderValidator.Builder createBlockHeaderRuleset( false, bftExtraDataCodec, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()); } 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 cd34570827f..55a2f3551a1 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 @@ -332,6 +332,7 @@ private static ControllerAndState createControllerAndFinalState( forksSchedule, IBFT_EXTRA_DATA_ENCODER, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()); ///////////////////////////////////////////////////////////////////////////////////// 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 bc4e6982ed2..4f2e4da4341 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,6 +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.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator; import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket; @@ -41,6 +42,7 @@ public class IbftProtocolScheduleBuilder 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 badBlockManager the cache to use to keep invalid blocks * @return the protocol schedule */ @@ -51,6 +53,7 @@ public static BftProtocolSchedule create( final boolean isRevertReasonEnabled, final BftExtraDataCodec bftExtraDataCodec, final EvmConfiguration evmConfiguration, + final MiningParameters miningParameters, final BadBlockManager badBlockManager) { return new IbftProtocolScheduleBuilder() .createProtocolSchedule( @@ -60,6 +63,7 @@ public static BftProtocolSchedule create( isRevertReasonEnabled, bftExtraDataCodec, evmConfiguration, + miningParameters, badBlockManager); } @@ -70,6 +74,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 badBlockManager the cache to use to keep invalid blocks * @return the protocol schedule */ @@ -78,6 +83,7 @@ public static BftProtocolSchedule create( final ForksSchedule forksSchedule, final BftExtraDataCodec bftExtraDataCodec, final EvmConfiguration evmConfiguration, + final MiningParameters miningParameters, final BadBlockManager badBlockManager) { return create( config, @@ -86,6 +92,7 @@ public static BftProtocolSchedule create( false, bftExtraDataCodec, evmConfiguration, + miningParameters, badBlockManager); } 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 de8ead1d23e..5ff7d2b5338 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 @@ -40,6 +40,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.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode; @@ -101,6 +102,7 @@ private BftProtocolSchedule createProtocolSchedule( false, bftExtraDataCodec, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()); } 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 621340d8299..25c5c1d10b8 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 @@ -120,6 +120,7 @@ public BlockHeaderValidator.Builder createBlockHeaderRuleset( false, bftExtraDataEncoder, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()); final ProtocolContext protContext = new ProtocolContext( 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 2521737f81c..feb5bbc97d7 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 @@ -69,6 +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.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule; @@ -179,6 +180,7 @@ public void setup() { new PrivacyParameters(), false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()); ProtocolSchedule protocolSchedule = 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 506dc217a35..ab1c940a8ef 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,6 +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.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; @@ -43,14 +44,21 @@ public class MergeProtocolSchedule { * * @param config the config * @param isRevertReasonEnabled the is revert reason enabled + * @param miningParameters the mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @return the protocol schedule */ public static ProtocolSchedule create( final GenesisConfigOptions config, final boolean isRevertReasonEnabled, + final MiningParameters miningParameters, final BadBlockManager badBlockManager) { - return create(config, PrivacyParameters.DEFAULT, isRevertReasonEnabled, badBlockManager); + return create( + config, + PrivacyParameters.DEFAULT, + isRevertReasonEnabled, + miningParameters, + badBlockManager); } /** @@ -59,6 +67,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 badBlockManager the cache to use to keep invalid blocks * @return the protocol schedule */ @@ -66,6 +75,7 @@ public static ProtocolSchedule create( final GenesisConfigOptions config, final PrivacyParameters privacyParameters, final boolean isRevertReasonEnabled, + final MiningParameters miningParameters, final BadBlockManager badBlockManager) { Map> postMergeModifications = @@ -84,6 +94,7 @@ public static ProtocolSchedule create( privacyParameters, isRevertReasonEnabled, EvmConfiguration.DEFAULT, + miningParameters, badBlockManager) .createProtocolSchedule(); } 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 bae3e518d9b..f15f0c1e9f2 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 @@ -19,6 +19,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.PermissionTransactionFilter; import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader; import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule; @@ -62,15 +63,19 @@ public TransitionProtocolSchedule( * * @param genesisConfigOptions {@link GenesisConfigOptions} containing the config options for the * milestone starting points + * @param miningParameters the mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @return an initialised TransitionProtocolSchedule using post-merge defaults */ public static TransitionProtocolSchedule fromConfig( - final GenesisConfigOptions genesisConfigOptions, final BadBlockManager badBlockManager) { + final GenesisConfigOptions genesisConfigOptions, + final MiningParameters miningParameters, + final BadBlockManager badBlockManager) { ProtocolSchedule preMergeProtocolSchedule = - MainnetProtocolSchedule.fromConfig(genesisConfigOptions, badBlockManager); + MainnetProtocolSchedule.fromConfig(genesisConfigOptions, miningParameters, badBlockManager); ProtocolSchedule postMergeProtocolSchedule = - MergeProtocolSchedule.create(genesisConfigOptions, false, badBlockManager); + MergeProtocolSchedule.create( + genesisConfigOptions, false, miningParameters, badBlockManager); return new TransitionProtocolSchedule( preMergeProtocolSchedule, postMergeProtocolSchedule, PostMergeContext.get()); } 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 5f6c38a34f5..a4a07054d34 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,6 +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.mainnet.MainnetBlockProcessor; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; @@ -46,7 +47,8 @@ public void protocolSpecsAreCreatedAtBlockDefinedInJson() { final GenesisConfigOptions config = GenesisConfigFile.fromConfig(jsonInput).getConfigOptions(); final ProtocolSchedule protocolSchedule = - MergeProtocolSchedule.create(config, false, new BadBlockManager()); + MergeProtocolSchedule.create( + config, false, MiningParameters.MINING_DISABLED, new BadBlockManager()); final ProtocolSpec homesteadSpec = protocolSchedule.getByBlockHeader(blockHeader(1)); final ProtocolSpec londonSpec = protocolSchedule.getByBlockHeader(blockHeader(1559)); @@ -61,7 +63,8 @@ public void mergeSpecificModificationsAreUnappliedForShanghai() { final GenesisConfigOptions config = GenesisConfigFile.mainnet().getConfigOptions(); final ProtocolSchedule protocolSchedule = - MergeProtocolSchedule.create(config, false, new BadBlockManager()); + MergeProtocolSchedule.create( + config, false, MiningParameters.MINING_DISABLED, new BadBlockManager()); final long lastParisBlockNumber = 17034869L; final ProtocolSpec parisSpec = @@ -96,7 +99,8 @@ public void mergeSpecificModificationsAreUnappliedForCancun_whenShanghaiNotConfi final GenesisConfigOptions config = GenesisConfigFile.fromConfig(jsonInput).getConfigOptions(); final ProtocolSchedule protocolSchedule = - MergeProtocolSchedule.create(config, false, new BadBlockManager()); + MergeProtocolSchedule.create( + config, false, MiningParameters.MINING_DISABLED, new BadBlockManager()); final ProtocolSpec parisSpec = protocolSchedule.getByBlockHeader( @@ -123,7 +127,8 @@ public void mergeSpecificModificationsAreUnappliedForCancun_whenShanghaiNotConfi public void mergeSpecificModificationsAreUnappliedForAllMainnetForksAfterParis() { final GenesisConfigOptions config = GenesisConfigFile.mainnet().getConfigOptions(); final ProtocolSchedule protocolSchedule = - MergeProtocolSchedule.create(config, false, new BadBlockManager()); + MergeProtocolSchedule.create( + config, false, MiningParameters.MINING_DISABLED, new BadBlockManager()); final long lastParisBlockNumber = 17034869L; final ProtocolSpec parisSpec = @@ -152,7 +157,10 @@ public void mergeSpecificModificationsAreUnappliedForAllMainnetForksAfterParis() public void parametersAlignWithMainnetWithAdjustments() { final ProtocolSpec london = MergeProtocolSchedule.create( - GenesisConfigFile.DEFAULT.getConfigOptions(), false, new BadBlockManager()) + GenesisConfigFile.DEFAULT.getConfigOptions(), + false, + MiningParameters.MINING_DISABLED, + new BadBlockManager()) .getByBlockHeader(blockHeader(0)); assertThat(london.getName()).isEqualTo("Paris"); 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 d7fcec771a4..80615552e74 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 @@ -21,6 +21,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.mainnet.ProtocolSchedule; import java.io.IOException; @@ -59,6 +60,9 @@ default Stream
genesisAllocations(final GenesisConfigFile configFile) { default ProtocolSchedule getMergeProtocolSchedule() { return MergeProtocolSchedule.create( - getPosGenesisConfigFile().getConfigOptions(), false, new BadBlockManager()); + getPosGenesisConfigFile().getConfigOptions(), + false, + MiningParameters.MINING_DISABLED, + new BadBlockManager()); } } 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 dcfb049dade..f66973ef6a9 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 @@ -150,6 +150,7 @@ private record ControllerAndState( private boolean useLondonMilestone = false; private boolean useShanghaiMilestone = false; private boolean useZeroBaseFee = false; + private boolean useFixedBaseFee = false; public static final int EPOCH_LENGTH = 10_000; public static final int BLOCK_TIMER_SEC = 3; public static final int ROUND_TIMER_SEC = 12; @@ -227,6 +228,11 @@ public TestContextBuilder useZeroBaseFee(final boolean useZeroBaseFee) { return this; } + public TestContextBuilder useFixedBaseFee(final boolean useFixedBaseFee) { + this.useFixedBaseFee = useFixedBaseFee; + return this; + } + public TestContextBuilder qbftForks(final List qbftForks) { this.qbftForks = qbftForks; return this; @@ -294,6 +300,7 @@ public TestContext build() { useLondonMilestone, useShanghaiMilestone, useZeroBaseFee, + useFixedBaseFee, qbftForks); // Add each networkNode to the Multicaster (such that each can receive msgs from local node). @@ -375,6 +382,7 @@ private static ControllerAndState createControllerAndFinalState( final boolean useLondonMilestone, final boolean useShanghaiMilestone, final boolean useZeroBaseFee, + final boolean useFixedBaseFee, final List qbftForks) { final MiningParameters miningParams = @@ -407,6 +415,9 @@ private static ControllerAndState createControllerAndFinalState( if (useZeroBaseFee) { genesisConfigOptions.zeroBaseFee(true); } + if (useFixedBaseFee) { + genesisConfigOptions.fixedBaseFee(true); + } genesisConfigOptions.qbftConfigOptions( new JsonQbftConfigOptions(JsonUtil.objectNodeFromMap(qbftConfigValues))); genesisConfigOptions.transitions(TestTransitions.createQbftTestTransitions(qbftForks)); @@ -425,6 +436,7 @@ private static ControllerAndState createControllerAndFinalState( forksSchedule, BFT_EXTRA_DATA_ENCODER, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()); final BftValidatorOverrides validatorOverrides = convertBftForks(qbftForks); diff --git a/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/test/ValidatorContractTest.java b/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/test/ValidatorContractTest.java index b1949e7917a..c5978560065 100644 --- a/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/test/ValidatorContractTest.java +++ b/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/test/ValidatorContractTest.java @@ -167,6 +167,57 @@ public void retrievesValidatorsFromValidatorContract_ShanghaiFork_ZeroBaseFee() assertThat(validatorProvider.getValidatorsForBlock(block1)).containsExactly(NODE_ADDRESS); } + @Test + public void retrievesValidatorsFromValidatorContract_LondonFork_FixedBaseFee() { + // Using London on a free gas network + final TestContext context = + new TestContextBuilder() + .indexOfFirstLocallyProposedBlock(0) + .nodeParams( + List.of(new NodeParams(NODE_ADDRESS, NodeKeyUtils.createFrom(NODE_PRIVATE_KEY)))) + .clock(TestClock.fixed()) + .genesisFile(Resources.getResource("genesis_validator_contract_london.json").getFile()) + .useValidatorContract(true) + .useLondonMilestone(true) + .useFixedBaseFee(true) + .buildAndStart(); + + createNewBlockAsProposer(context, 1); + + final ValidatorProvider validatorProvider = context.getValidatorProvider(); + final BlockHeader genesisBlock = context.getBlockchain().getBlockHeader(0).get(); + final BlockHeader block1 = context.getBlockchain().getBlockHeader(1).get(); + assertThat(validatorProvider.getValidatorsForBlock(genesisBlock)).containsExactly(NODE_ADDRESS); + assertThat(validatorProvider.getValidatorsForBlock(block1)).containsExactly(NODE_ADDRESS); + } + + @Test + public void retrievesValidatorsFromValidatorContract_ShanghaiFork_FixedBaseFee() { + // Using Shanghai on a free gas network + final TestContext context = + new TestContextBuilder() + .indexOfFirstLocallyProposedBlock(0) + .nodeParams( + List.of(new NodeParams(NODE_ADDRESS, NodeKeyUtils.createFrom(NODE_PRIVATE_KEY)))) + .clock(TestClock.fixed()) + .genesisFile( + Resources.getResource("genesis_validator_contract_shanghai.json").getFile()) + .useValidatorContract(true) + .useShanghaiMilestone(true) + .useFixedBaseFee(true) + .buildAndStart(); + + createNewBlockAsProposerFixedTime( + context, 1, + 266L); // 10s ahead of genesis timestamp in genesis_validator_contract_shanghai.json + + final ValidatorProvider validatorProvider = context.getValidatorProvider(); + final BlockHeader genesisBlock = context.getBlockchain().getBlockHeader(0).get(); + final BlockHeader block1 = context.getBlockchain().getBlockHeader(1).get(); + assertThat(validatorProvider.getValidatorsForBlock(genesisBlock)).containsExactly(NODE_ADDRESS); + assertThat(validatorProvider.getValidatorsForBlock(block1)).containsExactly(NODE_ADDRESS); + } + @Test public void transitionsFromBlockHeaderModeToValidatorContractMode() { final List qbftForks = 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 01d87b7cd92..d611e82372a 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,6 +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.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; @@ -45,6 +46,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 badBlockManager the cache to use to keep invalid blocks * @return the protocol schedule */ @@ -55,6 +57,7 @@ public static BftProtocolSchedule create( final boolean isRevertReasonEnabled, final BftExtraDataCodec bftExtraDataCodec, final EvmConfiguration evmConfiguration, + final MiningParameters miningParameters, final BadBlockManager badBlockManager) { return new QbftProtocolScheduleBuilder() .createProtocolSchedule( @@ -64,6 +67,7 @@ public static BftProtocolSchedule create( isRevertReasonEnabled, bftExtraDataCodec, evmConfiguration, + miningParameters, badBlockManager); } @@ -74,6 +78,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 badBlockManager the cache to use to keep invalid blocks * @return the protocol schedule */ @@ -82,6 +87,7 @@ public static BftProtocolSchedule create( final ForksSchedule qbftForksSchedule, final BftExtraDataCodec bftExtraDataCodec, final EvmConfiguration evmConfiguration, + final MiningParameters miningParameters, final BadBlockManager badBlockManager) { return create( config, @@ -90,6 +96,7 @@ public static BftProtocolSchedule create( false, bftExtraDataCodec, evmConfiguration, + miningParameters, badBlockManager); } @@ -100,6 +107,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 badBlockManager the cache to use to keep invalid blocks * @return the protocol schedule */ @@ -108,6 +116,7 @@ public static ProtocolSchedule create( final ForksSchedule qbftForksSchedule, final boolean isRevertReasonEnabled, final BftExtraDataCodec bftExtraDataCodec, + final MiningParameters miningParameters, final BadBlockManager badBlockManager) { return create( config, @@ -116,6 +125,7 @@ public static ProtocolSchedule create( isRevertReasonEnabled, bftExtraDataCodec, EvmConfiguration.DEFAULT, + miningParameters, badBlockManager); } 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 16a5f4ca31a..3243484152d 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 @@ -35,6 +35,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.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode; @@ -136,6 +137,7 @@ private BftProtocolSchedule createProtocolSchedule( false, bftExtraDataCodec, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()); } 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 b582f1a9b88..4a2dd5b9b86 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 @@ -68,6 +68,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.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule; @@ -179,6 +180,7 @@ QbftContext.class, validators, new QbftExtraDataCodec()), new PrivacyParameters(), false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()); ProtocolSchedule protocolSchedule = 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 a3ad8d4d693..2a62331d336 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,6 +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.mainnet.MainnetProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions; @@ -43,7 +44,9 @@ public class BlockchainImporter { public BlockchainImporter(final URL blocksUrl, final String genesisJson) throws Exception { protocolSchedule = MainnetProtocolSchedule.fromConfig( - GenesisConfigFile.fromConfig(genesisJson).getConfigOptions(), new BadBlockManager()); + GenesisConfigFile.fromConfig(genesisJson).getConfigOptions(), + MiningParameters.newDefault(), + new BadBlockManager()); final BlockHeaderFunctions blockHeaderFunctions = ScheduleBasedBlockHeaderFunctions.create(protocolSchedule); blocks = new ArrayList<>(); 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 797129710ed..a261ff2351a 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 @@ -108,6 +108,7 @@ public void initServerAndClient() throws Exception { synchronizer, MainnetProtocolSchedule.fromConfig( new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID), + MiningParameters.MINING_DISABLED, new BadBlockManager()), mock(ProtocolContext.class), mock(FilterManager.class), 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 357f41b8e46..2b8b1ae3475 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 @@ -137,7 +137,8 @@ public static void initServerAndClient() throws Exception { peerDiscoveryMock, blockchainQueries, synchronizer, - MainnetProtocolSchedule.fromConfig(genesisConfigOptions, new BadBlockManager()), + MainnetProtocolSchedule.fromConfig( + genesisConfigOptions, MiningParameters.MINING_DISABLED, new BadBlockManager()), mock(ProtocolContext.class), mock(FilterManager.class), mock(TransactionPool.class), 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 0ce460866e5..a5f90791ce6 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 @@ -118,6 +118,7 @@ public static void initServerAndClient() throws Exception { MainnetProtocolSchedule.fromConfig( new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID), EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()), mock(ProtocolContext.class), mock(FilterManager.class), 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 edea0a43150..2f62e490beb 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 @@ -122,6 +122,7 @@ public void initServer() throws Exception { synchronizer, MainnetProtocolSchedule.fromConfig( new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID), + MiningParameters.MINING_DISABLED, new BadBlockManager()), mock(ProtocolContext.class), mock(FilterManager.class), 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 0f20776e456..2ff0833bc69 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 @@ -110,6 +110,7 @@ public void beforeEach() { synchronizer, MainnetProtocolSchedule.fromConfig( new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID), + MiningParameters.MINING_DISABLED, new BadBlockManager()), mock(ProtocolContext.class), mock(FilterManager.class), 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 0a43cd0e37e..e650f9d490b 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 @@ -111,6 +111,7 @@ public void initServer() throws Exception { synchronizer, MainnetProtocolSchedule.fromConfig( new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID), + MiningParameters.MINING_DISABLED, new BadBlockManager()), mock(ProtocolContext.class), mock(FilterManager.class), 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 9b5c688ddd3..bedd7aa4c36 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 @@ -173,7 +173,10 @@ public void before() throws URISyntaxException { peerDiscoveryMock, blockchainQueries, synchronizer, - MainnetProtocolSchedule.fromConfig(genesisConfigOptions, new BadBlockManager()), + MainnetProtocolSchedule.fromConfig( + genesisConfigOptions, + MiningParameters.MINING_DISABLED, + new BadBlockManager()), mock(ProtocolContext.class), mock(FilterManager.class), mock(TransactionPool.class), 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 3e8cc8a685c..560c149877e 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 @@ -364,6 +364,7 @@ private AbstractBlockCreator createBlockCreator( PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()) .createProtocolSchedule()) .build(); 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 a3b657dbc3d..a7dab2f124e 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 @@ -221,6 +221,7 @@ public void emptyPendingTransactionsResultsInEmptyVettingResult() { FixedDifficultyProtocolSchedule.create( GenesisConfigFile.development().getConfigOptions(), EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()); final MainnetTransactionProcessor mainnetTransactionProcessor = protocolSchedule.getByBlockHeader(blockHeader(0)).getTransactionProcessor(); 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 10d54576b42..39db9c05cf2 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,6 +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.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration; @@ -59,6 +60,7 @@ protected ProtocolSchedule createProtocolSchedule() { new PrivacyParameters(), false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()) .createProtocolSchedule(); } 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 4a961d07e80..8250039b2b9 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 @@ -71,6 +71,7 @@ protected ProtocolSchedule createProtocolSchedule() { new PrivacyParameters(), false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()) .createProtocolSchedule(); } 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 ad3ce47887a..f7fd4486d1b 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 @@ -93,6 +93,7 @@ void createMainnetBlock1() throws IOException { PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()) .createProtocolSchedule()) .build(); @@ -148,6 +149,7 @@ void createMainnetBlock1_fixedDifficulty1() { PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()) .createProtocolSchedule()) .build(); @@ -193,6 +195,7 @@ void rewardBeneficiary_zeroReward_skipZeroRewardsFalse() { PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()) .createProtocolSchedule(); final ExecutionContextTestFixture executionContextTestFixture = @@ -261,6 +264,7 @@ void rewardBeneficiary_zeroReward_skipZeroRewardsTrue() { PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()) .createProtocolSchedule(); final ExecutionContextTestFixture executionContextTestFixture = 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 f92f0813fcd..b7f8395d92f 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,6 +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.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder; @@ -30,6 +31,7 @@ public static ProtocolSchedule create( final PrivacyParameters privacyParameters, final boolean isRevertReasonEnabled, final EvmConfiguration evmConfiguration, + final MiningParameters miningParameters, final BadBlockManager badBlockManager) { return new ProtocolScheduleBuilder( config, @@ -40,6 +42,7 @@ public static ProtocolSchedule create( privacyParameters, isRevertReasonEnabled, evmConfiguration, + miningParameters, badBlockManager) .createProtocolSchedule(); } @@ -48,19 +51,28 @@ public static ProtocolSchedule create( final GenesisConfigOptions config, final boolean isRevertReasonEnabled, final EvmConfiguration evmConfiguration, + final MiningParameters miningParameters, final BadBlockManager badBlockManager) { return create( config, PrivacyParameters.DEFAULT, isRevertReasonEnabled, evmConfiguration, + miningParameters, badBlockManager); } public static ProtocolSchedule create( final GenesisConfigOptions config, final EvmConfiguration evmConfiguration, + final MiningParameters miningParameters, final BadBlockManager badBlockManager) { - return create(config, PrivacyParameters.DEFAULT, false, evmConfiguration, badBlockManager); + return create( + config, + PrivacyParameters.DEFAULT, + false, + evmConfiguration, + miningParameters, + badBlockManager); } } 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 6982d28d4e6..794f96cfb39 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,6 +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.PrivacyParameters; import org.hyperledger.besu.ethereum.difficulty.fixed.FixedDifficultyCalculators; import org.hyperledger.besu.ethereum.difficulty.fixed.FixedDifficultyProtocolSchedule; @@ -37,6 +38,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 badBlockManager the cache to use to keep invalid blocks * @return A configured mainnet protocol schedule */ @@ -45,10 +47,16 @@ public static ProtocolSchedule fromConfig( final PrivacyParameters privacyParameters, final boolean isRevertReasonEnabled, final EvmConfiguration evmConfiguration, + final MiningParameters miningParameters, final BadBlockManager badBlockManager) { if (FixedDifficultyCalculators.isFixedDifficultyInConfig(config)) { return FixedDifficultyProtocolSchedule.create( - config, privacyParameters, isRevertReasonEnabled, evmConfiguration, badBlockManager); + config, + privacyParameters, + isRevertReasonEnabled, + evmConfiguration, + miningParameters, + badBlockManager); } return new ProtocolScheduleBuilder( config, @@ -57,6 +65,7 @@ public static ProtocolSchedule fromConfig( privacyParameters, isRevertReasonEnabled, evmConfiguration, + miningParameters, badBlockManager) .createProtocolSchedule(); } @@ -68,6 +77,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 badBlockManager the cache to use to keep invalid blocks * @return A configured mainnet protocol schedule */ @@ -75,12 +85,14 @@ public static ProtocolSchedule fromConfig( final GenesisConfigOptions config, final boolean isRevertReasonEnabled, final EvmConfiguration evmConfiguration, + final MiningParameters miningParameters, final BadBlockManager badBlockManager) { return fromConfig( config, PrivacyParameters.DEFAULT, isRevertReasonEnabled, evmConfiguration, + miningParameters, badBlockManager); } @@ -90,14 +102,22 @@ 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 badBlockManager the cache to use to keep invalid blocks * @return A configured mainnet protocol schedule */ public static ProtocolSchedule fromConfig( final GenesisConfigOptions config, final EvmConfiguration evmConfiguration, + final MiningParameters miningParameters, final BadBlockManager badBlockManager) { - return fromConfig(config, PrivacyParameters.DEFAULT, false, evmConfiguration, badBlockManager); + return fromConfig( + config, + PrivacyParameters.DEFAULT, + false, + evmConfiguration, + miningParameters, + badBlockManager); } /** @@ -105,12 +125,20 @@ public static ProtocolSchedule fromConfig( * * @param config {@link GenesisConfigOptions} containing the config options for the milestone * starting points + * @param miningParameters the mining parameters * @param badBlockManager the cache to use to keep invalid blocks * @return A configured mainnet protocol schedule */ public static ProtocolSchedule fromConfig( - final GenesisConfigOptions config, final BadBlockManager badBlockManager) { + final GenesisConfigOptions config, + final MiningParameters miningParameters, + final BadBlockManager badBlockManager) { return fromConfig( - config, PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, badBlockManager); + config, + PrivacyParameters.DEFAULT, + false, + EvmConfiguration.DEFAULT, + miningParameters, + badBlockManager); } } 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 de7f92465bf..06bc45084a7 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,6 +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.evm.internal.EvmConfiguration; import java.math.BigInteger; @@ -30,6 +31,7 @@ public class MainnetProtocolSpecFactory { private final boolean isRevertReasonEnabled; private final OptionalLong ecip1017EraRounds; private final EvmConfiguration evmConfiguration; + private final MiningParameters miningParameters; public MainnetProtocolSpecFactory( final Optional chainId, @@ -37,13 +39,15 @@ public MainnetProtocolSpecFactory( final OptionalInt evmStackSize, final boolean isRevertReasonEnabled, final OptionalLong ecip1017EraRounds, - final EvmConfiguration evmConfiguration) { + final EvmConfiguration evmConfiguration, + final MiningParameters miningParameters) { this.chainId = chainId; this.contractSizeLimit = contractSizeLimit; this.evmStackSize = evmStackSize; this.isRevertReasonEnabled = isRevertReasonEnabled; this.ecip1017EraRounds = ecip1017EraRounds; this.evmConfiguration = evmConfiguration; + this.miningParameters = miningParameters; } public ProtocolSpecBuilder frontierDefinition() { @@ -113,7 +117,8 @@ public ProtocolSpecBuilder londonDefinition(final GenesisConfigOptions genesisCo evmStackSize, isRevertReasonEnabled, genesisConfigOptions, - evmConfiguration); + evmConfiguration, + miningParameters); } public ProtocolSpecBuilder arrowGlacierDefinition( @@ -124,7 +129,8 @@ public ProtocolSpecBuilder arrowGlacierDefinition( evmStackSize, isRevertReasonEnabled, genesisConfigOptions, - evmConfiguration); + evmConfiguration, + miningParameters); } public ProtocolSpecBuilder grayGlacierDefinition( @@ -135,7 +141,8 @@ public ProtocolSpecBuilder grayGlacierDefinition( evmStackSize, isRevertReasonEnabled, genesisConfigOptions, - evmConfiguration); + evmConfiguration, + miningParameters); } public ProtocolSpecBuilder parisDefinition(final GenesisConfigOptions genesisConfigOptions) { @@ -145,7 +152,8 @@ public ProtocolSpecBuilder parisDefinition(final GenesisConfigOptions genesisCon evmStackSize, isRevertReasonEnabled, genesisConfigOptions, - evmConfiguration); + evmConfiguration, + miningParameters); } public ProtocolSpecBuilder shanghaiDefinition(final GenesisConfigOptions genesisConfigOptions) { @@ -155,7 +163,8 @@ public ProtocolSpecBuilder shanghaiDefinition(final GenesisConfigOptions genesis evmStackSize, isRevertReasonEnabled, genesisConfigOptions, - evmConfiguration); + evmConfiguration, + miningParameters); } public ProtocolSpecBuilder cancunDefinition(final GenesisConfigOptions genesisConfigOptions) { @@ -165,7 +174,8 @@ public ProtocolSpecBuilder cancunDefinition(final GenesisConfigOptions genesisCo evmStackSize, isRevertReasonEnabled, genesisConfigOptions, - evmConfiguration); + evmConfiguration, + miningParameters); } public ProtocolSpecBuilder pragueDefinition(final GenesisConfigOptions genesisConfigOptions) { @@ -175,7 +185,8 @@ public ProtocolSpecBuilder pragueDefinition(final GenesisConfigOptions genesisCo evmStackSize, isRevertReasonEnabled, genesisConfigOptions, - evmConfiguration); + evmConfiguration, + miningParameters); } /** @@ -196,7 +207,8 @@ public ProtocolSpecBuilder futureEipsDefinition(final GenesisConfigOptions genes evmStackSize, isRevertReasonEnabled, genesisConfigOptions, - evmConfiguration); + evmConfiguration, + miningParameters); } /** @@ -217,7 +229,8 @@ public ProtocolSpecBuilder experimentalEipsDefinition( evmStackSize, isRevertReasonEnabled, genesisConfigOptions, - evmConfiguration); + evmConfiguration, + miningParameters); } //////////////////////////////////////////////////////////////////////////////////////////////// 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 2e5f114157c..ca226484112 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 @@ -24,6 +24,7 @@ import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Deposit; +import org.hyperledger.besu.ethereum.core.MiningParameters; import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; @@ -433,7 +434,8 @@ static ProtocolSpecBuilder londonDefinition( final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, - final EvmConfiguration evmConfiguration) { + final EvmConfiguration evmConfiguration, + final MiningParameters miningParameters) { final int contractSizeLimit = configContractSizeLimit.orElse(SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT); final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE); @@ -442,7 +444,10 @@ static ProtocolSpecBuilder londonDefinition( final BaseFeeMarket londonFeeMarket = genesisConfigOptions.isZeroBaseFee() ? FeeMarket.zeroBaseFee(londonForkBlockNumber) - : FeeMarket.london(londonForkBlockNumber, genesisConfigOptions.getBaseFeePerGas()); + : genesisConfigOptions.isFixedBaseFee() + ? FeeMarket.fixedBaseFee( + londonForkBlockNumber, miningParameters.getMinTransactionGasPrice()) + : FeeMarket.london(londonForkBlockNumber, genesisConfigOptions.getBaseFeePerGas()); return berlinDefinition( chainId, configContractSizeLimit, @@ -515,14 +520,16 @@ static ProtocolSpecBuilder arrowGlacierDefinition( final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, - final EvmConfiguration evmConfiguration) { + final EvmConfiguration evmConfiguration, + final MiningParameters miningParameters) { return londonDefinition( chainId, configContractSizeLimit, configStackSizeLimit, enableRevertReason, genesisConfigOptions, - evmConfiguration) + evmConfiguration, + miningParameters) .difficultyCalculator(MainnetDifficultyCalculators.ARROW_GLACIER) .name("ArrowGlacier"); } @@ -533,14 +540,16 @@ static ProtocolSpecBuilder grayGlacierDefinition( final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, - final EvmConfiguration evmConfiguration) { + final EvmConfiguration evmConfiguration, + final MiningParameters miningParameters) { return arrowGlacierDefinition( chainId, configContractSizeLimit, configStackSizeLimit, enableRevertReason, genesisConfigOptions, - evmConfiguration) + evmConfiguration, + miningParameters) .difficultyCalculator(MainnetDifficultyCalculators.GRAY_GLACIER) .name("GrayGlacier"); } @@ -551,7 +560,8 @@ static ProtocolSpecBuilder parisDefinition( final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, - final EvmConfiguration evmConfiguration) { + final EvmConfiguration evmConfiguration, + final MiningParameters miningParameters) { return grayGlacierDefinition( chainId, @@ -559,7 +569,8 @@ static ProtocolSpecBuilder parisDefinition( configStackSizeLimit, enableRevertReason, genesisConfigOptions, - evmConfiguration) + evmConfiguration, + miningParameters) .evmBuilder( (gasCalculator, jdCacheConfig) -> MainnetEVMs.paris(gasCalculator, chainId.orElse(BigInteger.ZERO), evmConfiguration)) @@ -577,7 +588,8 @@ static ProtocolSpecBuilder shanghaiDefinition( final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, - final EvmConfiguration evmConfiguration) { + final EvmConfiguration evmConfiguration, + final MiningParameters miningParameters) { // extra variables need to support flipping the warm coinbase flag. final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE); @@ -588,7 +600,8 @@ static ProtocolSpecBuilder shanghaiDefinition( configStackSizeLimit, enableRevertReason, genesisConfigOptions, - evmConfiguration) + evmConfiguration, + miningParameters) // gas calculator has new code to support EIP-3860 limit and meter initcode .gasCalculator(ShanghaiGasCalculator::new) // EVM has a new operation for EIP-3855 PUSH0 instruction @@ -638,14 +651,18 @@ static ProtocolSpecBuilder cancunDefinition( final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, - final EvmConfiguration evmConfiguration) { + final EvmConfiguration evmConfiguration, + final MiningParameters miningParameters) { final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE); final long londonForkBlockNumber = genesisConfigOptions.getLondonBlockNumber().orElse(0L); final BaseFeeMarket cancunFeeMarket = genesisConfigOptions.isZeroBaseFee() ? FeeMarket.zeroBaseFee(londonForkBlockNumber) - : FeeMarket.cancun(londonForkBlockNumber, genesisConfigOptions.getBaseFeePerGas()); + : genesisConfigOptions.isFixedBaseFee() + ? FeeMarket.fixedBaseFee( + londonForkBlockNumber, miningParameters.getMinTransactionGasPrice()) + : FeeMarket.cancun(londonForkBlockNumber, genesisConfigOptions.getBaseFeePerGas()); return shanghaiDefinition( chainId, @@ -653,7 +670,8 @@ static ProtocolSpecBuilder cancunDefinition( configStackSizeLimit, enableRevertReason, genesisConfigOptions, - evmConfiguration) + evmConfiguration, + miningParameters) .feeMarket(cancunFeeMarket) // gas calculator for EIP-4844 blob gas .gasCalculator(CancunGasCalculator::new) @@ -710,7 +728,8 @@ static ProtocolSpecBuilder pragueDefinition( final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, - final EvmConfiguration evmConfiguration) { + final EvmConfiguration evmConfiguration, + final MiningParameters miningParameters) { final int contractSizeLimit = configContractSizeLimit.orElse(SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT); @@ -720,7 +739,8 @@ static ProtocolSpecBuilder pragueDefinition( configStackSizeLimit, enableRevertReason, genesisConfigOptions, - evmConfiguration) + evmConfiguration, + miningParameters) // EVM changes to support EOF EIPs (3670, 4200, 4750, 5450) .gasCalculator(PragueGasCalculator::new) .evmBuilder( @@ -749,7 +769,8 @@ static ProtocolSpecBuilder futureEipsDefinition( final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, - final EvmConfiguration evmConfiguration) { + final EvmConfiguration evmConfiguration, + final MiningParameters miningParameters) { final int contractSizeLimit = configContractSizeLimit.orElse(SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT); return pragueDefinition( @@ -758,7 +779,8 @@ static ProtocolSpecBuilder futureEipsDefinition( configStackSizeLimit, enableRevertReason, genesisConfigOptions, - evmConfiguration) + evmConfiguration, + miningParameters) // Use Future EIP configured EVM .evmBuilder( (gasCalculator, jdCacheConfig) -> @@ -786,7 +808,8 @@ static ProtocolSpecBuilder experimentalEipsDefinition( final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, - final EvmConfiguration evmConfiguration) { + final EvmConfiguration evmConfiguration, + final MiningParameters miningParameters) { final Address depositContractAddress = genesisConfigOptions.getDepositContractAddress().orElse(DEFAULT_DEPOSIT_CONTRACT_ADDRESS); @@ -797,7 +820,8 @@ static ProtocolSpecBuilder experimentalEipsDefinition( configStackSizeLimit, enableRevertReason, genesisConfigOptions, - evmConfiguration) + evmConfiguration, + miningParameters) .evmBuilder( (gasCalculator, jdCacheConfig) -> MainnetEVMs.experimentalEips( 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 14fcedba2f3..58db065155b 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 @@ -16,6 +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.PrivacyParameters; import org.hyperledger.besu.ethereum.privacy.PrivateTransactionValidator; import org.hyperledger.besu.evm.internal.EvmConfiguration; @@ -40,6 +41,7 @@ public class ProtocolScheduleBuilder { private final PrivacyParameters privacyParameters; private final boolean isRevertReasonEnabled; private final EvmConfiguration evmConfiguration; + private final MiningParameters miningParameters; private final BadBlockManager badBlockManager; private DefaultProtocolSchedule protocolSchedule; @@ -51,6 +53,7 @@ public ProtocolScheduleBuilder( final PrivacyParameters privacyParameters, final boolean isRevertReasonEnabled, final EvmConfiguration evmConfiguration, + final MiningParameters miningParameters, final BadBlockManager badBlockManager) { this( config, @@ -59,6 +62,7 @@ public ProtocolScheduleBuilder( privacyParameters, isRevertReasonEnabled, evmConfiguration, + miningParameters, badBlockManager); } @@ -68,6 +72,7 @@ public ProtocolScheduleBuilder( final PrivacyParameters privacyParameters, final boolean isRevertReasonEnabled, final EvmConfiguration evmConfiguration, + final MiningParameters miningParameters, final BadBlockManager badBlockManager) { this( config, @@ -76,6 +81,7 @@ public ProtocolScheduleBuilder( privacyParameters, isRevertReasonEnabled, evmConfiguration, + miningParameters, badBlockManager); } @@ -86,6 +92,7 @@ private ProtocolScheduleBuilder( final PrivacyParameters privacyParameters, final boolean isRevertReasonEnabled, final EvmConfiguration evmConfiguration, + final MiningParameters miningParameters, final BadBlockManager badBlockManager) { this.config = config; this.protocolSpecAdapters = protocolSpecAdapters; @@ -93,6 +100,7 @@ private ProtocolScheduleBuilder( this.isRevertReasonEnabled = isRevertReasonEnabled; this.evmConfiguration = evmConfiguration; this.defaultChainId = defaultChainId; + this.miningParameters = miningParameters; this.badBlockManager = badBlockManager; } @@ -113,7 +121,8 @@ private void initSchedule( config.getEvmStackSize(), isRevertReasonEnabled, config.getEcip1017EraRounds(), - evmConfiguration); + evmConfiguration, + miningParameters); validateForkOrdering(); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/feemarket/FeeMarket.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/feemarket/FeeMarket.java index 637ffb471ec..fc5defbd105 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/feemarket/FeeMarket.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/feemarket/FeeMarket.java @@ -53,6 +53,10 @@ static BaseFeeMarket zeroBaseFee(final long londonForkBlockNumber) { return new ZeroBaseFeeMarket(londonForkBlockNumber); } + static BaseFeeMarket fixedBaseFee(final long londonForkBlockNumber, final Wei fixedBaseFee) { + return new FixedBaseFeeMarket(londonForkBlockNumber, fixedBaseFee); + } + static FeeMarket legacy() { return new LegacyFeeMarket(); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/feemarket/FixedBaseFeeMarket.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/feemarket/FixedBaseFeeMarket.java new file mode 100644 index 00000000000..5aeddd06720 --- /dev/null +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/feemarket/FixedBaseFeeMarket.java @@ -0,0 +1,41 @@ +/* + * Copyright Hyperledger Besu Contributors. + * + * 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.mainnet.feemarket; + +import org.hyperledger.besu.datatypes.Wei; + +import java.util.Optional; + +public class FixedBaseFeeMarket extends LondonFeeMarket { + + public FixedBaseFeeMarket(final long londonForkBlockNumber, final Wei fixedBaseFee) { + super(londonForkBlockNumber, Optional.of(fixedBaseFee)); + } + + @Override + public Wei computeBaseFee( + final long blockNumber, + final Wei parentBaseFee, + final long parentBlockGasUsed, + final long targetGasUsed) { + + return baseFeeInitialValue; + } + + @Override + public ValidationMode baseFeeValidationMode(final long blockNumber) { + return ValidationMode.NONE; + } +} diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/feemarket/LondonFeeMarket.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/feemarket/LondonFeeMarket.java index 2fff3a629fa..d1a148ceedf 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/feemarket/LondonFeeMarket.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/feemarket/LondonFeeMarket.java @@ -35,7 +35,7 @@ public class LondonFeeMarket implements BaseFeeMarket { private static final Wei DEFAULT_BASEFEE_FLOOR = Wei.of(7L); - private final Wei baseFeeInitialValue; + protected final Wei baseFeeInitialValue; private final long londonForkBlockNumber; private final TransactionPriceCalculator txPriceCalculator; private final Wei baseFeeFloor; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/feemarket/ZeroBaseFeeMarket.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/feemarket/ZeroBaseFeeMarket.java index c2f406cad04..7b32e3f84c8 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/feemarket/ZeroBaseFeeMarket.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/feemarket/ZeroBaseFeeMarket.java @@ -16,22 +16,10 @@ import org.hyperledger.besu.datatypes.Wei; -import java.util.Optional; - -public class ZeroBaseFeeMarket extends LondonFeeMarket { +public class ZeroBaseFeeMarket extends FixedBaseFeeMarket { public ZeroBaseFeeMarket(final long londonForkBlockNumber) { - super(londonForkBlockNumber, Optional.of(Wei.ZERO)); - } - - @Override - public Wei computeBaseFee( - final long blockNumber, - final Wei parentBaseFee, - final long parentBlockGasUsed, - final long targetGasUsed) { - - return Wei.ZERO; + super(londonForkBlockNumber, Wei.ZERO); } @Override 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 cf142eb2ed8..f0ffbb98622 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 @@ -142,7 +142,10 @@ public static BlockchainSetupUtil createForEthashChain( private static ProtocolSchedule mainnetProtocolScheduleProvider( final GenesisConfigFile genesisConfigFile) { return MainnetProtocolSchedule.fromConfig( - genesisConfigFile.getConfigOptions(), EvmConfiguration.DEFAULT, new BadBlockManager()); + genesisConfigFile.getConfigOptions(), + EvmConfiguration.DEFAULT, + MiningParameters.newDefault(), + new BadBlockManager()); } private static ProtocolContext mainnetProtocolContextProvider( 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 25c65b357f8..40f4c8c9312 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 @@ -140,6 +140,7 @@ public ExecutionContextTestFixture build() { new PrivacyParameters(), false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()) .createProtocolSchedule(); } 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 b0292fda057..0df40c56da3 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,6 +39,7 @@ public class ProtocolScheduleFixture { PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, + MiningParameters.newDefault(), new BadBlockManager()); private static GenesisConfigOptions getMainnetConfigOptions() { 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 f4b589cf608..afb0e195f35 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,6 +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.mainnet.ProtocolSchedule; import org.hyperledger.besu.evm.internal.EvmConfiguration; @@ -34,6 +35,7 @@ public void reportedDifficultyForAllBlocksIsAFixedValue() { FixedDifficultyProtocolSchedule.create( GenesisConfigFile.development().getConfigOptions(), EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()); final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture(); 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 91bece386e2..b68104d81ba 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 @@ -23,6 +23,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.PrivacyParameters; import org.hyperledger.besu.evm.internal.EvmConfiguration; @@ -60,6 +61,7 @@ public void setup() { privacyParameters, isRevertReasonEnabled, evmConfiguration, + MiningParameters.MINING_DISABLED, new BadBlockManager()); } 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 60406fa05e2..a8b5b772f8e 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,6 +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.ProtocolScheduleFixture; import org.hyperledger.besu.evm.internal.EvmConfiguration; @@ -74,6 +75,7 @@ public void shouldOnlyUseFrontierWhenEmptyJsonConfigIsUsed() { MainnetProtocolSchedule.fromConfig( GenesisConfigFile.fromConfig("{}").getConfigOptions(), EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()); Assertions.assertThat(sched.getByBlockHeader(blockHeader(1L)).getName()).isEqualTo("Frontier"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(Long.MAX_VALUE)).getName()) @@ -88,6 +90,7 @@ public void createFromConfigWithSettings() { MainnetProtocolSchedule.fromConfig( GenesisConfigFile.fromConfig(json).getConfigOptions(), EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()); Assertions.assertThat(sched.getByBlockHeader(blockHeader(1)).getName()).isEqualTo("Frontier"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(2)).getName()).isEqualTo("Homestead"); @@ -119,6 +122,7 @@ public void outOfOrderConstantinoplesFail() { MainnetProtocolSchedule.fromConfig( GenesisConfigFile.fromConfig(json).getConfigOptions(), EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager())); } @@ -131,6 +135,7 @@ public void shouldCreateGoerliConfig() throws Exception { this.getClass().getResource("/goerli.json"), StandardCharsets.UTF_8)) .getConfigOptions(), EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()); Assertions.assertThat(sched.getByBlockHeader(blockHeader(0L)).getName()) .isEqualTo("Petersburg"); 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 ab1c64d2748..c7be26039e3 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 @@ -26,6 +26,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.PrivacyParameters; import org.hyperledger.besu.evm.internal.EvmConfiguration; @@ -59,6 +60,7 @@ public void setup() { new PrivacyParameters(), false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()); } @@ -213,6 +215,7 @@ private MilestoneStreamingProtocolSchedule createScheduleModifiedAt(final int bl new PrivacyParameters(), false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()); return new MilestoneStreamingProtocolSchedule( diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/feemarket/FixedBaseFeeMarketTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/feemarket/FixedBaseFeeMarketTest.java new file mode 100644 index 00000000000..0e0873b39ce --- /dev/null +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/feemarket/FixedBaseFeeMarketTest.java @@ -0,0 +1,152 @@ +/* + * Copyright Hyperledger Besu Contributors. + * + * 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.mainnet.feemarket; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.hyperledger.besu.crypto.KeyPair; +import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; +import org.hyperledger.besu.datatypes.BlobGas; +import org.hyperledger.besu.datatypes.TransactionType; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.core.Transaction; +import org.hyperledger.besu.ethereum.core.TransactionTestFixture; + +import java.util.Optional; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class FixedBaseFeeMarketTest { + + private static final KeyPair KEY_PAIR1 = + SignatureAlgorithmFactory.getInstance().generateKeyPair(); + private static final long FORK_BLOCK = 0; + private FixedBaseFeeMarket fixedBaseFeeMarket; + + @BeforeEach + public void setUp() throws Exception { + fixedBaseFeeMarket = new FixedBaseFeeMarket(FORK_BLOCK, Wei.ONE); + } + + @Test + public void getBasefeeMaxChangeDenominatorShouldUseLondonDefault() { + assertThat(fixedBaseFeeMarket.getBasefeeMaxChangeDenominator()) + .isEqualTo(LondonFeeMarket.DEFAULT_BASEFEE_MAX_CHANGE_DENOMINATOR); + } + + @Test + public void getInitialBasefeeShouldBeZero() { + assertThat(fixedBaseFeeMarket.getInitialBasefee()).isEqualTo(Wei.ONE); + } + + @Test + public void getSlackCoefficientShouldUseLondonDefault() { + assertThat(fixedBaseFeeMarket.getSlackCoefficient()) + .isEqualTo(LondonFeeMarket.DEFAULT_SLACK_COEFFICIENT); + } + + @Test + public void getTransactionPriceCalculatorShouldBeEIP1559() { + // only eip1559 will read the fee per gas values + final Transaction transaction = + new TransactionTestFixture() + .type(TransactionType.EIP1559) + .maxFeePerGas(Optional.of(Wei.of(8))) + .maxPriorityFeePerGas(Optional.of(Wei.of(8))) + .gasPrice(null) + .createTransaction(KEY_PAIR1); + + assertThat( + fixedBaseFeeMarket + .getTransactionPriceCalculator() + .price(transaction, Optional.of(Wei.ZERO))) + .isEqualTo(Wei.of(8)); + } + + @Test + public void satisfiesFloorTxCostWhenGasFeeIsNonZero() { + final Transaction transaction = + new TransactionTestFixture() + .type(TransactionType.FRONTIER) + .gasPrice(Wei.of(7)) + .createTransaction(KEY_PAIR1); + assertThat(fixedBaseFeeMarket.satisfiesFloorTxFee(transaction)).isTrue(); + } + + @Test + public void satisfiesFloorTxCostWhenGasFeeIsZero() { + final Transaction transaction = + new TransactionTestFixture() + .type(TransactionType.EIP1559) + .maxFeePerGas(Optional.of(Wei.ZERO)) + .maxPriorityFeePerGas(Optional.of(Wei.ZERO)) + .gasPrice(null) + .createTransaction(KEY_PAIR1); + assertThat(fixedBaseFeeMarket.satisfiesFloorTxFee(transaction)).isFalse(); + } + + @Test + public void computeBaseFeeReturnsFixedValue() { + assertThat(fixedBaseFeeMarket.computeBaseFee(1L, Wei.of(1), 1L, 2L)).isEqualTo(Wei.ONE); + } + + @Test + public void baseFeeValidationModeShouldBeNoneWhenIsForkBlock() { + assertThat(fixedBaseFeeMarket.baseFeeValidationMode(FORK_BLOCK)) + .isEqualTo(BaseFeeMarket.ValidationMode.NONE); + } + + @Test + public void baseFeeValidationModeShouldBeNoneWhenIsNotForkBlock() { + assertThat(fixedBaseFeeMarket.baseFeeValidationMode(FORK_BLOCK + 1)) + .isEqualTo(BaseFeeMarket.ValidationMode.NONE); + } + + @Test + public void gasLimitValidationModeShouldBeInitialWhenIsForkBlock() { + assertThat(fixedBaseFeeMarket.gasLimitValidationMode(FORK_BLOCK)) + .isEqualTo(BaseFeeMarket.ValidationMode.INITIAL); + } + + @Test + public void gasLimitValidationModeShouldBeOngoingWhenIsNotForkBlock() { + assertThat(fixedBaseFeeMarket.gasLimitValidationMode(FORK_BLOCK + 1)) + .isEqualTo(BaseFeeMarket.ValidationMode.ONGOING); + } + + @Test + public void isBeforeForkBlockShouldBeTrue() { + final FixedBaseFeeMarket fixedBaseFeeMarket = new FixedBaseFeeMarket(10, Wei.ONE); + assertThat(fixedBaseFeeMarket.isBeforeForkBlock(9)).isTrue(); + } + + @Test + public void isBeforeForkBlockShouldBeFalse() { + final FixedBaseFeeMarket fixedBaseFeeMarket = new FixedBaseFeeMarket(10, Wei.ONE); + assertThat(fixedBaseFeeMarket.isBeforeForkBlock(10)).isFalse(); + assertThat(fixedBaseFeeMarket.isBeforeForkBlock(11)).isFalse(); + } + + @Test + public void implementsDataFeedShouldReturnFalse() { + assertThat(fixedBaseFeeMarket.implementsDataFee()).isFalse(); + } + + @Test + public void dataPriceShouldReturnsZero() { + assertThat(fixedBaseFeeMarket.blobGasPricePerGas(BlobGas.ONE)).isEqualTo(Wei.ZERO); + } +} diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/BaseFeeMarketBlockHeaderGasPriceValidationRuleTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/BaseFeeMarketBlockHeaderGasPriceValidationRuleTest.java index ca2cfe4d565..2cd1936b3ab 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/BaseFeeMarketBlockHeaderGasPriceValidationRuleTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/BaseFeeMarketBlockHeaderGasPriceValidationRuleTest.java @@ -128,4 +128,29 @@ public void shouldReturnTrueIfUsingZeroBaseFeeMarketOnNonZeroLondonForkBlock() { blockHeader(FORK_BLOCK - 1, 0, Optional.of(londonFeeMarketBaseFee)))) .isTrue(); } + + @Test + public void shouldReturnTrueIfUsingFixedBaseFeeMarket() { + final BaseFeeMarket fixedBaseFeeMarket = FeeMarket.fixedBaseFee(FORK_BLOCK, Wei.ONE); + final var validationRule = + new BaseFeeMarketBlockHeaderGasPriceValidationRule(fixedBaseFeeMarket); + assertThat( + validationRule.validate( + blockHeader(FORK_BLOCK + 2, 0, Optional.of(fixedBaseFeeMarket.getInitialBasefee())), + blockHeader(FORK_BLOCK + 1, 0, Optional.of(feeMarket.getInitialBasefee()), 2))) + .isTrue(); + } + + @Test + public void shouldReturnTrueIfUsingFixedBaseFeeMarketOnNonZeroLondonForkBlock() { + final BaseFeeMarket zeroBaseFeeMarket = FeeMarket.fixedBaseFee(FORK_BLOCK, Wei.ONE); + final var validationRule = + new BaseFeeMarketBlockHeaderGasPriceValidationRule(zeroBaseFeeMarket); + final Wei londonFeeMarketBaseFee = feeMarket.getInitialBasefee(); + assertThat( + validationRule.validate( + blockHeader(FORK_BLOCK, 0, Optional.of(londonFeeMarketBaseFee)), + blockHeader(FORK_BLOCK - 1, 0, Optional.of(londonFeeMarketBaseFee)))) + .isTrue(); + } } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/GasLimitElasticityValidationRuleFixedBaseFeeMarketTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/GasLimitElasticityValidationRuleFixedBaseFeeMarketTest.java new file mode 100644 index 00000000000..7f2387cdca0 --- /dev/null +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/GasLimitElasticityValidationRuleFixedBaseFeeMarketTest.java @@ -0,0 +1,75 @@ +/* + * Copyright Hyperledger Besu Contributors. + * + * 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.mainnet.headervalidationrules; + +import static java.lang.Long.MAX_VALUE; +import static org.assertj.core.api.Assertions.assertThat; + +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; +import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket; +import org.hyperledger.besu.ethereum.mainnet.feemarket.FixedBaseFeeMarket; + +import java.util.Optional; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +public class GasLimitElasticityValidationRuleFixedBaseFeeMarketTest { + + private static final Optional fixedBaseFeeMarket = + Optional.of(new FixedBaseFeeMarket(10, Wei.ONE)); + + public GasLimitRangeAndDeltaValidationRule uut = + new GasLimitRangeAndDeltaValidationRule(5000, MAX_VALUE, fixedBaseFeeMarket); + + @ParameterizedTest + @CsvSource({ + "20000000, 10000000, 10, true", + "20019530, 10000000, 10, true", + "20019531, 10000000, 10, false", + "19980470, 10000000, 10, true", + "19980469, 10000000, 10, false", + "20000000, 20000000, 11, true", + "20019530, 20000000, 11, true", + "20019531, 20000000, 11, false", + "19980470, 20000000, 11, true", + "19980469, 20000000, 11, false", + "40039061, 40000000, 11, true", + "40039062, 40000000, 11, false", + "39960939, 40000000, 11, true", + "39960938, 40000000, 11, false", + "4999, 40000000, 11, false" + }) + public void test( + final long headerGasLimit, + final long parentGasLimit, + final long headerNumber, + final boolean expectedResult) { + + final BlockHeaderTestFixture blockHeaderBuilder = new BlockHeaderTestFixture(); + + blockHeaderBuilder.number(headerNumber); + blockHeaderBuilder.gasLimit(headerGasLimit); + final BlockHeader header = blockHeaderBuilder.buildHeader(); + + blockHeaderBuilder.number(headerNumber - 1); + blockHeaderBuilder.gasLimit(parentGasLimit); + final BlockHeader parent = blockHeaderBuilder.buildHeader(); + + assertThat(uut.validate(header, parent)).isEqualTo(expectedResult); + } +} diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/AbstractIsolationTests.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/AbstractIsolationTests.java index 33710bd4a4f..2d18bee3268 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/AbstractIsolationTests.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/AbstractIsolationTests.java @@ -105,7 +105,9 @@ public abstract class AbstractIsolationTests { .createKeyPair(SECPPrivateKey.create(Bytes32.fromHexString(key), "ECDSA")); protected final ProtocolSchedule protocolSchedule = MainnetProtocolSchedule.fromConfig( - GenesisConfigFile.development().getConfigOptions(), new BadBlockManager()); + GenesisConfigFile.development().getConfigOptions(), + MiningParameters.MINING_DISABLED, + new BadBlockManager()); protected final GenesisState genesisState = GenesisState.fromConfig(GenesisConfigFile.development(), protocolSchedule); protected final MutableBlockchain blockchain = createInMemoryBlockchain(genesisState.getBlock()); 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 67a81b4518e..1a69dd1daba 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,6 +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.Transaction; import org.hyperledger.besu.ethereum.difficulty.fixed.FixedDifficultyProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; @@ -58,6 +59,7 @@ public void setup() { GenesisConfigFile.development().getConfigOptions(), false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()); } 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 f1720c61c50..08d2262c2d5 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,6 +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.difficulty.fixed.FixedDifficultyProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; @@ -65,6 +66,7 @@ public void blockHeadersRoundTrip() throws IOException { GenesisConfigFile.development().getConfigOptions(), false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager())); for (int i = 0; i < 50; ++i) { 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 808005f858d..9912d66f381 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 @@ -22,6 +22,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.difficulty.fixed.FixedDifficultyProtocolSchedule; import org.hyperledger.besu.ethereum.eth.manager.ChainState; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; @@ -55,6 +56,7 @@ public class ChainHeadTrackerTest { GenesisConfigFile.development().getConfigOptions(), false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()); private final TrailingPeerLimiter trailingPeerLimiter = mock(TrailingPeerLimiter.class); 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 5ee3192fa02..622d66587c7 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 @@ -39,6 +39,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.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; @@ -94,7 +95,8 @@ public class BackwardSyncContextTest { @Spy private ProtocolSchedule protocolSchedule = - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions(), new BadBlockManager()); + MainnetProtocolSchedule.fromConfig( + new StubGenesisConfigOptions(), MiningParameters.MINING_DISABLED, new BadBlockManager()); @Spy private ProtocolSpec protocolSpec = 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 1656d7a7b48..a506e7fa3f7 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,6 +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.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; @@ -68,7 +69,8 @@ public class BackwardSyncStepTest { private BackwardSyncContext context; private final ProtocolSchedule protocolSchedule = - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions(), new BadBlockManager()); + MainnetProtocolSchedule.fromConfig( + new StubGenesisConfigOptions(), MiningParameters.MINING_DISABLED, new BadBlockManager()); private final DeterministicEthScheduler ethScheduler = new DeterministicEthScheduler(); 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 e8ae62d40b7..cb5cb0aed16 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 @@ -31,6 +31,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.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; @@ -74,7 +75,8 @@ public class ForwardSyncStepTest { private RespondingEthPeer peer; private final ProtocolSchedule protocolSchedule = - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions(), new BadBlockManager()); + MainnetProtocolSchedule.fromConfig( + new StubGenesisConfigOptions(), MiningParameters.MINING_DISABLED, new BadBlockManager()); private MutableBlockchain localBlockchain; GenericKeyValueStorageFacade headersStorage; GenericKeyValueStorageFacade blocksStorage; diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTest.java index e811df51f1b..082b50796ed 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTest.java @@ -60,6 +60,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.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; @@ -195,6 +196,7 @@ protected static ExecutionContextTestFixture createExecutionContextTestFixtureBa new PrivacyParameters(), false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()) .createProtocolSchedule(); final ExecutionContextTestFixture executionContextTestFixture = 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 762e7cf7a94..62dde1f8f41 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 @@ -116,6 +116,7 @@ public TestNode( GenesisConfigFile.development().getConfigOptions(), false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()); final GenesisState genesisState = GenesisState.fromConfig(genesisConfigFile, protocolSchedule); 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 422f21a8705..5410cfc92d7 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 @@ -366,6 +366,7 @@ private void setupScheduleWith(final StubGenesisConfigOptions config) { PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()) .createProtocolSchedule(); 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 8f18a796592..5b5f2e0fb8b 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 @@ -21,6 +21,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.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule; @@ -76,7 +77,7 @@ ProtocolSchedule provideProtocolSchedule( } } return MainnetProtocolSchedule.fromConfig( - configOptions, evmConfiguration, new BadBlockManager()); + configOptions, evmConfiguration, MiningParameters.newDefault(), new BadBlockManager()); } public static Map> createSchedules() { @@ -134,6 +135,7 @@ private static Supplier createSchedule(final GenesisConfigOpti PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()) .createProtocolSchedule(); } 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 dae9badfd1b..0a137c4ea82 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 @@ -18,6 +18,7 @@ import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.config.StubGenesisConfigOptions; 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.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder; @@ -106,6 +107,7 @@ private static ProtocolSchedule createSchedule(final GenesisConfigOptions option PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, + MiningParameters.MINING_DISABLED, new BadBlockManager()) .createProtocolSchedule(); } 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 df9fac4bdc2..6377b1ae3ba 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 @@ -27,6 +27,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.evm.internal.EvmConfiguration; import org.hyperledger.besu.evm.log.LogsBloomFilter; @@ -58,64 +59,64 @@ public static Stream getTestParametersForConfig() throws IOException MainnetProtocolSchedule.fromConfig( GenesisConfigFile.mainnet() .getConfigOptions(postMergeOverrides), - EvmConfiguration.DEFAULT, new BadBlockManager())), + EvmConfiguration.DEFAULT, MiningParameters.newDefault(), new BadBlockManager())), Arguments.of( "/DifficultyTests/dfGrayGlacier/difficultyGrayGlacierForkBlock.json", MainnetProtocolSchedule.fromConfig( - new StubGenesisConfigOptions().grayGlacierBlock(15050000), new BadBlockManager()) + new StubGenesisConfigOptions().grayGlacierBlock(15050000), MiningParameters.newDefault(), new BadBlockManager()) ), Arguments.of( "/DifficultyTests/dfGrayGlacier/difficultyGrayGlacierTimeDiff1.json", MainnetProtocolSchedule.fromConfig( - new StubGenesisConfigOptions().grayGlacierBlock(15050000), new BadBlockManager()) + new StubGenesisConfigOptions().grayGlacierBlock(15050000), MiningParameters.newDefault(), new BadBlockManager()) ), Arguments.of( "/DifficultyTests/dfGrayGlacier/difficultyGrayGlacierTimeDiff2.json", MainnetProtocolSchedule.fromConfig( - new StubGenesisConfigOptions().grayGlacierBlock(15050000), new BadBlockManager()) + new StubGenesisConfigOptions().grayGlacierBlock(15050000), MiningParameters.newDefault(), new BadBlockManager()) ), Arguments.of( "/DifficultyTests/dfArrowGlacier/difficultyArrowGlacierForkBlock.json", MainnetProtocolSchedule.fromConfig( - new StubGenesisConfigOptions().arrowGlacierBlock(13773000), new BadBlockManager()) + new StubGenesisConfigOptions().arrowGlacierBlock(13773000), MiningParameters.newDefault(), new BadBlockManager()) ), Arguments.of( "/DifficultyTests/dfArrowGlacier/difficultyArrowGlacierTimeDiff1.json", MainnetProtocolSchedule.fromConfig( - new StubGenesisConfigOptions().arrowGlacierBlock(13773000), new BadBlockManager()) + new StubGenesisConfigOptions().arrowGlacierBlock(13773000), MiningParameters.newDefault(), new BadBlockManager()) ), Arguments.of( "/DifficultyTests/dfArrowGlacier/difficultyArrowGlacierTimeDiff2.json", MainnetProtocolSchedule.fromConfig( - new StubGenesisConfigOptions().arrowGlacierBlock(13773000), new BadBlockManager()) + new StubGenesisConfigOptions().arrowGlacierBlock(13773000), MiningParameters.newDefault(), new BadBlockManager()) ), Arguments.of( "/DifficultyTests/dfByzantium/difficultyByzantium.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().byzantiumBlock(0), new BadBlockManager()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().byzantiumBlock(0), MiningParameters.newDefault(), new BadBlockManager()) ), Arguments.of( "/DifficultyTests/dfConstantinople/difficultyConstantinople.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().constantinopleBlock(0), new BadBlockManager()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().constantinopleBlock(0), MiningParameters.newDefault(), new BadBlockManager()) ), Arguments.of( "/DifficultyTests/dfEIP2384/difficultyEIP2384.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().muirGlacierBlock(0), new BadBlockManager()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().muirGlacierBlock(0), MiningParameters.newDefault(), new BadBlockManager()) ), Arguments.of( "/DifficultyTests/dfEIP2384/difficultyEIP2384_random.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().muirGlacierBlock(0), new BadBlockManager()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().muirGlacierBlock(0), MiningParameters.newDefault(), new BadBlockManager()) ), Arguments.of( "/DifficultyTests/dfEIP2384/difficultyEIP2384_random_to20M.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().muirGlacierBlock(0), new BadBlockManager()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().muirGlacierBlock(0), MiningParameters.newDefault(), new BadBlockManager()) ), Arguments.of( "/DifficultyTests/dfFrontier/difficultyFrontier.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions(), new BadBlockManager()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions(), MiningParameters.newDefault(), new BadBlockManager()) ), Arguments.of( "/DifficultyTests/dfHomestead/difficultyHomestead.json", - MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().homesteadBlock(0), new BadBlockManager()) + MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().homesteadBlock(0), MiningParameters.newDefault(), new BadBlockManager()) )); } 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 index a9b5050be37..e34d9f44731 100644 --- 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 @@ -158,7 +158,7 @@ private boolean buildContext( JsonUtil.getObjectNode(genesisConfig, "config").get()); protocolSchedule = MainnetProtocolSchedule.fromConfig( - jsonGenesisConfigOptions, EvmConfiguration.DEFAULT, badBlockManager); + jsonGenesisConfigOptions, EvmConfiguration.DEFAULT, miningParameters, badBlockManager); if ("NoReward".equalsIgnoreCase(sealEngine)) { protocolSchedule = new NoRewardProtocolScheduleWrapper(protocolSchedule, badBlockManager); } From 8c41e7c44dfc87241e7b48b42b288ce712eb322b Mon Sep 17 00:00:00 2001 From: Justin Florentine Date: Fri, 15 Mar 2024 21:32:39 -0400 Subject: [PATCH 11/22] Artifactory publish (#6746) * resumes publishing jars, but not distros to artifactory * checkMavenCoordinateCollisions needs a publication with an explicitly set version, does not inherit project.version --------- Signed-off-by: Justin Florentine Co-authored-by: garyschulte --- .github/workflows/artifacts.yml | 4 ++++ .github/workflows/pre-review.yml | 2 +- build.gradle | 7 ------- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/workflows/artifacts.yml b/.github/workflows/artifacts.yml index 6a737252bcc..e7db5a04ae2 100644 --- a/.github/workflows/artifacts.yml +++ b/.github/workflows/artifacts.yml @@ -46,6 +46,10 @@ jobs: path: 'build/distributions/besu*.zip' name: besu-${{ github.ref_name }}.zip compression-level: 0 + - name: Artifactory Publish + env: + ARTIFACTORY_USER: ${{ secrets.BESU_ARTIFACTORY }} + run: ./gradlew -Prelease.releaseVersion=${{ github.ref_name }} -Pversion=${{github.ref_name}} artifactoryPublish testWindows: runs-on: windows-2022 needs: artifacts diff --git a/.github/workflows/pre-review.yml b/.github/workflows/pre-review.yml index a7b2faf6e81..6a0b6e79ddb 100644 --- a/.github/workflows/pre-review.yml +++ b/.github/workflows/pre-review.yml @@ -124,7 +124,7 @@ jobs: - name: run unit tests id: unitTest run: ./gradlew $GRADLEW_UNIT_TEST_ARGS - - name: Upload Acceptance Test Results + - name: Upload Unit Test Results uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 with: name: unit-${{matrix.filename}}-test-results diff --git a/build.gradle b/build.gradle index 17d2d317ffd..9c98874597c 100644 --- a/build.gradle +++ b/build.gradle @@ -685,8 +685,6 @@ publishing { groupId = '.' version = project.version artifactId = 'besu' - artifact("$buildDir/distributions/besu-${project.version}.zip") - artifact("$buildDir/distributions/besu-${project.version}.tar.gz") { extension = 'tar.gz' } } } } @@ -698,11 +696,6 @@ def artifactoryOrg = System.getenv('ARTIFACTORY_ORG') ?: 'hyperledger' artifactory { contextUrl = "https://hyperledger.jfrog.io/${artifactoryOrg}" publish { - repository { - repoKey = "besu-binaries" - username = artifactoryUser - password = artifactoryKey - } defaults { publications('distArtifactory') publishArtifacts = true From 34bd2032a04bde5753a1165f24b0a2486f3f2b0f Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Mon, 18 Mar 2024 10:51:12 +1000 Subject: [PATCH 12/22] ignore flaky test (#6748) Signed-off-by: Sally MacFarlane --- .../jsonrpc/EthSendRawTransactionAcceptanceTest.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthSendRawTransactionAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthSendRawTransactionAcceptanceTest.java index c054a2a1653..b09bf1d5f91 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthSendRawTransactionAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthSendRawTransactionAcceptanceTest.java @@ -24,6 +24,7 @@ import java.math.BigInteger; import java.util.function.UnaryOperator; +import org.junit.Ignore; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -51,12 +52,15 @@ public void setUp() throws Exception { } @Test + @Ignore("flaky with timeout") public void shouldSendSuccessfullyToLenientNodeWithoutChainId() { final TransferTransaction tx = createTransactionWithoutChainId(); final String rawTx = tx.signedTransactionData(); final String txHash = tx.transactionHash(); lenientNode.verify(eth.expectSuccessfulEthRawTransaction(rawTx)); + + // this line is where the test is flaky // Tx should be included on-chain miningNode.verify(eth.expectSuccessfulTransactionReceipt(txHash)); } From 9439a1cb605243c0506d5945bd3c15db07ecae2b Mon Sep 17 00:00:00 2001 From: standstaff <163401255+standstaff@users.noreply.github.com> Date: Mon, 18 Mar 2024 09:24:26 +0800 Subject: [PATCH 13/22] chore: fix some typos (#6741) Signed-off-by: standstaff Co-authored-by: Sally MacFarlane --- CHANGELOG.md | 2 +- besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java | 2 +- .../org/hyperledger/besu/ethereum/core/VersionMetadata.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d95944227b..b1e07c26d4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2326,7 +2326,7 @@ Workaround - Limit the number of blocks queried by each `eth_getLogs` call. - Implemented private contract log filters including JSON-RPC methods to interact with private filters. [\#735](https://github.com/hyperledger/besu/pull/735) - Implemented EIP-2315: Simple Subroutines for the EVM [\#717](https://github.com/hyperledger/besu/pull/717) - Implemented Splunk logging. [\#725](https://github.com/hyperledger/besu/pull/725) -- Implemented optional native library encryption. [\#675](https://github.com/hyperledger/besu/pull/675). To enable add `--Xsecp256k1-native-enabled` (for transaciton signatures) and/or `--Xaltbn128-native-enabled` (for altbn128 precomiled contracts) as command line options. +- Implemented optional native library encryption. [\#675](https://github.com/hyperledger/besu/pull/675). To enable add `--Xsecp256k1-native-enabled` (for transaction signatures) and/or `--Xaltbn128-native-enabled` (for altbn128 precomiled contracts) as command line options. ### Bug Fixes 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 d5b6468a90c..c993dda3d04 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -2598,7 +2598,7 @@ String getLogLevel() { } /** - * Returns the flag indicating that version compatiblity checks will be made. + * Returns the flag indicating that version compatibility checks will be made. * * @return true if compatibility checks should be made, otherwise false */ diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/VersionMetadata.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/VersionMetadata.java index afa07cbf84b..5246cb5fae3 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/VersionMetadata.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/VersionMetadata.java @@ -98,7 +98,7 @@ private static VersionMetadata resolveVersionMetadata(final File metadataFile) * data directory. Currently this check is limited to checking that the version is >= the previous * version, to avoid accidentally running a lower version of Besu and potentially corrupting data, * but the method could be extended to perform any other version-to-version compatibility checks - * necessary. If the --version-compatibility-protection flag is set to true and the compatibilty + * necessary. If the --version-compatibility-protection flag is set to true and the compatibility * checks pass, the version metadata is updated to the current version of Besu. */ public static void versionCompatibilityChecks( From 4bd87333675f3fd34020c8799429691596f80cfa Mon Sep 17 00:00:00 2001 From: Andrew Davis <1709934+Savid@users.noreply.github.com> Date: Mon, 18 Mar 2024 12:03:44 +1000 Subject: [PATCH 14/22] fix(build): docker git ref (#6744) Signed-off-by: Andrew Davis <1709934+Savid@users.noreply.github.com> Co-authored-by: Sally MacFarlane --- build.gradle | 3 ++- ethereum/evmtool/build.gradle | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 9c98874597c..d9e854fd859 100644 --- a/build.gradle +++ b/build.gradle @@ -759,9 +759,10 @@ task distDocker { dockerPlatform = "--platform ${project.getProperty('docker-platform')}" println "Building for platform ${project.getProperty('docker-platform')}" } + def gitDetails = getGitCommitDetails(10) executable "sh" workingDir dockerBuildDir - args "-c", "docker build ${dockerPlatform} --build-arg BUILD_DATE=${buildTime()} --build-arg VERSION=${dockerBuildVersion} --build-arg VCS_REF=${getCheckedOutGitCommitHash()} -t ${image} ." + args "-c", "docker build ${dockerPlatform} --build-arg BUILD_DATE=${buildTime()} --build-arg VERSION=${dockerBuildVersion} --build-arg VCS_REF=${gitDetails.hash} -t ${image} ." } } diff --git a/ethereum/evmtool/build.gradle b/ethereum/evmtool/build.gradle index 5bc7877fc28..db582bcb02f 100644 --- a/ethereum/evmtool/build.gradle +++ b/ethereum/evmtool/build.gradle @@ -120,8 +120,9 @@ tasks.register('distDocker', Exec) { } } + def gitDetails = getGitCommitDetails(10) executable "sh" - args "-c", "docker build --build-arg BUILD_DATE=${buildTime()} --build-arg VERSION=${dockerBuildVersion} --build-arg VCS_REF=${getCheckedOutGitCommitHash()} -t ${image} ." + args "-c", "docker build --build-arg BUILD_DATE=${buildTime()} --build-arg VERSION=${dockerBuildVersion} --build-arg VCS_REF=${gitDetails.hash} -t ${image} ." } tasks.register('dockerUpload', Exec) { From 5c1e1e18791cd37bb60b9b246a7b5a109d37745a Mon Sep 17 00:00:00 2001 From: Usman Saleem Date: Mon, 18 Mar 2024 18:52:38 +1000 Subject: [PATCH 15/22] Suppress ComparisonOutOfRange error-prone warning in AbstractGasLimitSpecification (#6727) * Add suppression for ComparisonOutOfRange * test: Add unit test to cover max gas limit --------- Signed-off-by: Usman Saleem --- .../ethereum/mainnet/AbstractGasLimitSpecification.java | 7 +++++++ .../ethereum/mainnet/TargetingGasLimitCalculatorTest.java | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AbstractGasLimitSpecification.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AbstractGasLimitSpecification.java index b1a21e54b4b..91cf73c3df8 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AbstractGasLimitSpecification.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AbstractGasLimitSpecification.java @@ -40,6 +40,13 @@ public static long deltaBound(final long currentGasLimit) { return Long.divideUnsigned(currentGasLimit, GAS_LIMIT_BOUND_DIVISOR); } + /** + * Verify that the target gas limit is within the allowed bounds. + * + * @param targetGasLimit the target gas limit to validate + * @return true if within bounds + */ + @SuppressWarnings("ComparisonOutOfRange") public static boolean isValidTargetGasLimit(final long targetGasLimit) { return DEFAULT_MIN_GAS_LIMIT <= targetGasLimit && DEFAULT_MAX_GAS_LIMIT >= targetGasLimit; } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/TargetingGasLimitCalculatorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/TargetingGasLimitCalculatorTest.java index ef197143f2f..4932eef30d8 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/TargetingGasLimitCalculatorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/TargetingGasLimitCalculatorTest.java @@ -72,6 +72,12 @@ public void verifyMinGasLimit() { .isFalse(); } + @Test + public void verifyMaxGasLimit() { + assertThat(AbstractGasLimitSpecification.isValidTargetGasLimit(Long.MAX_VALUE - 1)).isTrue(); + assertThat(AbstractGasLimitSpecification.isValidTargetGasLimit(Long.MAX_VALUE)).isTrue(); + } + @Test public void verifyWithinGasLimitDelta() { final long targetGasLimit = 10_000_000L; From 391d6700262712ccb7133deed5038d78cb1b0bd4 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Tue, 19 Mar 2024 08:53:35 +1000 Subject: [PATCH 16/22] disable not ignore (#6754) Signed-off-by: Sally MacFarlane --- .../jsonrpc/EthSendRawTransactionAcceptanceTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthSendRawTransactionAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthSendRawTransactionAcceptanceTest.java index b09bf1d5f91..164393664bb 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthSendRawTransactionAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthSendRawTransactionAcceptanceTest.java @@ -24,8 +24,8 @@ import java.math.BigInteger; import java.util.function.UnaryOperator; -import org.junit.Ignore; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; public class EthSendRawTransactionAcceptanceTest extends AcceptanceTestBase { @@ -52,7 +52,7 @@ public void setUp() throws Exception { } @Test - @Ignore("flaky with timeout") + @Disabled("flaky with timeout") public void shouldSendSuccessfullyToLenientNodeWithoutChainId() { final TransferTransaction tx = createTransactionWithoutChainId(); final String rawTx = tx.signedTransactionData(); From 578d14ec26e6e4e433d7f0efcce0d7956e090c56 Mon Sep 17 00:00:00 2001 From: Justin Florentine Date: Mon, 18 Mar 2024 21:05:48 -0400 Subject: [PATCH 17/22] uprevved kzg library dependency, aligns version num with upstream (#6745) Signed-off-by: Justin Florentine --- gradle/verification-metadata.xml | 14 +++++++------- gradle/versions.gradle | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index cf5b501ba8a..9d36f782098 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -5976,15 +5976,15 @@ - - - + + + - - + + - - + + diff --git a/gradle/versions.gradle b/gradle/versions.gradle index cb66d14dce3..dbe70c1d608 100644 --- a/gradle/versions.gradle +++ b/gradle/versions.gradle @@ -158,7 +158,7 @@ dependencyManagement { dependency 'org.fusesource.jansi:jansi:2.4.1' dependency 'org.openjdk.jol:jol-core:0.17' - dependency 'tech.pegasys:jc-kzg-4844:0.8.0' + dependency 'tech.pegasys:jc-kzg-4844:1.0.0' dependencySet(group: 'org.hyperledger.besu', version: '0.8.2') { entry 'arithmetic' From cc201691f9ffb5bc974a107ff3059b4b3871d283 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Tue, 19 Mar 2024 13:31:07 +1000 Subject: [PATCH 18/22] allow empty maxFeePerBlobGas for eth_call (#6731) * allow empty blob gas for eth_call * handle empty maxFeePerBlobGas by setting to blobBaseFee if empty * set allowExceedingBalance if blobGas not specified * added a test case for strict with zero blob gas Signed-off-by: Sally MacFarlane --------- Signed-off-by: Sally MacFarlane Co-authored-by: Justin Florentine --- CHANGELOG.md | 9 ++--- .../api/jsonrpc/internal/methods/EthCall.java | 5 +++ ...th_call_blob_missing_maxFeePerBlobGas.json | 2 +- ..._blob_missing_maxFeePerBlobGas_strict.json | 25 +++++++++++++ .../jsonrpc/eth/eth_call_blob_zero_fee.json | 2 +- .../mainnet/MainnetTransactionValidator.java | 3 +- .../ethereum/transaction/CallParameter.java | 2 +- .../transaction/TransactionSimulator.java | 36 +++++++++++-------- .../MainnetTransactionValidatorTest.java | 2 +- 9 files changed, 63 insertions(+), 23 deletions(-) create mode 100644 ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_blob_missing_maxFeePerBlobGas_strict.json diff --git a/CHANGELOG.md b/CHANGELOG.md index b1e07c26d4a..8a6dbbde8af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,15 +13,16 @@ ### Additions and Improvements - `txpool_besuPendingTransactions`change parameter `numResults` to optional parameter [#6708](https://github.com/hyperledger/besu/pull/6708) - Extend `Blockchain` service [#6592](https://github.com/hyperledger/besu/pull/6592) -- Add bft-style blockperiodseconds transitions to Clique [#6596](https://github.com/hyperledger/besu/pull/6596) -- Add createemptyblocks transitions to Clique [#6608](https://github.com/hyperledger/besu/pull/6608) +- Add bft-style `blockperiodseconds` transitions to Clique [#6596](https://github.com/hyperledger/besu/pull/6596) +- Add `createemptyblocks` transitions to Clique [#6608](https://github.com/hyperledger/besu/pull/6608) - RocksDB database metadata refactoring [#6555](https://github.com/hyperledger/besu/pull/6555) -- Make layered txpool aware of minGasPrice and minPriorityFeePerGas dynamic options [#6611](https://github.com/hyperledger/besu/pull/6611) +- Make layered txpool aware of `minGasPrice` and `minPriorityFeePerGas` dynamic options [#6611](https://github.com/hyperledger/besu/pull/6611) - Update commons-compress to 1.26.0 [#6648](https://github.com/hyperledger/besu/pull/6648) - Update Vert.x to 4.5.4 [#6666](https://github.com/hyperledger/besu/pull/6666) - Refactor and extend `TransactionPoolValidatorService` [#6636](https://github.com/hyperledger/besu/pull/6636) -- Transaction call object to accept both `input` and `data` field simultaneously if they are set to equal values [#6702](https://github.com/hyperledger/besu/pull/6702) - Introduce `TransactionSimulationService` [#6686](https://github.com/hyperledger/besu/pull/6686) +- Transaction call object to accept both `input` and `data` field simultaneously if they are set to equal values [#6702](https://github.com/hyperledger/besu/pull/6702) +- `eth_call` for blob tx allows for empty `maxFeePerBlobGas` [#6731](https://github.com/hyperledger/besu/pull/6731) ### Bug fixes - Fix txpool dump/restore race condition [#6665](https://github.com/hyperledger/besu/pull/6665) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java index 698685f7457..989041547a6 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java @@ -164,6 +164,11 @@ private boolean isAllowExceedingBalanceAutoSelection( callParams.getGasPrice() == null || Wei.ZERO.equals(callParams.getGasPrice()); if (header.getBaseFee().isPresent()) { + if (callParams.getBlobVersionedHashes().isPresent() + && (callParams.getMaxFeePerBlobGas().isEmpty() + || callParams.getMaxFeePerBlobGas().get().equals(Wei.ZERO))) { + return true; + } boolean isZeroMaxFeePerGas = callParams.getMaxFeePerGas().orElse(Wei.ZERO).equals(Wei.ZERO); boolean isZeroMaxPriorityFeePerGas = callParams.getMaxPriorityFeePerGas().orElse(Wei.ZERO).equals(Wei.ZERO); diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_blob_missing_maxFeePerBlobGas.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_blob_missing_maxFeePerBlobGas.json index fd563c0c1de..2f92e43f7ae 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_blob_missing_maxFeePerBlobGas.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_blob_missing_maxFeePerBlobGas.json @@ -16,7 +16,7 @@ "response": { "jsonrpc": "2.0", "id": 4, - "error":{"code":-32603,"message":"Internal error"} + "result": "0x0000000000000000000000000000000000000000000000000000000000000001" }, "statusCode": 200 } \ No newline at end of file diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_blob_missing_maxFeePerBlobGas_strict.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_blob_missing_maxFeePerBlobGas_strict.json new file mode 100644 index 00000000000..3c16f9c0bf8 --- /dev/null +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_blob_missing_maxFeePerBlobGas_strict.json @@ -0,0 +1,25 @@ +{ + "request": { + "id": 4, + "jsonrpc": "2.0", + "method": "eth_call", + "params": [ + { + "to": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f", + "from": "a94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "data": "0x12a7b914", + "blobVersionedHashes" : ["0x0100000051c8833cfbaf272e62da1285b183b0405357f62b052a4894ffcdaa2d"], + "gasPrice": "0x000000000000000000000000000000000000000000000000000000003437004a", + "maxFeePerBlobGas": "0x0000000000000000000000000000000000000000000000000000000000000000", + "strict": true + }, + "latest" + ] + }, + "response": { + "jsonrpc": "2.0", + "id": 4, + "error":{"code":-32009,"message":"blob gas price below current blob base fee"} + }, + "statusCode": 200 +} \ No newline at end of file diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_blob_zero_fee.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_blob_zero_fee.json index f580e45d917..3b5d4a61194 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_blob_zero_fee.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_blob_zero_fee.json @@ -17,7 +17,7 @@ "response": { "jsonrpc": "2.0", "id": 4, - "error":{"code":-32009,"message":"blob gas price below current blob base fee"} + "result": "0x0000000000000000000000000000000000000000000000000000000000000001" }, "statusCode": 200 } \ No newline at end of file diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidator.java index 68eebe5e47c..b23b056692d 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidator.java @@ -173,12 +173,13 @@ private ValidationResult validateCostAndFee( if (maybeBlobFee.isEmpty()) { throw new IllegalArgumentException( "blob fee must be provided from blocks containing blobs"); + // tx.getMaxFeePerBlobGas can be empty for eth_call } else if (!transactionValidationParams.allowUnderpriced() && maybeBlobFee.get().compareTo(transaction.getMaxFeePerBlobGas().get()) > 0) { return ValidationResult.invalid( TransactionInvalidReason.BLOB_GAS_PRICE_BELOW_CURRENT_BLOB_BASE_FEE, String.format( - "max fee per blob gas less than block blob gas fee: address %s blobGasFeeCap: %s, blobBaseFee: %s", + "tx max fee per blob gas less than block blob gas fee: address %s blobGasFeeCap: %s, blobBaseFee: %s", transaction.getSender().toHexString(), transaction.getMaxFeePerBlobGas().get().toHumanReadableString(), maybeBlobFee.get().toHumanReadableString())); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/CallParameter.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/CallParameter.java index d74f17baef8..292c65cac61 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/CallParameter.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/CallParameter.java @@ -26,7 +26,7 @@ import org.apache.tuweni.bytes.Bytes; -// Represents parameters for a eth_call or eth_estimateGas JSON-RPC methods. +// Represents parameters for eth_call and eth_estimateGas JSON-RPC methods. public class CallParameter { private final Address from; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java index 842dc360848..c0cf365bbc5 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java @@ -247,6 +247,18 @@ public Optional processWithWorldUpdater( final MainnetTransactionProcessor transactionProcessor = protocolSchedule.getByBlockHeader(blockHeaderToProcess).getTransactionProcessor(); + final Optional maybeParentHeader = + blockchain.getBlockHeader(blockHeaderToProcess.getParentHash()); + final Wei blobGasPrice = + transactionValidationParams.isAllowExceedingBalance() + ? Wei.ZERO + : protocolSpec + .getFeeMarket() + .blobGasPricePerGas( + maybeParentHeader + .map(parent -> calculateExcessBlobGasForParent(protocolSpec, parent)) + .orElse(BlobGas.ZERO)); + final Optional maybeTransaction = buildTransaction( callParams, @@ -256,21 +268,12 @@ public Optional processWithWorldUpdater( nonce, gasLimit, value, - payload); + payload, + blobGasPrice); if (maybeTransaction.isEmpty()) { return Optional.empty(); } - final Optional maybeParentHeader = - blockchain.getBlockHeader(blockHeaderToProcess.getParentHash()); - final Wei blobGasPrice = - protocolSpec - .getFeeMarket() - .blobGasPricePerGas( - maybeParentHeader - .map(parent -> calculateExcessBlobGasForParent(protocolSpec, parent)) - .orElse(BlobGas.ZERO)); - final Transaction transaction = maybeTransaction.get(); final TransactionProcessingResult result = transactionProcessor.processTransaction( @@ -298,7 +301,8 @@ private Optional buildTransaction( final long nonce, final long gasLimit, final Wei value, - final Bytes payload) { + final Bytes payload, + final Wei blobGasPrice) { final Transaction.Builder transactionBuilder = Transaction.builder() .nonce(nonce) @@ -313,20 +317,21 @@ private Optional buildTransaction( callParams.getAccessList().ifPresent(transactionBuilder::accessList); // Set versioned hashes if present callParams.getBlobVersionedHashes().ifPresent(transactionBuilder::versionedHashes); - // Set max fee per blob gas if present - callParams.getMaxFeePerBlobGas().ifPresent(transactionBuilder::maxFeePerBlobGas); final Wei gasPrice; final Wei maxFeePerGas; final Wei maxPriorityFeePerGas; + final Wei maxFeePerBlobGas; if (transactionValidationParams.isAllowExceedingBalance()) { gasPrice = Wei.ZERO; maxFeePerGas = Wei.ZERO; maxPriorityFeePerGas = Wei.ZERO; + maxFeePerBlobGas = Wei.ZERO; } else { gasPrice = callParams.getGasPrice() != null ? callParams.getGasPrice() : Wei.ZERO; maxFeePerGas = callParams.getMaxFeePerGas().orElse(gasPrice); maxPriorityFeePerGas = callParams.getMaxPriorityFeePerGas().orElse(gasPrice); + maxFeePerBlobGas = callParams.getMaxFeePerBlobGas().orElse(blobGasPrice); } if (header.getBaseFee().isEmpty()) { transactionBuilder.gasPrice(gasPrice); @@ -337,6 +342,9 @@ private Optional buildTransaction( } transactionBuilder.guessType(); + if (transactionBuilder.getTransactionType().supportsBlob()) { + transactionBuilder.maxFeePerBlobGas(maxFeePerBlobGas); + } if (transactionBuilder.getTransactionType().requiresChainId()) { transactionBuilder.chainId( protocolSchedule diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidatorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidatorTest.java index b0e555c9dd0..6ec75e0e645 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidatorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidatorTest.java @@ -358,7 +358,7 @@ public void shouldRejectTransactionWithMaxBlobPriorityFeeSmallerThanBlobBaseFee( .isEqualTo(ValidationResult.invalid(BLOB_GAS_PRICE_BELOW_CURRENT_BLOB_BASE_FEE)); assertThat(validationResult.getErrorMessage()) .matches( - "max fee per blob gas less than block blob gas fee: address 0x[0-9a-f]+ blobGasFeeCap: 7 wei, blobBaseFee: 10 wei"); + "tx max fee per blob gas less than block blob gas fee: address 0x[0-9a-f]+ blobGasFeeCap: 7 wei, blobBaseFee: 10 wei"); } @Test From 42b32d253142a599f9633e7332a8fe715094ab33 Mon Sep 17 00:00:00 2001 From: Matt Whitehead Date: Tue, 19 Mar 2024 08:57:51 +0000 Subject: [PATCH 19/22] Log an info message on startup to indicate if IPv6 peer connectivity is possible (#6750) Signed-off-by: Matthew Whitehead --- .../besu/ethereum/p2p/discovery/PeerDiscoveryAgent.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryAgent.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryAgent.java index b93846bfbe1..d1f17b5304e 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryAgent.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryAgent.java @@ -151,7 +151,11 @@ public CompletableFuture start(final int tcpPort) { if (config.isActive()) { final String host = config.getBindHost(); final int port = config.getBindPort(); - LOG.info("Starting peer discovery agent on host={}, port={}", host, port); + LOG.info( + "Starting peer discovery agent on host={}, port={}. IPv6 {}.", + host, + port, + NetworkUtility.isIPv6Available() ? "available" : "not available"); // override advertised host if we detect an external IP address via NAT manager this.advertisedAddress = natService.queryExternalIPAddress(config.getAdvertisedHost()); From 2bfd51078502c029a4ce9e206d908ae92eb540f0 Mon Sep 17 00:00:00 2001 From: Danno Ferrin Date: Tue, 19 Mar 2024 09:51:43 -0700 Subject: [PATCH 20/22] Log blob count (#6761) Current blog logging shows blob transaction count. The blob count is more relevant and reflects the label better. Signed-off-by: Danno Ferrin (shemnon) --- .../internal/methods/engine/AbstractEngineNewPayload.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 a0c86d942c4..361f3c8f64d 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 @@ -320,7 +320,13 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext) if (executionResult.isSuccessful()) { logImportedBlockInfo( - block, blobTransactions.size(), (System.currentTimeMillis() - startTimeMs) / 1000.0); + block, + blobTransactions.stream() + .map(Transaction::getVersionedHashes) + .flatMap(Optional::stream) + .mapToInt(List::size) + .sum(), + (System.currentTimeMillis() - startTimeMs) / 1000.0); return respondWith(reqId, blockParam, newBlockHeader.getHash(), VALID); } else { if (executionResult.causedBy().isPresent()) { From 86cc6cb19e687aff4f4e53936df3a19f9f28067c Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Wed, 20 Mar 2024 21:31:29 +0100 Subject: [PATCH 21/22] Extend error handling of plugin RPC methods (#6759) Signed-off-by: Fabio Di Fabio --- CHANGELOG.md | 1 + .../TransactionSimulationServiceImpl.java | 23 ++- .../EthEstimateGasIntegrationTest.java | 13 +- .../api/jsonrpc/JsonRpcErrorConverter.java | 2 + .../internal/methods/AbstractEstimateGas.java | 7 +- .../internal/methods/PluginJsonRpcMethod.java | 9 +- .../internal/response/JsonRpcError.java | 31 ++-- .../internal/response/RpcErrorType.java | 28 ++- .../jsonrpc/JsonRpcHttpServiceTestBase.java | 5 +- .../api/jsonrpc/PluginJsonRpcMethodTest.java | 173 ++++++++++++++++++ .../internal/methods/EthEstimateGasTest.java | 23 ++- .../TransactionProcessingResult.java | 5 +- .../transaction/TransactionInvalidReason.java | 1 + plugin-api/build.gradle | 2 +- .../data/TransactionSimulationResult.java | 22 +++ .../exception/PluginRpcEndpointException.java | 38 +++- .../plugin/services/rpc/RpcMethodError.java | 51 ++++++ 17 files changed, 369 insertions(+), 65 deletions(-) create mode 100644 ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/PluginJsonRpcMethodTest.java create mode 100644 plugin-api/src/main/java/org/hyperledger/besu/plugin/services/rpc/RpcMethodError.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a6dbbde8af..eefdbec72e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ - Introduce `TransactionSimulationService` [#6686](https://github.com/hyperledger/besu/pull/6686) - Transaction call object to accept both `input` and `data` field simultaneously if they are set to equal values [#6702](https://github.com/hyperledger/besu/pull/6702) - `eth_call` for blob tx allows for empty `maxFeePerBlobGas` [#6731](https://github.com/hyperledger/besu/pull/6731) +- Extend error handling of plugin RPC methods [#6759](https://github.com/hyperledger/besu/pull/6759) ### Bug fixes - Fix txpool dump/restore race condition [#6665](https://github.com/hyperledger/besu/pull/6665) diff --git a/besu/src/main/java/org/hyperledger/besu/services/TransactionSimulationServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/TransactionSimulationServiceImpl.java index 5ebf48f0cef..0981e1ae34c 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/TransactionSimulationServiceImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/TransactionSimulationServiceImpl.java @@ -19,7 +19,10 @@ import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.mainnet.ImmutableTransactionValidationParams; import org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams; +import org.hyperledger.besu.ethereum.mainnet.ValidationResult; +import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; import org.hyperledger.besu.ethereum.transaction.CallParameter; +import org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason; import org.hyperledger.besu.ethereum.transaction.TransactionSimulator; import org.hyperledger.besu.evm.tracing.OperationTracer; import org.hyperledger.besu.plugin.Unstable; @@ -62,14 +65,16 @@ public Optional simulate( final CallParameter callParameter = CallParameter.fromTransaction(transaction); - final var blockHeader = - blockchain - .getBlockHeader(blockHash) - .or(() -> blockchain.getBlockHeaderSafe(blockHash)) - .orElseThrow( - () -> - new IllegalStateException( - "Block header not yet present for chain head hash: " + blockHash)); + final var maybeBlockHeader = + blockchain.getBlockHeader(blockHash).or(() -> blockchain.getBlockHeaderSafe(blockHash)); + + if (maybeBlockHeader.isEmpty()) { + return Optional.of( + new TransactionSimulationResult( + transaction, + TransactionProcessingResult.invalid( + ValidationResult.invalid(TransactionInvalidReason.BLOCK_NOT_FOUND)))); + } return transactionSimulator .process( @@ -78,7 +83,7 @@ public Optional simulate( ? SIMULATOR_ALLOWING_EXCEEDING_BALANCE : TransactionValidationParams.transactionSimulator(), operationTracer, - blockHeader) + maybeBlockHeader.get()) .map(res -> new TransactionSimulationResult(transaction, res.result())); } } diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthEstimateGasIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthEstimateGasIntegrationTest.java index ca64e046fd1..a461539030f 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthEstimateGasIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthEstimateGasIntegrationTest.java @@ -28,7 +28,8 @@ 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.mainnet.ValidationResult; +import org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason; import org.hyperledger.besu.testutil.BlockTestUtil; import java.util.Map; @@ -171,11 +172,11 @@ public void shouldNotIgnoreSenderBalanceAccountWhenStrictModeDisabledAndThrowErr null, null); final JsonRpcRequestContext request = requestWithParams(callParameter); - - final RpcErrorType rpcErrorType = RpcErrorType.TRANSACTION_UPFRONT_COST_EXCEEDS_BALANCE; - final JsonRpcError rpcError = new JsonRpcError(rpcErrorType); - rpcError.setReason( - "transaction up-front cost 0x1cc31b3333167018 exceeds transaction sender account balance 0x140"); + final ValidationResult validationResult = + ValidationResult.invalid( + TransactionInvalidReason.UPFRONT_COST_EXCEEDS_BALANCE, + "transaction up-front cost 0x1cc31b3333167018 exceeds transaction sender account balance 0x140"); + final JsonRpcError rpcError = JsonRpcError.from(validationResult); final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse(null, rpcError); final JsonRpcResponse response = method.response(request); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcErrorConverter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcErrorConverter.java index c583401b3f1..30ad7917a67 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcErrorConverter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcErrorConverter.java @@ -83,6 +83,8 @@ public static RpcErrorType convertTransactionInvalidReason( return RpcErrorType.BLOB_GAS_PRICE_BELOW_CURRENT_BLOB_BASE_FEE; case EXECUTION_HALTED: return RpcErrorType.EXECUTION_HALTED; + case BLOCK_NOT_FOUND: + return RpcErrorType.BLOCK_NOT_FOUND; default: return RpcErrorType.INTERNAL_ERROR; } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractEstimateGas.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractEstimateGas.java index 0f9b1b7be14..237eef2e022 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractEstimateGas.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractEstimateGas.java @@ -111,12 +111,7 @@ protected JsonRpcErrorResponse errorResponse( result.getValidationResult(); if (validationResult != null && !validationResult.isValid()) { if (validationResult.getErrorMessage().length() > 0) { - final RpcErrorType rpcErrorType = - JsonRpcErrorConverter.convertTransactionInvalidReason( - validationResult.getInvalidReason()); - final JsonRpcError rpcError = new JsonRpcError(rpcErrorType); - rpcError.setReason(validationResult.getErrorMessage()); - return errorResponse(request, rpcError); + return errorResponse(request, JsonRpcError.from(validationResult)); } return errorResponse( request, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/PluginJsonRpcMethod.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/PluginJsonRpcMethod.java index 46f9986b1c2..702404ae4bc 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/PluginJsonRpcMethod.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/PluginJsonRpcMethod.java @@ -14,9 +14,6 @@ */ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods; -import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType.INTERNAL_ERROR; -import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType.PLUGIN_INTERNAL_ERROR; - import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; @@ -53,13 +50,9 @@ public JsonRpcResponse response(final JsonRpcRequestContext request) { final Object result = function.apply(() -> request.getRequest().getParams()); return new JsonRpcSuccessResponse(request.getRequest().getId(), result); } catch (final PluginRpcEndpointException ex) { - final JsonRpcError error = new JsonRpcError(PLUGIN_INTERNAL_ERROR, ex.getMessage()); + final JsonRpcError error = new JsonRpcError(ex.getRpcMethodError(), ex.getMessage()); LOG.error("Error calling plugin JSON-RPC endpoint", ex); return new JsonRpcErrorResponse(request.getRequest().getId(), error); - } catch (final Exception ex) { - LOG.error("Error calling plugin JSON-RPC endpoint", ex); - return new JsonRpcErrorResponse( - request.getRequest().getId(), new JsonRpcError(INTERNAL_ERROR)); } } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/response/JsonRpcError.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/response/JsonRpcError.java index a3a3427de2b..59bb92c4433 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/response/JsonRpcError.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/response/JsonRpcError.java @@ -14,6 +14,11 @@ */ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.response; +import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcErrorConverter; +import org.hyperledger.besu.ethereum.mainnet.ValidationResult; +import org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason; +import org.hyperledger.besu.plugin.services.rpc.RpcMethodError; + import java.util.Objects; import com.fasterxml.jackson.annotation.JsonCreator; @@ -21,7 +26,6 @@ import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.tuweni.bytes.Bytes; @JsonInclude(value = JsonInclude.Include.NON_NULL) @JsonFormat(shape = JsonFormat.Shape.OBJECT) @@ -41,16 +45,11 @@ public JsonRpcError( this.data = data; } - public JsonRpcError(final RpcErrorType errorType, final String data) { + public JsonRpcError(final RpcMethodError errorType, final String data) { this(errorType.getCode(), errorType.getMessage(), data); - // For execution reverted errors decode the data (if present) - if (errorType == RpcErrorType.REVERT_ERROR && data != null) { - JsonRpcErrorResponse.decodeRevertReason(Bytes.fromHexString(data)) - .ifPresent( - (decodedReason) -> { - this.reason = decodedReason; - }); + if (data != null) { + errorType.decodeData(data).ifPresent(decodedData -> this.reason = decodedData); } } @@ -58,6 +57,16 @@ public JsonRpcError(final RpcErrorType errorType) { this(errorType, null); } + public static JsonRpcError from( + final ValidationResult validationResult) { + final var jsonRpcError = + new JsonRpcError( + JsonRpcErrorConverter.convertTransactionInvalidReason( + validationResult.getInvalidReason())); + jsonRpcError.reason = validationResult.getErrorMessage(); + return jsonRpcError; + } + @JsonGetter("code") public int getCode() { return code; @@ -73,10 +82,6 @@ public String getData() { return data; } - public void setReason(final String reason) { - this.reason = reason; - } - @Override public boolean equals(final Object o) { if (this == o) { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/response/RpcErrorType.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/response/RpcErrorType.java index 17d6d229fb3..3a13c5a8903 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/response/RpcErrorType.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/response/RpcErrorType.java @@ -14,7 +14,14 @@ */ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.response; -public enum RpcErrorType { +import org.hyperledger.besu.plugin.services.rpc.RpcMethodError; + +import java.util.Optional; +import java.util.function.Function; + +import org.apache.tuweni.bytes.Bytes; + +public enum RpcErrorType implements RpcMethodError { // Standard errors PARSE_ERROR(-32700, "Parse error"), INVALID_REQUEST(-32600, "Invalid Request"), @@ -67,7 +74,10 @@ public enum RpcErrorType { REPLAY_PROTECTED_SIGNATURES_NOT_SUPPORTED(-32000, "ChainId not supported"), REPLAY_PROTECTED_SIGNATURE_REQUIRED(-32000, "ChainId is required"), TX_FEECAP_EXCEEDED(-32000, "Transaction fee cap exceeded"), - REVERT_ERROR(-32000, "Execution reverted"), + REVERT_ERROR( + -32000, + "Execution reverted", + data -> JsonRpcErrorResponse.decodeRevertReason(Bytes.fromHexString(data))), TRANSACTION_NOT_FOUND(-32000, "Transaction not found"), MAX_PRIORITY_FEE_PER_GAS_EXCEEDS_MAX_FEE_PER_GAS( -32000, "Max priority fee per gas exceeds max fee per gas"), @@ -222,17 +232,31 @@ public enum RpcErrorType { private final int code; private final String message; + private final Function> dataDecoder; RpcErrorType(final int code, final String message) { + this(code, message, null); + } + + RpcErrorType( + final int code, final String message, Function> dataDecoder) { this.code = code; this.message = message; + this.dataDecoder = dataDecoder; } + @Override public int getCode() { return code; } + @Override public String getMessage() { return message; } + + @Override + public Optional decodeData(final String data) { + return dataDecoder == null ? Optional.empty() : dataDecoder.apply(data); + } } 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 a5f90791ce6..159e99b0bfb 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 @@ -152,8 +152,7 @@ public static void initServerAndClient() throws Exception { baseUrl = service.url(); } - protected static JsonRpcHttpService createJsonRpcHttpService(final JsonRpcConfiguration config) - throws Exception { + protected static JsonRpcHttpService createJsonRpcHttpService(final JsonRpcConfiguration config) { return new JsonRpcHttpService( vertx, folder, @@ -165,7 +164,7 @@ protected static JsonRpcHttpService createJsonRpcHttpService(final JsonRpcConfig HealthService.ALWAYS_HEALTHY); } - protected static JsonRpcHttpService createJsonRpcHttpService() throws Exception { + protected static JsonRpcHttpService createJsonRpcHttpService() { return new JsonRpcHttpService( vertx, folder, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/PluginJsonRpcMethodTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/PluginJsonRpcMethodTest.java new file mode 100644 index 00000000000..560a79a8bf8 --- /dev/null +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/PluginJsonRpcMethodTest.java @@ -0,0 +1,173 @@ +/* + * Copyright Hyperledger Besu contributors + * + * 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; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.PluginJsonRpcMethod; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; +import org.hyperledger.besu.plugin.services.exception.PluginRpcEndpointException; +import org.hyperledger.besu.plugin.services.rpc.PluginRpcRequest; +import org.hyperledger.besu.plugin.services.rpc.RpcMethodError; + +import io.vertx.core.json.JsonObject; +import okhttp3.RequestBody; +import okhttp3.Response; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +public class PluginJsonRpcMethodTest extends JsonRpcHttpServiceTestBase { + + @BeforeAll + public static void setup() throws Exception { + initServerAndClient(); + } + + /** Tears down the HTTP server. */ + @AfterAll + public static void shutdownServer() { + service.stop().join(); + } + + @Test + public void happyPath() throws Exception { + final var request = + """ + {"jsonrpc":"2.0","id":1,"method":"plugin_echo","params":["hello"]}"""; + + try (var unused = + addRpcMethod( + "plugin_echo", + new PluginJsonRpcMethod("plugin_echo", PluginJsonRpcMethodTest::echoPluginRpcMethod))) { + final RequestBody body = RequestBody.create(request, JSON); + + try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { + assertThat(resp.code()).isEqualTo(200); + final JsonObject json = new JsonObject(resp.body().string()); + testHelper.assertValidJsonRpcResult(json, 1); + assertThat(json.getString("result")).isEqualTo("hello"); + } + } + } + + @Test + public void invalidJsonShouldReturnParseError() throws Exception { + final var malformedRequest = + """ + {"jsonrpc":"2.0","id":1,"method":"plugin_echo","params":}"""; + + try (var unused = + addRpcMethod( + "plugin_echo", + new PluginJsonRpcMethod("plugin_echo", PluginJsonRpcMethodTest::echoPluginRpcMethod))) { + final RequestBody body = RequestBody.create(malformedRequest, JSON); + + try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { + assertThat(resp.code()).isEqualTo(400); + final JsonObject json = new JsonObject(resp.body().string()); + final JsonRpcError expectedError = new JsonRpcError(RpcErrorType.PARSE_ERROR); + testHelper.assertValidJsonRpcError( + json, null, expectedError.getCode(), expectedError.getMessage()); + } + } + } + + @Test + public void invalidParamsShouldReturnInvalidParams() throws Exception { + final var missingRequiredParam = + """ + {"jsonrpc":"2.0","id":1,"method":"plugin_echo","params":[]}"""; + try (var unused = + addRpcMethod( + "plugin_echo", + new PluginJsonRpcMethod("plugin_echo", PluginJsonRpcMethodTest::echoPluginRpcMethod))) { + final RequestBody body = RequestBody.create(missingRequiredParam, JSON); + + try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { + assertThat(resp.code()).isEqualTo(200); + final JsonObject json = new JsonObject(resp.body().string()); + final JsonRpcError expectedError = new JsonRpcError(RpcErrorType.INVALID_PARAMS); + testHelper.assertValidJsonRpcError( + json, 1, expectedError.getCode(), expectedError.getMessage()); + } + } + } + + @Test + public void methodErrorShouldReturnErrorResponse() throws Exception { + final var wrongParamContent = + """ + {"jsonrpc":"2.0","id":1,"method":"plugin_echo","params":[" "]}"""; + try (var unused = + addRpcMethod( + "plugin_echo", + new PluginJsonRpcMethod("plugin_echo", PluginJsonRpcMethodTest::echoPluginRpcMethod))) { + final RequestBody body = RequestBody.create(wrongParamContent, JSON); + + try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { + assertThat(resp.code()).isEqualTo(200); + final JsonObject json = new JsonObject(resp.body().string()); + testHelper.assertValidJsonRpcError(json, 1, -1, "Blank input not allowed"); + } + } + } + + @Test + public void unhandledExceptionShouldReturnInternalErrorResponse() throws Exception { + final var nullParam = + """ + {"jsonrpc":"2.0","id":1,"method":"plugin_echo","params":[null]}"""; + try (var unused = + addRpcMethod( + "plugin_echo", + new PluginJsonRpcMethod("plugin_echo", PluginJsonRpcMethodTest::echoPluginRpcMethod))) { + final RequestBody body = RequestBody.create(nullParam, JSON); + + try (final Response resp = client.newCall(buildPostRequest(body)).execute()) { + assertThat(resp.code()).isEqualTo(200); + final JsonObject json = new JsonObject(resp.body().string()); + final JsonRpcError expectedError = new JsonRpcError(RpcErrorType.INTERNAL_ERROR); + testHelper.assertValidJsonRpcError( + json, 1, expectedError.getCode(), expectedError.getMessage()); + } + } + } + + private static Object echoPluginRpcMethod(final PluginRpcRequest request) { + final var params = request.getParams(); + if (params.length == 0) { + throw new InvalidJsonRpcParameters("parameter is mandatory"); + } + final var input = params[0]; + if (input.toString().isBlank()) { + throw new PluginRpcEndpointException( + new RpcMethodError() { + @Override + public int getCode() { + return -1; + } + + @Override + public String getMessage() { + return "Blank input not allowed"; + } + }); + } + return input; + } +} diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java index 64d015d89a0..98b9226404a 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java @@ -219,9 +219,11 @@ public void shouldReturnErrorWhenLegacyTransactionProcessorReturnsTxInvalidReaso TransactionInvalidReason.UPFRONT_COST_EXCEEDS_BALANCE, "transaction up-front cost 10 exceeds transaction sender account balance 5"); - final RpcErrorType rpcErrorType = RpcErrorType.TRANSACTION_UPFRONT_COST_EXCEEDS_BALANCE; - final JsonRpcError rpcError = new JsonRpcError(rpcErrorType); - rpcError.setReason("transaction up-front cost 10 exceeds transaction sender account balance 5"); + final ValidationResult validationResult = + ValidationResult.invalid( + TransactionInvalidReason.UPFRONT_COST_EXCEEDS_BALANCE, + "transaction up-front cost 10 exceeds transaction sender account balance 5"); + final JsonRpcError rpcError = JsonRpcError.from(validationResult); final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse(null, rpcError); Assertions.assertThat(method.response(request)) @@ -235,10 +237,11 @@ public void shouldReturnErrorWhenEip1559TransactionProcessorReturnsTxInvalidReas mockTransientProcessorResultTxInvalidReason( TransactionInvalidReason.UPFRONT_COST_EXCEEDS_BALANCE, "transaction up-front cost 10 exceeds transaction sender account balance 5"); - - final RpcErrorType rpcErrorType = RpcErrorType.TRANSACTION_UPFRONT_COST_EXCEEDS_BALANCE; - final JsonRpcError rpcError = new JsonRpcError(rpcErrorType); - rpcError.setReason("transaction up-front cost 10 exceeds transaction sender account balance 5"); + final ValidationResult validationResult = + ValidationResult.invalid( + TransactionInvalidReason.UPFRONT_COST_EXCEEDS_BALANCE, + "transaction up-front cost 10 exceeds transaction sender account balance 5"); + final JsonRpcError rpcError = JsonRpcError.from(validationResult); final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse(null, rpcError); Assertions.assertThat(method.response(request)) @@ -384,9 +387,9 @@ public void shouldIncludeHaltReasonWhenExecutionHalts() { mockTransientProcessorResultTxInvalidReason( TransactionInvalidReason.EXECUTION_HALTED, "INVALID_OPERATION"); - final RpcErrorType rpcErrorType = RpcErrorType.EXECUTION_HALTED; - final JsonRpcError rpcError = new JsonRpcError(rpcErrorType); - rpcError.setReason("INVALID_OPERATION"); + final ValidationResult validationResult = + ValidationResult.invalid(TransactionInvalidReason.EXECUTION_HALTED, "INVALID_OPERATION"); + final JsonRpcError rpcError = JsonRpcError.from(validationResult); final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse(null, rpcError); Assertions.assertThat(method.response(request)) diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/processing/TransactionProcessingResult.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/processing/TransactionProcessingResult.java index e77062a7ddd..eca28927bdd 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/processing/TransactionProcessingResult.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/processing/TransactionProcessingResult.java @@ -18,7 +18,6 @@ import org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason; import org.hyperledger.besu.evm.log.Log; -import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -56,7 +55,7 @@ public enum Status { public static TransactionProcessingResult invalid( final ValidationResult validationResult) { return new TransactionProcessingResult( - Status.INVALID, new ArrayList<>(), -1, -1, Bytes.EMPTY, validationResult, Optional.empty()); + Status.INVALID, List.of(), -1, -1, Bytes.EMPTY, validationResult, Optional.empty()); } public static TransactionProcessingResult failed( @@ -66,7 +65,7 @@ public static TransactionProcessingResult failed( final Optional revertReason) { return new TransactionProcessingResult( Status.FAILED, - new ArrayList<>(), + List.of(), gasUsedByTransaction, gasRemaining, Bytes.EMPTY, diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionInvalidReason.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionInvalidReason.java index 0760740467f..c2d5bc3d8ab 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionInvalidReason.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionInvalidReason.java @@ -32,6 +32,7 @@ public enum TransactionInvalidReason { TX_SENDER_NOT_AUTHORIZED, CHAIN_HEAD_NOT_AVAILABLE, CHAIN_HEAD_WORLD_STATE_NOT_AVAILABLE, + BLOCK_NOT_FOUND, EXCEEDS_PER_TRANSACTION_GAS_LIMIT, INVALID_TRANSACTION_FORMAT, TRANSACTION_PRICE_TOO_LOW, diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index a0129425e21..7377359a165 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -69,7 +69,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 = 'ytjNiSzw9IR8YHyO4ikmqRTg1GTWkCX9QiQtwq2dRSg=' + knownHash = '0xiYCyr3M4oSrvqYXVkLgVDzlBg2T3fmrADub5tY5a0=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/data/TransactionSimulationResult.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/data/TransactionSimulationResult.java index 1651534a9fa..1f2e6a8ab82 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/data/TransactionSimulationResult.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/data/TransactionSimulationResult.java @@ -16,6 +16,10 @@ import org.hyperledger.besu.datatypes.Transaction; +import java.util.Optional; + +import org.apache.tuweni.bytes.Bytes; + /** * TransactionSimulationResult * @@ -43,6 +47,24 @@ public boolean isInvalid() { return result.isInvalid(); } + /** + * Return the optional revert reason + * + * @return the optional revert reason + */ + public Optional getRevertReason() { + return result.getRevertReason(); + } + + /** + * Return the optional invalid reason + * + * @return the optional invalid reason + */ + public Optional getInvalidReason() { + return result.getInvalidReason(); + } + /** * Estimated gas used by the transaction * diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/exception/PluginRpcEndpointException.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/exception/PluginRpcEndpointException.java index 9a38b891eb0..e736a1d2cf5 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/exception/PluginRpcEndpointException.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/exception/PluginRpcEndpointException.java @@ -14,28 +14,58 @@ */ package org.hyperledger.besu.plugin.services.exception; +import org.hyperledger.besu.plugin.services.rpc.RpcMethodError; + /** Base exception class for problems encountered in the RpcEndpointService. */ public class PluginRpcEndpointException extends RuntimeException { + /** The error */ + private final RpcMethodError rpcMethodError; + + /** + * Constructs a new PluginRpcEndpointException exception with the specified error. + * + * @param rpcMethodError the error. + */ + public PluginRpcEndpointException(final RpcMethodError rpcMethodError) { + super(); + this.rpcMethodError = rpcMethodError; + } + /** - * Constructs a new PluginRpcEndpointException exception with the specified message. + * Constructs a new PluginRpcEndpointException exception with the specified error and message. * + * @param rpcMethodError the error. * @param message the detail message (which is saved for later retrieval by the {@link * #getMessage()} method). */ - public PluginRpcEndpointException(final String message) { + public PluginRpcEndpointException(final RpcMethodError rpcMethodError, final String message) { super(message); + this.rpcMethodError = rpcMethodError; } /** - * Constructs a new PluginRpcEndpointException exception with the specified message. + * Constructs a new PluginRpcEndpointException exception with the specified error, message and + * cause. * + * @param rpcMethodError the error. * @param message the detail message (which is saved for later retrieval by the {@link * #getMessage()} method). * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). * (A {@code null} value is permitted, and indicates that the cause is nonexistent or * unknown.) */ - public PluginRpcEndpointException(final String message, final Throwable cause) { + public PluginRpcEndpointException( + final RpcMethodError rpcMethodError, final String message, final Throwable cause) { super(message, cause); + this.rpcMethodError = rpcMethodError; + } + + /** + * Get the error + * + * @return the error + */ + public RpcMethodError getRpcMethodError() { + return rpcMethodError; } } diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/rpc/RpcMethodError.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/rpc/RpcMethodError.java new file mode 100644 index 00000000000..c257febbc24 --- /dev/null +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/rpc/RpcMethodError.java @@ -0,0 +1,51 @@ +/* + * Copyright Hyperledger Besu Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.plugin.services.rpc; + +import java.util.Optional; + +/** + * The {@code RpcMethodError} interface defines the structure for RPC error handling within the + * context of plugins. It provides methods to retrieve error code, message, and an optional data + * decoder function. + */ +public interface RpcMethodError { + + /** + * Retrieves the error code associated with the RPC error. + * + * @return An integer representing the error code. + */ + int getCode(); + + /** + * Retrieves the message associated with the RPC error. + * + * @return A {@code String} containing the error message. + */ + String getMessage(); + + /** + * Some errors have additional data associated with them, that is possible to decode to provide a + * more detailed error response. + * + * @param data the additional data to decode + * @return an optional containing the decoded data if the error has it and the decoding is + * successful, otherwise empty. + */ + default Optional decodeData(final String data) { + return Optional.empty(); + } +} From c564fcd9193ab5d5af2261f49b064fe767b4b320 Mon Sep 17 00:00:00 2001 From: Justin Florentine Date: Wed, 20 Mar 2024 22:41:04 -0400 Subject: [PATCH 22/22] get value for sonar options from vars (#6767) Signed-off-by: Justin Florentine --- .github/workflows/sonarcloud.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 3ef37c1dafa..fc926a8adcc 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -36,6 +36,6 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - SONAR_ORGANIZATION: ${{ env.SONAR_ORGANIZATION }} - SONAR_PROJECT_KEY: $ {{ env.SONAR_PROJECT_KEY }} + SONAR_ORGANIZATION: ${{ vars.SONAR_ORGANIZATION }} + SONAR_PROJECT_KEY: $ {{ vars.SONAR_PROJECT_KEY }} run: ./gradlew build sonarqube --continue --info -Dorg.gradle.parallel=true -Dorg.gradle.caching=true