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

Fix blob tx size calculation #8123

Merged
merged 13 commits into from
Jan 30, 2025
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be cool in addition to Transaction to have NetworkTransaction class-wrapper with GetTransaction method or so to make it clearer which form is used here or there. So you can't call GetLength for transaction without NetworkWrapper. May be too much work though

{
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