From 7ea03c217b82dc8e3245453d8d847aad33c380e7 Mon Sep 17 00:00:00 2001 From: Marcin Sobczak <77129288+marcindsobczak@users.noreply.github.com> Date: Thu, 30 Jan 2025 10:52:42 +0100 Subject: [PATCH] Fix blob tx size calculation (#8123) Co-authored-by: Lukasz Rozmej --- src/Nethermind/Nethermind.Core/Transaction.cs | 4 +++- .../TxPoolTests.Blobs.cs | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Core/Transaction.cs b/src/Nethermind/Nethermind.Core/Transaction.cs index e47e4301200..d94b0abc38b 100644 --- a/src/Nethermind/Nethermind.Core/Transaction.cs +++ b/src/Nethermind/Nethermind.Core/Transaction.cs @@ -197,7 +197,9 @@ private void ClearPreHashInternal() /// public int GetLength(ITransactionSizeCalculator sizeCalculator, bool shouldCountBlobs) { - return _size ??= sizeCalculator.GetLength(this, shouldCountBlobs); + return shouldCountBlobs + ? _size ??= sizeCalculator.GetLength(this, true) + : sizeCalculator.GetLength(this, false); } public string ToShortString() diff --git a/src/Nethermind/Nethermind.TxPool.Test/TxPoolTests.Blobs.cs b/src/Nethermind/Nethermind.TxPool.Test/TxPoolTests.Blobs.cs index 823c29abc7b..30438690c1b 100644 --- a/src/Nethermind/Nethermind.TxPool.Test/TxPoolTests.Blobs.cs +++ b/src/Nethermind/Nethermind.TxPool.Test/TxPoolTests.Blobs.cs @@ -60,6 +60,24 @@ public void should_reject_blob_tx_if_max_size_is_exceeded([Values(true, false)] _txPool.GetPendingBlobTransactionsCount().Should().Be(sizeExceeded ? 0 : 1); } + [Test] + public void should_calculate_blob_tx_size_properly([Values(1, 2, 3, 4, 5, 6)] int numberOfBlobs) + { + Transaction tx = Build.A.Transaction + .WithShardBlobTxTypeAndFields(numberOfBlobs) + .WithMaxPriorityFeePerGas(1.GWei()) + .WithMaxFeePerGas(1.GWei()) + .SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA).TestObject; + EnsureSenderBalance(TestItem.AddressA, UInt256.MaxValue); + + var txPoolConfig = new TxPoolConfig() { MaxBlobTxSize = tx.GetLength(shouldCountBlobs: false) }; + _txPool = CreatePool(txPoolConfig, GetCancunSpecProvider()); + + _txPool.SubmitTx(tx, TxHandlingOptions.PersistentBroadcast).Should().Be(AcceptTxResult.Accepted); + _txPool.TryGetPendingBlobTransaction(tx.Hash!, out Transaction blobTx); + blobTx!.GetLength().Should().BeGreaterThan((int)txPoolConfig.MaxBlobTxSize); + } + [Test] public void blob_pool_size_should_be_correct([Values(true, false)] bool persistentStorageEnabled) {