Skip to content

Commit

Permalink
Split GetPayload result into V2 and V3
Browse files Browse the repository at this point in the history
  • Loading branch information
flcl42 committed Apr 26, 2023
1 parent bf48339 commit 6cd7555
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public partial class EngineModuleTests
public async Task ExccessDataGas_should_present_in_cancun_only((IReleaseSpec Spec, bool IsExcessDataGasSet) input)
{
(IEngineRpcModule rpcModule, string payloadId) = await BuildAndGetPayloadV3Result(input.Spec);
ResultWrapper<GetPayloadV2Result?> getPayloadResult =
ResultWrapper<GetPayloadV3Result?> getPayloadResult =
await rpcModule.engine_getPayloadV3(Bytes.FromHexString(payloadId));
Assert.That(getPayloadResult.Data!.ExecutionPayload.ExcessDataGas.HasValue,
Is.EqualTo(input.IsExcessDataGasSet));
Expand All @@ -40,7 +40,7 @@ public async Task GetPayloadV3_should_fail_on_unknown_payload()
IEngineRpcModule rpc = CreateEngineModule(chain);

byte[] payloadId = Bytes.FromHexString("0x0");
ResultWrapper<GetPayloadV2Result?> responseFirst = await rpc.engine_getPayloadV3(payloadId);
ResultWrapper<GetPayloadV3Result?> responseFirst = await rpc.engine_getPayloadV3(payloadId);
responseFirst.Should().NotBeNull();
responseFirst.Result.ResultType.Should().Be(ResultType.Failure);
responseFirst.ErrorCode.Should().Be(MergeErrorCodes.UnknownPayload);
Expand Down
13 changes: 3 additions & 10 deletions src/Nethermind/Nethermind.Merge.Plugin/Data/BlobsBundleV1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Collections.Generic;
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Newtonsoft.Json;

namespace Nethermind.Merge.Plugin.Data;

Expand All @@ -16,10 +13,6 @@ namespace Nethermind.Merge.Plugin.Data;
/// </summary>
public class BlobsBundleV1
{
public BlobsBundleV1()
{
}

public BlobsBundleV1(Block block)
{
int blobsCount = 0;
Expand Down Expand Up @@ -54,7 +47,7 @@ public BlobsBundleV1(Block block)
}
}

public Memory<byte>[]? Commitments { get; set; }
public Memory<byte>[]? Blobs { get; set; }
public Memory<byte>[]? Proofs { get; set; }
public Memory<byte>[] Commitments { get; }
public Memory<byte>[] Blobs { get; }
public Memory<byte>[] Proofs { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,15 @@ namespace Nethermind.Merge.Plugin.Data;

public class GetPayloadV2Result
{
public GetPayloadV2Result(Block block, UInt256 blockFees, BlobsBundleV1? blobsBundle = null)
public GetPayloadV2Result(Block block, UInt256 blockFees)
{
BlockValue = blockFees;
ExecutionPayload = new(block);
BlobsBundle = blobsBundle;
}

public UInt256 BlockValue { get; }

public ExecutionPayload ExecutionPayload { get; }


[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public BlobsBundleV1? BlobsBundle { get; }

public override string ToString() => $"{{ExecutionPayload: {ExecutionPayload}, Fees: {BlockValue}}}";
}
20 changes: 20 additions & 0 deletions src/Nethermind/Nethermind.Merge.Plugin/Data/GetPayloadV3Result.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Core;
using Nethermind.Int256;

namespace Nethermind.Merge.Plugin.Data;

public class GetPayloadV3Result : GetPayloadV2Result
{
public GetPayloadV3Result(Block block, UInt256 blockFees, BlobsBundleV1 blobsBundle) : base(block, blockFees)
{
BlobsBundle = blobsBundle;
}

public BlobsBundleV1 BlobsBundle { get; }

public override string ToString() =>
$"{{ExecutionPayload: {ExecutionPayload}, Fees: {BlockValue}, BlobsBundle blobs count: {BlobsBundle.Blobs.Length}}}";
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ namespace Nethermind.Merge.Plugin;

public partial class EngineRpcModule : IEngineRpcModule
{
private readonly IAsyncHandler<byte[], GetPayloadV2Result?> _getPayloadHandlerV3;
private readonly IAsyncHandler<byte[], GetPayloadV3Result?> _getPayloadHandlerV3;

public Task<ResultWrapper<PayloadStatusV1>> engine_newPayloadV3(ExecutionPayload executionPayload) =>
NewPayload(executionPayload, 3);

public async Task<ResultWrapper<GetPayloadV2Result?>> engine_getPayloadV3(byte[] payloadId) =>
public async Task<ResultWrapper<GetPayloadV3Result?>> engine_getPayloadV3(byte[] payloadId) =>
await _getPayloadHandlerV3.HandleAsync(payloadId);
}
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 @@ -23,7 +23,7 @@ public partial class EngineRpcModule : IEngineRpcModule
public EngineRpcModule(
IAsyncHandler<byte[], ExecutionPayload?> getPayloadHandlerV1,
IAsyncHandler<byte[], GetPayloadV2Result?> getPayloadHandlerV2,
IAsyncHandler<byte[], GetPayloadV2Result?> getPayloadHandlerV3,
IAsyncHandler<byte[], GetPayloadV3Result?> getPayloadHandlerV3,
IAsyncHandler<ExecutionPayload, PayloadStatusV1> newPayloadV1Handler,
IForkchoiceUpdatedHandler forkchoiceUpdatedV1Handler,
IAsyncHandler<IList<Keccak>, IEnumerable<ExecutionPayloadBodyV1Result?>> executionGetPayloadBodiesByHashV1Handler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ namespace Nethermind.Merge.Plugin.Handlers;
/// <a href="https://github.com/ethereum/execution-apis/blob/main/src/engine/experimental/blob-extension.md#engine_getpayloadv3">
/// engine_getpayloadv3</a>
/// </summary>
public class GetPayloadV3Handler : GetPayloadHandlerBase<GetPayloadV2Result>
public class GetPayloadV3Handler : GetPayloadHandlerBase<GetPayloadV3Result>
{
public GetPayloadV3Handler(IPayloadPreparationService payloadPreparationService, ILogManager logManager) : base(
3, payloadPreparationService, logManager)
{
}

protected override GetPayloadV2Result GetPayloadResultFromBlock(IBlockProductionContext context) =>
protected override GetPayloadV3Result GetPayloadResultFromBlock(IBlockProductionContext context) =>
new(context.CurrentBestBlock!, context.BlockFees, new BlobsBundleV1(context.CurrentBestBlock!));
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ public partial interface IEngineRpcModule : IRpcModule
Description = "Returns the most recent version of an execution payload and fees with respect to the transaction set contained by the mempool.",
IsSharable = true,
IsImplemented = true)]
public Task<ResultWrapper<GetPayloadV2Result?>> engine_getPayloadV3(byte[] payloadId);
public Task<ResultWrapper<GetPayloadV3Result?>> engine_getPayloadV3(byte[] payloadId);
}

0 comments on commit 6cd7555

Please sign in to comment.