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

Update txPool worst value if removal unsuccessful #6702

Merged
merged 1 commit into from
Feb 12, 2024
Merged
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
13 changes: 5 additions & 8 deletions src/Nethermind/Nethermind.TxPool/Collections/SortedPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,9 @@ public virtual bool TryInsert(TKey key, TValue value, out TValue? removed)

if (_cacheMap.Count > _capacity)
{
RemoveLast(out removed);

// Self-recovery in case of exceeding collection's max capacity.
// If capacity is exceeded by more than 1 (1 is normal situation), then remove one more item.
// Every time when we will add 1 item, we will remove 2, until we will drop below max cap.
if (_cacheMap.Count > _capacity)
if (!RemoveLast(out removed) || _cacheMap.Count > _capacity)
{
UpdateWorstValue();
RemoveLast(out removed);
}

Expand All @@ -334,16 +330,17 @@ public virtual bool TryInsert(TKey key, TValue value, out TValue? removed)

public bool TryInsert(TKey key, TValue value) => TryInsert(key, value, out _);

private void RemoveLast(out TValue? removed)
private bool RemoveLast(out TValue? removed)
{
TKey? key = _worstValue.GetValueOrDefault().Value;
if (key is not null)
{
TryRemoveNonLocked(key, true, out removed, out _);
return TryRemoveNonLocked(key, true, out removed, out _);
}
else
{
removed = default;
return false;
}
}

Expand Down