Skip to content

Commit

Permalink
optimise executionRequestProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
rjnrohit committed Oct 9, 2024
1 parent c9cd867 commit a87a144
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,6 @@ .. executionConsolidationRequests
Assert.That(processedRequest.RequestData, Is.EqualTo(expectedRequest.RequestData));
}

Assert.That(block.Header.RequestsHash, Is.EqualTo(block.ExecutionRequests.CalculateHash()));
Assert.That(block.Header.RequestsHash, Is.EqualTo(block.ExecutionRequests.ToArray().CalculateHash()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ private IEnumerable<ExecutionRequest> ReadRequests(Block block, IWorldState stat

}

public Hash256 CalculateRequestsHash(Block block, IWorldState state, TxReceipt[] receipts, IReleaseSpec spec, out ExecutionRequest[] requests)
public Hash256 CalculateRequestsHash(Block block, IWorldState state, TxReceipt[] receipts, IReleaseSpec spec, out ArrayPoolList<ExecutionRequest> requests)
{
List<ExecutionRequest> requestsList = new();
ArrayPoolList<ExecutionRequest> requestsList = new ArrayPoolList<ExecutionRequest>(0);
using (SHA256 sha256 = SHA256.Create())
{
using (SHA256 sha256Inner = SHA256.Create())
Expand Down Expand Up @@ -162,7 +162,7 @@ public Hash256 CalculateRequestsHash(Block block, IWorldState state, TxReceipt[]

// Complete the final hash computation
sha256.TransformFinalBlock(new byte[0], 0, 0);
requests = requestsList.ToArray();
requests = requestsList;
return new Hash256(sha256.Hash!);
}
}
Expand All @@ -172,7 +172,7 @@ public void ProcessExecutionRequests(Block block, IWorldState state, TxReceipt[]
{
if (!spec.RequestsEnabled)
return;
block.Header.RequestsHash = CalculateRequestsHash(block, state, receipts, spec, out ExecutionRequest[] requests);
block.Header.RequestsHash = CalculateRequestsHash(block, state, receipts, spec, out ArrayPoolList<ExecutionRequest> requests);
block.ExecutionRequests = requests;
}
}
3 changes: 2 additions & 1 deletion src/Nethermind/Nethermind.Core.Test/Builders/BlockBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Linq;
using Nethermind.Core.Collections;
using Nethermind.Core.Crypto;
using Nethermind.Core.ExecutionRequest;
using Nethermind.Core.Specs;
Expand Down Expand Up @@ -251,7 +252,7 @@ public BlockBuilder WithReceiptsRoot(Hash256 keccak)
public BlockBuilder WithEmptyRequestsHash()
{
TestObjectInternal.Header.RequestsHash = Array.Empty<ExecutionRequest.ExecutionRequest>().CalculateHash();
TestObjectInternal.ExecutionRequests = Array.Empty<ExecutionRequest.ExecutionRequest>();
TestObjectInternal.ExecutionRequests = new ArrayPoolList<ExecutionRequest.ExecutionRequest>(0);
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Core/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public Transaction[] Transactions
public Hash256? RequestsHash => Header.RequestsHash; // do not add setter here

[JsonIgnore]
public ExecutionRequest.ExecutionRequest[]? ExecutionRequests { get; set; }
public ArrayPoolList<ExecutionRequest.ExecutionRequest>? ExecutionRequests { get; set; }

[JsonIgnore]
public ArrayPoolList<AddressAsKey>? AccountChanges { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public async Task can_progress_chain_one_by_one_v4_with_requests(int count)
last!.IsGenesis.Should().BeTrue();

Block? head = chain.BlockTree.Head;
head!.ExecutionRequests!.Length.Should().Be(ExecutionRequestsProcessorMock.Requests.Length);
head!.ExecutionRequests!.ToArray().Length.Should().Be(ExecutionRequestsProcessorMock.Requests.Length);
}

private async Task<IReadOnlyList<ExecutionPayload>> ProduceBranchV4(IEngineRpcModule rpc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Nethermind.Consensus.ExecutionRequests;
using Nethermind.Core;
using Nethermind.Core.Collections;
using Nethermind.Core.ExecutionRequest;
using Nethermind.Core.Specs;
using Nethermind.Core.Test.Builders;
Expand Down Expand Up @@ -30,7 +31,11 @@ public void ProcessExecutionRequests(Block block, IWorldState state, TxReceipt[]
if (block.IsGenesis)
return;

block.ExecutionRequests = Requests;
block.ExecutionRequests = new ArrayPoolList<ExecutionRequest>(Requests.Length);
foreach (var request in Requests)
{
block.ExecutionRequests.Add(request);
}
block.Header.RequestsHash = Requests.CalculateHash();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class GetPayloadV4Handler(
{
protected override GetPayloadV4Result GetPayloadResultFromBlock(IBlockProductionContext context)
{
return new(context.CurrentBestBlock!, context.BlockFees, new BlobsBundleV1(context.CurrentBestBlock!), context.CurrentBestBlock!.ExecutionRequests!)
return new(context.CurrentBestBlock!, context.BlockFees, new BlobsBundleV1(context.CurrentBestBlock!), context.CurrentBestBlock!.ExecutionRequests!.ToArray())
{
ShouldOverrideBuilder = censorshipDetector?.GetCensoredBlocks().Contains(new BlockNumberHash(context.CurrentBestBlock!)) ?? false
};
Expand Down

0 comments on commit a87a144

Please sign in to comment.