diff --git a/src/Nethermind/Nethermind.Consensus.AuRa/Validators/PendingValidatorsDecoder.cs b/src/Nethermind/Nethermind.Consensus.AuRa/Validators/PendingValidatorsDecoder.cs index 22e1a168e92..7dc6dcc2894 100644 --- a/src/Nethermind/Nethermind.Consensus.AuRa/Validators/PendingValidatorsDecoder.cs +++ b/src/Nethermind/Nethermind.Consensus.AuRa/Validators/PendingValidatorsDecoder.cs @@ -2,7 +2,6 @@ // SPDX-License-Identifier: LGPL-3.0-only using System.Collections.Generic; -using System.Linq; using Nethermind.Core; using Nethermind.Serialization.Rlp; @@ -84,6 +83,11 @@ private static (int Total, int Addresses) GetContentLength(PendingValidators ite return (contentLength, addressesLength); } - private static int GetAddressesLength(Address[] addresses) => addresses.Sum(Rlp.LengthOf); + private static int GetAddressesLength(Address[] addresses) + { + const int AddressLengthWithRlpLengthPrefix = 1 + 20; + + return addresses.Length * AddressLengthWithRlpLengthPrefix; + } } } diff --git a/src/Nethermind/Nethermind.Core/Eip2930/AccessList.cs b/src/Nethermind/Nethermind.Core/Eip2930/AccessList.cs index 7d271adc44f..8d5cb5e9e16 100644 --- a/src/Nethermind/Nethermind.Core/Eip2930/AccessList.cs +++ b/src/Nethermind/Nethermind.Core/Eip2930/AccessList.cs @@ -116,6 +116,8 @@ public readonly void Dispose() { } private readonly int _index; private readonly int _count; + public int Count => _count; + public StorageKeysEnumerable(AccessList accessList, int index, int count) { _accessList = accessList; diff --git a/src/Nethermind/Nethermind.Flashbots/Handlers/ValidateBuilderSubmissionHandler.cs b/src/Nethermind/Nethermind.Flashbots/Handlers/ValidateBuilderSubmissionHandler.cs index 484369ac425..d037584a42f 100644 --- a/src/Nethermind/Nethermind.Flashbots/Handlers/ValidateBuilderSubmissionHandler.cs +++ b/src/Nethermind/Nethermind.Flashbots/Handlers/ValidateBuilderSubmissionHandler.cs @@ -3,25 +3,23 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; using Nethermind.Blockchain; using Nethermind.Blockchain.Tracing; -using Nethermind.Flashbots.Data; using Nethermind.Consensus; using Nethermind.Consensus.Processing; using Nethermind.Consensus.Validators; using Nethermind.Core; +using Nethermind.Core.Crypto; using Nethermind.Core.Specs; using Nethermind.Crypto; using Nethermind.Evm; -using Nethermind.Evm.Tracing; +using Nethermind.Evm.State; +using Nethermind.Flashbots.Data; using Nethermind.Int256; using Nethermind.JsonRpc; using Nethermind.Logging; using Nethermind.Merge.Plugin.Data; -using Nethermind.Core.Crypto; -using Nethermind.Evm.State; using Nethermind.State.OverridableEnv; namespace Nethermind.Flashbots.Handlers; @@ -147,7 +145,15 @@ private bool ValidateBlock(Block block, BidTrace message, long registeredGasLimi private bool ValidateBlobsBundle(Transaction[] transactions, BlobsBundleV1 blobsBundle, out string? error) { // get sum of length of blobs of each transaction - int totalBlobsLength = transactions.Sum(t => t.BlobVersionedHashes is not null ? t.BlobVersionedHashes.Length : 0); + int totalBlobsLength = 0; + foreach (Transaction tx in transactions) + { + byte[]?[]? versionedHashes = tx.BlobVersionedHashes; + if (versionedHashes is not null) + { + totalBlobsLength += versionedHashes.Length; + } + } if (totalBlobsLength != blobsBundle.Blobs.Length) { diff --git a/src/Nethermind/Nethermind.Serialization.Rlp/BlockBodyDecoder.cs b/src/Nethermind/Nethermind.Serialization.Rlp/BlockBodyDecoder.cs index d3b619a846b..f7fc6028159 100644 --- a/src/Nethermind/Nethermind.Serialization.Rlp/BlockBodyDecoder.cs +++ b/src/Nethermind/Nethermind.Serialization.Rlp/BlockBodyDecoder.cs @@ -2,7 +2,6 @@ // SPDX-License-Identifier: LGPL-3.0-only using System; -using System.Linq; using Nethermind.Core; namespace Nethermind.Serialization.Rlp; @@ -41,11 +40,44 @@ public int GetBodyLength(BlockBody b) b.Withdrawals is not null ? GetWithdrawalsLength(b.Withdrawals) : null ); - private int GetTxLength(Transaction[] transactions) => transactions.Sum(t => _txDecoder.GetLength(t, RlpBehaviors.None)); + private int GetTxLength(Transaction[] transactions) + { + if (transactions.Length == 0) return 0; + + int sum = 0; + foreach (Transaction tx in transactions) + { + sum += _txDecoder.GetLength(tx, RlpBehaviors.None); + } + + return sum; + } + + private int GetUnclesLength(BlockHeader[] headers) + { + if (headers.Length == 0) return 0; + + int sum = 0; + foreach (BlockHeader header in headers) + { + sum += _headerDecoder.GetLength(header, RlpBehaviors.None); + } - private int GetUnclesLength(BlockHeader[] headers) => headers.Sum(t => _headerDecoder.GetLength(t, RlpBehaviors.None)); + return sum; + } + + private int GetWithdrawalsLength(Withdrawal[] withdrawals) + { + if (withdrawals.Length == 0) return 0; - private int GetWithdrawalsLength(Withdrawal[] withdrawals) => withdrawals.Sum(t => _withdrawalDecoderDecoder.GetLength(t, RlpBehaviors.None)); + int sum = 0; + foreach (Withdrawal withdrawal in withdrawals) + { + sum += _withdrawalDecoderDecoder.GetLength(withdrawal, RlpBehaviors.None); + } + + return sum; + } public BlockBody? Decode(ref Rlp.ValueDecoderContext ctx, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { diff --git a/src/Nethermind/Nethermind.Serialization.Rlp/Eip2930/AccessListDecoder.cs b/src/Nethermind/Nethermind.Serialization.Rlp/Eip2930/AccessListDecoder.cs index 47cd8b2a634..e61b35690cc 100644 --- a/src/Nethermind/Nethermind.Serialization.Rlp/Eip2930/AccessListDecoder.cs +++ b/src/Nethermind/Nethermind.Serialization.Rlp/Eip2930/AccessListDecoder.cs @@ -1,7 +1,6 @@ // SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited // SPDX-License-Identifier: LGPL-3.0-only -using System.Linq; using Nethermind.Core; using Nethermind.Core.Eip2930; using Nethermind.Int256; @@ -151,7 +150,7 @@ public void Encode(RlpStream stream, AccessList? item, RlpBehaviors rlpBehaviors // Index2 // ... // IndexN - AccessItemLengths lengths = new(storageKeys.Count()); + AccessItemLengths lengths = new(storageKeys.Count); stream.StartSequence(lengths.ContentLength); { stream.Encode(address); @@ -199,9 +198,15 @@ public AccessItemLengths(int indexesCount) private static int GetContentLength(AccessList accessList) { - return accessList - .Select(static entry => new AccessItemLengths(entry.StorageKeys.Count())) - .Sum(static lengths => lengths.SequenceLength); + int sum = 0; + foreach ((Address Address, AccessList.StorageKeysEnumerable StorageKeys) entry in accessList) + { + int indexesContentLength = entry.StorageKeys.Count * Rlp.LengthOfKeccakRlp; + int contentLength = Rlp.LengthOfSequence(indexesContentLength) + Rlp.LengthOfAddressRlp; + sum += Rlp.LengthOfSequence(contentLength); + } + + return sum; } } }