From 7053ee56564d9a73f0d5b543deb3457e4318da7b Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Mon, 22 May 2023 11:21:54 +1000 Subject: [PATCH] Implement debug_getRawReceipts (#5476) Co-authored-by: Gabriel-Trintinalia Signed-off-by: Adrian Sutton --- CHANGELOG.md | 1 + .../besu/ethereum/api/jsonrpc/RpcMethod.java | 1 + .../internal/methods/DebugGetRawReceipts.java | 61 +++++++++++++++++++ .../jsonrpc/methods/DebugJsonRpcMethods.java | 4 +- 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawReceipts.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 891197a910..f129925dcf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - New optional feature to save the txpool content to file on shutdown and reloading it on startup [#5434](https://github.com/hyperledger/besu/pull/5434) - New option to send SNI header in TLS ClientHello message [#5439](https://github.com/hyperledger/besu/pull/5439) - Early access - layered transaction pool implementation [#5290](https://github.com/hyperledger/besu/pull/5290) +- New RPC method `debug_getRawReceipts` ### Bug Fixes - Fix eth_feeHistory response for the case in which blockCount is higher than highestBlock requested. [#5397](https://github.com/hyperledger/besu/pull/5397) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/RpcMethod.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/RpcMethod.java index bdecee7c9e..4530e22baa 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/RpcMethod.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/RpcMethod.java @@ -48,6 +48,7 @@ public enum RpcMethod { DEBUG_GET_BAD_BLOCKS("debug_getBadBlocks"), DEBUG_GET_RAW_HEADER("debug_getRawHeader"), DEBUG_GET_RAW_BLOCK("debug_getRawBlock"), + DEBUG_GET_RAW_RECEIPTS("debug_getRawReceipts"), ENGINE_GET_PAYLOAD_V1("engine_getPayloadV1"), ENGINE_GET_PAYLOAD_V2("engine_getPayloadV2"), ENGINE_NEW_PAYLOAD_V1("engine_newPayloadV1"), diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawReceipts.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawReceipts.java new file mode 100644 index 0000000000..9e879de517 --- /dev/null +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawReceipts.java @@ -0,0 +1,61 @@ +/* + * Copyright Hyperledger Besu Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods; + +import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameterOrBlockHash; +import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; +import org.hyperledger.besu.ethereum.core.TransactionReceipt; +import org.hyperledger.besu.ethereum.rlp.RLP; + +import java.util.List; + +import com.google.common.base.Suppliers; + +public class DebugGetRawReceipts extends AbstractBlockParameterOrBlockHashMethod { + + public DebugGetRawReceipts(final BlockchainQueries blockchain) { + super(Suppliers.ofInstance(blockchain)); + } + + @Override + public String getName() { + return RpcMethod.DEBUG_GET_RAW_RECEIPTS.getMethodName(); + } + + @Override + protected BlockParameterOrBlockHash blockParameterOrBlockHash( + final JsonRpcRequestContext request) { + return request.getRequiredParameter(0, BlockParameterOrBlockHash.class); + } + + @Override + protected Object resultByBlockHash(final JsonRpcRequestContext request, final Hash blockHash) { + return blockchainQueries + .get() + .getBlockchain() + .getTxReceipts(blockHash) + .map(this::toRLP) + .orElseGet(() -> new String[0]); + } + + private String[] toRLP(final List receipts) { + return receipts.stream() + .map(receipt -> RLP.encode(receipt::writeTo).toHexString()) + .toArray(String[]::new); + } +} 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 index cce9ada72a..0dc681bf2f 100644 --- 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 @@ -23,6 +23,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugBatchSend import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugGetBadBlocks; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugGetRawBlock; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugGetRawHeader; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugGetRawReceipts; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugMetrics; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugResyncWorldstate; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugSetHead; @@ -109,6 +110,7 @@ public class DebugJsonRpcMethods extends ApiGroupJsonRpcMethods { () -> new TransactionTracer(blockReplay), blockchainQueries, protocolSchedule, dataDir), new DebugAccountAt(blockchainQueries, () -> new BlockTracer(blockReplay)), new DebugGetRawHeader(blockchainQueries), - new DebugGetRawBlock(blockchainQueries)); + new DebugGetRawBlock(blockchainQueries), + new DebugGetRawReceipts(blockchainQueries)); } }