From da380db47bcbe9e54e49469bb730c4e4ee5acab8 Mon Sep 17 00:00:00 2001 From: Rohit Ranjan Date: Tue, 15 Oct 2024 16:50:32 +0530 Subject: [PATCH 1/3] optimise alocations --- .../ExecutionRequestProcessorTests.cs | 10 ++- .../ExecutionRequestProcessor.cs | 32 +++---- .../Nethermind.Core.Test/Builders/TestItem.cs | 18 ++-- .../ExecutionRequest/ExecutionRequest.cs | 84 ++++++++++++------- .../Data/GetPayloadV4Result.cs | 2 +- 5 files changed, 85 insertions(+), 61 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus.Test/ExecutionRequestProcessorTests.cs b/src/Nethermind/Nethermind.Consensus.Test/ExecutionRequestProcessorTests.cs index e7731326ea9..4e4bd95e4e9 100644 --- a/src/Nethermind/Nethermind.Consensus.Test/ExecutionRequestProcessorTests.cs +++ b/src/Nethermind/Nethermind.Consensus.Test/ExecutionRequestProcessorTests.cs @@ -76,11 +76,15 @@ public void Setup() CallOutputTracer tracer = ci.Arg(); if (transaction.To == eip7002Account) { - tracer.ReturnValue = executionWithdrawalRequests.FlatEncodeWithoutType(); + Span buffer = new byte[executionWithdrawalRequests.GetRequestsByteSize()]; + executionWithdrawalRequests.FlatEncodeWithoutType(buffer); + tracer.ReturnValue = buffer.ToArray(); } else if (transaction.To == eip7251Account) { - tracer.ReturnValue = executionConsolidationRequests.FlatEncodeWithoutType(); + Span buffer = new byte[executionConsolidationRequests.GetRequestsByteSize()]; + executionConsolidationRequests.FlatEncodeWithoutType(buffer); + tracer.ReturnValue = buffer.ToArray(); } else { @@ -120,7 +124,7 @@ .. executionConsolidationRequests ])) { Assert.That(processedRequest.RequestType, Is.EqualTo(expectedRequest.RequestType)); - Assert.That(processedRequest.RequestData, Is.EqualTo(expectedRequest.RequestData)); + Assert.That(processedRequest.RequestData.ToArray(), Is.EqualTo(expectedRequest.RequestData.ToArray())); } Assert.That(block.Header.RequestsHash, Is.EqualTo(block.ExecutionRequests.ToArray().CalculateHash())); diff --git a/src/Nethermind/Nethermind.Consensus/ExecutionRequests/ExecutionRequestProcessor.cs b/src/Nethermind/Nethermind.Consensus/ExecutionRequests/ExecutionRequestProcessor.cs index f02f6f70ed0..3f81950cf77 100644 --- a/src/Nethermind/Nethermind.Consensus/ExecutionRequests/ExecutionRequestProcessor.cs +++ b/src/Nethermind/Nethermind.Consensus/ExecutionRequests/ExecutionRequestProcessor.cs @@ -137,29 +137,23 @@ public Hash256 CalculateRequestsHash(Block block, IWorldState state, TxReceipt[] { using (SHA256 sha256Inner = SHA256.Create()) { - foreach (ExecutionRequest request in ProcessDeposits(receipts, spec)) + void ProcessAndHashRequests(IEnumerable executionRequests) { - requestsList.AddRange(request); - byte[] requestHash = sha256Inner.ComputeHash(request.FlatEncode()); - - // Update the outer hash with the result of each inner hash - sha256.TransformBlock(requestHash, 0, requestHash.Length, null, 0); - } - foreach (ExecutionRequest request in ReadRequests(block, state, spec, spec.Eip7002ContractAddress)) - { - requestsList.AddRange(request); - byte[] requestHash = sha256Inner.ComputeHash(request.FlatEncode()); + foreach (ExecutionRequest request in executionRequests) + { + requestsList.AddRange(request); + var internalBuffer = new byte[request.RequestData.Length + 1]; + request.FlatEncode(internalBuffer); + byte[] requestHash = sha256Inner.ComputeHash(internalBuffer); - sha256.TransformBlock(requestHash, 0, requestHash.Length, null, 0); + // Update the outer hash with the result of each inner hash + sha256.TransformBlock(requestHash, 0, requestHash.Length, null, 0); + } } - foreach (ExecutionRequest request in ReadRequests(block, state, spec, spec.Eip7251ContractAddress)) - { - requestsList.AddRange(request); - byte[] requestHash = sha256Inner.ComputeHash(request.FlatEncode()); - - sha256.TransformBlock(requestHash, 0, requestHash.Length, null, 0); - } + ProcessAndHashRequests(ProcessDeposits(receipts, spec)); + ProcessAndHashRequests(ReadRequests(block, state, spec, spec.Eip7002ContractAddress)); + ProcessAndHashRequests(ReadRequests(block, state, spec, spec.Eip7251ContractAddress)); // Complete the final hash computation sha256.TransformFinalBlock(new byte[0], 0, 0); diff --git a/src/Nethermind/Nethermind.Core.Test/Builders/TestItem.cs b/src/Nethermind/Nethermind.Core.Test/Builders/TestItem.cs index e7345b1bcf3..9865dcb0089 100644 --- a/src/Nethermind/Nethermind.Core.Test/Builders/TestItem.cs +++ b/src/Nethermind/Nethermind.Core.Test/Builders/TestItem.cs @@ -102,15 +102,15 @@ public static Hash256 KeccakFromNumber(int i) public static byte[] SignatureBytes = [.. new Signature("0x9242685bf161793cc25603c231bc2f568eb630ea16aa137d2664ac80388256084f8ae3bd7535248d0bd448298cc2e2071e56992d0774dc340c368ae950852ada1c").Bytes, .. KeccakA.Bytes]; - public static ExecutionRequest.ExecutionRequest ExecutionRequestA = new() { RequestType = 0, RequestData = ([.. PublicKeyA.Bytes.Slice(0, 48), .. KeccakA.Bytes, .. (BitConverter.GetBytes((ulong)1_000_000_000)), .. SignatureBytes, .. BitConverter.GetBytes((ulong)1)]) }; - public static ExecutionRequest.ExecutionRequest ExecutionRequestB = new() { RequestType = 0, RequestData = ([.. PublicKeyB.Bytes.Slice(0, 48), .. KeccakB.Bytes, .. (BitConverter.GetBytes((ulong)2_000_000_000)), .. SignatureBytes, .. BitConverter.GetBytes((ulong)2)]) }; - public static ExecutionRequest.ExecutionRequest ExecutionRequestC = new() { RequestType = 0, RequestData = ([.. PublicKeyC.Bytes.Slice(0, 48), .. KeccakC.Bytes, .. (BitConverter.GetBytes((ulong)3_000_000_000)), .. SignatureBytes, .. BitConverter.GetBytes((ulong)3)]) }; - public static ExecutionRequest.ExecutionRequest ExecutionRequestD = new() { RequestType = 1, RequestData = ([.. AddressA.Bytes, .. PublicKeyA.Bytes.Slice(0, 48), .. (BitConverter.GetBytes((ulong)1_000_000_000))]) }; - public static ExecutionRequest.ExecutionRequest ExecutionRequestE = new() { RequestType = 1, RequestData = ([.. AddressB.Bytes, .. PublicKeyB.Bytes.Slice(0, 48), .. (BitConverter.GetBytes((ulong)2_000_000_000))]) }; - public static ExecutionRequest.ExecutionRequest ExecutionRequestF = new() { RequestType = 1, RequestData = ([.. AddressC.Bytes, .. PublicKeyC.Bytes.Slice(0, 48), .. (BitConverter.GetBytes((ulong)3_000_000_000))]) }; - public static ExecutionRequest.ExecutionRequest ExecutionRequestG = new() { RequestType = 2, RequestData = ([.. AddressA.Bytes, .. PublicKeyA.Bytes.Slice(0, 48), .. PublicKeyB.Bytes.Slice(0, 48)]) }; - public static ExecutionRequest.ExecutionRequest ExecutionRequestH = new() { RequestType = 2, RequestData = ([.. AddressB.Bytes, .. PublicKeyB.Bytes.Slice(0, 48), .. PublicKeyC.Bytes.Slice(0, 48)]) }; - public static ExecutionRequest.ExecutionRequest ExecutionRequestI = new() { RequestType = 2, RequestData = ([.. AddressC.Bytes, .. PublicKeyC.Bytes.Slice(0, 48), .. PublicKeyA.Bytes.Slice(0, 48)]) }; + public static ExecutionRequest.ExecutionRequest ExecutionRequestA = new() { RequestType = 0, RequestData = (byte[])([.. PublicKeyA.Bytes.Slice(0, 48), .. KeccakA.Bytes, .. (BitConverter.GetBytes((ulong)1_000_000_000)), .. SignatureBytes, .. BitConverter.GetBytes((ulong)1)]) }; + public static ExecutionRequest.ExecutionRequest ExecutionRequestB = new() { RequestType = 0, RequestData = (byte[])([.. PublicKeyB.Bytes.Slice(0, 48), .. KeccakB.Bytes, .. (BitConverter.GetBytes((ulong)2_000_000_000)), .. SignatureBytes, .. BitConverter.GetBytes((ulong)2)]) }; + public static ExecutionRequest.ExecutionRequest ExecutionRequestC = new() { RequestType = 0, RequestData = (byte[])([.. PublicKeyC.Bytes.Slice(0, 48), .. KeccakC.Bytes, .. (BitConverter.GetBytes((ulong)3_000_000_000)), .. SignatureBytes, .. BitConverter.GetBytes((ulong)3)]) }; + public static ExecutionRequest.ExecutionRequest ExecutionRequestD = new() { RequestType = 1, RequestData = (byte[])([.. AddressA.Bytes, .. PublicKeyA.Bytes.Slice(0, 48), .. (BitConverter.GetBytes((ulong)1_000_000_000))]) }; + public static ExecutionRequest.ExecutionRequest ExecutionRequestE = new() { RequestType = 1, RequestData = (byte[])([.. AddressB.Bytes, .. PublicKeyB.Bytes.Slice(0, 48), .. (BitConverter.GetBytes((ulong)2_000_000_000))]) }; + public static ExecutionRequest.ExecutionRequest ExecutionRequestF = new() { RequestType = 1, RequestData = (byte[])([.. AddressC.Bytes, .. PublicKeyC.Bytes.Slice(0, 48), .. (BitConverter.GetBytes((ulong)3_000_000_000))]) }; + public static ExecutionRequest.ExecutionRequest ExecutionRequestG = new() { RequestType = 2, RequestData = (byte[])([.. AddressA.Bytes, .. PublicKeyA.Bytes.Slice(0, 48), .. PublicKeyB.Bytes.Slice(0, 48)]) }; + public static ExecutionRequest.ExecutionRequest ExecutionRequestH = new() { RequestType = 2, RequestData = (byte[])([.. AddressB.Bytes, .. PublicKeyB.Bytes.Slice(0, 48), .. PublicKeyC.Bytes.Slice(0, 48)]) }; + public static ExecutionRequest.ExecutionRequest ExecutionRequestI = new() { RequestType = 2, RequestData = (byte[])([.. AddressC.Bytes, .. PublicKeyC.Bytes.Slice(0, 48), .. PublicKeyA.Bytes.Slice(0, 48)]) }; public static IPEndPoint IPEndPointA = IPEndPoint.Parse("10.0.0.1"); public static IPEndPoint IPEndPointB = IPEndPoint.Parse("10.0.0.2"); diff --git a/src/Nethermind/Nethermind.Core/ExecutionRequest/ExecutionRequest.cs b/src/Nethermind/Nethermind.Core/ExecutionRequest/ExecutionRequest.cs index 29711de9dd4..eac860854ce 100644 --- a/src/Nethermind/Nethermind.Core/ExecutionRequest/ExecutionRequest.cs +++ b/src/Nethermind/Nethermind.Core/ExecutionRequest/ExecutionRequest.cs @@ -4,9 +4,7 @@ using System; using System.Collections.Generic; -using System.Data.SqlTypes; using System.Security.Cryptography; -using System.Linq; using Nethermind.Core.Crypto; using Nethermind.Core.Extensions; @@ -24,61 +22,89 @@ public class ExecutionRequest public byte RequestType { get; set; } public byte[]? RequestData { get; set; } - public byte[] FlatEncode() + public void FlatEncode(Span buffer) { - byte[] encoded = new byte[RequestData!.Length + 1]; - encoded[0] = RequestType; - RequestData.CopyTo(encoded, 1); - return encoded; + if (buffer.Length < RequestData!.Length + 1) + throw new ArgumentException("Buffer too small"); + + buffer[0] = RequestType; + RequestData.CopyTo(buffer.Slice(1)); } public override string ToString() => ToString(string.Empty); public string ToString(string indentation) => @$"{indentation}{nameof(ExecutionRequest)} {{{nameof(RequestType)}: {RequestType}, - {nameof(RequestData)}: {RequestData?.ToHexString()}}}"; + {nameof(RequestData)}: {RequestData!.ToHexString()}}}"; } public static class ExecutionRequestExtensions { - public static byte[] FlatEncode(this ExecutionRequest[] requests) + public static int GetRequestsByteSize(this ExecutionRequest[] requests) { - List encoded = new(); + int size = 0; foreach (ExecutionRequest request in requests) { - encoded.AddRange(request.FlatEncode()); + size += request.RequestData!.Length + 1; } - return encoded.ToArray(); + return size; } - public static byte[] FlatEncodeWithoutType(this ExecutionRequest[] requests) + public static void FlatEncode(this ExecutionRequest[] requests, Span buffer) { - List encoded = new(); + int currentPosition = 0; + foreach (ExecutionRequest request in requests) { - encoded.AddRange(request.RequestData!); + Span internalBuffer = new byte[request.RequestData!.Length + 1]; + request.FlatEncode(internalBuffer); + + // Ensure the buffer has enough space to accommodate the new data + if (currentPosition + internalBuffer.Length > buffer.Length) + { + throw new InvalidOperationException("Buffer is not large enough to hold all data of requests"); + } + + // Copy the internalBuffer to the buffer at the current position + internalBuffer.CopyTo(buffer.Slice(currentPosition, internalBuffer.Length)); + currentPosition += internalBuffer.Length; } - return encoded.ToArray(); } - public static Hash256 CalculateHash(this ExecutionRequest[] requests) + public static void FlatEncodeWithoutType(this ExecutionRequest[] requests, Span buffer) { - using (SHA256 sha256 = SHA256.Create()) + int currentPosition = 0; + + foreach (ExecutionRequest request in requests) { - using (SHA256 sha256Inner = SHA256.Create()) + // Ensure the buffer has enough space to accommodate the new data + if (currentPosition + request.RequestData!.Length > buffer.Length) { - foreach (ExecutionRequest request in requests) - { - byte[] requestHash = sha256Inner.ComputeHash(request.FlatEncode()); - - // Update the outer hash with the result of each inner hash - sha256.TransformBlock(requestHash, 0, requestHash.Length, null, 0); - } - // Complete the final hash computation - sha256.TransformFinalBlock(new byte[0], 0, 0); - return new Hash256(sha256.Hash!); + throw new InvalidOperationException("Buffer is not large enough to hold all data of requests"); } + + // Copy the RequestData to the buffer at the current position + request.RequestData.CopyTo(buffer.Slice(currentPosition, request.RequestData.Length)); + currentPosition += request.RequestData.Length; + } + } + + public static Hash256 CalculateHash(this IEnumerable requests) + { + using var sha256 = SHA256.Create(); + using var sha256Inner = SHA256.Create(); + foreach (ExecutionRequest request in requests) + { + var internalBuffer = new byte[request.RequestData!.Length + 1]; + request.FlatEncode(internalBuffer); + byte[] requestHash = sha256Inner.ComputeHash(internalBuffer); + + // Update the outer hash with the result of each inner hash + sha256.TransformBlock(requestHash, 0, requestHash.Length, null, 0); } + // Complete the final hash computation + sha256.TransformFinalBlock(Array.Empty(), 0, 0); + return new Hash256(sha256.Hash!); } public static bool IsSortedByType(this ExecutionRequest[] requests) diff --git a/src/Nethermind/Nethermind.Merge.Plugin/Data/GetPayloadV4Result.cs b/src/Nethermind/Nethermind.Merge.Plugin/Data/GetPayloadV4Result.cs index 5db3bf94e95..c3b7bef351a 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/Data/GetPayloadV4Result.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/Data/GetPayloadV4Result.cs @@ -12,5 +12,5 @@ public class GetPayloadV4Result(Block block, UInt256 blockFees, BlobsBundleV1 bl public ExecutionRequest[]? ExecutionRequests { get; } = ExecutionRequests; public override string ToString() => - $"{{ExecutionPayload: {ExecutionPayload}, Fees: {BlockValue}, BlobsBundle blobs count: {BlobsBundle.Blobs.Length}, ShouldOverrideBuilder {ShouldOverrideBuilder}, ExecutionRequests : {ExecutionRequests?.FlatEncode()}}}"; + $"{{ExecutionPayload: {ExecutionPayload}, Fees: {BlockValue}, BlobsBundle blobs count: {BlobsBundle.Blobs.Length}, ShouldOverrideBuilder {ShouldOverrideBuilder}, ExecutionRequests count : {ExecutionRequests?.Length}}}"; } From 226d904a95190ab3c1aa5506819860a89b5bf37d Mon Sep 17 00:00:00 2001 From: Rohit Ranjan Date: Wed, 16 Oct 2024 21:27:24 +0530 Subject: [PATCH 2/3] optimize further --- .../ExecutionRequestProcessor.cs | 42 +++---------------- .../Builders/BlockBuilder.cs | 2 +- src/Nethermind/Nethermind.Core/Block.cs | 2 +- .../ExecutionRequest/ExecutionRequest.cs | 27 ++++++------ .../ExecutionRequestsProcessorMock.cs | 6 +-- .../Handlers/GetPayloadV4Handler.cs | 2 +- 6 files changed, 24 insertions(+), 57 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/ExecutionRequests/ExecutionRequestProcessor.cs b/src/Nethermind/Nethermind.Consensus/ExecutionRequests/ExecutionRequestProcessor.cs index 3f81950cf77..0d46820272e 100644 --- a/src/Nethermind/Nethermind.Consensus/ExecutionRequests/ExecutionRequestProcessor.cs +++ b/src/Nethermind/Nethermind.Consensus/ExecutionRequests/ExecutionRequestProcessor.cs @@ -4,11 +4,9 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Security.Cryptography; using Nethermind.Abi; using Nethermind.Core; using Nethermind.Core.Collections; -using Nethermind.Core.Crypto; using Nethermind.Core.ExecutionRequest; using Nethermind.Core.Extensions; using Nethermind.Core.Specs; @@ -130,44 +128,14 @@ private IEnumerable ReadRequests(Block block, IWorldState stat } - public Hash256 CalculateRequestsHash(Block block, IWorldState state, TxReceipt[] receipts, IReleaseSpec spec, out ArrayPoolList requests) - { - ArrayPoolList requestsList = new ArrayPoolList(receipts.Length * 2); - using (SHA256 sha256 = SHA256.Create()) - { - using (SHA256 sha256Inner = SHA256.Create()) - { - void ProcessAndHashRequests(IEnumerable executionRequests) - { - foreach (ExecutionRequest request in executionRequests) - { - requestsList.AddRange(request); - var internalBuffer = new byte[request.RequestData.Length + 1]; - request.FlatEncode(internalBuffer); - byte[] requestHash = sha256Inner.ComputeHash(internalBuffer); - - // Update the outer hash with the result of each inner hash - sha256.TransformBlock(requestHash, 0, requestHash.Length, null, 0); - } - } - - ProcessAndHashRequests(ProcessDeposits(receipts, spec)); - ProcessAndHashRequests(ReadRequests(block, state, spec, spec.Eip7002ContractAddress)); - ProcessAndHashRequests(ReadRequests(block, state, spec, spec.Eip7251ContractAddress)); - - // Complete the final hash computation - sha256.TransformFinalBlock(new byte[0], 0, 0); - requests = requestsList; - return new Hash256(sha256.Hash!); - } - } - } - public void ProcessExecutionRequests(Block block, IWorldState state, TxReceipt[] receipts, IReleaseSpec spec) { if (!spec.RequestsEnabled) return; - block.Header.RequestsHash = CalculateRequestsHash(block, state, receipts, spec, out ArrayPoolList requests); - block.ExecutionRequests = requests; + IEnumerable requests = ProcessDeposits(receipts, spec) + .Concat(ReadRequests(block, state, spec, spec.Eip7002ContractAddress)) + .Concat(ReadRequests(block, state, spec, spec.Eip7251ContractAddress)); + block.Header.RequestsHash = requests.CalculateHash(); + block.ExecutionRequests = requests.ToArray(); } } diff --git a/src/Nethermind/Nethermind.Core.Test/Builders/BlockBuilder.cs b/src/Nethermind/Nethermind.Core.Test/Builders/BlockBuilder.cs index ee80f1bb81a..e66e47f283c 100644 --- a/src/Nethermind/Nethermind.Core.Test/Builders/BlockBuilder.cs +++ b/src/Nethermind/Nethermind.Core.Test/Builders/BlockBuilder.cs @@ -252,7 +252,7 @@ public BlockBuilder WithReceiptsRoot(Hash256 keccak) public BlockBuilder WithEmptyRequestsHash() { TestObjectInternal.Header.RequestsHash = Array.Empty().CalculateHash(); - TestObjectInternal.ExecutionRequests = new ArrayPoolList(0); + TestObjectInternal.ExecutionRequests = Array.Empty(); return this; } diff --git a/src/Nethermind/Nethermind.Core/Block.cs b/src/Nethermind/Nethermind.Core/Block.cs index 935a1b0b900..57ebf3b5726 100644 --- a/src/Nethermind/Nethermind.Core/Block.cs +++ b/src/Nethermind/Nethermind.Core/Block.cs @@ -118,7 +118,7 @@ public Transaction[] Transactions public Hash256? RequestsHash => Header.RequestsHash; // do not add setter here [JsonIgnore] - public ArrayPoolList? ExecutionRequests { get; set; } + public ExecutionRequest.ExecutionRequest[]? ExecutionRequests { get; set; } [JsonIgnore] public ArrayPoolList? AccountChanges { get; set; } diff --git a/src/Nethermind/Nethermind.Core/ExecutionRequest/ExecutionRequest.cs b/src/Nethermind/Nethermind.Core/ExecutionRequest/ExecutionRequest.cs index eac860854ce..07ed2b96b9a 100644 --- a/src/Nethermind/Nethermind.Core/ExecutionRequest/ExecutionRequest.cs +++ b/src/Nethermind/Nethermind.Core/ExecutionRequest/ExecutionRequest.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Security.Cryptography; using Nethermind.Core.Crypto; using Nethermind.Core.Extensions; @@ -40,7 +41,7 @@ public string ToString(string indentation) => @$"{indentation}{nameof(ExecutionR public static class ExecutionRequestExtensions { - public static int GetRequestsByteSize(this ExecutionRequest[] requests) + public static int GetRequestsByteSize(this IEnumerable requests) { int size = 0; foreach (ExecutionRequest request in requests) @@ -91,20 +92,22 @@ public static void FlatEncodeWithoutType(this ExecutionRequest[] requests, Span< public static Hash256 CalculateHash(this IEnumerable requests) { - using var sha256 = SHA256.Create(); - using var sha256Inner = SHA256.Create(); - foreach (ExecutionRequest request in requests) + using (SHA256 sha256 = SHA256.Create()) { - var internalBuffer = new byte[request.RequestData!.Length + 1]; - request.FlatEncode(internalBuffer); - byte[] requestHash = sha256Inner.ComputeHash(internalBuffer); + Span concatenatedHashes = new byte[32*requests.Count()]; + int currentPosition = 0; + // Compute sha256 for each request and concatenate them + foreach (ExecutionRequest request in requests) + { + Span requestBuffer = new byte[request.RequestData!.Length + 1]; + request.FlatEncode(requestBuffer); + sha256.ComputeHash(requestBuffer.ToArray()).CopyTo(concatenatedHashes.Slice(currentPosition, 32)); + currentPosition += 32; + } - // Update the outer hash with the result of each inner hash - sha256.TransformBlock(requestHash, 0, requestHash.Length, null, 0); + // Compute sha256 of the concatenated hashes + return new Hash256(sha256.ComputeHash(concatenatedHashes.ToArray())); } - // Complete the final hash computation - sha256.TransformFinalBlock(Array.Empty(), 0, 0); - return new Hash256(sha256.Hash!); } public static bool IsSortedByType(this ExecutionRequest[] requests) diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/ExecutionRequestsProcessorMock.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/ExecutionRequestsProcessorMock.cs index 4217bec0535..3f2f22bfcef 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/ExecutionRequestsProcessorMock.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/ExecutionRequestsProcessorMock.cs @@ -31,11 +31,7 @@ public void ProcessExecutionRequests(Block block, IWorldState state, TxReceipt[] if (block.IsGenesis) return; - block.ExecutionRequests = new ArrayPoolList(Requests.Length); - foreach (var request in Requests) - { - block.ExecutionRequests.Add(request); - } + block.ExecutionRequests = Requests; block.Header.RequestsHash = Requests.CalculateHash(); } } diff --git a/src/Nethermind/Nethermind.Merge.Plugin/Handlers/GetPayloadV4Handler.cs b/src/Nethermind/Nethermind.Merge.Plugin/Handlers/GetPayloadV4Handler.cs index 6a9b458fa31..d403c8c43bb 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/Handlers/GetPayloadV4Handler.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/Handlers/GetPayloadV4Handler.cs @@ -24,7 +24,7 @@ public class GetPayloadV4Handler( { protected override GetPayloadV4Result GetPayloadResultFromBlock(IBlockProductionContext context) { - return new(context.CurrentBestBlock!, context.BlockFees, new BlobsBundleV1(context.CurrentBestBlock!), context.CurrentBestBlock!.ExecutionRequests!.ToArray()) + return new(context.CurrentBestBlock!, context.BlockFees, new BlobsBundleV1(context.CurrentBestBlock!), context.CurrentBestBlock!.ExecutionRequests!) { ShouldOverrideBuilder = censorshipDetector?.GetCensoredBlocks().Contains(new BlockNumberHash(context.CurrentBestBlock!)) ?? false }; From ad3698b1b56eec2b023c8d1eebeadea497ff8717 Mon Sep 17 00:00:00 2001 From: Rohit Ranjan Date: Wed, 16 Oct 2024 21:41:06 +0530 Subject: [PATCH 3/3] format files --- .../Nethermind.Core/ExecutionRequest/ExecutionRequest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Core/ExecutionRequest/ExecutionRequest.cs b/src/Nethermind/Nethermind.Core/ExecutionRequest/ExecutionRequest.cs index 07ed2b96b9a..7e81a8abb35 100644 --- a/src/Nethermind/Nethermind.Core/ExecutionRequest/ExecutionRequest.cs +++ b/src/Nethermind/Nethermind.Core/ExecutionRequest/ExecutionRequest.cs @@ -94,7 +94,7 @@ public static Hash256 CalculateHash(this IEnumerable requests) { using (SHA256 sha256 = SHA256.Create()) { - Span concatenatedHashes = new byte[32*requests.Count()]; + Span concatenatedHashes = new byte[32 * requests.Count()]; int currentPosition = 0; // Compute sha256 for each request and concatenate them foreach (ExecutionRequest request in requests)