From 724b7d9af647c60cefe96a5b8fe3b59c13d03476 Mon Sep 17 00:00:00 2001 From: Alexey Osipov Date: Fri, 27 Oct 2023 18:24:18 +0300 Subject: [PATCH] Use blob gas instead of count --- .../Producers/TxPoolTxSource.cs | 16 ++++++++-------- .../Nethermind.Core/Eip4844Constants.cs | 2 +- .../Nethermind.TxPool/LightTransaction.cs | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/Producers/TxPoolTxSource.cs b/src/Nethermind/Nethermind.Consensus/Producers/TxPoolTxSource.cs index a06d3394c70..4e85ff5d7ab 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/TxPoolTxSource.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/TxPoolTxSource.cs @@ -60,7 +60,7 @@ public IEnumerable GetTransactions(BlockHeader parent, long gasLimi int checkedTransactions = 0; int selectedTransactions = 0; - using ArrayPoolList selectedBlobTxs = new(Eip4844Constants.MaxBlobsPerBlock); + using ArrayPoolList selectedBlobTxs = new((int)(Eip4844Constants.MaxBlobGasPerBlock / Eip4844Constants.GasPerBlob)); SelectBlobTransactions(blobTransactions, parent, spec, selectedBlobTxs); @@ -121,21 +121,21 @@ private void SelectBlobTransactions(IEnumerable 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; @@ -162,8 +162,8 @@ private void SelectBlobTransactions(IEnumerable 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); diff --git a/src/Nethermind/Nethermind.Core/Eip4844Constants.cs b/src/Nethermind/Nethermind.Core/Eip4844Constants.cs index 100fc075029..5e36a2db54f 100644 --- a/src/Nethermind/Nethermind.Core/Eip4844Constants.cs +++ b/src/Nethermind/Nethermind.Core/Eip4844Constants.cs @@ -16,7 +16,7 @@ public class Eip4844Constants /// Defaults to 2e17. public const ulong GasPerBlob = 1 << 17; - public const int MaxBlobsPerBlock = 6; + private const int MaxBlobsPerBlock = 6; public const int MinBlobsPerTransaction = 1; /// diff --git a/src/Nethermind/Nethermind.TxPool/LightTransaction.cs b/src/Nethermind/Nethermind.TxPool/LightTransaction.cs index e456887d816..52563472b77 100644 --- a/src/Nethermind/Nethermind.TxPool/LightTransaction.cs +++ b/src/Nethermind/Nethermind.TxPool/LightTransaction.cs @@ -16,7 +16,7 @@ namespace Nethermind.TxPool; public class LightTransaction : Transaction { private static readonly Dictionary _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)