Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Nethermind/Nethermind.State/StateProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ public void Commit(IReleaseSpec releaseSpec, IWorldStateTracer stateTracer, bool
{
FlushToTree();
}

return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
namespace Nethermind.TxPool.Test.Collections
{
[TestFixture]
[Parallelizable(ParallelScope.None)]
[Parallelizable(ParallelScope.Self)]
public class DistinctValueSortedPoolTests
{
private const int Capacity = 16;
Expand Down Expand Up @@ -73,13 +73,12 @@ public static IEnumerable DistinctTestCases
[TestCaseSource(nameof(DistinctTestCases))]
public void Distinct_transactions_are_all_added(Transaction[] transactions, int expectedCount)
{

var pool = new TxDistinctSortedPool(Capacity, _transactionComparerProvider.GetDefaultComparer(), LimboLogs.Instance);

foreach (var transaction in transactions)
Parallel.ForEach(transactions, transaction =>
{
pool.TryInsert(transaction.Hash, transaction);
}
});

pool.Count.Should().Be(expectedCount);
}
Expand Down Expand Up @@ -219,14 +218,11 @@ public void Capacity_can_shrink_to_given_value(int shrinkValue, int expectedCapa
int capacityMultiplier = 10;
int expectedAllCount = Capacity * capacityMultiplier;

WithFinalizer newOne;
for (int i = 0; i < expectedAllCount; i++)
Parallel.For(0, expectedAllCount, i =>
{
newOne = new WithFinalizer();
WithFinalizer newOne = new();
pool.TryInsert(newOne.Index, newOne);
}

newOne = null;
});

CollectAndFinalize();

Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.TxPool.Test/NonceManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void should_reuse_nonce_if_tx_rejected()
}

[Test]
[Repeat(10)]
[Repeat(2)]
public void should_lock_on_same_account()
{
using NonceLocker locker = _nonceManager.ReserveNonce(TestItem.AddressA, out UInt256 nonce);
Expand All @@ -200,7 +200,7 @@ public void should_lock_on_same_account()
{
using NonceLocker locker = _nonceManager.ReserveNonce(TestItem.AddressA, out UInt256 _);
});
TimeSpan ts = TimeSpan.FromMilliseconds(1000);
TimeSpan ts = TimeSpan.FromMilliseconds(100);
task.Wait(ts);
task.IsCompleted.Should().Be(false);
}
Expand Down
37 changes: 20 additions & 17 deletions src/Nethermind/Nethermind.TxPool.Test/TxBroadcasterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ public async Task should_not_broadcast_persisted_tx_to_peer_too_quickly()
int addedTxsCount = TestItem.PrivateKeys.Length;
Transaction[] transactions = new Transaction[addedTxsCount];

for (int i = 0; i < addedTxsCount; i++)
Parallel.For(0, addedTxsCount, i =>
{
transactions[i] = Build.A.Transaction
.WithGasPrice(i.GWei())
.SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeys[i])
.TestObject;

_broadcaster.Broadcast(transactions[i], true);
}
});

_broadcaster.GetSnapshot().Length.Should().Be(addedTxsCount);

