Skip to content

Commit

Permalink
Add new RPC endpoints debug_setHead & debug_replayBlock (hyperledger#…
Browse files Browse the repository at this point in the history
…4580)

* add debug_setHead & debug_replayBlock endpoint

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>
  • Loading branch information
daniellehrner authored Nov 12, 2022
1 parent e2b1994 commit 6a3d452
Show file tree
Hide file tree
Showing 29 changed files with 784 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Support for ephemeral testnet Shandong. EIPs are still in flux, besu does not fully sync yet, and the network is subject to restarts. [#//FIXME](https://github.com/hyperledger/besu/pull///FIXME)
- Improve performance of block processing by parallelizing some parts during the "commit" step [#4635](https://github.com/hyperledger/besu/pull/4635)
- Upgrade RocksDB version from 7.6.0 to 7.7.3
- Added new RPC endpoints `debug_setHead` & `debug_replayBlock [4580](https://github.com/hyperledger/besu/pull/4580)

### Bug Fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ private String getDiscoveryPort() {
return port;
}

private Optional<String> jsonRpcBaseUrl() {
public Optional<String> jsonRpcBaseUrl() {
if (isJsonRpcEnabled()) {
return Optional.of(
HTTP + jsonRpcConfiguration.getHost() + ":" + portsProperties.getProperty(JSON_RPC));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ public BesuNodeConfigurationBuilder jsonRpcAdmin() {
return this;
}

public BesuNodeConfigurationBuilder jsonRpcDebug() {
this.jsonRpcConfiguration.addRpcApi(RpcApis.DEBUG.name());
return this;
}

public BesuNodeConfigurationBuilder jsonRpcAuthenticationConfiguration(final String authFile)
throws URISyntaxException {
final String authTomlPath =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ public BesuNode createCustomGenesisNode(
public BesuNode createExecutionEngineGenesisNode(final String name, final String genesisPath)
throws IOException {
final String genesisFile = GenesisConfigurationFactory.readGenesisFile(genesisPath);

return create(
new BesuNodeConfigurationBuilder()
.name(name)
Expand All @@ -521,6 +522,7 @@ public BesuNode createExecutionEngineGenesisNode(final String name, final String
.miningEnabled()
.jsonRpcEnabled()
.engineRpcEnabled(true)
.jsonRpcDebug()
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static class JsonRpcTestsContext {

public JsonRpcTestsContext(final String genesisFile) throws IOException {
cluster = new Cluster(new NetConditions(new NetTransactions()));

besuNode =
new BesuNodeFactory().createExecutionEngineGenesisNode("executionEngine", genesisFile);
cluster.start(besuNode);
Expand Down Expand Up @@ -78,10 +79,12 @@ public void test() throws IOException {
final JsonRpcTestCase testCase =
testsContext.mapper.readValue(testCaseFileURI.toURL(), JsonRpcTestCase.class);

final String rpcMethod = String.valueOf(testCase.getRequest().get("method"));

final Call testRequest =
testsContext.httpClient.newCall(
new Request.Builder()
.url(testsContext.besuNode.engineRpcUrl().get())
.url(getRpcUrl(rpcMethod))
.post(RequestBody.create(testCase.getRequest().toString(), MEDIA_TYPE_JSON))
.build());
final Response response = testRequest.execute();
Expand All @@ -90,6 +93,14 @@ public void test() throws IOException {
assertThat(response.body().string()).isEqualTo(testCase.getResponse().toPrettyString());
}

private String getRpcUrl(final String rpcMethod) {
if (rpcMethod.contains("eth_") || rpcMethod.contains("engine_")) {
return testsContext.besuNode.engineRpcUrl().get();
}

return testsContext.besuNode.jsonRpcBaseUrl().get();
}

public static Iterable<Object[]> testCases(final String testCasesPath) throws URISyntaxException {

final File[] testCasesList =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright Hyperledger Besu Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.tests.acceptance.jsonrpc;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

@RunWith(Parameterized.class)
public class DebugReplayBlockAcceptanceTest extends AbstractJsonRpcTest {
private static final String GENESIS_FILE = "/jsonrpc/debug/replayBlock/genesis.json";
private static final String TEST_CASE_PATH = "/jsonrpc/debug/replayBlock/test-cases/";

private static AbstractJsonRpcTest.JsonRpcTestsContext testsContext;

public DebugReplayBlockAcceptanceTest(final String ignored, final URI testCaseFileURI) {
super(ignored, testsContext, testCaseFileURI);
}

@BeforeClass
public static void init() throws IOException {
testsContext = new JsonRpcTestsContext(GENESIS_FILE);
}

@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> testCases() throws URISyntaxException {
return testCases(TEST_CASE_PATH);
}

@AfterClass
public static void tearDown() {
testsContext.cluster.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright Hyperledger Besu Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.tests.acceptance.jsonrpc;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

@RunWith(Parameterized.class)
public class DebugSetHeadAcceptanceTest extends AbstractJsonRpcTest {
private static final String GENESIS_FILE = "/jsonrpc/debug/setHead/genesis.json";
private static final String TEST_CASE_PATH = "/jsonrpc/debug/setHead/test-cases/";

private static JsonRpcTestsContext testsContext;

public DebugSetHeadAcceptanceTest(final String ignored, final URI testCaseFileURI) {
super(ignored, testsContext, testCaseFileURI);
}

@BeforeClass
public static void init() throws IOException {
testsContext = new JsonRpcTestsContext(GENESIS_FILE);
}

@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> testCases() throws URISyntaxException {
return testCases(TEST_CASE_PATH);
}

@AfterClass
public static void tearDown() {
testsContext.cluster.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"config": {
"chainId":1,
"homesteadBlock":0,
"eip150Block":0,
"eip155Block":0,
"eip158Block":0,
"byzantiumBlock":0,
"constantinopleBlock":0,
"petersburgBlock":0,
"istanbulBlock":0,
"muirGlacierBlock":0,
"berlinBlock":0,
"londonBlock":0,
"clique": {
"period": 5,
"epoch": 30000
},
"terminalTotalDifficulty":0
},
"nonce":"0x42",
"timestamp":"0x0",
"extraData":"0x0000000000000000000000000000000000000000000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"gasLimit":"0x1C9C380",
"difficulty":"0x400000000",
"mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase":"0x0000000000000000000000000000000000000000",
"alloc":{
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b":{"balance":"0x6d6172697573766477000000"}
},
"number":"0x0",
"gasUsed":"0x0",
"parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000",
"baseFeePerGas":"0x7"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"request": {
"jsonrpc": "2.0",
"method": "engine_forkchoiceUpdatedV1",
"params": [
{
"headBlockHash": "0x3b8fb240d288781d4aac94d3fd16809ee413bc99294a085798a589dae51ddd4a",
"safeBlockHash": "0x3b8fb240d288781d4aac94d3fd16809ee413bc99294a085798a589dae51ddd4a",
"finalizedBlockHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
},
{
"timestamp": "0x5",
"prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000",
"suggestedFeeRecipient": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"
}
],
"id": 67
},
"response": {
"jsonrpc": "2.0",
"id": 67,
"result": {
"payloadStatus": {
"status": "VALID",
"latestValidHash": "0x3b8fb240d288781d4aac94d3fd16809ee413bc99294a085798a589dae51ddd4a",
"validationError": null
},
"payloadId": "0x0065bd195a9b3bfb"
}
},
"statusCode" : 200
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"request": {
"jsonrpc": "2.0",
"method": "engine_newPayloadV1",
"params": [
{
"parentHash": "0x3b8fb240d288781d4aac94d3fd16809ee413bc99294a085798a589dae51ddd4a",
"feeRecipient": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"stateRoot": "0xca3149fa9e37db08d1cd49c9061db1002ef1cd58db2210f2115c8c989b2bdf45",
"receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000",
"blockNumber": "0x1",
"gasLimit": "0x1c9c380",
"gasUsed": "0x0",
"timestamp": "0x5",
"extraData": "0x",
"baseFeePerGas": "0x7",
"blockHash": "0x3559e851470f6e7bbed1db474980683e8c315bfce99b2a6ef47c057c04de7858",
"transactions": []
}
],
"id": 67
},
"response": {
"jsonrpc": "2.0",
"id": 67,
"result": {
"status": "VALID",
"latestValidHash": "0x3559e851470f6e7bbed1db474980683e8c315bfce99b2a6ef47c057c04de7858",
"validationError": null
}
},
"statusCode": 200
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"request": {
"jsonrpc": "2.0",
"method": "engine_newPayloadV1",
"params": [
{
"parentHash": "0x3559e851470f6e7bbed1db474980683e8c315bfce99b2a6ef47c057c04de7858",
"feeRecipient": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"stateRoot": "0xca3149fa9e37db08d1cd49c9061db1002ef1cd58db2210f2115c8c989b2bdf45",
"receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000",
"blockNumber": "0x2",
"gasLimit": "0x1c9c380",
"gasUsed": "0x0",
"timestamp": "0x6",
"extraData": "0x",
"baseFeePerGas": "0x7",
"blockHash": "0x80732341439dd124df94271386141735f13ef8a85e12e9fba15c06bc1ad9fd73",
"transactions": []
}
],
"id": 67
},
"response": {
"jsonrpc": "2.0",
"id": 67,
"result": {
"status": "VALID",
"latestValidHash": "0x80732341439dd124df94271386141735f13ef8a85e12e9fba15c06bc1ad9fd73",
"validationError": null
}
},
"statusCode": 200
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"request": {
"jsonrpc": "2.0",
"method": "engine_forkchoiceUpdatedV1",
"params": [
{
"headBlockHash": "0x80732341439dd124df94271386141735f13ef8a85e12e9fba15c06bc1ad9fd73",
"safeBlockHash": "0x80732341439dd124df94271386141735f13ef8a85e12e9fba15c06bc1ad9fd73",
"finalizedBlockHash": "0x3b8fb240d288781d4aac94d3fd16809ee413bc99294a085798a589dae51ddd4a"
},
null
],
"id": 67
},
"response": {
"jsonrpc": "2.0",
"id": 67,
"result": {
"payloadStatus": {
"status": "VALID",
"latestValidHash": "0x80732341439dd124df94271386141735f13ef8a85e12e9fba15c06bc1ad9fd73",
"validationError": null
},
"payloadId": null
}
},
"statusCode": 200
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"request": {
"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest", false],"id":1
},
"response": {
"jsonrpc": "2.0",
"id": 1,
"result": {
"number": "0x2",
"hash": "0x80732341439dd124df94271386141735f13ef8a85e12e9fba15c06bc1ad9fd73",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash": "0x3559e851470f6e7bbed1db474980683e8c315bfce99b2a6ef47c057c04de7858",
"nonce": "0x0000000000000000",
"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"stateRoot": "0xca3149fa9e37db08d1cd49c9061db1002ef1cd58db2210f2115c8c989b2bdf45",
"receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"miner": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"difficulty": "0x0",
"totalDifficulty": "0x400000000",
"extraData": "0x",
"baseFeePerGas": "0x7",
"size": "0x1fa",
"gasLimit": "0x1c9c380",
"gasUsed": "0x0",
"timestamp": "0x6",
"uncles": [],
"transactions": []
}
},
"statusCode": 200
}
Loading

0 comments on commit 6a3d452

Please sign in to comment.