From 23604d340ce57e2b6df69558a66ae7d3b2a15204 Mon Sep 17 00:00:00 2001 From: MadelineMurray <43356962+MadelineMurray@users.noreply.github.com> Date: Wed, 6 Nov 2019 08:55:35 +1000 Subject: [PATCH 1/7] Added 1.3.3 changes (#160) * Added 1.3.3 changes * updating version number to 1.3.3 Signed-off-by: Madeline Signed-off-by: Joshua Fernandes --- CHANGELOG.md | 25 +++++++++++++++++++++++++ gradle.properties | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f12bc767046..7376bdd4cd4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,31 @@ From v1.2, Besu requires Java 11. Besu on Java 8 is no longer supported. In v1.2, we removed the entry-point script from our Docker image. Refer to the [migration guide](https://besu.hyperledger.org/en/latest/HowTo/Get-Started/Migration-Docker/) for information on options that were previously automatically added to the Besu command line. +### 1.3.3 + +### Technical Improvements + +- Add --identity flag for client identification in node browsers [\#150](https://github.com/hyperledger/besu/pull/150) +- Add priv\_getEeaTransactionCount [\#110](https://github.com/hyperledger/besu/pull/110) + +### Additions and Improvements + +- Redesign of how JsonRpcMethods are created [\#159](https://github.com/hyperledger/besu/pull/159) +- Moving JsonRpcMethods classes into the same package, prior to refactor [\#154](https://github.com/hyperledger/besu/pull/154) +- Reflect default logging in CLI help [\#148](https://github.com/hyperledger/besu/pull/148) +- Handle zero port better in NAT [\#147](https://github.com/hyperledger/besu/pull/147) +- Rework how filter and log query parameters are created/used [\#146](https://github.com/hyperledger/besu/pull/146) +- Don't generate shutdown tasks in controller [\#141](https://github.com/hyperledger/besu/pull/141) +- Ibft queries [\#138](https://github.com/hyperledger/besu/pull/138) +- Enable pruning by default for fast sync [\#135](https://github.com/hyperledger/besu/pull/135) +- Ensure spotless runs in CI [\#132](https://github.com/hyperledger/besu/pull/132) +- Add more logging around peer disconnects [\#131](https://github.com/hyperledger/besu/pull/131) +- Repair EthGetLogs returning incorrect results [\#128](https://github.com/hyperledger/besu/pull/128) +- Use Bloombits for Logs queries [\#127](https://github.com/hyperledger/besu/pull/127) +- Improve message when extraData missing [\#121](https://github.com/hyperledger/besu/pull/121) +- Fix miner startup logic [\#104](https://github.com/hyperledger/besu/pull/104) +- Support log reordring from reorgs in `LogSubscriptionService` [\#86](https://github.com/hyperledger/besu/pull/86) + ### 1.3.2 ### Additions and Improvements diff --git a/gradle.properties b/gradle.properties index 02d3c8cfdef5..2e66eba3e6bb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ org.gradle.jvmargs=-Xmx1g -version=1.3.3-SNAPSHOT +version=1.3.3 From 4549a95ec6c3d69d778ce0ec7a80a51f05f70b30 Mon Sep 17 00:00:00 2001 From: Joshua Fernandes Date: Wed, 6 Nov 2019 10:09:35 +1000 Subject: [PATCH 2/7] updating version to 1.3.4-snapshot (#162) Signed-off-by: Joshua Fernandes --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 2e66eba3e6bb..9a925430cb4f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ org.gradle.jvmargs=-Xmx1g -version=1.3.3 +version=1.3.4-SNAPSHOT From 761cfb3435fcf4b30d3fc20ef8d94183ee4ef583 Mon Sep 17 00:00:00 2001 From: Joshua Fernandes Date: Wed, 6 Nov 2019 13:24:17 +1000 Subject: [PATCH 3/7] Revert "[PAN-2798] Enable pruning by default for fast sync (#135)" (#164) This reverts commit 7e2497bf95a5673faeba439bf5da2be4b6361d5b. Signed-off-by: Joshua Fernandes --- .../org/hyperledger/besu/cli/BesuCommand.java | 13 +++---- .../controller/BesuControllerBuilder.java | 4 +-- .../hyperledger/besu/cli/BesuCommandTest.java | 35 +------------------ .../src/test/resources/everything_config.toml | 3 -- 4 files changed, 8 insertions(+), 47 deletions(-) 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 50eca10ca026..bdc4c9f61dff 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -587,9 +587,10 @@ void setBannedNodeIds(final List values) { @Option( names = {"--pruning-enabled"}, + hidden = true, description = - "Enable pruning of world state of blocks older than the retention period (default: true if fast sync is enabled, false otherwise)") - private Boolean pruningOverride; + "Enable pruning of world state of blocks older than the retention period (default: ${DEFAULT-VALUE})") + private final Boolean isPruningEnabled = false; @Option( names = {"--pruning-blocks-retained"}, @@ -1011,7 +1012,7 @@ private void issueOptionWarnings() { logger, commandLine, "--pruning-enabled", - !isPruningEnabled(), + !isPruningEnabled, asList("--pruning-block-confirmations", "--pruning-blocks-retained")); } @@ -1087,7 +1088,7 @@ public BesuControllerBuilder getControllerBuilder() { .clock(Clock.systemUTC()) .isRevertReasonEnabled(isRevertReasonEnabled) .storageProvider(keyStorageProvider(keyValueStorageName)) - .isPruningEnabled(isPruningEnabled()) + .isPruningEnabled(isPruningEnabled) .pruningConfiguration(buildPruningConfiguration()) .genesisConfigOverrides(genesisConfigOverrides) .targetGasLimit(targetGasLimit == null ? Optional.empty() : Optional.of(targetGasLimit)) @@ -1374,10 +1375,6 @@ private PruningConfiguration buildPruningConfiguration() { return new PruningConfiguration(pruningBlockConfirmations, pruningBlocksRetained); } - private boolean isPruningEnabled() { - return Optional.ofNullable(pruningOverride).orElse(syncMode == SyncMode.FAST); - } - // Blockchain synchronisation from peers. private void synchronize( final BesuController controller, diff --git a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java index c52bbadf5d95..472245fb075f 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java @@ -159,8 +159,8 @@ public BesuControllerBuilder isRevertReasonEnabled(final boolean isRevertReas return this; } - public BesuControllerBuilder isPruningEnabled(final boolean isPruningEnabled) { - this.isPruningEnabled = isPruningEnabled; + public BesuControllerBuilder isPruningEnabled(final boolean pruningEnabled) { + this.isPruningEnabled = pruningEnabled; return this; } diff --git a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java index bbc0f75fbafc..5704da843e18 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java @@ -2327,29 +2327,7 @@ public void miningParametersAreCaptured() throws Exception { } @Test - public void pruningIsEnabledIfSyncModeIsFast() { - parseCommand("--sync-mode", "FAST"); - - verify(mockControllerBuilder).isPruningEnabled(true); - verify(mockControllerBuilder).build(); - - assertThat(commandOutput.toString()).isEmpty(); - assertThat(commandErrorOutput.toString()).isEmpty(); - } - - @Test - public void pruningIsDisabledIfSyncModeIsFull() { - parseCommand("--sync-mode", "FULL"); - - verify(mockControllerBuilder).isPruningEnabled(false); - verify(mockControllerBuilder).build(); - - assertThat(commandOutput.toString()).isEmpty(); - assertThat(commandErrorOutput.toString()).isEmpty(); - } - - @Test - public void pruningEnabledExplicitly() { + public void pruningIsEnabledWhenSpecified() throws Exception { parseCommand("--pruning-enabled"); verify(mockControllerBuilder).isPruningEnabled(true); @@ -2359,17 +2337,6 @@ public void pruningEnabledExplicitly() { assertThat(commandErrorOutput.toString()).isEmpty(); } - @Test - public void pruningDisabledExplicitly() { - parseCommand("--pruning-enabled=false"); - - verify(mockControllerBuilder).isPruningEnabled(false); - verify(mockControllerBuilder).build(); - - assertThat(commandOutput.toString()).isEmpty(); - assertThat(commandErrorOutput.toString()).isEmpty(); - } - @Test public void pruningOptionsRequiresServiceToBeEnabled() { diff --git a/besu/src/test/resources/everything_config.toml b/besu/src/test/resources/everything_config.toml index b480d4f1253a..dfa3c0328595 100644 --- a/besu/src/test/resources/everything_config.toml +++ b/besu/src/test/resources/everything_config.toml @@ -83,9 +83,6 @@ miner-coinbase="0x0000000000000000000000000000000000000002" miner-extra-data="0x444F4E27542050414E4943202120484F444C2C20484F444C2C20484F444C2021" min-gas-price=1 -# Pruning -pruning-enabled=true - # Permissioning permissions-nodes-config-file-enabled=false permissions-nodes-config-file="./permissions_config.toml" From c5e51b0d2c5cf65c45c7e1a98778d6deaf8dae6d Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Wed, 6 Nov 2019 14:35:00 +1000 Subject: [PATCH 4/7] Unhide the --pruning-enabled command (#165) Signed-off-by: Adrian Sutton --- besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java | 1 - besu/src/test/resources/everything_config.toml | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) 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 bdc4c9f61dff..c665cdee2e7e 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -587,7 +587,6 @@ void setBannedNodeIds(final List values) { @Option( names = {"--pruning-enabled"}, - hidden = true, description = "Enable pruning of world state of blocks older than the retention period (default: ${DEFAULT-VALUE})") private final Boolean isPruningEnabled = false; diff --git a/besu/src/test/resources/everything_config.toml b/besu/src/test/resources/everything_config.toml index dfa3c0328595..b480d4f1253a 100644 --- a/besu/src/test/resources/everything_config.toml +++ b/besu/src/test/resources/everything_config.toml @@ -83,6 +83,9 @@ miner-coinbase="0x0000000000000000000000000000000000000002" miner-extra-data="0x444F4E27542050414E4943202120484F444C2C20484F444C2C20484F444C2021" min-gas-price=1 +# Pruning +pruning-enabled=true + # Permissioning permissions-nodes-config-file-enabled=false permissions-nodes-config-file="./permissions_config.toml" From 906674aa6fd7cdfd4ba07bc37e5df483b2e140a1 Mon Sep 17 00:00:00 2001 From: MadelineMurray <43356962+MadelineMurray@users.noreply.github.com> Date: Wed, 6 Nov 2019 15:01:50 +1000 Subject: [PATCH 5/7] Updated changelog for 1.3.4 (#167) Signed-off-by: Madeline --- CHANGELOG.md | 14 +++++++++----- gradle.properties | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7376bdd4cd4d..c9005df98ca3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,19 +1,23 @@ # Changelog -### Java 11 Required from v1.2 +## Istanbul Compatibility -From v1.2, Besu requires Java 11. Besu on Java 8 is no longer supported. +For compatibility with Ethereum Istanbul upgrade, use v1.3.4 or later. -### Docker Image Migration +## Pruning -In v1.2, we removed the entry-point script from our Docker image. Refer to the [migration guide](https://besu.hyperledger.org/en/latest/HowTo/Get-Started/Migration-Docker/) -for information on options that were previously automatically added to the Besu command line. +Pruning cannot be used in networks using private transactions. + +### 1.3.4 + +- Reverted _Enable pruning by default for fast sync (#135)_ [\#164](https://github.com/hyperledger/besu/pull/164) ### 1.3.3 ### Technical Improvements - Add --identity flag for client identification in node browsers [\#150](https://github.com/hyperledger/besu/pull/150) +- Istanbul Mainnet Block [\#145](https://github.com/hyperledger/besu/pull/150) - Add priv\_getEeaTransactionCount [\#110](https://github.com/hyperledger/besu/pull/110) ### Additions and Improvements diff --git a/gradle.properties b/gradle.properties index 9a925430cb4f..39a57e1cbb13 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ org.gradle.jvmargs=-Xmx1g -version=1.3.4-SNAPSHOT +version=1.3.4 From e3feaf25fc376aefda138cbec4201b697ae913b6 Mon Sep 17 00:00:00 2001 From: Joshua Fernandes Date: Wed, 6 Nov 2019 15:31:23 +1000 Subject: [PATCH 6/7] update ver to 1.3.5-snapshot (#169) Signed-off-by: Joshua Fernandes --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 39a57e1cbb13..5312ee02256e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ org.gradle.jvmargs=-Xmx1g -version=1.3.4 +version=1.3.5-SNAPSHOT From 1001ef37df94b309d1eb37617cb1bd5be8c86182 Mon Sep 17 00:00:00 2001 From: Gregory Markou Date: Wed, 6 Nov 2019 13:02:54 -0500 Subject: [PATCH 7/7] address pr comments Signed-off-by: Gregory Markou --- .circleci/config.yml | 5 +- .../org/hyperledger/besu/RunnerBuilder.java | 2 +- .../org/hyperledger/besu/cli/BesuCommand.java | 13 +- .../besu/cli/DefaultCommandValues.java | 2 - .../besu/controller/BesuController.java | 8 +- .../controller/BesuControllerBuilder.java | 10 +- .../CliqueBesuControllerBuilder.java | 8 +- .../controller/IbftBesuControllerBuilder.java | 8 +- .../hyperledger/besu/cli/BesuCommandTest.java | 57 ++- .../src/test/resources/everything_config.toml | 3 + .../besu/config/GenesisConfigOptions.java | 71 ++- .../besu/config/JsonGenesisConfigOptions.java | 38 +- .../besu/config/StubGenesisConfigOptions.java | 48 +- ...Factory.java => CliqueJsonRpcMethods.java} | 46 +- ...dsFactory.java => IbftJsonRpcMethods.java} | 50 +-- .../jsonrpc/JsonRpcTestMethodsFactory.java | 2 +- .../EthCallIntegrationTest.java | 2 +- .../EthEstimateGasIntegrationTest.java | 2 +- .../EthGetBlockByHashIntegrationTest.java | 2 +- .../EthGetBlockByNumberIntegrationTest.java | 2 +- .../EthGetFilterChangesIntegrationTest.java | 2 +- ...cleByBlockHashAndIndexIntegrationTest.java | 2 +- ...eByBlockNumberAndIndexIntegrationTest.java | 2 +- ...vGetPrivateTransactionIntegrationTest.java | 2 +- .../jsonrpc/method/JsonRpcMethodsFactory.java | 420 ------------------ .../jsonrpc/methods/AdminJsonRpcMethods.java | 70 +++ .../methods/ApiGroupJsonRpcMethods.java | 41 ++ .../jsonrpc/methods/DebugJsonRpcMethods.java | 80 ++++ .../jsonrpc/methods/EeaJsonRpcMethods.java | 58 +++ .../jsonrpc/methods/EthJsonRpcMethods.java | 163 +++++++ .../JsonRpcMethods.java} | 6 +- .../methods/JsonRpcMethodsFactory.java | 157 +++++++ .../jsonrpc/methods/MinerJsonRpcMethods.java | 52 +++ .../jsonrpc/methods/NetJsonRpcMethods.java | 69 +++ .../jsonrpc/methods/PermJsonRpcMethods.java | 63 +++ .../jsonrpc/methods/PrivJsonRpcMethods.java | 73 +++ .../PrivacyApiGroupJsonRpcMethods.java | 101 +++++ .../jsonrpc/methods/TraceJsonRpcMethods.java | 60 +++ .../jsonrpc/methods/TxPoolJsonRpcMethods.java | 45 ++ .../jsonrpc/methods/Web3JsonRpcMethods.java | 42 ++ .../AbstractJsonRpcHttpServiceTest.java | 2 +- .../JsonRpcHttpServiceHostWhitelistTest.java | 2 +- .../jsonrpc/JsonRpcHttpServiceLoginTest.java | 2 +- .../JsonRpcHttpServiceRpcApisTest.java | 2 +- .../api/jsonrpc/JsonRpcHttpServiceTest.java | 2 +- .../mainnet/ClassicProtocolSpecs.java | 34 -- .../ethereum/retesteth/RetestethService.java | 62 +-- 47 files changed, 1353 insertions(+), 640 deletions(-) rename consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/{CliqueJsonRpcMethodsFactory.java => CliqueJsonRpcMethods.java} (68%) rename consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/{IbftJsonRpcMethodsFactory.java => IbftJsonRpcMethods.java} (55%) rename ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/{method => methods}/EthCallIntegrationTest.java (99%) rename ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/{method => methods}/EthEstimateGasIntegrationTest.java (99%) rename ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/{method => methods}/EthGetBlockByHashIntegrationTest.java (99%) rename ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/{method => methods}/EthGetBlockByNumberIntegrationTest.java (99%) rename ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/{method => methods}/EthGetFilterChangesIntegrationTest.java (99%) rename ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/{method => methods}/EthGetUncleByBlockHashAndIndexIntegrationTest.java (98%) rename ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/{method => methods}/EthGetUncleByBlockNumberAndIndexIntegrationTest.java (98%) rename ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/{method => methods}/PrivGetPrivateTransactionIntegrationTest.java (99%) delete mode 100644 ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/JsonRpcMethodsFactory.java create mode 100644 ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/AdminJsonRpcMethods.java create mode 100644 ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/ApiGroupJsonRpcMethods.java create mode 100644 ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/DebugJsonRpcMethods.java create mode 100644 ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EeaJsonRpcMethods.java create mode 100644 ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthJsonRpcMethods.java rename ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/{method/JsonRpcMethodFactory.java => methods/JsonRpcMethods.java} (81%) create mode 100644 ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethodsFactory.java create mode 100644 ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/MinerJsonRpcMethods.java create mode 100644 ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/NetJsonRpcMethods.java create mode 100644 ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PermJsonRpcMethods.java create mode 100644 ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivJsonRpcMethods.java create mode 100644 ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivacyApiGroupJsonRpcMethods.java create mode 100644 ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/TraceJsonRpcMethods.java create mode 100644 ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/TxPoolJsonRpcMethods.java create mode 100644 ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/Web3JsonRpcMethods.java diff --git a/.circleci/config.yml b/.circleci/config.yml index d37a548f8a5c..6552dc52c30a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -53,6 +53,7 @@ commands: done - store_test_results: path: build/test-results + jobs: assemble: executor: besu_executor_xl @@ -202,7 +203,7 @@ workflows: branches: only: - master - - /^release-.*/ + #- /^release-.*/ requires: - integrationTests - unitTests @@ -214,7 +215,7 @@ workflows: branches: only: - master - - /^release-.*/ + #- /^release-.*/ requires: - integrationTests - unitTests diff --git a/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java b/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java index 0dc79f668439..6251f1cfbf8d 100644 --- a/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java @@ -36,7 +36,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterRepository; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; -import org.hyperledger.besu.ethereum.api.jsonrpc.method.JsonRpcMethodsFactory; +import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory; import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketRequestHandler; import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketService; 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 bdc4c9f61dff..50eca10ca026 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -587,10 +587,9 @@ void setBannedNodeIds(final List values) { @Option( names = {"--pruning-enabled"}, - hidden = true, description = - "Enable pruning of world state of blocks older than the retention period (default: ${DEFAULT-VALUE})") - private final Boolean isPruningEnabled = false; + "Enable pruning of world state of blocks older than the retention period (default: true if fast sync is enabled, false otherwise)") + private Boolean pruningOverride; @Option( names = {"--pruning-blocks-retained"}, @@ -1012,7 +1011,7 @@ private void issueOptionWarnings() { logger, commandLine, "--pruning-enabled", - !isPruningEnabled, + !isPruningEnabled(), asList("--pruning-block-confirmations", "--pruning-blocks-retained")); } @@ -1088,7 +1087,7 @@ public BesuControllerBuilder getControllerBuilder() { .clock(Clock.systemUTC()) .isRevertReasonEnabled(isRevertReasonEnabled) .storageProvider(keyStorageProvider(keyValueStorageName)) - .isPruningEnabled(isPruningEnabled) + .isPruningEnabled(isPruningEnabled()) .pruningConfiguration(buildPruningConfiguration()) .genesisConfigOverrides(genesisConfigOverrides) .targetGasLimit(targetGasLimit == null ? Optional.empty() : Optional.of(targetGasLimit)) @@ -1375,6 +1374,10 @@ private PruningConfiguration buildPruningConfiguration() { return new PruningConfiguration(pruningBlockConfirmations, pruningBlocksRetained); } + private boolean isPruningEnabled() { + return Optional.ofNullable(pruningOverride).orElse(syncMode == SyncMode.FAST); + } + // Blockchain synchronisation from peers. private void synchronize( final BesuController controller, diff --git a/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java b/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java index 94fb80415c67..f7c8f73f9011 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java @@ -62,8 +62,6 @@ public interface DefaultCommandValues { String PERMISSIONING_CONFIG_LOCATION = "permissions_config.toml"; String MANDATORY_HOST_FORMAT_HELP = ""; String MANDATORY_PORT_FORMAT_HELP = ""; - // Default should be FAST for the next release - // but we use FULL for the moment as Fast is still in progress SyncMode DEFAULT_SYNC_MODE = SyncMode.FULL; NatMethod DEFAULT_NAT_METHOD = NatMethod.NONE; int FAST_SYNC_MIN_PEER_COUNT = 5; diff --git a/besu/src/main/java/org/hyperledger/besu/controller/BesuController.java b/besu/src/main/java/org/hyperledger/besu/controller/BesuController.java index ef6c31918f46..452302ae48a6 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/BesuController.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/BesuController.java @@ -21,7 +21,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApi; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; -import org.hyperledger.besu.ethereum.api.jsonrpc.method.JsonRpcMethodFactory; +import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethods; import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Synchronizer; @@ -52,7 +52,7 @@ public class BesuController implements java.io.Closeable { private final SubProtocolConfiguration subProtocolConfiguration; private final KeyPair keyPair; private final Synchronizer synchronizer; - private final JsonRpcMethodFactory additionalJsonRpcMethodsFactory; + private final JsonRpcMethods additionalJsonRpcMethodsFactory; private final TransactionPool transactionPool; private final MiningCoordinator miningCoordinator; @@ -72,7 +72,7 @@ public class BesuController implements java.io.Closeable { final TransactionPool transactionPool, final MiningCoordinator miningCoordinator, final PrivacyParameters privacyParameters, - final JsonRpcMethodFactory additionalJsonRpcMethodsFactory, + final JsonRpcMethods additionalJsonRpcMethodsFactory, final KeyPair keyPair, final List closeables, final PluginServiceFactory additionalPluginServices) { @@ -147,7 +147,7 @@ public PrivacyParameters getPrivacyParameters() { public Map getAdditionalJsonRpcMethods( final Collection enabledRpcApis) { - return additionalJsonRpcMethodsFactory.createJsonRpcMethods(enabledRpcApis); + return additionalJsonRpcMethodsFactory.create(enabledRpcApis); } public SyncState getSyncState() { diff --git a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java index 9d9288063a42..c52bbadf5d95 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java @@ -21,7 +21,7 @@ import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.crypto.SECP256K1.KeyPair; import org.hyperledger.besu.ethereum.ProtocolContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.method.JsonRpcMethodFactory; +import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethods; import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.GenesisState; @@ -159,8 +159,8 @@ public BesuControllerBuilder isRevertReasonEnabled(final boolean isRevertReas return this; } - public BesuControllerBuilder isPruningEnabled(final boolean pruningEnabled) { - this.isPruningEnabled = pruningEnabled; + public BesuControllerBuilder isPruningEnabled(final boolean isPruningEnabled) { + this.isPruningEnabled = isPruningEnabled; return this; } @@ -279,7 +279,7 @@ public BesuController build() { final SubProtocolConfiguration subProtocolConfiguration = createSubProtocolConfiguration(ethProtocolManager); - final JsonRpcMethodFactory additionalJsonRpcMethodFactory = + final JsonRpcMethods additionalJsonRpcMethodFactory = createAdditionalJsonRpcMethodFactory(protocolContext); List closeables = new ArrayList<>(); @@ -307,7 +307,7 @@ public BesuController build() { protected void prepForBuild() {} - protected JsonRpcMethodFactory createAdditionalJsonRpcMethodFactory( + protected JsonRpcMethods createAdditionalJsonRpcMethodFactory( final ProtocolContext protocolContext) { return apis -> Collections.emptyMap(); } 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 e64ac26e3ed7..ee70e2bc015f 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java @@ -22,14 +22,14 @@ import org.hyperledger.besu.consensus.clique.blockcreation.CliqueBlockScheduler; import org.hyperledger.besu.consensus.clique.blockcreation.CliqueMinerExecutor; import org.hyperledger.besu.consensus.clique.blockcreation.CliqueMiningCoordinator; -import org.hyperledger.besu.consensus.clique.jsonrpc.CliqueJsonRpcMethodsFactory; +import org.hyperledger.besu.consensus.clique.jsonrpc.CliqueJsonRpcMethods; import org.hyperledger.besu.consensus.common.BlockInterface; import org.hyperledger.besu.consensus.common.EpochManager; import org.hyperledger.besu.consensus.common.VoteProposer; import org.hyperledger.besu.consensus.common.VoteTallyCache; import org.hyperledger.besu.consensus.common.VoteTallyUpdater; import org.hyperledger.besu.ethereum.ProtocolContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.method.JsonRpcMethodFactory; +import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethods; import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.Address; @@ -65,9 +65,9 @@ protected void prepForBuild() { } @Override - protected JsonRpcMethodFactory createAdditionalJsonRpcMethodFactory( + protected JsonRpcMethods createAdditionalJsonRpcMethodFactory( final ProtocolContext protocolContext) { - return new CliqueJsonRpcMethodsFactory(protocolContext); + return new CliqueJsonRpcMethods(protocolContext); } @Override diff --git a/besu/src/main/java/org/hyperledger/besu/controller/IbftBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/IbftBesuControllerBuilder.java index e9a84123409f..69a02796758b 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/IbftBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/IbftBesuControllerBuilder.java @@ -36,7 +36,7 @@ import org.hyperledger.besu.consensus.ibft.blockcreation.IbftBlockCreatorFactory; import org.hyperledger.besu.consensus.ibft.blockcreation.IbftMiningCoordinator; import org.hyperledger.besu.consensus.ibft.blockcreation.ProposerSelector; -import org.hyperledger.besu.consensus.ibft.jsonrpc.IbftJsonRpcMethodsFactory; +import org.hyperledger.besu.consensus.ibft.jsonrpc.IbftJsonRpcMethods; import org.hyperledger.besu.consensus.ibft.network.ValidatorPeers; import org.hyperledger.besu.consensus.ibft.payload.MessageFactory; import org.hyperledger.besu.consensus.ibft.protocol.IbftProtocolManager; @@ -48,7 +48,7 @@ import org.hyperledger.besu.consensus.ibft.statemachine.IbftRoundFactory; import org.hyperledger.besu.consensus.ibft.validation.MessageValidatorFactory; import org.hyperledger.besu.ethereum.ProtocolContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.method.JsonRpcMethodFactory; +import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethods; import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.MinedBlockObserver; @@ -82,9 +82,9 @@ protected void prepForBuild() { } @Override - protected JsonRpcMethodFactory createAdditionalJsonRpcMethodFactory( + protected JsonRpcMethods createAdditionalJsonRpcMethodFactory( final ProtocolContext protocolContext) { - return new IbftJsonRpcMethodsFactory(protocolContext); + return new IbftJsonRpcMethods(protocolContext); } @Override diff --git a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java index 611997e4a4f6..8fa12d4a4375 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java @@ -20,6 +20,7 @@ import static org.hyperledger.besu.cli.config.NetworkName.CLASSIC; import static org.hyperledger.besu.cli.config.NetworkName.DEV; import static org.hyperledger.besu.cli.config.NetworkName.GOERLI; +import static org.hyperledger.besu.cli.config.NetworkName.KOTTI; import static org.hyperledger.besu.cli.config.NetworkName.MAINNET; import static org.hyperledger.besu.cli.config.NetworkName.RINKEBY; import static org.hyperledger.besu.cli.config.NetworkName.ROPSTEN; @@ -2328,7 +2329,29 @@ public void miningParametersAreCaptured() throws Exception { } @Test - public void pruningIsEnabledWhenSpecified() throws Exception { + public void pruningIsEnabledIfSyncModeIsFast() { + parseCommand("--sync-mode", "FAST"); + + verify(mockControllerBuilder).isPruningEnabled(true); + verify(mockControllerBuilder).build(); + + assertThat(commandOutput.toString()).isEmpty(); + assertThat(commandErrorOutput.toString()).isEmpty(); + } + + @Test + public void pruningIsDisabledIfSyncModeIsFull() { + parseCommand("--sync-mode", "FULL"); + + verify(mockControllerBuilder).isPruningEnabled(false); + verify(mockControllerBuilder).build(); + + assertThat(commandOutput.toString()).isEmpty(); + assertThat(commandErrorOutput.toString()).isEmpty(); + } + + @Test + public void pruningEnabledExplicitly() { parseCommand("--pruning-enabled"); verify(mockControllerBuilder).isPruningEnabled(true); @@ -2338,6 +2361,17 @@ public void pruningIsEnabledWhenSpecified() throws Exception { assertThat(commandErrorOutput.toString()).isEmpty(); } + @Test + public void pruningDisabledExplicitly() { + parseCommand("--pruning-enabled=false"); + + verify(mockControllerBuilder).isPruningEnabled(false); + verify(mockControllerBuilder).build(); + + assertThat(commandOutput.toString()).isEmpty(); + assertThat(commandErrorOutput.toString()).isEmpty(); + } + @Test public void pruningOptionsRequiresServiceToBeEnabled() { @@ -2447,6 +2481,22 @@ public void classicValuesAreUsed() throws Exception { assertThat(commandErrorOutput.toString()).isEmpty(); } + @Test + public void kottiValuesAreUsed() throws Exception { + parseCommand("--network", "kotti"); + + final ArgumentCaptor networkArg = + ArgumentCaptor.forClass(EthNetworkConfig.class); + + verify(mockControllerBuilderFactory).fromEthNetworkConfig(networkArg.capture(), any()); + verify(mockControllerBuilder).build(); + + assertThat(networkArg.getValue()).isEqualTo(EthNetworkConfig.getNetworkConfig(KOTTI)); + + assertThat(commandOutput.toString()).isEmpty(); + assertThat(commandErrorOutput.toString()).isEmpty(); + } + @Test public void rinkebyValuesCanBeOverridden() throws Exception { networkValuesCanBeOverridden("rinkeby"); @@ -2472,6 +2522,11 @@ public void classicValuesCanBeOverridden() throws Exception { networkValuesCanBeOverridden("classic"); } + @Test + public void kottiValuesCanBeOverridden() throws Exception { + networkValuesCanBeOverridden("kotti"); + } + private void networkValuesCanBeOverridden(final String network) throws Exception { parseCommand( "--network", diff --git a/besu/src/test/resources/everything_config.toml b/besu/src/test/resources/everything_config.toml index dfa3c0328595..b480d4f1253a 100644 --- a/besu/src/test/resources/everything_config.toml +++ b/besu/src/test/resources/everything_config.toml @@ -83,6 +83,9 @@ miner-coinbase="0x0000000000000000000000000000000000000002" miner-extra-data="0x444F4E27542050414E4943202120484F444C2C20484F444C2C20484F444C2021" min-gas-price=1 +# Pruning +pruning-enabled=true + # Permissioning permissions-nodes-config-file-enabled=false permissions-nodes-config-file="./permissions_config.toml" 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 f82672eab810..a1c95b9d2fd7 100644 --- a/config/src/main/java/org/hyperledger/besu/config/GenesisConfigOptions.java +++ b/config/src/main/java/org/hyperledger/besu/config/GenesisConfigOptions.java @@ -46,12 +46,8 @@ public interface GenesisConfigOptions { OptionalLong getTangerineWhistleBlockNumber(); - OptionalLong getEcip1015BlockNumber(); - OptionalLong getSpuriousDragonBlockNumber(); - OptionalLong getDieHardBlockNumber(); - OptionalLong getByzantiumBlockNumber(); OptionalLong getConstantinopleBlockNumber(); @@ -60,17 +56,72 @@ public interface GenesisConfigOptions { OptionalLong getIstanbulBlockNumber(); - Optional getChainId(); - - OptionalInt getContractSizeLimit(); - - OptionalInt getEvmStackSize(); + /** + * Block number for ECIP-1015 fork on Classic network ECIP-1015: Long-term gas cost changes for + * IO-heavy operations to mitigate transaction spam attacks In reference to EIP-150 (ETH Tangerine + * Whistle) Note, this fork happens after Homestead (Mainnet definition) and before DieHard fork + * + * @see https://ecips.ethereumclassic.org/ECIPs/ecip-1015 + * @return block number to activate ECIP-1015 code + */ + OptionalLong getEcip1015BlockNumber(); - Map asMap(); + /** + * Block number for DieHard fork on Classic network The DieHard fork includes changes to meet + * specification for ECIP-1010 and EIP-160 Note, this fork happens after ECIP-1015 (classic + * tangerine whistle) and before Gotham fork ECIP-1010: Delay Difficulty Bomb Explosion + * + * @see https://ecips.ethereumclassic.org/ECIPs/ecip-1010 + * EIP-160: EXP cost increase + * @see https://eips.ethereum.org/EIPS/eip-160 + * @return block number to activate Classic DieHard fork + */ + OptionalLong getDieHardBlockNumber(); + // TODO edwardmack, Add gotham fork block number here + + /** + * Block number to remove difficulty bomb on Classic network The DefuseDifficultyBomb fork + * includes changes to meet specification for ECIP-1041 Note, this fork happen after Gotham fork + * and before Atlantis fork ECIP-1041: Remove Difficulty Bomb + * + * @see https://ecips.ethereumclassic.org/ECIPs/ecip-1041 + * @return block number to activate Defuse Difficulty Bomb fork on Classic + */ OptionalLong getDefuseDifficultyBombBlockNumber(); + /** + * Block number for Atlantis fork on Classic network Note, this fork happen after Defuse + * Difficulty Bomb fork and before Agharta fork ECIP-1054: Atlantis EVM and Protocol Upgrades + * Enable the outstanding Ethereum Foundation Spurious Dragon and Byzantium network protocol + * upgrades for the Ethereum Classic network. + * + * @see https://ecips.ethereumclassic.org/ECIPs/ecip-1054 + * @return block number for Atlantis fork on Classic network + */ OptionalLong getAtlantisBlockNumber(); + /** + * Block number for Agharta fork on Classic network Note, this fork happen after Atlantis fork + * ECIP-1056: Agharta EVM and Protocol Upgrades Enable the outstanding Ethereum Foundation + * Constaninople and Petersburg network protocol upgrades for the Ethereum Classic network. + * + * @see https://ecips.ethereumclassic.org/ECIPs/ecip-1056 + * @return block number for Agharta fork on Classic network + */ OptionalLong getAghartaBlockNumber(); + + Optional getChainId(); + + OptionalInt getContractSizeLimit(); + + OptionalInt getEvmStackSize(); + + Map asMap(); } 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 701c9f3ed7fc..10c413e8247f 100644 --- a/config/src/main/java/org/hyperledger/besu/config/JsonGenesisConfigOptions.java +++ b/config/src/main/java/org/hyperledger/besu/config/JsonGenesisConfigOptions.java @@ -134,21 +134,11 @@ public OptionalLong getTangerineWhistleBlockNumber() { return getOptionalLong("eip150block"); } - @Override - public OptionalLong getEcip1015BlockNumber() { - return getOptionalLong("ecip1015block"); - } - @Override public OptionalLong getSpuriousDragonBlockNumber() { return getOptionalLong("eip158block"); } - @Override - public OptionalLong getDieHardBlockNumber() { - return getOptionalLong("diehardblock"); - } - @Override public OptionalLong getByzantiumBlockNumber() { return getOptionalLong("byzantiumblock"); @@ -170,18 +160,13 @@ public OptionalLong getIstanbulBlockNumber() { } @Override - public Optional getChainId() { - return getOptionalBigInteger("chainid"); - } - - @Override - public OptionalInt getContractSizeLimit() { - return getOptionalInt("contractsizelimit"); + public OptionalLong getEcip1015BlockNumber() { + return getOptionalLong("ecip1015block"); } @Override - public OptionalInt getEvmStackSize() { - return getOptionalInt("evmstacksize"); + public OptionalLong getDieHardBlockNumber() { + return getOptionalLong("diehardblock"); } @Override @@ -199,6 +184,21 @@ public OptionalLong getAghartaBlockNumber() { return getOptionalLong("aghartablock"); } + @Override + public Optional getChainId() { + return getOptionalBigInteger("chainid"); + } + + @Override + public OptionalInt getContractSizeLimit() { + return getOptionalInt("contractsizelimit"); + } + + @Override + public OptionalInt getEvmStackSize() { + return getOptionalInt("evmstacksize"); + } + @Override public Map asMap() { final ImmutableMap.Builder builder = ImmutableMap.builder(); diff --git a/config/src/test-support/java/org/hyperledger/besu/config/StubGenesisConfigOptions.java b/config/src/test-support/java/org/hyperledger/besu/config/StubGenesisConfigOptions.java index 379d1c5f9731..07cbc9ada797 100644 --- a/config/src/test-support/java/org/hyperledger/besu/config/StubGenesisConfigOptions.java +++ b/config/src/test-support/java/org/hyperledger/besu/config/StubGenesisConfigOptions.java @@ -32,14 +32,14 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions { private OptionalLong constantinopleBlockNumber = OptionalLong.empty(); private OptionalLong constantinopleFixBlockNumber = OptionalLong.empty(); private OptionalLong istanbulBlockNumber = OptionalLong.empty(); - private Optional chainId = Optional.empty(); - private OptionalInt contractSizeLimit = OptionalInt.empty(); - private OptionalInt stackSizeLimit = OptionalInt.empty(); + private OptionalLong ecip1015BlockNumber = OptionalLong.empty(); + private OptionalLong diehardBlockNumber = OptionalLong.empty(); private OptionalLong defuseDifficultyBombBlockNumber = OptionalLong.empty(); private OptionalLong atlantisBlockNumber = OptionalLong.empty(); private OptionalLong aghartaBlockNumber = OptionalLong.empty(); - private OptionalLong ecip1015BlockNumber = OptionalLong.empty(); - private OptionalLong diehardBlockNumber = OptionalLong.empty(); + private Optional chainId = Optional.empty(); + private OptionalInt contractSizeLimit = OptionalInt.empty(); + private OptionalInt stackSizeLimit = OptionalInt.empty(); @Override public String getConsensusEngine() { @@ -101,21 +101,11 @@ public OptionalLong getTangerineWhistleBlockNumber() { return tangerineWhistleBlockNumber; } - @Override - public OptionalLong getEcip1015BlockNumber() { - return ecip1015BlockNumber; - } - @Override public OptionalLong getSpuriousDragonBlockNumber() { return spuriousDragonBlockNumber; } - @Override - public OptionalLong getDieHardBlockNumber() { - return diehardBlockNumber; - } - @Override public OptionalLong getByzantiumBlockNumber() { return byzantiumBlockNumber; @@ -137,18 +127,13 @@ public OptionalLong getIstanbulBlockNumber() { } @Override - public OptionalInt getContractSizeLimit() { - return contractSizeLimit; - } - - @Override - public OptionalInt getEvmStackSize() { - return stackSizeLimit; + public OptionalLong getEcip1015BlockNumber() { + return ecip1015BlockNumber; } @Override - public Optional getChainId() { - return chainId; + public OptionalLong getDieHardBlockNumber() { + return diehardBlockNumber; } @Override @@ -166,6 +151,21 @@ public OptionalLong getAghartaBlockNumber() { return aghartaBlockNumber; } + @Override + public OptionalInt getContractSizeLimit() { + return contractSizeLimit; + } + + @Override + public OptionalInt getEvmStackSize() { + return stackSizeLimit; + } + + @Override + public Optional getChainId() { + return chainId; + } + @Override public Map asMap() { final ImmutableMap.Builder builder = ImmutableMap.builder(); diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/CliqueJsonRpcMethodsFactory.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/CliqueJsonRpcMethods.java similarity index 68% rename from consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/CliqueJsonRpcMethodsFactory.java rename to consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/CliqueJsonRpcMethods.java index b0217992ab6d..860af0e93696 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/CliqueJsonRpcMethodsFactory.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/jsonrpc/CliqueJsonRpcMethods.java @@ -30,55 +30,45 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApi; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; -import org.hyperledger.besu.ethereum.api.jsonrpc.method.JsonRpcMethodFactory; +import org.hyperledger.besu.ethereum.api.jsonrpc.methods.ApiGroupJsonRpcMethods; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; -import java.util.Collection; -import java.util.HashMap; import java.util.Map; -public class CliqueJsonRpcMethodsFactory implements JsonRpcMethodFactory { +public class CliqueJsonRpcMethods extends ApiGroupJsonRpcMethods { + private final JsonRpcParameter parameter = new JsonRpcParameter(); private final ProtocolContext context; - public CliqueJsonRpcMethodsFactory(final ProtocolContext context) { + public CliqueJsonRpcMethods(final ProtocolContext context) { this.context = context; } @Override - public Map createJsonRpcMethods(final Collection jsonRpcApis) { - final Map rpcMethods = new HashMap<>(); - if (!jsonRpcApis.contains(CliqueRpcApis.CLIQUE)) { - return rpcMethods; - } + protected RpcApi getApiGroup() { + return CliqueRpcApis.CLIQUE; + } + + @Override + protected Map create() { final MutableBlockchain blockchain = context.getBlockchain(); final WorldStateArchive worldStateArchive = context.getWorldStateArchive(); final BlockchainQueries blockchainQueries = new BlockchainQueries(blockchain, worldStateArchive); final VoteProposer voteProposer = context.getConsensusState().getVoteProposer(); - final JsonRpcParameter jsonRpcParameter = new JsonRpcParameter(); + // Must create our own voteTallyCache as using this would pollute the main voteTallyCache final VoteTallyCache voteTallyCache = createVoteTallyCache(context, blockchain); - final CliqueGetSigners cliqueGetSigners = - new CliqueGetSigners(blockchainQueries, voteTallyCache, jsonRpcParameter); - final CliqueGetSignersAtHash cliqueGetSignersAtHash = - new CliqueGetSignersAtHash(blockchainQueries, voteTallyCache, jsonRpcParameter); - final Propose proposeRpc = new Propose(voteProposer, jsonRpcParameter); - final Discard discardRpc = new Discard(voteProposer, jsonRpcParameter); - final CliqueProposals cliqueProposals = new CliqueProposals(voteProposer); - final CliqueGetSignerMetrics cliqueGetSignerMetrics = - new CliqueGetSignerMetrics(new CliqueBlockInterface(), blockchainQueries, jsonRpcParameter); - - rpcMethods.put(cliqueGetSigners.getName(), cliqueGetSigners); - rpcMethods.put(cliqueGetSignersAtHash.getName(), cliqueGetSignersAtHash); - rpcMethods.put(proposeRpc.getName(), proposeRpc); - rpcMethods.put(discardRpc.getName(), discardRpc); - rpcMethods.put(cliqueProposals.getName(), cliqueProposals); - rpcMethods.put(cliqueGetSignerMetrics.getName(), cliqueGetSignerMetrics); - return rpcMethods; + return mapOf( + new CliqueGetSigners(blockchainQueries, voteTallyCache, parameter), + new CliqueGetSignersAtHash(blockchainQueries, voteTallyCache, parameter), + new Propose(voteProposer, parameter), + new Discard(voteProposer, parameter), + new CliqueProposals(voteProposer), + new CliqueGetSignerMetrics(new CliqueBlockInterface(), blockchainQueries, parameter)); } private VoteTallyCache createVoteTallyCache( diff --git a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/IbftJsonRpcMethodsFactory.java b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/IbftJsonRpcMethods.java similarity index 55% rename from consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/IbftJsonRpcMethodsFactory.java rename to consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/IbftJsonRpcMethods.java index dcafe3c34de5..a0480f7b5774 100644 --- a/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/IbftJsonRpcMethodsFactory.java +++ b/consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/jsonrpc/IbftJsonRpcMethods.java @@ -28,50 +28,38 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApi; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; -import org.hyperledger.besu.ethereum.api.jsonrpc.method.JsonRpcMethodFactory; +import org.hyperledger.besu.ethereum.api.jsonrpc.methods.ApiGroupJsonRpcMethods; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; -import java.util.Collection; -import java.util.HashMap; import java.util.Map; -public class IbftJsonRpcMethodsFactory implements JsonRpcMethodFactory { +public class IbftJsonRpcMethods extends ApiGroupJsonRpcMethods { private final JsonRpcParameter jsonRpcParameter = new JsonRpcParameter(); private final ProtocolContext context; - public IbftJsonRpcMethodsFactory(final ProtocolContext context) { + public IbftJsonRpcMethods(final ProtocolContext context) { this.context = context; } @Override - public Map createJsonRpcMethods(final Collection jsonRpcApis) { - final Map rpcMethods = new HashMap<>(); - - if (jsonRpcApis.contains(IbftRpcApis.IBFT)) { - final BlockchainQueries blockchainQueries = - new BlockchainQueries(context.getBlockchain(), context.getWorldStateArchive()); - final VoteProposer voteProposer = context.getConsensusState().getVoteProposer(); - final BlockInterface blockInterface = new IbftBlockInterface(); - - addMethods( - rpcMethods, - new IbftProposeValidatorVote(voteProposer, jsonRpcParameter), - new IbftGetValidatorsByBlockNumber(blockchainQueries, blockInterface, jsonRpcParameter), - new IbftDiscardValidatorVote(voteProposer, jsonRpcParameter), - new IbftGetValidatorsByBlockHash( - context.getBlockchain(), blockInterface, jsonRpcParameter), - new IbftGetSignerMetrics(blockInterface, blockchainQueries, jsonRpcParameter), - new IbftGetPendingVotes(voteProposer)); - } - - return rpcMethods; + protected RpcApi getApiGroup() { + return IbftRpcApis.IBFT; } - private void addMethods( - final Map methods, final JsonRpcMethod... rpcMethods) { - for (final JsonRpcMethod rpcMethod : rpcMethods) { - methods.put(rpcMethod.getName(), rpcMethod); - } + @Override + protected Map create() { + final BlockchainQueries blockchainQueries = + new BlockchainQueries(context.getBlockchain(), context.getWorldStateArchive()); + final VoteProposer voteProposer = context.getConsensusState().getVoteProposer(); + final BlockInterface blockInterface = new IbftBlockInterface(); + + return mapOf( + new IbftProposeValidatorVote(voteProposer, jsonRpcParameter), + new IbftGetValidatorsByBlockNumber(blockchainQueries, blockInterface, jsonRpcParameter), + new IbftDiscardValidatorVote(voteProposer, jsonRpcParameter), + new IbftGetValidatorsByBlockHash(context.getBlockchain(), blockInterface, jsonRpcParameter), + new IbftGetSignerMetrics(blockInterface, blockchainQueries, jsonRpcParameter), + new IbftGetPendingVotes(voteProposer)); } } diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java index fd827adec730..a9f8c40a6b05 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java @@ -24,7 +24,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterRepository; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; -import org.hyperledger.besu.ethereum.api.jsonrpc.method.JsonRpcMethodsFactory; +import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory; import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/EthCallIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthCallIntegrationTest.java similarity index 99% rename from ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/EthCallIntegrationTest.java rename to ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthCallIntegrationTest.java index 33d7a4240ccd..d8251a980cc6 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/EthCallIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthCallIntegrationTest.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.api.jsonrpc.method; +package org.hyperledger.besu.ethereum.api.jsonrpc.methods; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchThrowable; diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/EthEstimateGasIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthEstimateGasIntegrationTest.java similarity index 99% rename from ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/EthEstimateGasIntegrationTest.java rename to ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthEstimateGasIntegrationTest.java index 37d838fefcb5..e721b236f9f0 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/EthEstimateGasIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthEstimateGasIntegrationTest.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.api.jsonrpc.method; +package org.hyperledger.besu.ethereum.api.jsonrpc.methods; import static org.assertj.core.api.Assertions.assertThat; diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/EthGetBlockByHashIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetBlockByHashIntegrationTest.java similarity index 99% rename from ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/EthGetBlockByHashIntegrationTest.java rename to ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetBlockByHashIntegrationTest.java index 6eae107548c3..c827fc59cb6f 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/EthGetBlockByHashIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetBlockByHashIntegrationTest.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.api.jsonrpc.method; +package org.hyperledger.besu.ethereum.api.jsonrpc.methods; import static org.assertj.core.api.Assertions.assertThat; diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/EthGetBlockByNumberIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetBlockByNumberIntegrationTest.java similarity index 99% rename from ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/EthGetBlockByNumberIntegrationTest.java rename to ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetBlockByNumberIntegrationTest.java index 7c83af67a85b..e6440ad102d3 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/EthGetBlockByNumberIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetBlockByNumberIntegrationTest.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.api.jsonrpc.method; +package org.hyperledger.besu.ethereum.api.jsonrpc.methods; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchThrowable; diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/EthGetFilterChangesIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetFilterChangesIntegrationTest.java similarity index 99% rename from ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/EthGetFilterChangesIntegrationTest.java rename to ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetFilterChangesIntegrationTest.java index 3d882d024632..ee85ca3781b2 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/EthGetFilterChangesIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetFilterChangesIntegrationTest.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.api.jsonrpc.method; +package org.hyperledger.besu.ethereum.api.jsonrpc.methods; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/EthGetUncleByBlockHashAndIndexIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetUncleByBlockHashAndIndexIntegrationTest.java similarity index 98% rename from ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/EthGetUncleByBlockHashAndIndexIntegrationTest.java rename to ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetUncleByBlockHashAndIndexIntegrationTest.java index d78d5741e122..810fe93428c8 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/EthGetUncleByBlockHashAndIndexIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetUncleByBlockHashAndIndexIntegrationTest.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.api.jsonrpc.method; +package org.hyperledger.besu.ethereum.api.jsonrpc.methods; import static org.assertj.core.api.Assertions.assertThat; diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/EthGetUncleByBlockNumberAndIndexIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetUncleByBlockNumberAndIndexIntegrationTest.java similarity index 98% rename from ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/EthGetUncleByBlockNumberAndIndexIntegrationTest.java rename to ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetUncleByBlockNumberAndIndexIntegrationTest.java index b8a361938de5..fa49bf7f9c28 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/EthGetUncleByBlockNumberAndIndexIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetUncleByBlockNumberAndIndexIntegrationTest.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.api.jsonrpc.method; +package org.hyperledger.besu.ethereum.api.jsonrpc.methods; import static org.assertj.core.api.Assertions.assertThat; diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/PrivGetPrivateTransactionIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivGetPrivateTransactionIntegrationTest.java similarity index 99% rename from ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/PrivGetPrivateTransactionIntegrationTest.java rename to ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivGetPrivateTransactionIntegrationTest.java index a90a5d32470e..ad44bfbe5fc6 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/PrivGetPrivateTransactionIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivGetPrivateTransactionIntegrationTest.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.api.jsonrpc.method; +package org.hyperledger.besu.ethereum.api.jsonrpc.methods; import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/JsonRpcMethodsFactory.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/JsonRpcMethodsFactory.java deleted file mode 100644 index b5a39b3c08ae..000000000000 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/JsonRpcMethodsFactory.java +++ /dev/null @@ -1,420 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.ethereum.api.jsonrpc.method; - -import org.hyperledger.besu.config.GenesisConfigOptions; -import org.hyperledger.besu.enclave.Enclave; -import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration; -import org.hyperledger.besu.ethereum.api.jsonrpc.LatestNonceProvider; -import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApi; -import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AdminAddPeer; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AdminChangeLogLevel; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AdminNodeInfo; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AdminPeers; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AdminRemovePeer; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugAccountRange; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugMetrics; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugStorageRangeAt; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugTraceBlock; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugTraceBlockByHash; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugTraceBlockByNumber; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugTraceTransaction; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthAccounts; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthBlockNumber; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthCall; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthChainId; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthCoinbase; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthEstimateGas; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGasPrice; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetBalance; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetBlockByHash; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetBlockByNumber; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetBlockTransactionCountByHash; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetBlockTransactionCountByNumber; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetCode; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetFilterChanges; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetFilterLogs; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetLogs; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetProof; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetStorageAt; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetTransactionByBlockHashAndIndex; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetTransactionByBlockNumberAndIndex; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetTransactionByHash; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetTransactionCount; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetTransactionReceipt; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetUncleByBlockHashAndIndex; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetUncleByBlockNumberAndIndex; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetUncleCountByBlockHash; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetUncleCountByBlockNumber; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetWork; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthHashrate; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthMining; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthNewBlockFilter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthNewFilter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthNewPendingTransactionFilter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthProtocolVersion; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthSendRawTransaction; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthSendTransaction; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthSyncing; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthUninstallFilter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.NetEnode; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.NetListening; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.NetPeerCount; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.NetServices; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.NetVersion; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.RpcModules; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.TxPoolBesuStatistics; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.TxPoolBesuTransactions; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.Web3ClientVersion; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.Web3Sha3; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.miner.MinerSetCoinbase; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.miner.MinerSetEtherbase; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.miner.MinerStart; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.miner.MinerStop; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermAddAccountsToWhitelist; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermAddNodesToWhitelist; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermGetAccountsWhitelist; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermGetNodesWhitelist; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermReloadPermissionsFromFile; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermRemoveAccountsFromWhitelist; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermRemoveNodesFromWhitelist; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.eea.EeaSendRawTransaction; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivCreatePrivacyGroup; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivDeletePrivacyGroup; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivDistributeRawTransaction; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivFindPrivacyGroup; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetEeaTransactionCount; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetPrivacyPrecompileAddress; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetPrivateTransaction; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetTransactionCount; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetTransactionReceipt; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivateEeaNonceProvider; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockReplay; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTracer; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory; -import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; -import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; -import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; -import org.hyperledger.besu.ethereum.chain.Blockchain; -import org.hyperledger.besu.ethereum.core.Address; -import org.hyperledger.besu.ethereum.core.PrivacyParameters; -import org.hyperledger.besu.ethereum.core.Synchronizer; -import org.hyperledger.besu.ethereum.eth.transactions.PendingTransactions; -import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; -import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions; -import org.hyperledger.besu.ethereum.p2p.network.P2PNetwork; -import org.hyperledger.besu.ethereum.p2p.rlpx.wire.Capability; -import org.hyperledger.besu.ethereum.permissioning.AccountLocalConfigPermissioningController; -import org.hyperledger.besu.ethereum.permissioning.NodeLocalConfigPermissioningController; -import org.hyperledger.besu.ethereum.privacy.PrivateTransactionHandler; -import org.hyperledger.besu.ethereum.privacy.markertransaction.FixedKeySigningPrivateMarkerTransactionFactory; -import org.hyperledger.besu.ethereum.privacy.markertransaction.PrivateMarkerTransactionFactory; -import org.hyperledger.besu.ethereum.privacy.markertransaction.RandomSigningPrivateMarkerTransactionFactory; -import org.hyperledger.besu.ethereum.transaction.TransactionSimulator; -import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; -import org.hyperledger.besu.metrics.ObservableMetricsSystem; -import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; - -import java.math.BigInteger; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.Set; - -public class JsonRpcMethodsFactory { - - private final BlockResultFactory blockResult = new BlockResultFactory(); - private final JsonRpcParameter parameter = new JsonRpcParameter(); - - public Map methods( - final String clientVersion, - final BigInteger networkId, - final GenesisConfigOptions genesisConfigOptions, - final P2PNetwork peerNetworkingService, - final Blockchain blockchain, - final WorldStateArchive worldStateArchive, - final Synchronizer synchronizer, - final TransactionPool transactionPool, - final ProtocolSchedule protocolSchedule, - final MiningCoordinator miningCoordinator, - final ObservableMetricsSystem metricsSystem, - final Set supportedCapabilities, - final Collection rpcApis, - final FilterManager filterManager, - final Optional accountsWhitelistController, - final Optional nodeWhitelistController, - final PrivacyParameters privacyParameters, - final JsonRpcConfiguration jsonRpcConfiguration, - final WebSocketConfiguration webSocketConfiguration, - final MetricsConfiguration metricsConfiguration) { - final BlockchainQueries blockchainQueries = - new BlockchainQueries(blockchain, worldStateArchive); - return methods( - clientVersion, - networkId, - genesisConfigOptions, - peerNetworkingService, - blockchainQueries, - synchronizer, - protocolSchedule, - filterManager, - transactionPool, - miningCoordinator, - metricsSystem, - supportedCapabilities, - accountsWhitelistController, - nodeWhitelistController, - rpcApis, - privacyParameters, - jsonRpcConfiguration, - webSocketConfiguration, - metricsConfiguration); - } - - public Map methods( - final String clientVersion, - final BigInteger networkId, - final GenesisConfigOptions genesisConfigOptions, - final P2PNetwork p2pNetwork, - final BlockchainQueries blockchainQueries, - final Synchronizer synchronizer, - final ProtocolSchedule protocolSchedule, - final FilterManager filterManager, - final TransactionPool transactionPool, - final MiningCoordinator miningCoordinator, - final ObservableMetricsSystem metricsSystem, - final Set supportedCapabilities, - final Optional accountsWhitelistController, - final Optional nodeWhitelistController, - final Collection rpcApis, - final PrivacyParameters privacyParameters, - final JsonRpcConfiguration jsonRpcConfiguration, - final WebSocketConfiguration webSocketConfiguration, - final MetricsConfiguration metricsConfiguration) { - final Map enabledMethods = new HashMap<>(); - if (!rpcApis.isEmpty()) { - addMethods(enabledMethods, new RpcModules(rpcApis)); - } - if (rpcApis.contains(RpcApis.ETH)) { - addMethods( - enabledMethods, - new EthAccounts(), - new EthBlockNumber(blockchainQueries), - new EthGetBalance(blockchainQueries, parameter), - new EthGetBlockByHash(blockchainQueries, blockResult, parameter), - new EthGetBlockByNumber(blockchainQueries, blockResult, parameter), - new EthGetBlockTransactionCountByNumber(blockchainQueries, parameter), - new EthGetBlockTransactionCountByHash(blockchainQueries, parameter), - new EthCall( - blockchainQueries, - new TransactionSimulator( - blockchainQueries.getBlockchain(), - blockchainQueries.getWorldStateArchive(), - protocolSchedule), - parameter), - new EthGetCode(blockchainQueries, parameter), - new EthGetLogs(blockchainQueries, parameter), - new EthGetProof(blockchainQueries, parameter), - new EthGetUncleCountByBlockHash(blockchainQueries, parameter), - new EthGetUncleCountByBlockNumber(blockchainQueries, parameter), - new EthGetUncleByBlockNumberAndIndex(blockchainQueries, parameter), - new EthGetUncleByBlockHashAndIndex(blockchainQueries, parameter), - new EthNewBlockFilter(filterManager), - new EthNewPendingTransactionFilter(filterManager), - new EthNewFilter(filterManager, parameter), - new EthGetTransactionByHash( - blockchainQueries, transactionPool.getPendingTransactions(), parameter), - new EthGetTransactionByBlockHashAndIndex(blockchainQueries, parameter), - new EthGetTransactionByBlockNumberAndIndex(blockchainQueries, parameter), - new EthGetTransactionCount( - blockchainQueries, transactionPool.getPendingTransactions(), parameter), - new EthGetTransactionReceipt(blockchainQueries, parameter), - new EthUninstallFilter(filterManager, parameter), - new EthGetFilterChanges(filterManager, parameter), - new EthGetFilterLogs(filterManager, parameter), - new EthSyncing(synchronizer), - new EthGetStorageAt(blockchainQueries, parameter), - new EthSendRawTransaction(transactionPool, parameter), - new EthSendTransaction(), - new EthEstimateGas( - blockchainQueries, - new TransactionSimulator( - blockchainQueries.getBlockchain(), - blockchainQueries.getWorldStateArchive(), - protocolSchedule), - parameter), - new EthMining(miningCoordinator), - new EthCoinbase(miningCoordinator), - new EthProtocolVersion(supportedCapabilities), - new EthGasPrice(miningCoordinator), - new EthGetWork(miningCoordinator), - new EthHashrate(miningCoordinator), - new EthChainId(protocolSchedule.getChainId())); - } - if (rpcApis.contains(RpcApis.DEBUG)) { - final BlockReplay blockReplay = - new BlockReplay( - protocolSchedule, - blockchainQueries.getBlockchain(), - blockchainQueries.getWorldStateArchive()); - addMethods( - enabledMethods, - new DebugTraceTransaction( - blockchainQueries, new TransactionTracer(blockReplay), parameter), - new DebugAccountRange(parameter, blockchainQueries), - new DebugStorageRangeAt(parameter, blockchainQueries, blockReplay), - new DebugMetrics(metricsSystem), - new DebugTraceBlock( - parameter, - new BlockTracer(blockReplay), - ScheduleBasedBlockHeaderFunctions.create(protocolSchedule), - blockchainQueries), - new DebugTraceBlockByNumber(parameter, new BlockTracer(blockReplay), blockchainQueries), - new DebugTraceBlockByHash(parameter, new BlockTracer(blockReplay))); - } - if (rpcApis.contains(RpcApis.NET)) { - addMethods( - enabledMethods, - new NetVersion(protocolSchedule.getChainId()), - new NetListening(p2pNetwork), - new NetPeerCount(p2pNetwork), - new NetEnode(p2pNetwork), - new NetServices( - jsonRpcConfiguration, webSocketConfiguration, p2pNetwork, metricsConfiguration)); - } - if (rpcApis.contains(RpcApis.WEB3)) { - addMethods(enabledMethods, new Web3ClientVersion(clientVersion), new Web3Sha3()); - } - if (rpcApis.contains(RpcApis.MINER)) { - final MinerSetCoinbase minerSetCoinbase = new MinerSetCoinbase(miningCoordinator, parameter); - addMethods( - enabledMethods, - new MinerStart(miningCoordinator), - new MinerStop(miningCoordinator), - minerSetCoinbase, - new MinerSetEtherbase(minerSetCoinbase)); - } - if (rpcApis.contains(RpcApis.TX_POOL)) { - addMethods( - enabledMethods, - new TxPoolBesuTransactions(transactionPool.getPendingTransactions()), - new TxPoolBesuStatistics(transactionPool.getPendingTransactions())); - } - if (rpcApis.contains(RpcApis.PERM)) { - addMethods( - enabledMethods, - new PermAddNodesToWhitelist(nodeWhitelistController, parameter), - new PermRemoveNodesFromWhitelist(nodeWhitelistController, parameter), - new PermGetNodesWhitelist(nodeWhitelistController), - new PermGetAccountsWhitelist(accountsWhitelistController), - new PermAddAccountsToWhitelist(accountsWhitelistController, parameter), - new PermRemoveAccountsFromWhitelist(accountsWhitelistController, parameter), - new PermReloadPermissionsFromFile(accountsWhitelistController, nodeWhitelistController)); - } - if (rpcApis.contains(RpcApis.ADMIN)) { - addMethods( - enabledMethods, - new AdminAddPeer(p2pNetwork, parameter), - new AdminRemovePeer(p2pNetwork, parameter), - new AdminNodeInfo( - clientVersion, networkId, genesisConfigOptions, p2pNetwork, blockchainQueries), - new AdminPeers(p2pNetwork), - new AdminChangeLogLevel(parameter)); - } - - // Disable TRACE functionality while under development - // if (rpcApis.contains(RpcApis.TRACE)) { - // addMethods( - // enabledMethods, - // new TraceReplayBlockTransactions( - // parameter, - // new BlockTracer( - // new BlockReplay( - // protocolSchedule, - // blockchainQueries.getBlockchain(), - // blockchainQueries.getWorldStateArchive())), - // blockchainQueries, - // protocolSchedule)); - // } - - final boolean eea = rpcApis.contains(RpcApis.EEA); - final boolean priv = rpcApis.contains(RpcApis.PRIV); - if (eea || priv) { - final PrivateMarkerTransactionFactory markerTransactionFactory = - createPrivateMarkerTransactionFactory( - privacyParameters, blockchainQueries, transactionPool.getPendingTransactions()); - - final PrivateTransactionHandler privateTransactionHandler = - new PrivateTransactionHandler( - privacyParameters, protocolSchedule.getChainId(), markerTransactionFactory); - final Enclave enclave = new Enclave(privacyParameters.getEnclaveUri()); - if (eea) { - addMethods( - enabledMethods, - new EeaSendRawTransaction(privateTransactionHandler, transactionPool, parameter), - new PrivGetEeaTransactionCount( - parameter, new PrivateEeaNonceProvider(enclave, privateTransactionHandler))); - } - if (priv) { - addMethods( - enabledMethods, - new PrivGetTransactionReceipt(blockchainQueries, enclave, parameter, privacyParameters), - new PrivCreatePrivacyGroup( - new Enclave(privacyParameters.getEnclaveUri()), privacyParameters, parameter), - new PrivDeletePrivacyGroup( - new Enclave(privacyParameters.getEnclaveUri()), privacyParameters, parameter), - new PrivFindPrivacyGroup(new Enclave(privacyParameters.getEnclaveUri()), parameter), - new PrivGetPrivacyPrecompileAddress(privacyParameters), - new PrivGetTransactionCount(parameter, privateTransactionHandler), - new PrivGetPrivateTransaction(blockchainQueries, enclave, parameter, privacyParameters), - new PrivDistributeRawTransaction( - privateTransactionHandler, transactionPool, parameter)); - } - } - - return enabledMethods; - } - - public static void addMethods( - final Map methods, final JsonRpcMethod... rpcMethods) { - for (final JsonRpcMethod rpcMethod : rpcMethods) { - methods.put(rpcMethod.getName(), rpcMethod); - } - } - - private PrivateMarkerTransactionFactory createPrivateMarkerTransactionFactory( - final PrivacyParameters privacyParameters, - final BlockchainQueries blockchainQueries, - final PendingTransactions pendingTransactions) { - - final Address privateContractAddress = - Address.privacyPrecompiled(privacyParameters.getPrivacyAddress()); - - if (privacyParameters.getSigningKeyPair().isPresent()) { - return new FixedKeySigningPrivateMarkerTransactionFactory( - privateContractAddress, - new LatestNonceProvider(blockchainQueries, pendingTransactions), - privacyParameters.getSigningKeyPair().get()); - } - return new RandomSigningPrivateMarkerTransactionFactory(privateContractAddress); - } -} diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/AdminJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/AdminJsonRpcMethods.java new file mode 100644 index 000000000000..1c5b588db451 --- /dev/null +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/AdminJsonRpcMethods.java @@ -0,0 +1,70 @@ +/* + * Copyright ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.api.jsonrpc.methods; + +import org.hyperledger.besu.config.GenesisConfigOptions; +import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApi; +import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AdminAddPeer; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AdminChangeLogLevel; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AdminNodeInfo; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AdminPeers; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.AdminRemovePeer; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; +import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; +import org.hyperledger.besu.ethereum.p2p.network.P2PNetwork; + +import java.math.BigInteger; +import java.util.Map; + +public class AdminJsonRpcMethods extends ApiGroupJsonRpcMethods { + + private final JsonRpcParameter parameter = new JsonRpcParameter(); + private final String clientVersion; + private final BigInteger networkId; + private final GenesisConfigOptions genesisConfigOptions; + private final P2PNetwork p2pNetwork; + private final BlockchainQueries blockchainQueries; + + public AdminJsonRpcMethods( + final String clientVersion, + final BigInteger networkId, + final GenesisConfigOptions genesisConfigOptions, + final P2PNetwork p2pNetwork, + final BlockchainQueries blockchainQueries) { + this.clientVersion = clientVersion; + this.networkId = networkId; + this.genesisConfigOptions = genesisConfigOptions; + this.p2pNetwork = p2pNetwork; + this.blockchainQueries = blockchainQueries; + } + + @Override + protected RpcApi getApiGroup() { + return RpcApis.ADMIN; + } + + @Override + protected Map create() { + return mapOf( + new AdminAddPeer(p2pNetwork, parameter), + new AdminRemovePeer(p2pNetwork, parameter), + new AdminNodeInfo( + clientVersion, networkId, genesisConfigOptions, p2pNetwork, blockchainQueries), + new AdminPeers(p2pNetwork), + new AdminChangeLogLevel(parameter)); + } +} diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/ApiGroupJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/ApiGroupJsonRpcMethods.java new file mode 100644 index 000000000000..eb1d04e17c34 --- /dev/null +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/ApiGroupJsonRpcMethods.java @@ -0,0 +1,41 @@ +/* + * Copyright ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.api.jsonrpc.methods; + +import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApi; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; +import java.util.stream.Collectors; + +public abstract class ApiGroupJsonRpcMethods implements JsonRpcMethods { + + @Override + public Map create(final Collection apis) { + return apis.contains(getApiGroup()) ? create() : Collections.emptyMap(); + } + + protected abstract RpcApi getApiGroup(); + + protected abstract Map create(); + + protected Map mapOf(final JsonRpcMethod... methods) { + return Arrays.stream(methods) + .collect(Collectors.toMap(JsonRpcMethod::getName, method -> method)); + } +} diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/DebugJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/DebugJsonRpcMethods.java new file mode 100644 index 000000000000..e9acf87a4e6f --- /dev/null +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/DebugJsonRpcMethods.java @@ -0,0 +1,80 @@ +/* + * Copyright ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.api.jsonrpc.methods; + +import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApi; +import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugAccountRange; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugMetrics; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugStorageRangeAt; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugTraceBlock; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugTraceBlockByHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugTraceBlockByNumber; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugTraceTransaction; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockReplay; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTracer; +import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions; +import org.hyperledger.besu.metrics.ObservableMetricsSystem; + +import java.util.Map; + +public class DebugJsonRpcMethods extends ApiGroupJsonRpcMethods { + + private final JsonRpcParameter parameter = new JsonRpcParameter(); + private final BlockchainQueries blockchainQueries; + private final ProtocolSchedule protocolSchedule; + private final ObservableMetricsSystem metricsSystem; + + public DebugJsonRpcMethods( + final BlockchainQueries blockchainQueries, + final ProtocolSchedule protocolSchedule, + final ObservableMetricsSystem metricsSystem) { + this.blockchainQueries = blockchainQueries; + this.protocolSchedule = protocolSchedule; + this.metricsSystem = metricsSystem; + } + + @Override + protected RpcApi getApiGroup() { + return RpcApis.DEBUG; + } + + @Override + protected Map create() { + final BlockReplay blockReplay = + new BlockReplay( + protocolSchedule, + blockchainQueries.getBlockchain(), + blockchainQueries.getWorldStateArchive()); + + return mapOf( + new DebugTraceTransaction(blockchainQueries, new TransactionTracer(blockReplay), parameter), + new DebugAccountRange(parameter, blockchainQueries), + new DebugStorageRangeAt(parameter, blockchainQueries, blockReplay), + new DebugMetrics(metricsSystem), + new DebugTraceBlock( + parameter, + new BlockTracer(blockReplay), + ScheduleBasedBlockHeaderFunctions.create(protocolSchedule), + blockchainQueries), + new DebugTraceBlockByNumber(parameter, new BlockTracer(blockReplay), blockchainQueries), + new DebugTraceBlockByHash(parameter, new BlockTracer(blockReplay))); + } +} diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EeaJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EeaJsonRpcMethods.java new file mode 100644 index 000000000000..d8020069c298 --- /dev/null +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EeaJsonRpcMethods.java @@ -0,0 +1,58 @@ +/* + * Copyright ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.api.jsonrpc.methods; + +import org.hyperledger.besu.enclave.Enclave; +import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApi; +import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.eea.EeaSendRawTransaction; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetEeaTransactionCount; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivateEeaNonceProvider; +import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; +import org.hyperledger.besu.ethereum.core.PrivacyParameters; +import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.privacy.PrivateTransactionHandler; + +import java.util.Map; + +public class EeaJsonRpcMethods extends PrivacyApiGroupJsonRpcMethods { + + private final JsonRpcParameter parameter = new JsonRpcParameter(); + + public EeaJsonRpcMethods( + final BlockchainQueries blockchainQueries, + final ProtocolSchedule protocolSchedule, + final TransactionPool transactionPool, + final PrivacyParameters privacyParameters) { + super(blockchainQueries, protocolSchedule, transactionPool, privacyParameters); + } + + @Override + protected RpcApi getApiGroup() { + return RpcApis.EEA; + } + + @Override + protected Map create( + final PrivateTransactionHandler privateTransactionHandler, final Enclave enclave) { + return mapOf( + new EeaSendRawTransaction(privateTransactionHandler, getTransactionPool(), parameter), + new PrivGetEeaTransactionCount( + parameter, new PrivateEeaNonceProvider(enclave, privateTransactionHandler))); + } +} diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthJsonRpcMethods.java new file mode 100644 index 000000000000..86197aa9f8d8 --- /dev/null +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthJsonRpcMethods.java @@ -0,0 +1,163 @@ +/* + * Copyright ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.api.jsonrpc.methods; + +import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApi; +import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthAccounts; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthBlockNumber; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthCall; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthChainId; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthCoinbase; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthEstimateGas; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGasPrice; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetBalance; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetBlockByHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetBlockByNumber; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetBlockTransactionCountByHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetBlockTransactionCountByNumber; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetCode; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetFilterChanges; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetFilterLogs; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetLogs; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetProof; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetStorageAt; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetTransactionByBlockHashAndIndex; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetTransactionByBlockNumberAndIndex; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetTransactionByHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetTransactionCount; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetTransactionReceipt; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetUncleByBlockHashAndIndex; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetUncleByBlockNumberAndIndex; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetUncleCountByBlockHash; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetUncleCountByBlockNumber; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetWork; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthHashrate; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthMining; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthNewBlockFilter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthNewFilter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthNewPendingTransactionFilter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthProtocolVersion; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthSendRawTransaction; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthSendTransaction; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthSyncing; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthUninstallFilter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory; +import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; +import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; +import org.hyperledger.besu.ethereum.core.Synchronizer; +import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.p2p.rlpx.wire.Capability; +import org.hyperledger.besu.ethereum.transaction.TransactionSimulator; + +import java.util.Map; +import java.util.Set; + +public class EthJsonRpcMethods extends ApiGroupJsonRpcMethods { + + private final BlockResultFactory blockResult = new BlockResultFactory(); + private final JsonRpcParameter parameter = new JsonRpcParameter(); + + private final BlockchainQueries blockchainQueries; + private final Synchronizer synchronizer; + private final ProtocolSchedule protocolSchedule; + private final FilterManager filterManager; + private final TransactionPool transactionPool; + private final MiningCoordinator miningCoordinator; + private final Set supportedCapabilities; + + public EthJsonRpcMethods( + final BlockchainQueries blockchainQueries, + final Synchronizer synchronizer, + final ProtocolSchedule protocolSchedule, + final FilterManager filterManager, + final TransactionPool transactionPool, + final MiningCoordinator miningCoordinator, + final Set supportedCapabilities) { + this.blockchainQueries = blockchainQueries; + this.synchronizer = synchronizer; + this.protocolSchedule = protocolSchedule; + this.filterManager = filterManager; + this.transactionPool = transactionPool; + this.miningCoordinator = miningCoordinator; + this.supportedCapabilities = supportedCapabilities; + } + + @Override + protected RpcApi getApiGroup() { + return RpcApis.ETH; + } + + @Override + protected Map create() { + return mapOf( + new EthAccounts(), + new EthBlockNumber(blockchainQueries), + new EthGetBalance(blockchainQueries, parameter), + new EthGetBlockByHash(blockchainQueries, blockResult, parameter), + new EthGetBlockByNumber(blockchainQueries, blockResult, parameter), + new EthGetBlockTransactionCountByNumber(blockchainQueries, parameter), + new EthGetBlockTransactionCountByHash(blockchainQueries, parameter), + new EthCall( + blockchainQueries, + new TransactionSimulator( + blockchainQueries.getBlockchain(), + blockchainQueries.getWorldStateArchive(), + protocolSchedule), + parameter), + new EthGetCode(blockchainQueries, parameter), + new EthGetLogs(blockchainQueries, parameter), + new EthGetProof(blockchainQueries, parameter), + new EthGetUncleCountByBlockHash(blockchainQueries, parameter), + new EthGetUncleCountByBlockNumber(blockchainQueries, parameter), + new EthGetUncleByBlockNumberAndIndex(blockchainQueries, parameter), + new EthGetUncleByBlockHashAndIndex(blockchainQueries, parameter), + new EthNewBlockFilter(filterManager), + new EthNewPendingTransactionFilter(filterManager), + new EthNewFilter(filterManager, parameter), + new EthGetTransactionByHash( + blockchainQueries, transactionPool.getPendingTransactions(), parameter), + new EthGetTransactionByBlockHashAndIndex(blockchainQueries, parameter), + new EthGetTransactionByBlockNumberAndIndex(blockchainQueries, parameter), + new EthGetTransactionCount( + blockchainQueries, transactionPool.getPendingTransactions(), parameter), + new EthGetTransactionReceipt(blockchainQueries, parameter), + new EthUninstallFilter(filterManager, parameter), + new EthGetFilterChanges(filterManager, parameter), + new EthGetFilterLogs(filterManager, parameter), + new EthSyncing(synchronizer), + new EthGetStorageAt(blockchainQueries, parameter), + new EthSendRawTransaction(transactionPool, parameter), + new EthSendTransaction(), + new EthEstimateGas( + blockchainQueries, + new TransactionSimulator( + blockchainQueries.getBlockchain(), + blockchainQueries.getWorldStateArchive(), + protocolSchedule), + parameter), + new EthMining(miningCoordinator), + new EthCoinbase(miningCoordinator), + new EthProtocolVersion(supportedCapabilities), + new EthGasPrice(miningCoordinator), + new EthGetWork(miningCoordinator), + new EthHashrate(miningCoordinator), + new EthChainId(protocolSchedule.getChainId())); + } +} diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/JsonRpcMethodFactory.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethods.java similarity index 81% rename from ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/JsonRpcMethodFactory.java rename to ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethods.java index 2cdd2c55a6e9..0b4ae464772e 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/method/JsonRpcMethodFactory.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethods.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.api.jsonrpc.method; +package org.hyperledger.besu.ethereum.api.jsonrpc.methods; import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApi; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; @@ -20,6 +20,6 @@ import java.util.Collection; import java.util.Map; -public interface JsonRpcMethodFactory { - Map createJsonRpcMethods(Collection enabledRpcApis); +public interface JsonRpcMethods { + Map create(Collection enabledRpcApis); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethodsFactory.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethodsFactory.java new file mode 100644 index 000000000000..5991ecc510d3 --- /dev/null +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethodsFactory.java @@ -0,0 +1,157 @@ +/* + * Copyright ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.api.jsonrpc.methods; + +import org.hyperledger.besu.config.GenesisConfigOptions; +import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration; +import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApi; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.RpcModules; +import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; +import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; +import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; +import org.hyperledger.besu.ethereum.chain.Blockchain; +import org.hyperledger.besu.ethereum.core.PrivacyParameters; +import org.hyperledger.besu.ethereum.core.Synchronizer; +import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.p2p.network.P2PNetwork; +import org.hyperledger.besu.ethereum.p2p.rlpx.wire.Capability; +import org.hyperledger.besu.ethereum.permissioning.AccountLocalConfigPermissioningController; +import org.hyperledger.besu.ethereum.permissioning.NodeLocalConfigPermissioningController; +import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; +import org.hyperledger.besu.metrics.ObservableMetricsSystem; +import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; + +import java.math.BigInteger; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; + +public class JsonRpcMethodsFactory { + + public Map methods( + final String clientVersion, + final BigInteger networkId, + final GenesisConfigOptions genesisConfigOptions, + final P2PNetwork peerNetworkingService, + final Blockchain blockchain, + final WorldStateArchive worldStateArchive, + final Synchronizer synchronizer, + final TransactionPool transactionPool, + final ProtocolSchedule protocolSchedule, + final MiningCoordinator miningCoordinator, + final ObservableMetricsSystem metricsSystem, + final Set supportedCapabilities, + final Collection rpcApis, + final FilterManager filterManager, + final Optional accountsWhitelistController, + final Optional nodeWhitelistController, + final PrivacyParameters privacyParameters, + final JsonRpcConfiguration jsonRpcConfiguration, + final WebSocketConfiguration webSocketConfiguration, + final MetricsConfiguration metricsConfiguration) { + final BlockchainQueries blockchainQueries = + new BlockchainQueries(blockchain, worldStateArchive); + return methods( + clientVersion, + networkId, + genesisConfigOptions, + peerNetworkingService, + blockchainQueries, + synchronizer, + protocolSchedule, + filterManager, + transactionPool, + miningCoordinator, + metricsSystem, + supportedCapabilities, + accountsWhitelistController, + nodeWhitelistController, + rpcApis, + privacyParameters, + jsonRpcConfiguration, + webSocketConfiguration, + metricsConfiguration); + } + + public Map methods( + final String clientVersion, + final BigInteger networkId, + final GenesisConfigOptions genesisConfigOptions, + final P2PNetwork p2pNetwork, + final BlockchainQueries blockchainQueries, + final Synchronizer synchronizer, + final ProtocolSchedule protocolSchedule, + final FilterManager filterManager, + final TransactionPool transactionPool, + final MiningCoordinator miningCoordinator, + final ObservableMetricsSystem metricsSystem, + final Set supportedCapabilities, + final Optional accountsWhitelistController, + final Optional nodeWhitelistController, + final Collection rpcApis, + final PrivacyParameters privacyParameters, + final JsonRpcConfiguration jsonRpcConfiguration, + final WebSocketConfiguration webSocketConfiguration, + final MetricsConfiguration metricsConfiguration) { + final Map enabled = new HashMap<>(); + + if (!rpcApis.isEmpty()) { + final JsonRpcMethod modules = new RpcModules(rpcApis); + enabled.put(modules.getName(), modules); + + final List availableApiGroups = + List.of( + new AdminJsonRpcMethods( + clientVersion, networkId, genesisConfigOptions, p2pNetwork, blockchainQueries), + new DebugJsonRpcMethods(blockchainQueries, protocolSchedule, metricsSystem), + new EeaJsonRpcMethods( + blockchainQueries, protocolSchedule, transactionPool, privacyParameters), + new EthJsonRpcMethods( + blockchainQueries, + synchronizer, + protocolSchedule, + filterManager, + transactionPool, + miningCoordinator, + supportedCapabilities), + new NetJsonRpcMethods( + p2pNetwork, + protocolSchedule, + jsonRpcConfiguration, + webSocketConfiguration, + metricsConfiguration), + new MinerJsonRpcMethods(miningCoordinator), + new PermJsonRpcMethods(accountsWhitelistController, nodeWhitelistController), + new PrivJsonRpcMethods( + blockchainQueries, protocolSchedule, transactionPool, privacyParameters), + new Web3JsonRpcMethods(clientVersion), + // TRACE Methods (Disabled while under development) + // new TraceJsonRpcMethods(blockchainQueries,protocolSchedule) + new TxPoolJsonRpcMethods(transactionPool)); + + for (final JsonRpcMethods apiGroup : availableApiGroups) { + enabled.putAll(apiGroup.create(rpcApis)); + } + } + + return enabled; + } +} diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/MinerJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/MinerJsonRpcMethods.java new file mode 100644 index 000000000000..bed18cbaaea0 --- /dev/null +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/MinerJsonRpcMethods.java @@ -0,0 +1,52 @@ +/* + * Copyright ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.api.jsonrpc.methods; + +import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApi; +import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.miner.MinerSetCoinbase; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.miner.MinerSetEtherbase; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.miner.MinerStart; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.miner.MinerStop; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; +import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; + +import java.util.Map; + +public class MinerJsonRpcMethods extends ApiGroupJsonRpcMethods { + + private final JsonRpcParameter parameter = new JsonRpcParameter(); + private final MiningCoordinator miningCoordinator; + + public MinerJsonRpcMethods(final MiningCoordinator miningCoordinator) { + this.miningCoordinator = miningCoordinator; + } + + @Override + protected RpcApi getApiGroup() { + return RpcApis.MINER; + } + + @Override + protected Map create() { + final MinerSetCoinbase minerSetCoinbase = new MinerSetCoinbase(miningCoordinator, parameter); + return mapOf( + new MinerStart(miningCoordinator), + new MinerStop(miningCoordinator), + minerSetCoinbase, + new MinerSetEtherbase(minerSetCoinbase)); + } +} diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/NetJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/NetJsonRpcMethods.java new file mode 100644 index 000000000000..49a81953d64f --- /dev/null +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/NetJsonRpcMethods.java @@ -0,0 +1,69 @@ +/* + * Copyright ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.api.jsonrpc.methods; + +import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration; +import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApi; +import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.NetEnode; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.NetListening; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.NetPeerCount; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.NetServices; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.NetVersion; +import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.p2p.network.P2PNetwork; +import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; + +import java.util.Map; + +public class NetJsonRpcMethods extends ApiGroupJsonRpcMethods { + + private final P2PNetwork p2pNetwork; + private final ProtocolSchedule protocolSchedule; + private final JsonRpcConfiguration jsonRpcConfiguration; + private final WebSocketConfiguration webSocketConfiguration; + private final MetricsConfiguration metricsConfiguration; + + public NetJsonRpcMethods( + final P2PNetwork p2pNetwork, + final ProtocolSchedule protocolSchedule, + final JsonRpcConfiguration jsonRpcConfiguration, + final WebSocketConfiguration webSocketConfiguration, + final MetricsConfiguration metricsConfiguration) { + this.p2pNetwork = p2pNetwork; + this.protocolSchedule = protocolSchedule; + this.jsonRpcConfiguration = jsonRpcConfiguration; + this.webSocketConfiguration = webSocketConfiguration; + this.metricsConfiguration = metricsConfiguration; + } + + @Override + protected RpcApi getApiGroup() { + return RpcApis.NET; + } + + @Override + protected Map create() { + return mapOf( + new NetVersion(protocolSchedule.getChainId()), + new NetListening(p2pNetwork), + new NetPeerCount(p2pNetwork), + new NetEnode(p2pNetwork), + new NetServices( + jsonRpcConfiguration, webSocketConfiguration, p2pNetwork, metricsConfiguration)); + } +} diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PermJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PermJsonRpcMethods.java new file mode 100644 index 000000000000..6f667c2743e5 --- /dev/null +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PermJsonRpcMethods.java @@ -0,0 +1,63 @@ +/* + * Copyright ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.api.jsonrpc.methods; + +import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApi; +import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermAddAccountsToWhitelist; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermAddNodesToWhitelist; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermGetAccountsWhitelist; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermGetNodesWhitelist; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermReloadPermissionsFromFile; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermRemoveAccountsFromWhitelist; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermRemoveNodesFromWhitelist; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; +import org.hyperledger.besu.ethereum.permissioning.AccountLocalConfigPermissioningController; +import org.hyperledger.besu.ethereum.permissioning.NodeLocalConfigPermissioningController; + +import java.util.Map; +import java.util.Optional; + +public class PermJsonRpcMethods extends ApiGroupJsonRpcMethods { + + private final JsonRpcParameter parameter = new JsonRpcParameter(); + private final Optional accountsWhitelistController; + private final Optional nodeWhitelistController; + + public PermJsonRpcMethods( + final Optional accountsWhitelistController, + final Optional nodeWhitelistController) { + this.accountsWhitelistController = accountsWhitelistController; + this.nodeWhitelistController = nodeWhitelistController; + } + + @Override + protected RpcApi getApiGroup() { + return RpcApis.PERM; + } + + @Override + protected Map create() { + return mapOf( + new PermAddNodesToWhitelist(nodeWhitelistController, parameter), + new PermRemoveNodesFromWhitelist(nodeWhitelistController, parameter), + new PermGetNodesWhitelist(nodeWhitelistController), + new PermGetAccountsWhitelist(accountsWhitelistController), + new PermAddAccountsToWhitelist(accountsWhitelistController, parameter), + new PermRemoveAccountsFromWhitelist(accountsWhitelistController, parameter), + new PermReloadPermissionsFromFile(accountsWhitelistController, nodeWhitelistController)); + } +} diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivJsonRpcMethods.java new file mode 100644 index 000000000000..6b79f8f59d55 --- /dev/null +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivJsonRpcMethods.java @@ -0,0 +1,73 @@ +/* + * Copyright ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.api.jsonrpc.methods; + +import org.hyperledger.besu.enclave.Enclave; +import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApi; +import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivCreatePrivacyGroup; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivDeletePrivacyGroup; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivDistributeRawTransaction; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivFindPrivacyGroup; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetPrivacyPrecompileAddress; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetPrivateTransaction; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetTransactionCount; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetTransactionReceipt; +import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; +import org.hyperledger.besu.ethereum.core.PrivacyParameters; +import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.privacy.PrivateTransactionHandler; + +import java.util.Map; + +public class PrivJsonRpcMethods extends PrivacyApiGroupJsonRpcMethods { + + private final JsonRpcParameter parameter = new JsonRpcParameter(); + + public PrivJsonRpcMethods( + final BlockchainQueries blockchainQueries, + final ProtocolSchedule protocolSchedule, + final TransactionPool transactionPool, + final PrivacyParameters privacyParameters) { + super(blockchainQueries, protocolSchedule, transactionPool, privacyParameters); + } + + @Override + protected RpcApi getApiGroup() { + return RpcApis.PRIV; + } + + @Override + protected Map create( + final PrivateTransactionHandler privateTransactionHandler, final Enclave enclave) { + return mapOf( + new PrivGetTransactionReceipt( + getBlockchainQueries(), enclave, parameter, getPrivacyParameters()), + new PrivCreatePrivacyGroup( + new Enclave(getPrivacyParameters().getEnclaveUri()), getPrivacyParameters(), parameter), + new PrivDeletePrivacyGroup( + new Enclave(getPrivacyParameters().getEnclaveUri()), getPrivacyParameters(), parameter), + new PrivFindPrivacyGroup(new Enclave(getPrivacyParameters().getEnclaveUri()), parameter), + new PrivGetPrivacyPrecompileAddress(getPrivacyParameters()), + new PrivGetTransactionCount(parameter, privateTransactionHandler), + new PrivGetPrivateTransaction( + getBlockchainQueries(), enclave, parameter, getPrivacyParameters()), + new PrivDistributeRawTransaction( + privateTransactionHandler, getTransactionPool(), parameter)); + } +} diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivacyApiGroupJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivacyApiGroupJsonRpcMethods.java new file mode 100644 index 000000000000..53881a8c0154 --- /dev/null +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivacyApiGroupJsonRpcMethods.java @@ -0,0 +1,101 @@ +/* + * Copyright ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.api.jsonrpc.methods; + +import org.hyperledger.besu.enclave.Enclave; +import org.hyperledger.besu.ethereum.api.jsonrpc.LatestNonceProvider; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; +import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; +import org.hyperledger.besu.ethereum.core.Address; +import org.hyperledger.besu.ethereum.core.PrivacyParameters; +import org.hyperledger.besu.ethereum.eth.transactions.PendingTransactions; +import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.privacy.PrivateTransactionHandler; +import org.hyperledger.besu.ethereum.privacy.markertransaction.FixedKeySigningPrivateMarkerTransactionFactory; +import org.hyperledger.besu.ethereum.privacy.markertransaction.PrivateMarkerTransactionFactory; +import org.hyperledger.besu.ethereum.privacy.markertransaction.RandomSigningPrivateMarkerTransactionFactory; + +import java.util.Map; + +public abstract class PrivacyApiGroupJsonRpcMethods extends ApiGroupJsonRpcMethods { + + private final BlockchainQueries blockchainQueries; + private final ProtocolSchedule protocolSchedule; + private final TransactionPool transactionPool; + private final PrivacyParameters privacyParameters; + + public PrivacyApiGroupJsonRpcMethods( + final BlockchainQueries blockchainQueries, + final ProtocolSchedule protocolSchedule, + final TransactionPool transactionPool, + final PrivacyParameters privacyParameters) { + this.blockchainQueries = blockchainQueries; + this.protocolSchedule = protocolSchedule; + this.transactionPool = transactionPool; + this.privacyParameters = privacyParameters; + } + + public BlockchainQueries getBlockchainQueries() { + return blockchainQueries; + } + + public ProtocolSchedule getProtocolSchedule() { + return protocolSchedule; + } + + public TransactionPool getTransactionPool() { + return transactionPool; + } + + public PrivacyParameters getPrivacyParameters() { + return privacyParameters; + } + + @Override + protected Map create() { + final PrivateMarkerTransactionFactory markerTransactionFactory = + createPrivateMarkerTransactionFactory( + privacyParameters, blockchainQueries, transactionPool.getPendingTransactions()); + + final PrivateTransactionHandler privateTransactionHandler = + new PrivateTransactionHandler( + privacyParameters, protocolSchedule.getChainId(), markerTransactionFactory); + + final Enclave enclave = new Enclave(privacyParameters.getEnclaveUri()); + + return create(privateTransactionHandler, enclave); + } + + protected abstract Map create( + final PrivateTransactionHandler privateTransactionHandler, final Enclave enclave); + + private PrivateMarkerTransactionFactory createPrivateMarkerTransactionFactory( + final PrivacyParameters privacyParameters, + final BlockchainQueries blockchainQueries, + final PendingTransactions pendingTransactions) { + + final Address privateContractAddress = + Address.privacyPrecompiled(privacyParameters.getPrivacyAddress()); + + if (privacyParameters.getSigningKeyPair().isPresent()) { + return new FixedKeySigningPrivateMarkerTransactionFactory( + privateContractAddress, + new LatestNonceProvider(blockchainQueries, pendingTransactions), + privacyParameters.getSigningKeyPair().get()); + } + return new RandomSigningPrivateMarkerTransactionFactory(privateContractAddress); + } +} diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/TraceJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/TraceJsonRpcMethods.java new file mode 100644 index 000000000000..eb0c8b469008 --- /dev/null +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/TraceJsonRpcMethods.java @@ -0,0 +1,60 @@ +/* + * Copyright ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.api.jsonrpc.methods; + +import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApi; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.TraceReplayBlockTransactions; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockReplay; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer; +import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; + +import java.util.Map; + +public class TraceJsonRpcMethods extends ApiGroupJsonRpcMethods { + + private final JsonRpcParameter parameter = new JsonRpcParameter(); + private final BlockchainQueries blockchainQueries; + private final ProtocolSchedule protocolSchedule; + + public TraceJsonRpcMethods( + final BlockchainQueries blockchainQueries, final ProtocolSchedule protocolSchedule) { + this.blockchainQueries = blockchainQueries; + this.protocolSchedule = protocolSchedule; + } + + @Override + protected RpcApi getApiGroup() { + // Disable TRACE functionality while under development + // return RpcApis.TRACE; + return null; + } + + @Override + protected Map create() { + return mapOf( + new TraceReplayBlockTransactions( + parameter, + new BlockTracer( + new BlockReplay( + protocolSchedule, + blockchainQueries.getBlockchain(), + blockchainQueries.getWorldStateArchive())), + blockchainQueries, + protocolSchedule)); + } +} diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/TxPoolJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/TxPoolJsonRpcMethods.java new file mode 100644 index 000000000000..f1e3197d52f7 --- /dev/null +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/TxPoolJsonRpcMethods.java @@ -0,0 +1,45 @@ +/* + * Copyright ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.api.jsonrpc.methods; + +import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApi; +import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.TxPoolBesuStatistics; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.TxPoolBesuTransactions; +import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; + +import java.util.Map; + +public class TxPoolJsonRpcMethods extends ApiGroupJsonRpcMethods { + + private final TransactionPool transactionPool; + + public TxPoolJsonRpcMethods(final TransactionPool transactionPool) { + this.transactionPool = transactionPool; + } + + @Override + protected RpcApi getApiGroup() { + return RpcApis.TX_POOL; + } + + @Override + protected Map create() { + return mapOf( + new TxPoolBesuTransactions(transactionPool.getPendingTransactions()), + new TxPoolBesuStatistics(transactionPool.getPendingTransactions())); + } +} diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/Web3JsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/Web3JsonRpcMethods.java new file mode 100644 index 000000000000..ca9176aec21a --- /dev/null +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/Web3JsonRpcMethods.java @@ -0,0 +1,42 @@ +/* + * Copyright ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.api.jsonrpc.methods; + +import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApi; +import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.Web3ClientVersion; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.Web3Sha3; + +import java.util.Map; + +public class Web3JsonRpcMethods extends ApiGroupJsonRpcMethods { + + private final String clientVersion; + + public Web3JsonRpcMethods(final String clientVersion) { + this.clientVersion = clientVersion; + } + + @Override + protected RpcApi getApiGroup() { + return RpcApis.WEB3; + } + + @Override + protected Map create() { + return mapOf(new Web3ClientVersion(clientVersion), new Web3Sha3()); + } +} diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/AbstractJsonRpcHttpServiceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/AbstractJsonRpcHttpServiceTest.java index dee25966e5c4..1af7864a72ac 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/AbstractJsonRpcHttpServiceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/AbstractJsonRpcHttpServiceTest.java @@ -26,7 +26,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterRepository; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; -import org.hyperledger.besu.ethereum.api.jsonrpc.method.JsonRpcMethodsFactory; +import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory; import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceHostWhitelistTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceHostWhitelistTest.java index 73b23950b175..40b4d1b10eb2 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceHostWhitelistTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceHostWhitelistTest.java @@ -22,7 +22,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.health.HealthService; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; -import org.hyperledger.besu.ethereum.api.jsonrpc.method.JsonRpcMethodsFactory; +import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory; import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; 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 e4318c6b74d7..ca423147645c 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 @@ -28,7 +28,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.NetVersion; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.Web3ClientVersion; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.Web3Sha3; -import org.hyperledger.besu.ethereum.api.jsonrpc.method.JsonRpcMethodsFactory; +import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory; import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java index 2a8e01b49d8c..881325c480b2 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java @@ -25,7 +25,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; -import org.hyperledger.besu.ethereum.api.jsonrpc.method.JsonRpcMethodsFactory; +import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory; import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.blockcreation.EthHashMiningCoordinator; diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java index aaae48d35eeb..d9b9b527395c 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java @@ -29,7 +29,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; -import org.hyperledger.besu.ethereum.api.jsonrpc.method.JsonRpcMethodsFactory; +import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory; import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; import org.hyperledger.besu.ethereum.api.query.BlockWithMetadata; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java index 75f0a275eb9d..913c410dc5cd 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java @@ -54,38 +54,8 @@ public static ProtocolSpecBuilder dieHardDefinition( final Optional chainId, final OptionalInt configContractSizeLimit, final OptionalInt configStackSizeLimit) { - // final int contractSizeLimit = - // configContractSizeLimit.orElse(SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT); - // final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE); - return tangerineWhistleDefinition(chainId, OptionalInt.empty(), configStackSizeLimit) .gasCalculator(SpuriousDragonGasCalculator::new) - // .skipZeroBlockRewards(true) - // .messageCallProcessorBuilder(MainnetMessageCallProcessor::new) - // .contractCreationProcessorBuilder( - // (gasCalculator, evm) -> - // new MainnetContractCreationProcessor( - // gasCalculator, - // evm, - // true, - // - // Collections.singletonList(MaxCodeSizeRule.of(contractSizeLimit)), - // 1)) - .transactionValidatorBuilder( - gasCalculator -> new MainnetTransactionValidator(gasCalculator, true, chainId)) - // .transactionProcessorBuilder( - // (gasCalculator, - // transactionValidator, - // contractCreationProcessor, - // messageCallProcessor) -> - // new MainnetTransactionProcessor( - // gasCalculator, - // transactionValidator, - // contractCreationProcessor, - // messageCallProcessor, - // true, - // stackSizeLimit, - // Account.DEFAULT_VERSION)) .name("DieHard"); } @@ -157,10 +127,6 @@ public static ProtocolSpecBuilder aghartaDefinition( return MainnetProtocolSpecs.constantinopleFixDefinition( chainId, configContractSizeLimit, configStackSizeLimit, enableRevertReason) .gasCalculator(IstanbulGasCalculator::new) - // .evmBuilder( - // gasCalculator -> - // MainnetEvmRegistries.istanbul(gasCalculator, - // chainId.orElse(BigInteger.ZERO))) .precompileContractRegistryBuilder(MainnetPrecompiledContractRegistries::istanbul) .contractCreationProcessorBuilder( (gasCalculator, evm) -> diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethService.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethService.java index 06aec92198ff..37096c5eb6e7 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethService.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethService.java @@ -30,7 +30,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.Web3ClientVersion; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory; -import org.hyperledger.besu.ethereum.api.jsonrpc.method.JsonRpcMethodsFactory; import org.hyperledger.besu.ethereum.retesteth.methods.TestGetLogHash; import org.hyperledger.besu.ethereum.retesteth.methods.TestImportRawBlock; import org.hyperledger.besu.ethereum.retesteth.methods.TestMineBlocks; @@ -39,9 +38,10 @@ import org.hyperledger.besu.ethereum.retesteth.methods.TestSetChainParams; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; -import java.util.HashMap; +import java.util.Arrays; import java.util.Map; import java.util.Optional; +import java.util.stream.Collectors; import io.vertx.core.Vertx; @@ -61,33 +61,32 @@ public RetestethService( final JsonRpcParameter parameters = new JsonRpcParameter(); final BlockResultFactory blockResult = new BlockResultFactory(); - final Map jsonRpcMethods = new HashMap<>(); - JsonRpcMethodsFactory.addMethods( - jsonRpcMethods, - new Web3ClientVersion(clientVersion), - new TestSetChainParams(retestethContext), - new TestImportRawBlock(retestethContext, parameters), - new EthBlockNumber(retestethContext::getBlockchainQueries, true), - new EthGetBlockByNumber( - retestethContext::getBlockchainQueries, blockResult, parameters, true), - new DebugAccountRange(parameters, retestethContext::getBlockchainQueries), - new EthGetBalance(retestethContext::getBlockchainQueries, parameters), - new EthGetCode(retestethContext::getBlockchainQueries, parameters), - new EthGetTransactionCount( - retestethContext::getBlockchainQueries, - retestethContext::getPendingTransactions, - parameters, - true), - new DebugStorageRangeAt( - parameters, - retestethContext::getBlockchainQueries, - retestethContext::getBlockReplay, - true), - new TestModifyTimestamp(retestethContext, parameters), - new EthSendRawTransaction(retestethContext::getTransactionPool, parameters, true), - new TestMineBlocks(retestethContext, parameters), - new TestGetLogHash(retestethContext, parameters), - new TestRewindToBlock(retestethContext, parameters)); + final Map jsonRpcMethods = + mapOf( + new Web3ClientVersion(clientVersion), + new TestSetChainParams(retestethContext), + new TestImportRawBlock(retestethContext, parameters), + new EthBlockNumber(retestethContext::getBlockchainQueries, true), + new EthGetBlockByNumber( + retestethContext::getBlockchainQueries, blockResult, parameters, true), + new DebugAccountRange(parameters, retestethContext::getBlockchainQueries), + new EthGetBalance(retestethContext::getBlockchainQueries, parameters), + new EthGetCode(retestethContext::getBlockchainQueries, parameters), + new EthGetTransactionCount( + retestethContext::getBlockchainQueries, + retestethContext::getPendingTransactions, + parameters, + true), + new DebugStorageRangeAt( + parameters, + retestethContext::getBlockchainQueries, + retestethContext::getBlockReplay, + true), + new TestModifyTimestamp(retestethContext, parameters), + new EthSendRawTransaction(retestethContext::getTransactionPool, parameters, true), + new TestMineBlocks(retestethContext, parameters), + new TestGetLogHash(retestethContext, parameters), + new TestRewindToBlock(retestethContext, parameters)); jsonRpcHttpService = new JsonRpcHttpService( @@ -112,4 +111,9 @@ public void close() { public void stop() { jsonRpcHttpService.stop(); } + + private static Map mapOf(final JsonRpcMethod... rpcMethods) { + return Arrays.stream(rpcMethods) + .collect(Collectors.toMap(JsonRpcMethod::getName, rpcMethod -> rpcMethod)); + } }