Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use blob gas instead of count #6229

Merged
merged 3 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 8 additions & 8 deletions src/Nethermind/Nethermind.Consensus/Producers/TxPoolTxSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public IEnumerable<Transaction> GetTransactions(BlockHeader parent, long gasLimi

int checkedTransactions = 0;
int selectedTransactions = 0;
using ArrayPoolList<Transaction> selectedBlobTxs = new(Eip4844Constants.MaxBlobsPerBlock);
using ArrayPoolList<Transaction> selectedBlobTxs = new((int)(Eip4844Constants.MaxBlobGasPerBlock / Eip4844Constants.GasPerBlob));

SelectBlobTransactions(blobTransactions, parent, spec, selectedBlobTxs);

Expand Down Expand Up @@ -121,21 +121,21 @@ private void SelectBlobTransactions(IEnumerable<Transaction> blobTransactions, B
{
int checkedBlobTransactions = 0;
int selectedBlobTransactions = 0;
int blobsCounter = 0;
UInt256 blobGasCounter = 0;
UInt256 blobGasPrice = UInt256.Zero;

foreach (Transaction blobTx in blobTransactions)
{
if (blobsCounter == Eip4844Constants.MaxBlobsPerBlock)
if (blobGasCounter >= Eip4844Constants.MaxBlobGasPerBlock)
{
if (_logger.IsTrace) _logger.Trace($"Declining {blobTx.ToShortString()}, no more blob space. Block already have {blobsCounter} which is max value allowed.");
if (_logger.IsTrace) _logger.Trace($"Declining {blobTx.ToShortString()}, no more blob space. Block already have {blobGasCounter} blob gas which is max value allowed.");
break;
}

checkedBlobTransactions++;

int txAmountOfBlobs = blobTx.BlobVersionedHashes?.Length ?? 0;
if (blobsCounter + txAmountOfBlobs > Eip4844Constants.MaxBlobsPerBlock)
ulong txBlobGas = (ulong)(blobTx.BlobVersionedHashes?.Length ?? 0) * Eip4844Constants.GasPerBlob;
if (txBlobGas > Eip4844Constants.MaxBlobGasPerBlock - blobGasCounter)
{
if (_logger.IsTrace) _logger.Trace($"Declining {blobTx.ToShortString()}, not enough blob space.");
continue;
Expand All @@ -162,8 +162,8 @@ private void SelectBlobTransactions(IEnumerable<Transaction> blobTransactions, B
continue;
}

blobsCounter += txAmountOfBlobs;
if (_logger.IsTrace) _logger.Trace($"Selected shard blob tx {fullBlobTx.ToShortString()} to be potentially included in block, total blobs included: {blobsCounter}.");
blobGasCounter += txBlobGas;
if (_logger.IsTrace) _logger.Trace($"Selected shard blob tx {fullBlobTx.ToShortString()} to be potentially included in block, total blob gas included: {blobGasCounter}.");

selectedBlobTransactions++;
selectedBlobTxs.Add(fullBlobTx);
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Core/Eip4844Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Eip4844Constants
/// <remarks>Defaults to 2e17.</remarks>
public const ulong GasPerBlob = 1 << 17;

public const int MaxBlobsPerBlock = 6;
private const int MaxBlobsPerBlock = 6;
public const int MinBlobsPerTransaction = 1;

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.TxPool/LightTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Nethermind.TxPool;
public class LightTransaction : Transaction
{
private static readonly Dictionary<int, byte[][]> _blobVersionedHashesCache =
Enumerable.Range(1, Eip4844Constants.MaxBlobsPerBlock).ToDictionary(i => i, i => new byte[i][]);
Enumerable.Range(1, (int)(Eip4844Constants.MaxBlobGasPerBlock / Eip4844Constants.GasPerBlob)).ToDictionary(i => i, i => new byte[i][]);


public LightTransaction(Transaction fullTx)
Expand Down
Loading