From 3541107ebafed0b8777527f508f98a735f08bd0d Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 11 Dec 2024 22:48:22 +0000 Subject: [PATCH] Use Ordinal rather than InvariantCulture --- .../Nethermind.Blockchain/Find/BlockParameter.cs | 10 +++++----- src/Nethermind/Nethermind.Config/ConfigProvider.cs | 2 +- src/Nethermind/Nethermind.Config/ConfigSourceHelper.cs | 2 +- .../Nethermind.Consensus/Processing/BlockExtensions.cs | 2 +- .../Nethermind.JsonRpc.Test/JsonRpcLocalStats.cs | 4 ++-- src/Nethermind/Nethermind.JsonRpc/JsonRpcUrl.cs | 2 +- .../Nethermind.JsonRpc/JsonRpcUrlCollection.cs | 2 +- .../Modules/Eth/TransactionsOption.cs | 4 ++-- src/Nethermind/Nethermind.KeyStore/FileKeyStore.cs | 2 +- src/Nethermind/Nethermind.Logging/PathUtils.cs | 4 ++-- src/Nethermind/Nethermind.Merge.Plugin/MergePlugin.cs | 6 +++--- src/Nethermind/Nethermind.Network.Dns/EnrTreeParser.cs | 8 ++++---- .../StaticNodes/StaticNodesManager.cs | 2 +- .../Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs | 2 +- 14 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/Nethermind/Nethermind.Blockchain/Find/BlockParameter.cs b/src/Nethermind/Nethermind.Blockchain/Find/BlockParameter.cs index b646bb29407..cf6136e7d67 100644 --- a/src/Nethermind/Nethermind.Blockchain/Find/BlockParameter.cs +++ b/src/Nethermind/Nethermind.Blockchain/Find/BlockParameter.cs @@ -300,15 +300,15 @@ public static BlockParameter GetBlockParameter(string? value) { case null: case { } empty when string.IsNullOrWhiteSpace(empty): - case { } latest when latest.Equals("latest", StringComparison.InvariantCultureIgnoreCase): + case { } latest when latest.Equals("latest", StringComparison.OrdinalIgnoreCase): return BlockParameter.Latest; - case { } earliest when earliest.Equals("earliest", StringComparison.InvariantCultureIgnoreCase): + case { } earliest when earliest.Equals("earliest", StringComparison.OrdinalIgnoreCase): return BlockParameter.Earliest; - case { } pending when pending.Equals("pending", StringComparison.InvariantCultureIgnoreCase): + case { } pending when pending.Equals("pending", StringComparison.OrdinalIgnoreCase): return BlockParameter.Pending; - case { } finalized when finalized.Equals("finalized", StringComparison.InvariantCultureIgnoreCase): + case { } finalized when finalized.Equals("finalized", StringComparison.OrdinalIgnoreCase): return BlockParameter.Finalized; - case { } safe when safe.Equals("safe", StringComparison.InvariantCultureIgnoreCase): + case { } safe when safe.Equals("safe", StringComparison.OrdinalIgnoreCase): return BlockParameter.Safe; case { Length: 66 } hash when hash.StartsWith("0x"): return new BlockParameter(new Hash256(hash)); diff --git a/src/Nethermind/Nethermind.Config/ConfigProvider.cs b/src/Nethermind/Nethermind.Config/ConfigProvider.cs index ce5b5100184..d9459720657 100644 --- a/src/Nethermind/Nethermind.Config/ConfigProvider.cs +++ b/src/Nethermind/Nethermind.Config/ConfigProvider.cs @@ -53,7 +53,7 @@ public object GetRawValue(string category, string name) return Categories.TryGetValue(category, out object value) ? value.GetType() .GetProperties(BindingFlags.Instance | BindingFlags.Public) - .SingleOrDefault(p => string.Equals(p.Name, name, StringComparison.InvariantCultureIgnoreCase)) + .SingleOrDefault(p => string.Equals(p.Name, name, StringComparison.OrdinalIgnoreCase)) ?.GetValue(value) : null; } diff --git a/src/Nethermind/Nethermind.Config/ConfigSourceHelper.cs b/src/Nethermind/Nethermind.Config/ConfigSourceHelper.cs index 462e5ca74fa..5edfede868b 100644 --- a/src/Nethermind/Nethermind.Config/ConfigSourceHelper.cs +++ b/src/Nethermind/Nethermind.Config/ConfigSourceHelper.cs @@ -99,7 +99,7 @@ public static object ParseValue(Type valueType, string valueString, string categ } private static bool IsNullString(string valueString) => - string.IsNullOrEmpty(valueString) || valueString.Equals("null", StringComparison.InvariantCultureIgnoreCase); + string.IsNullOrEmpty(valueString) || valueString.Equals("null", StringComparison.OrdinalIgnoreCase); public static object GetDefault(Type type) => type.IsValueType ? (false, Activator.CreateInstance(type)) : (false, null); diff --git a/src/Nethermind/Nethermind.Consensus/Processing/BlockExtensions.cs b/src/Nethermind/Nethermind.Consensus/Processing/BlockExtensions.cs index a0287bb1d0f..bf3e081e048 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/BlockExtensions.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/BlockExtensions.cs @@ -40,7 +40,7 @@ public static bool TrySetTransactions(this Block block, Transaction[] transactio public static bool IsByNethermindNode(this BlockHeader block) => Ascii.IsValid(block.ExtraData) && Encoding.ASCII.GetString(block.ExtraData ?? []) - .Contains(BlocksConfig.DefaultExtraData, StringComparison.InvariantCultureIgnoreCase); + .Contains(BlocksConfig.DefaultExtraData, StringComparison.OrdinalIgnoreCase); public static string ParsedExtraData(this Block block) { diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/JsonRpcLocalStats.cs b/src/Nethermind/Nethermind.JsonRpc.Test/JsonRpcLocalStats.cs index 8365e784e7f..20bfc3a8e3a 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/JsonRpcLocalStats.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/JsonRpcLocalStats.cs @@ -149,8 +149,8 @@ public async Task Orders_alphabetically() await localStats.ReportCall("B", 3, false); MakeTimePass(); await localStats.ReportCall("A", 300, true); - _testLogger.LogList[0].IndexOf("A ", StringComparison.InvariantCulture).Should().BeLessThan(_testLogger.LogList[0].IndexOf("B ", StringComparison.InvariantCulture)); - _testLogger.LogList[0].IndexOf("B ", StringComparison.InvariantCulture).Should().BeLessThan(_testLogger.LogList[0].IndexOf("C ", StringComparison.InvariantCulture)); + _testLogger.LogList[0].IndexOf("A ", StringComparison.Ordinal).Should().BeLessThan(_testLogger.LogList[0].IndexOf("B ", StringComparison.Ordinal)); + _testLogger.LogList[0].IndexOf("B ", StringComparison.Ordinal).Should().BeLessThan(_testLogger.LogList[0].IndexOf("C ", StringComparison.Ordinal)); } private void MakeTimePass(int seconds) diff --git a/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrl.cs b/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrl.cs index 8d3fb8498bd..f3777012d62 100644 --- a/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrl.cs +++ b/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrl.cs @@ -58,7 +58,7 @@ public static JsonRpcUrl Parse(string packedUrlValue) if (enabledModules.Length == 0) throw new FormatException("Third part must contain at least one module delimited by ';'"); - bool isAuthenticated = enabledModules.Contains(ModuleType.Engine, StringComparison.InvariantCultureIgnoreCase); + bool isAuthenticated = enabledModules.Contains(ModuleType.Engine, StringComparison.OrdinalIgnoreCase); // Check if authentication disabled for this url if (parts.Length == 4) diff --git a/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs b/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs index b7a60475d2f..81af1e31b4f 100644 --- a/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs +++ b/src/Nethermind/Nethermind.JsonRpc/JsonRpcUrlCollection.cs @@ -30,7 +30,7 @@ public JsonRpcUrlCollection(ILogManager logManager, IJsonRpcConfig jsonRpcConfig private void BuildUrls(bool includeWebSockets) { - bool HasEngineApi = _jsonRpcConfig.EnabledModules.Any(m => m.Equals(ModuleType.Engine, StringComparison.InvariantCultureIgnoreCase)); + bool HasEngineApi = _jsonRpcConfig.EnabledModules.Any(m => m.Equals(ModuleType.Engine, StringComparison.OrdinalIgnoreCase)); JsonRpcUrl defaultUrl = new(Uri.UriSchemeHttp, _jsonRpcConfig.Host, _jsonRpcConfig.Port, RpcEndpoint.Http, HasEngineApi, _jsonRpcConfig.EnabledModules, HasEngineApi ? SocketClient.MAX_REQUEST_BODY_SIZE_FOR_ENGINE_API : _jsonRpcConfig.MaxRequestBodySize); Add(defaultUrl.Port, defaultUrl); diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/TransactionsOption.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/TransactionsOption.cs index 8dceee0a0c9..63c01c5a3f7 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/TransactionsOption.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/TransactionsOption.cs @@ -42,8 +42,8 @@ public void ReadJson(JsonElement jsonValue, JsonSerializerOptions options) } string? text = jsonValue.GetString(); - bool isTrue = string.Equals(text, bool.TrueString, StringComparison.InvariantCultureIgnoreCase); - bool isFalse = string.Equals(text, bool.FalseString, StringComparison.InvariantCultureIgnoreCase); + bool isTrue = string.Equals(text, bool.TrueString, StringComparison.OrdinalIgnoreCase); + bool isFalse = string.Equals(text, bool.FalseString, StringComparison.OrdinalIgnoreCase); IncludeTransactions = isTrue || isFalse ? isTrue diff --git a/src/Nethermind/Nethermind.KeyStore/FileKeyStore.cs b/src/Nethermind/Nethermind.KeyStore/FileKeyStore.cs index 937fe237588..65b9937fe4b 100644 --- a/src/Nethermind/Nethermind.KeyStore/FileKeyStore.cs +++ b/src/Nethermind/Nethermind.KeyStore/FileKeyStore.cs @@ -71,7 +71,7 @@ public FileKeyStore( _jsonSerializer = jsonSerializer ?? throw new ArgumentNullException(nameof(jsonSerializer)); _symmetricEncrypter = symmetricEncrypter ?? throw new ArgumentNullException(nameof(symmetricEncrypter)); _cryptoRandom = cryptoRandom ?? throw new ArgumentNullException(nameof(cryptoRandom)); - _keyStoreEncoding = _config.KeyStoreEncoding.Equals("UTF-8", StringComparison.InvariantCultureIgnoreCase) + _keyStoreEncoding = _config.KeyStoreEncoding.Equals("UTF-8", StringComparison.OrdinalIgnoreCase) ? new UTF8Encoding(false) : Encoding.GetEncoding(_config.KeyStoreEncoding); _privateKeyGenerator = new PrivateKeyGenerator(_cryptoRandom); diff --git a/src/Nethermind/Nethermind.Logging/PathUtils.cs b/src/Nethermind/Nethermind.Logging/PathUtils.cs index 9a16cedbfca..564d531032a 100644 --- a/src/Nethermind/Nethermind.Logging/PathUtils.cs +++ b/src/Nethermind/Nethermind.Logging/PathUtils.cs @@ -16,8 +16,8 @@ public static class PathUtils static PathUtils() { Process process = Process.GetCurrentProcess(); - if (process.ProcessName.StartsWith("dotnet", StringComparison.InvariantCultureIgnoreCase) - || process.ProcessName.Equals("ReSharperTestRunner", StringComparison.InvariantCultureIgnoreCase)) + if (process.ProcessName.StartsWith("dotnet", StringComparison.OrdinalIgnoreCase) + || process.ProcessName.Equals("ReSharperTestRunner", StringComparison.OrdinalIgnoreCase)) { ExecutingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); } diff --git a/src/Nethermind/Nethermind.Merge.Plugin/MergePlugin.cs b/src/Nethermind/Nethermind.Merge.Plugin/MergePlugin.cs index 8e7789d913d..f96a6ece876 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/MergePlugin.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/MergePlugin.cs @@ -192,14 +192,14 @@ private void EnsureJsonRpcUrl() EnsureEngineModuleIsConfigured(); - if (!jsonRpcConfig.EnabledModules.Contains(ModuleType.Engine, StringComparison.InvariantCultureIgnoreCase)) + if (!jsonRpcConfig.EnabledModules.Contains(ModuleType.Engine, StringComparison.OrdinalIgnoreCase)) { // Disable it jsonRpcConfig.EnabledModules = []; } jsonRpcConfig.AdditionalRpcUrls = jsonRpcConfig.AdditionalRpcUrls - .Where((url) => JsonRpcUrl.Parse(url).EnabledModules.Contains(ModuleType.Engine, StringComparison.InvariantCultureIgnoreCase)) + .Where((url) => JsonRpcUrl.Parse(url).EnabledModules.Contains(ModuleType.Engine, StringComparison.OrdinalIgnoreCase)) .ToArray(); } else @@ -213,7 +213,7 @@ private void EnsureEngineModuleIsConfigured() JsonRpcUrlCollection urlCollection = new(_api.LogManager, _api.Config(), false); bool hasEngineApiConfigured = urlCollection .Values - .Any(rpcUrl => rpcUrl.EnabledModules.Contains(ModuleType.Engine, StringComparison.InvariantCultureIgnoreCase)); + .Any(rpcUrl => rpcUrl.EnabledModules.Contains(ModuleType.Engine, StringComparison.OrdinalIgnoreCase)); if (!hasEngineApiConfigured) { diff --git a/src/Nethermind/Nethermind.Network.Dns/EnrTreeParser.cs b/src/Nethermind/Nethermind.Network.Dns/EnrTreeParser.cs index 7a5385bc493..884f844e9a6 100644 --- a/src/Nethermind/Nethermind.Network.Dns/EnrTreeParser.cs +++ b/src/Nethermind/Nethermind.Network.Dns/EnrTreeParser.cs @@ -62,17 +62,17 @@ public static EnrTreeRoot ParseEnrRoot(string enrTreeRootText) EnrTreeRoot enrTreeRoot = new(); - int ensRootIndex = enrTreeRootText.IndexOf("e=", StringComparison.InvariantCulture); + int ensRootIndex = enrTreeRootText.IndexOf("e=", StringComparison.Ordinal); enrTreeRoot.EnrRoot = enrTreeRootText.Substring(ensRootIndex + 2, HashLengthBase32); - int linkRootIndex = enrTreeRootText.IndexOf("l=", StringComparison.InvariantCulture); + int linkRootIndex = enrTreeRootText.IndexOf("l=", StringComparison.Ordinal); enrTreeRoot.LinkRoot = enrTreeRootText.Substring(linkRootIndex + 2, HashLengthBase32); - int seqIndex = enrTreeRootText.IndexOf("seq=", StringComparison.InvariantCulture); + int seqIndex = enrTreeRootText.IndexOf("seq=", StringComparison.Ordinal); int seqLength = enrTreeRootText.IndexOf(' ', seqIndex) - (seqIndex + 4); enrTreeRoot.Sequence = int.Parse(enrTreeRootText.AsSpan(seqIndex + 4, seqLength)); - int sigIndex = enrTreeRootText.IndexOf("sig=", StringComparison.InvariantCulture); + int sigIndex = enrTreeRootText.IndexOf("sig=", StringComparison.Ordinal); enrTreeRoot.Signature = enrTreeRootText.Substring(sigIndex + 4, SigLengthBase32); return enrTreeRoot; diff --git a/src/Nethermind/Nethermind.Network/StaticNodes/StaticNodesManager.cs b/src/Nethermind/Nethermind.Network/StaticNodes/StaticNodesManager.cs index d4d9a3bdd06..18bb6c8c142 100644 --- a/src/Nethermind/Nethermind.Network/StaticNodes/StaticNodesManager.cs +++ b/src/Nethermind/Nethermind.Network/StaticNodes/StaticNodesManager.cs @@ -131,7 +131,7 @@ public bool IsStatic(string enode) { NetworkNode node = new(enode); return _nodes.TryGetValue(node.NodeId, out NetworkNode staticNode) && string.Equals(staticNode.Host, - node.Host, StringComparison.InvariantCultureIgnoreCase); + node.Host, StringComparison.OrdinalIgnoreCase); } private Task SaveFileAsync() diff --git a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs index 10ae78bd3f0..49f18d5ec7b 100644 --- a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs +++ b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs @@ -56,7 +56,7 @@ private void LoadParameters(ChainSpecJson chainSpecJson, ChainSpec chainSpec) { long? GetTransitions(string builtInName, Predicate> predicate) { - var allocation = chainSpecJson.Accounts?.Values.FirstOrDefault(v => v.BuiltIn?.Name.Equals(builtInName, StringComparison.InvariantCultureIgnoreCase) == true); + var allocation = chainSpecJson.Accounts?.Values.FirstOrDefault(v => v.BuiltIn?.Name.Equals(builtInName, StringComparison.OrdinalIgnoreCase) == true); if (allocation is null) return null; KeyValuePair[] pricing = allocation.BuiltIn.Pricing.Where(o => predicate(o)).ToArray(); if (pricing.Length > 0)