Skip to content

Commit

Permalink
- Merged master again
Browse files Browse the repository at this point in the history
  • Loading branch information
Demuirgos committed Aug 17, 2023
2 parents 706c8dc + bb5c5d5 commit 3142e87
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ private static ExecutionPayloadV3 CreateBlockRequestV3(IReleaseSpec spec, IWorld
LogsBloom = Bloom.Empty,
Timestamp = parent.Timestamp + 1,
Withdrawals = withdrawals,
BlobGasUsed = blobGasUsed,
ExcessBlobGas = excessBlobGas,
ParentBeaconBlockRoot = parentBeaconBlockRoot,
};

if (blockRequest is ExecutionPayloadV3 blockRequestV3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ public async Task NewPayloadV2_should_decline_post_cancun()
Assert.That(result.ErrorCode, Is.EqualTo(ErrorCodes.UnsupportedFork));
}

[TestCaseSource(nameof(CancunFieldsTestSource))]
public async Task<int> NewPayloadV2_should_decline_pre_cancun_with_cancun_fields(ulong? blobGasUsed, ulong? excessBlobGas, Keccak? parentBlockBeaconRoot)
{
MergeTestBlockchain chain = await CreateBlockchain(releaseSpec: Shanghai.Instance);
IEngineRpcModule rpcModule = CreateEngineModule(chain);
ExecutionPayload executionPayload = CreateBlockRequest(
CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD, withdrawals: Array.Empty<Withdrawal>(),
blobGasUsed: blobGasUsed, excessBlobGas: excessBlobGas, parentBeaconBlockRoot: parentBlockBeaconRoot);

ResultWrapper<PayloadStatusV1> result = await rpcModule.engine_newPayloadV2(executionPayload);

return result.ErrorCode;
}

[Test]
public async Task NewPayloadV3_should_decline_pre_cancun_payloads()
{
Expand Down Expand Up @@ -408,6 +422,48 @@ public static IEnumerable<TestCaseData> BlobVersionedHashesDoNotMatchTestSource
}
}

public static IEnumerable<TestCaseData> CancunFieldsTestSource
{
get
{
yield return new TestCaseData(null, null, null)
{
ExpectedResult = ErrorCodes.None,
TestName = "No Cancun fields",
};
yield return new TestCaseData(0ul, null, null)
{
ExpectedResult = ErrorCodes.InvalidParams,
TestName = $"{nameof(ExecutionPayloadV3.BlobGasUsed)} is set",
};
yield return new TestCaseData(null, 0ul, null)
{
ExpectedResult = ErrorCodes.InvalidParams,
TestName = $"{nameof(ExecutionPayloadV3.ExcessBlobGas)} is set",
};
yield return new TestCaseData(null, null, Keccak.Zero)
{
ExpectedResult = ErrorCodes.InvalidParams,
TestName = $"{nameof(ExecutionPayloadV3.ParentBeaconBlockRoot)} is set",
};
yield return new TestCaseData(1ul, 1ul, null)
{
ExpectedResult = ErrorCodes.InvalidParams,
TestName = $"Multiple fields #1",
};
yield return new TestCaseData(1ul, 1ul, Keccak.Zero)
{
ExpectedResult = ErrorCodes.InvalidParams,
TestName = $"Multiple fields #2",
};
yield return new TestCaseData(1ul, null, Keccak.Zero)
{
ExpectedResult = ErrorCodes.InvalidParams,
TestName = $"Multiple fields #3",
};
}
}

private async Task<ExecutionPayload> SendNewBlockV3(IEngineRpcModule rpc, MergeTestBlockchain chain, IList<Withdrawal>? withdrawals)
{
ExecutionPayloadV3 executionPayload = CreateBlockRequestV3(
Expand Down
30 changes: 26 additions & 4 deletions src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Nethermind.Core;
using Nethermind.Core.Crypto;
Expand All @@ -12,6 +11,7 @@
using Nethermind.Merge.Plugin.Handlers;
using Nethermind.Serialization.Rlp;
using Nethermind.State.Proofs;
using Newtonsoft.Json;

namespace Nethermind.Merge.Plugin.Data;

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


/// <summary>
/// Gets or sets <see cref="Block.BlobGasUsed"/> as defined in
/// <see href="https://eips.ethereum.org/EIPS/eip-4844">EIP-4844</see>.
/// </summary>
public 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>
public ulong? ExcessBlobGas { get; set; }

/// <summary>
/// Gets or sets <see cref="Block.ParentBeaconBlockRoot"/> as defined in
/// <see href="https://eips.ethereum.org/EIPS/eip-4788">EIP-4788</see>.
/// </summary>
[JsonIgnore]
public Keccak? ParentBeaconBlockRoot { get; set; }

/// <summary>
/// Creates the execution block from payload.
/// </summary>
Expand Down Expand Up @@ -169,15 +188,18 @@ public void SetTransactions(params Transaction[] transactions)

public virtual ValidationResult ValidateParams(IReleaseSpec spec, int version, out string? error)
{
int GetVersion() => Withdrawals is null ? 1 : 2;

if (spec.IsEip4844Enabled)
{
error = "ExecutionPayloadV3 expected";
return ValidationResult.Fail;
}

int actualVersion = GetVersion();
int actualVersion = this switch
{
{ BlobGasUsed: not null } or { ExcessBlobGas: not null } or { ParentBeaconBlockRoot: not null } => 3,
{ Withdrawals: not null } => 2,
_ => 1
};

error = actualVersion switch
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System.Diagnostics.CodeAnalysis;
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Core.Specs;
Expand Down

0 comments on commit 3142e87

Please sign in to comment.