Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
}
}
2 changes: 2 additions & 0 deletions src/Nethermind/Nethermind.Core/Eip2930/AccessList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
40 changes: 36 additions & 4 deletions src/Nethermind/Nethermind.Serialization.Rlp/BlockBodyDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Linq;
using Nethermind.Core;

namespace Nethermind.Serialization.Rlp;
Expand Down Expand Up @@ -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)
{
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.Linq;
using Nethermind.Core;
using Nethermind.Core.Eip2930;
using Nethermind.Int256;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
}