Expand Down Expand Up @@ -126,15 +126,15 @@ public void should_pick_best_persistent_txs_to_broadcast([Values(1, 2, 99, 100,
int addedTxsCount = TestItem.PrivateKeys.Length;
Transaction[] transactions = new Transaction[addedTxsCount];

for (int i = 0; i < addedTxsCount; i++)
Parallel.For(0, addedTxsCount, i =>
{
transactions[i] = Build.A.Transaction
.WithGasPrice(i.GWei())
.SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeys[i])
.TestObject;

_broadcaster.Broadcast(transactions[i], true);
}
});

_broadcaster.GetSnapshot().Length.Should().Be(addedTxsCount);

Expand Down Expand Up @@ -210,7 +210,7 @@ public void should_skip_large_txs_when_picking_best_persistent_txs_to_broadcast(
int addedTxsCount = TestItem.PrivateKeys.Length;
Transaction[] transactions = new Transaction[addedTxsCount];

for (int i = 0; i < addedTxsCount; i++)
Parallel.For(0, addedTxsCount, i =>
{
bool isLarge = i % 10 == 0;
transactions[i] = Build.A.Transaction
Expand All @@ -221,7 +221,7 @@ public void should_skip_large_txs_when_picking_best_persistent_txs_to_broadcast(
.TestObject;

_broadcaster.Broadcast(transactions[i], true);
}
});

_broadcaster.GetSnapshot().Length.Should().Be(addedTxsCount);

Expand Down Expand Up @@ -256,7 +256,7 @@ public void should_skip_blob_txs_when_picking_best_persistent_txs_to_broadcast([
int addedTxsCount = TestItem.PrivateKeys.Length;
Transaction[] transactions = new Transaction[addedTxsCount];

for (int i = 0; i < addedTxsCount; i++)
Parallel.For(0, addedTxsCount, i =>
{
bool isBlob = i % 10 == 0;
transactions[i] = Build.A.Transaction
Expand All @@ -267,7 +267,7 @@ public void should_skip_blob_txs_when_picking_best_persistent_txs_to_broadcast([
.TestObject;

_broadcaster.Broadcast(transactions[i], true);
}
});

_broadcaster.GetSnapshot().Length.Should().Be(addedTxsCount);

Expand Down Expand Up @@ -308,15 +308,15 @@ public void should_not_pick_txs_with_GasPrice_lower_than_CurrentBaseFee([Values(
int addedTxsCount = TestItem.PrivateKeys.Length;
Transaction[] transactions = new Transaction[addedTxsCount];

for (int i = 0; i < addedTxsCount; i++)
Parallel.For(0, addedTxsCount, i =>
{
transactions[i] = Build.A.Transaction
.WithGasPrice(i.GWei())
.SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeys[i])
.TestObject;

_broadcaster.Broadcast(transactions[i], true);
}
});

_broadcaster.GetSnapshot().Length.Should().Be(addedTxsCount);

Expand Down Expand Up @@ -382,7 +382,7 @@ public void should_not_pick_1559_txs_with_MaxFeePerGas_lower_than_CurrentBaseFee
int addedTxsCount = TestItem.PrivateKeys.Length;
Transaction[] transactions = new Transaction[addedTxsCount];

for (int i = 0; i < addedTxsCount; i++)
Parallel.For(0, addedTxsCount, i =>
{
transactions[i] = Build.A.Transaction
.WithType(TxType.EIP1559)
Expand All @@ -391,7 +391,7 @@ public void should_not_pick_1559_txs_with_MaxFeePerGas_lower_than_CurrentBaseFee
.TestObject;

_broadcaster.Broadcast(transactions[i], true);
}
});

_broadcaster.GetSnapshot().Length.Should().Be(addedTxsCount);

Expand Down Expand Up @@ -423,14 +423,17 @@ public void should_not_pick_blob_txs_with_MaxFeePerBlobGas_lower_than_CurrentFee
int addedTxsCount = TestItem.PrivateKeys.Length;
Transaction[] transactions = new Transaction[addedTxsCount];

for (int i = 0; i < addedTxsCount; i++)
Parallel.For(0, addedTxsCount, i =>
{
transactions[i] = Build.A.Transaction
.WithShardBlobTxTypeAndFields()
.WithMaxFeePerBlobGas(i.GWei())
.SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeys[i])
.TestObject;
});

for (int i = 0; i < addedTxsCount; i++)
{
Comment on lines +435 to +436
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here

_broadcaster.Broadcast(transactions[i], true);
}

Expand Down Expand Up @@ -466,7 +469,7 @@ public void should_pick_tx_with_lowest_nonce_from_bucket()
const int addedTxsCount = 5;
Transaction[] transactions = new Transaction[addedTxsCount];

for (int i = 0; i < addedTxsCount; i++)
Parallel.For(0, addedTxsCount, i =>
{
transactions[i] = Build.A.Transaction
.WithNonce((UInt256)i)
Expand All @@ -475,7 +478,7 @@ public void should_pick_tx_with_lowest_nonce_from_bucket()
.TestObject;

_broadcaster.Broadcast(transactions[i], true);
}
});
_broadcaster.GetSnapshot().Length.Should().Be(addedTxsCount);

IList<Transaction> pickedTxs = _broadcaster.GetPersistentTxsToSend().TransactionsToSend;
Expand Down Expand Up @@ -676,13 +679,13 @@ public void should_rebroadcast_all_persistent_transactions_if_PeerNotificationTh
_txPoolConfig = new TxPoolConfig() { Size = 100, PeerNotificationThreshold = shouldBroadcastAll ? 100 : 5 };
_broadcaster = new TxBroadcaster(_comparer, TimerFactory.Default, _txPoolConfig, _headInfo, _logManager);

for (int i = 0; i < _txPoolConfig.Size; i++)
Parallel.For(0, _txPoolConfig.Size, i =>
{
Transaction tx = Build.A.Transaction
.WithNonce((UInt256)i)
.SignedAndResolved(TestItem.PrivateKeyA).TestObject;
_broadcaster.Broadcast(tx, true);
}
});

Transaction[] pickedTxs = _broadcaster.GetPersistentTxsToSend().TransactionsToSend.ToArray();
pickedTxs.Length.Should().Be(shouldBroadcastAll ? 100 : 1);
Expand Down
18 changes: 12 additions & 6 deletions src/Nethermind/Nethermind.TxPool.Test/TxPoolTests.Blobs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,22 @@ public void should_reject_txs_with_nonce_too_far_in_future(TxType txType, int ma
};
_txPool = CreatePool(txPoolConfig, GetCancunSpecProvider());
EnsureSenderBalance(TestItem.AddressA, UInt256.MaxValue);
for (int nonce = 0; nonce < txPoolConfig.Size; nonce++)

Transaction[] txs = new Transaction[txPoolConfig.Size];
Parallel.For(0, txPoolConfig.Size, (nonce) =>
{
Transaction tx = Build.A.Transaction
txs[nonce] = Build.A.Transaction
.WithNonce((UInt256)nonce)
.WithType(txType)
.WithShardBlobTxTypeAndFieldsIfBlobTx()
.WithMaxFeePerGas(1.GWei())
.WithMaxPriorityFeePerGas(1.GWei())
.SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA).TestObject;
});

_txPool.SubmitTx(tx, TxHandlingOptions.None).Should().Be(nonce > expectedNumberOfAcceptedTxs
for (int nonce = 0; nonce < txPoolConfig.Size; nonce++)
{
_txPool.SubmitTx(txs[nonce], TxHandlingOptions.None).Should().Be(nonce > expectedNumberOfAcceptedTxs
? AcceptTxResult.NonceTooFarInFuture
: AcceptTxResult.Accepted);
}
Expand Down Expand Up @@ -775,7 +780,8 @@ public void should_index_blobs_when_adding_txs([Values(true, false)] bool isPers
public void should_handle_indexing_blobs_when_adding_txs_in_parallel([Values(true, false)] bool isPersistentStorage)
{
const int txsPerSender = 10;
int poolSize = TestItem.PrivateKeys.Length * txsPerSender;
PrivateKey[] testPrivateKeys = TestItem.PrivateKeys[..64];
int poolSize = testPrivateKeys.Length * txsPerSender;
TxPoolConfig txPoolConfig = new()
{
BlobsSupport = isPersistentStorage ? BlobsSupportMode.Storage : BlobsSupportMode.InMemory,
Expand All @@ -791,13 +797,13 @@ public void should_handle_indexing_blobs_when_adding_txs_in_parallel([Values(tru

byte[] expectedBlobVersionedHash = null;

foreach (PrivateKey privateKey in TestItem.PrivateKeys)
foreach (PrivateKey privateKey in testPrivateKeys)
{
EnsureSenderBalance(privateKey.Address, UInt256.MaxValue);
}

// adding, getting and removing txs in parallel
Parallel.ForEach(TestItem.PrivateKeys, privateKey =>
Parallel.ForEach(testPrivateKeys, privateKey =>
{
for (int i = 0; i < txsPerSender; i++)
{
Expand Down
Loading