Skip to content

Commit 3142e87

Browse files
committed
- Merged master again
2 parents 706c8dc + bb5c5d5 commit 3142e87

File tree

4 files changed

+85
-5
lines changed

4 files changed

+85
-5
lines changed

src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs

+3
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ private static ExecutionPayloadV3 CreateBlockRequestV3(IReleaseSpec spec, IWorld
120120
LogsBloom = Bloom.Empty,
121121
Timestamp = parent.Timestamp + 1,
122122
Withdrawals = withdrawals,
123+
BlobGasUsed = blobGasUsed,
124+
ExcessBlobGas = excessBlobGas,
125+
ParentBeaconBlockRoot = parentBeaconBlockRoot,
123126
};
124127

125128
if (blockRequest is ExecutionPayloadV3 blockRequestV3)

src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs

+56
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ public async Task NewPayloadV2_should_decline_post_cancun()
6464
Assert.That(result.ErrorCode, Is.EqualTo(ErrorCodes.UnsupportedFork));
6565
}
6666

67+
[TestCaseSource(nameof(CancunFieldsTestSource))]
68+
public async Task<int> NewPayloadV2_should_decline_pre_cancun_with_cancun_fields(ulong? blobGasUsed, ulong? excessBlobGas, Keccak? parentBlockBeaconRoot)
69+
{
70+
MergeTestBlockchain chain = await CreateBlockchain(releaseSpec: Shanghai.Instance);
71+
IEngineRpcModule rpcModule = CreateEngineModule(chain);
72+
ExecutionPayload executionPayload = CreateBlockRequest(
73+
CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD, withdrawals: Array.Empty<Withdrawal>(),
74+
blobGasUsed: blobGasUsed, excessBlobGas: excessBlobGas, parentBeaconBlockRoot: parentBlockBeaconRoot);
75+
76+
ResultWrapper<PayloadStatusV1> result = await rpcModule.engine_newPayloadV2(executionPayload);
77+
78+
return result.ErrorCode;
79+
}
80+
6781
[Test]
6882
public async Task NewPayloadV3_should_decline_pre_cancun_payloads()
6983
{
@@ -408,6 +422,48 @@ public static IEnumerable<TestCaseData> BlobVersionedHashesDoNotMatchTestSource
408422
}
409423
}
410424

425+
public static IEnumerable<TestCaseData> CancunFieldsTestSource
426+
{
427+
get
428+
{
429+
yield return new TestCaseData(null, null, null)
430+
{
431+
ExpectedResult = ErrorCodes.None,
432+
TestName = "No Cancun fields",
433+
};
434+
yield return new TestCaseData(0ul, null, null)
435+
{
436+
ExpectedResult = ErrorCodes.InvalidParams,
437+
TestName = $"{nameof(ExecutionPayloadV3.BlobGasUsed)} is set",
438+
};
439+
yield return new TestCaseData(null, 0ul, null)
440+
{
441+
ExpectedResult = ErrorCodes.InvalidParams,
442+
TestName = $"{nameof(ExecutionPayloadV3.ExcessBlobGas)} is set",
443+
};
444+
yield return new TestCaseData(null, null, Keccak.Zero)
445+
{
446+
ExpectedResult = ErrorCodes.InvalidParams,
447+
TestName = $"{nameof(ExecutionPayloadV3.ParentBeaconBlockRoot)} is set",
448+
};
449+
yield return new TestCaseData(1ul, 1ul, null)
450+
{
451+
ExpectedResult = ErrorCodes.InvalidParams,
452+
TestName = $"Multiple fields #1",
453+
};
454+
yield return new TestCaseData(1ul, 1ul, Keccak.Zero)
455+
{
456+
ExpectedResult = ErrorCodes.InvalidParams,
457+
TestName = $"Multiple fields #2",
458+
};
459+
yield return new TestCaseData(1ul, null, Keccak.Zero)
460+
{
461+
ExpectedResult = ErrorCodes.InvalidParams,
462+
TestName = $"Multiple fields #3",
463+
};
464+
}
465+
}
466+
411467
private async Task<ExecutionPayload> SendNewBlockV3(IEngineRpcModule rpc, MergeTestBlockchain chain, IList<Withdrawal>? withdrawals)
412468
{
413469
ExecutionPayloadV3 executionPayload = CreateBlockRequestV3(

src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayload.cs

+26-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using System.Diagnostics.CodeAnalysis;
76
using System.Linq;
87
using Nethermind.Core;
98
using Nethermind.Core.Crypto;
@@ -12,6 +11,7 @@
1211
using Nethermind.Merge.Plugin.Handlers;
1312
using Nethermind.Serialization.Rlp;
1413
using Nethermind.State.Proofs;
14+
using Newtonsoft.Json;
1515

1616
namespace Nethermind.Merge.Plugin.Data;
1717

@@ -92,6 +92,25 @@ public byte[][] Transactions
9292
public IEnumerable<Withdrawal>? Withdrawals { get; set; }
9393

9494

95+
/// <summary>
96+
/// Gets or sets <see cref="Block.BlobGasUsed"/> as defined in
97+
/// <see href="https://eips.ethereum.org/EIPS/eip-4844">EIP-4844</see>.
98+
/// </summary>
99+
public ulong? BlobGasUsed { get; set; }
100+
101+
/// <summary>
102+
/// Gets or sets <see cref="Block.ExcessBlobGas"/> as defined in
103+
/// <see href="https://eips.ethereum.org/EIPS/eip-4844">EIP-4844</see>.
104+
/// </summary>
105+
public ulong? ExcessBlobGas { get; set; }
106+
107+
/// <summary>
108+
/// Gets or sets <see cref="Block.ParentBeaconBlockRoot"/> as defined in
109+
/// <see href="https://eips.ethereum.org/EIPS/eip-4788">EIP-4788</see>.
110+
/// </summary>
111+
[JsonIgnore]
112+
public Keccak? ParentBeaconBlockRoot { get; set; }
113+
95114
/// <summary>
96115
/// Creates the execution block from payload.
97116
/// </summary>
@@ -169,15 +188,18 @@ public void SetTransactions(params Transaction[] transactions)
169188

170189
public virtual ValidationResult ValidateParams(IReleaseSpec spec, int version, out string? error)
171190
{
172-
int GetVersion() => Withdrawals is null ? 1 : 2;
173-
174191
if (spec.IsEip4844Enabled)
175192
{
176193
error = "ExecutionPayloadV3 expected";
177194
return ValidationResult.Fail;
178195
}
179196

180-
int actualVersion = GetVersion();
197+
int actualVersion = this switch
198+
{
199+
{ BlobGasUsed: not null } or { ExcessBlobGas: not null } or { ParentBeaconBlockRoot: not null } => 3,
200+
{ Withdrawals: not null } => 2,
201+
_ => 1
202+
};
181203

182204
error = actualVersion switch
183205
{

src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayloadV3.cs

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

4-
using System.Diagnostics.CodeAnalysis;
54
using Nethermind.Core;
65
using Nethermind.Core.Crypto;
76
using Nethermind.Core.Specs;

0 commit comments

Comments
 (0)