Skip to content

Commit

Permalink
Other Lru keys types
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams committed Feb 8, 2023
1 parent a7ae5f1 commit 129ff7b
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public bool allows_transactions_before_transitions(long blockNumber)
VersionedTransactionPermissionContract transactionPermissionContract = new(AbiEncoder.Instance,
TestItem.AddressA,
5,
Substitute.For<IReadOnlyTxProcessorSource>(), new LruCache<Keccak, UInt256>(100, "TestCache"),
Substitute.For<IReadOnlyTxProcessorSource>(), new LruCache<KeccakKey, UInt256>(100, "TestCache"),
LimboLogs.Instance,
Substitute.For<ISpecProvider>());

Expand All @@ -263,7 +263,7 @@ public class TestTxPermissionsBlockchain : TestContractBlockchain
public PermissionBasedTxFilter PermissionBasedTxFilter { get; private set; }
public PermissionBasedTxFilter.Cache TxPermissionFilterCache { get; private set; }

public LruCache<Keccak, UInt256> TransactionPermissionContractVersions { get; private set; }
public LruCache<KeccakKey, UInt256> TransactionPermissionContractVersions { get; private set; }

protected override BlockProcessor CreateBlockProcessor()
{
Expand All @@ -274,7 +274,7 @@ protected override BlockProcessor CreateBlockProcessor()
};

TransactionPermissionContractVersions =
new LruCache<Keccak, UInt256>(PermissionBasedTxFilter.Cache.MaxCacheSize, nameof(TransactionPermissionContract));
new LruCache<KeccakKey, UInt256>(PermissionBasedTxFilter.Cache.MaxCacheSize, nameof(TransactionPermissionContract));

IReadOnlyTrieStore trieStore = new TrieStore(DbProvider.StateDb, LimboLogs.Instance).AsReadOnly();
IReadOnlyTxProcessorSource txProcessorSource = new ReadOnlyTxProcessingEnv(
Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.Blockchain/BlockTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ private readonly LruCache<KeccakKey, Block>
private readonly IDb _blockInfoDb;
private readonly IDb _metadataDb;

private readonly LruCache<Keccak, Block> _invalidBlocks =
new LruCache<Keccak, Block>(128, 128, "invalid blocks");
private readonly LruCache<KeccakKey, Block> _invalidBlocks =
new(128, 128, "invalid blocks");

private readonly BlockDecoder _blockDecoder = new();
private readonly HeaderDecoder _headerDecoder = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public class Cache
{
private const int MaxCacheSize = 10;

internal LruCache<Keccak, long?> GasLimitCache { get; } = new LruCache<Keccak, long?>(MaxCacheSize, "BlockGasLimit");
internal LruCache<KeccakKey, long?> GasLimitCache { get; } = new(MaxCacheSize, "BlockGasLimit");
}

public bool IsGasLimitValid(BlockHeader parentHeader, in long gasLimit, out long? expectedGasLimit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ public abstract class VersionedContract<T> : IActivatedAtBlock where T : IVersio
private readonly IDictionary<UInt256, T> _versions;

private readonly IVersionedContract _versionSelectorContract;
private readonly LruCache<Keccak, UInt256> _versionsCache;
private readonly LruCache<KeccakKey, UInt256> _versionsCache;
private readonly ILogger _logger;

protected VersionedContract(IDictionary<UInt256, T> versions, LruCache<Keccak, UInt256> cache, long activation, ILogManager logManager)
protected VersionedContract(IDictionary<UInt256, T> versions, LruCache<KeccakKey, UInt256> cache, long activation, ILogManager logManager)
{
_versions = versions ?? throw new ArgumentNullException(nameof(versions));
_versionSelectorContract = versions.Values.Last();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public VersionedTransactionPermissionContract(IAbiEncoder abiEncoder,
Address contractAddress,
long activation,
IReadOnlyTxProcessorSource readOnlyTxProcessorSource,
LruCache<Keccak, UInt256> cache,
LruCache<KeccakKey, UInt256> cache,
ILogManager logManager,
ISpecProvider specProvider)
: base(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class AuRaNethermindApi : NethermindApi

public IValidatorStore? ValidatorStore { get; set; }

public LruCache<Keccak, UInt256> TransactionPermissionContractVersions { get; }
= new LruCache<Keccak, UInt256>(
public LruCache<KeccakKey, UInt256> TransactionPermissionContractVersions { get; }
= new(
PermissionBasedTxFilter.Cache.MaxCacheSize,
nameof(TransactionPermissionContract));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class InvalidChainTracker : IInvalidChainTracker
private readonly IBlockFinder _blockFinder;
private readonly IBlockCacheService _blockCacheService;
private readonly ILogger _logger;
private readonly LruCache<Keccak, Node> _tree;
private readonly LruCache<KeccakKey, Node> _tree;

// CompositeDisposable only available on System.Reactive. So this will do for now.
private readonly List<Action> _disposables = new();
Expand All @@ -38,7 +38,7 @@ public InvalidChainTracker(
{
_poSSwitcher = poSSwitcher;
_blockFinder = blockFinder;
_tree = new LruCache<Keccak, Node>(1024, nameof(InvalidChainTracker));
_tree = new(1024, nameof(InvalidChainTracker));
_logger = logManager.GetClassLogger<InvalidChainTracker>();
_blockCacheService = blockCacheService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class WitnessCollector : IWitnessCollector, IWitnessRepository
[ThreadStatic]
private static bool _collectWitness;

private readonly LruCache<Keccak, Keccak[]> _witnessCache = new(256, "Witnesses");
private readonly LruCache<KeccakKey, Keccak[]> _witnessCache = new(256, "Witnesses");

public IReadOnlyCollection<Keccak> Collected => _collected;

Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.TxPool/TxPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ public void Dispose()
private static void AddNodeInfoEntryForTxPool()
{
ThisNodeInfo.AddInfo("Mem est tx :",
$"{(LruCache<Keccak, object>.CalculateMemorySize(32, MemoryAllowance.TxHashCacheSize) + LruCache<Keccak, Transaction>.CalculateMemorySize(4096, MemoryAllowance.MemPoolSize)) / 1000 / 1000}MB"
$"{(LruCache<KeccakKey, object>.CalculateMemorySize(32, MemoryAllowance.TxHashCacheSize) + LruCache<Keccak, Transaction>.CalculateMemorySize(4096, MemoryAllowance.MemPoolSize)) / 1000 / 1000}MB"
.PadLeft(8));
}
}
Expand Down

0 comments on commit 129ff7b

Please sign in to comment.