Skip to content

Commit

Permalink
Fix blob tx size calculation (#8123)
Browse files Browse the repository at this point in the history
Co-authored-by: Lukasz Rozmej <[email protected]>
  • Loading branch information
marcindsobczak and LukaszRozmej authored Jan 30, 2025
1 parent e8707e6 commit 7ea03c2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Nethermind/Nethermind.Core/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ private void ClearPreHashInternal()
/// </summary>
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()
Expand Down
18 changes: 18 additions & 0 deletions src/Nethermind/Nethermind.TxPool.Test/TxPoolTests.Blobs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 7ea03c2

Please sign in to comment.