Skip to content

Commit

Permalink
Fix json response in engine_getBlobsV1 (#7650)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcindsobczak authored Oct 24, 2024
1 parent 0b6328b commit c9deec9
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 34 deletions.
29 changes: 14 additions & 15 deletions src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public async Task<string> NewPayloadV3_should_verify_blob_versioned_hashes_again
Substitute.For<IGetPayloadBodiesByRangeV2Handler>(),
Substitute.For<IHandler<TransitionConfigurationV1, TransitionConfigurationV1>>(),
Substitute.For<IHandler<IEnumerable<string>, IEnumerable<string>>>(),
Substitute.For<IAsyncHandler<byte[][], GetBlobsV1Result>>(),
Substitute.For<IAsyncHandler<byte[][], IEnumerable<BlobAndProofV1?>>>(),
chain.SpecProvider,
new GCKeeper(NoGCStrategy.Instance, chain.LogManager),
Substitute.For<ILogManager>()));
Expand Down Expand Up @@ -539,7 +539,7 @@ public async Task GetBlobsV1_should_throw_if_more_than_128_requested_blobs([Valu
request.Add(Bytes.FromHexString(i.ToString("X64")));
}

ResultWrapper<GetBlobsV1Result> result = await rpcModule.engine_getBlobsV1(request.ToArray());
ResultWrapper<IEnumerable<BlobAndProofV1?>> result = await rpcModule.engine_getBlobsV1(request.ToArray());

if (requestSize > 128)
{
Expand All @@ -549,7 +549,7 @@ public async Task GetBlobsV1_should_throw_if_more_than_128_requested_blobs([Valu
else
{
result.Result.Should().Be(Result.Success);
result.Data.BlobsAndProofs.Should().HaveCount(requestSize);
result.Data.Should().HaveCount(requestSize);
}
}

Expand All @@ -559,10 +559,10 @@ public async Task GetBlobsV1_should_handle_empty_request()
MergeTestBlockchain chain = await CreateBlockchain(releaseSpec: Cancun.Instance);
IEngineRpcModule rpcModule = CreateEngineModule(chain, null, TimeSpan.FromDays(1));

ResultWrapper<GetBlobsV1Result> result = await rpcModule.engine_getBlobsV1([]);
ResultWrapper<IEnumerable<BlobAndProofV1?>> result = await rpcModule.engine_getBlobsV1([]);

result.Result.Should().Be(Result.Success);
result.Data.Should().BeEquivalentTo(new GetBlobsV1Result(ArraySegment<BlobAndProofV1?>.Empty));
result.Data.Should().BeEquivalentTo(ArraySegment<BlobAndProofV1?>.Empty);
}

[Test]
Expand All @@ -580,11 +580,11 @@ public async Task GetBlobsV1_should_return_requested_blobs([Values(1, 2, 3, 4, 5

chain.TxPool.SubmitTx(blobTx, TxHandlingOptions.None).Should().Be(AcceptTxResult.Accepted);

ResultWrapper<GetBlobsV1Result> result = await rpcModule.engine_getBlobsV1(blobTx.BlobVersionedHashes!);
ResultWrapper<IEnumerable<BlobAndProofV1?>> result = await rpcModule.engine_getBlobsV1(blobTx.BlobVersionedHashes!);

ShardBlobNetworkWrapper wrapper = (ShardBlobNetworkWrapper)blobTx.NetworkWrapper!;
result.Data.BlobsAndProofs.Select(b => b!.Blob).Should().BeEquivalentTo(wrapper.Blobs);
result.Data.BlobsAndProofs.Select(b => b!.Proof).Should().BeEquivalentTo(wrapper.Proofs);
result.Data.Select(b => b!.Blob).Should().BeEquivalentTo(wrapper.Blobs);
result.Data.Select(b => b!.Proof).Should().BeEquivalentTo(wrapper.Proofs);
}

[Test]
Expand All @@ -602,10 +602,10 @@ public async Task GetBlobsV1_should_return_nulls_when_blobs_not_found([Values(1,
.SignedAndResolved(chain.EthereumEcdsa, TestItem.PrivateKeyA).TestObject;

// requesting hashes that are not present in TxPool
ResultWrapper<GetBlobsV1Result> result = await rpcModule.engine_getBlobsV1(blobTx.BlobVersionedHashes!);
ResultWrapper<IEnumerable<BlobAndProofV1?>> result = await rpcModule.engine_getBlobsV1(blobTx.BlobVersionedHashes!);

result.Data.BlobsAndProofs.Should().HaveCount(numberOfRequestedBlobs);
result.Data.BlobsAndProofs.Should().AllBeEquivalentTo<BlobAndProofV1?>(null);
result.Data.Should().HaveCount(numberOfRequestedBlobs);
result.Data.Should().AllBeEquivalentTo<BlobAndProofV1?>(null);
}

[Test]
Expand Down Expand Up @@ -638,12 +638,11 @@ public async Task GetBlobsV1_should_return_mix_of_blobs_and_nulls([Values(1, 2,
: null);
blobVersionedHashesRequest.Add(addActualHash ? blobTx.BlobVersionedHashes![actualIndex++]! : Bytes.FromHexString(i.ToString("X64")));
}
GetBlobsV1Result expected = new(blobsAndProofs.ToArray());

ResultWrapper<GetBlobsV1Result> result = await rpcModule.engine_getBlobsV1(blobVersionedHashesRequest.ToArray());
ResultWrapper<IEnumerable<BlobAndProofV1?>> result = await rpcModule.engine_getBlobsV1(blobVersionedHashesRequest.ToArray());

result.Data.Should().BeEquivalentTo(expected);
BlobAndProofV1?[] resultBlobsAndProofs = result.Data.BlobsAndProofs.ToArray();
result.Data.Should().BeEquivalentTo(blobsAndProofs);
BlobAndProofV1?[] resultBlobsAndProofs = result.Data.ToArray();
resultBlobsAndProofs.Length.Should().Be(requestSize);
for (int i = 0; i < requestSize; i++)
{
Expand Down
11 changes: 0 additions & 11 deletions src/Nethermind/Nethermind.Merge.Plugin/Data/GetBlobsV1Result.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System.Collections.Generic;
using System.Threading.Tasks;
using Nethermind.Consensus;
using Nethermind.Consensus.Producers;
Expand All @@ -14,7 +15,7 @@ namespace Nethermind.Merge.Plugin;
public partial class EngineRpcModule : IEngineRpcModule
{
private readonly IAsyncHandler<byte[], GetPayloadV3Result?> _getPayloadHandlerV3;
private readonly IAsyncHandler<byte[][], GetBlobsV1Result> _getBlobsHandler;
private readonly IAsyncHandler<byte[][], IEnumerable<BlobAndProofV1?>> _getBlobsHandler;

public Task<ResultWrapper<ForkchoiceUpdatedV1Result>> engine_forkchoiceUpdatedV3(ForkchoiceStateV1 forkchoiceState, PayloadAttributes? payloadAttributes = null)
=> ForkchoiceUpdated(forkchoiceState, payloadAttributes, EngineApiVersions.Cancun);
Expand All @@ -25,6 +26,6 @@ public Task<ResultWrapper<PayloadStatusV1>> engine_newPayloadV3(ExecutionPayload
public async Task<ResultWrapper<GetPayloadV3Result?>> engine_getPayloadV3(byte[] payloadId) =>
await _getPayloadHandlerV3.HandleAsync(payloadId);

public async Task<ResultWrapper<GetBlobsV1Result>> engine_getBlobsV1(byte[][] blobVersionedHashes) =>
public async Task<ResultWrapper<IEnumerable<BlobAndProofV1?>>> engine_getBlobsV1(byte[][] blobVersionedHashes) =>
await _getBlobsHandler.HandleAsync(blobVersionedHashes);
}
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public EngineRpcModule(
IGetPayloadBodiesByRangeV2Handler executionGetPayloadBodiesByRangeV2Handler,
IHandler<TransitionConfigurationV1, TransitionConfigurationV1> transitionConfigurationHandler,
IHandler<IEnumerable<string>, IEnumerable<string>> capabilitiesHandler,
IAsyncHandler<byte[][], GetBlobsV1Result> getBlobsHandler,
IAsyncHandler<byte[][], IEnumerable<BlobAndProofV1?>> getBlobsHandler,
ISpecProvider specProvider,
GCKeeper gcKeeper,
ILogManager logManager)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@

namespace Nethermind.Merge.Plugin.Handlers;

public class GetBlobsHandler(ITxPool txPool) : IAsyncHandler<byte[][], GetBlobsV1Result>
public class GetBlobsHandler(ITxPool txPool) : IAsyncHandler<byte[][], IEnumerable<BlobAndProofV1?>>
{
private const int MaxRequest = 128;

public Task<ResultWrapper<GetBlobsV1Result>> HandleAsync(byte[][] request)
public Task<ResultWrapper<IEnumerable<BlobAndProofV1?>>> HandleAsync(byte[][] request)
{
if (request.Length > MaxRequest)
{
var error = $"The number of requested blobs must not exceed {MaxRequest}";
return ResultWrapper<GetBlobsV1Result>.Fail(error, MergeErrorCodes.TooLargeRequest);
return ResultWrapper<IEnumerable<BlobAndProofV1?>>.Fail(error, MergeErrorCodes.TooLargeRequest);
}

return ResultWrapper<GetBlobsV1Result>.Success(new GetBlobsV1Result(GetBlobsAndProofs(request)));
return ResultWrapper<IEnumerable<BlobAndProofV1?>>.Success(GetBlobsAndProofs(request));
}

private IEnumerable<BlobAndProofV1?> GetBlobsAndProofs(byte[][] request)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System.Collections.Generic;
using System.Threading.Tasks;
using Nethermind.Consensus.Producers;
using Nethermind.Core.Crypto;
Expand Down Expand Up @@ -35,5 +36,5 @@ public partial interface IEngineRpcModule : IRpcModule
Description = "Returns requested blobs and proofs.",
IsSharable = true,
IsImplemented = true)]
public Task<ResultWrapper<GetBlobsV1Result>> engine_getBlobsV1(byte[][] blobVersionedHashes);
public Task<ResultWrapper<IEnumerable<BlobAndProofV1?>>> engine_getBlobsV1(byte[][] blobVersionedHashes);
}

0 comments on commit c9deec9

Please sign in to comment.