Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
9d6d9e1
feat: added support for debug_getBadBlocks (#4889)
BartoszSolkaBD Feb 9, 2026
21ad2a4
test: refactor tests to not repeat test body (#4889)
BartoszSolkaBD Feb 11, 2026
cba3cee
docs: aligned summary field of debug_getBadBlocks in openrpc.json (#4…
BartoszSolkaBD Feb 11, 2026
145910e
test: added description to get-bad-blocks.io (#4889)
BartoszSolkaBD Feb 11, 2026
7896368
docs: added clarification for debug_getBadBlocks summary (#4889)
BartoszSolkaBD Feb 12, 2026
874238e
refactor: removed try-catch block in debug_getBadBlock (#4889)
BartoszSolkaBD Feb 12, 2026
26581f6
feat: added support for debug_getRawReceipt (#4892)
BartoszSolkaBD Feb 13, 2026
8d5d63d
Merge branch 'main' into 4892-Add-debug_getRawReceipts-method
BartoszSolkaBD Feb 13, 2026
06121e5
feat: added unit test that checks consistency between debug_getRawRec…
BartoszSolkaBD Feb 16, 2026
c9a54b2
chore: update comments in debug tests to specify Hedera Mainnet for c…
BartoszSolkaBD Feb 16, 2026
d115ca0
chore: added unit tests for receiptSerialization (#4892)
BartoszSolkaBD Feb 16, 2026
6fdd45c
chore: added unit test for canonical scalar encoding and aligned impl…
BartoszSolkaBD Feb 16, 2026
3b5780c
chore: removed debug_getRawReceipts from NOT_IMPLEMENTED_METHODS in o…
BartoszSolkaBD Feb 16, 2026
26d47da
Merge remote-tracking branch 'origin/main' into 4892-Add-debug_getRaw…
BartoszSolkaBD Feb 17, 2026
c91ef46
refactor: refactored debug_getRawReceipts to not reuse eth_getBlockRe…
BartoszSolkaBD Feb 19, 2026
8a876cc
fix: aligned ts-doc return type of getRawReceipts function (#4892)
BartoszSolkaBD Feb 19, 2026
fb1e877
Merge remote-tracking branch 'origin/main' into 4892-Add-debug_getRaw…
BartoszSolkaBD Feb 20, 2026
eed78ea
fix: added missing ts-docs; removed rlp related mappers from Transact…
BartoszSolkaBD Feb 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,30 @@
}
}
},
{
"name": "debug_getRawReceipts",
"summary": "Returns an array of EIP-2718 binary-encoded receipts.",
"description": "![](https://raw.githubusercontent.com/hiero-ledger/hiero-json-rpc-relay/main/docs/images/http_label.png)",
"params": [
{
"name": "block",
"required": true,
"schema": {
"$ref": "#/components/schemas/BlockNumberOrTagOrHash"
}
}
],
"result": {
"name": "debug_getRawReceipts result",
"description": "An array of EIP-2718 binary-encoded receipts.",
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/bytes"
}
}
}
},
{
"name": "eth_getProof",
"summary": "Always returns UNSUPPORTED_METHOD error.",
Expand Down
2 changes: 1 addition & 1 deletion docs/rpc-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ These methods are extensions provided by various Ethereum clients but are not pa
| [debug_getBadBlocks](https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-debug#debuggetbadblocks) | **Implemented** - Requires `DEBUG_API_ENABLED=true` | N/A | Always returns empty array |
| [debug_getRawBlock](https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-debug#debuggetrawblock) | **Implemented** - Requires `DEBUG_API_ENABLED=true` | N/A | |
| [debug_getRawHeader](https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-debug#debuggetrawheader) | **Not Implemented** | N/A | |
| [debug_getRawReceipts](https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-debug#debuggetrawreceipts) | **Not Implemented** | N/A | |
| [debug_getRawReceipts](https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-debug#debuggetrawreceipts) | **Implemented** - Requires `DEBUG_API_ENABLED=true` | N/A | |
| [debug_getRawTransaction](https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-debug#debuggetrawtransaction) | **Not Implemented** | N/A | |
| [debug_traceBlockByHash](https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-debug#debugtraceblockbyhash) | **Implemented** - Requires `DEBUG_API_ENABLED=true` | Mirror Node | Supports CallTracer and PrestateTracer, caches results |
| [debug_traceBlockByNumber](https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-debug#debugtraceblockbynumber) | **Implemented** - Requires `DEBUG_API_ENABLED=true` | Mirror Node | Supports CallTracer and PrestateTracer, caches results |
Expand Down
2 changes: 2 additions & 0 deletions packages/relay/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export interface Debug {
getRawBlock(blockNrOrHash: string, requestDetails: RequestDetails): Promise<string | JsonRpcError>;

traceBlockByHash(blockHash: string, tracerObject: BlockTracerConfig, requestDetails: RequestDetails): Promise<any>;

getRawReceipts(blockHashOrNumber: string, requestDetails: RequestDetails): Promise<string[]>;
}

export interface Web3 {
Expand Down
28 changes: 28 additions & 0 deletions packages/relay/src/lib/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,34 @@ export class DebugImpl implements Debug {
return [];
}

/**
* Returns an array of EIP-2718 binary-encoded receipts.
*
* @async
* @rpcMethod Exposed as debug_getRawReceipts RPC endpoint
* @rpcParamValidationRules Applies JSON-RPC parameter validation according to the API specification
*
* @param {string} blockHashOrNumber - The block hash or block number.
* @param {RequestDetails} requestDetails - The request details for logging and tracking.
* @throws {Error} Throws an error if the debug API is not enabled or if an exception occurs.
* @returns {Promise<string[]>} A Promise that resolves to an array of EIP-2718 binary-encoded receipts or empty array if block not found.
*
* @example
* const result = await getRawReceipts('0x1234', requestDetails);
* // result: ["0xe6808...", "0xe6809..."]
*/
@rpcMethod
@rpcParamValidationRules({
0: { type: ['blockNumber', 'blockHash'], required: true },
})
@cache({
skipParams: [{ index: '0', value: constants.NON_CACHABLE_BLOCK_PARAMS }],
})
async getRawReceipts(blockHashOrNumber: string, requestDetails: RequestDetails): Promise<string[]> {
DebugImpl.requireDebugAPIEnabled();
return await this.blockService.getRawReceipts(blockHashOrNumber, requestDetails);
}

/**
* Formats the result from the actions endpoint to the expected response
*
Expand Down
78 changes: 78 additions & 0 deletions packages/relay/src/lib/receiptSerialization.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange I really thought I left a comment on this file in the previous round of review. Anyhoo should we consider moving this module out of the root of src/lib where the other generic namespace modules live? It feels like the receipt-related logic here would be better encapsulated in a dedicated class rather than sitting alongside the other top-level modules. Since these methods are all doing transaction receipt related work, would it make sense to move them into the TransactionReceiptFactory class? That seems like a natural home for them and would keep things cleaner overall.

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// SPDX-License-Identifier: Apache-2.0

/**
* Receipt serialization per Ethereum Yellow Paper and EIP-2718.
*
* Yellow Paper: receipt is RLP of the 4-tuple
* (receipt_root_or_status, cumulative_gas_used, logs_bloom, logs).
* Post-Byzantium: first field is status (empty for 0, 0x01 for 1) or 32-byte state root.
* Each log: RLP([address, topics[], data]).
*
* EIP-2718: for typed txs (type !== 0), wire format is type_byte || RLP(above 4-tuple).
*/

import { RLP } from '@ethereumjs/rlp';
import { bytesToInt, concatBytes, hexToBytes, intToBytes } from '@ethereumjs/util';

import { prepend0x, toHexString } from '../formatters';
import constants from './constants';
import type { Log } from './model';
import { IReceiptRlpInput } from './types/IReceiptRlpInput';

/**
* Converts receipt logs into the RLP encoded log structure.
*
* Each log becomes a 3-tuple [address, topics[], data] per the Yellow Paper
* (address and data as bytes; topics as array of 32-byte topic hashes).
*
* @param logs - The logs array from the transaction receipt (see {@link Log}).
* @returns Array of [address, topics, data] as Uint8Arrays for RLP encoding.
*/
function encodeLogsForReceipt(logs: Log[]): [Uint8Array, Uint8Array[], Uint8Array][] {
return logs.map((log) => [hexToBytes(log.address), log.topics.map((t) => hexToBytes(t)), hexToBytes(log.data)]);
}

/**
* Encodes a single transaction receipt to EIP-2718 binary form.
*
* Produces the RLP-encoded 4-tuple (receipt_root_or_status, cumulative_gas_used,
* logs_bloom, logs) per the Ethereum Yellow Paper. For typed transactions (type !== 0),
* the output is the single-byte type prefix followed by that RLP payload (EIP-2718).
*
* Based on section 4.4.1 (Transaction Receipt) from the Ethereum Yellow Paper: https://ethereum.github.io/yellowpaper/paper.pdf
*
* @param receipt - The transaction receipt to encode (see {@link ITransactionReceipt}).
* @returns Hex string (0x-prefixed) of the encoded receipt, suitable for receipts root hashing.
*/
export function encodeReceiptToHex(receipt: IReceiptRlpInput): string {
const txType = receipt.type !== null ? bytesToInt(hexToBytes(receipt.type)) : 0;

// First field: receipt root or status (post-Byzantium)
let receiptRootOrStatus: Uint8Array;
if (receipt.root && receipt.root.length > 2) {
receiptRootOrStatus = hexToBytes(receipt.root);
} else if (receipt.status && bytesToInt(hexToBytes(receipt.status)) === 0) {
receiptRootOrStatus = new Uint8Array(0);
} else {
receiptRootOrStatus = hexToBytes(constants.ONE_HEX);
}

const cumulativeGasUsed = receipt.cumulativeGasUsed;
const cumulativeGasUsedBytes =
BigInt(cumulativeGasUsed) === BigInt(0)
? new Uint8Array(0)
: hexToBytes(prepend0x(BigInt(cumulativeGasUsed).toString(16))); // canonical RLP encoding (no leading zeros)

const encodedList = RLP.encode([
receiptRootOrStatus,
cumulativeGasUsedBytes,
hexToBytes(receipt.logsBloom),
encodeLogsForReceipt(receipt.logs),
]);

if (txType === 0) {
return prepend0x(toHexString(encodedList));
}
const withPrefix = concatBytes(intToBytes(txType), encodedList);
return prepend0x(toHexString(withPrefix));
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import { Logger } from 'pino';

import { numberTo0x } from '../../../../formatters';
import { ICacheClient } from '../../../clients/cache/ICacheClient';
import { MirrorNodeClient } from '../../../clients/mirrorNodeClient';
import constants from '../../../constants';
import { Block } from '../../../model';
import { ITransactionReceipt, MirrorNodeBlock, RequestDetails } from '../../../types';
import { IBlockService, ICommonService } from '../../index';
import { WorkersPool } from '../../workersService/WorkersPool';
import { ICacheClient } from '../../../clients/cache/ICacheClient';

export class BlockService implements IBlockService {
/**
Expand Down Expand Up @@ -115,6 +115,25 @@ export class BlockService implements IBlockService {
);
}

/**
* Gets the raw transaction receipts for a block by block hash or block number.
*
* @param {string} blockHashOrBlockNumber The block hash or block number
* @param {RequestDetails} requestDetails The request details for logging and tracking
* @returns {Promise<string[]>} Array of raw block receipts for the block
*/
public async getRawReceipts(blockHashOrBlockNumber: string, requestDetails: RequestDetails): Promise<string[]> {
return WorkersPool.run(
{
type: 'getRawReceipts',
blockHashOrBlockNumber,
requestDetails,
},
this.mirrorNodeClient,
this.cacheService,
);
}

/**
* Gets the number of transaction in a block by its block hash.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface IBlockService {
getBlockTransactionCountByHash: (hash: string, requestDetails: RequestDetails) => Promise<string | null>;
getBlockTransactionCountByNumber: (blockNum: string, requestDetails: RequestDetails) => Promise<string | null>;
getBlockReceipts: (blockHash: string, requestDetails: RequestDetails) => Promise<ITransactionReceipt[] | null>;
getRawReceipts: (blockHashOrBlockNumber: string, requestDetails: RequestDetails) => Promise<string[]>;
getUncleByBlockHashAndIndex: (blockHash: string, index: string) => null;
getUncleByBlockNumberAndIndex: (blockNumOrTag: string, index: string) => null;
getUncleCountByBlockHash: (blockHash: string) => string;
Expand Down
Loading
Loading