diff --git a/src/Nethermind/Nethermind.AccountAbstraction.Test/AccountAbstractionPeerManagerTests.cs b/src/Nethermind/Nethermind.AccountAbstraction.Test/AccountAbstractionPeerManagerTests.cs index b274ceb01ef..4c242b20cc6 100644 --- a/src/Nethermind/Nethermind.AccountAbstraction.Test/AccountAbstractionPeerManagerTests.cs +++ b/src/Nethermind/Nethermind.AccountAbstraction.Test/AccountAbstractionPeerManagerTests.cs @@ -26,16 +26,16 @@ namespace Nethermind.AccountAbstraction.Test [TestFixture] public class AccountAbstractionPeerManagerTests { - private IDictionary _userOperationPools = new Dictionary(); - private IUserOperationSimulator _simulator = Substitute.For(); - private IBlockTree _blockTree = Substitute.For(); - private ILogger _logger = Substitute.For(); - private ILogFinder _logFinder = Substitute.For(); - private IWorldState _stateProvider = Substitute.For(); - private ISpecProvider _specProvider = Substitute.For(); + private readonly IDictionary _userOperationPools = new Dictionary(); + private readonly IUserOperationSimulator _simulator = Substitute.For(); + private readonly IBlockTree _blockTree = Substitute.For(); + private readonly ILogger _logger = Substitute.For(); + private readonly ILogFinder _logFinder = Substitute.For(); + private readonly IWorldState _stateProvider = Substitute.For(); + private readonly ISpecProvider _specProvider = Substitute.For(); private readonly ISigner _signer = Substitute.For(); private readonly string[] _entryPointContractAddress = { "0x8595dd9e0438640b5e1254f9df579ac12a86865f", "0x96cc609c8f5458fb8a7da4d94b678e38ebf3d04e" }; - private static Address _notAnAddress = new("0x373f2D08b1C195fF08B9AbEdE3C78575FAAC2aCf"); + private static readonly Address _notAnAddress = new("0x373f2D08b1C195fF08B9AbEdE3C78575FAAC2aCf"); [Test] public void should_add_peers() diff --git a/src/Nethermind/Nethermind.AccountAbstraction.Test/AccountAbstractionRpcModuleTests.TestAccountAbstractionRpcBlockchain.cs b/src/Nethermind/Nethermind.AccountAbstraction.Test/AccountAbstractionRpcModuleTests.TestAccountAbstractionRpcBlockchain.cs index 3e8f29490ab..78ef9773988 100644 --- a/src/Nethermind/Nethermind.AccountAbstraction.Test/AccountAbstractionRpcModuleTests.TestAccountAbstractionRpcBlockchain.cs +++ b/src/Nethermind/Nethermind.AccountAbstraction.Test/AccountAbstractionRpcModuleTests.TestAccountAbstractionRpcBlockchain.cs @@ -80,7 +80,7 @@ public TestAccountAbstractionRpcBlockchain(UInt256? initialBaseFeePerGas) public IAccountAbstractionRpcModule AccountAbstractionRpcModule { get; set; } = Substitute.For(); public ManualGasLimitCalculator GasLimitCalculator = new() { GasLimit = 10_000_000 }; - private AccountAbstractionConfig _accountAbstractionConfig = new AccountAbstractionConfig() + private readonly AccountAbstractionConfig _accountAbstractionConfig = new AccountAbstractionConfig() { Enabled = true, EntryPointContractAddresses = "0xb0894727fe4ff102e1f1c8a16f38afc7b859f215,0x96cc609c8f5458fb8a7da4d94b678e38ebf3d04e", diff --git a/src/Nethermind/Nethermind.AccountAbstraction.Test/AccountAbstractionRpcModuleTests.cs b/src/Nethermind/Nethermind.AccountAbstraction.Test/AccountAbstractionRpcModuleTests.cs index 9adf2ceb376..fca2101ad3f 100644 --- a/src/Nethermind/Nethermind.AccountAbstraction.Test/AccountAbstractionRpcModuleTests.cs +++ b/src/Nethermind/Nethermind.AccountAbstraction.Test/AccountAbstractionRpcModuleTests.cs @@ -31,9 +31,9 @@ namespace Nethermind.AccountAbstraction.Test; [TestFixture] public partial class AccountAbstractionRpcModuleTests { - private Contracts _contracts = new(); - private AbiEncoder _encoder = new(); - private static int entryPointNum = 2; + private readonly Contracts _contracts = new(); + private readonly AbiEncoder _encoder = new(); + private static readonly int entryPointNum = 2; public class Contracts { @@ -43,7 +43,7 @@ public class Contracts internal AbiDefinition TestCounterAbi; internal AbiDefinition TokenPaymasterAbi; - private AbiEncoder _encoder = new(); + private readonly AbiEncoder _encoder = new(); public Contracts() { diff --git a/src/Nethermind/Nethermind.AccountAbstraction.Test/UserOperationPoolTests.cs b/src/Nethermind/Nethermind.AccountAbstraction.Test/UserOperationPoolTests.cs index 094100155fd..b66eddd16fa 100644 --- a/src/Nethermind/Nethermind.AccountAbstraction.Test/UserOperationPoolTests.cs +++ b/src/Nethermind/Nethermind.AccountAbstraction.Test/UserOperationPoolTests.cs @@ -36,16 +36,16 @@ public class UserOperationPoolTests #pragma warning disable NUnit1032 private IUserOperationPool _userOperationPool = Substitute.For(); #pragma warning restore NUnit1032 - private IUserOperationSimulator _simulator = Substitute.For(); - private IBlockTree _blockTree = Substitute.For(); - private IReceiptFinder _receiptFinder = Substitute.For(); - private ILogFinder _logFinder = Substitute.For(); - private IWorldState _stateProvider = Substitute.For(); - private ISpecProvider _specProvider = Substitute.For(); + private readonly IUserOperationSimulator _simulator = Substitute.For(); + private readonly IBlockTree _blockTree = Substitute.For(); + private readonly IReceiptFinder _receiptFinder = Substitute.For(); + private readonly ILogFinder _logFinder = Substitute.For(); + private readonly IWorldState _stateProvider = Substitute.For(); + private readonly ISpecProvider _specProvider = Substitute.For(); private readonly ISigner _signer = Substitute.For(); private readonly Hash256 _userOperationEventTopic = new("0x33fd4d1f25a5461bea901784a6571de6debc16cd0831932c22c6969cd73ba994"); private readonly string _entryPointContractAddress = "0x8595dd9e0438640b5e1254f9df579ac12a86865f"; - private static Address _notAnAddress = new("0x373f2D08b1C195fF08B9AbEdE3C78575FAAC2aCf"); + private static readonly Address _notAnAddress = new("0x373f2D08b1C195fF08B9AbEdE3C78575FAAC2aCf"); [Test] public void Can_add_user_operation_correctly() diff --git a/src/Nethermind/Nethermind.AccountAbstraction.Test/UserOperationSubscribeTests.cs b/src/Nethermind/Nethermind.AccountAbstraction.Test/UserOperationSubscribeTests.cs index 3d7e6ce7bef..409ed0d0beb 100644 --- a/src/Nethermind/Nethermind.AccountAbstraction.Test/UserOperationSubscribeTests.cs +++ b/src/Nethermind/Nethermind.AccountAbstraction.Test/UserOperationSubscribeTests.cs @@ -49,11 +49,11 @@ public class UserOperationSubscribeTests private IJsonRpcDuplexClient _jsonRpcDuplexClient = null!; private IJsonSerializer _jsonSerializer = null!; private ISpecProvider _specProvider = null!; - private ISyncConfig _syncConfig = new SyncConfig(); - private IDictionary _userOperationPools = new Dictionary(); + private readonly ISyncConfig _syncConfig = new SyncConfig(); + private readonly IDictionary _userOperationPools = new Dictionary(); //Any test pool and entry point addresses should work for testing. - private Address _testPoolAddress = Address.Zero; - private Address _entryPointAddress = new("0x90f3e1105e63c877bf9587de5388c23cdb702c6b"); + private readonly Address _testPoolAddress = Address.Zero; + private readonly Address _entryPointAddress = new("0x90f3e1105e63c877bf9587de5388c23cdb702c6b"); [SetUp] public void Setup() diff --git a/src/Nethermind/Nethermind.AccountAbstraction/Bundler/MevBundler.cs b/src/Nethermind/Nethermind.AccountAbstraction/Bundler/MevBundler.cs index b4e3fa82b42..2a295a5b1cf 100644 --- a/src/Nethermind/Nethermind.AccountAbstraction/Bundler/MevBundler.cs +++ b/src/Nethermind/Nethermind.AccountAbstraction/Bundler/MevBundler.cs @@ -12,10 +12,10 @@ namespace Nethermind.AccountAbstraction.Bundler { public class MevBundler : IBundler { - private IBundleTrigger _trigger; - private ITxSource _txSource; - private IBundlePool _bundlePool; - private ILogger _logger; + private readonly IBundleTrigger _trigger; + private readonly ITxSource _txSource; + private readonly IBundlePool _bundlePool; + private readonly ILogger _logger; public MevBundler(IBundleTrigger trigger, ITxSource txSource, IBundlePool bundlePool, ILogger logger) { diff --git a/src/Nethermind/Nethermind.AccountAbstraction/Network/AaProtocolHandler.cs b/src/Nethermind/Nethermind.AccountAbstraction/Network/AaProtocolHandler.cs index 7ae364d1e66..ea6832c043a 100644 --- a/src/Nethermind/Nethermind.AccountAbstraction/Network/AaProtocolHandler.cs +++ b/src/Nethermind/Nethermind.AccountAbstraction/Network/AaProtocolHandler.cs @@ -26,7 +26,7 @@ namespace Nethermind.AccountAbstraction.Network public class AaProtocolHandler : ProtocolHandlerBase, IZeroProtocolHandler, IUserOperationPoolPeer { private readonly ISession _session; - private IDictionary _userOperationPools; + private readonly IDictionary _userOperationPools; private readonly IAccountAbstractionPeerManager _peerManager; public AaProtocolHandler(ISession session, diff --git a/src/Nethermind/Nethermind.AccountAbstraction/Network/AccountAbstractionPeerManager.cs b/src/Nethermind/Nethermind.AccountAbstraction/Network/AccountAbstractionPeerManager.cs index 833b53dab31..f9dbce52af7 100644 --- a/src/Nethermind/Nethermind.AccountAbstraction/Network/AccountAbstractionPeerManager.cs +++ b/src/Nethermind/Nethermind.AccountAbstraction/Network/AccountAbstractionPeerManager.cs @@ -14,7 +14,7 @@ namespace Nethermind.AccountAbstraction.Network { public class AccountAbstractionPeerManager : IAccountAbstractionPeerManager { - private IDictionary _userOperationPools; + private readonly IDictionary _userOperationPools; private readonly IUserOperationBroadcaster _broadcaster; private readonly ILogger _logger; diff --git a/src/Nethermind/Nethermind.AccountAbstraction/Network/UserOperationsMessageSerializer.cs b/src/Nethermind/Nethermind.AccountAbstraction/Network/UserOperationsMessageSerializer.cs index 510fb503852..1a3e9de316b 100644 --- a/src/Nethermind/Nethermind.AccountAbstraction/Network/UserOperationsMessageSerializer.cs +++ b/src/Nethermind/Nethermind.AccountAbstraction/Network/UserOperationsMessageSerializer.cs @@ -10,7 +10,7 @@ namespace Nethermind.AccountAbstraction.Network { public class UserOperationsMessageSerializer : IZeroInnerMessageSerializer { - private UserOperationDecoder _decoder = new(); + private readonly UserOperationDecoder _decoder = new(); public void Serialize(IByteBuffer byteBuffer, UserOperationsMessage message) { diff --git a/src/Nethermind/Nethermind.Analytics/RewardsVerifier.cs b/src/Nethermind/Nethermind.Analytics/RewardsVerifier.cs index c53e26f8a0d..ac876d041d0 100644 --- a/src/Nethermind/Nethermind.Analytics/RewardsVerifier.cs +++ b/src/Nethermind/Nethermind.Analytics/RewardsVerifier.cs @@ -15,12 +15,12 @@ namespace Nethermind.Analytics { public class RewardsVerifier : IBlockTreeVisitor { - private ILogger _logger; + private readonly ILogger _logger; public bool PreventsAcceptingNewBlocks => true; public long StartLevelInclusive => 0; public long EndLevelExclusive { get; } - private UInt256 _genesisAllocations = UInt256.Parse("72009990499480000000000000"); + private readonly UInt256 _genesisAllocations = UInt256.Parse("72009990499480000000000000"); private UInt256 _uncles; public UInt256 BlockRewards { get; private set; } diff --git a/src/Nethermind/Nethermind.Analytics/SupplyVerifier.cs b/src/Nethermind/Nethermind.Analytics/SupplyVerifier.cs index bfe07c8ef0a..513ace3ff10 100644 --- a/src/Nethermind/Nethermind.Analytics/SupplyVerifier.cs +++ b/src/Nethermind/Nethermind.Analytics/SupplyVerifier.cs @@ -14,7 +14,7 @@ namespace Nethermind.Analytics public class SupplyVerifier : ITreeVisitor { private readonly ILogger _logger; - private HashSet _ignoreThisOne = new HashSet(); + private readonly HashSet _ignoreThisOne = new HashSet(); private int _accountsVisited; private int _nodesVisited; diff --git a/src/Nethermind/Nethermind.AuRa.Test/Transactions/PermissionTxComparerTests.cs b/src/Nethermind/Nethermind.AuRa.Test/Transactions/PermissionTxComparerTests.cs index 9fee91bac4b..66804baf543 100644 --- a/src/Nethermind/Nethermind.AuRa.Test/Transactions/PermissionTxComparerTests.cs +++ b/src/Nethermind/Nethermind.AuRa.Test/Transactions/PermissionTxComparerTests.cs @@ -27,7 +27,7 @@ namespace Nethermind.AuRa.Test.Transactions { public class PermissionTxComparerTests { - private static Address[] WhitelistedSenders = new[] { TestItem.AddressC, TestItem.AddressD }; + private static readonly Address[] WhitelistedSenders = new[] { TestItem.AddressC, TestItem.AddressD }; public static IEnumerable OrderingTests { diff --git a/src/Nethermind/Nethermind.AuRa.Test/Validators/ContractBasedValidatorTests.cs b/src/Nethermind/Nethermind.AuRa.Test/Validators/ContractBasedValidatorTests.cs index f1b18c2789e..91dad8e1fc5 100644 --- a/src/Nethermind/Nethermind.AuRa.Test/Validators/ContractBasedValidatorTests.cs +++ b/src/Nethermind/Nethermind.AuRa.Test/Validators/ContractBasedValidatorTests.cs @@ -45,7 +45,7 @@ public class ContractBasedValidatorTests private BlockHeader _parentHeader; private IReadOnlyTransactionProcessor _transactionProcessor; private IAuRaBlockFinalizationManager _blockFinalizationManager; - private static Address _contractAddress = Address.FromNumber(1000); + private static readonly Address _contractAddress = Address.FromNumber(1000); private (Address Sender, byte[] TransactionData) _getValidatorsData = (Address.Zero, new byte[] { 0, 1, 2 }); private (Address Sender, byte[] TransactionData) _finalizeChangeData = (Address.SystemUser, new byte[] { 3, 4, 5 }); private Address[] _initialValidators; diff --git a/src/Nethermind/Nethermind.Blockchain.Test/BlockTreeTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/BlockTreeTests.cs index 03d3b870be0..abf91c29860 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/BlockTreeTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/BlockTreeTests.cs @@ -1215,7 +1215,7 @@ public void Loads_lowest_inserted_body_correctly(long beginIndex, long insertedB } - private static object[] SourceOfBSearchTestCases = + private static readonly object[] SourceOfBSearchTestCases = { new object[] {1L, 0L}, new object[] {1L, 1L}, diff --git a/src/Nethermind/Nethermind.Blockchain.Test/BlockchainProcessorTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/BlockchainProcessorTests.cs index 054b47e4296..aa50d09e96d 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/BlockchainProcessorTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/BlockchainProcessorTests.cs @@ -33,17 +33,17 @@ public class BlockchainProcessorTests { private class ProcessingTestContext { - private ILogManager _logManager = LimboLogs.Instance; + private readonly ILogManager _logManager = LimboLogs.Instance; private class BlockProcessorMock : IBlockProcessor { - private ILogger _logger; + private readonly ILogger _logger; - private HashSet _allowed = new(); + private readonly HashSet _allowed = new(); - private HashSet _allowedToFail = new(); + private readonly HashSet _allowedToFail = new(); - private HashSet _rootProcessed = new(); + private readonly HashSet _rootProcessed = new(); public BlockProcessorMock(ILogManager logManager, IStateReader stateReader) { diff --git a/src/Nethermind/Nethermind.Blockchain.Test/Consensus/SinglePendingTxSelectorTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/Consensus/SinglePendingTxSelectorTests.cs index f8d509b7e5d..de48f000265 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/Consensus/SinglePendingTxSelectorTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/Consensus/SinglePendingTxSelectorTests.cs @@ -14,7 +14,7 @@ namespace Nethermind.Blockchain.Test.Consensus { public class SinglePendingTxSelectorTests { - private BlockHeader _anyParent = Build.A.BlockHeader.TestObject; + private readonly BlockHeader _anyParent = Build.A.BlockHeader.TestObject; [Test, Timeout(Timeout.MaxTestTime)] public void To_string_does_not_throw() diff --git a/src/Nethermind/Nethermind.Blockchain.Test/Receipts/ReceiptsIteratorTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/Receipts/ReceiptsIteratorTests.cs index 6201e017336..da658279ddc 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/Receipts/ReceiptsIteratorTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/Receipts/ReceiptsIteratorTests.cs @@ -17,7 +17,7 @@ namespace Nethermind.Blockchain.Test.Receipts; public class ReceiptsIteratorTests { - ReceiptArrayStorageDecoder _decoder = ReceiptArrayStorageDecoder.Instance; + readonly ReceiptArrayStorageDecoder _decoder = ReceiptArrayStorageDecoder.Instance; [Test] public void SmokeTestWithRecovery() diff --git a/src/Nethermind/Nethermind.Blockchain.Test/Validators/TestTransactionValidator.cs b/src/Nethermind/Nethermind.Blockchain.Test/Validators/TestTransactionValidator.cs index 34a939e8f0f..61f1ce96815 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/Validators/TestTransactionValidator.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/Validators/TestTransactionValidator.cs @@ -14,7 +14,7 @@ public class TestTxValidator : ITxValidator public static TestTxValidator NeverValid = new(false); private readonly Queue _validationResults = new(); - private bool? _alwaysSameResult; + private readonly bool? _alwaysSameResult; public TestTxValidator(Queue validationResults) { diff --git a/src/Nethermind/Nethermind.Blockchain/BlockTree.cs b/src/Nethermind/Nethermind.Blockchain/BlockTree.cs index 52207849d4a..1cd26959893 100644 --- a/src/Nethermind/Nethermind.Blockchain/BlockTree.cs +++ b/src/Nethermind/Nethermind.Blockchain/BlockTree.cs @@ -33,7 +33,7 @@ public partial class BlockTree : IBlockTree { // there is not much logic in the addressing here public static readonly byte[] LowestInsertedBodyNumberDbEntryAddress = ((long)0).ToBigEndianByteArrayWithoutLeadingZeros(); - private static byte[] StateHeadHashDbEntryAddress = new byte[16]; + private static readonly byte[] StateHeadHashDbEntryAddress = new byte[16]; internal static Hash256 DeletePointerAddressInDb = new(new BitArray(32 * 8, true).ToBytes()); internal static Hash256 HeadAddressInDb = Keccak.Zero; diff --git a/src/Nethermind/Nethermind.Blockchain/BlockhashProvider.cs b/src/Nethermind/Nethermind.Blockchain/BlockhashProvider.cs index 02a1343acaf..065211ac7a2 100644 --- a/src/Nethermind/Nethermind.Blockchain/BlockhashProvider.cs +++ b/src/Nethermind/Nethermind.Blockchain/BlockhashProvider.cs @@ -13,7 +13,7 @@ namespace Nethermind.Blockchain { public class BlockhashProvider : IBlockhashProvider { - private static int _maxDepth = 256; + private static readonly int _maxDepth = 256; private readonly IBlockTree _blockTree; private readonly ILogger _logger; diff --git a/src/Nethermind/Nethermind.Blockchain/FullPruning/CopyTreeVisitor.cs b/src/Nethermind/Nethermind.Blockchain/FullPruning/CopyTreeVisitor.cs index ef271982b0b..ee85beb5d79 100644 --- a/src/Nethermind/Nethermind.Blockchain/FullPruning/CopyTreeVisitor.cs +++ b/src/Nethermind/Nethermind.Blockchain/FullPruning/CopyTreeVisitor.cs @@ -26,7 +26,7 @@ public class CopyTreeVisitor : ITreeVisitor, IDisposable private readonly Stopwatch _stopwatch; private long _persistedNodes = 0; private bool _finished = false; - private WriteFlags _writeFlags; + private readonly WriteFlags _writeFlags; private readonly CancellationToken _cancellationToken; private const int Million = 1_000_000; diff --git a/src/Nethermind/Nethermind.Blockchain/Receipts/LogEntriesIterator.cs b/src/Nethermind/Nethermind.Blockchain/Receipts/LogEntriesIterator.cs index b240a5367ae..62a1cfff39f 100644 --- a/src/Nethermind/Nethermind.Blockchain/Receipts/LogEntriesIterator.cs +++ b/src/Nethermind/Nethermind.Blockchain/Receipts/LogEntriesIterator.cs @@ -12,7 +12,7 @@ public ref struct LogEntriesIterator private readonly LogEntry[]? _logs; private readonly int _length; private Rlp.ValueDecoderContext _decoderContext; - private IReceiptRefDecoder _receiptRefDecoder; + private readonly IReceiptRefDecoder _receiptRefDecoder; public long Index { get; private set; } public LogEntriesIterator(Span data, IReceiptRefDecoder receiptRefDecoder) diff --git a/src/Nethermind/Nethermind.Blockchain/Receipts/ReceiptsIterator.cs b/src/Nethermind/Nethermind.Blockchain/Receipts/ReceiptsIterator.cs index 03f482f2e68..141952a117d 100644 --- a/src/Nethermind/Nethermind.Blockchain/Receipts/ReceiptsIterator.cs +++ b/src/Nethermind/Nethermind.Blockchain/Receipts/ReceiptsIterator.cs @@ -15,14 +15,14 @@ public ref struct ReceiptsIterator private readonly IDb _blocksDb; private readonly int _length; private Rlp.ValueDecoderContext _decoderContext; - private int _startingPosition; + private readonly int _startingPosition; private readonly TxReceipt[]? _receipts; private int _receiptIndex; private readonly Func? _recoveryContextFactory; private IReceiptsRecovery.IRecoveryContext? _recoveryContext; - private IReceiptRefDecoder _receiptRefDecoder; + private readonly IReceiptRefDecoder _receiptRefDecoder; private bool _recoveryContextConfigured; public ReceiptsIterator(scoped in Span receiptsData, IDb blocksDb, Func? recoveryContextFactory, IReceiptRefDecoder receiptRefDecoder) diff --git a/src/Nethermind/Nethermind.Blockchain/Visitors/StartupBlockTreeFixer.cs b/src/Nethermind/Nethermind.Blockchain/Visitors/StartupBlockTreeFixer.cs index 2dc9658cb99..9d00840036c 100644 --- a/src/Nethermind/Nethermind.Blockchain/Visitors/StartupBlockTreeFixer.cs +++ b/src/Nethermind/Nethermind.Blockchain/Visitors/StartupBlockTreeFixer.cs @@ -22,8 +22,8 @@ public class StartupBlockTreeFixer : IBlockTreeVisitor private readonly IBlockTree _blockTree; private readonly IStateReader _stateReader; private readonly ILogger _logger; - private long _startNumber; - private long _blocksToLoad; + private readonly long _startNumber; + private readonly long _blocksToLoad; private ChainLevelInfo _currentLevel; private long _currentLevelNumber; diff --git a/src/Nethermind/Nethermind.Cli.Test/ProofCliModuleTests.cs b/src/Nethermind/Nethermind.Cli.Test/ProofCliModuleTests.cs index eecfdf18ccc..dac449f4a53 100644 --- a/src/Nethermind/Nethermind.Cli.Test/ProofCliModuleTests.cs +++ b/src/Nethermind/Nethermind.Cli.Test/ProofCliModuleTests.cs @@ -19,7 +19,7 @@ namespace Nethermind.Cli.Test { public class ProofCliModuleTests { - private ICliConsole _cliConsole = Substitute.For(); + private readonly ICliConsole _cliConsole = Substitute.For(); private EthereumJsonSerializer _serializer; private IJsonRpcClient _jsonRpcClient; private CliEngine _engine; diff --git a/src/Nethermind/Nethermind.Cli/Modules/CliModuleLoader.cs b/src/Nethermind/Nethermind.Cli/Modules/CliModuleLoader.cs index 21ac2e6079e..2f8d1860054 100644 --- a/src/Nethermind/Nethermind.Cli/Modules/CliModuleLoader.cs +++ b/src/Nethermind/Nethermind.Cli/Modules/CliModuleLoader.cs @@ -217,7 +217,7 @@ public void LoadModule(Type type) } } - private Dictionary _objects = new Dictionary(); + private readonly Dictionary _objects = new Dictionary(); private static void AddMethod(ObjectInstance instance, string name, DelegateWrapper delegateWrapper) { diff --git a/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs b/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs index b0205e5430e..2b90cea30dc 100644 --- a/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs +++ b/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs @@ -46,18 +46,18 @@ public class CliqueBlockProducerTests { private class On { - private ILogManager _logManager = LimboLogs.Instance; + private readonly ILogManager _logManager = LimboLogs.Instance; // private ILogManager _logManager = new OneLoggerLogManager(new ConsoleAsyncLogger(LogLevel.Debug)); - private ILogger _logger; - private static ITimestamper _timestamper = Timestamper.Default; - private CliqueConfig _cliqueConfig; - private EthereumEcdsa _ethereumEcdsa = new(BlockchainIds.Goerli, LimboLogs.Instance); - private Dictionary _logManagers = new(); - private Dictionary _snapshotManager = new(); - private Dictionary _blockTrees = new(); - private Dictionary _blockEvents = new(); - private Dictionary _producers = new(); - private Dictionary _pools = new(); + private readonly ILogger _logger; + private static readonly ITimestamper _timestamper = Timestamper.Default; + private readonly CliqueConfig _cliqueConfig; + private readonly EthereumEcdsa _ethereumEcdsa = new(BlockchainIds.Goerli, LimboLogs.Instance); + private readonly Dictionary _logManagers = new(); + private readonly Dictionary _snapshotManager = new(); + private readonly Dictionary _blockTrees = new(); + private readonly Dictionary _blockEvents = new(); + private readonly Dictionary _producers = new(); + private readonly Dictionary _pools = new(); private On() : this(15) @@ -198,9 +198,9 @@ public On CreateNode(PrivateKey privateKey, bool withGenesisAlreadyProcessed = f public static On FastGoerli => new(1); - private Block _genesis3Validators; + private readonly Block _genesis3Validators; - private Block _genesis; + private readonly Block _genesis; private Block GetGenesis(int validatorsCount = 2) { @@ -438,7 +438,7 @@ public async Task StopNode(PrivateKey privateKeyA) return this; } - private UInt256 _currentNonce = 0; + private readonly UInt256 _currentNonce = 0; public On AddPendingTransaction(PrivateKey nodeKey) { @@ -553,7 +553,7 @@ public On Wait(int i) } } - private static int _timeout = 2000; // this has to cover block period of second + wiggle of up to 500ms * (signers - 1) + 100ms delay of the block readiness check + private static readonly int _timeout = 2000; // this has to cover block period of second + wiggle of up to 500ms * (signers - 1) + 100ms delay of the block readiness check [Test] public async Task Can_produce_block_with_transactions() diff --git a/src/Nethermind/Nethermind.Clique.Test/SnapshotManagerTests.cs b/src/Nethermind/Nethermind.Clique.Test/SnapshotManagerTests.cs index d826d8481bc..e48acbab9c9 100644 --- a/src/Nethermind/Nethermind.Clique.Test/SnapshotManagerTests.cs +++ b/src/Nethermind/Nethermind.Clique.Test/SnapshotManagerTests.cs @@ -20,7 +20,7 @@ namespace Nethermind.Clique.Test [TestFixture] public class SnapshotManagerTests { - private IDb _snapshotDb = new MemDb(); + private readonly IDb _snapshotDb = new MemDb(); private const string Block1Rlp = "f9025bf90256a06341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a053580584816f617295ea26c0e17641e0120cab2f0a8ffb53a866fd53aa8e8c2da056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002018347c94c808458ee45dab861d783010600846765746887676f312e372e33856c696e757800000000000000009f1efa1efa72af138c915966c639544a0255e6288e188c22ce9168c10dbe46da3d88b4aa065930119fb886210bf01a084fde5d3bc48d8aa38bca92e4fcc5215100a00000000000000000000000000000000000000000000000000000000000000000880000000000000000c0c0"; private const string Block2Rlp = "f9025bf90256a0a7684ac44d48494670b2e0d9085b7750e7341620f0a271db146ed5e70c1db854a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a053580584816f617295ea26c0e17641e0120cab2f0a8ffb53a866fd53aa8e8c2da056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002028347db3d808458ee45eab861d783010600846765746887676f312e372e33856c696e75780000000000000000b5a4a624d2e19fdab62ff7f4d2f2b80dfab4c518761beb56c2319c4224dd156f698bb1a2750c7edf12d61c4022079622062039637f40fb817e2cce0f0a4dae9c01a00000000000000000000000000000000000000000000000000000000000000000880000000000000000c0c0"; diff --git a/src/Nethermind/Nethermind.Config.Test/StandardConfigTests.cs b/src/Nethermind/Nethermind.Config.Test/StandardConfigTests.cs index 7f2e9781129..15443b22a45 100644 --- a/src/Nethermind/Nethermind.Config.Test/StandardConfigTests.cs +++ b/src/Nethermind/Nethermind.Config.Test/StandardConfigTests.cs @@ -14,7 +14,7 @@ namespace Nethermind.Config.Test { public static class StandardConfigTests { - private static JsonSerializerOptions _jsonOptions = new() { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping }; + private static readonly JsonSerializerOptions _jsonOptions = new() { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping }; public static void ValidateDefaultValues() { diff --git a/src/Nethermind/Nethermind.Config/EnvConfigSource.cs b/src/Nethermind/Nethermind.Config/EnvConfigSource.cs index 24246cc39eb..fd28c23b195 100644 --- a/src/Nethermind/Nethermind.Config/EnvConfigSource.cs +++ b/src/Nethermind/Nethermind.Config/EnvConfigSource.cs @@ -9,7 +9,7 @@ namespace Nethermind.Config { public class EnvConfigSource : IConfigSource { - private IEnvironment _environmentWrapper; + private readonly IEnvironment _environmentWrapper; public EnvConfigSource() : this(new EnvironmentWrapper()) { diff --git a/src/Nethermind/Nethermind.Config/JsonConfigProvider.cs b/src/Nethermind/Nethermind.Config/JsonConfigProvider.cs index f986072bf01..46034a6f097 100644 --- a/src/Nethermind/Nethermind.Config/JsonConfigProvider.cs +++ b/src/Nethermind/Nethermind.Config/JsonConfigProvider.cs @@ -7,7 +7,7 @@ namespace Nethermind.Config { public class JsonConfigProvider : IConfigProvider { - private ConfigProvider _provider = new(); + private readonly ConfigProvider _provider = new(); public JsonConfigProvider(string jsonConfigFile) { diff --git a/src/Nethermind/Nethermind.Consensus.AuRa/Contracts/RegisterContract.cs b/src/Nethermind/Nethermind.Consensus.AuRa/Contracts/RegisterContract.cs index a81bbc521c9..6d7d3e67960 100644 --- a/src/Nethermind/Nethermind.Consensus.AuRa/Contracts/RegisterContract.cs +++ b/src/Nethermind/Nethermind.Consensus.AuRa/Contracts/RegisterContract.cs @@ -21,7 +21,7 @@ public interface IRegisterContract /// public class RegisterContract : Contract, IRegisterContract { - private static Address MissingAddress = Address.Zero; + private static readonly Address MissingAddress = Address.Zero; private static readonly object[] MissingGetAddressResult = { MissingAddress }; /// diff --git a/src/Nethermind/Nethermind.Consensus.Clique/CliqueSealValidator.cs b/src/Nethermind/Nethermind.Consensus.Clique/CliqueSealValidator.cs index e400297aa41..3089eac04c4 100644 --- a/src/Nethermind/Nethermind.Consensus.Clique/CliqueSealValidator.cs +++ b/src/Nethermind/Nethermind.Consensus.Clique/CliqueSealValidator.cs @@ -12,7 +12,7 @@ internal class CliqueSealValidator : ISealValidator { private readonly ICliqueConfig _cliqueConfig; private readonly ISnapshotManager _snapshotManager; - private ILogger _logger; + private readonly ILogger _logger; public CliqueSealValidator(ICliqueConfig cliqueConfig, ISnapshotManager snapshotManager, ILogManager logManager) { diff --git a/src/Nethermind/Nethermind.Consensus.Clique/SnapshotManager.cs b/src/Nethermind/Nethermind.Consensus.Clique/SnapshotManager.cs index 5474bc8e533..0d801cd18ae 100644 --- a/src/Nethermind/Nethermind.Consensus.Clique/SnapshotManager.cs +++ b/src/Nethermind/Nethermind.Consensus.Clique/SnapshotManager.cs @@ -21,15 +21,15 @@ namespace Nethermind.Consensus.Clique { public class SnapshotManager : ISnapshotManager { - private static byte[] _snapshotBytes = Encoding.UTF8.GetBytes("snapshot-"); + private static readonly byte[] _snapshotBytes = Encoding.UTF8.GetBytes("snapshot-"); private readonly IBlockTree _blockTree; private readonly ICliqueConfig _cliqueConfig; private readonly ILogger _logger; private readonly LruCache _signatures; private readonly IEthereumEcdsa _ecdsa; - private IDb _blocksDb; + private readonly IDb _blocksDb; private ulong _lastSignersCount = 0; - private LruCache _snapshotCache = new(Clique.InMemorySnapshots, "clique snapshots"); + private readonly LruCache _snapshotCache = new(Clique.InMemorySnapshots, "clique snapshots"); public SnapshotManager(ICliqueConfig cliqueConfig, IDb blocksDb, IBlockTree blockTree, IEthereumEcdsa ecdsa, ILogManager logManager) { @@ -84,7 +84,7 @@ public static Hash256 CalculateCliqueHeaderHash(BlockHeader blockHeader) return sigHash; } - private object _snapshotCreationLock = new(); + private readonly object _snapshotCreationLock = new(); public ulong GetLastSignersCount() => _lastSignersCount; @@ -226,7 +226,7 @@ private static Hash256 GetSnapshotKey(Hash256 blockHash) return new Hash256(keyBytes); } - private SnapshotDecoder _decoder = new(); + private readonly SnapshotDecoder _decoder = new(); [Todo(Improve.Refactor, "I guess it was only added here because of the use of blocksdb")] private Snapshot? LoadSnapshot(Hash256 hash) diff --git a/src/Nethermind/Nethermind.Consensus.Ethash/Ethash.cs b/src/Nethermind/Nethermind.Consensus.Ethash/Ethash.cs index 8ba606c652d..f3f5813e2eb 100644 --- a/src/Nethermind/Nethermind.Consensus.Ethash/Ethash.cs +++ b/src/Nethermind/Nethermind.Consensus.Ethash/Ethash.cs @@ -24,7 +24,7 @@ namespace Nethermind.Consensus.Ethash { internal class Ethash : IEthash { - private HintBasedCache _hintBasedCache; + private readonly HintBasedCache _hintBasedCache; private readonly ILogger _logger; @@ -208,7 +208,7 @@ public void HintRange(Guid guid, long start, long end) _hintBasedCache.Hint(guid, start, end); } - private Guid _hintBasedCacheUser = Guid.Empty; + private readonly Guid _hintBasedCacheUser = Guid.Empty; public bool Validate(BlockHeader header) { @@ -251,7 +251,7 @@ private IEthashDataSet BuildCache(uint epoch) return dataSet; } - private static HeaderDecoder _headerDecoder = new(); + private static readonly HeaderDecoder _headerDecoder = new(); private static Hash256 GetTruncatedHash(BlockHeader header) { diff --git a/src/Nethermind/Nethermind.Consensus.Ethash/EthashCache.cs b/src/Nethermind/Nethermind.Consensus.Ethash/EthashCache.cs index a3de622c77c..33d06038295 100644 --- a/src/Nethermind/Nethermind.Consensus.Ethash/EthashCache.cs +++ b/src/Nethermind/Nethermind.Consensus.Ethash/EthashCache.cs @@ -57,7 +57,7 @@ public static Bucket Xor(Bucket a, Bucket b) } } - private ArrayPool _arrayPool = ArrayPool.Create(1024 * 1024 * 2, 50); + private readonly ArrayPool _arrayPool = ArrayPool.Create(1024 * 1024 * 2, 50); private Bucket[] Data { get; set; } diff --git a/src/Nethermind/Nethermind.Consensus.Ethash/HintBasedCache.cs b/src/Nethermind/Nethermind.Consensus.Ethash/HintBasedCache.cs index bf9f0a42f21..1794b8bcc14 100644 --- a/src/Nethermind/Nethermind.Consensus.Ethash/HintBasedCache.cs +++ b/src/Nethermind/Nethermind.Consensus.Ethash/HintBasedCache.cs @@ -14,10 +14,10 @@ namespace Nethermind.Consensus.Ethash { internal class HintBasedCache { - private Dictionary> _epochsPerGuid = new(); - private Dictionary _epochRefs = new(); - private Dictionary> _cachedSets = new(); - private Dictionary _recent = new(); + private readonly Dictionary> _epochsPerGuid = new(); + private readonly Dictionary _epochRefs = new(); + private readonly Dictionary> _cachedSets = new(); + private readonly Dictionary _recent = new(); private struct DataSetWithTime { @@ -36,7 +36,7 @@ public DataSetWithTime(DateTimeOffset timestamp, Task dataSet) public int CachedEpochsCount => _cachedEpochsCount; private readonly Func _createDataSet; - private ILogger _logger; + private readonly ILogger _logger; public HintBasedCache(Func createDataSet, ILogManager logManager) { diff --git a/src/Nethermind/Nethermind.Consensus/Processing/OneTimeProcessor.cs b/src/Nethermind/Nethermind.Consensus/Processing/OneTimeProcessor.cs index b2d0b8c14a8..7742620dde6 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/OneTimeProcessor.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/OneTimeProcessor.cs @@ -17,7 +17,7 @@ public class OneTimeChainProcessor : IBlockchainProcessor private readonly IBlockchainProcessor _processor; private readonly IWorldState _worldState; - private object _lock = new(); + private readonly object _lock = new(); public OneTimeChainProcessor(IWorldState worldState, IBlockchainProcessor processor) { diff --git a/src/Nethermind/Nethermind.Consensus/Processing/ProcessingStats.cs b/src/Nethermind/Nethermind.Consensus/Processing/ProcessingStats.cs index 5d36900eb83..5f29f9af04e 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/ProcessingStats.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/ProcessingStats.cs @@ -35,7 +35,7 @@ internal class ProcessingStats private long _lastSelfDestructs; private long _maxMemory; private long _totalBlocks; - private bool _isDebugMode = false; + private readonly bool _isDebugMode = false; private decimal _processingMicroseconds; private long _lastTotalCreates; private long _lastReportMs; diff --git a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs index 1163effe3da..e23c0705e0d 100644 --- a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs +++ b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs @@ -93,7 +93,7 @@ protected TestBlockchain() public static Address AccountC = TestItem.AddressC; public SemaphoreSlim _resetEvent = null!; private ManualResetEvent _suggestedBlockResetEvent = null!; - private AutoResetEvent _oneAtATime = new(true); + private readonly AutoResetEvent _oneAtATime = new(true); private IBlockFinder _blockFinder = null!; public static readonly UInt256 InitialValue = 1000.Ether(); diff --git a/src/Nethermind/Nethermind.Core.Test/Builders/PrivateKeyBuilder.cs b/src/Nethermind/Nethermind.Core.Test/Builders/PrivateKeyBuilder.cs index d9ee47e3ff9..2d2dfa5f227 100644 --- a/src/Nethermind/Nethermind.Core.Test/Builders/PrivateKeyBuilder.cs +++ b/src/Nethermind/Nethermind.Core.Test/Builders/PrivateKeyBuilder.cs @@ -7,7 +7,7 @@ namespace Nethermind.Core.Test.Builders { public class PrivateKeyBuilder : BuilderBase { - private PrivateKeyGenerator _generator = new(); + private readonly PrivateKeyGenerator _generator = new(); public PrivateKeyBuilder() { diff --git a/src/Nethermind/Nethermind.Core.Test/Encoding/BlockDecoderTests.cs b/src/Nethermind/Nethermind.Core.Test/Encoding/BlockDecoderTests.cs index 1de97dd9f91..bf378f9d01c 100644 --- a/src/Nethermind/Nethermind.Core.Test/Encoding/BlockDecoderTests.cs +++ b/src/Nethermind/Nethermind.Core.Test/Encoding/BlockDecoderTests.cs @@ -17,7 +17,7 @@ namespace Nethermind.Core.Test.Encoding; [TestFixture] public class BlockDecoderTests { - private Block[] _scenarios; + private readonly Block[] _scenarios; public BlockDecoderTests() { @@ -99,7 +99,7 @@ public void Can_do_roundtrip_null([Values(true, false)] bool valueDecoder) Assert.IsNull(decoded); } - private string regression5644 = "f902cff9025aa05297f2a4a699ba7d038a229a8eb7ab29d0073b37376ff0311f2bd9c608411830a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0fe77dd4ad7c2a3fa4c11868a00e4d728adcdfef8d2e3c13b256b06cbdbb02ec9a00d0abe08c162e4e0891e7a45a8107a98ae44ed47195c2d041fe574de40272df0a0056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000182160c837a1200825208845c54648eb8613078366336393733363936653733366236390000000000000000000000000000f3ec96e458292ccea72a1e53e95f94c28051ab51880b7e03d933f7fa78c9692f635ae55ac3899c9c6999d33c758b5248a05894a3471282333bcd76067c5d391300a00000000000000000000000000000000000000000000000000000000000000000880000000000000000f86ff86d80843b9aca008252089422ea9f6b28db76a7162054c05ed812deb2f519cd8a152d02c7e14af6800000802da0f67424c67d9f91a87b5437db1bdaa05e29bd020ab474b2f67f7be163c9f650dda02f90ab34b44165d776ae04449b15210076d6a72abe2bda2903d4b87f0d1ce541c0"; + private readonly string regression5644 = "f902cff9025aa05297f2a4a699ba7d038a229a8eb7ab29d0073b37376ff0311f2bd9c608411830a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0fe77dd4ad7c2a3fa4c11868a00e4d728adcdfef8d2e3c13b256b06cbdbb02ec9a00d0abe08c162e4e0891e7a45a8107a98ae44ed47195c2d041fe574de40272df0a0056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000182160c837a1200825208845c54648eb8613078366336393733363936653733366236390000000000000000000000000000f3ec96e458292ccea72a1e53e95f94c28051ab51880b7e03d933f7fa78c9692f635ae55ac3899c9c6999d33c758b5248a05894a3471282333bcd76067c5d391300a00000000000000000000000000000000000000000000000000000000000000000880000000000000000f86ff86d80843b9aca008252089422ea9f6b28db76a7162054c05ed812deb2f519cd8a152d02c7e14af6800000802da0f67424c67d9f91a87b5437db1bdaa05e29bd020ab474b2f67f7be163c9f650dda02f90ab34b44165d776ae04449b15210076d6a72abe2bda2903d4b87f0d1ce541c0"; [Test] public void Can_do_roundtrip_regression([Values(true, false)] bool valueDecoder) diff --git a/src/Nethermind/Nethermind.Core.Test/Json/BigIntegerConverterTests.cs b/src/Nethermind/Nethermind.Core.Test/Json/BigIntegerConverterTests.cs index 02f86072dd6..0ac2270dfda 100644 --- a/src/Nethermind/Nethermind.Core.Test/Json/BigIntegerConverterTests.cs +++ b/src/Nethermind/Nethermind.Core.Test/Json/BigIntegerConverterTests.cs @@ -14,8 +14,8 @@ namespace Nethermind.Core.Test.Json [TestFixture] public class BigIntegerConverterTests : ConverterTestBase { - static BigIntegerConverter converter = new BigIntegerConverter(); - static JsonSerializerOptions options = new JsonSerializerOptions { Converters = { converter } }; + static readonly BigIntegerConverter converter = new BigIntegerConverter(); + static readonly JsonSerializerOptions options = new JsonSerializerOptions { Converters = { converter } }; public void Test_roundtrip() { diff --git a/src/Nethermind/Nethermind.Core.Test/Json/Hash256ConverterTests.cs b/src/Nethermind/Nethermind.Core.Test/Json/Hash256ConverterTests.cs index 336070222c6..66ae46b8e72 100644 --- a/src/Nethermind/Nethermind.Core.Test/Json/Hash256ConverterTests.cs +++ b/src/Nethermind/Nethermind.Core.Test/Json/Hash256ConverterTests.cs @@ -14,8 +14,8 @@ namespace Nethermind.Core.Test.Json [TestFixture] public class Hash256ConverterTests { - static Hash256Converter converter = new(); - static JsonSerializerOptions options = new JsonSerializerOptions { Converters = { converter } }; + static readonly Hash256Converter converter = new(); + static readonly JsonSerializerOptions options = new JsonSerializerOptions { Converters = { converter } }; [Test] public void Can_read_null() diff --git a/src/Nethermind/Nethermind.Core.Test/Json/LongConverterTests.cs b/src/Nethermind/Nethermind.Core.Test/Json/LongConverterTests.cs index b7ecf8cc1b7..49eaa264371 100644 --- a/src/Nethermind/Nethermind.Core.Test/Json/LongConverterTests.cs +++ b/src/Nethermind/Nethermind.Core.Test/Json/LongConverterTests.cs @@ -14,8 +14,8 @@ namespace Nethermind.Core.Test.Json [TestFixture] public class LongConverterTests : ConverterTestBase { - static LongConverter converter = new(); - static JsonSerializerOptions options = new JsonSerializerOptions { Converters = { converter } }; + static readonly LongConverter converter = new(); + static readonly JsonSerializerOptions options = new JsonSerializerOptions { Converters = { converter } }; public void Test_roundtrip() { diff --git a/src/Nethermind/Nethermind.Core.Test/Json/NullableBigIntegerConverterTests.cs b/src/Nethermind/Nethermind.Core.Test/Json/NullableBigIntegerConverterTests.cs index dd29a2f7c38..eb0c8bb5bf5 100644 --- a/src/Nethermind/Nethermind.Core.Test/Json/NullableBigIntegerConverterTests.cs +++ b/src/Nethermind/Nethermind.Core.Test/Json/NullableBigIntegerConverterTests.cs @@ -14,8 +14,8 @@ namespace Nethermind.Core.Test.Json [TestFixture] public class NullableBigIntegerConverterTests : ConverterTestBase { - static NullableBigIntegerConverter converter = new NullableBigIntegerConverter(); - static JsonSerializerOptions options = new JsonSerializerOptions { Converters = { converter } }; + static readonly NullableBigIntegerConverter converter = new NullableBigIntegerConverter(); + static readonly JsonSerializerOptions options = new JsonSerializerOptions { Converters = { converter } }; public void Test_roundtrip() { TestConverter(null, (integer, bigInteger) => integer.Equals(bigInteger), converter); diff --git a/src/Nethermind/Nethermind.Core.Test/Json/NullableLongConverterTests.cs b/src/Nethermind/Nethermind.Core.Test/Json/NullableLongConverterTests.cs index 70917d3f953..1bcc127f0c7 100644 --- a/src/Nethermind/Nethermind.Core.Test/Json/NullableLongConverterTests.cs +++ b/src/Nethermind/Nethermind.Core.Test/Json/NullableLongConverterTests.cs @@ -14,8 +14,8 @@ namespace Nethermind.Core.Test.Json [TestFixture] public class NullableLongConverterTests : ConverterTestBase { - static NullableLongConverter converter = new(); - static JsonSerializerOptions options = new JsonSerializerOptions { Converters = { converter } }; + static readonly NullableLongConverter converter = new(); + static readonly JsonSerializerOptions options = new JsonSerializerOptions { Converters = { converter } }; public void Test_roundtrip() { diff --git a/src/Nethermind/Nethermind.Core.Test/Json/NullableUInt256ConverterTests.cs b/src/Nethermind/Nethermind.Core.Test/Json/NullableUInt256ConverterTests.cs index b15ef87ae15..ebdaaf2a549 100644 --- a/src/Nethermind/Nethermind.Core.Test/Json/NullableUInt256ConverterTests.cs +++ b/src/Nethermind/Nethermind.Core.Test/Json/NullableUInt256ConverterTests.cs @@ -13,8 +13,8 @@ namespace Nethermind.Core.Test.Json [TestFixture] public class NullableUInt256ConverterTests : ConverterTestBase { - static NullableUInt256Converter converter = new(); - static JsonSerializerOptions options = new JsonSerializerOptions { Converters = { converter } }; + static readonly NullableUInt256Converter converter = new(); + static readonly JsonSerializerOptions options = new JsonSerializerOptions { Converters = { converter } }; [TestCase(NumberConversion.Hex)] [TestCase(NumberConversion.Decimal)] diff --git a/src/Nethermind/Nethermind.Core.Test/Json/NullableUlongConverterTests.cs b/src/Nethermind/Nethermind.Core.Test/Json/NullableUlongConverterTests.cs index 373cd9ef080..3199608c669 100644 --- a/src/Nethermind/Nethermind.Core.Test/Json/NullableUlongConverterTests.cs +++ b/src/Nethermind/Nethermind.Core.Test/Json/NullableUlongConverterTests.cs @@ -13,8 +13,8 @@ namespace Nethermind.Core.Test.Json [TestFixture] public class NullableULongConverterTests : ConverterTestBase { - static NullableULongConverter converter = new(); - static JsonSerializerOptions options = new JsonSerializerOptions { Converters = { converter } }; + static readonly NullableULongConverter converter = new(); + static readonly JsonSerializerOptions options = new JsonSerializerOptions { Converters = { converter } }; [TestCase(NumberConversion.Hex)] [TestCase(NumberConversion.Decimal)] diff --git a/src/Nethermind/Nethermind.Core.Test/Json/UInt256ConverterTests.cs b/src/Nethermind/Nethermind.Core.Test/Json/UInt256ConverterTests.cs index c5686aeec28..c0f771b8091 100644 --- a/src/Nethermind/Nethermind.Core.Test/Json/UInt256ConverterTests.cs +++ b/src/Nethermind/Nethermind.Core.Test/Json/UInt256ConverterTests.cs @@ -15,8 +15,8 @@ namespace Nethermind.Core.Test.Json [TestFixture] public class UInt256ConverterTests : ConverterTestBase { - static UInt256Converter converter = new(); - static JsonSerializerOptions options = new JsonSerializerOptions { Converters = { converter } }; + static readonly UInt256Converter converter = new(); + static readonly JsonSerializerOptions options = new JsonSerializerOptions { Converters = { converter } }; [TestCase(NumberConversion.Hex)] [TestCase(NumberConversion.Decimal)] diff --git a/src/Nethermind/Nethermind.Core.Test/TestMemDb.cs b/src/Nethermind/Nethermind.Core.Test/TestMemDb.cs index 89a1ce1bc6a..bd7795430d6 100644 --- a/src/Nethermind/Nethermind.Core.Test/TestMemDb.cs +++ b/src/Nethermind/Nethermind.Core.Test/TestMemDb.cs @@ -16,10 +16,10 @@ namespace Nethermind.Core.Test; /// public class TestMemDb : MemDb, ITunableDb { - private List<(byte[], ReadFlags)> _readKeys = new(); - private List<((byte[], byte[]?), WriteFlags)> _writes = new(); - private List _removedKeys = new(); - private List _tuneTypes = new(); + private readonly List<(byte[], ReadFlags)> _readKeys = new(); + private readonly List<((byte[], byte[]?), WriteFlags)> _writes = new(); + private readonly List _removedKeys = new(); + private readonly List _tuneTypes = new(); public Func? ReadFunc { get; set; } public Func? WriteFunc { get; set; } diff --git a/src/Nethermind/Nethermind.Core/Buffers/CappedArray.cs b/src/Nethermind/Nethermind.Core/Buffers/CappedArray.cs index ae665b44c9a..c6e4ba1ab39 100644 --- a/src/Nethermind/Nethermind.Core/Buffers/CappedArray.cs +++ b/src/Nethermind/Nethermind.Core/Buffers/CappedArray.cs @@ -15,7 +15,7 @@ namespace Nethermind.Core.Buffers; /// public struct CappedArray { - private T[]? _array = null; + private readonly T[]? _array = null; private int _length = 0; public CappedArray(T[]? array, int length) diff --git a/src/Nethermind/Nethermind.Core/Collections/ClampedReadOnlyList.cs b/src/Nethermind/Nethermind.Core/Collections/ClampedReadOnlyList.cs index d81dbbf1a2c..4dfe379329b 100644 --- a/src/Nethermind/Nethermind.Core/Collections/ClampedReadOnlyList.cs +++ b/src/Nethermind/Nethermind.Core/Collections/ClampedReadOnlyList.cs @@ -10,7 +10,7 @@ namespace Nethermind.Core.Test.Collections; public class ClampedReadOnlyList : IReadOnlyList { - private IReadOnlyList _baseImplementation; + private readonly IReadOnlyList _baseImplementation; public ClampedReadOnlyList(IReadOnlyList toClampList, int maxSize) { diff --git a/src/Nethermind/Nethermind.Core/Collections/CompactStack.cs b/src/Nethermind/Nethermind.Core/Collections/CompactStack.cs index bcade1d9fde..84a9778c78e 100644 --- a/src/Nethermind/Nethermind.Core/Collections/CompactStack.cs +++ b/src/Nethermind/Nethermind.Core/Collections/CompactStack.cs @@ -48,7 +48,7 @@ public bool Return(Node obj) } } - private ObjectPool _nodePool; + private readonly ObjectPool _nodePool; private Node? _head = null; public CompactStack(ObjectPool? nodePool = null) diff --git a/src/Nethermind/Nethermind.Core/Crypto/KeccakHash.cs b/src/Nethermind/Nethermind.Core/Crypto/KeccakHash.cs index 3ca0d2f0dfe..f2609cc4508 100644 --- a/src/Nethermind/Nethermind.Core/Crypto/KeccakHash.cs +++ b/src/Nethermind/Nethermind.Core/Crypto/KeccakHash.cs @@ -643,7 +643,7 @@ public void ResetTo(KeccakHash original) private static class Pool { private const int MaxPooled = 24; - private static ConcurrentQueue s_remainderCache = new(); + private static readonly ConcurrentQueue s_remainderCache = new(); public static byte[] RentRemainder() => s_remainderCache.TryDequeue(out byte[]? remainder) ? remainder : new byte[STATE_SIZE]; public static void ReturnRemainder(ref byte[] remainder) { @@ -658,7 +658,7 @@ public static void ReturnRemainder(ref byte[] remainder) remainder = Array.Empty(); } - private static ConcurrentQueue s_stateCache = new(); + private static readonly ConcurrentQueue s_stateCache = new(); public static ulong[] RentState() => s_stateCache.TryDequeue(out ulong[]? state) ? state : new ulong[STATE_SIZE / sizeof(ulong)]; public static void ReturnState(ref ulong[] state) { diff --git a/src/Nethermind/Nethermind.Core/Crypto/PublicKey.cs b/src/Nethermind/Nethermind.Core/Crypto/PublicKey.cs index ba7f359825f..ad29ff3b5b5 100644 --- a/src/Nethermind/Nethermind.Core/Crypto/PublicKey.cs +++ b/src/Nethermind/Nethermind.Core/Crypto/PublicKey.cs @@ -20,7 +20,7 @@ public class PublicKey : IEquatable private Address? _address; private byte[]? _prefixedBytes; - private int _hashCode; + private readonly int _hashCode; public PublicKey(string? hexString) : this(Core.Extensions.Bytes.FromHexString(hexString ?? throw new ArgumentNullException(nameof(hexString)))) diff --git a/src/Nethermind/Nethermind.Core/MemorySizes.cs b/src/Nethermind/Nethermind.Core/MemorySizes.cs index 5f10e1dcaae..20f8494aa4c 100644 --- a/src/Nethermind/Nethermind.Core/MemorySizes.cs +++ b/src/Nethermind/Nethermind.Core/MemorySizes.cs @@ -27,7 +27,7 @@ public static long Align(long unalignedSize) // public const int LargeObjectOverhead = 32; // just guessing, 20 on 32bit public const int ArrayOverhead = 24; - private static BitArray _isPrime = ESieve(1024 * 1024); // 1MB in memory + private static readonly BitArray _isPrime = ESieve(1024 * 1024); // 1MB in memory public static int FindNextPrime(int number) { diff --git a/src/Nethermind/Nethermind.Core/ThisNodeInfo.cs b/src/Nethermind/Nethermind.Core/ThisNodeInfo.cs index 2e8ba4f0b5e..d103715e51c 100644 --- a/src/Nethermind/Nethermind.Core/ThisNodeInfo.cs +++ b/src/Nethermind/Nethermind.Core/ThisNodeInfo.cs @@ -9,7 +9,7 @@ namespace Nethermind.Core { public static class ThisNodeInfo { - private static ConcurrentDictionary _nodeInfoItems = new(); + private static readonly ConcurrentDictionary _nodeInfoItems = new(); public static void AddInfo(string infoDescription, string value) { diff --git a/src/Nethermind/Nethermind.Crypto/EciesCipher.cs b/src/Nethermind/Nethermind.Crypto/EciesCipher.cs index cf756db5ef3..9dadad24833 100644 --- a/src/Nethermind/Nethermind.Crypto/EciesCipher.cs +++ b/src/Nethermind/Nethermind.Crypto/EciesCipher.cs @@ -20,7 +20,7 @@ public class EciesCipher : IEciesCipher { private const int KeySize = 128; private readonly ICryptoRandom _cryptoRandom; - private PrivateKeyGenerator _keyGenerator; + private readonly PrivateKeyGenerator _keyGenerator; public EciesCipher(ICryptoRandom cryptoRandom) { @@ -68,7 +68,7 @@ public byte[] Encrypt(PublicKey recipientPublicKey, byte[] plainText, byte[] mac return outputArray; } - private OptimizedKdf _optimizedKdf = new(); + private readonly OptimizedKdf _optimizedKdf = new(); private byte[] Decrypt(PublicKey ephemeralPublicKey, PrivateKey privateKey, byte[] iv, byte[] ciphertextBody, byte[] macData) { @@ -76,7 +76,7 @@ private byte[] Decrypt(PublicKey ephemeralPublicKey, PrivateKey privateKey, byte return iesEngine.ProcessBlock(ciphertextBody, 0, ciphertextBody.Length, macData); } - private static IesParameters _iesParameters = new IesWithCipherParameters(Array.Empty(), Array.Empty(), KeySize, KeySize); + private static readonly IesParameters _iesParameters = new IesWithCipherParameters(Array.Empty(), Array.Empty(), KeySize, KeySize); private IIesEngine MakeIesEngine(bool isEncrypt, PublicKey publicKey, PrivateKey privateKey, byte[] iv) { diff --git a/src/Nethermind/Nethermind.Crypto/EthereumIesEngine.cs b/src/Nethermind/Nethermind.Crypto/EthereumIesEngine.cs index 1bfb9c08cac..5520deab0fc 100644 --- a/src/Nethermind/Nethermind.Crypto/EthereumIesEngine.cs +++ b/src/Nethermind/Nethermind.Crypto/EthereumIesEngine.cs @@ -21,9 +21,9 @@ public class EthereumIesEngine : IIesEngine { private bool _forEncryption; private byte[] _kdfKey; - private IDigest _hash; - private IMac _mac; - private BufferedBlockCipher _cipher; + private readonly IDigest _hash; + private readonly IMac _mac; + private readonly BufferedBlockCipher _cipher; private IesParameters _iesParameters; private byte[] _iv; diff --git a/src/Nethermind/Nethermind.Db.Rocks/ColumnDb.cs b/src/Nethermind/Nethermind.Db.Rocks/ColumnDb.cs index 2d144068455..63c44fce165 100644 --- a/src/Nethermind/Nethermind.Db.Rocks/ColumnDb.cs +++ b/src/Nethermind/Nethermind.Db.Rocks/ColumnDb.cs @@ -17,7 +17,7 @@ public class ColumnDb : IDb internal readonly DbOnTheRocks _mainDb; internal readonly ColumnFamilyHandle _columnFamily; - private DbOnTheRocks.ManagedIterators _readaheadIterators = new(); + private readonly DbOnTheRocks.ManagedIterators _readaheadIterators = new(); public ColumnDb(RocksDb rocksDb, DbOnTheRocks mainDb, string name) { diff --git a/src/Nethermind/Nethermind.Db.Rocks/ColumnsDb.cs b/src/Nethermind/Nethermind.Db.Rocks/ColumnsDb.cs index 3a9dd620db8..f73091856b6 100644 --- a/src/Nethermind/Nethermind.Db.Rocks/ColumnsDb.cs +++ b/src/Nethermind/Nethermind.Db.Rocks/ColumnsDb.cs @@ -72,7 +72,7 @@ protected override void ApplyOptions(IDictionary options) private class RocksColumnsWriteBatch : IColumnsWriteBatch { internal RocksDbWriteBatch _writeBatch; - private ColumnsDb _columnsDb; + private readonly ColumnsDb _columnsDb; public RocksColumnsWriteBatch(ColumnsDb columnsDb) { diff --git a/src/Nethermind/Nethermind.Db.Rocks/DbOnTheRocks.cs b/src/Nethermind/Nethermind.Db.Rocks/DbOnTheRocks.cs index 1dcc79ff0b6..df0e1e4603a 100644 --- a/src/Nethermind/Nethermind.Db.Rocks/DbOnTheRocks.cs +++ b/src/Nethermind/Nethermind.Db.Rocks/DbOnTheRocks.cs @@ -66,9 +66,9 @@ public class DbOnTheRocks : IDb, ITunableDb private string CorruptMarkerPath => Path.Join(_fullPath, "corrupt.marker"); - private List _metricsUpdaters = new(); + private readonly List _metricsUpdaters = new(); - private ManagedIterators _readaheadIterators = new(); + private readonly ManagedIterators _readaheadIterators = new(); internal long _allocatedSpan = 0; diff --git a/src/Nethermind/Nethermind.Db.Rocks/RocksDbFactory.cs b/src/Nethermind/Nethermind.Db.Rocks/RocksDbFactory.cs index a5639382c77..e346e0ea418 100644 --- a/src/Nethermind/Nethermind.Db.Rocks/RocksDbFactory.cs +++ b/src/Nethermind/Nethermind.Db.Rocks/RocksDbFactory.cs @@ -15,7 +15,7 @@ public class RocksDbFactory : IRocksDbFactory private readonly string _basePath; - private IntPtr _sharedCache; + private readonly IntPtr _sharedCache; public RocksDbFactory(IDbConfig dbConfig, ILogManager logManager, string basePath) { diff --git a/src/Nethermind/Nethermind.Db.Test/DbOnTheRocksTests.cs b/src/Nethermind/Nethermind.Db.Test/DbOnTheRocksTests.cs index a72b594674b..5e70338d5e1 100644 --- a/src/Nethermind/Nethermind.Db.Test/DbOnTheRocksTests.cs +++ b/src/Nethermind/Nethermind.Db.Test/DbOnTheRocksTests.cs @@ -204,7 +204,7 @@ public class DbOnTheRocksDbTests private IDb _db = null!; IDisposable? _dbDisposable = null!; - private bool _useColumnDb = false; + private readonly bool _useColumnDb = false; public DbOnTheRocksDbTests(bool useColumnDb) { diff --git a/src/Nethermind/Nethermind.Db.Test/MemDbTests.cs b/src/Nethermind/Nethermind.Db.Test/MemDbTests.cs index 21f5e36665a..ba3ef5fc7ef 100644 --- a/src/Nethermind/Nethermind.Db.Test/MemDbTests.cs +++ b/src/Nethermind/Nethermind.Db.Test/MemDbTests.cs @@ -23,7 +23,7 @@ public void Simple_set_get_is_fine() retrievedBytes.Should().BeEquivalentTo(bytes); } - private byte[] _sampleValue = { 1, 2, 3 }; + private readonly byte[] _sampleValue = { 1, 2, 3 }; [Test] public void Can_create_with_delays() diff --git a/src/Nethermind/Nethermind.Db/FullPruning/FullPruningDb.cs b/src/Nethermind/Nethermind.Db/FullPruning/FullPruningDb.cs index 9175ba9b9e9..e610a94e49f 100755 --- a/src/Nethermind/Nethermind.Db/FullPruning/FullPruningDb.cs +++ b/src/Nethermind/Nethermind.Db/FullPruning/FullPruningDb.cs @@ -224,7 +224,7 @@ private class PruningContext : IPruningContext private readonly FullPruningDb _db; private long _counter = 0; - private ConcurrentQueue _batches = new(); + private readonly ConcurrentQueue _batches = new(); public PruningContext(FullPruningDb db, IDb cloningDb, bool duplicateReads) { diff --git a/src/Nethermind/Nethermind.Db/InMemoryColumnBatch.cs b/src/Nethermind/Nethermind.Db/InMemoryColumnBatch.cs index 5c1c78b7128..9cff6e2fa95 100644 --- a/src/Nethermind/Nethermind.Db/InMemoryColumnBatch.cs +++ b/src/Nethermind/Nethermind.Db/InMemoryColumnBatch.cs @@ -8,7 +8,7 @@ namespace Nethermind.Db { public class InMemoryColumnWriteBatch : IColumnsWriteBatch { - private IList _underlyingBatch = new List(); + private readonly IList _underlyingBatch = new List(); private readonly IColumnsDb _columnsDb; public InMemoryColumnWriteBatch(IColumnsDb columnsDb) diff --git a/src/Nethermind/Nethermind.Evm.Test/Eip6780Tests.cs b/src/Nethermind/Nethermind.Evm.Test/Eip6780Tests.cs index 55281021029..2384a375c7a 100644 --- a/src/Nethermind/Nethermind.Evm.Test/Eip6780Tests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/Eip6780Tests.cs @@ -39,8 +39,8 @@ public class Eip6780Tests : VirtualMachineTestsBase private byte[] _selfDestructCode; private Address _contractAddress; private byte[] _initCode; - private long _gasLimit = 1000000; - private EthereumEcdsa _ecdsa = new(1, LimboLogs.Instance); + private readonly long _gasLimit = 1000000; + private readonly EthereumEcdsa _ecdsa = new(1, LimboLogs.Instance); [SetUp] public override void Setup() diff --git a/src/Nethermind/Nethermind.Evm.Test/InvalidOpcodeTests.cs b/src/Nethermind/Nethermind.Evm.Test/InvalidOpcodeTests.cs index 40e91fe7ec6..c1592e11c84 100644 --- a/src/Nethermind/Nethermind.Evm.Test/InvalidOpcodeTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/InvalidOpcodeTests.cs @@ -112,7 +112,7 @@ public class InvalidOpcodeTests : VirtualMachineTestsBase } ).ToArray(); - private Dictionary _validOpcodes + private readonly Dictionary _validOpcodes = new() { {(ForkActivation)0, FrontierInstructions}, diff --git a/src/Nethermind/Nethermind.Evm/CodeAnalysis/CodeInfo.cs b/src/Nethermind/Nethermind.Evm/CodeAnalysis/CodeInfo.cs index d8cec2c0adb..ec8df2a5870 100644 --- a/src/Nethermind/Nethermind.Evm/CodeAnalysis/CodeInfo.cs +++ b/src/Nethermind/Nethermind.Evm/CodeAnalysis/CodeInfo.cs @@ -11,7 +11,7 @@ public class CodeInfo private const int SampledCodeLength = 10_001; private const int PercentageOfPush1 = 40; private const int NumberOfSamples = 100; - private static Random _rand = new(); + private static readonly Random _rand = new(); public byte[] MachineCode { get; set; } public IPrecompile? Precompile { get; set; } diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Blake2FPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Blake2FPrecompile.cs index 3688f39f8c2..14534399d3f 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Blake2FPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Blake2FPrecompile.cs @@ -13,7 +13,7 @@ public class Blake2FPrecompile : IPrecompile { private const int RequiredInputLength = 213; - private Blake2Compression _blake = new(); + private readonly Blake2Compression _blake = new(); public static readonly Blake2FPrecompile Instance = new Blake2FPrecompile(); diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/Discount.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/Discount.cs index f5fe0a53f31..a84d69d1d06 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/Discount.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/Discount.cs @@ -20,7 +20,7 @@ public static int For(int k) }; } - private static Dictionary _discountTable = new() + private static readonly Dictionary _discountTable = new() { { 1, 1200 }, { 2, 888 }, diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Sha256Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Sha256Precompile.cs index 9946514d023..4aa42639104 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Sha256Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Sha256Precompile.cs @@ -11,7 +11,7 @@ namespace Nethermind.Evm.Precompiles { public class Sha256Precompile : IPrecompile { - private static ThreadLocal _sha256 = new(); + private static readonly ThreadLocal _sha256 = new(); public static readonly Sha256Precompile Instance = new Sha256Precompile(); diff --git a/src/Nethermind/Nethermind.Evm/Tracing/GethStyle/GethLikeBlockFileTracer.cs b/src/Nethermind/Nethermind.Evm/Tracing/GethStyle/GethLikeBlockFileTracer.cs index e70a0c5b25b..79c35a0f7d2 100644 --- a/src/Nethermind/Nethermind.Evm/Tracing/GethStyle/GethLikeBlockFileTracer.cs +++ b/src/Nethermind/Nethermind.Evm/Tracing/GethStyle/GethLikeBlockFileTracer.cs @@ -21,7 +21,7 @@ public class GethLikeBlockFileTracer : BlockTracerBase _fileNames = new(); - private IFileSystem _fileSystem; + private readonly IFileSystem _fileSystem; private Utf8JsonWriter _jsonWriter; private readonly GethTraceOptions _options; private readonly JsonSerializerOptions _serializerOptions = new(); diff --git a/src/Nethermind/Nethermind.Evm/Tracing/ParityStyle/ParityAccountStateChangeJsonConverter.cs b/src/Nethermind/Nethermind.Evm/Tracing/ParityStyle/ParityAccountStateChangeJsonConverter.cs index d82c1540a79..af98fb2662b 100644 --- a/src/Nethermind/Nethermind.Evm/Tracing/ParityStyle/ParityAccountStateChangeJsonConverter.cs +++ b/src/Nethermind/Nethermind.Evm/Tracing/ParityStyle/ParityAccountStateChangeJsonConverter.cs @@ -14,7 +14,7 @@ namespace Nethermind.Evm.Tracing.ParityStyle; public class ParityAccountStateChangeJsonConverter : JsonConverter { - private Bytes32Converter _32BytesConverter = new(); + private readonly Bytes32Converter _32BytesConverter = new(); public override ParityAccountStateChange Read( ref Utf8JsonReader reader, diff --git a/src/Nethermind/Nethermind.Evm/VirtualMachine.cs b/src/Nethermind/Nethermind.Evm/VirtualMachine.cs index a9107e307fe..c168656d7ba 100644 --- a/src/Nethermind/Nethermind.Evm/VirtualMachine.cs +++ b/src/Nethermind/Nethermind.Evm/VirtualMachine.cs @@ -129,9 +129,9 @@ public interface IIsTracing { } internal sealed class VirtualMachine : IVirtualMachine where TLogger : struct, IIsTracing { - private UInt256 P255Int = (UInt256)System.Numerics.BigInteger.Pow(2, 255); + private readonly UInt256 P255Int = (UInt256)System.Numerics.BigInteger.Pow(2, 255); private UInt256 P255 => P255Int; - private UInt256 BigInt256 = 256; + private readonly UInt256 BigInt256 = 256; public UInt256 BigInt32 = 32; internal byte[] BytesZero = { 0 }; diff --git a/src/Nethermind/Nethermind.Facade/Filters/FilterStore.cs b/src/Nethermind/Nethermind.Facade/Filters/FilterStore.cs index d434245ac30..b6af25caa12 100644 --- a/src/Nethermind/Nethermind.Facade/Filters/FilterStore.cs +++ b/src/Nethermind/Nethermind.Facade/Filters/FilterStore.cs @@ -18,7 +18,7 @@ namespace Nethermind.Blockchain.Filters public class FilterStore : IFilterStore { private int _currentFilterId = -1; - private object _locker = new object(); + private readonly object _locker = new object(); private readonly ConcurrentDictionary _filters = new(); diff --git a/src/Nethermind/Nethermind.Hive/HiveRunner.cs b/src/Nethermind/Nethermind.Hive/HiveRunner.cs index eeb6c4b6c73..ce5006938e7 100644 --- a/src/Nethermind/Nethermind.Hive/HiveRunner.cs +++ b/src/Nethermind/Nethermind.Hive/HiveRunner.cs @@ -27,7 +27,7 @@ public class HiveRunner private readonly IConfigProvider _configurationProvider; private readonly IFileSystem _fileSystem; private readonly IBlockValidator _blockValidator; - private SemaphoreSlim _resetEvent; + private readonly SemaphoreSlim _resetEvent; private bool BlockSuggested; public HiveRunner( diff --git a/src/Nethermind/Nethermind.Init/MemoryHintMan.cs b/src/Nethermind/Nethermind.Init/MemoryHintMan.cs index c5b47d218ba..62927f0d803 100644 --- a/src/Nethermind/Nethermind.Init/MemoryHintMan.cs +++ b/src/Nethermind/Nethermind.Init/MemoryHintMan.cs @@ -22,8 +22,8 @@ namespace Nethermind.Init /// public class MemoryHintMan { - private ILogger _logger; - private MallocHelper _mallocHelper; + private readonly ILogger _logger; + private readonly MallocHelper _mallocHelper; public MemoryHintMan(ILogManager logManager, MallocHelper? mallocHelper = null) { diff --git a/src/Nethermind/Nethermind.Init/Steps/ApplyMemoryHint.cs b/src/Nethermind/Nethermind.Init/Steps/ApplyMemoryHint.cs index 64bb227dcd0..d9a279eb78f 100644 --- a/src/Nethermind/Nethermind.Init/Steps/ApplyMemoryHint.cs +++ b/src/Nethermind/Nethermind.Init/Steps/ApplyMemoryHint.cs @@ -16,11 +16,11 @@ namespace Nethermind.Init.Steps public sealed class ApplyMemoryHint : IStep { private readonly INethermindApi _api; - private IInitConfig _initConfig; - private IDbConfig _dbConfig; - private INetworkConfig _networkConfig; - private ISyncConfig _syncConfig; - private ITxPoolConfig _txPoolConfig; + private readonly IInitConfig _initConfig; + private readonly IDbConfig _dbConfig; + private readonly INetworkConfig _networkConfig; + private readonly ISyncConfig _syncConfig; + private readonly ITxPoolConfig _txPoolConfig; public ApplyMemoryHint(INethermindApi api) { diff --git a/src/Nethermind/Nethermind.Init/Steps/EthereumStepsManager.cs b/src/Nethermind/Nethermind.Init/Steps/EthereumStepsManager.cs index c713f5b0fbb..6baa25ed061 100644 --- a/src/Nethermind/Nethermind.Init/Steps/EthereumStepsManager.cs +++ b/src/Nethermind/Nethermind.Init/Steps/EthereumStepsManager.cs @@ -17,9 +17,9 @@ namespace Nethermind.Init.Steps { public class EthereumStepsManager { - private ILogger _logger; + private readonly ILogger _logger; - private AutoResetEvent _autoResetEvent = new AutoResetEvent(true); + private readonly AutoResetEvent _autoResetEvent = new AutoResetEvent(true); private readonly INethermindApi _api; private readonly List _allSteps; private readonly Dictionary _allStepsByBaseType; diff --git a/src/Nethermind/Nethermind.Init/Steps/InitializeBlockProducer.cs b/src/Nethermind/Nethermind.Init/Steps/InitializeBlockProducer.cs index 0fa117e656e..fe8d01a22ed 100644 --- a/src/Nethermind/Nethermind.Init/Steps/InitializeBlockProducer.cs +++ b/src/Nethermind/Nethermind.Init/Steps/InitializeBlockProducer.cs @@ -15,7 +15,7 @@ namespace Nethermind.Init.Steps [RunnerStepDependencies(typeof(StartBlockProcessor), typeof(SetupKeyStore), typeof(InitializeNetwork), typeof(ReviewBlockTree))] public class InitializeBlockProducer : IStep { - private IApiWithBlockchain _api; + private readonly IApiWithBlockchain _api; public InitializeBlockProducer(INethermindApi api) { diff --git a/src/Nethermind/Nethermind.Init/Steps/ReviewBlockTree.cs b/src/Nethermind/Nethermind.Init/Steps/ReviewBlockTree.cs index b9dd8fb4797..2a200190434 100644 --- a/src/Nethermind/Nethermind.Init/Steps/ReviewBlockTree.cs +++ b/src/Nethermind/Nethermind.Init/Steps/ReviewBlockTree.cs @@ -14,7 +14,7 @@ namespace Nethermind.Init.Steps public class ReviewBlockTree : IStep { private readonly IApiWithBlockchain _api; - private ILogger _logger; + private readonly ILogger _logger; public ReviewBlockTree(INethermindApi api) { diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/ConsensusHelperTests.cs b/src/Nethermind/Nethermind.JsonRpc.Test/ConsensusHelperTests.cs index cc9a940ec4f..ede281b37ad 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/ConsensusHelperTests.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/ConsensusHelperTests.cs @@ -27,7 +27,7 @@ namespace Nethermind.JsonRpc.Test [Explicit] public partial class ConsensusHelperTests { - private static Func, EquivalencyAssertionOptions> ReceiptOptions = + private static readonly Func, EquivalencyAssertionOptions> ReceiptOptions = options => options.WithStrictOrdering() .IncludingNestedObjects() .Including(r => r.TransactionHash) diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/JsonRpcLocalStats.cs b/src/Nethermind/Nethermind.JsonRpc.Test/JsonRpcLocalStats.cs index e735a5fbe51..be18b1fa3a2 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/JsonRpcLocalStats.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/JsonRpcLocalStats.cs @@ -16,11 +16,11 @@ public class JsonRpcLocalStatsTests { private TestLogger _testLogger = null!; - private JsonRpcConfig _config = new(); + private readonly JsonRpcConfig _config = new(); private ManualTimestamper _manualTimestamper = null!; - private DateTime _startTime = DateTime.MinValue; + private readonly DateTime _startTime = DateTime.MinValue; private OneLoggerLogManager _logManager = null!; [SetUp] diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/DebugModuleTests.cs b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/DebugModuleTests.cs index 217a9f9b563..dabb9c414e0 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/DebugModuleTests.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/DebugModuleTests.cs @@ -28,8 +28,8 @@ namespace Nethermind.JsonRpc.Test.Modules; [TestFixture] public class DebugModuleTests { - private IJsonRpcConfig jsonRpcConfig = new JsonRpcConfig(); - private IDebugBridge debugBridge = Substitute.For(); + private readonly IJsonRpcConfig jsonRpcConfig = new JsonRpcConfig(); + private readonly IDebugBridge debugBridge = Substitute.For(); [Test] public async Task Get_from_db() diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/DebugModuleFactory.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/DebugModuleFactory.cs index 7b36aa1930b..e9664e06f0d 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/DebugModuleFactory.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/DebugModule/DebugModuleFactory.cs @@ -40,7 +40,7 @@ public class DebugModuleFactory : ModuleFactoryBase private readonly IReadOnlyBlockTree _blockTree; private readonly ISyncModeSelector _syncModeSelector; private readonly IFileSystem _fileSystem; - private ILogger _logger; + private readonly ILogger _logger; public DebugModuleFactory( IWorldStateManager worldStateManager, diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/Net/NetRpcModule.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/Net/NetRpcModule.cs index 89a8d4875ca..a6a0f354289 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/Net/NetRpcModule.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/Net/NetRpcModule.cs @@ -10,7 +10,7 @@ namespace Nethermind.JsonRpc.Modules.Net public class NetRpcModule : INetRpcModule { private readonly INetBridge _netBridge; - private string _netVersionString; + private readonly string _netVersionString; public NetRpcModule(ILogManager logManager, INetBridge netBridge) { diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/NullModuleProvider.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/NullModuleProvider.cs index 8ebedcb9f9f..91e023557d9 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/NullModuleProvider.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/NullModuleProvider.cs @@ -14,7 +14,7 @@ namespace Nethermind.JsonRpc.Modules public class NullModuleProvider : IRpcModuleProvider { public static NullModuleProvider Instance = new(); - private static Task Null = Task.FromResult(default(IRpcModule)); + private static readonly Task Null = Task.FromResult(default(IRpcModule)); private NullModuleProvider() { diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/Personal/PersonalRpcModule.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/Personal/PersonalRpcModule.cs index e0a09e6ecec..1070270a9d5 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/Personal/PersonalRpcModule.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/Personal/PersonalRpcModule.cs @@ -15,7 +15,7 @@ namespace Nethermind.JsonRpc.Modules.Personal { public class PersonalRpcModule : IPersonalRpcModule { - private Encoding _messageEncoding = Encoding.UTF8; + private readonly Encoding _messageEncoding = Encoding.UTF8; private readonly IEcdsa _ecdsa; private readonly IWallet _wallet; private readonly IKeyStore _keyStore; diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/Trace/ParityTxTraceFromReplay.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/Trace/ParityTxTraceFromReplay.cs index 65267360b6c..a3d258984de 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/Trace/ParityTxTraceFromReplay.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/Trace/ParityTxTraceFromReplay.cs @@ -126,7 +126,7 @@ public override void Write( public class ParityTxTraceFromReplayJsonConverter : JsonConverter { - ParityTraceActionFromReplayJsonConverter _actionConverter = new(); + readonly ParityTraceActionFromReplayJsonConverter _actionConverter = new(); public override ParityTxTraceFromReplay Read( ref Utf8JsonReader reader, Type typeToConvert, diff --git a/src/Nethermind/Nethermind.JsonRpc/Recorder.cs b/src/Nethermind/Nethermind.JsonRpc/Recorder.cs index 7374551f4cd..b26fee1579f 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Recorder.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Recorder.cs @@ -10,14 +10,14 @@ namespace Nethermind.JsonRpc { internal class Recorder { - private string _recorderBaseFilePath; + private readonly string _recorderBaseFilePath; private readonly IFileSystem _fileSystem; private readonly ILogger _logger; private int _recorderFileCounter; private string _currentRecorderFilePath; private int _currentRecorderFileLength; private bool _isEnabled = true; - private object _recorderSync = new(); + private readonly object _recorderSync = new(); public Recorder(string basePath, IFileSystem fileSystem, ILogger logger) { diff --git a/src/Nethermind/Nethermind.KeyStore.Test/FilePasswordProviderTests.cs b/src/Nethermind/Nethermind.KeyStore.Test/FilePasswordProviderTests.cs index 47a50155d65..917b147286e 100644 --- a/src/Nethermind/Nethermind.KeyStore.Test/FilePasswordProviderTests.cs +++ b/src/Nethermind/Nethermind.KeyStore.Test/FilePasswordProviderTests.cs @@ -11,7 +11,7 @@ namespace Nethermind.KeyStore.Test { public class FilePasswordProviderTests { - private static List<(string Name, string Content)> _files = new List<(string Name, string Content)>() + private static readonly List<(string Name, string Content)> _files = new List<(string Name, string Content)>() { ("TestingPasswordProviderFileF1", "PF1"), ("TestingPasswordProviderFileF2", "P F2"), diff --git a/src/Nethermind/Nethermind.KeyStore.Test/KeyStorePasswordProviderTests.cs b/src/Nethermind/Nethermind.KeyStore.Test/KeyStorePasswordProviderTests.cs index 0f57ad1111e..4d664ac4a35 100644 --- a/src/Nethermind/Nethermind.KeyStore.Test/KeyStorePasswordProviderTests.cs +++ b/src/Nethermind/Nethermind.KeyStore.Test/KeyStorePasswordProviderTests.cs @@ -18,7 +18,7 @@ namespace Nethermind.KeyStore.Test { public class KeyStorePasswordProviderTests { - private static List<(string Name, string Content)> _files = new List<(string Name, string Content)>() + private static readonly List<(string Name, string Content)> _files = new List<(string Name, string Content)>() { ("TestingPasswordProviderFileF1", "PF1"), ("TestingPasswordProviderFileF2", "P F2"), diff --git a/src/Nethermind/Nethermind.Logging.NLog/NLogManager.cs b/src/Nethermind/Nethermind.Logging.NLog/NLogManager.cs index 20ad3867675..0b25b336fc0 100644 --- a/src/Nethermind/Nethermind.Logging.NLog/NLogManager.cs +++ b/src/Nethermind/Nethermind.Logging.NLog/NLogManager.cs @@ -57,8 +57,8 @@ private static string SetupLogDirectory(string logDirectory) return logDirectory; } - private ConcurrentDictionary _loggers = new(); - private EventHandler _logManagerOnConfigurationChanged; + private readonly ConcurrentDictionary _loggers = new(); + private readonly EventHandler _logManagerOnConfigurationChanged; private NLogLogger BuildLogger(Type type) => new(type); diff --git a/src/Nethermind/Nethermind.Logging/ConsoleAsyncLogger.cs b/src/Nethermind/Nethermind.Logging/ConsoleAsyncLogger.cs index ac6226ecbc1..f2fb30bf4a8 100644 --- a/src/Nethermind/Nethermind.Logging/ConsoleAsyncLogger.cs +++ b/src/Nethermind/Nethermind.Logging/ConsoleAsyncLogger.cs @@ -22,7 +22,7 @@ public void Flush() _task.Wait(); } - private Task _task; + private readonly Task _task; public ConsoleAsyncLogger(LogLevel logLevel, string prefix = null) { diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/InvalidChainTracker/InvalidHeaderSealInterceptorTest.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/InvalidChainTracker/InvalidHeaderSealInterceptorTest.cs index a7fda193665..97663767f3f 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/InvalidChainTracker/InvalidHeaderSealInterceptorTest.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/InvalidChainTracker/InvalidHeaderSealInterceptorTest.cs @@ -16,9 +16,9 @@ public class InvalidHeaderSealInterceptorTest { private class Context { - private BlockHeader _blockHeader = Build.A.BlockHeader.TestObject; - private ISealValidator _baseValidator = Substitute.For(); - private IInvalidChainTracker _invalidChainTracker = Substitute.For(); + private readonly BlockHeader _blockHeader = Build.A.BlockHeader.TestObject; + private readonly ISealValidator _baseValidator = Substitute.For(); + private readonly IInvalidChainTracker _invalidChainTracker = Substitute.For(); public Context OnValidateSeal() { diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/MergeSealValidatorTests.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/MergeSealValidatorTests.cs index 234b1159252..4053c503d7b 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/MergeSealValidatorTests.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/MergeSealValidatorTests.cs @@ -12,9 +12,9 @@ public class MergeSealValidatorTests { private class Context { - private BlockHeader _blockHeader = Build.A.BlockHeader.TestObject; - private IPoSSwitcher _poSSwitcher = Substitute.For(); - private ISealValidator _baseValidator = Substitute.For(); + private readonly BlockHeader _blockHeader = Build.A.BlockHeader.TestObject; + private readonly IPoSSwitcher _poSSwitcher = Substitute.For(); + private readonly ISealValidator _baseValidator = Substitute.For(); public Context WhenHeaderIsTerminalBlock() { diff --git a/src/Nethermind/Nethermind.Merge.Plugin/InvalidChainTracker/InvalidBlockInterceptor.cs b/src/Nethermind/Nethermind.Merge.Plugin/InvalidChainTracker/InvalidBlockInterceptor.cs index 71034535de8..e72a4ad4bd6 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/InvalidChainTracker/InvalidBlockInterceptor.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/InvalidChainTracker/InvalidBlockInterceptor.cs @@ -9,9 +9,9 @@ namespace Nethermind.Merge.Plugin.InvalidChainTracker; public class InvalidBlockInterceptor : IBlockValidator { - private IBlockValidator _baseValidator; - private IInvalidChainTracker _invalidChainTracker; - private ILogger _logger; + private readonly IBlockValidator _baseValidator; + private readonly IInvalidChainTracker _invalidChainTracker; + private readonly ILogger _logger; public InvalidBlockInterceptor( IBlockValidator headerValidator, diff --git a/src/Nethermind/Nethermind.Merkleization/MemMerkleTreeStore.cs b/src/Nethermind/Nethermind.Merkleization/MemMerkleTreeStore.cs index 416bb5ffb97..bfc85711d2f 100644 --- a/src/Nethermind/Nethermind.Merkleization/MemMerkleTreeStore.cs +++ b/src/Nethermind/Nethermind.Merkleization/MemMerkleTreeStore.cs @@ -8,7 +8,7 @@ namespace Nethermind.Merkleization; public class MemMerkleTreeStore : IKeyValueStore { - private Dictionary _dictionary = new Dictionary(); + private readonly Dictionary _dictionary = new Dictionary(); public byte[]? this[ulong key] { diff --git a/src/Nethermind/Nethermind.Merkleization/Merkle.Containers.cs b/src/Nethermind/Nethermind.Merkleization/Merkle.Containers.cs index 679bbdc7e38..a16b088d6e7 100644 --- a/src/Nethermind/Nethermind.Merkleization/Merkle.Containers.cs +++ b/src/Nethermind/Nethermind.Merkleization/Merkle.Containers.cs @@ -316,7 +316,7 @@ public static partial class Merkle // merkleizer.CalculateRoot(out root); //} - private static UInt256 RootOfNull; + private static readonly UInt256 RootOfNull; //public static void Ize(out UInt256 root, ProposerSlashing container) //{ diff --git a/src/Nethermind/Nethermind.Merkleization/MerkleTree.cs b/src/Nethermind/Nethermind.Merkleization/MerkleTree.cs index cbede0536f0..5df4e71f782 100644 --- a/src/Nethermind/Nethermind.Merkleization/MerkleTree.cs +++ b/src/Nethermind/Nethermind.Merkleization/MerkleTree.cs @@ -22,7 +22,7 @@ public abstract class MerkleTree : IMerkleList private readonly IKeyValueStore _keyValueStore; - private static ulong _countKey = ulong.MaxValue; + private static readonly ulong _countKey = ulong.MaxValue; public readonly ref struct Index { @@ -267,7 +267,7 @@ public void Insert(Bytes32 leaf) StoreCountInTheDb(); } - private byte[] _countBytes = new byte[32]; + private readonly byte[] _countBytes = new byte[32]; /// /// Check if 'leaf' at 'index' verifies against the Merkle 'root' and 'branch' diff --git a/src/Nethermind/Nethermind.Merkleization/Merkleizer.cs b/src/Nethermind/Nethermind.Merkleization/Merkleizer.cs index 364b4b69880..200391191cc 100644 --- a/src/Nethermind/Nethermind.Merkleization/Merkleizer.cs +++ b/src/Nethermind/Nethermind.Merkleization/Merkleizer.cs @@ -28,7 +28,7 @@ public void UnsetKthBit(int k) _filled &= ~((ulong)1 << k); } - private Span _chunks; + private readonly Span _chunks; private ulong _filled; public UInt256 PartChunk diff --git a/src/Nethermind/Nethermind.Mev.Test/MevRpcModuleTests.TestMevRpcBlockchain.cs b/src/Nethermind/Nethermind.Mev.Test/MevRpcModuleTests.TestMevRpcBlockchain.cs index 6824ebb1800..b87338a918b 100644 --- a/src/Nethermind/Nethermind.Mev.Test/MevRpcModuleTests.TestMevRpcBlockchain.cs +++ b/src/Nethermind/Nethermind.Mev.Test/MevRpcModuleTests.TestMevRpcBlockchain.cs @@ -58,7 +58,7 @@ public class TestMevRpcBlockchain : TestRpcBlockchain private ITracerFactory _tracerFactory = null!; public TestBundlePool BundlePool { get; private set; } = null!; - private MevConfig _mevConfig; + private readonly MevConfig _mevConfig; public TestMevRpcBlockchain(int maxMergedBundles, UInt256? initialBaseFeePerGas, Address[]? relayAddresses) { diff --git a/src/Nethermind/Nethermind.Mev.Test/MevRpcModuleTests.cs b/src/Nethermind/Nethermind.Mev.Test/MevRpcModuleTests.cs index cdfcfb51641..ef4b4b913a3 100644 --- a/src/Nethermind/Nethermind.Mev.Test/MevRpcModuleTests.cs +++ b/src/Nethermind/Nethermind.Mev.Test/MevRpcModuleTests.cs @@ -65,7 +65,7 @@ public static class Contracts // WARNING be careful when using PrivateKeyC // make sure keys from A to D are funded with test ether - private static PrivateKey ContractCreatorPrivateKey = TestItem.PrivateKeyC; + private static readonly PrivateKey ContractCreatorPrivateKey = TestItem.PrivateKeyC; public static async Task
Deploy(TestMevRpcBlockchain chain, string code, ulong nonce = 0, int value = 1) { diff --git a/src/Nethermind/Nethermind.Mev.Test/TestBundlePool.cs b/src/Nethermind/Nethermind.Mev.Test/TestBundlePool.cs index d350a274e77..7320a09bfe5 100644 --- a/src/Nethermind/Nethermind.Mev.Test/TestBundlePool.cs +++ b/src/Nethermind/Nethermind.Mev.Test/TestBundlePool.cs @@ -18,7 +18,7 @@ namespace Nethermind.Mev.Test { public class TestBundlePool : BundlePool { - private BlockingCollection<(MevBundle Bundle, SimulatedMevBundleContext? Context)> _queue = new(new ConcurrentQueue<(MevBundle, SimulatedMevBundleContext?)>()); + private readonly BlockingCollection<(MevBundle Bundle, SimulatedMevBundleContext? Context)> _queue = new(new ConcurrentQueue<(MevBundle, SimulatedMevBundleContext?)>()); public TestBundlePool(IBlockTree blockTree, IBundleSimulator simulator, diff --git a/src/Nethermind/Nethermind.Mining.Test/HintBasedCacheTests.cs b/src/Nethermind/Nethermind.Mining.Test/HintBasedCacheTests.cs index aa2fe9e20de..a48d9c6b7d6 100644 --- a/src/Nethermind/Nethermind.Mining.Test/HintBasedCacheTests.cs +++ b/src/Nethermind/Nethermind.Mining.Test/HintBasedCacheTests.cs @@ -37,9 +37,9 @@ public void Without_hint_return_null() } } - private Guid _guidA = Guid.NewGuid(); - private Guid _guidB = Guid.NewGuid(); - private Guid _guidC = Guid.NewGuid(); + private readonly Guid _guidA = Guid.NewGuid(); + private readonly Guid _guidB = Guid.NewGuid(); + private readonly Guid _guidC = Guid.NewGuid(); [Test] public async Task With_hint_returns_value() diff --git a/src/Nethermind/Nethermind.Network.Discovery.Test/NodeLifecycleManagerTests.cs b/src/Nethermind/Nethermind.Network.Discovery.Test/NodeLifecycleManagerTests.cs index d30f74bbde4..7ab3007f1e4 100644 --- a/src/Nethermind/Nethermind.Network.Discovery.Test/NodeLifecycleManagerTests.cs +++ b/src/Nethermind/Nethermind.Network.Discovery.Test/NodeLifecycleManagerTests.cs @@ -42,8 +42,8 @@ public class NodeLifecycleManagerTests private INodeTable _nodeTable = null!; private IEvictionManager _evictionManagerMock = null!; private ILogger _loggerMock = null!; - private int _port = 1; - private string _host = "192.168.1.27"; + private readonly int _port = 1; + private readonly string _host = "192.168.1.27"; [SetUp] public void Setup() diff --git a/src/Nethermind/Nethermind.Network.Discovery.Test/RoutingTable/NodeBucketTests.cs b/src/Nethermind/Nethermind.Network.Discovery.Test/RoutingTable/NodeBucketTests.cs index 256c4e9dcdf..d5038f6374e 100644 --- a/src/Nethermind/Nethermind.Network.Discovery.Test/RoutingTable/NodeBucketTests.cs +++ b/src/Nethermind/Nethermind.Network.Discovery.Test/RoutingTable/NodeBucketTests.cs @@ -15,9 +15,9 @@ namespace Nethermind.Network.Discovery.Test.RoutingTable [TestFixture] public class NodeBucketTests { - private Node _node = new(TestItem.PublicKeyA, IPAddress.Broadcast.ToString(), 30000); - private Node _node2 = new(TestItem.PublicKeyB, IPAddress.Broadcast.ToString(), 3000); - private Node _node3 = new(TestItem.PublicKeyC, IPAddress.Broadcast.ToString(), 3000); + private readonly Node _node = new(TestItem.PublicKeyA, IPAddress.Broadcast.ToString(), 30000); + private readonly Node _node2 = new(TestItem.PublicKeyB, IPAddress.Broadcast.ToString(), 3000); + private readonly Node _node3 = new(TestItem.PublicKeyC, IPAddress.Broadcast.ToString(), 3000); [Test] public void Bonded_count_is_tracked() diff --git a/src/Nethermind/Nethermind.Network.Discovery/RoutingTable/NodeAddResult.cs b/src/Nethermind/Nethermind.Network.Discovery/RoutingTable/NodeAddResult.cs index 2c5064c4116..3ebdff63a7b 100644 --- a/src/Nethermind/Nethermind.Network.Discovery/RoutingTable/NodeAddResult.cs +++ b/src/Nethermind/Nethermind.Network.Discovery/RoutingTable/NodeAddResult.cs @@ -9,8 +9,8 @@ public class NodeAddResult public NodeBucketItem? EvictionCandidate { get; private init; } - private static NodeAddResult? _added = null; - private static NodeAddResult? _dropped = null; + private static readonly NodeAddResult? _added = null; + private static readonly NodeAddResult? _dropped = null; public static NodeAddResult Added() { diff --git a/src/Nethermind/Nethermind.Network.Test/P2P/P2PProtocolHandlerTests.cs b/src/Nethermind/Nethermind.Network.Test/P2P/P2PProtocolHandlerTests.cs index 4e2f8f3bb86..305d92937c2 100644 --- a/src/Nethermind/Nethermind.Network.Test/P2P/P2PProtocolHandlerTests.cs +++ b/src/Nethermind/Nethermind.Network.Test/P2P/P2PProtocolHandlerTests.cs @@ -40,7 +40,7 @@ public void Setup() private ISession _session; private IMessageSerializationService _serializer; - private Node node = new(TestItem.PublicKeyA, "127.0.0.1", 30303); + private readonly Node node = new(TestItem.PublicKeyA, "127.0.0.1", 30303); private INodeStatsManager _nodeStatsManager; private Regex? _clientIdPattern; diff --git a/src/Nethermind/Nethermind.Network.Test/PeerManagerTests.cs b/src/Nethermind/Nethermind.Network.Test/PeerManagerTests.cs index aac19d165d0..4dda0b92184 100644 --- a/src/Nethermind/Nethermind.Network.Test/PeerManagerTests.cs +++ b/src/Nethermind/Nethermind.Network.Test/PeerManagerTests.cs @@ -408,10 +408,10 @@ public async Task IfPeerAdded_with_invalid_chain_then_do_not_connect() ctx.PeerPool.ActivePeers.Count.Should().Be(0); } - private int _travisDelay = 500; + private readonly int _travisDelay = 500; - private int _travisDelayLong = 1000; - private int _travisDelayLonger = 3000; + private readonly int _travisDelayLong = 1000; + private readonly int _travisDelayLonger = 3000; [Test] [Ignore("Behaviour changed that allows peers to go over max if awaiting response")] diff --git a/src/Nethermind/Nethermind.Network.Test/ProtocolsManagerTests.cs b/src/Nethermind/Nethermind.Network.Test/ProtocolsManagerTests.cs index 9b72d269f19..7eab2dfa091 100644 --- a/src/Nethermind/Nethermind.Network.Test/ProtocolsManagerTests.cs +++ b/src/Nethermind/Nethermind.Network.Test/ProtocolsManagerTests.cs @@ -47,27 +47,27 @@ public void SetUp() public class Context { - private int _localPort = 30312; - private int _remotePort = 30000; - private string _remoteHost = "35.0.0.1"; + private readonly int _localPort = 30312; + private readonly int _remotePort = 30000; + private readonly string _remoteHost = "35.0.0.1"; private ISession _currentSession; - private IDiscoveryApp _discoveryApp; - private IRlpxHost _rlpxHost; - private ProtocolsManager _manager; - private INodeStatsManager _nodeStatsManager; - private INetworkStorage _peerStorage; - private IProtocolValidator _protocolValidator; - private IMessageSerializationService _serializer; - private ISyncServer _syncServer; - private ISyncPeerPool _syncPeerPool; - private ITxPool _txPool; - private IPooledTxsRequestor _pooledTxsRequestor; - private IChannelHandlerContext _channelHandlerContext; - private IChannel _channel; - private IChannelPipeline _pipeline; - private IPacketSender _packetSender; - private IBlockTree _blockTree; - private IGossipPolicy _gossipPolicy; + private readonly IDiscoveryApp _discoveryApp; + private readonly IRlpxHost _rlpxHost; + private readonly ProtocolsManager _manager; + private readonly INodeStatsManager _nodeStatsManager; + private readonly INetworkStorage _peerStorage; + private readonly IProtocolValidator _protocolValidator; + private readonly IMessageSerializationService _serializer; + private readonly ISyncServer _syncServer; + private readonly ISyncPeerPool _syncPeerPool; + private readonly ITxPool _txPool; + private readonly IPooledTxsRequestor _pooledTxsRequestor; + private readonly IChannelHandlerContext _channelHandlerContext; + private readonly IChannel _channel; + private readonly IChannelPipeline _pipeline; + private readonly IPacketSender _packetSender; + private readonly IBlockTree _blockTree; + private readonly IGossipPolicy _gossipPolicy; public Context() { diff --git a/src/Nethermind/Nethermind.Network.Test/SnapProtocolHandlerTests.cs b/src/Nethermind/Nethermind.Network.Test/SnapProtocolHandlerTests.cs index 0d6726ad6ba..a150ac86b90 100644 --- a/src/Nethermind/Nethermind.Network.Test/SnapProtocolHandlerTests.cs +++ b/src/Nethermind/Nethermind.Network.Test/SnapProtocolHandlerTests.cs @@ -65,7 +65,7 @@ public SnapProtocolHandler SnapProtocolHandler public TimeSpan SimulatedLatency { get; set; } = TimeSpan.Zero; - private List _recordedResponseBytesLength = new(); + private readonly List _recordedResponseBytesLength = new(); public Context WithResponseBytesRecorder { get diff --git a/src/Nethermind/Nethermind.Network/P2P/PacketSender.cs b/src/Nethermind/Nethermind.Network/P2P/PacketSender.cs index 1321dc672e5..7edf47360ac 100644 --- a/src/Nethermind/Nethermind.Network/P2P/PacketSender.cs +++ b/src/Nethermind/Nethermind.Network/P2P/PacketSender.cs @@ -15,7 +15,7 @@ public class PacketSender : ChannelHandlerAdapter, IPacketSender private readonly IMessageSerializationService _messageSerializationService; private readonly ILogger _logger; private IChannelHandlerContext _context; - private TimeSpan _sendLatency; + private readonly TimeSpan _sendLatency; public PacketSender(IMessageSerializationService messageSerializationService, ILogManager logManager, TimeSpan sendLatency) diff --git a/src/Nethermind/Nethermind.Network/P2P/Session.cs b/src/Nethermind/Nethermind.Network/P2P/Session.cs index 8b1bbda7e85..d9ab8c9bb6e 100644 --- a/src/Nethermind/Nethermind.Network/P2P/Session.cs +++ b/src/Nethermind/Nethermind.Network/P2P/Session.cs @@ -426,7 +426,7 @@ bool ShouldDisconnectStaticNode() MarkDisconnected(disconnectReason, DisconnectType.Local, details); } - private object _sessionStateLock = new(); + private readonly object _sessionStateLock = new(); public byte P2PVersion { get; private set; } private SessionState _state; diff --git a/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V62/Messages/BlockHeadersMessageSerializer.cs b/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V62/Messages/BlockHeadersMessageSerializer.cs index dcb6cab2b8e..9a016430478 100644 --- a/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V62/Messages/BlockHeadersMessageSerializer.cs +++ b/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V62/Messages/BlockHeadersMessageSerializer.cs @@ -9,7 +9,7 @@ namespace Nethermind.Network.P2P.Subprotocols.Eth.V62.Messages { public class BlockHeadersMessageSerializer : IZeroInnerMessageSerializer { - private HeaderDecoder _headerDecoder = new(); + private readonly HeaderDecoder _headerDecoder = new(); public void Serialize(IByteBuffer byteBuffer, BlockHeadersMessage message) { diff --git a/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V62/Messages/NewBlockMessageSerializer.cs b/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V62/Messages/NewBlockMessageSerializer.cs index ebccfd90825..89bce75712b 100644 --- a/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V62/Messages/NewBlockMessageSerializer.cs +++ b/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V62/Messages/NewBlockMessageSerializer.cs @@ -9,7 +9,7 @@ namespace Nethermind.Network.P2P.Subprotocols.Eth.V62.Messages { public class NewBlockMessageSerializer : IZeroInnerMessageSerializer { - private BlockDecoder _blockDecoder = new(); + private readonly BlockDecoder _blockDecoder = new(); public void Serialize(IByteBuffer byteBuffer, NewBlockMessage message) { diff --git a/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V62/Messages/TransactionsMessageSerializer.cs b/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V62/Messages/TransactionsMessageSerializer.cs index 87cadefb349..a3c23bbfecb 100644 --- a/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V62/Messages/TransactionsMessageSerializer.cs +++ b/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V62/Messages/TransactionsMessageSerializer.cs @@ -9,7 +9,7 @@ namespace Nethermind.Network.P2P.Subprotocols.Eth.V62.Messages { public class TransactionsMessageSerializer : IZeroInnerMessageSerializer { - private TxDecoder _decoder = new(); + private readonly TxDecoder _decoder = new(); public void Serialize(IByteBuffer byteBuffer, TransactionsMessage message) { diff --git a/src/Nethermind/Nethermind.Network/PeerPool.cs b/src/Nethermind/Nethermind.Network/PeerPool.cs index e4958a54a24..6d074f97e6a 100644 --- a/src/Nethermind/Nethermind.Network/PeerPool.cs +++ b/src/Nethermind/Nethermind.Network/PeerPool.cs @@ -42,8 +42,8 @@ public class PeerPool : IPeerPool private readonly CancellationTokenSource _cancellationTokenSource = new(); - Func Statics), Peer> _createNewNodePeer; - Func Statics), Peer> _createNewNetworkNodePeer; + readonly Func Statics), Peer> _createNewNodePeer; + readonly Func Statics), Peer> _createNewNetworkNodePeer; public PeerPool( INodeSource nodeSource, diff --git a/src/Nethermind/Nethermind.Network/ProtocolValidator.cs b/src/Nethermind/Nethermind.Network/ProtocolValidator.cs index 41e855a05d4..d34d8c71cdb 100644 --- a/src/Nethermind/Nethermind.Network/ProtocolValidator.cs +++ b/src/Nethermind/Nethermind.Network/ProtocolValidator.cs @@ -20,7 +20,7 @@ public class ProtocolValidator : IProtocolValidator private readonly INodeStatsManager _nodeStatsManager; private readonly IBlockTree _blockTree; private readonly ForkInfo _forkInfo; - private ILogger _logger; + private readonly ILogger _logger; public ProtocolValidator(INodeStatsManager nodeStatsManager, IBlockTree blockTree, ForkInfo forkInfo, ILogManager? logManager) { diff --git a/src/Nethermind/Nethermind.Network/Rlpx/FrameMacProcessor.cs b/src/Nethermind/Nethermind.Network/Rlpx/FrameMacProcessor.cs index 3c5d40f4ec6..e13301f70e7 100644 --- a/src/Nethermind/Nethermind.Network/Rlpx/FrameMacProcessor.cs +++ b/src/Nethermind/Nethermind.Network/Rlpx/FrameMacProcessor.cs @@ -104,10 +104,10 @@ public void AddMac(byte[] input, int offset, int length, byte[] output, int outp } } - private byte[] _addMacBuffer; - private byte[] _checkMacBuffer; - private byte[] _ingressAesBlockBuffer; - private byte[] _egressAesBlockBuffer; + private readonly byte[] _addMacBuffer; + private readonly byte[] _checkMacBuffer; + private readonly byte[] _ingressAesBlockBuffer; + private readonly byte[] _egressAesBlockBuffer; public bool CheckMac(byte[] mac, bool isHeader) { diff --git a/src/Nethermind/Nethermind.Network/Rlpx/Handshake/HandshakeService.cs b/src/Nethermind/Nethermind.Network/Rlpx/Handshake/HandshakeService.cs index dfc33b9e60e..f1657f241a2 100644 --- a/src/Nethermind/Nethermind.Network/Rlpx/Handshake/HandshakeService.cs +++ b/src/Nethermind/Nethermind.Network/Rlpx/Handshake/HandshakeService.cs @@ -18,8 +18,8 @@ namespace Nethermind.Network.Rlpx.Handshake ///
public class HandshakeService : IHandshakeService { - private static int MacBitsSize = 256; - private static int MacBytesSize = MacBitsSize / 8; + private static readonly int MacBitsSize = 256; + private static readonly int MacBytesSize = MacBitsSize / 8; private readonly IPrivateKeyGenerator _ephemeralGenerator; private readonly ICryptoRandom _cryptoRandom; diff --git a/src/Nethermind/Nethermind.Network/Rlpx/NettyHandshakeHandler.cs b/src/Nethermind/Nethermind.Network/Rlpx/NettyHandshakeHandler.cs index 4a87da592f1..59869c891cd 100644 --- a/src/Nethermind/Nethermind.Network/Rlpx/NettyHandshakeHandler.cs +++ b/src/Nethermind/Nethermind.Network/Rlpx/NettyHandshakeHandler.cs @@ -33,7 +33,7 @@ public class NettyHandshakeHandler : SimpleChannelInboundHandler private PublicKey RemoteId => _session.RemoteNodeId; private readonly TaskCompletionSource _initCompletionSource; private IChannel _channel; - private TimeSpan _sendLatency; + private readonly TimeSpan _sendLatency; public NettyHandshakeHandler( IMessageSerializationService serializationService, diff --git a/src/Nethermind/Nethermind.Network/Rlpx/RlpxHost.cs b/src/Nethermind/Nethermind.Network/Rlpx/RlpxHost.cs index 458b0b856da..fdec36e745a 100644 --- a/src/Nethermind/Nethermind.Network/Rlpx/RlpxHost.cs +++ b/src/Nethermind/Nethermind.Network/Rlpx/RlpxHost.cs @@ -40,8 +40,8 @@ public class RlpxHost : IRlpxHost private readonly ILogger _logger; private readonly ISessionMonitor _sessionMonitor; private readonly IDisconnectsAnalyzer _disconnectsAnalyzer; - private IEventExecutorGroup _group; - private TimeSpan _sendLatency; + private readonly IEventExecutorGroup _group; + private readonly TimeSpan _sendLatency; private readonly TimeSpan _connectTimeout; public RlpxHost(IMessageSerializationService serializationService, diff --git a/src/Nethermind/Nethermind.Network/Rlpx/ZeroFrameMerger.cs b/src/Nethermind/Nethermind.Network/Rlpx/ZeroFrameMerger.cs index b4590e4d4d2..4e2b2b9f8cf 100644 --- a/src/Nethermind/Nethermind.Network/Rlpx/ZeroFrameMerger.cs +++ b/src/Nethermind/Nethermind.Network/Rlpx/ZeroFrameMerger.cs @@ -14,10 +14,10 @@ namespace Nethermind.Network.Rlpx { public class ZeroFrameMerger : ByteToMessageDecoder { - private ILogger _logger; + private readonly ILogger _logger; private ZeroPacket? _zeroPacket; - private FrameHeaderReader _headerReader = new(); + private readonly FrameHeaderReader _headerReader = new(); public ZeroFrameMerger(ILogManager logManager) { diff --git a/src/Nethermind/Nethermind.Network/Rlpx/ZeroPacketSplitter.cs b/src/Nethermind/Nethermind.Network/Rlpx/ZeroPacketSplitter.cs index 66cc1cc9ce2..2917b343eb0 100644 --- a/src/Nethermind/Nethermind.Network/Rlpx/ZeroPacketSplitter.cs +++ b/src/Nethermind/Nethermind.Network/Rlpx/ZeroPacketSplitter.cs @@ -14,7 +14,7 @@ namespace Nethermind.Network.Rlpx { public class ZeroPacketSplitter : MessageToByteEncoder, IFramingAware { - private ILogger _logger; + private readonly ILogger _logger; public ZeroPacketSplitter(ILogManager logManager) { diff --git a/src/Nethermind/Nethermind.Network/SessionMonitor.cs b/src/Nethermind/Nethermind.Network/SessionMonitor.cs index 9cd9f4ec4cf..58b21d89e2a 100644 --- a/src/Nethermind/Nethermind.Network/SessionMonitor.cs +++ b/src/Nethermind/Nethermind.Network/SessionMonitor.cs @@ -23,8 +23,8 @@ public class SessionMonitor : ISessionMonitor private readonly INetworkConfig _networkConfig; private readonly ILogger _logger; - private TimeSpan _pingInterval; - private List> _pingTasks = new(); + private readonly TimeSpan _pingInterval; + private readonly List> _pingTasks = new(); private CancellationTokenSource? _cancellationTokenSource; @@ -46,7 +46,7 @@ public void Stop() StopPingTimer(); } - private ConcurrentDictionary _sessions = new(); + private readonly ConcurrentDictionary _sessions = new(); public void AddSession(ISession session) { diff --git a/src/Nethermind/Nethermind.Optimism/OptimismEthereumEcdsa.cs b/src/Nethermind/Nethermind.Optimism/OptimismEthereumEcdsa.cs index 0b4e70ca97d..f70db353bf7 100644 --- a/src/Nethermind/Nethermind.Optimism/OptimismEthereumEcdsa.cs +++ b/src/Nethermind/Nethermind.Optimism/OptimismEthereumEcdsa.cs @@ -10,7 +10,7 @@ namespace Nethermind.Optimism; public class OptimismEthereumEcdsa : Ecdsa, IEthereumEcdsa { - private IEthereumEcdsa _ethereumEcdsa; + private readonly IEthereumEcdsa _ethereumEcdsa; public OptimismEthereumEcdsa(IEthereumEcdsa ethereumEcdsa) { diff --git a/src/Nethermind/Nethermind.Overseer.Test/Framework/TestBuilder.cs b/src/Nethermind/Nethermind.Overseer.Test/Framework/TestBuilder.cs index 4b1d09f411d..7daffcafa70 100644 --- a/src/Nethermind/Nethermind.Overseer.Test/Framework/TestBuilder.cs +++ b/src/Nethermind/Nethermind.Overseer.Test/Framework/TestBuilder.cs @@ -111,9 +111,9 @@ public void QueueWork(TestStepBase step) private readonly ProcessBuilder _processBuilder; - private static string _runnerDir; - private static string _dbsDir; - private static string _configsDir; + private static readonly string _runnerDir; + private static readonly string _dbsDir; + private static readonly string _configsDir; static TestBuilder() { diff --git a/src/Nethermind/Nethermind.Runner.Test/ChainspecFilesTests.cs b/src/Nethermind/Nethermind.Runner.Test/ChainspecFilesTests.cs index 7ea6dd028b4..ce5a4a7b625 100644 --- a/src/Nethermind/Nethermind.Runner.Test/ChainspecFilesTests.cs +++ b/src/Nethermind/Nethermind.Runner.Test/ChainspecFilesTests.cs @@ -15,8 +15,8 @@ namespace Nethermind.Runner.Test public class ChainspecFilesTests { - private IJsonSerializer _jsonSerializer = new EthereumJsonSerializer(); - private IChainSpecLoader _loader; + private readonly IJsonSerializer _jsonSerializer = new EthereumJsonSerializer(); + private readonly IChainSpecLoader _loader; public ILogger _logger; public ChainspecFilesTests() { diff --git a/src/Nethermind/Nethermind.Runner/Ethereum/EthereumRunner.cs b/src/Nethermind/Nethermind.Runner/Ethereum/EthereumRunner.cs index 3d2d57793d1..e445b7320ab 100644 --- a/src/Nethermind/Nethermind.Runner/Ethereum/EthereumRunner.cs +++ b/src/Nethermind/Nethermind.Runner/Ethereum/EthereumRunner.cs @@ -17,9 +17,9 @@ namespace Nethermind.Runner.Ethereum { public class EthereumRunner { - private INethermindApi _api; + private readonly INethermindApi _api; - private ILogger _logger; + private readonly ILogger _logger; public EthereumRunner(INethermindApi api) { diff --git a/src/Nethermind/Nethermind.Runner/Ethereum/JsonRpcRunner.cs b/src/Nethermind/Nethermind.Runner/Ethereum/JsonRpcRunner.cs index 4d911adbd43..172616f6523 100644 --- a/src/Nethermind/Nethermind.Runner/Ethereum/JsonRpcRunner.cs +++ b/src/Nethermind/Nethermind.Runner/Ethereum/JsonRpcRunner.cs @@ -35,8 +35,8 @@ public class JsonRpcRunner private readonly IWebSocketsManager _webSocketsManager; private readonly IJsonRpcConfig _jsonRpcConfig; private IWebHost? _webHost; - private IInitConfig _initConfig; - private INethermindApi _api; + private readonly IInitConfig _initConfig; + private readonly INethermindApi _api; public JsonRpcRunner( IJsonRpcProcessor jsonRpcProcessor, diff --git a/src/Nethermind/Nethermind.Serialization.Json/EthereumJsonSerializer.cs b/src/Nethermind/Nethermind.Serialization.Json/EthereumJsonSerializer.cs index 946bd3effb0..86189982c5c 100644 --- a/src/Nethermind/Nethermind.Serialization.Json/EthereumJsonSerializer.cs +++ b/src/Nethermind/Nethermind.Serialization.Json/EthereumJsonSerializer.cs @@ -17,7 +17,7 @@ namespace Nethermind.Serialization.Json { public class EthereumJsonSerializer : IJsonSerializer { - private JsonSerializerOptions _jsonOptions; + private readonly JsonSerializerOptions _jsonOptions; public EthereumJsonSerializer(int? maxDepth = null) { @@ -93,7 +93,7 @@ private static JsonSerializerOptions CreateOptions(bool indented, int maxDepth = return options; } - private static List _additionalConverters = new(); + private static readonly List _additionalConverters = new(); public static void AddConverter(JsonConverter converter) { _additionalConverters.Add(converter); @@ -106,8 +106,8 @@ public static void AddConverter(JsonConverter converter) public static JsonSerializerOptions JsonOptionsIndented { get; private set; } = CreateOptions(indented: true); - private static StreamPipeWriterOptions optionsLeaveOpen = new(pool: MemoryPool.Shared, minimumBufferSize: 4096, leaveOpen: true); - private static StreamPipeWriterOptions options = new(pool: MemoryPool.Shared, minimumBufferSize: 4096, leaveOpen: false); + private static readonly StreamPipeWriterOptions optionsLeaveOpen = new(pool: MemoryPool.Shared, minimumBufferSize: 4096, leaveOpen: true); + private static readonly StreamPipeWriterOptions options = new(pool: MemoryPool.Shared, minimumBufferSize: 4096, leaveOpen: false); private static CountingStreamPipeWriter GetPipeWriter(Stream stream, bool leaveOpen) { diff --git a/src/Nethermind/Nethermind.Serialization.Json/PubSub/LogPublisher.cs b/src/Nethermind/Nethermind.Serialization.Json/PubSub/LogPublisher.cs index b0f9de3b5b5..75a0807cca7 100644 --- a/src/Nethermind/Nethermind.Serialization.Json/PubSub/LogPublisher.cs +++ b/src/Nethermind/Nethermind.Serialization.Json/PubSub/LogPublisher.cs @@ -9,8 +9,8 @@ namespace Nethermind.Serialization.Json.PubSub { public class LogPublisher : IPublisher { - private ILogger _logger; - private IJsonSerializer _jsonSerializer; + private readonly ILogger _logger; + private readonly IJsonSerializer _jsonSerializer; public LogPublisher(IJsonSerializer jsonSerializer, ILogManager logManager) { diff --git a/src/Nethermind/Nethermind.Serialization.Json/StorageCellIndexConverter.cs b/src/Nethermind/Nethermind.Serialization.Json/StorageCellIndexConverter.cs index a70c82123d3..bfabde7e275 100644 --- a/src/Nethermind/Nethermind.Serialization.Json/StorageCellIndexConverter.cs +++ b/src/Nethermind/Nethermind.Serialization.Json/StorageCellIndexConverter.cs @@ -16,7 +16,7 @@ namespace Nethermind.Serialization.Json public class StorageCellIndexConverter : JsonConverter?> { - private UInt256Converter _converter = new(); + private readonly UInt256Converter _converter = new(); public override IEnumerable? Read( ref Utf8JsonReader reader, diff --git a/src/Nethermind/Nethermind.Serialization.Rlp/OwnedBlockBodies.cs b/src/Nethermind/Nethermind.Serialization.Rlp/OwnedBlockBodies.cs index 0fe63fdfe53..7e48f40d863 100644 --- a/src/Nethermind/Nethermind.Serialization.Rlp/OwnedBlockBodies.cs +++ b/src/Nethermind/Nethermind.Serialization.Rlp/OwnedBlockBodies.cs @@ -15,7 +15,7 @@ namespace Nethermind.Core; /// public class OwnedBlockBodies : IDisposable { - private BlockBody?[]? _rawBodies = null; + private readonly BlockBody?[]? _rawBodies = null; private IMemoryOwner? _memoryOwner = null; diff --git a/src/Nethermind/Nethermind.Serialization.Rlp/ReceiptArrayStorageDecoder.cs b/src/Nethermind/Nethermind.Serialization.Rlp/ReceiptArrayStorageDecoder.cs index 6d1b0f7a750..af1c6563ff2 100644 --- a/src/Nethermind/Nethermind.Serialization.Rlp/ReceiptArrayStorageDecoder.cs +++ b/src/Nethermind/Nethermind.Serialization.Rlp/ReceiptArrayStorageDecoder.cs @@ -11,11 +11,11 @@ namespace Nethermind.Serialization.Rlp; public class ReceiptArrayStorageDecoder : IRlpStreamDecoder { public static readonly ReceiptArrayStorageDecoder Instance = new(); - private ReceiptStorageDecoder StorageDecoder = ReceiptStorageDecoder.Instance; - private CompactReceiptStorageDecoder CompactReceiptStorageDecoder = CompactReceiptStorageDecoder.Instance; + private readonly ReceiptStorageDecoder StorageDecoder = ReceiptStorageDecoder.Instance; + private readonly CompactReceiptStorageDecoder CompactReceiptStorageDecoder = CompactReceiptStorageDecoder.Instance; public const int CompactEncoding = 127; - private bool _useCompactEncoding = true; + private readonly bool _useCompactEncoding = true; public ReceiptArrayStorageDecoder(bool compactEncoding = true) { diff --git a/src/Nethermind/Nethermind.Serialization.Ssz.Test/MerkleTreeTests.cs b/src/Nethermind/Nethermind.Serialization.Ssz.Test/MerkleTreeTests.cs index ce20f018783..7653cdc20b8 100644 --- a/src/Nethermind/Nethermind.Serialization.Ssz.Test/MerkleTreeTests.cs +++ b/src/Nethermind/Nethermind.Serialization.Ssz.Test/MerkleTreeTests.cs @@ -17,7 +17,7 @@ namespace Nethermind.Serialization.Ssz.Test [TestFixture] public class MerkleTreeTests { - private Bytes32[] _testLeaves = new Bytes32[32]; + private readonly Bytes32[] _testLeaves = new Bytes32[32]; private const ulong _nodeIndexOfTheFirstLeaf = (1ul << MerkleTree.TreeHeight) - 1ul; private const ulong _lastNodeIndex = (1ul << (MerkleTree.TreeHeight + 1)) - 2ul; private const uint _lastLeafIndex = (uint)((1ul << MerkleTree.TreeHeight) - 1u); diff --git a/src/Nethermind/Nethermind.State/Proofs/AccountProofCollector.cs b/src/Nethermind/Nethermind.State/Proofs/AccountProofCollector.cs index d1e58694845..42eeac15af9 100644 --- a/src/Nethermind/Nethermind.State/Proofs/AccountProofCollector.cs +++ b/src/Nethermind/Nethermind.State/Proofs/AccountProofCollector.cs @@ -19,17 +19,17 @@ namespace Nethermind.State.Proofs public class AccountProofCollector : ITreeVisitor { private int _pathTraversalIndex; - private Address _address = Address.Zero; - private AccountProof _accountProof; + private readonly Address _address = Address.Zero; + private readonly AccountProof _accountProof; - private Nibble[] _fullAccountPath; - private Nibble[][] _fullStoragePaths; + private readonly Nibble[] _fullAccountPath; + private readonly Nibble[][] _fullStoragePaths; - private List _accountProofItems = new(); - private List[] _storageProofItems; + private readonly List _accountProofItems = new(); + private readonly List[] _storageProofItems; - private Dictionary _storageNodeInfos = new(); - private HashSet _nodeToVisitFilter = new(); + private readonly Dictionary _storageNodeInfos = new(); + private readonly HashSet _nodeToVisitFilter = new(); private class StorageNodeInfo { @@ -329,7 +329,7 @@ private bool IsPathMatched(TrieNode node, Nibble[] path) return isPathMatched; } - private AccountDecoder _accountDecoder = new(); + private readonly AccountDecoder _accountDecoder = new(); public void VisitCode(Hash256 codeHash, TrieVisitContext trieVisitContext) { diff --git a/src/Nethermind/Nethermind.State/Proofs/ProofCollector.cs b/src/Nethermind/Nethermind.State/Proofs/ProofCollector.cs index 431e2e42558..bb29de189d1 100644 --- a/src/Nethermind/Nethermind.State/Proofs/ProofCollector.cs +++ b/src/Nethermind/Nethermind.State/Proofs/ProofCollector.cs @@ -20,9 +20,9 @@ public class ProofCollector : ITreeVisitor private Nibble[] Prefix => Nibbles.FromBytes(_key); - private HashSet _visitingFilter = new(); + private readonly HashSet _visitingFilter = new(); - private List _proofBits = new(); + private readonly List _proofBits = new(); public ProofCollector(byte[] key) { diff --git a/src/Nethermind/Nethermind.State/ReadOnlyWorldStateManager.cs b/src/Nethermind/Nethermind.State/ReadOnlyWorldStateManager.cs index d2a9b5ebce1..f4bdd53a19a 100644 --- a/src/Nethermind/Nethermind.State/ReadOnlyWorldStateManager.cs +++ b/src/Nethermind/Nethermind.State/ReadOnlyWorldStateManager.cs @@ -14,9 +14,9 @@ namespace Nethermind.State; /// public class ReadOnlyWorldStateManager : IWorldStateManager { - private IReadOnlyDbProvider _readOnlyDbProvider; - private IReadOnlyTrieStore? _readOnlyTrieStore; - private ILogManager _logManager; + private readonly IReadOnlyDbProvider _readOnlyDbProvider; + private readonly IReadOnlyTrieStore? _readOnlyTrieStore; + private readonly ILogManager _logManager; private readonly IDbProvider _dbProvider; private readonly ReadOnlyDb _codeDb; diff --git a/src/Nethermind/Nethermind.Synchronization.Test/DbTuner/SyncDbTunerTests.cs b/src/Nethermind/Nethermind.Synchronization.Test/DbTuner/SyncDbTunerTests.cs index 4ae44021e69..8c7954d8b92 100644 --- a/src/Nethermind/Nethermind.Synchronization.Test/DbTuner/SyncDbTunerTests.cs +++ b/src/Nethermind/Nethermind.Synchronization.Test/DbTuner/SyncDbTunerTests.cs @@ -15,7 +15,7 @@ namespace Nethermind.Synchronization.Test.DbTuner; public class SyncDbTunerTests { private ITunableDb.TuneType _tuneType = ITunableDb.TuneType.HeavyWrite; - private ITunableDb.TuneType _blocksTuneType = ITunableDb.TuneType.AggressiveHeavyWrite; + private readonly ITunableDb.TuneType _blocksTuneType = ITunableDb.TuneType.AggressiveHeavyWrite; private SyncConfig _syncConfig = null!; private ISyncFeed _snapSyncFeed = null!; private ISyncFeed _bodiesSyncFeed = null!; diff --git a/src/Nethermind/Nethermind.Synchronization.Test/FastSync/StateSyncAllocationStrategyTests.cs b/src/Nethermind/Nethermind.Synchronization.Test/FastSync/StateSyncAllocationStrategyTests.cs index 16f6986339c..6eaf16095b9 100644 --- a/src/Nethermind/Nethermind.Synchronization.Test/FastSync/StateSyncAllocationStrategyTests.cs +++ b/src/Nethermind/Nethermind.Synchronization.Test/FastSync/StateSyncAllocationStrategyTests.cs @@ -21,7 +21,7 @@ namespace Nethermind.Synchronization.Test.FastSync; public class StateSyncAllocationStrategyTests { - private static IPeerAllocationStrategy _strategy = new StateSyncAllocationStrategyFactory.AllocationStrategy(new NoopAllocationStrategy()); + private static readonly IPeerAllocationStrategy _strategy = new StateSyncAllocationStrategyFactory.AllocationStrategy(new NoopAllocationStrategy()); [Test] public void Can_allocate_node_with_snap() diff --git a/src/Nethermind/Nethermind.Synchronization.Test/SyncThreadTests.cs b/src/Nethermind/Nethermind.Synchronization.Test/SyncThreadTests.cs index 4753b1bbcda..73320482dbd 100644 --- a/src/Nethermind/Nethermind.Synchronization.Test/SyncThreadTests.cs +++ b/src/Nethermind/Nethermind.Synchronization.Test/SyncThreadTests.cs @@ -59,7 +59,7 @@ public SyncThreadsTests(SynchronizerType synchronizerType) _synchronizerType = synchronizerType; } - private int remotePeersCount = 2; + private readonly int remotePeersCount = 2; [SetUp] public void Setup() @@ -177,7 +177,7 @@ private Block ProduceBlocks(int chainLength) return headBlock; } - private int _chainLength = 100; + private readonly int _chainLength = 100; [Test, Ignore("Fails when running with other tests due to pool starvation in NUnit adapter")] public void Can_sync_when_initially_disconnected() diff --git a/src/Nethermind/Nethermind.Synchronization/Blocks/SyncBatchSize.cs b/src/Nethermind/Nethermind.Synchronization/Blocks/SyncBatchSize.cs index 05f91a88c60..113a0d32396 100644 --- a/src/Nethermind/Nethermind.Synchronization/Blocks/SyncBatchSize.cs +++ b/src/Nethermind/Nethermind.Synchronization/Blocks/SyncBatchSize.cs @@ -10,7 +10,7 @@ namespace Nethermind.Synchronization.Blocks [DebuggerDisplay("{Current}")] public struct SyncBatchSize { - private ILogger _logger; + private readonly ILogger _logger; // The batch size is kinda also used for downloading bodies which is large. Peers can return less body // than required, however, they still tend to timeout, so we try to limit this from our side. diff --git a/src/Nethermind/Nethermind.Synchronization/DbTuner/SyncDbOptimizer.cs b/src/Nethermind/Nethermind.Synchronization/DbTuner/SyncDbOptimizer.cs index 90826b95e24..ed7e325f292 100644 --- a/src/Nethermind/Nethermind.Synchronization/DbTuner/SyncDbOptimizer.cs +++ b/src/Nethermind/Nethermind.Synchronization/DbTuner/SyncDbOptimizer.cs @@ -16,8 +16,8 @@ public class SyncDbTuner private readonly ITunableDb? _blockDb; private readonly ITunableDb? _receiptDb; - private ITunableDb.TuneType _tuneType; - private ITunableDb.TuneType _blocksDbTuneType; + private readonly ITunableDb.TuneType _tuneType; + private readonly ITunableDb.TuneType _blocksDbTuneType; public SyncDbTuner( ISyncConfig syncConfig, diff --git a/src/Nethermind/Nethermind.Synchronization/FastBlocks/BodiesSyncDownloader.cs b/src/Nethermind/Nethermind.Synchronization/FastBlocks/BodiesSyncDownloader.cs index 8edde07ee90..90565e0fe1b 100644 --- a/src/Nethermind/Nethermind.Synchronization/FastBlocks/BodiesSyncDownloader.cs +++ b/src/Nethermind/Nethermind.Synchronization/FastBlocks/BodiesSyncDownloader.cs @@ -16,7 +16,7 @@ namespace Nethermind.Synchronization.FastBlocks { public class BodiesSyncDownloader : ISyncDownloader { - private ILogger Logger; + private readonly ILogger Logger; public BodiesSyncDownloader(ILogManager logManager) { diff --git a/src/Nethermind/Nethermind.Synchronization/FastBlocks/FastBlocksBatch.cs b/src/Nethermind/Nethermind.Synchronization/FastBlocks/FastBlocksBatch.cs index 776c9666674..2df793393d3 100644 --- a/src/Nethermind/Nethermind.Synchronization/FastBlocks/FastBlocksBatch.cs +++ b/src/Nethermind/Nethermind.Synchronization/FastBlocks/FastBlocksBatch.cs @@ -8,7 +8,7 @@ namespace Nethermind.Synchronization.FastBlocks { public abstract class FastBlocksBatch { - private Stopwatch _stopwatch = new(); + private readonly Stopwatch _stopwatch = new(); private long? _scheduledLastTime; private long? _requestSentTime; private long? _validationStartTime; diff --git a/src/Nethermind/Nethermind.Synchronization/FastBlocks/FastBlocksSelectionStrategy.cs b/src/Nethermind/Nethermind.Synchronization/FastBlocks/FastBlocksSelectionStrategy.cs index 42df6cdbe20..7964397e791 100644 --- a/src/Nethermind/Nethermind.Synchronization/FastBlocks/FastBlocksSelectionStrategy.cs +++ b/src/Nethermind/Nethermind.Synchronization/FastBlocks/FastBlocksSelectionStrategy.cs @@ -24,8 +24,8 @@ public FastBlocksAllocationStrategy(TransferSpeedType speedType, long? minNumber _fastest = new BySpeedStrategy(speedType, true); } - private IPeerAllocationStrategy _slowest; - private IPeerAllocationStrategy _fastest; + private readonly IPeerAllocationStrategy _slowest; + private readonly IPeerAllocationStrategy _fastest; public bool CanBeReplaced => false; diff --git a/src/Nethermind/Nethermind.Synchronization/FastBlocks/HeadersSyncDownloader.cs b/src/Nethermind/Nethermind.Synchronization/FastBlocks/HeadersSyncDownloader.cs index 89548d213cf..bd07183f502 100644 --- a/src/Nethermind/Nethermind.Synchronization/FastBlocks/HeadersSyncDownloader.cs +++ b/src/Nethermind/Nethermind.Synchronization/FastBlocks/HeadersSyncDownloader.cs @@ -13,7 +13,7 @@ namespace Nethermind.Synchronization.FastBlocks { public class HeadersSyncDownloader : ISyncDownloader { - private ILogger Logger; + private readonly ILogger Logger; public HeadersSyncDownloader(ILogManager logManager) { diff --git a/src/Nethermind/Nethermind.Synchronization/FastBlocks/ReceiptsSyncDownloader.cs b/src/Nethermind/Nethermind.Synchronization/FastBlocks/ReceiptsSyncDownloader.cs index 12570ba0323..bf8ae6c037f 100644 --- a/src/Nethermind/Nethermind.Synchronization/FastBlocks/ReceiptsSyncDownloader.cs +++ b/src/Nethermind/Nethermind.Synchronization/FastBlocks/ReceiptsSyncDownloader.cs @@ -16,7 +16,7 @@ namespace Nethermind.Synchronization.FastBlocks { public class ReceiptsSyncDispatcher : ISyncDownloader { - private ILogger Logger; + private readonly ILogger Logger; public ReceiptsSyncDispatcher(ILogManager logManager) { diff --git a/src/Nethermind/Nethermind.Synchronization/FastSync/BranchProgress.cs b/src/Nethermind/Nethermind.Synchronization/FastSync/BranchProgress.cs index 672c7edb6c5..e8448618a89 100644 --- a/src/Nethermind/Nethermind.Synchronization/FastSync/BranchProgress.cs +++ b/src/Nethermind/Nethermind.Synchronization/FastSync/BranchProgress.cs @@ -19,8 +19,8 @@ namespace Nethermind.Synchronization.FastSync /// internal class BranchProgress { - private ILogger _logger; - private NodeProgressState[] _syncProgress; + private readonly ILogger _logger; + private readonly NodeProgressState[] _syncProgress; public decimal LastProgress { get; private set; } public long CurrentSyncBlock { get; } diff --git a/src/Nethermind/Nethermind.Synchronization/FastSync/PendingSyncItems.cs b/src/Nethermind/Nethermind.Synchronization/FastSync/PendingSyncItems.cs index 93a504eff08..2cd79d10912 100644 --- a/src/Nethermind/Nethermind.Synchronization/FastSync/PendingSyncItems.cs +++ b/src/Nethermind/Nethermind.Synchronization/FastSync/PendingSyncItems.cs @@ -25,7 +25,7 @@ internal interface IPendingSyncItems internal class PendingSyncItems : IPendingSyncItems { - private ConcurrentStack[] _allStacks = new ConcurrentStack[7]; + private readonly ConcurrentStack[] _allStacks = new ConcurrentStack[7]; private ConcurrentStack CodeItems => _allStacks[0]; diff --git a/src/Nethermind/Nethermind.Synchronization/FastSync/TreeSync.cs b/src/Nethermind/Nethermind.Synchronization/FastSync/TreeSync.cs index 7fa40f87319..ac11401f63b 100644 --- a/src/Nethermind/Nethermind.Synchronization/FastSync/TreeSync.cs +++ b/src/Nethermind/Nethermind.Synchronization/FastSync/TreeSync.cs @@ -43,7 +43,7 @@ public class TreeSync private long _currentSyncStartSecondsInSync; private DateTime _lastResetRoot = DateTime.UtcNow - TimeSpan.FromHours(1); - private TimeSpan _minTimeBetweenReset = TimeSpan.FromMinutes(2); + private readonly TimeSpan _minTimeBetweenReset = TimeSpan.FromMinutes(2); private readonly ReaderWriterLockSlim _stateDbLock = new(); private readonly ReaderWriterLockSlim _codeDbLock = new(); @@ -66,14 +66,14 @@ public class TreeSync private readonly ReaderWriterLockSlim _syncStateLock = new(); private readonly ConcurrentDictionary _pendingRequests = new(); private Dictionary> _dependencies = new(); - private LruKeyCache _alreadySavedNode = new(AlreadySavedCapacity, "saved nodes"); - private LruKeyCache _alreadySavedCode = new(AlreadySavedCapacity, "saved nodes"); + private readonly LruKeyCache _alreadySavedNode = new(AlreadySavedCapacity, "saved nodes"); + private readonly LruKeyCache _alreadySavedCode = new(AlreadySavedCapacity, "saved nodes"); private readonly HashSet _codesSameAsNodes = new(); private BranchProgress _branchProgress; private int _hintsToResetRoot; private long _blockNumber; - private SyncMode _syncMode; + private readonly SyncMode _syncMode; public TreeSync(SyncMode syncMode, IDb codeDb, IDb stateDb, IBlockTree blockTree, ILogManager logManager) { diff --git a/src/Nethermind/Nethermind.Synchronization/LesSync/ChtProofCollector.cs b/src/Nethermind/Nethermind.Synchronization/LesSync/ChtProofCollector.cs index b1784da86e8..910c5a1473e 100644 --- a/src/Nethermind/Nethermind.Synchronization/LesSync/ChtProofCollector.cs +++ b/src/Nethermind/Nethermind.Synchronization/LesSync/ChtProofCollector.cs @@ -8,7 +8,7 @@ namespace Nethermind.Synchronization.LesSync { class ChtProofCollector : ProofCollector { - long _fromLevel; + readonly long _fromLevel; long _level; public ChtProofCollector(byte[] key, long fromLevel) : base(key) { diff --git a/src/Nethermind/Nethermind.Synchronization/MallocTrimmer.cs b/src/Nethermind/Nethermind.Synchronization/MallocTrimmer.cs index 4574e37c9b9..63c6e85e36c 100644 --- a/src/Nethermind/Nethermind.Synchronization/MallocTrimmer.cs +++ b/src/Nethermind/Nethermind.Synchronization/MallocTrimmer.cs @@ -13,8 +13,8 @@ namespace Nethermind.Synchronization; public class MallocTrimmer { - private MallocHelper _mallocHelper; - private ILogger _logger; + private readonly MallocHelper _mallocHelper; + private readonly ILogger _logger; public MallocTrimmer( ISyncModeSelector syncModeSelector, diff --git a/src/Nethermind/Nethermind.Synchronization/ParallelSync/ActivatedSyncFeed.cs b/src/Nethermind/Nethermind.Synchronization/ParallelSync/ActivatedSyncFeed.cs index 5365b924f84..936a140f84e 100644 --- a/src/Nethermind/Nethermind.Synchronization/ParallelSync/ActivatedSyncFeed.cs +++ b/src/Nethermind/Nethermind.Synchronization/ParallelSync/ActivatedSyncFeed.cs @@ -7,7 +7,7 @@ namespace Nethermind.Synchronization.ParallelSync { public abstract class ActivatedSyncFeed : SyncFeed, IDisposable { - private bool _disposed = false; + private readonly bool _disposed = false; protected ActivatedSyncFeed() { diff --git a/src/Nethermind/Nethermind.Synchronization/Peers/SyncPeersReport.cs b/src/Nethermind/Nethermind.Synchronization/Peers/SyncPeersReport.cs index 5f80e4a9699..b3e4d4f3ba1 100644 --- a/src/Nethermind/Nethermind.Synchronization/Peers/SyncPeersReport.cs +++ b/src/Nethermind/Nethermind.Synchronization/Peers/SyncPeersReport.cs @@ -16,7 +16,7 @@ namespace Nethermind.Synchronization.Peers /// internal class SyncPeersReport { - private StringBuilder _stringBuilder = new(); + private readonly StringBuilder _stringBuilder = new(); private int _currentInitializedPeerCount; private readonly ISyncPeerPool _peerPool; @@ -33,7 +33,7 @@ public SyncPeersReport(ISyncPeerPool peerPool, INodeStatsManager statsManager, I } } - private object _writeLock = new(); + private readonly object _writeLock = new(); private IEnumerable OrderedPeers => _peerPool.InitializedPeers .OrderByDescending(p => p.SyncPeer?.HeadNumber) diff --git a/src/Nethermind/Nethermind.Synchronization/SnapSync/SnapSyncDownloader.cs b/src/Nethermind/Nethermind.Synchronization/SnapSync/SnapSyncDownloader.cs index 7a9c95a8612..57cc1de379a 100644 --- a/src/Nethermind/Nethermind.Synchronization/SnapSync/SnapSyncDownloader.cs +++ b/src/Nethermind/Nethermind.Synchronization/SnapSync/SnapSyncDownloader.cs @@ -13,7 +13,7 @@ namespace Nethermind.Synchronization.SnapSync { public class SnapSyncDownloader : ISyncDownloader { - private ILogger Logger; + private readonly ILogger Logger; public SnapSyncDownloader(ILogManager? logManager) { diff --git a/src/Nethermind/Nethermind.Synchronization/StateSync/StateSyncDownloader.cs b/src/Nethermind/Nethermind.Synchronization/StateSync/StateSyncDownloader.cs index 13a404b1aef..f11f39409f5 100644 --- a/src/Nethermind/Nethermind.Synchronization/StateSync/StateSyncDownloader.cs +++ b/src/Nethermind/Nethermind.Synchronization/StateSync/StateSyncDownloader.cs @@ -21,7 +21,7 @@ namespace Nethermind.Synchronization.StateSync { public class StateSyncDownloader : ISyncDownloader { - private ILogger Logger; + private readonly ILogger Logger; public StateSyncDownloader(ILogManager logManager) { @@ -212,7 +212,7 @@ public IEnumerator GetEnumerator() /// private sealed class KeccakToValueKeccakList : IReadOnlyList { - private HashList _innerList; + private readonly HashList _innerList; internal KeccakToValueKeccakList(HashList innerList) { diff --git a/src/Nethermind/Nethermind.Synchronization/Synchronizer.cs b/src/Nethermind/Nethermind.Synchronization/Synchronizer.cs index d74a06f8fff..3fa163e643f 100644 --- a/src/Nethermind/Nethermind.Synchronization/Synchronizer.cs +++ b/src/Nethermind/Nethermind.Synchronization/Synchronizer.cs @@ -56,7 +56,7 @@ public class Synchronizer : ISynchronizer private FastSyncFeed? _fastSyncFeed; private StateSyncFeed? _stateSyncFeed; private FullSyncFeed? _fullSyncFeed; - private IProcessExitSource _exitSource; + private readonly IProcessExitSource _exitSource; protected IBetterPeerStrategy _betterPeerStrategy; private readonly ChainSpec _chainSpec; diff --git a/src/Nethermind/Nethermind.Trie.Test/Pruning/TreeStoreTests.cs b/src/Nethermind/Nethermind.Trie.Test/Pruning/TreeStoreTests.cs index ee3fd30a147..a381ae4ad3f 100644 --- a/src/Nethermind/Nethermind.Trie.Test/Pruning/TreeStoreTests.cs +++ b/src/Nethermind/Nethermind.Trie.Test/Pruning/TreeStoreTests.cs @@ -393,7 +393,7 @@ public void Will_get_dropped_on_snapshot_if_it_was_a_transient_node() private class BadDb : IKeyValueStoreWithBatching { - private Dictionary _db = new(); + private readonly Dictionary _db = new(); public byte[]? this[ReadOnlySpan key] { @@ -418,7 +418,7 @@ public IWriteBatch StartWriteBatch() private class BadWriteBatch : IWriteBatch { - private Dictionary _inBatched = new(); + private readonly Dictionary _inBatched = new(); public void Dispose() { @@ -446,7 +446,7 @@ public void Trie_store_multi_threaded_scenario() tree.Set(TestItem.AddressB, Build.A.Account.WithBalance(1000).TestObject); } - private AccountDecoder _accountDecoder = new(); + private readonly AccountDecoder _accountDecoder = new(); [Test] public void Will_store_storage_on_snapshot() diff --git a/src/Nethermind/Nethermind.Trie.Test/PruningScenariosTests.cs b/src/Nethermind/Nethermind.Trie.Test/PruningScenariosTests.cs index 16fb682cb6a..9ce405ed6a5 100644 --- a/src/Nethermind/Nethermind.Trie.Test/PruningScenariosTests.cs +++ b/src/Nethermind/Nethermind.Trie.Test/PruningScenariosTests.cs @@ -30,15 +30,15 @@ Analysis of branch / extension might be more difficult because of the hashing of public class PruningContext { private long _blockNumber = 1; - private Dictionary _branchingPoints = new(); - private IDbProvider _dbProvider; + private readonly Dictionary _branchingPoints = new(); + private readonly IDbProvider _dbProvider; private IWorldState _stateProvider; private IStateReader _stateReader; - private ILogManager _logManager; - private ILogger _logger; + private readonly ILogManager _logManager; + private readonly ILogger _logger; private TrieStore _trieStore; - private IPersistenceStrategy _persistenceStrategy; - private TestPruningStrategy _pruningStrategy; + private readonly IPersistenceStrategy _persistenceStrategy; + private readonly TestPruningStrategy _pruningStrategy; [DebuggerStepThrough] private PruningContext(TestPruningStrategy pruningStrategy, IPersistenceStrategy persistenceStrategy) diff --git a/src/Nethermind/Nethermind.Trie.Test/TrieTests.cs b/src/Nethermind/Nethermind.Trie.Test/TrieTests.cs index 692c71bef1c..dbc8afd111f 100644 --- a/src/Nethermind/Nethermind.Trie.Test/TrieTests.cs +++ b/src/Nethermind/Nethermind.Trie.Test/TrieTests.cs @@ -49,10 +49,10 @@ private static readonly byte[] _longLeaf2 private static readonly byte[] _longLeaf3 = Bytes.FromHexString("0000000000000000000000000000000000000000000000000000000000000000000000000000000003"); - private static byte[] _keyA = Bytes.FromHexString("000000000000000aa"); - private static byte[] _keyB = Bytes.FromHexString("000000000000000bb"); - private static byte[] _keyC = Bytes.FromHexString("000000000000001aa"); - private static byte[] _keyD = Bytes.FromHexString("000000000000001bb"); + private static readonly byte[] _keyA = Bytes.FromHexString("000000000000000aa"); + private static readonly byte[] _keyB = Bytes.FromHexString("000000000000000bb"); + private static readonly byte[] _keyC = Bytes.FromHexString("000000000000001aa"); + private static readonly byte[] _keyD = Bytes.FromHexString("000000000000001bb"); [Test] public void Single_leaf() diff --git a/src/Nethermind/Nethermind.Trie/BatchedTrieVisitor.cs b/src/Nethermind/Nethermind.Trie/BatchedTrieVisitor.cs index 649cc8b8c09..5c93e9f9035 100644 --- a/src/Nethermind/Nethermind.Trie/BatchedTrieVisitor.cs +++ b/src/Nethermind/Nethermind.Trie/BatchedTrieVisitor.cs @@ -40,8 +40,8 @@ namespace Nethermind.Trie; public class BatchedTrieVisitor { // Not using shared pool so GC can reclaim them later. - private ArrayPool _jobArrayPool = ArrayPool.Create(); - private ArrayPool<(TrieNode, SmallTrieVisitContext)> _trieNodePool = ArrayPool<(TrieNode, SmallTrieVisitContext)>.Create(); + private readonly ArrayPool _jobArrayPool = ArrayPool.Create(); + private readonly ArrayPool<(TrieNode, SmallTrieVisitContext)> _trieNodePool = ArrayPool<(TrieNode, SmallTrieVisitContext)>.Create(); private readonly int _maxBatchSize; private readonly long _partitionCount; @@ -52,7 +52,7 @@ public class BatchedTrieVisitor private long _queuedJobs; private bool _failed; private long _currentPointer; - private long _readAheadThreshold; + private readonly long _readAheadThreshold; private readonly ITrieNodeResolver _resolver; private readonly ITreeVisitor _visitor; diff --git a/src/Nethermind/Nethermind.Trie/Nibbles.cs b/src/Nethermind/Nethermind.Trie/Nibbles.cs index f327d14aaab..d5470e2f735 100644 --- a/src/Nethermind/Nethermind.Trie/Nibbles.cs +++ b/src/Nethermind/Nethermind.Trie/Nibbles.cs @@ -10,7 +10,7 @@ namespace Nethermind.Trie public struct Nibble { // ReSharper disable once FieldCanBeMadeReadOnly.Local - private byte _nibble; + private readonly byte _nibble; public Nibble(char hexChar) { diff --git a/src/Nethermind/Nethermind.Trie/Pruning/TrieStore.cs b/src/Nethermind/Nethermind.Trie/Pruning/TrieStore.cs index 976483b4172..5c8ddadc909 100644 --- a/src/Nethermind/Nethermind.Trie/Pruning/TrieStore.cs +++ b/src/Nethermind/Nethermind.Trie/Pruning/TrieStore.cs @@ -131,7 +131,7 @@ public void Clear() private bool _lastPersistedReachedReorgBoundary; private Task _pruningTask = Task.CompletedTask; - private CancellationTokenSource _pruningTaskCancellationTokenSource = new(); + private readonly CancellationTokenSource _pruningTaskCancellationTokenSource = new(); public TrieStore(IKeyValueStoreWithBatching? keyValueStore, ILogManager? logManager) : this(keyValueStore, No.Pruning, Pruning.Persist.EveryBlock, logManager) diff --git a/src/Nethermind/Nethermind.Trie/TrackingCappedArrayPool.cs b/src/Nethermind/Nethermind.Trie/TrackingCappedArrayPool.cs index a26edd82ad7..73c8c41d525 100644 --- a/src/Nethermind/Nethermind.Trie/TrackingCappedArrayPool.cs +++ b/src/Nethermind/Nethermind.Trie/TrackingCappedArrayPool.cs @@ -14,8 +14,8 @@ namespace Nethermind.Trie; /// public class TrackingCappedArrayPool : ICappedArrayPool { - private List> _rentedBuffers; - private ArrayPool _arrayPool; + private readonly List> _rentedBuffers; + private readonly ArrayPool _arrayPool; public TrackingCappedArrayPool() : this(0) { diff --git a/src/Nethermind/Nethermind.Trie/TreeDumper.cs b/src/Nethermind/Nethermind.Trie/TreeDumper.cs index 7607fcfcc1a..a879ea85207 100644 --- a/src/Nethermind/Nethermind.Trie/TreeDumper.cs +++ b/src/Nethermind/Nethermind.Trie/TreeDumper.cs @@ -11,7 +11,7 @@ namespace Nethermind.Trie { public class TreeDumper : ITreeVisitor { - private StringBuilder _builder = new(); + private readonly StringBuilder _builder = new(); public void Reset() { @@ -57,7 +57,7 @@ public void VisitExtension(TrieNode node, TrieVisitContext trieVisitContext) _builder.AppendLine($"{GetPrefix(trieVisitContext)}EXTENSION {Nibbles.FromBytes(node.Key).ToPackedByteArray().ToHexString(false)} -> {KeccakOrRlpStringOfNode(node)}"); } - private AccountDecoder decoder = new(); + private readonly AccountDecoder decoder = new(); public void VisitLeaf(TrieNode node, TrieVisitContext trieVisitContext, byte[] value = null) { diff --git a/src/Nethermind/Nethermind.Trie/TrieNode.cs b/src/Nethermind/Nethermind.Trie/TrieNode.cs index ca434b62076..9658389d4ce 100644 --- a/src/Nethermind/Nethermind.Trie/TrieNode.cs +++ b/src/Nethermind/Nethermind.Trie/TrieNode.cs @@ -29,9 +29,9 @@ public partial class TrieNode public bool IsBoundaryProofNode { get; set; } private TrieNode? _storageRoot; - private static object _nullNode = new(); - private static TrieNodeDecoder _nodeDecoder = new(); - private static AccountDecoder _accountDecoder = new(); + private static readonly object _nullNode = new(); + private static readonly TrieNodeDecoder _nodeDecoder = new(); + private static readonly AccountDecoder _accountDecoder = new(); private static Action _markPersisted => tn => tn.IsPersisted = true; private RlpStream? _rlpStream; private object?[]? _data; diff --git a/src/Nethermind/Nethermind.TxPool.Test/Collections/SortedPoolTests.cs b/src/Nethermind/Nethermind.TxPool.Test/Collections/SortedPoolTests.cs index 92c8efac751..3afceac09c3 100644 --- a/src/Nethermind/Nethermind.TxPool.Test/Collections/SortedPoolTests.cs +++ b/src/Nethermind/Nethermind.TxPool.Test/Collections/SortedPoolTests.cs @@ -26,7 +26,7 @@ public class SortedPoolTests private SortedPool _sortedPool; - private Transaction[] _transactions = new Transaction[Capacity * 8]; + private readonly Transaction[] _transactions = new Transaction[Capacity * 8]; [SetUp] public void Setup() diff --git a/src/Nethermind/Nethermind.TxPool.Test/TxPoolTests.cs b/src/Nethermind/Nethermind.TxPool.Test/TxPoolTests.cs index 6ad0f609cc9..6bd0ca3925f 100644 --- a/src/Nethermind/Nethermind.TxPool.Test/TxPoolTests.cs +++ b/src/Nethermind/Nethermind.TxPool.Test/TxPoolTests.cs @@ -44,7 +44,7 @@ public partial class TxPoolTests private IWorldState _stateProvider; private IBlockTree _blockTree; - private int _txGasLimit = 1_000_000; + private readonly int _txGasLimit = 1_000_000; [SetUp] public void Setup() diff --git a/src/Nethermind/Nethermind.UPnP.Plugin/UPnPPlugin.cs b/src/Nethermind/Nethermind.UPnP.Plugin/UPnPPlugin.cs index 2f0a4b40457..ea06514e3af 100644 --- a/src/Nethermind/Nethermind.UPnP.Plugin/UPnPPlugin.cs +++ b/src/Nethermind/Nethermind.UPnP.Plugin/UPnPPlugin.cs @@ -18,7 +18,7 @@ public class UPnPPlugin : INethermindPlugin // Routers tend to clean mapping, so we need to periodically private readonly TimeSpan ExpirationRate = TimeSpan.FromMinutes(10); private PeriodicTimer? _timer = null; - private CancellationTokenSource _cancellationTokenSource = new(); + private readonly CancellationTokenSource _cancellationTokenSource = new(); private INetworkConfig _networkConfig = new NetworkConfig(); private ILogger _logger = NullLogger.Instance; diff --git a/src/Nethermind/Nethermind.Wallet.Test/AccountUnlockerTests.cs b/src/Nethermind/Nethermind.Wallet.Test/AccountUnlockerTests.cs index 97f9adea07c..1a7162fc9b4 100644 --- a/src/Nethermind/Nethermind.Wallet.Test/AccountUnlockerTests.cs +++ b/src/Nethermind/Nethermind.Wallet.Test/AccountUnlockerTests.cs @@ -19,7 +19,7 @@ namespace Nethermind.Wallet.Test { public class AccountUnlockerTests { - private static List<(string Name, string Content)> _files = new List<(string Name, string Content)>() + private static readonly List<(string Name, string Content)> _files = new List<(string Name, string Content)>() { ("TestingFileF1", "PF1"), ("TestingFileF2", "PF2") diff --git a/src/Nethermind/Nethermind.Wallet/DevWallet.cs b/src/Nethermind/Nethermind.Wallet/DevWallet.cs index 64e99519384..6971df3af7a 100644 --- a/src/Nethermind/Nethermind.Wallet/DevWallet.cs +++ b/src/Nethermind/Nethermind.Wallet/DevWallet.cs @@ -17,11 +17,11 @@ namespace Nethermind.Wallet public class DevWallet : IWallet { private const string AnyPassword = "#DEV_ACCOUNT_NETHERMIND_ANY_PASSWORD#"; - private static byte[] _keySeed = new byte[32]; + private static readonly byte[] _keySeed = new byte[32]; private readonly ILogger _logger; - private Dictionary _isUnlocked = new Dictionary(); - private Dictionary _keys = new Dictionary(); - private Dictionary _passwords = new Dictionary(); + private readonly Dictionary _isUnlocked = new Dictionary(); + private readonly Dictionary _keys = new Dictionary(); + private readonly Dictionary _passwords = new Dictionary(); public event EventHandler AccountLocked; public event EventHandler AccountUnlocked;