Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new RPC methods debug_getRawBlock, debug_getRawReceipts, debug_getRawHeader, debug_getRawTransaction #6368

Merged
merged 44 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
c6593a4
Fix peer header when no peers to show (#4411)
smartprogrammer93 Aug 11, 2022
8779c1f
Revise product version (#4322)
rubo Aug 18, 2022
164fe9f
Replace submodules with packages (#4374)
rubo Aug 18, 2022
7d2764c
Add optional argument Address in parity_pendingTransactions (#4413)
smartprogrammer93 Aug 19, 2022
6688570
Add enough projects to build benchmark runner (#4431)
flcl42 Aug 24, 2022
2846174
Fix peer header when no peers to show (#4411)
smartprogrammer93 Aug 11, 2022
f7b2082
Revise product version (#4322)
rubo Aug 18, 2022
704bcf1
Replace submodules with packages (#4374)
rubo Aug 18, 2022
360a6f8
Add optional argument Address in parity_pendingTransactions (#4413)
smartprogrammer93 Aug 19, 2022
8ac41d4
Add enough projects to build benchmark runner (#4431)
flcl42 Aug 24, 2022
57fe7bb
Fix develop branch
dceleda Aug 29, 2022
054a80b
Merge branch 'develop' of https://github.com/NethermindEth/nethermind…
Demuirgos Aug 30, 2022
000d641
Exit early on error (#4220)
asdacap Sep 1, 2022
afd883f
Merge branch 'develop' of https://github.com/NethermindEth/nethermind…
Demuirgos Sep 5, 2022
c26e05f
Fix peer header when no peers to show (#4411)
smartprogrammer93 Aug 11, 2022
6fba7d6
Revise product version (#4322)
rubo Aug 18, 2022
b5c76b5
Replace submodules with packages (#4374)
rubo Aug 18, 2022
65e25b8
Add optional argument Address in parity_pendingTransactions (#4413)
smartprogrammer93 Aug 19, 2022
c937f09
Add enough projects to build benchmark runner (#4431)
flcl42 Aug 24, 2022
ef25479
Fix develop branch
dceleda Aug 29, 2022
c61837d
Exit early on error (#4220)
asdacap Sep 1, 2022
569dd87
Merge branch 'develop' of https://github.com/NethermindEth/nethermind…
Demuirgos Sep 7, 2022
c86c268
Changes to BlockForRPC class : Ignored Author field in JsonDeserializ…
Demuirgos Sep 8, 2022
c2e0235
Changes to TransactionForRPC class : Ignored 'data' field in JsonDese…
Demuirgos Sep 8, 2022
35794e6
Changes to [DebugBridge, IDebugBridge] files : Added utility function…
Demuirgos Sep 8, 2022
1c4cf2e
Changes to [DebugRpcModule, IDebugRpcModule] files : Added missing de…
Demuirgos Sep 8, 2022
854d6d4
Changes to TransactionForRPC class : Ignored 'data' field in JsonDese…
Demuirgos Sep 8, 2022
b0a9f62
Changes to ProofConverter class : stripped leading zeros from value f…
Demuirgos Sep 9, 2022
62337da
Changes to [DebugRpcModule, IDebugRpcModule] files : new Debug functi…
Demuirgos Sep 14, 2022
1585e95
Changes to [DebugRpcModule, IDebugRpcModule] files : fix getRawReceipts
Demuirgos Sep 14, 2022
3bf3c45
Changes to [DebugRpcModule, IDebugRpcModule] files : fix getRawReceip…
Demuirgos Sep 14, 2022
e55bcf5
Changes to [Rlp, ReceiptStorageDecoder] files : added parameterless c…
Demuirgos Sep 14, 2022
e6c6093
Changes to [ReceiptMessageDecoder] files : added IRlpObjectDecoder in…
Demuirgos Sep 14, 2022
11513e7
Changes to [Rlp] files : changed Decoder selection strategy to depend…
Demuirgos Sep 14, 2022
a08b27f
Changes to [DebugRpcModule] files : added custom RlpBehaviour to Rlp.…
Demuirgos Sep 14, 2022
527ab45
Changes to [EthRpcModule.cs] files : deactivated optimization for eth…
Demuirgos Sep 15, 2022
e4d897a
merge master
Demuirgos Dec 13, 2023
250d378
fix merge issues
Demuirgos Dec 13, 2023
94e2c54
fix failing tests
Demuirgos Dec 13, 2023
6687d4e
fixed ws
Demuirgos Dec 13, 2023
c41870e
fix merge issue
Demuirgos Dec 13, 2023
be8cf67
revert script changes
Demuirgos Dec 13, 2023
9db9db3
remove non related changes from PR
Demuirgos Dec 14, 2023
85b4099
Merge remote-tracking branch 'origin/master' into hive-test/rpc-compact
Demuirgos Dec 19, 2023
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
Empty file modified scripts/deployment/archive-packages.sh
100755 → 100644
Copy link
Contributor

Choose a reason for hiding this comment

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

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(happened after merging master) I actually dont know what is wrong here, I diffed master's version and these and they are identical

Empty file.
Empty file modified scripts/deployment/build-runner.sh
100755 → 100644
Copy link
Contributor

Choose a reason for hiding this comment

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

?

Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Nethermind.Logging;
using Nethermind.Serialization.Rlp;
using NSubstitute;
using NSubstitute.ReturnsExtensions;
using NUnit.Framework;

namespace Nethermind.JsonRpc.Test.Modules;
Expand Down Expand Up @@ -88,7 +89,7 @@ public async Task Get_block_rlp_by_hash()
{
BlockDecoder decoder = new();
Rlp rlp = decoder.Encode(Build.A.Block.WithNumber(1).TestObject);
debugBridge.GetBlockRlp(Keccak.Zero).Returns(rlp.Bytes);
debugBridge.GetBlockRlp(new BlockParameter(Keccak.Zero)).Returns(rlp.Bytes);

DebugRpcModule rpcModule = new(LimboLogs.Instance, debugBridge, jsonRpcConfig);
JsonRpcSuccessResponse? response = await RpcTest.TestRequest<IDebugRpcModule>(rpcModule, "debug_getBlockRlpByHash", $"{Keccak.Zero.Bytes.ToHexString()}") as JsonRpcSuccessResponse;
Expand All @@ -101,7 +102,7 @@ public async Task Get_block_rlp()
BlockDecoder decoder = new();
IDebugBridge debugBridge = Substitute.For<IDebugBridge>();
Rlp rlp = decoder.Encode(Build.A.Block.WithNumber(1).TestObject);
debugBridge.GetBlockRlp(1).Returns(rlp.Bytes);
debugBridge.GetBlockRlp(new BlockParameter(1)).Returns(rlp.Bytes);

DebugRpcModule rpcModule = new(LimboLogs.Instance, debugBridge, jsonRpcConfig);
JsonRpcSuccessResponse? response = await RpcTest.TestRequest<IDebugRpcModule>(rpcModule, "debug_getBlockRlp", "1") as JsonRpcSuccessResponse;
Expand All @@ -112,7 +113,7 @@ public async Task Get_block_rlp()
[Test]
public async Task Get_block_rlp_when_missing()
{
debugBridge.GetBlockRlp(1).Returns((byte[])null!);
debugBridge.GetBlockRlp(new BlockParameter(1)).ReturnsNull();

DebugRpcModule rpcModule = new(LimboLogs.Instance, debugBridge, jsonRpcConfig);
JsonRpcErrorResponse? response = await RpcTest.TestRequest<IDebugRpcModule>(rpcModule, "debug_getBlockRlp", "1") as JsonRpcErrorResponse;
Expand All @@ -125,7 +126,7 @@ public async Task Get_block_rlp_by_hash_when_missing()
{
BlockDecoder decoder = new();
Rlp rlp = decoder.Encode(Build.A.Block.WithNumber(1).TestObject);
debugBridge.GetBlockRlp(Keccak.Zero).Returns((byte[])null!);
debugBridge.GetBlockRlp(new BlockParameter(Keccak.Zero)).ReturnsNull();

DebugRpcModule rpcModule = new(LimboLogs.Instance, debugBridge, jsonRpcConfig);
JsonRpcErrorResponse? response = await RpcTest.TestRequest<IDebugRpcModule>(rpcModule, "debug_getBlockRlpByHash", $"{Keccak.Zero.Bytes.ToHexString()}") as JsonRpcErrorResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,31 @@ public void InsertReceipts(BlockParameter blockParameter, TxReceipt[] txReceipts
_receiptStorage.Insert(block, txReceipts);
}

public TxReceipt[]? GetReceiptsForBlock(BlockParameter blockParam)
{
SearchResult<Block> searchResult = _blockTree.SearchForBlock(blockParam);
if (searchResult.IsError)
{
throw new InvalidDataException(searchResult.Error);
}

Block block = searchResult.Object;
return _receiptStorage.Get(block);
}

public Transaction? GetTransactionFromHash(Hash256 txHash)
{
Hash256 blockHash = _receiptStorage.FindBlockHash(txHash);
SearchResult<Block> searchResult = _blockTree.SearchForBlock(new BlockParameter(blockHash));
if (searchResult.IsError)
{
throw new InvalidDataException(searchResult.Error);
}
Block block = searchResult.Object;
TxReceipt txReceipt = _receiptStorage.Get(block).ForTransaction(txHash);
return block?.Transactions[txReceipt.Index];
}

public GethLikeTxTrace GetTransactionTrace(Hash256 transactionHash, CancellationToken cancellationToken, GethTraceOptions gethTraceOptions = null)
{
return _tracer.Trace(transactionHash, gethTraceOptions ?? GethTraceOptions.Default, cancellationToken);
Expand Down Expand Up @@ -153,11 +178,28 @@ public IReadOnlyCollection<GethLikeTxTrace> GetBlockTrace(Rlp blockRlp, Cancella
return _tracer.TraceBlock(blockRlp, gethTraceOptions ?? GethTraceOptions.Default, cancellationToken);
}


public byte[]? GetBlockRlp(BlockParameter parameter)
{
if (parameter.BlockHash is Hash256 hash)
{
return GetBlockRlp(hash);

}
if (parameter.BlockNumber is long num)
{
return GetBlockRlp(num);
}
return null;
}

public byte[] GetBlockRlp(Hash256 blockHash)
{
return _dbMappings[DbNames.Blocks].Get(blockHash);
}

public Block? GetBlock(BlockParameter param)
=> _blockTree.FindBlock(param);
public byte[] GetBlockRlp(long number)
{
Hash256 hash = _blockTree.FindHash(number);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public ResultWrapper<GcStats> debug_gcStats()

public ResultWrapper<byte[]> debug_getBlockRlp(long blockNumber)
{
byte[] rlp = _debugBridge.GetBlockRlp(blockNumber);
byte[] rlp = _debugBridge.GetBlockRlp(new BlockParameter(blockNumber));
if (rlp is null)
{
return ResultWrapper<byte[]>.Fail($"Block {blockNumber} was not found", ErrorCodes.ResourceNotFound);
Expand All @@ -219,7 +219,7 @@ public ResultWrapper<byte[]> debug_getBlockRlp(long blockNumber)

public ResultWrapper<byte[]> debug_getBlockRlpByHash(Hash256 hash)
{
byte[] rlp = _debugBridge.GetBlockRlp(hash);
byte[] rlp = _debugBridge.GetBlockRlp(new BlockParameter(hash));
if (rlp is null)
{
return ResultWrapper<byte[]>.Fail($"Block {hash} was not found", ErrorCodes.ResourceNotFound);
Expand Down Expand Up @@ -261,6 +261,50 @@ public ResultWrapper<bool> debug_resetHead(Hash256 blockHash)
return ResultWrapper<bool>.Success(true);
}

public ResultWrapper<byte[]> debug_getRawTransaction(Hash256 transactionHash)
{
var transaction = _debugBridge.GetTransactionFromHash(transactionHash);
if (transaction == null)
{
return ResultWrapper<byte[]>.Fail($"Transaction {transactionHash} was not found", ErrorCodes.ResourceNotFound);
}
var rlp = Rlp.Encode(transaction);
return ResultWrapper<byte[]>.Success(rlp.Bytes);
}

public ResultWrapper<byte[][]> debug_getRawReceipts(long blockNumber)
{
var receipts = _debugBridge.GetReceiptsForBlock(new BlockParameter(blockNumber));
if (receipts == null)
{
return ResultWrapper<byte[][]>.Fail($"Receipts are not found for block {blockNumber}", ErrorCodes.ResourceNotFound);
}

var rlp = receipts.Select(tx => Rlp.Encode(tx, RlpBehaviors.Eip658Receipts).Bytes);
return ResultWrapper<byte[][]>.Success(rlp.ToArray());
}

public ResultWrapper<byte[]> debug_getRawBlock(long blockNumber)
{
var blockRLP = _debugBridge.GetBlockRlp(new BlockParameter(blockNumber));
if (blockRLP == null)
{
return ResultWrapper<byte[]>.Fail($"Block {blockNumber} was not found", ErrorCodes.ResourceNotFound);
}
return ResultWrapper<byte[]>.Success(blockRLP);
}

public ResultWrapper<byte[]> debug_getRawHeader(long blockNumber)
{
var block = _debugBridge.GetBlock(new BlockParameter(blockNumber));
if (block == null)
{
return ResultWrapper<byte[]>.Fail($"Block {blockNumber} was not found", ErrorCodes.ResourceNotFound);
}
Rlp rlp = Rlp.Encode<BlockHeader>(block.Header);
return ResultWrapper<byte[]>.Success(rlp.Bytes);
}

public Task<ResultWrapper<SyncReportSymmary>> debug_getSyncStage()
{
return ResultWrapper<SyncReportSymmary>.Success(_debugBridge.GetCurrentSyncStage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public interface IDebugBridge
GethLikeTxTrace? GetTransactionTrace(Transaction transaction, BlockParameter blockParameter, CancellationToken cancellationToken, GethTraceOptions? gethTraceOptions = null);
IReadOnlyCollection<GethLikeTxTrace> GetBlockTrace(BlockParameter blockParameter, CancellationToken cancellationToken, GethTraceOptions gethTraceOptions = null);
IReadOnlyCollection<GethLikeTxTrace> GetBlockTrace(Rlp blockRlp, CancellationToken cancellationToken, GethTraceOptions? gethTraceOptions = null);
byte[] GetBlockRlp(BlockParameter param);
Block? GetBlock(BlockParameter param);
byte[] GetBlockRlp(Hash256 blockHash);
byte[] GetBlockRlp(long number);
byte[] GetDbValue(string dbName, byte[] key);
Expand All @@ -33,4 +35,6 @@ public interface IDebugBridge
void InsertReceipts(BlockParameter blockParameter, TxReceipt[] receipts);
SyncReportSymmary GetCurrentSyncStage();
IEnumerable<string> TraceBlockToFile(Hash256 blockHash, CancellationToken cancellationToken, GethTraceOptions? gethTraceOptions = null);
TxReceipt[]? GetReceiptsForBlock(BlockParameter param);
Transaction? GetTransactionFromHash(Hash256 hash);
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ public interface IDebugRpcModule : IRpcModule
[JsonRpcMethod(Description = "Insert receipts for the block after verifying receipts root correctness.")]
Task<ResultWrapper<bool>> debug_insertReceipts(BlockParameter blockParameter, ReceiptForRpc[] receiptForRpc);

[JsonRpcMethod(Description = "Get Raw Block format.")]
ResultWrapper<byte[]> debug_getRawBlock(long blockNumber);

[JsonRpcMethod(Description = "Get Raw Receipt format.")]
ResultWrapper<byte[][]> debug_getRawReceipts(long blockNumber);

[JsonRpcMethod(Description = "Get Raw Header format.")]
ResultWrapper<byte[]> debug_getRawHeader(long blockNumber);

[JsonRpcMethod(Description = "Get Raw Transaction format.")]
ResultWrapper<byte[]> debug_getRawTransaction(Hash256 transactionHash);

[JsonRpcMethod(Description = "Retrives Nethermind Sync Stage, With extra Metadata")]
Task<ResultWrapper<SyncReportSymmary>> debug_getSyncStage();

Expand Down