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

NewPayloadV3 required fields json deserialization #6362

Merged
merged 10 commits into from
Dec 14, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
using System.Collections.Generic;
using System.IO.Abstractions;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
using k8s.Models;
using Nethermind.Consensus.Producers;
using Nethermind.Core;
using Nethermind.Core.Crypto;
Expand All @@ -28,7 +26,6 @@
using Nethermind.Merge.Plugin.Handlers;
using Nethermind.Serialization.Json;
using Nethermind.Serialization.Rlp;
using Nethermind.Specs;
using Nethermind.Specs.Forks;
using NSubstitute;
using NUnit.Framework;
Expand Down Expand Up @@ -190,7 +187,6 @@ public async Task NewPayloadV3_should_decline_null_blobversionedhashes()
= await PreparePayloadRequestEnv();

string executionPayloadString = serializer.Serialize(executionPayload);
string blobsString = serializer.Serialize(Array.Empty<byte[]>());

JsonRpcRequest request = RpcTest.GetJsonRequest(nameof(IEngineRpcModule.engine_newPayloadV3),
executionPayloadString, null!);
Expand All @@ -199,6 +195,24 @@ public async Task NewPayloadV3_should_decline_null_blobversionedhashes()
Assert.That(response!.Error!.Code, Is.EqualTo(ErrorCodes.InvalidParams));
}

[Test]
public async Task NewPayloadV3_invalidblockhash()
{
(JsonRpcService jsonRpcService, JsonRpcContext context, EthereumJsonSerializer _, ExecutionPayloadV3 _)
= await PreparePayloadRequestEnv();

string requestStr = """
{"parentHash":"0xd6194b42ad579c195e9aaaf04692619f4de9c5fbdd6b58baaabe93384e834d25","feeRecipient":"0x0000000000000000000000000000000000000000","stateRoot":"0xfe1fa6bb862e4a5efd9ee8967b356d4f7b6205a437eeac8b0e625db3cb662018","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","prevRandao":"0xfaebfae9aef88ac8eba03decf329c8155991e07cb1a9dc6ac69e420550a45037","blockNumber":"0x1","gasLimit":"0x2fefd8","gasUsed":"0x0","timestamp":"0x1235","extraData":"0x4e65746865726d696e64","baseFeePerGas":"0x342770c0","blockHash":"0x0718890af079939b4aae6ac0ecaa94c633ad73e69e787f526f0d558043e8e2f1","transactions":[],"withdrawals":[{"index":"0x1","validatorIndex":"0x0","address":"0x0000000000000000000000000000000000000000","amount":"0x64"},{"index":"0x2","validatorIndex":"0x1","address":"0x0100000000000000000000000000000000000000","amount":"0x64"},{"index":"0x3","validatorIndex":"0x2","address":"0x0200000000000000000000000000000000000000","amount":"0x64"},{"index":"0x4","validatorIndex":"0x3","address":"0x0300000000000000000000000000000000000000","amount":"0x64"},{"index":"0x5","validatorIndex":"0x4","address":"0x0400000000000000000000000000000000000000","amount":"0x64"},{"index":"0x6","validatorIndex":"0x5","address":"0x0500000000000000000000000000000000000000","amount":"0x64"},{"index":"0x7","validatorIndex":"0x6","address":"0x0600000000000000000000000000000000000000","amount":"0x64"},{"index":"0x8","validatorIndex":"0x7","address":"0x0700000000000000000000000000000000000000","amount":"0x64"},{"index":"0x9","validatorIndex":"0x8","address":"0x0800000000000000000000000000000000000000","amount":"0x64"},{"index":"0xa","validatorIndex":"0x9","address":"0x0900000000000000000000000000000000000000","amount":"0x64"}],"excessBlobGas":"0x0"}
""";
JsonRpcRequest request = RpcTest.GetJsonRequest(nameof(IEngineRpcModule.engine_newPayloadV3),
requestStr, "[]", "0x169630f535b4a41330164c6e5c92b1224c0c407f582d407d0ac3d206cd32fd52");

var rpcResponse = await jsonRpcService.SendRequestAsync(request, context);
JsonRpcErrorResponse? response = (rpcResponse) as JsonRpcErrorResponse;
Assert.That(response?.Error, Is.Not.Null);
Assert.That(response!.Error!.Code, Is.EqualTo(ErrorCodes.InvalidParams));
}

private async Task<(JsonRpcService jsonRpcService, JsonRpcContext context, EthereumJsonSerializer serializer, ExecutionPayloadV3 correctExecutionPayload)>
PreparePayloadRequestEnv()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Core.Specs;
using Nethermind.Int256;
using Nethermind.Merge.Plugin.Handlers;
using Nethermind.Serialization.Json;
using Nethermind.Serialization.Rlp;
using Nethermind.State.Proofs;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Nethermind.Merge.Plugin.Data;
Expand Down Expand Up @@ -100,14 +97,14 @@ public byte[][] Transactions
/// <see href="https://eips.ethereum.org/EIPS/eip-4844">EIP-4844</see>.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public ulong? BlobGasUsed { get; set; }
public virtual ulong? BlobGasUsed { get; set; }

/// <summary>
/// Gets or sets <see cref="Block.ExcessBlobGas"/> as defined in
/// <see href="https://eips.ethereum.org/EIPS/eip-4844">EIP-4844</see>.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public ulong? ExcessBlobGas { get; set; }
public virtual ulong? ExcessBlobGas { get; set; }

/// <summary>
/// Gets or sets <see cref="Block.ParentBeaconBlockRoot"/> as defined in
Expand Down
15 changes: 15 additions & 0 deletions src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayloadV3.cs
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.Text.Json.Serialization;
using Nethermind.Core;
using Nethermind.Core.Specs;
using Nethermind.Int256;
Expand Down Expand Up @@ -36,4 +37,18 @@ public override bool TryGetBlock(out Block? block, UInt256? totalDifficulty = nu

public override bool ValidateFork(ISpecProvider specProvider) =>
specProvider.GetSpec(BlockNumber, Timestamp).IsEip4844Enabled;

/// <summary>
/// Gets or sets <see cref="Block.BlobGasUsed"/> as defined in
/// <see href="https://eips.ethereum.org/EIPS/eip-4844">EIP-4844</see>.
/// </summary>
[JsonRequired]
public override ulong? BlobGasUsed { get; set; }

/// <summary>
/// Gets or sets <see cref="Block.ExcessBlobGas"/> as defined in
/// <see href="https://eips.ethereum.org/EIPS/eip-4844">EIP-4844</see>.
/// </summary>
[JsonRequired]
public override ulong? ExcessBlobGas { get; set; }
}