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

New filter restricting delegations in txpool #8022

Merged
merged 22 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void Accept_Eip7702IsNotActivated_ReturnsExpected(bool isActive, AcceptTx
headInfoProvider.GetCurrentHeadSpec().Returns(isActive ? Prague.Instance : Cancun.Instance);
TxDistinctSortedPool standardPool = new TxDistinctSortedPool(MemoryAllowance.MemPoolSize, Substitute.For<IComparer<Transaction>>(), NullLogManager.Instance);
TxDistinctSortedPool blobPool = new BlobTxDistinctSortedPool(10, Substitute.For<IComparer<Transaction>>(), NullLogManager.Instance);
Transaction inPool = Build.A.Transaction.SignedAndResolved(new EthereumEcdsa(0), TestItem.PrivateKeyA).TestObject;
Transaction inPool = Build.A.Transaction.WithNonce(0).SignedAndResolved(new EthereumEcdsa(0), TestItem.PrivateKeyA).TestObject;
standardPool.TryInsert(inPool.Hash, inPool);
IDb stateDb = new MemDb();
IDb codeDb = new MemDb();
Expand Down
8 changes: 8 additions & 0 deletions src/Nethermind/Nethermind.TxPool/Collections/SortedPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,14 @@ public bool TryGetBucketsWorstValue(TGroupKey groupKey, out TValue? item)
return false;
}

public bool BucketEmptyExcept(TGroupKey groupKey, Func<TValue, bool> predicate)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe better name BucketAny?

{
using var lockRelease = Lock.Acquire();
if (_buckets.TryGetValue(groupKey, out EnhancedSortedSet<TValue>? bucket) && bucket.Count > 0)
return bucket.Any(predicate);
return true;
}

protected void EnsureCapacity(int? expectedCapacity = null)
{
expectedCapacity ??= _capacity; // expectedCapacity is added for testing purpose. null should be used in production code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,9 @@ public AcceptTxResult Accept(Transaction tx, ref TxFilteringState state, TxHandl

if (!codeInfoRepository.TryGetDelegation(worldState, tx.SenderAddress!, out _))
return AcceptTxResult.Accepted;
Transaction[] currentTxs;

//Transactios from the same source can only be either blob transactions or some other type
if (standardPool.TryGetBucket(tx.SenderAddress!, out currentTxs) || blobPool.TryGetBucket(tx.SenderAddress!, out currentTxs))
if (!standardPool.BucketEmptyExcept(tx.SenderAddress!, (t) => t.Nonce == tx.Nonce) || !blobPool.BucketEmptyExcept(tx.SenderAddress!, (t) => t.Nonce == tx.Nonce))
ak88 marked this conversation as resolved.
Show resolved Hide resolved
{
foreach (Transaction existingTx in currentTxs)
{
if (existingTx.Nonce == tx.Nonce)
{
//This is a replacement tx so accept it, and let the comparers check for correct replacement rules
return AcceptTxResult.Accepted;
}
}
return AcceptTxResult.OnlyOneTxPerDelegatedAccount;
}
return AcceptTxResult.Accepted;
Expand Down
Loading