Skip to content

Commit

Permalink
Use blob gas instead of count
Browse files Browse the repository at this point in the history
  • Loading branch information
flcl42 committed Oct 27, 2023
1 parent 422a1fe commit 724b7d9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
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} which is max value allowed.");
break;
}

checkedBlobTransactions++;

int txAmountOfBlobs = blobTx.BlobVersionedHashes?.Length ?? 0;
if (blobsCounter + txAmountOfBlobs > Eip4844Constants.MaxBlobsPerBlock)
ulong txAmountOfBlobs = (ulong)(blobTx.BlobVersionedHashes?.Length ?? 0);
if (Eip4844Constants.GasPerBlob * txAmountOfBlobs > Eip4844Constants.MaxBlobGasPerBlock - Eip4844Constants.GasPerBlob)
{
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 += txAmountOfBlobs * Eip4844Constants.GasPerBlob;
if (_logger.IsTrace) _logger.Trace($"Selected shard blob tx {fullBlobTx.ToShortString()} to be potentially included in block, total blobs 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

0 comments on commit 724b7d9

Please sign in to comment.