Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams committed Jun 25, 2024
1 parent f90cf97 commit 6309415
Show file tree
Hide file tree
Showing 17 changed files with 409 additions and 529 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class PeerInfo : IUserOperationPoolPeer
{
private IUserOperationPoolPeer Peer { get; }

private ClockKeyCache<ValueHash256> NotifiedUserOperations { get; } = new(MemoryAllowance.MemPoolSize, "notifiedUserOperations");
private ClockKeyCache<ValueHash256> NotifiedUserOperations { get; } = new(MemoryAllowance.MemPoolSize);

public PeerInfo(IUserOperationPoolPeer peer)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ClockCacheTests
{
private static Cache Create()
{
return new Cache(Capacity, "test")!;
return new Cache(Capacity)!;
}

private const int Capacity = 32;
Expand Down Expand Up @@ -183,7 +183,7 @@ public void Beyond_capacity_lru_check()
[Test]
public void Beyond_capacity_lru_parallel()
{
Cache cache = new(Capacity, "test");
Cache cache = new(Capacity);
Parallel.For(0, Environment.ProcessorCount * 8, (iter) =>
{
for (int ii = 0; ii < Capacity; ii++)
Expand Down Expand Up @@ -275,7 +275,7 @@ public void Delete_keeps_internal_structure()
int itemsToKeep = 10;
int iterations = 40;

ClockCache<int, int> cache = new(maxCapacity, "test");
ClockCache<int, int> cache = new(maxCapacity);

for (int i = 0; i < iterations; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void Setup()
[Test]
public void At_capacity()
{
ClockKeyCacheNonConcurrent<AddressAsKey> cache = new(Capacity, "test");
ClockKeyCacheNonConcurrent<AddressAsKey> cache = new(Capacity);
for (int i = 0; i < Capacity; i++)
{
cache.Set(_addresses[i]).Should().BeTrue();
Expand All @@ -43,7 +43,7 @@ public void At_capacity()
[Test]
public void Can_reset()
{
ClockKeyCacheNonConcurrent<AddressAsKey> cache = new(Capacity, "test");
ClockKeyCacheNonConcurrent<AddressAsKey> cache = new(Capacity);
cache.Set(_addresses[0]).Should().BeTrue();
cache.Set(_addresses[0]).Should().BeFalse();
cache.Get(_addresses[0]).Should().BeTrue();
Expand All @@ -52,14 +52,14 @@ public void Can_reset()
[Test]
public void Can_ask_before_first_set()
{
ClockKeyCacheNonConcurrent<AddressAsKey> cache = new(Capacity, "test");
ClockKeyCacheNonConcurrent<AddressAsKey> cache = new(Capacity);
cache.Get(_addresses[0]).Should().BeFalse();
}

[Test]
public void Can_clear()
{
ClockKeyCacheNonConcurrent<AddressAsKey> cache = new(Capacity, "test");
ClockKeyCacheNonConcurrent<AddressAsKey> cache = new(Capacity);
cache.Set(_addresses[0]).Should().BeTrue();
cache.Clear();
cache.Get(_addresses[0]).Should().BeFalse();
Expand All @@ -70,7 +70,7 @@ public void Can_clear()
[Test]
public void Beyond_capacity()
{
ClockKeyCacheNonConcurrent<AddressAsKey> cache = new(Capacity, "test");
ClockKeyCacheNonConcurrent<AddressAsKey> cache = new(Capacity);
for (int i = 0; i < Capacity * 2; i++)
{
cache.Set(_addresses[i]);
Expand All @@ -90,7 +90,7 @@ public void Beyond_capacity()
[Test]
public void Beyond_capacity_lru()
{
ClockKeyCacheNonConcurrent<AddressAsKey> cache = new(Capacity, "test");
ClockKeyCacheNonConcurrent<AddressAsKey> cache = new(Capacity);
for (int i = 0; i < Capacity * 2; i++)
{
for (int ii = 0; ii < Capacity / 2; ii++)
Expand All @@ -105,7 +105,7 @@ public void Beyond_capacity_lru()
public void Beyond_capacity_lru_check()
{
Random random = new();
ClockKeyCacheNonConcurrent<AddressAsKey> cache = new(Capacity, "test");
ClockKeyCacheNonConcurrent<AddressAsKey> cache = new(Capacity);
for (var iter = 0; iter < Capacity; iter++)
{
for (int ii = 0; ii < Capacity; ii++)
Expand Down Expand Up @@ -172,7 +172,7 @@ public void Beyond_capacity_lru_check()
[Test]
public void Can_delete()
{
ClockKeyCacheNonConcurrent<AddressAsKey> cache = new(Capacity, "test");
ClockKeyCacheNonConcurrent<AddressAsKey> cache = new(Capacity);
cache.Set(_addresses[0]).Should().BeTrue();
cache.Delete(_addresses[0]);
cache.Get(_addresses[0]).Should().BeFalse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void Setup()
[Test]
public void At_capacity()
{
ClockKeyCache<AddressAsKey> cache = new(Capacity, "test");
ClockKeyCache<AddressAsKey> cache = new(Capacity);
for (int i = 0; i < Capacity; i++)
{
cache.Set(_addresses[i]);
Expand All @@ -44,7 +44,7 @@ public void At_capacity()
[Test]
public void Can_reset()
{
ClockKeyCache<AddressAsKey> cache = new(Capacity, "test");
ClockKeyCache<AddressAsKey> cache = new(Capacity);
cache.Set(_addresses[0]).Should().BeTrue();
cache.Set(_addresses[0]).Should().BeFalse();
cache.Get(_addresses[0]).Should().BeTrue();
Expand All @@ -53,14 +53,14 @@ public void Can_reset()
[Test]
public void Can_ask_before_first_set()
{
ClockKeyCache<AddressAsKey> cache = new(Capacity, "test");
ClockKeyCache<AddressAsKey> cache = new(Capacity);
cache.Get(_addresses[0]).Should().BeFalse();
}

[Test]
public void Can_clear()
{
ClockKeyCache<AddressAsKey> cache = new(Capacity, "test");
ClockKeyCache<AddressAsKey> cache = new(Capacity);
cache.Set(_addresses[0]).Should().BeTrue();
cache.Clear();
cache.Get(_addresses[0]).Should().BeFalse();
Expand All @@ -71,7 +71,7 @@ public void Can_clear()
[Test]
public void Beyond_capacity()
{
ClockKeyCache<AddressAsKey> cache = new(Capacity, "test");
ClockKeyCache<AddressAsKey> cache = new(Capacity);
for (int i = 0; i < Capacity * 2; i++)
{
cache.Set(_addresses[i]);
Expand All @@ -91,7 +91,7 @@ public void Beyond_capacity()
[Test]
public void Beyond_capacity_lru()
{
ClockKeyCache<AddressAsKey> cache = new(Capacity, "test");
ClockKeyCache<AddressAsKey> cache = new(Capacity);
for (int i = 0; i < Capacity * 2; i++)
{
for (int ii = 0; ii < Capacity / 2; ii++)
Expand All @@ -106,7 +106,7 @@ public void Beyond_capacity_lru()
public void Beyond_capacity_lru_check()
{
Random random = new();
ClockKeyCache<AddressAsKey> cache = new(Capacity, "test");
ClockKeyCache<AddressAsKey> cache = new(Capacity);
for (var iter = 0; iter < Capacity; iter++)
{
for (int ii = 0; ii < Capacity; ii++)
Expand Down Expand Up @@ -154,7 +154,7 @@ public void Beyond_capacity_lru_check()
[Test]
public void Beyond_capacity_lru_parallel()
{
ClockKeyCache<AddressAsKey> cache = new(Capacity, "test");
ClockKeyCache<AddressAsKey> cache = new(Capacity);
Parallel.For(0, Environment.ProcessorCount * 8, (s) =>
{
for (int ii = 0; ii < Capacity; ii++)
Expand Down Expand Up @@ -189,7 +189,7 @@ public void Beyond_capacity_lru_parallel()
[Test]
public void Can_delete()
{
ClockKeyCache<AddressAsKey> cache = new(Capacity, "test");
ClockKeyCache<AddressAsKey> cache = new(Capacity);
cache.Set(_addresses[0]);
cache.Delete(_addresses[0]);
cache.Get(_addresses[0]).Should().BeFalse();
Expand Down
4 changes: 4 additions & 0 deletions src/Nethermind/Nethermind.Core/Address.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ public readonly struct AddressAsKey(Address key) : IEquatable<AddressAsKey>

public bool Equals(AddressAsKey other) => _key == other._key;
public override int GetHashCode() => _key?.GetHashCode() ?? 0;
public override string ToString()
{
return _key?.ToString() ?? "<null>";
}
}

public ref struct AddressStructRef
Expand Down
Loading

0 comments on commit 6309415

Please sign in to comment.