From 99c3dd2e39cf2c4a22193760459650977175de69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Moraczy=C5=84ski?= Date: Mon, 7 Oct 2024 18:14:00 +0200 Subject: [PATCH 01/12] t/s to tps in logs? (#7551) --- .../Nethermind.Consensus/Processing/ProcessingStats.cs | 6 +++--- src/Nethermind/Nethermind.Runner/NLog.config | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/Processing/ProcessingStats.cs b/src/Nethermind/Nethermind.Consensus/Processing/ProcessingStats.cs index fd4e888d9d5..48845fb904d 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/ProcessingStats.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/ProcessingStats.cs @@ -239,17 +239,17 @@ void IThreadPoolWorkItem.Execute() _logger.Info($"- Block{(chunkBlocks > 1 ? $"s {chunkBlocks,-9:N0}" : " ")}{(chunkBlocks == 1 ? mgasColor : "")} {chunkMGas,9:F2}{resetColor} MGas | {chunkTx,8:N0} txs | calls {callsColor}{chunkCalls,6:N0}{resetColor} {darkGreyText}({chunkEmptyCalls,3:N0}){resetColor} | sload {chunkSload,7:N0} | sstore {sstoreColor}{chunkSstore,6:N0}{resetColor} | create {createsColor}{chunkCreates,3:N0}{resetColor}{(currentSelfDestructs - _lastSelfDestructs > 0 ? $"{darkGreyText}({-(currentSelfDestructs - _lastSelfDestructs),3:N0}){resetColor}" : "")}"); if (recoveryQueue > 0 || processingQueue > 0) { - _logger.Info($"- Block throughput {mgasPerSecondColor}{mgasPerSecond,9:F2}{resetColor} MGas/s{(mgasPerSecond > 1000 ? "🔥" : " ")}| {txps,10:N1} t/s | {bps,7:F2} Blk/s | recover {recoveryQueue,5:N0} | process {processingQueue,5:N0}"); + _logger.Info($"- Block throughput {mgasPerSecondColor}{mgasPerSecond,9:F2}{resetColor} MGas/s{(mgasPerSecond > 1000 ? "🔥" : " ")}| {txps,10:N1} tps | {bps,7:F2} Blk/s | recover {recoveryQueue,5:N0} | process {processingQueue,5:N0}"); } else { - _logger.Info($"- Block throughput {mgasPerSecondColor}{mgasPerSecond,9:F2}{resetColor} MGas/s{(mgasPerSecond > 1000 ? "🔥" : " ")}| {txps,10:N1} t/s | {bps,7:F2} Blk/s | exec code {resetColor} from cache {cachedContractsUsed,7:N0} |{resetColor} new {contractsAnalysed,6:N0}"); + _logger.Info($"- Block throughput {mgasPerSecondColor}{mgasPerSecond,9:F2}{resetColor} MGas/s{(mgasPerSecond > 1000 ? "🔥" : " ")}| {txps,10:N1} tps | {bps,7:F2} Blk/s | exec code {resetColor} from cache {cachedContractsUsed,7:N0} |{resetColor} new {contractsAnalysed,6:N0}"); } // Only output the total throughput in debug mode if (_logger.IsDebug) { - _logger.Debug($"- Total throughput {totalMgasPerSecond,9:F2} MGas/s | {totalTxPerSecond,9:F2} t/s | {totalBlocksPerSecond,7:F2} Blk/s |⛽ Gas gwei: {Evm.Metrics.MinGasPrice:N2} .. {Math.Max(Evm.Metrics.MinGasPrice, Evm.Metrics.EstMedianGasPrice):N2} ({Evm.Metrics.AveGasPrice:N2}) .. {Evm.Metrics.MaxGasPrice:N2}"); + _logger.Debug($"- Total throughput {totalMgasPerSecond,9:F2} MGas/s | {totalTxPerSecond,9:F2} tps | {totalBlocksPerSecond,7:F2} Blk/s |⛽ Gas gwei: {Evm.Metrics.MinGasPrice:N2} .. {Math.Max(Evm.Metrics.MinGasPrice, Evm.Metrics.EstMedianGasPrice):N2} ({Evm.Metrics.AveGasPrice:N2}) .. {Evm.Metrics.MaxGasPrice:N2}"); } } diff --git a/src/Nethermind/Nethermind.Runner/NLog.config b/src/Nethermind/Nethermind.Runner/NLog.config index d99f39d9003..b9e3d620738 100644 --- a/src/Nethermind/Nethermind.Runner/NLog.config +++ b/src/Nethermind/Nethermind.Runner/NLog.config @@ -66,7 +66,7 @@ - + From dac7890798db879ce887ec384d75e378e0a56911 Mon Sep 17 00:00:00 2001 From: Shubham Sonthalia Date: Tue, 8 Oct 2024 01:01:30 +0530 Subject: [PATCH 02/12] 7553 get elapsed time refactoring (#7558) --- src/Nethermind/Nethermind.Cli/NodeManager.cs | 12 ++++------ .../CliqueBlockProducerTests.cs | 5 ++-- .../Nethermind.Evm.Test/Eip1153Tests.cs | 6 ++--- .../Proxy/DefaultHttpClient.cs | 6 ++--- .../Steps/EthereumStepsManager.cs | 9 ++++--- .../Steps/InitializePlugins.cs | 5 ++-- .../Nethermind.JsonRpc/JsonRpcProcessor.cs | 24 +++++++------------ .../WebSockets/JsonRpcSocketsClient.cs | 11 ++++----- .../EngineRpcModule.Paris.cs | 10 ++++---- .../Synchronization/MergeBlockDownloader.cs | 4 ++-- .../DiscoveryManagerTests.cs | 4 ++-- .../EnrDiscoveryTests.cs | 4 ++-- .../ProtocolHandlers/P2PProtocolHandler.cs | 4 ++-- .../SyncPeerProtocolHandlerBase.cs | 15 +++++------- .../Eth/V63/Eth63ProtocolHandler.cs | 5 ++-- .../Eth/V65/Eth65ProtocolHandler.cs | 11 ++++----- .../Eth/V66/Eth66ProtocolHandler.cs | 5 ++-- .../Eth/V68/Eth68ProtocolHandler.cs | 6 ++--- .../Nethermind.Runner/JsonRpc/Startup.cs | 4 ++-- src/Nethermind/Nethermind.Runner/Program.cs | 5 ++-- .../Blocks/BlockDownloader.cs | 4 ++-- .../FastSync/PendingSyncItems.cs | 5 ++-- .../FastSync/TreeSync.cs | 14 +++++------ .../PersistentBlobTxDistinctSortedPool.cs | 7 +++--- 24 files changed, 76 insertions(+), 109 deletions(-) diff --git a/src/Nethermind/Nethermind.Cli/NodeManager.cs b/src/Nethermind/Nethermind.Cli/NodeManager.cs index c392a499e59..75cfe3df20f 100644 --- a/src/Nethermind/Nethermind.Cli/NodeManager.cs +++ b/src/Nethermind/Nethermind.Cli/NodeManager.cs @@ -69,11 +69,9 @@ public async Task PostJint(string method, params object[] parameters) } else { - Stopwatch stopwatch = new(); - stopwatch.Start(); + long startTime = Stopwatch.GetTimestamp(); object? result = await _currentClient.Post(method, parameters); - stopwatch.Stop(); - decimal totalMicroseconds = stopwatch.ElapsedTicks * (1_000_000m / Stopwatch.Frequency); + decimal totalMicroseconds = (decimal)Stopwatch.GetElapsedTime(startTime).TotalMicroseconds; Colorful.Console.WriteLine($"Request complete in {totalMicroseconds}μs"); if (result is bool boolResult) @@ -121,11 +119,9 @@ public async Task PostJint(string method, params object[] parameters) } else { - Stopwatch stopwatch = new(); - stopwatch.Start(); + long starting = Stopwatch.GetTimestamp(); result = await _currentClient.Post(method, parameters); - stopwatch.Stop(); - decimal totalMicroseconds = stopwatch.ElapsedTicks * (1_000_000m / Stopwatch.Frequency); + decimal totalMicroseconds = (decimal)Stopwatch.GetElapsedTime(starting).TotalMicroseconds; Colorful.Console.WriteLine($"Request complete in {totalMicroseconds}μs"); } } diff --git a/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs b/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs index a9f2092be3e..83e2f3b5372 100644 --- a/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs +++ b/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs @@ -424,9 +424,8 @@ private void WaitForNumber(PrivateKey nodeKey, long number) { if (_logger.IsInfo) _logger.Info($"WAITING ON {nodeKey.Address} FOR BLOCK {number}"); SpinWait spinWait = new(); - Stopwatch stopwatch = new(); - stopwatch.Start(); - while (stopwatch.ElapsedMilliseconds < _timeout) + long startTime = Stopwatch.GetTimestamp(); + while (Stopwatch.GetElapsedTime(startTime).TotalMilliseconds < _timeout) { spinWait.SpinOnce(); if (_blockTrees[nodeKey].Head.Number >= number) diff --git a/src/Nethermind/Nethermind.Evm.Test/Eip1153Tests.cs b/src/Nethermind/Nethermind.Evm.Test/Eip1153Tests.cs index 97d509a3b57..0f2e4bed9ff 100644 --- a/src/Nethermind/Nethermind.Evm.Test/Eip1153Tests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/Eip1153Tests.cs @@ -80,7 +80,6 @@ public void tload_uninitialized_returns_zero() [Test] public void transient_storage_performance_test() { - Stopwatch stopwatch = new Stopwatch(); long blockGasLimit = 30000000; long numOfOps = (long)(blockGasLimit * .95) / (GasCostOf.TLoad + GasCostOf.TStore + GasCostOf.VeryLow * 4); Prepare prepare = Prepare.EvmCode; @@ -93,11 +92,10 @@ public void transient_storage_performance_test() byte[] code = prepare.Done; - stopwatch.Start(); + long startTime = Stopwatch.GetTimestamp(); TestAllTracerWithOutput result = Execute((MainnetSpecProvider.GrayGlacierBlockNumber, Timestamp), blockGasLimit, code, blockGasLimit); Assert.That(result.StatusCode, Is.EqualTo(StatusCode.Success)); - stopwatch.Stop(); - Assert.That(stopwatch.ElapsedMilliseconds < 5000, Is.True); + Assert.That(Stopwatch.GetElapsedTime(startTime).TotalMilliseconds < 5000, Is.True); } /// diff --git a/src/Nethermind/Nethermind.Facade/Proxy/DefaultHttpClient.cs b/src/Nethermind/Nethermind.Facade/Proxy/DefaultHttpClient.cs index aac11f47041..53765e36759 100644 --- a/src/Nethermind/Nethermind.Facade/Proxy/DefaultHttpClient.cs +++ b/src/Nethermind/Nethermind.Facade/Proxy/DefaultHttpClient.cs @@ -79,7 +79,7 @@ private async Task ProcessRequestAsync(Method method, string endpoint, str string methodType = method.ToString(); string json = payload is null ? "{}" : _jsonSerializer.Serialize(payload); if (_logger.IsTrace) _logger.Trace($"Sending HTTP {methodType} request to: {endpoint} [id: {requestId}]{(method == Method.Get ? "." : $": {json}")}"); - Stopwatch stopWatch = Stopwatch.StartNew(); + long startTime = Stopwatch.GetTimestamp(); HttpResponseMessage response; switch (method) { @@ -94,9 +94,7 @@ private async Task ProcessRequestAsync(Method method, string endpoint, str if (_logger.IsError) _logger.Error($"Unsupported HTTP method: {methodType}."); return default; } - - stopWatch.Stop(); - if (_logger.IsTrace) _logger.Trace($"Received HTTP {methodType} response from: {endpoint} [id: {requestId}, elapsed: {stopWatch.ElapsedMilliseconds} ms]: {response}"); + if (_logger.IsTrace) _logger.Trace($"Received HTTP {methodType} response from: {endpoint} [id: {requestId}, elapsed: {Stopwatch.GetElapsedTime(startTime).TotalMilliseconds:N0} ms]: {response}"); if (!response.IsSuccessStatusCode) { return default; diff --git a/src/Nethermind/Nethermind.Init/Steps/EthereumStepsManager.cs b/src/Nethermind/Nethermind.Init/Steps/EthereumStepsManager.cs index 4912b4ba817..337729eb705 100644 --- a/src/Nethermind/Nethermind.Init/Steps/EthereumStepsManager.cs +++ b/src/Nethermind/Nethermind.Init/Steps/EthereumStepsManager.cs @@ -147,14 +147,14 @@ private void RunOneRoundOfInitialization(CancellationToken cancellationToken) private async Task ExecuteStep(IStep step, StepInfo stepInfo, CancellationToken cancellationToken) { - Stopwatch stopwatch = Stopwatch.StartNew(); + long startTime = Stopwatch.GetTimestamp(); try { await step.Execute(cancellationToken); if (_logger.IsDebug) _logger.Debug( - $"Step {step.GetType().Name.PadRight(24)} executed in {stopwatch.ElapsedMilliseconds}ms"); + $"Step {step.GetType().Name.PadRight(24)} executed in {Stopwatch.GetElapsedTime(startTime).TotalMilliseconds:N0}ms"); stepInfo.Stage = StepInitializationStage.Complete; } @@ -164,7 +164,7 @@ private async Task ExecuteStep(IStep step, StepInfo stepInfo, CancellationToken { if (_logger.IsError) _logger.Error( - $"Step {step.GetType().Name.PadRight(24)} failed after {stopwatch.ElapsedMilliseconds}ms", + $"Step {step.GetType().Name.PadRight(24)} failed after {Stopwatch.GetElapsedTime(startTime).TotalMilliseconds:N0}ms", exception); stepInfo.Stage = StepInitializationStage.Failed; @@ -174,13 +174,12 @@ private async Task ExecuteStep(IStep step, StepInfo stepInfo, CancellationToken if (_logger.IsWarn) { _logger.Warn( - $"Step {step.GetType().Name.PadRight(24)} failed after {stopwatch.ElapsedMilliseconds}ms {exception}"); + $"Step {step.GetType().Name.PadRight(24)} failed after {Stopwatch.GetElapsedTime(startTime).TotalMilliseconds:N0}ms {exception}"); } stepInfo.Stage = StepInitializationStage.Complete; } finally { - stopwatch.Stop(); _autoResetEvent.Set(); if (_logger.IsDebug) _logger.Debug($"{step.GetType().Name.PadRight(24)} complete"); diff --git a/src/Nethermind/Nethermind.Init/Steps/InitializePlugins.cs b/src/Nethermind/Nethermind.Init/Steps/InitializePlugins.cs index 31143a8f43e..122ba122348 100644 --- a/src/Nethermind/Nethermind.Init/Steps/InitializePlugins.cs +++ b/src/Nethermind/Nethermind.Init/Steps/InitializePlugins.cs @@ -30,11 +30,10 @@ public async Task Execute(CancellationToken cancellationToken) try { if (logger.IsInfo) logger.Info($" {plugin.Name} by {plugin.Author}"); - Stopwatch stopwatch = Stopwatch.StartNew(); + long startTime = Stopwatch.GetTimestamp(); await plugin.Init(_api); - stopwatch.Stop(); if (logger.IsInfo) - logger.Info($" {plugin.Name} by {plugin.Author} initialized in {stopwatch.ElapsedMilliseconds}ms"); + logger.Info($" {plugin.Name} by {plugin.Author} initialized in {Stopwatch.GetElapsedTime(startTime).TotalMilliseconds:N0}ms"); } catch (Exception e) { diff --git a/src/Nethermind/Nethermind.JsonRpc/JsonRpcProcessor.cs b/src/Nethermind/Nethermind.JsonRpc/JsonRpcProcessor.cs index bcc2a257cab..b684ee14b23 100644 --- a/src/Nethermind/Nethermind.JsonRpc/JsonRpcProcessor.cs +++ b/src/Nethermind/Nethermind.JsonRpc/JsonRpcProcessor.cs @@ -119,7 +119,7 @@ private ArrayPoolList DeserializeArray(JsonElement element) => public async IAsyncEnumerable ProcessAsync(PipeReader reader, JsonRpcContext context) { reader = await RecordRequest(reader); - Stopwatch stopwatch = Stopwatch.StartNew(); + long startTime = Stopwatch.GetTimestamp(); CancellationTokenSource timeoutSource = new(_jsonRpcConfig.Timeout); // Handles general exceptions during parsing and validation. @@ -130,8 +130,7 @@ JsonRpcResult GetParsingError(string error, Exception? exception = null) if (_logger.IsError) _logger.Error(error, exception); JsonRpcErrorResponse response = _jsonRpcService.GetErrorResponse(ErrorCodes.ParseError, "Incorrect message"); TraceResult(response); - stopwatch.Stop(); - return JsonRpcResult.Single(RecordResponse(response, new RpcReport("# parsing error #", stopwatch.ElapsedMicroseconds(), false))); + return JsonRpcResult.Single(RecordResponse(response, new RpcReport("# parsing error #", (long)Stopwatch.GetElapsedTime(startTime).TotalMicroseconds, false))); } // Initializes a buffer to store the data read from the reader. @@ -219,9 +218,6 @@ JsonRpcResult GetParsingError(string error, Exception? exception = null) yield return deserializationFailureResult.Value; break; } - - // Stops the stopwatch and yields the batch processing result. - stopwatch.Stop(); JsonRpcBatchResult jsonRpcBatchResult = new((e, c) => IterateRequest(collection, context, e).GetAsyncEnumerator(c)); jsonRpcBatchResult.AddDisposable(() => collection.Dispose()); yield return JsonRpcResult.Collection(jsonRpcBatchResult); @@ -235,9 +231,8 @@ JsonRpcResult GetParsingError(string error, Exception? exception = null) errorResponse.AddDisposable(() => jsonDocument.Dispose()); TraceResult(errorResponse); - stopwatch.Stop(); - if (_logger.IsDebug) _logger.Debug($" Failed request handled in {stopwatch.Elapsed.TotalMilliseconds}ms"); - deserializationFailureResult = JsonRpcResult.Single(RecordResponse(errorResponse, new RpcReport("# parsing error #", stopwatch.ElapsedMicroseconds(), false))); + if (_logger.IsDebug) _logger.Debug($" Failed request handled in {Stopwatch.GetElapsedTime(startTime).TotalMilliseconds:N0}ms"); + deserializationFailureResult = JsonRpcResult.Single(RecordResponse(errorResponse, new RpcReport("# parsing error #", (long)Stopwatch.GetElapsedTime(startTime).TotalMilliseconds, false))); yield return deserializationFailureResult.Value; break; } @@ -304,7 +299,7 @@ static bool HasNonWhitespace(ReadOnlySpan span) { try { - Stopwatch stopwatch = Stopwatch.StartNew(); + long startTime = Stopwatch.GetTimestamp(); int requestIndex = 0; for (int index = 0; index < requests.Count; index++) { @@ -325,7 +320,7 @@ static bool HasNonWhitespace(ReadOnlySpan span) yield return RecordResponse(response); } - if (_logger.IsDebug) _logger.Debug($" {requests.Count} requests handled in {stopwatch.Elapsed.TotalMilliseconds}ms"); + if (_logger.IsDebug) _logger.Debug($" {requests.Count} requests handled in {Stopwatch.GetElapsedTime(startTime).TotalMilliseconds:N0}ms"); } finally { @@ -336,7 +331,7 @@ static bool HasNonWhitespace(ReadOnlySpan span) private async Task HandleSingleRequest(JsonRpcRequest request, JsonRpcContext context) { Metrics.JsonRpcRequests++; - Stopwatch stopwatch = Stopwatch.StartNew(); + long startTime = Stopwatch.GetTimestamp(); JsonRpcResponse response = await _jsonRpcService.SendRequestAsync(request, context); JsonRpcErrorResponse localErrorResponse = response as JsonRpcErrorResponse; @@ -355,11 +350,10 @@ static bool HasNonWhitespace(ReadOnlySpan span) Metrics.JsonRpcSuccesses++; } - stopwatch.Stop(); - if (_logger.IsDebug) _logger.Debug($" {request} handled in {stopwatch.Elapsed.TotalMilliseconds}ms"); + if (_logger.IsDebug) _logger.Debug($" {request} handled in {Stopwatch.GetElapsedTime(startTime).TotalMilliseconds:N0}ms"); - JsonRpcResult.Entry result = new(response, new RpcReport(request.Method, stopwatch.ElapsedMicroseconds(), isSuccess)); + JsonRpcResult.Entry result = new(response, new RpcReport(request.Method, (long)Stopwatch.GetElapsedTime(startTime).TotalMicroseconds, isSuccess)); TraceResult(result); return result; } diff --git a/src/Nethermind/Nethermind.JsonRpc/WebSockets/JsonRpcSocketsClient.cs b/src/Nethermind/Nethermind.JsonRpc/WebSockets/JsonRpcSocketsClient.cs index 3cf54185a5e..ddf29f87e36 100644 --- a/src/Nethermind/Nethermind.JsonRpc/WebSockets/JsonRpcSocketsClient.cs +++ b/src/Nethermind/Nethermind.JsonRpc/WebSockets/JsonRpcSocketsClient.cs @@ -58,7 +58,6 @@ public override void Dispose() public override async Task ProcessAsync(ArraySegment data) { - Stopwatch stopwatch = Stopwatch.StartNew(); IncrementBytesReceivedMetric(data.Count); PipeReader request = PipeReader.Create(new ReadOnlySequence(data.Array!, data.Offset, data.Count)); int allResponsesSize = 0; @@ -67,23 +66,21 @@ public override async Task ProcessAsync(ArraySegment data) { using (result) { - stopwatch.Restart(); - int singleResponseSize = await SendJsonRpcResult(result); allResponsesSize += singleResponseSize; + long startTime = Stopwatch.GetTimestamp(); + if (result.IsCollection) { - long handlingTimeMicroseconds = stopwatch.ElapsedMicroseconds(); + long handlingTimeMicroseconds = (long)Stopwatch.GetElapsedTime(startTime).TotalMicroseconds; _ = _jsonRpcLocalStats.ReportCall(new RpcReport("# collection serialization #", handlingTimeMicroseconds, true), handlingTimeMicroseconds, singleResponseSize); } else { - long handlingTimeMicroseconds = stopwatch.ElapsedMicroseconds(); + long handlingTimeMicroseconds = (long)Stopwatch.GetElapsedTime(startTime).TotalMicroseconds; _ = _jsonRpcLocalStats.ReportCall(result.Report!.Value, handlingTimeMicroseconds, singleResponseSize); } - - stopwatch.Restart(); } } diff --git a/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Paris.cs b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Paris.cs index f5c0616b826..4cf84584a76 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Paris.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Paris.cs @@ -41,15 +41,14 @@ protected async Task> ForkchoiceUpdated { if (await _locker.WaitAsync(_timeout)) { - Stopwatch watch = Stopwatch.StartNew(); + long startTime = Stopwatch.GetTimestamp(); try { return await _forkchoiceUpdatedV1Handler.Handle(forkchoiceState, payloadAttributes, version); } finally { - watch.Stop(); - Metrics.ForkchoiceUpdedExecutionTime = watch.ElapsedMilliseconds; + Metrics.ForkchoiceUpdedExecutionTime = (long)Stopwatch.GetElapsedTime(startTime).TotalMilliseconds; _locker.Release(); } } @@ -82,7 +81,7 @@ protected async Task> NewPayload(IExecutionPayloa if (await _locker.WaitAsync(_timeout)) { - Stopwatch watch = Stopwatch.StartNew(); + long startTime = Stopwatch.GetTimestamp(); try { using IDisposable region = _gcKeeper.TryStartNoGCRegion(); @@ -95,8 +94,7 @@ protected async Task> NewPayload(IExecutionPayloa } finally { - watch.Stop(); - Metrics.NewPayloadExecutionTime = watch.ElapsedMilliseconds; + Metrics.NewPayloadExecutionTime = (long)Stopwatch.GetElapsedTime(startTime).TotalMilliseconds; _locker.Release(); } } diff --git a/src/Nethermind/Nethermind.Merge.Plugin/Synchronization/MergeBlockDownloader.cs b/src/Nethermind/Nethermind.Merge.Plugin/Synchronization/MergeBlockDownloader.cs index 1091473ca26..f0768e39168 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/Synchronization/MergeBlockDownloader.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/Synchronization/MergeBlockDownloader.cs @@ -179,7 +179,7 @@ bool HasMoreToSync(out BlockHeader[]? headers, out int headersToRequest) if (cancellation.IsCancellationRequested) return blocksSynced; // check before every heavy operation - Stopwatch sw = Stopwatch.StartNew(); + long startTime = Stopwatch.GetTimestamp(); await RequestBodies(bestPeer, cancellation, context); if (downloadReceipts) @@ -189,7 +189,7 @@ bool HasMoreToSync(out BlockHeader[]? headers, out int headersToRequest) await RequestReceipts(bestPeer, cancellation, context); } - AdjustSyncBatchSize(sw.Elapsed); + AdjustSyncBatchSize(Stopwatch.GetElapsedTime(startTime)); blocks = context.Blocks; receipts = context.ReceiptsForBlocks; diff --git a/src/Nethermind/Nethermind.Network.Discovery.Test/DiscoveryManagerTests.cs b/src/Nethermind/Nethermind.Network.Discovery.Test/DiscoveryManagerTests.cs index f6d36407232..7921d946c1c 100644 --- a/src/Nethermind/Nethermind.Network.Discovery.Test/DiscoveryManagerTests.cs +++ b/src/Nethermind/Nethermind.Network.Discovery.Test/DiscoveryManagerTests.cs @@ -200,7 +200,7 @@ public async Task RateLimitOutgoingMessage() MaxOutgoingMessagePerSecond = 5 }); - Stopwatch sw = Stopwatch.StartNew(); + long startTime = Stopwatch.GetTimestamp(); FindNodeMsg msg = new(_publicKey, 0, Array.Empty()); await _discoveryManager.SendMessageAsync(msg); await _discoveryManager.SendMessageAsync(msg); @@ -208,7 +208,7 @@ public async Task RateLimitOutgoingMessage() await _discoveryManager.SendMessageAsync(msg); await _discoveryManager.SendMessageAsync(msg); await _discoveryManager.SendMessageAsync(msg); - sw.Elapsed.Should().BeGreaterOrEqualTo(TimeSpan.FromSeconds(0.9)); + Stopwatch.GetElapsedTime(startTime).Should().BeGreaterOrEqualTo(TimeSpan.FromSeconds(0.9)); } } } diff --git a/src/Nethermind/Nethermind.Network.Dns.Test/EnrDiscoveryTests.cs b/src/Nethermind/Nethermind.Network.Dns.Test/EnrDiscoveryTests.cs index fb20bb43b14..0c5dc4143ed 100644 --- a/src/Nethermind/Nethermind.Network.Dns.Test/EnrDiscoveryTests.cs +++ b/src/Nethermind/Nethermind.Network.Dns.Test/EnrDiscoveryTests.cs @@ -33,10 +33,10 @@ public async Task Test_enr_discovery(string url) INetworkConfig config = new NetworkConfig(); config.DiscoveryDns = url; EnrDiscovery enrDiscovery = new(new EnrRecordParser(singer), config, testErrorLogManager); - Stopwatch stopwatch = Stopwatch.StartNew(); + long startTime = Stopwatch.GetTimestamp(); List addedRecords = enrDiscovery.DiscoverNodes(default).ToBlockingEnumerable().ToList(); - await TestContext.Out.WriteLineAsync($"Actually added {addedRecords.Count} in {stopwatch.Elapsed:g}"); + await TestContext.Out.WriteLineAsync($"Actually added {addedRecords.Count} in {Stopwatch.GetElapsedTime(startTime):g}"); foreach (TestErrorLogManager.Error error in testErrorLogManager.Errors) { await TestContext.Out.WriteLineAsync(error.Text); diff --git a/src/Nethermind/Nethermind.Network/P2P/ProtocolHandlers/P2PProtocolHandler.cs b/src/Nethermind/Nethermind.Network/P2P/ProtocolHandlers/P2PProtocolHandler.cs index e5a3db6b9d6..b0c3c5d1615 100644 --- a/src/Nethermind/Nethermind.Network/P2P/ProtocolHandlers/P2PProtocolHandler.cs +++ b/src/Nethermind/Nethermind.Network/P2P/ProtocolHandlers/P2PProtocolHandler.cs @@ -271,7 +271,7 @@ public async Task SendPing() if (Logger.IsTrace) Logger.Trace($"{Session} P2P sending ping on {Session.RemotePort} ({RemoteClientId})"); Send(PingMessage.Instance); _nodeStatsManager.ReportEvent(Session.Node, NodeStatsEventType.P2PPingOut); - Stopwatch stopwatch = Stopwatch.StartNew(); + long startTime = Stopwatch.GetTimestamp(); CancellationTokenSource delayCancellation = new(); try @@ -286,7 +286,7 @@ public async Task SendPing() return false; } - long latency = stopwatch.ElapsedMilliseconds; + long latency = (long)Stopwatch.GetElapsedTime(startTime).TotalMilliseconds; _nodeStatsManager.ReportTransferSpeedEvent(Session.Node, TransferSpeedType.Latency, latency); return true; } diff --git a/src/Nethermind/Nethermind.Network/P2P/ProtocolHandlers/SyncPeerProtocolHandlerBase.cs b/src/Nethermind/Nethermind.Network/P2P/ProtocolHandlers/SyncPeerProtocolHandlerBase.cs index b47db24a5ac..e930beb17dc 100644 --- a/src/Nethermind/Nethermind.Network/P2P/ProtocolHandlers/SyncPeerProtocolHandlerBase.cs +++ b/src/Nethermind/Nethermind.Network/P2P/ProtocolHandlers/SyncPeerProtocolHandlerBase.cs @@ -283,7 +283,7 @@ private void SendMessage(IOwnedReadOnlyList txsToSend) protected async Task Handle(GetBlockHeadersMessage getBlockHeadersMessage, CancellationToken cancellationToken) { using GetBlockHeadersMessage message = getBlockHeadersMessage; - Stopwatch stopwatch = Stopwatch.StartNew(); + long startTime = Stopwatch.GetTimestamp(); if (Logger.IsTrace) { Logger.Trace($"Received headers request from {Session.Node:c}:"); @@ -309,8 +309,7 @@ protected async Task Handle(GetBlockHeadersMessage getBlock // } BlockHeadersMessage resp = await FulfillBlockHeadersRequest(message, cancellationToken); - stopwatch.Stop(); - if (Logger.IsTrace) Logger.Trace($"OUT {Counter:D5} BlockHeaders to {Node:c} in {stopwatch.Elapsed.TotalMilliseconds}ms"); + if (Logger.IsTrace) Logger.Trace($"OUT {Counter:D5} BlockHeaders to {Node:c} in {Stopwatch.GetElapsedTime(startTime).TotalMilliseconds:N0}ms"); return resp; } @@ -343,12 +342,11 @@ protected async Task Handle(GetBlockBodiesMessage request, C Logger.Trace($"Received bodies request of length {message.BlockHashes.Count} from {Session.Node:c}:"); } - Stopwatch stopwatch = Stopwatch.StartNew(); + long startTime = Stopwatch.GetTimestamp(); Interlocked.Increment(ref Counter); BlockBodiesMessage resp = await FulfillBlockBodiesRequest(message, cancellationToken); - stopwatch.Stop(); - if (Logger.IsTrace) Logger.Trace($"OUT {Counter:D5} BlockBodies to {Node:c} in {stopwatch.Elapsed.TotalMilliseconds}ms"); + if (Logger.IsTrace) Logger.Trace($"OUT {Counter:D5} BlockBodies to {Node:c} in {Stopwatch.GetElapsedTime(startTime).TotalMilliseconds:N0}ms"); return resp; } @@ -391,10 +389,9 @@ protected async Task Handle(GetReceiptsMessage msg, Cancellatio throw new EthSyncException("Incoming receipts request for more than 512 blocks"); } - Stopwatch stopwatch = Stopwatch.StartNew(); + long startTime = Stopwatch.GetTimestamp(); ReceiptsMessage resp = await FulfillReceiptsRequest(message, cancellationToken); - stopwatch.Stop(); - if (Logger.IsTrace) Logger.Trace($"OUT {Counter:D5} Receipts to {Node:c} in {stopwatch.Elapsed.TotalMilliseconds}ms"); + if (Logger.IsTrace) Logger.Trace($"OUT {Counter:D5} Receipts to {Node:c} in {Stopwatch.GetElapsedTime(startTime).TotalMilliseconds:N0}ms"); return resp; } diff --git a/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V63/Eth63ProtocolHandler.cs b/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V63/Eth63ProtocolHandler.cs index be1d225effb..a3f07a11fa4 100644 --- a/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V63/Eth63ProtocolHandler.cs +++ b/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V63/Eth63ProtocolHandler.cs @@ -106,10 +106,9 @@ private async Task Handle(GetNodeDataMessage msg, CancellationT { using var message = msg; - Stopwatch stopwatch = Stopwatch.StartNew(); + long startTime = Stopwatch.GetTimestamp(); NodeDataMessage response = await FulfillNodeDataRequest(message, cancellationToken); - stopwatch.Stop(); - if (Logger.IsTrace) Logger.Trace($"OUT {Counter:D5} NodeData to {Node:c} in {stopwatch.Elapsed.TotalMilliseconds}ms"); + if (Logger.IsTrace) Logger.Trace($"OUT {Counter:D5} NodeData to {Node:c} in {Stopwatch.GetElapsedTime(startTime).TotalMilliseconds:N0}ms"); return response; } diff --git a/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V65/Eth65ProtocolHandler.cs b/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V65/Eth65ProtocolHandler.cs index a15a71193f5..b322f6905ed 100644 --- a/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V65/Eth65ProtocolHandler.cs +++ b/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V65/Eth65ProtocolHandler.cs @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited // SPDX-License-Identifier: LGPL-3.0-only +using System; using System.Collections.Generic; using System.Diagnostics; using System.Threading; @@ -97,15 +98,14 @@ protected virtual void Handle(NewPooledTransactionHashesMessage msg) using var _ = msg; AddNotifiedTransactions(msg.Hashes); - Stopwatch stopwatch = Stopwatch.StartNew(); + long startTime = Stopwatch.GetTimestamp(); TxPool.Metrics.PendingTransactionsHashesReceived += msg.Hashes.Count; _pooledTxsRequestor.RequestTransactions(Send, msg.Hashes); - stopwatch.Stop(); if (Logger.IsTrace) Logger.Trace($"OUT {Counter:D5} {nameof(NewPooledTransactionHashesMessage)} to {Node:c} " + - $"in {stopwatch.Elapsed.TotalMilliseconds}ms"); + $"in {Stopwatch.GetElapsedTime(startTime).TotalMilliseconds:N0}ms"); } protected void AddNotifiedTransactions(IReadOnlyList hashes) @@ -119,12 +119,11 @@ protected void AddNotifiedTransactions(IReadOnlyList hashes) private async ValueTask Handle(GetPooledTransactionsMessage msg, CancellationToken cancellationToken) { using var message = msg; - var stopwatch = Stopwatch.StartNew(); + long startTime = Stopwatch.GetTimestamp(); Send(await FulfillPooledTransactionsRequest(message, cancellationToken)); - stopwatch.Stop(); if (Logger.IsTrace) Logger.Trace($"OUT {Counter:D5} {nameof(GetPooledTransactionsMessage)} to {Node:c} " + - $"in {stopwatch.Elapsed.TotalMilliseconds}ms"); + $"in {Stopwatch.GetElapsedTime(startTime).TotalMilliseconds:N0}ms"); } internal Task FulfillPooledTransactionsRequest(GetPooledTransactionsMessage msg, CancellationToken cancellationToken) diff --git a/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V66/Eth66ProtocolHandler.cs b/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V66/Eth66ProtocolHandler.cs index 95595b3b5c0..265feceb2c0 100644 --- a/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V66/Eth66ProtocolHandler.cs +++ b/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V66/Eth66ProtocolHandler.cs @@ -194,15 +194,14 @@ protected override void Handle(NewPooledTransactionHashesMessage msg) { using var message = msg; bool isTrace = Logger.IsTrace; - Stopwatch? stopwatch = isTrace ? Stopwatch.StartNew() : null; + long startTime = Stopwatch.GetTimestamp(); TxPool.Metrics.PendingTransactionsHashesReceived += message.Hashes.Count; _pooledTxsRequestor.RequestTransactionsEth66(_sendAction, message.Hashes); - stopwatch?.Stop(); if (isTrace) Logger.Trace($"OUT {Counter:D5} {nameof(NewPooledTransactionHashesMessage)} to {Node:c} " + - $"in {stopwatch.Elapsed.TotalMilliseconds}ms"); + $"in {Stopwatch.GetElapsedTime(startTime).TotalMilliseconds:N0}ms"); } protected override async Task> SendRequest(V62.Messages.GetBlockHeadersMessage message, CancellationToken token) diff --git a/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V68/Eth68ProtocolHandler.cs b/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V68/Eth68ProtocolHandler.cs index 15c0ace7a19..4dae6ba58b9 100644 --- a/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V68/Eth68ProtocolHandler.cs +++ b/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V68/Eth68ProtocolHandler.cs @@ -94,13 +94,11 @@ private void Handle(NewPooledTransactionHashesMessage68 msg) AddNotifiedTransactions(message.Hashes); - Stopwatch? stopwatch = isTrace ? Stopwatch.StartNew() : null; + long startTime = isTrace ? Stopwatch.GetTimestamp() : 0; _pooledTxsRequestor.RequestTransactionsEth68(_sendAction, message.Hashes, message.Sizes, message.Types); - stopwatch?.Stop(); - - if (isTrace) Logger.Trace($"OUT {Counter:D5} {nameof(NewPooledTransactionHashesMessage68)} to {Node:c} in {stopwatch.Elapsed.TotalMilliseconds}ms"); + if (isTrace) Logger.Trace($"OUT {Counter:D5} {nameof(NewPooledTransactionHashesMessage68)} to {Node:c} in {Stopwatch.GetElapsedTime(startTime).TotalMilliseconds}ms"); } protected override void SendNewTransactionCore(Transaction tx) diff --git a/src/Nethermind/Nethermind.Runner/JsonRpc/Startup.cs b/src/Nethermind/Nethermind.Runner/JsonRpc/Startup.cs index f3c29b1fed8..7e970cda02d 100644 --- a/src/Nethermind/Nethermind.Runner/JsonRpc/Startup.cs +++ b/src/Nethermind/Nethermind.Runner/JsonRpc/Startup.cs @@ -163,7 +163,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IJsonRpc if (jsonRpcUrl.MaxRequestBodySize is not null) ctx.Features.Get().MaxRequestBodySize = jsonRpcUrl.MaxRequestBodySize; - Stopwatch stopwatch = Stopwatch.StartNew(); + long startTime = Stopwatch.GetTimestamp(); CountingPipeReader request = new(ctx.Request.BodyReader); try { @@ -243,7 +243,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IJsonRpc await ctx.Response.CompleteAsync(); } - long handlingTimeMicroseconds = stopwatch.ElapsedMicroseconds(); + long handlingTimeMicroseconds = (long)Stopwatch.GetElapsedTime(startTime).TotalMicroseconds; _ = jsonRpcLocalStats.ReportCall(result.IsCollection ? new RpcReport("# collection serialization #", handlingTimeMicroseconds, true) : result.Report.Value, handlingTimeMicroseconds, resultWriter.WrittenCount); diff --git a/src/Nethermind/Nethermind.Runner/Program.cs b/src/Nethermind/Nethermind.Runner/Program.cs index e6d0b5780a0..fef352adc11 100644 --- a/src/Nethermind/Nethermind.Runner/Program.cs +++ b/src/Nethermind/Nethermind.Runner/Program.cs @@ -412,11 +412,10 @@ private static IConfigProvider BuildConfigProvider( else { _logger.Info($"Loading standard NLog.config file from {"NLog.config".GetApplicationResourcePath()}."); - Stopwatch stopwatch = Stopwatch.StartNew(); + long startTime = Stopwatch.GetTimestamp(); LogManager.Configuration = new XmlLoggingConfiguration("NLog.config".GetApplicationResourcePath()); - stopwatch.Stop(); - _logger.Info($"NLog.config loaded in {stopwatch.ElapsedMilliseconds}ms."); + _logger.Info($"NLog.config loaded in {Stopwatch.GetElapsedTime(startTime).TotalMilliseconds:N0}ms."); } // TODO: dynamically switch log levels from CLI! diff --git a/src/Nethermind/Nethermind.Synchronization/Blocks/BlockDownloader.cs b/src/Nethermind/Nethermind.Synchronization/Blocks/BlockDownloader.cs index 765c0f7e7a4..77f78aa7420 100644 --- a/src/Nethermind/Nethermind.Synchronization/Blocks/BlockDownloader.cs +++ b/src/Nethermind/Nethermind.Synchronization/Blocks/BlockDownloader.cs @@ -167,7 +167,7 @@ bool HasMoreToSync() } if (_logger.IsDebug) _logger.Debug($"Headers request {currentNumber}+{headersToRequest} to peer {bestPeer} with {bestPeer.HeadNumber} blocks. Got {currentNumber} and asking for {headersToRequest} more."); - Stopwatch sw = Stopwatch.StartNew(); + long startTime = Stopwatch.GetTimestamp(); using IOwnedReadOnlyList headers = await RequestHeaders(bestPeer, cancellation, currentNumber, headersToRequest); Hash256? startHeaderHash = headers[0]?.Hash; @@ -188,7 +188,7 @@ bool HasMoreToSync() } ancestorLookupLevel = 0; - AdjustSyncBatchSize(sw.Elapsed); + AdjustSyncBatchSize(Stopwatch.GetElapsedTime(startTime)); for (int i = 1; i < headers.Count; i++) { diff --git a/src/Nethermind/Nethermind.Synchronization/FastSync/PendingSyncItems.cs b/src/Nethermind/Nethermind.Synchronization/FastSync/PendingSyncItems.cs index 2cd79d10912..cfc36ce4509 100644 --- a/src/Nethermind/Nethermind.Synchronization/FastSync/PendingSyncItems.cs +++ b/src/Nethermind/Nethermind.Synchronization/FastSync/PendingSyncItems.cs @@ -202,7 +202,7 @@ public List TakeBatch(int maxSize) [MethodImpl(MethodImplOptions.Synchronized)] public string RecalculatePriorities() { - Stopwatch stopwatch = Stopwatch.StartNew(); + long startTime = Stopwatch.GetTimestamp(); string reviewMessage = $"Node sync queues review ({LevelsDescription}):" + Environment.NewLine; reviewMessage += $" before {Description}" + Environment.NewLine; @@ -225,8 +225,7 @@ public string RecalculatePriorities() reviewMessage += $" after {Description}" + Environment.NewLine; - stopwatch.Stop(); - reviewMessage += $" time spent in review: {stopwatch.ElapsedMilliseconds}ms"; + reviewMessage += $" time spent in review: {Stopwatch.GetElapsedTime(startTime).TotalMilliseconds:N0}ms"; return reviewMessage; } } diff --git a/src/Nethermind/Nethermind.Synchronization/FastSync/TreeSync.cs b/src/Nethermind/Nethermind.Synchronization/FastSync/TreeSync.cs index 4cc449cb47b..0c4b7b35568 100644 --- a/src/Nethermind/Nethermind.Synchronization/FastSync/TreeSync.cs +++ b/src/Nethermind/Nethermind.Synchronization/FastSync/TreeSync.cs @@ -167,7 +167,7 @@ void AddAgainAllItems() if (_logger.IsDebug) _logger.Debug(reviewMessage); } - Stopwatch handleWatch = Stopwatch.StartNew(); + long startTime = Stopwatch.GetTimestamp(); bool isMissingRequestData = batch.RequestedNodes is null; if (isMissingRequestData) @@ -289,24 +289,24 @@ shorter than the request */ _data.DisplayProgressReport(_pendingRequests.Count, _branchProgress, _logger); - handleWatch.Stop(); - long total = handleWatch.ElapsedMilliseconds + _networkWatch.ElapsedMilliseconds; + long elapsedTime = (long)Stopwatch.GetElapsedTime(startTime).TotalMilliseconds; + long total = elapsedTime + _networkWatch.ElapsedMilliseconds; if (total != 0) { // calculate averages if (_logger.IsTrace) _logger.Trace( - $"Prepare batch {_networkWatch.ElapsedMilliseconds}ms ({(decimal)_networkWatch.ElapsedMilliseconds / total:P0}) - Handle {handleWatch.ElapsedMilliseconds}ms ({(decimal)handleWatch.ElapsedMilliseconds / total:P0})"); + $"Prepare batch {_networkWatch.ElapsedMilliseconds}ms ({(decimal)_networkWatch.ElapsedMilliseconds / total:P0}) - Handle {elapsedTime:N0}ms ({(decimal)elapsedTime / total:P0})"); } - if (handleWatch.ElapsedMilliseconds > 250) + if (Stopwatch.GetElapsedTime(startTime).TotalMilliseconds > 250) { if (_logger.IsDebug) _logger.Debug( - $"Handle watch {handleWatch.ElapsedMilliseconds}, DB reads {_data.DbChecks - _data.LastDbReads}, ratio {(decimal)handleWatch.ElapsedMilliseconds / Math.Max(1, _data.DbChecks - _data.LastDbReads)}"); + $"Handle watch {elapsedTime:N0}, DB reads {_data.DbChecks - _data.LastDbReads}, ratio {(decimal)elapsedTime / Math.Max(1, _data.DbChecks - _data.LastDbReads)}"); } - Interlocked.Add(ref _handleWatch, handleWatch.ElapsedMilliseconds); + Interlocked.Add(ref _handleWatch, (long)Stopwatch.GetElapsedTime(startTime).TotalMilliseconds); _data.LastDbReads = _data.DbChecks; _data.AverageTimeInHandler = _handleWatch / (decimal)_data.ProcessedRequestsCount; diff --git a/src/Nethermind/Nethermind.TxPool/Collections/PersistentBlobTxDistinctSortedPool.cs b/src/Nethermind/Nethermind.TxPool/Collections/PersistentBlobTxDistinctSortedPool.cs index d0f7eb34d92..d768df97d28 100644 --- a/src/Nethermind/Nethermind.TxPool/Collections/PersistentBlobTxDistinctSortedPool.cs +++ b/src/Nethermind/Nethermind.TxPool/Collections/PersistentBlobTxDistinctSortedPool.cs @@ -33,7 +33,7 @@ private void RecreateLightTxCollectionAndCache(ITxStorage blobTxStorage) if (_logger.IsDebug) _logger.Debug("Recreating light collection of blob transactions and cache"); int numberOfTxsInDb = 0; int numberOfBlobsInDb = 0; - Stopwatch stopwatch = Stopwatch.StartNew(); + long startTime = Stopwatch.GetTimestamp(); foreach (LightTransaction lightBlobTx in blobTxStorage.GetAll()) { if (base.TryInsert(lightBlobTx.Hash, lightBlobTx, out _)) @@ -46,11 +46,10 @@ private void RecreateLightTxCollectionAndCache(ITxStorage blobTxStorage) if (_logger.IsInfo && numberOfTxsInDb != 0) { - long loadingTime = stopwatch.ElapsedMilliseconds; - _logger.Info($"Loaded {numberOfTxsInDb} blob txs from persistent db, containing {numberOfBlobsInDb} blobs, in {loadingTime}ms"); + long loadingTime = (long)Stopwatch.GetElapsedTime(startTime).TotalMilliseconds; + _logger.Info($"Loaded {numberOfTxsInDb} blob txs from persistent db, containing {numberOfBlobsInDb} blobs, in {loadingTime:N0}ms"); _logger.Info($"There are {BlobIndex.Count} unique blobs indexed"); } - stopwatch.Stop(); } public override bool TryInsert(ValueHash256 hash, Transaction fullBlobTx, out Transaction? removed) From 0944765ba18fb6705a60d6c9dbb89dc1c45c19f5 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Mon, 7 Oct 2024 22:50:43 +0100 Subject: [PATCH 03/12] Revert "Avx512 Keccak (#7561)" (#7569) --- .../Nethermind.Core/Crypto/KeccakHash.cs | 137 ------------------ 1 file changed, 137 deletions(-) diff --git a/src/Nethermind/Nethermind.Core/Crypto/KeccakHash.cs b/src/Nethermind/Nethermind.Core/Crypto/KeccakHash.cs index b946dc902df..f3cca085977 100644 --- a/src/Nethermind/Nethermind.Core/Crypto/KeccakHash.cs +++ b/src/Nethermind/Nethermind.Core/Crypto/KeccakHash.cs @@ -5,11 +5,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using System.Runtime.Intrinsics; -using System.Runtime.Intrinsics.X86; - using static System.Numerics.BitOperations; // ReSharper disable InconsistentNaming @@ -92,18 +88,6 @@ private KeccakHash(int size) // update the state with given number of rounds private static void KeccakF(Span st) - { - if (Avx512F.IsSupported) - { - KeccakF1600Avx512F(st); - } - else - { - KeccakF1600(st); - } - } - - private static void KeccakF1600(Span st) { Debug.Assert(st.Length == 25); @@ -637,126 +621,5 @@ public static void ReturnState(ref ulong[] state) state = Array.Empty(); } } - - [SkipLocalsInit] - public static void KeccakF1600Avx512F(Span state) - { - { - // Redundant statement that removes all the in loop bounds checks - _ = state[24]; - } - - // Can straight load and over-read for start elements - Vector512 mask = Vector512.Create(ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, 0UL, 0UL, 0UL); - Vector512 c0 = Unsafe.As>(ref MemoryMarshal.GetReference(state)); - // Clear the over-read values from first vectors - c0 = Vector512.BitwiseAnd(mask, c0); - Vector512 c1 = Unsafe.As>(ref Unsafe.Add(ref MemoryMarshal.GetReference(state), 5)); - c1 = Vector512.BitwiseAnd(mask, c1); - Vector512 c2 = Unsafe.As>(ref Unsafe.Add(ref MemoryMarshal.GetReference(state), 10)); - c2 = Vector512.BitwiseAnd(mask, c2); - Vector512 c3 = Unsafe.As>(ref Unsafe.Add(ref MemoryMarshal.GetReference(state), 15)); - c3 = Vector512.BitwiseAnd(mask, c3); - - // Can't over-read for the last elements (8 items in vector 5 to be remaining) - // so read a Vector256 and ulong then combine - Vector256 c4a = Unsafe.As>(ref Unsafe.Add(ref MemoryMarshal.GetReference(state), 20)); - Vector256 c4b = Vector256.Create(state[24], 0UL, 0UL, 0UL); - Vector512 c4 = Vector512.Create(c4a, c4b); - - ulong[] roundConstants = RoundConstants; - for (int round = 0; round < roundConstants.Length; round++) - { - // Theta step - Vector512 bVec = Vector512.Xor(Vector512.Xor(Vector512.Xor(c0, c1), Vector512.Xor(c2, c3)), c4); - - // Compute Theta Vector - Vector512 bVecRot1 = Avx512F.PermuteVar8x64(bVec, Vector512.Create(1UL, 2UL, 3UL, 4UL, 0UL, 5UL, 6UL, 7UL)); - Vector512 bVecRot4 = Avx512F.PermuteVar8x64(bVec, Vector512.Create(4UL, 0UL, 1UL, 2UL, 3UL, 5UL, 6UL, 7UL)); - - // Rotate bVecRot1 left by 1 - Vector512 bVecRot1ShiftedLeft = Avx512F.ShiftLeftLogical(bVecRot1, 1); - Vector512 bVecRot1ShiftedRight = Avx512F.ShiftRightLogical(bVecRot1, 63); - Vector512 bVecRot1Rotated = Avx512F.Or(bVecRot1ShiftedLeft, bVecRot1ShiftedRight); - - Vector512 thetaVec = Avx512F.Xor(bVecRot4, bVecRot1Rotated); - - c0 = Avx512F.Xor(c0, thetaVec); - c1 = Avx512F.Xor(c1, thetaVec); - c2 = Avx512F.Xor(c2, thetaVec); - c3 = Avx512F.Xor(c3, thetaVec); - c4 = Avx512F.Xor(c4, thetaVec); - - // Rho step - Vector512 rhoVec0 = Vector512.Create(0UL, 1UL, 62UL, 28UL, 27UL, 0UL, 0UL, 0UL); - c0 = Avx512F.RotateLeftVariable(c0, rhoVec0); - - Vector512 rhoVec1 = Vector512.Create(36UL, 44UL, 6UL, 55UL, 20UL, 0UL, 0UL, 0UL); - c1 = Avx512F.RotateLeftVariable(c1, rhoVec1); - - Vector512 rhoVec2 = Vector512.Create(3UL, 10UL, 43UL, 25UL, 39UL, 0UL, 0UL, 0UL); - c2 = Avx512F.RotateLeftVariable(c2, rhoVec2); - - Vector512 rhoVec3 = Vector512.Create(41UL, 45UL, 15UL, 21UL, 8UL, 0UL, 0UL, 0UL); - c3 = Avx512F.RotateLeftVariable(c3, rhoVec3); - - Vector512 rhoVec4 = Vector512.Create(18UL, 2UL, 61UL, 56UL, 14UL, 0UL, 0UL, 0UL); - c4 = Avx512F.RotateLeftVariable(c4, rhoVec4); - - // Pi step - Vector512 c0Pi = Avx512F.PermuteVar8x64x2(c0, Vector512.Create(0UL, 8 + 1, 2, 3, 4, 5, 6, 7), c1); - c0Pi = Avx512F.PermuteVar8x64x2(c0Pi, Vector512.Create(0UL, 1, 8 + 2, 3, 4, 5, 6, 7), c2); - c0Pi = Avx512F.PermuteVar8x64x2(c0Pi, Vector512.Create(0UL, 1, 2, 8 + 3, 4, 5, 6, 7), c3); - c0Pi = Avx512F.PermuteVar8x64x2(c0Pi, Vector512.Create(0UL, 1, 2, 3, 8 + 4, 5, 6, 7), c4); - - Vector512 c1Pi = Avx512F.PermuteVar8x64x2(c0, Vector512.Create(3UL, 8 + 4, 2, 3, 4, 5, 6, 7), c1); - c1Pi = Avx512F.PermuteVar8x64x2(c1Pi, Vector512.Create(0UL, 1, 8 + 0, 3, 4, 5, 6, 7), c2); - c1Pi = Avx512F.PermuteVar8x64x2(c1Pi, Vector512.Create(0UL, 1, 2, 8 + 1, 4, 5, 6, 7), c3); - c1Pi = Avx512F.PermuteVar8x64x2(c1Pi, Vector512.Create(0UL, 1, 2, 3, 8 + 2, 5, 6, 7), c4); - - Vector512 c2Pi = Avx512F.PermuteVar8x64x2(c0, Vector512.Create(1UL, 8 + 2, 2, 3, 4, 5, 6, 7), c1); - c2Pi = Avx512F.PermuteVar8x64x2(c2Pi, Vector512.Create(0UL, 1, 8 + 3, 3, 4, 5, 6, 7), c2); - c2Pi = Avx512F.PermuteVar8x64x2(c2Pi, Vector512.Create(0UL, 1, 2, 8 + 4, 4, 5, 6, 7), c3); - c2Pi = Avx512F.PermuteVar8x64x2(c2Pi, Vector512.Create(0UL, 1, 2, 3, 8 + 0, 5, 6, 7), c4); - - Vector512 c3Pi = Avx512F.PermuteVar8x64x2(c0, Vector512.Create(4UL, 8 + 0, 2, 3, 4, 5, 6, 7), c1); - c3Pi = Avx512F.PermuteVar8x64x2(c3Pi, Vector512.Create(0UL, 1, 8 + 1, 3, 4, 5, 6, 7), c2); - c3Pi = Avx512F.PermuteVar8x64x2(c3Pi, Vector512.Create(0UL, 1, 2, 8 + 2, 4, 5, 6, 7), c3); - c3Pi = Avx512F.PermuteVar8x64x2(c3Pi, Vector512.Create(0UL, 1, 2, 3, 8 + 3, 5, 6, 7), c4); - - Vector512 c4Pi = Avx512F.PermuteVar8x64x2(c0, Vector512.Create(2UL, 8 + 3, 2, 3, 4, 5, 6, 7), c1); - c4Pi = Avx512F.PermuteVar8x64x2(c4Pi, Vector512.Create(0UL, 1, 8 + 4, 3, 4, 5, 6, 7), c2); - c4Pi = Avx512F.PermuteVar8x64x2(c4Pi, Vector512.Create(0UL, 1, 2, 8 + 0, 4, 5, 6, 7), c3); - c4Pi = Avx512F.PermuteVar8x64x2(c4Pi, Vector512.Create(0UL, 1, 2, 3, 8 + 1, 5, 6, 7), c4); - - c0 = c0Pi; - c1 = c1Pi; - c2 = c2Pi; - c3 = c3Pi; - c4 = c4Pi; - - // Chi step - Vector512 permute1 = Vector512.Create(1UL, 2UL, 3UL, 4UL, 0UL, 5UL, 6UL, 7UL); - Vector512 permute2 = Vector512.Create(2UL, 3UL, 4UL, 0UL, 1UL, 5UL, 6UL, 7UL); - - c0 = Avx512F.TernaryLogic(c0, Avx512F.PermuteVar8x64(c0, permute1), Avx512F.PermuteVar8x64(c0, permute2), 0xD2); - c1 = Avx512F.TernaryLogic(c1, Avx512F.PermuteVar8x64(c1, permute1), Avx512F.PermuteVar8x64(c1, permute2), 0xD2); - c2 = Avx512F.TernaryLogic(c2, Avx512F.PermuteVar8x64(c2, permute1), Avx512F.PermuteVar8x64(c2, permute2), 0xD2); - c3 = Avx512F.TernaryLogic(c3, Avx512F.PermuteVar8x64(c3, permute1), Avx512F.PermuteVar8x64(c3, permute2), 0xD2); - c4 = Avx512F.TernaryLogic(c4, Avx512F.PermuteVar8x64(c4, permute1), Avx512F.PermuteVar8x64(c4, permute2), 0xD2); - - // Iota step - c0 = Vector512.Xor(c0, Vector512.Create(roundConstants[round], 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL)); - } - - // Can over-write for first elements - Unsafe.As>(ref MemoryMarshal.GetReference(state)) = c0; - Unsafe.As>(ref Unsafe.Add(ref MemoryMarshal.GetReference(state), 5)) = c1; - Unsafe.As>(ref Unsafe.Add(ref MemoryMarshal.GetReference(state), 10)) = c2; - Unsafe.As>(ref Unsafe.Add(ref MemoryMarshal.GetReference(state), 15)) = c3; - // Can't over-write for last elements so write the upper Vector256 and then ulong - Unsafe.As>(ref Unsafe.Add(ref MemoryMarshal.GetReference(state), 20)) = c3.GetUpper(); - state[24] = c4.GetElement(4); - } } } From 29613fdf528e4d75c7fc09d17489064c37bcc287 Mon Sep 17 00:00:00 2001 From: ak88 Date: Wed, 9 Oct 2024 11:54:45 +0200 Subject: [PATCH 04/12] Fix/tool projects build errors (#7579) --- tools/SendBlobs/AccountException.cs | 4 ---- tools/SendBlobs/BlobSender.cs | 6 +++--- tools/SendBlobs/FundsDistributor.cs | 4 ++-- tools/TxParser/Program.cs | 3 +-- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/tools/SendBlobs/AccountException.cs b/tools/SendBlobs/AccountException.cs index 624e8754a86..00f66e3966f 100644 --- a/tools/SendBlobs/AccountException.cs +++ b/tools/SendBlobs/AccountException.cs @@ -22,8 +22,4 @@ public AccountException(string? message) : base(message) public AccountException(string? message, Exception? innerException) : base(message, innerException) { } - - protected AccountException(SerializationInfo info, StreamingContext context) : base(info, context) - { - } } diff --git a/tools/SendBlobs/BlobSender.cs b/tools/SendBlobs/BlobSender.cs index 4b4d0889ced..008523c85e5 100644 --- a/tools/SendBlobs/BlobSender.cs +++ b/tools/SendBlobs/BlobSender.cs @@ -16,7 +16,7 @@ namespace SendBlobs; internal class BlobSender { - private static readonly TxDecoder txDecoder = new(); + private static readonly TxDecoder txDecoder = TxDecoder.Instance; private INodeManager _nodeManager; private readonly ILogger _logger; @@ -85,7 +85,7 @@ public async Task SendRandomBlobs( signers.Add(new(new Signer(chainId, privateKey, _logManager), nonce)); } - TxDecoder txDecoder = new(); + TxDecoder txDecoder = TxDecoder.Instance; Random random = new(); int signerIndex = -1; @@ -283,7 +283,7 @@ public async Task SendData( if (defaultMaxFeePerBlobGas is null) { ulong excessBlobsReserve = 2 * Eip4844Constants.TargetBlobGasPerBlock; - BlobGasCalculator.TryCalculateBlobGasPricePerUnit( + BlobGasCalculator.TryCalculateFeePerBlobGas( (block.ExcessBlobGas ?? 0) + excessBlobs * Eip4844Constants.MaxBlobGasPerBlock + excessBlobsReserve, diff --git a/tools/SendBlobs/FundsDistributor.cs b/tools/SendBlobs/FundsDistributor.cs index 6356d91d345..d794abbfeff 100644 --- a/tools/SendBlobs/FundsDistributor.cs +++ b/tools/SendBlobs/FundsDistributor.cs @@ -83,7 +83,7 @@ public async Task> DitributeFunds(Signer distributeFrom, uin List txHash = new List(); - TxDecoder txDecoder = new(); + TxDecoder txDecoder = TxDecoder.Instance; StreamWriter? keyWriter = null; if (!string.IsNullOrWhiteSpace(_keyFilePath)) @@ -147,7 +147,7 @@ public async Task> ReclaimFunds(Address beneficiary, UInt256 ILogger log = _logManager.GetClassLogger(); List txHashes = new List(); - TxDecoder txDecoder = new(); + TxDecoder txDecoder = TxDecoder.Instance; foreach (var signer in privateSigners) { diff --git a/tools/TxParser/Program.cs b/tools/TxParser/Program.cs index 409c755ef97..cd2baab450c 100644 --- a/tools/TxParser/Program.cs +++ b/tools/TxParser/Program.cs @@ -5,7 +5,6 @@ using Nethermind.Core.Extensions; using Nethermind.Serialization.Rlp; using Nethermind.Crypto; -using Nethermind.Logging; using Nethermind.Consensus.Validators; using Nethermind.Specs.Forks; @@ -21,7 +20,7 @@ TxValidator txValidator = new TxValidator(BlockchainIds.Mainnet); if (txValidator.IsWellFormed(tx, GrayGlacier.Instance)) { - EthereumEcdsa ecdsa = new(BlockchainIds.Mainnet, SimpleConsoleLogManager.Instance); + EthereumEcdsa ecdsa = new(BlockchainIds.Mainnet); Address? sender = ecdsa.RecoverAddress(tx); if (sender is null) { From 23018670ef5a8188eaee7ffa2c0daa79fefb2adf Mon Sep 17 00:00:00 2001 From: Lukasz Rozmej Date: Wed, 9 Oct 2024 14:05:27 +0200 Subject: [PATCH 05/12] Fix Blob index locking v2 (#7572) Co-authored-by: Marcin Sobczak --- .../Collections/BlobTxDistinctSortedPool.cs | 47 ++++++++++--------- .../Collections/DistinctValueSortedPool.cs | 10 ++-- .../PersistentBlobTxDistinctSortedPool.cs | 4 +- .../Collections/SortedPool.cs | 15 ++++-- 4 files changed, 43 insertions(+), 33 deletions(-) diff --git a/src/Nethermind/Nethermind.TxPool/Collections/BlobTxDistinctSortedPool.cs b/src/Nethermind/Nethermind.TxPool/Collections/BlobTxDistinctSortedPool.cs index d447cf4af9f..dc8e4ad85e1 100644 --- a/src/Nethermind/Nethermind.TxPool/Collections/BlobTxDistinctSortedPool.cs +++ b/src/Nethermind/Nethermind.TxPool/Collections/BlobTxDistinctSortedPool.cs @@ -4,6 +4,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; using Nethermind.Core; using Nethermind.Core.Crypto; using Nethermind.Core.Extensions; @@ -17,7 +18,7 @@ public class BlobTxDistinctSortedPool(int capacity, IComparer compa { protected override string ShortPoolName => "BlobPool"; - internal readonly ConcurrentDictionary> BlobIndex = new(Bytes.EqualityComparer); + internal readonly Dictionary> BlobIndex = new(Bytes.EqualityComparer); protected override IComparer GetReplacementComparer(IComparer comparer) => comparer.GetBlobReplacementComparer(); @@ -26,19 +27,24 @@ public bool TryGetBlobAndProof(byte[] requestedBlobVersionedHash, [NotNullWhen(true)] out byte[]? blob, [NotNullWhen(true)] out byte[]? proof) { - if (BlobIndex.TryGetValue(requestedBlobVersionedHash, out List? txHashes) - && txHashes[0] is not null - && TryGetValue(txHashes[0], out Transaction? blobTx) - && blobTx.BlobVersionedHashes?.Length > 0) + using var lockRelease = Lock.Acquire(); + + if (BlobIndex.TryGetValue(requestedBlobVersionedHash, out List? txHashes)) { - for (int indexOfBlob = 0; indexOfBlob < blobTx.BlobVersionedHashes.Length; indexOfBlob++) + foreach (Hash256 hash in CollectionsMarshal.AsSpan(txHashes)) { - if (Bytes.AreEqual(blobTx.BlobVersionedHashes[indexOfBlob], requestedBlobVersionedHash) - && blobTx.NetworkWrapper is ShardBlobNetworkWrapper wrapper) + if (TryGetValueNonLocked(hash, out Transaction? blobTx) && blobTx.BlobVersionedHashes?.Length > 0) { - blob = wrapper.Blobs[indexOfBlob]; - proof = wrapper.Proofs[indexOfBlob]; - return true; + for (int indexOfBlob = 0; indexOfBlob < blobTx.BlobVersionedHashes.Length; indexOfBlob++) + { + if (Bytes.AreEqual(blobTx.BlobVersionedHashes[indexOfBlob], requestedBlobVersionedHash) + && blobTx.NetworkWrapper is ShardBlobNetworkWrapper wrapper) + { + blob = wrapper.Blobs[indexOfBlob]; + proof = wrapper.Proofs[indexOfBlob]; + return true; + } + } } } } @@ -48,11 +54,11 @@ public bool TryGetBlobAndProof(byte[] requestedBlobVersionedHash, return false; } - public override bool TryInsert(ValueHash256 hash, Transaction blobTx, out Transaction? removed) + protected override bool InsertCore(ValueHash256 key, Transaction value, AddressAsKey groupKey) { - if (base.TryInsert(blobTx.Hash, blobTx, out removed)) + if (base.InsertCore(key, value, groupKey)) { - AddToBlobIndex(blobTx); + AddToBlobIndex(value); return true; } @@ -67,13 +73,9 @@ protected void AddToBlobIndex(Transaction blobTx) { if (blobVersionedHash?.Length == KzgPolynomialCommitments.BytesPerBlobVersionedHash) { - BlobIndex.AddOrUpdate(blobVersionedHash, - k => [blobTx.Hash!], - (k, b) => - { - b.Add(blobTx.Hash!); - return b; - }); + ref List? list = ref CollectionsMarshal.GetValueRefOrAddDefault(BlobIndex, blobVersionedHash, out _); + list ??= new List(); + list.Add(blobTx.Hash!); } } } @@ -99,8 +101,7 @@ private void RemoveFromBlobIndex(Transaction blobTx) { foreach (var blobVersionedHash in blobTx.BlobVersionedHashes) { - if (blobVersionedHash is not null - && BlobIndex.TryGetValue(blobVersionedHash, out List? txHashes)) + if (blobVersionedHash is not null && BlobIndex.TryGetValue(blobVersionedHash, out List? txHashes)) { if (txHashes.Count < 2) { diff --git a/src/Nethermind/Nethermind.TxPool/Collections/DistinctValueSortedPool.cs b/src/Nethermind/Nethermind.TxPool/Collections/DistinctValueSortedPool.cs index c37a14346d0..86821529b2d 100644 --- a/src/Nethermind/Nethermind.TxPool/Collections/DistinctValueSortedPool.cs +++ b/src/Nethermind/Nethermind.TxPool/Collections/DistinctValueSortedPool.cs @@ -45,16 +45,20 @@ protected DistinctValueSortedPool( protected virtual IComparer GetReplacementComparer(IComparer comparer) => comparer; - protected override void InsertCore(TKey key, TValue value, TGroupKey groupKey) + protected override bool InsertCore(TKey key, TValue value, TGroupKey groupKey) { if (_distinctDictionary.TryGetValue(value, out KeyValuePair oldKvp)) { TryRemoveNonLocked(oldKvp.Key, evicted: false, out _, out _); } - base.InsertCore(key, value, groupKey); + if (base.InsertCore(key, value, groupKey)) + { + _distinctDictionary[value] = new KeyValuePair(key, value); + return true; + } - _distinctDictionary[value] = new KeyValuePair(key, value); + return false; } protected override bool Remove(TKey key, out TValue? value) diff --git a/src/Nethermind/Nethermind.TxPool/Collections/PersistentBlobTxDistinctSortedPool.cs b/src/Nethermind/Nethermind.TxPool/Collections/PersistentBlobTxDistinctSortedPool.cs index d768df97d28..c8dcbee9b96 100644 --- a/src/Nethermind/Nethermind.TxPool/Collections/PersistentBlobTxDistinctSortedPool.cs +++ b/src/Nethermind/Nethermind.TxPool/Collections/PersistentBlobTxDistinctSortedPool.cs @@ -52,9 +52,9 @@ private void RecreateLightTxCollectionAndCache(ITxStorage blobTxStorage) } } - public override bool TryInsert(ValueHash256 hash, Transaction fullBlobTx, out Transaction? removed) + protected override bool InsertCore(ValueHash256 hash, Transaction fullBlobTx, AddressAsKey groupKey) { - if (base.TryInsert(fullBlobTx.Hash, new LightTransaction(fullBlobTx), out removed)) + if (base.InsertCore(hash, new LightTransaction(fullBlobTx), groupKey)) { _blobTxCache.Set(fullBlobTx.Hash, fullBlobTx); _blobTxStorage.Add(fullBlobTx); diff --git a/src/Nethermind/Nethermind.TxPool/Collections/SortedPool.cs b/src/Nethermind/Nethermind.TxPool/Collections/SortedPool.cs index 98a32ce04e3..fd3bda14b9b 100644 --- a/src/Nethermind/Nethermind.TxPool/Collections/SortedPool.cs +++ b/src/Nethermind/Nethermind.TxPool/Collections/SortedPool.cs @@ -340,9 +340,11 @@ public virtual bool TryGetValue(TKey key, [NotNullWhen(true)] out TValue? value) { using var lockRelease = Lock.Acquire(); - return _cacheMap.TryGetValue(key, out value) && value is not null; + return TryGetValueNonLocked(key, out value); } + protected bool TryGetValueNonLocked(TKey key, [NotNullWhen(true)] out TValue? value) => _cacheMap.TryGetValue(key, out value) && value is not null; + /// /// Tries to insert element. /// @@ -360,7 +362,7 @@ public virtual bool TryInsert(TKey key, TValue value, out TValue? removed) if (group is not null) { - InsertCore(key, value, group); + bool inserted = InsertCore(key, value, group); if (_cacheMap.Count > _capacity) { @@ -372,11 +374,11 @@ public virtual bool TryInsert(TKey key, TValue value, out TValue? removed) RemoveLast(out removed); } - return true; + return inserted; } removed = default; - return true; + return inserted; } } @@ -430,7 +432,7 @@ protected virtual bool CanInsert(TKey key, TValue value) /// /// Actual insert mechanism. /// - protected virtual void InsertCore(TKey key, TValue value, TGroupKey groupKey) + protected virtual bool InsertCore(TKey key, TValue value, TGroupKey groupKey) { if (!_buckets.TryGetValue(groupKey, out EnhancedSortedSet? bucket)) { @@ -445,7 +447,10 @@ protected virtual void InsertCore(TKey key, TValue value, TGroupKey groupKey) UpdateSortedValues(bucket, last); _snapshot = null; Inserted?.Invoke(this, new SortedPoolEventArgs(key, value)); + return true; } + + return false; } private void UpdateSortedValues(EnhancedSortedSet bucket, TValue? previousLast) From 00d1680d0e6af4129743031fbefd0e937bbfbfb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Moraczy=C5=84ski?= Date: Wed, 9 Oct 2024 14:51:22 +0200 Subject: [PATCH 06/12] One more test in TargetAdjustedGasLimitCalculator (#7582) --- .../TargetAdjustedGasLimitCalculatorTests.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Nethermind/Nethermind.Consensus.Test/TargetAdjustedGasLimitCalculatorTests.cs b/src/Nethermind/Nethermind.Consensus.Test/TargetAdjustedGasLimitCalculatorTests.cs index 2f96501987d..e049e77b6e2 100644 --- a/src/Nethermind/Nethermind.Consensus.Test/TargetAdjustedGasLimitCalculatorTests.cs +++ b/src/Nethermind/Nethermind.Consensus.Test/TargetAdjustedGasLimitCalculatorTests.cs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LGPL-3.0-only +using FluentAssertions; using Nethermind.Config; using Nethermind.Core; using Nethermind.Core.Test.Builders; @@ -29,5 +30,21 @@ public void Is_bump_on_1559_eip_block() long actualValue = targetedAdjustedGasLimitCalculator.GetGasLimit(header); Assert.That(actualValue, Is.EqualTo(gasLimit * Eip1559Constants.DefaultElasticityMultiplier)); } + + [TestCase(30_000_000, 100_000_000, 30029295)] + public void Is_calculating_correct_gasLimit(long currentGasLimit, long targetGasLimit, long expectedGasLimit) + { + int blockNumber = 20_000_000; + long gasLimit = currentGasLimit; + TestSpecProvider specProvider = new(Prague.Instance); + TargetAdjustedGasLimitCalculator targetedAdjustedGasLimitCalculator = new(specProvider, + new BlocksConfig() + { + TargetBlockGasLimit = targetGasLimit + }); + BlockHeader header = Build.A.BlockHeader.WithNumber(blockNumber - 1).WithGasLimit(gasLimit).TestObject; + long actualValue = targetedAdjustedGasLimitCalculator.GetGasLimit(header); + actualValue.Should().Be(expectedGasLimit); + } } } From 807111c15fd2bc8c961f384cc241ac0b9c733adc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Moraczy=C5=84ski?= Date: Wed, 9 Oct 2024 15:07:04 +0200 Subject: [PATCH 07/12] Opt-in censorship detector (#7583) --- .../Processing/CensorshipDetector/CensorshipDetectorConfig.cs | 2 +- .../Processing/CensorshipDetector/ICensorshipDetectorConfig.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/Processing/CensorshipDetector/CensorshipDetectorConfig.cs b/src/Nethermind/Nethermind.Consensus/Processing/CensorshipDetector/CensorshipDetectorConfig.cs index c350c8bf8b4..b4e3bb243fd 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/CensorshipDetector/CensorshipDetectorConfig.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/CensorshipDetector/CensorshipDetectorConfig.cs @@ -5,7 +5,7 @@ namespace Nethermind.Consensus.Processing.CensorshipDetector; public class CensorshipDetectorConfig : ICensorshipDetectorConfig { - public bool Enabled { get; set; } = true; + public bool Enabled { get; set; } = false; public uint BlockCensorshipThreshold { get; set; } = 2; public string[]? AddressesForCensorshipDetection { get; set; } = null; } diff --git a/src/Nethermind/Nethermind.Consensus/Processing/CensorshipDetector/ICensorshipDetectorConfig.cs b/src/Nethermind/Nethermind.Consensus/Processing/CensorshipDetector/ICensorshipDetectorConfig.cs index 29dec2ddf4d..259636bb7ca 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/CensorshipDetector/ICensorshipDetectorConfig.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/CensorshipDetector/ICensorshipDetectorConfig.cs @@ -7,7 +7,7 @@ namespace Nethermind.Consensus.Processing.CensorshipDetector; public interface ICensorshipDetectorConfig : IConfig { - [ConfigItem(DefaultValue = "true", + [ConfigItem(DefaultValue = "false", Description = "Enabling censorship detection feature")] bool Enabled { get; set; } From 5c468392ea820c9ca1321fbb67c47ddfa8c620f8 Mon Sep 17 00:00:00 2001 From: Marcin Sobczak <77129288+marcindsobczak@users.noreply.github.com> Date: Wed, 9 Oct 2024 15:30:08 +0200 Subject: [PATCH 08/12] Add test for `engine_getBlobsV1` concurrency (#7581) Co-authored-by: Lukasz Rozmej --- .../TxPoolTests.Blobs.cs | 60 +++++++++++++++++++ .../Collections/BlobTxDistinctSortedPool.cs | 2 +- .../PersistentBlobTxDistinctSortedPool.cs | 4 +- .../Collections/SortedPool.cs | 4 +- 4 files changed, 65 insertions(+), 5 deletions(-) diff --git a/src/Nethermind/Nethermind.TxPool.Test/TxPoolTests.Blobs.cs b/src/Nethermind/Nethermind.TxPool.Test/TxPoolTests.Blobs.cs index f95d2eb8c31..b2e21635f62 100644 --- a/src/Nethermind/Nethermind.TxPool.Test/TxPoolTests.Blobs.cs +++ b/src/Nethermind/Nethermind.TxPool.Test/TxPoolTests.Blobs.cs @@ -12,6 +12,7 @@ using Nethermind.Core.Test.Builders; using Nethermind.Crypto; using Nethermind.Evm; +using Nethermind.Evm.Tracing.GethStyle.Custom.JavaScript; using Nethermind.Int256; using Nethermind.Logging; using Nethermind.TxPool.Collections; @@ -679,6 +680,65 @@ public void should_index_blobs_when_adding_txs([Values(true, false)] bool isPers } } + [Test] + [Repeat(3)] + public void should_handle_indexing_blobs_when_adding_txs_in_parallel([Values(true, false)] bool isPersistentStorage) + { + const int txsPerSender = 10; + int poolSize = TestItem.PrivateKeys.Length * txsPerSender; + TxPoolConfig txPoolConfig = new() + { + BlobsSupport = isPersistentStorage ? BlobsSupportMode.Storage : BlobsSupportMode.InMemory, + PersistentBlobStorageSize = isPersistentStorage ? poolSize : 0, + InMemoryBlobPoolSize = isPersistentStorage ? 0 : poolSize + }; + + IComparer comparer = new TransactionComparerProvider(_specProvider, _blockTree).GetDefaultComparer(); + + BlobTxDistinctSortedPool blobPool = isPersistentStorage + ? new PersistentBlobTxDistinctSortedPool(new BlobTxStorage(), txPoolConfig, comparer, LimboLogs.Instance) + : new BlobTxDistinctSortedPool(txPoolConfig.InMemoryBlobPoolSize, comparer, LimboLogs.Instance); + + byte[] expectedBlobVersionedHash = null; + + foreach (PrivateKey privateKey in TestItem.PrivateKeys) + { + EnsureSenderBalance(privateKey.Address, UInt256.MaxValue); + } + + // adding, getting and removing txs in parallel + Parallel.ForEach(TestItem.PrivateKeys, privateKey => + { + for (int i = 0; i < txsPerSender; i++) + { + Transaction tx = Build.A.Transaction + .WithNonce((UInt256)i) + .WithShardBlobTxTypeAndFields() + .WithMaxFeePerGas(1.GWei()) + .WithMaxPriorityFeePerGas(1.GWei()) + .WithMaxFeePerBlobGas(1000.Wei()) + .SignedAndResolved(_ethereumEcdsa, privateKey).TestObject; + + expectedBlobVersionedHash ??= tx.BlobVersionedHashes[0]!; + + blobPool.TryInsert(tx.Hash, tx, out _).Should().BeTrue(); + + for (int j = 0; j < 100; j++) + { + blobPool.TryGetBlobAndProof(expectedBlobVersionedHash.ToBytes(), out _, out _).Should().BeTrue(); + } + + // removing 50% of txs + if (i % 2 == 0) blobPool.TryRemove(tx.Hash, out _).Should().BeTrue(); + } + }); + + // we expect index to have 1 key with poolSize/2 values (50% of txs were removed) + blobPool.BlobIndex.Count.Should().Be(1); + blobPool.BlobIndex.TryGetValue(expectedBlobVersionedHash, out List values).Should().BeTrue(); + values.Count.Should().Be(poolSize / 2); + } + private Transaction GetTx(PrivateKey sender) { return Build.A.Transaction diff --git a/src/Nethermind/Nethermind.TxPool/Collections/BlobTxDistinctSortedPool.cs b/src/Nethermind/Nethermind.TxPool/Collections/BlobTxDistinctSortedPool.cs index dc8e4ad85e1..9f814668b0e 100644 --- a/src/Nethermind/Nethermind.TxPool/Collections/BlobTxDistinctSortedPool.cs +++ b/src/Nethermind/Nethermind.TxPool/Collections/BlobTxDistinctSortedPool.cs @@ -120,5 +120,5 @@ private void RemoveFromBlobIndex(Transaction blobTx) /// For tests only - to test sorting /// internal void TryGetBlobTxSortingEquivalent(Hash256 hash, out Transaction? lightBlobTx) - => base.TryGetValue(hash, out lightBlobTx); + => base.TryGetValueNonLocked(hash, out lightBlobTx); } diff --git a/src/Nethermind/Nethermind.TxPool/Collections/PersistentBlobTxDistinctSortedPool.cs b/src/Nethermind/Nethermind.TxPool/Collections/PersistentBlobTxDistinctSortedPool.cs index c8dcbee9b96..26e3d7ad826 100644 --- a/src/Nethermind/Nethermind.TxPool/Collections/PersistentBlobTxDistinctSortedPool.cs +++ b/src/Nethermind/Nethermind.TxPool/Collections/PersistentBlobTxDistinctSortedPool.cs @@ -64,11 +64,11 @@ protected override bool InsertCore(ValueHash256 hash, Transaction fullBlobTx, Ad return false; } - public override bool TryGetValue(ValueHash256 hash, [NotNullWhen(true)] out Transaction? fullBlobTx) + protected override bool TryGetValueNonLocked(ValueHash256 hash, [NotNullWhen(true)] out Transaction? fullBlobTx) { // Firstly check if tx is present in in-memory collection of light blob txs (without actual blobs). // If not, just return false - if (base.TryGetValue(hash, out Transaction? lightTx)) + if (base.TryGetValueNonLocked(hash, out Transaction? lightTx)) { // tx is present in light collection. Try to get full blob tx from cache if (_blobTxCache.TryGet(hash, out fullBlobTx)) diff --git a/src/Nethermind/Nethermind.TxPool/Collections/SortedPool.cs b/src/Nethermind/Nethermind.TxPool/Collections/SortedPool.cs index fd3bda14b9b..c8db34851c7 100644 --- a/src/Nethermind/Nethermind.TxPool/Collections/SortedPool.cs +++ b/src/Nethermind/Nethermind.TxPool/Collections/SortedPool.cs @@ -336,14 +336,14 @@ public bool ContainsKey(TKey key) /// Key to be returned. /// Returned element or null. /// If element retrieval succeeded. True if element was present in pool. - public virtual bool TryGetValue(TKey key, [NotNullWhen(true)] out TValue? value) + public bool TryGetValue(TKey key, [NotNullWhen(true)] out TValue? value) { using var lockRelease = Lock.Acquire(); return TryGetValueNonLocked(key, out value); } - protected bool TryGetValueNonLocked(TKey key, [NotNullWhen(true)] out TValue? value) => _cacheMap.TryGetValue(key, out value) && value is not null; + protected virtual bool TryGetValueNonLocked(TKey key, [NotNullWhen(true)] out TValue? value) => _cacheMap.TryGetValue(key, out value) && value is not null; /// /// Tries to insert element. From a705c1a77246f0662be09d541658522d0e217794 Mon Sep 17 00:00:00 2001 From: Marc Date: Wed, 9 Oct 2024 15:04:28 +0100 Subject: [PATCH 09/12] BLS precompile native benchmarking & improvements (#7544) --- .../Collections/ArrayPoolList.cs | 3 +- ...ileTests.cs => BlsG1AddPrecompileTests.cs} | 0 ...ileTests.cs => BlsG1MSMPrecompileTests.cs} | 6 +- ...ileTests.cs => BlsG2AddPrecompileTests.cs} | 2 +- ...ileTests.cs => BlsG2MSMPrecompileTests.cs} | 8 +- ...sMapToG2Tests.cs => BlsMapFp2ToG2Tests.cs} | 4 +- ...lsMapToG1Tests.cs => BlsMapFpToG1Tests.cs} | 4 +- ...s.cs => BlsPairingCheckPrecompileTests.cs} | 4 +- .../Nethermind.Evm/CodeInfoRepository.cs | 10 +- .../Precompiles/Bls/BlsConst.cs | 3 + .../Precompiles/Bls/BlsExtensions.cs | 76 ++++++++-- .../Precompiles/Bls/G1AddPrecompile.cs | 2 + ...ltiMulPrecompile.cs => G1MSMPrecompile.cs} | 49 +++--- .../Precompiles/Bls/G1MulPrecompile.cs | 4 +- .../Precompiles/Bls/G2AddPrecompile.cs | 2 + ...ltiMulPrecompile.cs => G2MSMPrecompile.cs} | 51 ++++--- .../Precompiles/Bls/G2MulPrecompile.cs | 4 +- ...2Precompile.cs => MapFp2ToG2Precompile.cs} | 8 +- ...G1Precompile.cs => MapFpToG1Precompile.cs} | 8 +- ...recompile.cs => PairingCheckPrecompile.cs} | 21 ++- .../NativeCallTracerCallFrameConverter.cs | 4 +- .../BlsG1AddBenchmark.cs | 18 +++ .../BlsG1MSMBenchmark.cs | 18 +++ .../BlsG1MulBenchmark.cs | 18 +++ .../BlsG2AddBenchmark.cs | 18 +++ .../BlsG2MSMBenchmark.cs | 18 +++ .../BlsG2MulBenchmark.cs | 18 +++ .../BlsMapFp2ToG2Benchmark.cs | 18 +++ .../BlsMapFpToG1Benchmark.cs | 18 +++ .../BlsPairingCheckBenchmark.cs | 18 +++ .../Nethermind.Precompiles.Benchmark.csproj | 4 - .../modexp/current/file.json | 142 ------------------ src/bench_precompiles | 2 +- 33 files changed, 342 insertions(+), 241 deletions(-) rename src/Nethermind/Nethermind.Evm.Test/{BlsAddG1PrecompileTests.cs => BlsG1AddPrecompileTests.cs} (100%) rename src/Nethermind/Nethermind.Evm.Test/{BlsMultiMulG1PrecompileTests.cs => BlsG1MSMPrecompileTests.cs} (99%) rename src/Nethermind/Nethermind.Evm.Test/{BlsAddG2PrecompileTests.cs => BlsG2AddPrecompileTests.cs} (99%) rename src/Nethermind/Nethermind.Evm.Test/{BlsMultiMulG2PrecompileTests.cs => BlsG2MSMPrecompileTests.cs} (99%) rename src/Nethermind/Nethermind.Evm.Test/{BlsMapToG2Tests.cs => BlsMapFp2ToG2Tests.cs} (99%) rename src/Nethermind/Nethermind.Evm.Test/{BlsMapToG1Tests.cs => BlsMapFpToG1Tests.cs} (99%) rename src/Nethermind/Nethermind.Evm.Test/{BlsPairingPrecompileTests.cs => BlsPairingCheckPrecompileTests.cs} (99%) rename src/Nethermind/Nethermind.Evm/Precompiles/Bls/{G1MultiMulPrecompile.cs => G1MSMPrecompile.cs} (62%) rename src/Nethermind/Nethermind.Evm/Precompiles/Bls/{G2MultiMulPrecompile.cs => G2MSMPrecompile.cs} (59%) rename src/Nethermind/Nethermind.Evm/Precompiles/Bls/{MapToG2Precompile.cs => MapFp2ToG2Precompile.cs} (85%) rename src/Nethermind/Nethermind.Evm/Precompiles/Bls/{MapToG1Precompile.cs => MapFpToG1Precompile.cs} (82%) rename src/Nethermind/Nethermind.Evm/Precompiles/Bls/{PairingPrecompile.cs => PairingCheckPrecompile.cs} (74%) create mode 100644 src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG1AddBenchmark.cs create mode 100644 src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG1MSMBenchmark.cs create mode 100644 src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG1MulBenchmark.cs create mode 100644 src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG2AddBenchmark.cs create mode 100644 src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG2MSMBenchmark.cs create mode 100644 src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG2MulBenchmark.cs create mode 100644 src/Nethermind/Nethermind.Precompiles.Benchmark/BlsMapFp2ToG2Benchmark.cs create mode 100644 src/Nethermind/Nethermind.Precompiles.Benchmark/BlsMapFpToG1Benchmark.cs create mode 100644 src/Nethermind/Nethermind.Precompiles.Benchmark/BlsPairingCheckBenchmark.cs delete mode 100644 src/Nethermind/Nethermind.Precompiles.Benchmark/modexp/current/file.json diff --git a/src/Nethermind/Nethermind.Core/Collections/ArrayPoolList.cs b/src/Nethermind/Nethermind.Core/Collections/ArrayPoolList.cs index c43e1ee0b0a..827c592d5e6 100644 --- a/src/Nethermind/Nethermind.Core/Collections/ArrayPoolList.cs +++ b/src/Nethermind/Nethermind.Core/Collections/ArrayPoolList.cs @@ -363,5 +363,6 @@ public void Dispose() public Span AsSpan() => _array.AsSpan(0, Count); - public ReadOnlyMemory AsMemory() => new(_array, 0, Count); + public Memory AsMemory() => new(_array, 0, Count); + public ReadOnlyMemory AsReadOnlyMemory() => new(_array, 0, Count); } diff --git a/src/Nethermind/Nethermind.Evm.Test/BlsAddG1PrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BlsG1AddPrecompileTests.cs similarity index 100% rename from src/Nethermind/Nethermind.Evm.Test/BlsAddG1PrecompileTests.cs rename to src/Nethermind/Nethermind.Evm.Test/BlsG1AddPrecompileTests.cs diff --git a/src/Nethermind/Nethermind.Evm.Test/BlsMultiMulG1PrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BlsG1MSMPrecompileTests.cs similarity index 99% rename from src/Nethermind/Nethermind.Evm.Test/BlsMultiMulG1PrecompileTests.cs rename to src/Nethermind/Nethermind.Evm.Test/BlsG1MSMPrecompileTests.cs index 627ebd8c53c..9626fa7238e 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BlsMultiMulG1PrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BlsG1MSMPrecompileTests.cs @@ -12,15 +12,15 @@ namespace Nethermind.Evm.Test; -public class BlsMultiMulG1PrecompileTests +public class BlsG1MSMPrecompileTests { [Test] public void Test() { foreach ((byte[] input, ReadOnlyMemory expectedResult) in Inputs) { - IPrecompile precompile = G1MultiMulPrecompile.Instance; - (ReadOnlyMemory output, bool success) = precompile.Run(input, MuirGlacier.Instance); + IPrecompile precompile = G1MSMPrecompile.Instance; + (ReadOnlyMemory output, bool success) = precompile.Run(input, Prague.Instance); output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray()); success.Should().BeTrue(); } diff --git a/src/Nethermind/Nethermind.Evm.Test/BlsAddG2PrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BlsG2AddPrecompileTests.cs similarity index 99% rename from src/Nethermind/Nethermind.Evm.Test/BlsAddG2PrecompileTests.cs rename to src/Nethermind/Nethermind.Evm.Test/BlsG2AddPrecompileTests.cs index 4c6dabd96a0..be2609d84ef 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BlsAddG2PrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BlsG2AddPrecompileTests.cs @@ -12,7 +12,7 @@ namespace Nethermind.Evm.Test; -public class BlsAddG2PrecompileTests +public class BlsG2AddPrecompileTests { [Test] public void Test() diff --git a/src/Nethermind/Nethermind.Evm.Test/BlsMultiMulG2PrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BlsG2MSMPrecompileTests.cs similarity index 99% rename from src/Nethermind/Nethermind.Evm.Test/BlsMultiMulG2PrecompileTests.cs rename to src/Nethermind/Nethermind.Evm.Test/BlsG2MSMPrecompileTests.cs index 3914ae8e860..c9310444b3b 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BlsMultiMulG2PrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BlsG2MSMPrecompileTests.cs @@ -8,19 +8,19 @@ using Nethermind.Evm.Precompiles; using Nethermind.Evm.Precompiles.Bls; using NUnit.Framework; -using static Nethermind.Specs.Forks.MuirGlacier; +using Nethermind.Specs.Forks; namespace Nethermind.Evm.Test; -public class BlsMultiMulG2PrecompileTests +public class BlsG2MSMPrecompileTests { [Test] public void Test() { foreach ((byte[] input, ReadOnlyMemory expectedResult) in Inputs) { - IPrecompile precompile = G2MultiMulPrecompile.Instance; - (ReadOnlyMemory output, bool success) = precompile.Run(input, Instance); + IPrecompile precompile = G2MSMPrecompile.Instance; + (ReadOnlyMemory output, bool success) = precompile.Run(input, Prague.Instance); output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray()); success.Should().BeTrue(); } diff --git a/src/Nethermind/Nethermind.Evm.Test/BlsMapToG2Tests.cs b/src/Nethermind/Nethermind.Evm.Test/BlsMapFp2ToG2Tests.cs similarity index 99% rename from src/Nethermind/Nethermind.Evm.Test/BlsMapToG2Tests.cs rename to src/Nethermind/Nethermind.Evm.Test/BlsMapFp2ToG2Tests.cs index 6122b9ac2a6..61982b51754 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BlsMapToG2Tests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BlsMapFp2ToG2Tests.cs @@ -12,14 +12,14 @@ namespace Nethermind.Evm.Test; -public class BlsMapToG2Tests +public class BlsMapFp2ToG2Tests { [Test] public void Test() { foreach ((byte[] input, ReadOnlyMemory expectedResult) in Inputs) { - IPrecompile precompile = MapToG2Precompile.Instance; + IPrecompile precompile = MapFp2ToG2Precompile.Instance; (ReadOnlyMemory output, bool success) = precompile.Run(input, MuirGlacier.Instance); output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray()); diff --git a/src/Nethermind/Nethermind.Evm.Test/BlsMapToG1Tests.cs b/src/Nethermind/Nethermind.Evm.Test/BlsMapFpToG1Tests.cs similarity index 99% rename from src/Nethermind/Nethermind.Evm.Test/BlsMapToG1Tests.cs rename to src/Nethermind/Nethermind.Evm.Test/BlsMapFpToG1Tests.cs index 35f44f4151e..801f1fdc387 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BlsMapToG1Tests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BlsMapFpToG1Tests.cs @@ -12,14 +12,14 @@ namespace Nethermind.Evm.Test; -public class BlsMapToG1Tests +public class BlsMapFpToG1Tests { [Test] public void Test() { foreach ((byte[] input, ReadOnlyMemory expectedResult) in Inputs) { - IPrecompile precompile = MapToG1Precompile.Instance; + IPrecompile precompile = MapFpToG1Precompile.Instance; (ReadOnlyMemory output, bool success) = precompile.Run(input, MuirGlacier.Instance); output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray()); diff --git a/src/Nethermind/Nethermind.Evm.Test/BlsPairingPrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BlsPairingCheckPrecompileTests.cs similarity index 99% rename from src/Nethermind/Nethermind.Evm.Test/BlsPairingPrecompileTests.cs rename to src/Nethermind/Nethermind.Evm.Test/BlsPairingCheckPrecompileTests.cs index f717785b44f..ee490e4513e 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BlsPairingPrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BlsPairingCheckPrecompileTests.cs @@ -12,14 +12,14 @@ namespace Nethermind.Evm.Test; -public class BlsPairingPrecompileTests +public class BlsPairingCheckPrecompileTests { [Test] public void Test() { foreach ((byte[] input, ReadOnlyMemory expectedResult) in Inputs) { - IPrecompile precompile = PairingPrecompile.Instance; + IPrecompile precompile = PairingCheckPrecompile.Instance; (ReadOnlyMemory output, bool success) = precompile.Run(input, MuirGlacier.Instance); output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray()); diff --git a/src/Nethermind/Nethermind.Evm/CodeInfoRepository.cs b/src/Nethermind/Nethermind.Evm/CodeInfoRepository.cs index 99e8d3720d5..fe631b3fb10 100644 --- a/src/Nethermind/Nethermind.Evm/CodeInfoRepository.cs +++ b/src/Nethermind/Nethermind.Evm/CodeInfoRepository.cs @@ -44,13 +44,13 @@ private static FrozenDictionary InitializePrecompiledCon [G1AddPrecompile.Address] = new(G1AddPrecompile.Instance), [G1MulPrecompile.Address] = new(G1MulPrecompile.Instance), - [G1MultiMulPrecompile.Address] = new(G1MultiMulPrecompile.Instance), + [G1MSMPrecompile.Address] = new(G1MSMPrecompile.Instance), [G2AddPrecompile.Address] = new(G2AddPrecompile.Instance), [G2MulPrecompile.Address] = new(G2MulPrecompile.Instance), - [G2MultiMulPrecompile.Address] = new(G2MultiMulPrecompile.Instance), - [PairingPrecompile.Address] = new(PairingPrecompile.Instance), - [MapToG1Precompile.Address] = new(MapToG1Precompile.Instance), - [MapToG2Precompile.Address] = new(MapToG2Precompile.Instance), + [G2MSMPrecompile.Address] = new(G2MSMPrecompile.Instance), + [PairingCheckPrecompile.Address] = new(PairingCheckPrecompile.Instance), + [MapFpToG1Precompile.Address] = new(MapFpToG1Precompile.Instance), + [MapFp2ToG2Precompile.Address] = new(MapFp2ToG2Precompile.Instance), [PointEvaluationPrecompile.Address] = new(PointEvaluationPrecompile.Instance), diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/BlsConst.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/BlsConst.cs index 6587e354ee4..cd378705202 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/BlsConst.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/BlsConst.cs @@ -8,6 +8,8 @@ namespace Nethermind.Evm.Precompiles.Bls; public static class BlsConst { + public const bool DisableConcurrency = false; + public const bool DisableSubgroupChecks = false; public const int LenFr = 32; public const int LenFp = 64; public const int LenFpTrimmed = 48; @@ -16,6 +18,7 @@ public static class BlsConst public const int LenG1Trimmed = 2 * LenFpTrimmed; public const int LenG2 = 4 * LenFp; public const int LenG2Trimmed = 4 * LenFpTrimmed; + public static readonly byte[] BaseFieldOrder = [0x1a, 0x01, 0x11, 0xea, 0x39, 0x7f, 0xe6, 0x9a, 0x4b, 0x1b, 0xa7, 0xb6, 0x43, 0x4b, 0xac, 0xd7, 0x64, 0x77, 0x4b, 0x84, 0xf3, 0x85, 0x12, 0xbf, 0x67, 0x30, 0xd2, 0xa0, 0xf6, 0xb0, 0xf6, 0x24, 0x1e, 0xab, 0xff, 0xfe, 0xb1, 0x53, 0xff, 0xff, 0xb9, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xaa, 0xab]; public static readonly ReadOnlyMemory G1Inf = Enumerable.Repeat(0, 128).ToArray(); public static readonly ReadOnlyMemory G2Inf = Enumerable.Repeat(0, 256).ToArray(); diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/BlsExtensions.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/BlsExtensions.cs index 4a3d539b334..ab8d862d60d 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/BlsExtensions.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/BlsExtensions.cs @@ -41,20 +41,6 @@ public static bool TryDecodeRaw(this G1 p, ReadOnlySpan raw) return true; } - public static ReadOnlyMemory EncodeRaw(this G1 p) - { - if (p.IsInf()) - { - return BlsConst.G1Inf; - } - - byte[] raw = new byte[BlsConst.LenG1]; - ReadOnlySpan trimmed = p.Serialize(); - trimmed[..BlsConst.LenFpTrimmed].CopyTo(raw.AsSpan()[BlsConst.LenFpPad..BlsConst.LenFp]); - trimmed[BlsConst.LenFpTrimmed..].CopyTo(raw.AsSpan()[(BlsConst.LenFp + BlsConst.LenFpPad)..]); - return raw; - } - public static bool TryDecodeRaw(this G2 p, ReadOnlySpan raw) { if (raw.Length != BlsConst.LenG2) @@ -96,6 +82,20 @@ public static bool TryDecodeRaw(this G2 p, ReadOnlySpan raw) return true; } + public static ReadOnlyMemory EncodeRaw(this G1 p) + { + if (p.IsInf()) + { + return BlsConst.G1Inf; + } + + byte[] raw = new byte[BlsConst.LenG1]; + ReadOnlySpan trimmed = p.Serialize(); + trimmed[..BlsConst.LenFpTrimmed].CopyTo(raw.AsSpan()[BlsConst.LenFpPad..BlsConst.LenFp]); + trimmed[BlsConst.LenFpTrimmed..].CopyTo(raw.AsSpan()[(BlsConst.LenFp + BlsConst.LenFpPad)..]); + return raw; + } + public static ReadOnlyMemory EncodeRaw(this G2 p) { if (p.IsInf()) @@ -128,4 +128,52 @@ public static bool ValidRawFp(ReadOnlySpan fp) // check that fp < base field order return fp[BlsConst.LenFpPad..].SequenceCompareTo(BlsConst.BaseFieldOrder.AsSpan()) < 0; } + + public static bool TryDecodeG1ToBuffer(ReadOnlyMemory inputData, Memory pointBuffer, Memory scalarBuffer, int dest, int index) + => TryDecodePointToBuffer(inputData, pointBuffer, scalarBuffer, dest, index, BlsConst.LenG1, G1MSMPrecompile.ItemSize, DecodeAndCheckG1); + + public static bool TryDecodeG2ToBuffer(ReadOnlyMemory inputData, Memory pointBuffer, Memory scalarBuffer, int dest, int index) + => TryDecodePointToBuffer(inputData, pointBuffer, scalarBuffer, dest, index, BlsConst.LenG2, G2MSMPrecompile.ItemSize, DecodeAndCheckG2); + + private static bool DecodeAndCheckG1(ReadOnlyMemory rawPoint, Memory pointBuffer, int dest) + { + G1 p = new(pointBuffer.Span[(dest * G1.Sz)..]); + return p.TryDecodeRaw(rawPoint.Span) && (BlsConst.DisableSubgroupChecks || p.InGroup()); + } + + private static bool DecodeAndCheckG2(ReadOnlyMemory rawPoint, Memory pointBuffer, int dest) + { + G2 p = new(pointBuffer.Span[(dest * G2.Sz)..]); + return p.TryDecodeRaw(rawPoint.Span) && (BlsConst.DisableSubgroupChecks || p.InGroup()); + } + + private static bool TryDecodePointToBuffer( + ReadOnlyMemory inputData, + Memory pointBuffer, + Memory scalarBuffer, + int dest, + int index, + int pointLen, + int itemSize, + Func, Memory, int, bool> decodeAndCheckPoint) + { + if (dest == -1) + { + return true; + } + + int offset = index * itemSize; + ReadOnlyMemory rawPoint = inputData[offset..(offset + pointLen)]; + ReadOnlyMemory reversedScalar = inputData[(offset + pointLen)..(offset + itemSize)]; + + if (!decodeAndCheckPoint(rawPoint, pointBuffer, dest)) + { + return false; + } + + int destOffset = dest * 32; + reversedScalar.CopyTo(scalarBuffer[destOffset..]); + scalarBuffer[destOffset..(destOffset + 32)].Span.Reverse(); + return true; + } } diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1AddPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1AddPrecompile.cs index 2f23c913a8d..53df7f426df 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1AddPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1AddPrecompile.cs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LGPL-3.0-only using System; +using System.Runtime.CompilerServices; using Nethermind.Core; using Nethermind.Core.Specs; @@ -26,6 +27,7 @@ private G1AddPrecompile() public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0L; + [SkipLocalsInit] public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) { Metrics.BlsG1AddPrecompile++; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MultiMulPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MSMPrecompile.cs similarity index 62% rename from src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MultiMulPrecompile.cs rename to src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MSMPrecompile.cs index 3e1e9a1765d..8f3f734f37f 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MultiMulPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MSMPrecompile.cs @@ -8,17 +8,18 @@ using Nethermind.Core.Collections; using G1 = Nethermind.Crypto.Bls.P1; +using System.Runtime.CompilerServices; namespace Nethermind.Evm.Precompiles.Bls; /// /// https://eips.ethereum.org/EIPS/eip-2537 /// -public class G1MultiMulPrecompile : IPrecompile +public class G1MSMPrecompile : IPrecompile { - public static readonly G1MultiMulPrecompile Instance = new(); + public static readonly G1MSMPrecompile Instance = new(); - private G1MultiMulPrecompile() + private G1MSMPrecompile() { } @@ -32,8 +33,9 @@ public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec return 12000L * k * Discount.For(k) / 1000; } - private const int ItemSize = 160; + public const int ItemSize = 160; + [SkipLocalsInit] public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) { Metrics.BlsG1MSMPrecompile++; @@ -45,7 +47,7 @@ public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec int nItems = inputData.Length / ItemSize; - using ArrayPoolList rawPoints = new(nItems * 18, nItems * 18); + using ArrayPoolList rawPoints = new(nItems * G1.Sz, nItems * G1.Sz); using ArrayPoolList rawScalars = new(nItems * 32, nItems * 32); using ArrayPoolList pointDestinations = new(nItems); @@ -66,34 +68,39 @@ public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec } bool fail = false; - Parallel.ForEach(pointDestinations, (dest, state, i) => + +#pragma warning disable CS0162 // Unreachable code detected + if (BlsConst.DisableConcurrency) { - if (dest != -1) + for (int i = 0; i < pointDestinations.Count; i++) { - int offset = (int)i * ItemSize; - ReadOnlySpan rawPoint = inputData[offset..(offset + BlsConst.LenG1)].Span; - ReadOnlySpan rawScalar = inputData[(offset + BlsConst.LenG1)..(offset + ItemSize)].Span; - - G1 p = new(rawPoints.AsSpan()[(dest * 18)..]); - - if (!p.TryDecodeRaw(rawPoint) || !p.InGroup()) + if (!BlsExtensions.TryDecodeG1ToBuffer(inputData, rawPoints.AsMemory(), rawScalars.AsMemory(), pointDestinations[i], i)) { fail = true; - state.Break(); + break; } - - int destOffset = dest * 32; - rawScalar.CopyTo(rawScalars.AsSpan()[destOffset..]); - rawScalars.AsSpan()[destOffset..(destOffset + 32)].Reverse(); } - }); + } + else + { + Parallel.ForEach(pointDestinations, (dest, state, i) => + { + int index = (int)i; + if (!BlsExtensions.TryDecodeG1ToBuffer(inputData, rawPoints.AsMemory(), rawScalars.AsMemory(), dest, index)) + { + fail = true; + state.Break(); + } + }); + } +#pragma warning restore CS0162 // Unreachable code detected if (fail) { return IPrecompile.Failure; } - G1 res = new G1().MultiMult(rawPoints.AsSpan(), rawScalars.AsSpan(), npoints); + G1 res = new G1(stackalloc long[G1.Sz]).MultiMult(rawPoints.AsSpan(), rawScalars.AsSpan(), npoints); return (res.EncodeRaw(), true); } } diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs index ef78ac65181..18eb5889913 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LGPL-3.0-only using System; +using System.Runtime.CompilerServices; using Nethermind.Core; using Nethermind.Core.Specs; using G1 = Nethermind.Crypto.Bls.P1; @@ -25,6 +26,7 @@ private G1MulPrecompile() public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0L; + [SkipLocalsInit] public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) { Metrics.BlsG1MulPrecompile++; @@ -36,7 +38,7 @@ private G1MulPrecompile() } G1 x = new(stackalloc long[G1.Sz]); - if (!x.TryDecodeRaw(inputData[..BlsConst.LenG1].Span) || !x.InGroup()) + if (!x.TryDecodeRaw(inputData[..BlsConst.LenG1].Span) || !(BlsConst.DisableSubgroupChecks || x.InGroup())) { return IPrecompile.Failure; } diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs index ad0ed53a8d3..710954f3a3b 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LGPL-3.0-only using System; +using System.Runtime.CompilerServices; using Nethermind.Core; using Nethermind.Core.Specs; @@ -26,6 +27,7 @@ private G2AddPrecompile() public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0L; + [SkipLocalsInit] public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) { Metrics.BlsG2AddPrecompile++; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MultiMulPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MSMPrecompile.cs similarity index 59% rename from src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MultiMulPrecompile.cs rename to src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MSMPrecompile.cs index 714d0d6ad72..495e5c91a59 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MultiMulPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MSMPrecompile.cs @@ -8,17 +8,18 @@ using System.Threading.Tasks; using G2 = Nethermind.Crypto.Bls.P2; +using System.Runtime.CompilerServices; namespace Nethermind.Evm.Precompiles.Bls; /// /// https://eips.ethereum.org/EIPS/eip-2537 /// -public class G2MultiMulPrecompile : IPrecompile +public class G2MSMPrecompile : IPrecompile { - public static readonly G2MultiMulPrecompile Instance = new(); + public static readonly G2MSMPrecompile Instance = new(); - private G2MultiMulPrecompile() + private G2MSMPrecompile() { } @@ -32,8 +33,9 @@ public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec return 45000L * k * Discount.For(k) / 1000; } - private const int ItemSize = 288; + public const int ItemSize = 288; + [SkipLocalsInit] public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) { Metrics.BlsG2MSMPrecompile++; @@ -45,8 +47,8 @@ public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec int nItems = inputData.Length / ItemSize; - using ArrayPoolList rawPoints = new(nItems * 36, nItems * 36); - using ArrayPoolList rawScalars = new(nItems * 32, nItems * 32); + using ArrayPoolList pointBuffer = new(nItems * G2.Sz, nItems * G2.Sz); + using ArrayPoolList scalarBuffer = new(nItems * 32, nItems * 32); using ArrayPoolList pointDestinations = new(nItems); int npoints = 0; @@ -66,34 +68,39 @@ public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec } bool fail = false; - Parallel.ForEach(pointDestinations, (dest, state, i) => + +#pragma warning disable CS0162 // Unreachable code detected + if (BlsConst.DisableConcurrency) { - if (dest != -1) + for (int i = 0; i < pointDestinations.Count; i++) { - int offset = (int)i * ItemSize; - ReadOnlySpan rawPoint = inputData[offset..(offset + BlsConst.LenG2)].Span; - ReadOnlySpan rawScalar = inputData[(offset + BlsConst.LenG2)..(offset + ItemSize)].Span; - - G2 p = new(rawPoints.AsSpan()[(dest * 36)..]); - - if (!p.TryDecodeRaw(rawPoint) || !p.InGroup()) + if (!BlsExtensions.TryDecodeG2ToBuffer(inputData, pointBuffer.AsMemory(), scalarBuffer.AsMemory(), pointDestinations[i], i)) { fail = true; - state.Break(); + break; } - - int destOffset = dest * 32; - rawScalar.CopyTo(rawScalars.AsSpan()[destOffset..]); - rawScalars.AsSpan()[destOffset..(destOffset + 32)].Reverse(); } - }); + } + else + { + Parallel.ForEach(pointDestinations, (dest, state, i) => + { + int index = (int)i; + if (!BlsExtensions.TryDecodeG2ToBuffer(inputData, pointBuffer.AsMemory(), scalarBuffer.AsMemory(), dest, index)) + { + fail = true; + state.Break(); + } + }); + } +#pragma warning restore CS0162 // Unreachable code detected if (fail) { return IPrecompile.Failure; } - G2 res = new G2().MultiMult(rawPoints.AsSpan(), rawScalars.AsSpan(), npoints); + G2 res = new G2(stackalloc long[G2.Sz]).MultiMult(pointBuffer.AsSpan(), scalarBuffer.AsSpan(), npoints); return (res.EncodeRaw(), true); } diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs index 4756c49620a..fbe99e32867 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LGPL-3.0-only using System; +using System.Runtime.CompilerServices; using Nethermind.Core; using Nethermind.Core.Specs; @@ -26,6 +27,7 @@ private G2MulPrecompile() public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0L; + [SkipLocalsInit] public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) { Metrics.BlsG2MulPrecompile++; @@ -38,7 +40,7 @@ private G2MulPrecompile() } G2 x = new(stackalloc long[G2.Sz]); - if (!x.TryDecodeRaw(inputData[..BlsConst.LenG2].Span) || !x.InGroup()) + if (!x.TryDecodeRaw(inputData[..BlsConst.LenG2].Span) || !(BlsConst.DisableSubgroupChecks || x.InGroup())) { return IPrecompile.Failure; } diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG2Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs similarity index 85% rename from src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG2Precompile.cs rename to src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs index 9443a8c78da..5190c58be57 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG2Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LGPL-3.0-only using System; +using System.Runtime.CompilerServices; using Nethermind.Core; using Nethermind.Core.Specs; @@ -12,11 +13,11 @@ namespace Nethermind.Evm.Precompiles.Bls; /// /// https://eips.ethereum.org/EIPS/eip-2537 /// -public class MapToG2Precompile : IPrecompile +public class MapFp2ToG2Precompile : IPrecompile { - public static readonly MapToG2Precompile Instance = new(); + public static readonly MapFp2ToG2Precompile Instance = new(); - private MapToG2Precompile() + private MapFp2ToG2Precompile() { } @@ -26,6 +27,7 @@ private MapToG2Precompile() public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0L; + [SkipLocalsInit] public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) { Metrics.BlsMapFp2ToG2Precompile++; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG1Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs similarity index 82% rename from src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG1Precompile.cs rename to src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs index 441ad1d3c8b..eb1032ea1f5 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG1Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LGPL-3.0-only using System; +using System.Runtime.CompilerServices; using Nethermind.Core; using Nethermind.Core.Specs; using G1 = Nethermind.Crypto.Bls.P1; @@ -11,11 +12,11 @@ namespace Nethermind.Evm.Precompiles.Bls; /// /// https://eips.ethereum.org/EIPS/eip-2537 /// -public class MapToG1Precompile : IPrecompile +public class MapFpToG1Precompile : IPrecompile { - public static readonly MapToG1Precompile Instance = new MapToG1Precompile(); + public static readonly MapFpToG1Precompile Instance = new MapFpToG1Precompile(); - private MapToG1Precompile() + private MapFpToG1Precompile() { } @@ -25,6 +26,7 @@ private MapToG1Precompile() public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0L; + [SkipLocalsInit] public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) { Metrics.BlsMapFpToG1Precompile++; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs similarity index 74% rename from src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingPrecompile.cs rename to src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs index cf3412e4dab..6be90e9054a 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs @@ -2,7 +2,9 @@ // SPDX-License-Identifier: LGPL-3.0-only using System; +using System.Runtime.CompilerServices; using Nethermind.Core; +using Nethermind.Core.Collections; using Nethermind.Core.Specs; using G1 = Nethermind.Crypto.Bls.P1; @@ -14,12 +16,12 @@ namespace Nethermind.Evm.Precompiles.Bls; /// /// https://eips.ethereum.org/EIPS/eip-2537 /// -public class PairingPrecompile : IPrecompile +public class PairingCheckPrecompile : IPrecompile { private const int PairSize = 384; - public static readonly PairingPrecompile Instance = new(); + public static readonly PairingCheckPrecompile Instance = new(); - private PairingPrecompile() { } + private PairingCheckPrecompile() { } public static Address Address { get; } = Address.FromNumber(0x11); @@ -27,6 +29,7 @@ private PairingPrecompile() { } public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 43000L * (inputData.Length / PairSize); + [SkipLocalsInit] public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) { Metrics.BlsPairingCheckPrecompile++; @@ -39,15 +42,18 @@ private PairingPrecompile() { } G1 x = new(stackalloc long[G1.Sz]); G2 y = new(stackalloc long[G2.Sz]); - var acc = GT.One(); + using ArrayPoolList buf = new(GT.Sz * 2, GT.Sz * 2); + var acc = GT.One(buf.AsSpan()); + GT p = new(buf.AsSpan()[GT.Sz..]); + for (int i = 0; i < inputData.Length / PairSize; i++) { int offset = i * PairSize; if (!x.TryDecodeRaw(inputData[offset..(offset + BlsConst.LenG1)].Span) || - !x.InGroup() || + !(BlsConst.DisableSubgroupChecks || x.InGroup()) || !y.TryDecodeRaw(inputData[(offset + BlsConst.LenG1)..(offset + PairSize)].Span) || - !y.InGroup()) + !(BlsConst.DisableSubgroupChecks || y.InGroup())) { return IPrecompile.Failure; } @@ -58,7 +64,8 @@ private PairingPrecompile() { } continue; } - acc.Mul(new GT(y, x)); + p.MillerLoop(y, x); + acc.Mul(p); } bool verified = acc.FinalExp().IsOne(); diff --git a/src/Nethermind/Nethermind.Evm/Tracing/GethStyle/Custom/Native/Call/NativeCallTracerCallFrameConverter.cs b/src/Nethermind/Nethermind.Evm/Tracing/GethStyle/Custom/Native/Call/NativeCallTracerCallFrameConverter.cs index 37f181cee8e..bc89734d8c5 100644 --- a/src/Nethermind/Nethermind.Evm/Tracing/GethStyle/Custom/Native/Call/NativeCallTracerCallFrameConverter.cs +++ b/src/Nethermind/Nethermind.Evm/Tracing/GethStyle/Custom/Native/Call/NativeCallTracerCallFrameConverter.cs @@ -49,13 +49,13 @@ public override void Write(Utf8JsonWriter writer, NativeCallTracerCallFrame valu } else { - JsonSerializer.Serialize(writer, value.Input.AsMemory(), options); + JsonSerializer.Serialize(writer, value.Input.AsReadOnlyMemory(), options); } if (value.Output?.Count > 0) { writer.WritePropertyName("output"u8); - JsonSerializer.Serialize(writer, value.Output.AsMemory(), options); + JsonSerializer.Serialize(writer, value.Output.AsReadOnlyMemory(), options); } if (value.Error is not null) diff --git a/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG1AddBenchmark.cs b/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG1AddBenchmark.cs new file mode 100644 index 00000000000..26733025c3d --- /dev/null +++ b/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG1AddBenchmark.cs @@ -0,0 +1,18 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using System.Collections.Generic; +using Nethermind.Evm.Precompiles; +using Nethermind.Evm.Precompiles.Bls; + +namespace Nethermind.Precompiles.Benchmark; + +public class BlsG1AddBenchmark : PrecompileBenchmarkBase +{ + protected override IEnumerable Precompiles => new[] + { + G1AddPrecompile.Instance + }; + + protected override string InputsDirectory => "blsg1add"; +} diff --git a/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG1MSMBenchmark.cs b/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG1MSMBenchmark.cs new file mode 100644 index 00000000000..ebd52dddb05 --- /dev/null +++ b/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG1MSMBenchmark.cs @@ -0,0 +1,18 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using System.Collections.Generic; +using Nethermind.Evm.Precompiles; +using Nethermind.Evm.Precompiles.Bls; + +namespace Nethermind.Precompiles.Benchmark; + +public class BlsG1MSMBenchmark : PrecompileBenchmarkBase +{ + protected override IEnumerable Precompiles => new[] + { + G1MSMPrecompile.Instance + }; + + protected override string InputsDirectory => "blsg1msm"; +} diff --git a/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG1MulBenchmark.cs b/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG1MulBenchmark.cs new file mode 100644 index 00000000000..7d1adc95338 --- /dev/null +++ b/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG1MulBenchmark.cs @@ -0,0 +1,18 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using System.Collections.Generic; +using Nethermind.Evm.Precompiles; +using Nethermind.Evm.Precompiles.Bls; + +namespace Nethermind.Precompiles.Benchmark; + +public class BlsG1MulBenchmark : PrecompileBenchmarkBase +{ + protected override IEnumerable Precompiles => new[] + { + G1MulPrecompile.Instance + }; + + protected override string InputsDirectory => "blsg1mul"; +} diff --git a/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG2AddBenchmark.cs b/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG2AddBenchmark.cs new file mode 100644 index 00000000000..d89edf3e771 --- /dev/null +++ b/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG2AddBenchmark.cs @@ -0,0 +1,18 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using System.Collections.Generic; +using Nethermind.Evm.Precompiles; +using Nethermind.Evm.Precompiles.Bls; + +namespace Nethermind.Precompiles.Benchmark; + +public class BlsG2AddBenchmark : PrecompileBenchmarkBase +{ + protected override IEnumerable Precompiles => new[] + { + G2AddPrecompile.Instance + }; + + protected override string InputsDirectory => "blsg2add"; +} diff --git a/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG2MSMBenchmark.cs b/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG2MSMBenchmark.cs new file mode 100644 index 00000000000..59efd92b36f --- /dev/null +++ b/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG2MSMBenchmark.cs @@ -0,0 +1,18 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using System.Collections.Generic; +using Nethermind.Evm.Precompiles; +using Nethermind.Evm.Precompiles.Bls; + +namespace Nethermind.Precompiles.Benchmark; + +public class BlsG2MSMBenchmark : PrecompileBenchmarkBase +{ + protected override IEnumerable Precompiles => new[] + { + G2MSMPrecompile.Instance + }; + + protected override string InputsDirectory => "blsg2msm"; +} diff --git a/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG2MulBenchmark.cs b/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG2MulBenchmark.cs new file mode 100644 index 00000000000..6df853a9778 --- /dev/null +++ b/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsG2MulBenchmark.cs @@ -0,0 +1,18 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using System.Collections.Generic; +using Nethermind.Evm.Precompiles; +using Nethermind.Evm.Precompiles.Bls; + +namespace Nethermind.Precompiles.Benchmark; + +public class BlsG2MulBenchmark : PrecompileBenchmarkBase +{ + protected override IEnumerable Precompiles => new[] + { + G2MulPrecompile.Instance + }; + + protected override string InputsDirectory => "blsg2mul"; +} diff --git a/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsMapFp2ToG2Benchmark.cs b/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsMapFp2ToG2Benchmark.cs new file mode 100644 index 00000000000..ff903b6e1e7 --- /dev/null +++ b/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsMapFp2ToG2Benchmark.cs @@ -0,0 +1,18 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using System.Collections.Generic; +using Nethermind.Evm.Precompiles; +using Nethermind.Evm.Precompiles.Bls; + +namespace Nethermind.Precompiles.Benchmark; + +public class BlsMapFp2ToG2Benchmark : PrecompileBenchmarkBase +{ + protected override IEnumerable Precompiles => new[] + { + MapFp2ToG2Precompile.Instance + }; + + protected override string InputsDirectory => "blsmapfp2tog2"; +} diff --git a/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsMapFpToG1Benchmark.cs b/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsMapFpToG1Benchmark.cs new file mode 100644 index 00000000000..0f2fc9bad0b --- /dev/null +++ b/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsMapFpToG1Benchmark.cs @@ -0,0 +1,18 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using System.Collections.Generic; +using Nethermind.Evm.Precompiles; +using Nethermind.Evm.Precompiles.Bls; + +namespace Nethermind.Precompiles.Benchmark; + +public class BlsMapFpToG1Benchmark : PrecompileBenchmarkBase +{ + protected override IEnumerable Precompiles => new[] + { + MapFpToG1Precompile.Instance + }; + + protected override string InputsDirectory => "blsmapfptog1"; +} diff --git a/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsPairingCheckBenchmark.cs b/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsPairingCheckBenchmark.cs new file mode 100644 index 00000000000..23c7933af1f --- /dev/null +++ b/src/Nethermind/Nethermind.Precompiles.Benchmark/BlsPairingCheckBenchmark.cs @@ -0,0 +1,18 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using System.Collections.Generic; +using Nethermind.Evm.Precompiles; +using Nethermind.Evm.Precompiles.Bls; + +namespace Nethermind.Precompiles.Benchmark; + +public class BlsPairingCheckBenchmark : PrecompileBenchmarkBase +{ + protected override IEnumerable Precompiles => new[] + { + PairingCheckPrecompile.Instance + }; + + protected override string InputsDirectory => "blspairingcheck"; +} diff --git a/src/Nethermind/Nethermind.Precompiles.Benchmark/Nethermind.Precompiles.Benchmark.csproj b/src/Nethermind/Nethermind.Precompiles.Benchmark/Nethermind.Precompiles.Benchmark.csproj index c7d79384acf..1fa7275f368 100644 --- a/src/Nethermind/Nethermind.Precompiles.Benchmark/Nethermind.Precompiles.Benchmark.csproj +++ b/src/Nethermind/Nethermind.Precompiles.Benchmark/Nethermind.Precompiles.Benchmark.csproj @@ -18,10 +18,6 @@ %(RecursiveDir)%(FileName)%(Extension) PreserveNewest - - - PreserveNewest - diff --git a/src/Nethermind/Nethermind.Precompiles.Benchmark/modexp/current/file.json b/src/Nethermind/Nethermind.Precompiles.Benchmark/modexp/current/file.json deleted file mode 100644 index a7fc3a30973..00000000000 --- a/src/Nethermind/Nethermind.Precompiles.Benchmark/modexp/current/file.json +++ /dev/null @@ -1,142 +0,0 @@ -[ - { - "Input": "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002003fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2efffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f", - "Expected": "0000000000000000000000000000000000000000000000000000000000000001", - "Name": "eip_example1", - "Gas": 13056, - "NoBenchmark": false - }, - { - "Input": "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2efffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f", - "Expected": "0000000000000000000000000000000000000000000000000000000000000000", - "Name": "eip_example2", - "Gas": 13056, - "NoBenchmark": false - }, - { - "Input": "000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040e09ad9675465c53a109fac66a445c91b292d2bb2c5268addb30cd82f80fcb0033ff97c80a5fc6f39193ae969c6ede6710a6b7ac27078a06d90ef1c72e5c85fb502fc9e1f6beb81516545975218075ec2af118cd8798df6e08a147c60fd6095ac2bb02c2908cf4dd7c81f11c289e4bce98f3553768f392a80ce22bf5c4f4a248c6b", - "Expected": "60008f1614cc01dcfb6bfb09c625cf90b47d4468db81b5f8b7a39d42f332eab9b2da8f2d95311648a8f243f4bb13cfb3d8f7f2a3c014122ebb3ed41b02783adc", - "Name": "nagydani-1-square", - "Gas": 204, - "NoBenchmark": false - }, - { - "Input": "000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040e09ad9675465c53a109fac66a445c91b292d2bb2c5268addb30cd82f80fcb0033ff97c80a5fc6f39193ae969c6ede6710a6b7ac27078a06d90ef1c72e5c85fb503fc9e1f6beb81516545975218075ec2af118cd8798df6e08a147c60fd6095ac2bb02c2908cf4dd7c81f11c289e4bce98f3553768f392a80ce22bf5c4f4a248c6b", - "Expected": "4834a46ba565db27903b1c720c9d593e84e4cbd6ad2e64b31885d944f68cd801f92225a8961c952ddf2797fa4701b330c85c4b363798100b921a1a22a46a7fec", - "Name": "nagydani-1-qube", - "Gas": 204, - "NoBenchmark": false - }, - { - "Input": "000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000040e09ad9675465c53a109fac66a445c91b292d2bb2c5268addb30cd82f80fcb0033ff97c80a5fc6f39193ae969c6ede6710a6b7ac27078a06d90ef1c72e5c85fb5010001fc9e1f6beb81516545975218075ec2af118cd8798df6e08a147c60fd6095ac2bb02c2908cf4dd7c81f11c289e4bce98f3553768f392a80ce22bf5c4f4a248c6b", - "Expected": "c36d804180c35d4426b57b50c5bfcca5c01856d104564cd513b461d3c8b8409128a5573e416d0ebe38f5f736766d9dc27143e4da981dfa4d67f7dc474cbee6d2", - "Name": "nagydani-1-pow0x10001", - "Gas": 3276, - "NoBenchmark": false - }, - { - "Input": "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000080cad7d991a00047dd54d3399b6b0b937c718abddef7917c75b6681f40cc15e2be0003657d8d4c34167b2f0bbbca0ccaa407c2a6a07d50f1517a8f22979ce12a81dcaf707cc0cebfc0ce2ee84ee7f77c38b9281b9822a8d3de62784c089c9b18dcb9a2a5eecbede90ea788a862a9ddd9d609c2c52972d63e289e28f6a590ffbf5102e6d893b80aeed5e6e9ce9afa8a5d5675c93a32ac05554cb20e9951b2c140e3ef4e433068cf0fb73bc9f33af1853f64aa27a0028cbf570d7ac9048eae5dc7b28c87c31e5810f1e7fa2cda6adf9f1076dbc1ec1238560071e7efc4e9565c49be9e7656951985860a558a754594115830bcdb421f741408346dd5997bb01c287087", - "Expected": "981dd99c3b113fae3e3eaa9435c0dc96779a23c12a53d1084b4f67b0b053a27560f627b873e3f16ad78f28c94f14b6392def26e4d8896c5e3c984e50fa0b3aa44f1da78b913187c6128baa9340b1e9c9a0fd02cb78885e72576da4a8f7e5a113e173a7a2889fde9d407bd9f06eb05bc8fc7b4229377a32941a02bf4edcc06d70", - "Name": "nagydani-2-square", - "Gas": 665, - "NoBenchmark": false - }, - { - "Input": "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000080cad7d991a00047dd54d3399b6b0b937c718abddef7917c75b6681f40cc15e2be0003657d8d4c34167b2f0bbbca0ccaa407c2a6a07d50f1517a8f22979ce12a81dcaf707cc0cebfc0ce2ee84ee7f77c38b9281b9822a8d3de62784c089c9b18dcb9a2a5eecbede90ea788a862a9ddd9d609c2c52972d63e289e28f6a590ffbf5103e6d893b80aeed5e6e9ce9afa8a5d5675c93a32ac05554cb20e9951b2c140e3ef4e433068cf0fb73bc9f33af1853f64aa27a0028cbf570d7ac9048eae5dc7b28c87c31e5810f1e7fa2cda6adf9f1076dbc1ec1238560071e7efc4e9565c49be9e7656951985860a558a754594115830bcdb421f741408346dd5997bb01c287087", - "Expected": "d89ceb68c32da4f6364978d62aaa40d7b09b59ec61eb3c0159c87ec3a91037f7dc6967594e530a69d049b64adfa39c8fa208ea970cfe4b7bcd359d345744405afe1cbf761647e32b3184c7fbe87cee8c6c7ff3b378faba6c68b83b6889cb40f1603ee68c56b4c03d48c595c826c041112dc941878f8c5be828154afd4a16311f", - "Name": "nagydani-2-qube", - "Gas": 665, - "NoBenchmark": false - }, - { - "Input": "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000080cad7d991a00047dd54d3399b6b0b937c718abddef7917c75b6681f40cc15e2be0003657d8d4c34167b2f0bbbca0ccaa407c2a6a07d50f1517a8f22979ce12a81dcaf707cc0cebfc0ce2ee84ee7f77c38b9281b9822a8d3de62784c089c9b18dcb9a2a5eecbede90ea788a862a9ddd9d609c2c52972d63e289e28f6a590ffbf51010001e6d893b80aeed5e6e9ce9afa8a5d5675c93a32ac05554cb20e9951b2c140e3ef4e433068cf0fb73bc9f33af1853f64aa27a0028cbf570d7ac9048eae5dc7b28c87c31e5810f1e7fa2cda6adf9f1076dbc1ec1238560071e7efc4e9565c49be9e7656951985860a558a754594115830bcdb421f741408346dd5997bb01c287087", - "Expected": "ad85e8ef13fd1dd46eae44af8b91ad1ccae5b7a1c92944f92a19f21b0b658139e0cabe9c1f679507c2de354bf2c91ebd965d1e633978a830d517d2f6f8dd5fd58065d58559de7e2334a878f8ec6992d9b9e77430d4764e863d77c0f87beede8f2f7f2ab2e7222f85cc9d98b8467f4bb72e87ef2882423ebdb6daf02dddac6db2", - "Name": "nagydani-2-pow0x10001", - "Gas": 10649, - "NoBenchmark": false - }, - { - "Input": "000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000100c9130579f243e12451760976261416413742bd7c91d39ae087f46794062b8c239f2a74abf3918605a0e046a7890e049475ba7fbb78f5de6490bd22a710cc04d30088179a919d86c2da62cf37f59d8f258d2310d94c24891be2d7eeafaa32a8cb4b0cfe5f475ed778f45907dc8916a73f03635f233f7a77a00a3ec9ca6761a5bbd558a2318ecd0caa1c5016691523e7e1fa267dd35e70c66e84380bdcf7c0582f540174e572c41f81e93da0b757dff0b0fe23eb03aa19af0bdec3afb474216febaacb8d0381e631802683182b0fe72c28392539850650b70509f54980241dc175191a35d967288b532a7a8223ce2440d010615f70df269501944d4ec16fe4a3cb02d7a85909174757835187cb52e71934e6c07ef43b4c46fc30bbcd0bc72913068267c54a4aabebb493922492820babdeb7dc9b1558fcf7bd82c37c82d3147e455b623ab0efa752fe0b3a67ca6e4d126639e645a0bf417568adbb2a6a4eef62fa1fa29b2a5a43bebea1f82193a7dd98eb483d09bb595af1fa9c97c7f41f5649d976aee3e5e59e2329b43b13bea228d4a93f16ba139ccb511de521ffe747aa2eca664f7c9e33da59075cc335afcd2bf3ae09765f01ab5a7c3e3938ec168b74724b5074247d200d9970382f683d6059b94dbc336603d1dfee714e4b447ac2fa1d99ecb4961da2854e03795ed758220312d101e1e3d87d5313a6d052aebde75110363d", - "Expected": "affc7507ea6d84751ec6b3f0d7b99dbcc263f33330e450d1b3ff0bc3d0874320bf4edd57debd587306988157958cb3cfd369cc0c9c198706f635c9e0f15d047df5cb44d03e2727f26b083c4ad8485080e1293f171c1ed52aef5993a5815c35108e848c951cf1e334490b4a539a139e57b68f44fee583306f5b85ffa57206b3ee5660458858534e5386b9584af3c7f67806e84c189d695e5eb96e1272d06ec2df5dc5fabc6e94b793718c60c36be0a4d031fc84cd658aa72294b2e16fc240aef70cb9e591248e38bd49c5a554d1afa01f38dab72733092f7555334bbef6c8c430119840492380aa95fa025dcf699f0a39669d812b0c6946b6091e6e235337b6f8", - "Name": "nagydani-3-square", - "Gas": 1894, - "NoBenchmark": false - }, - { - "Input": "000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000100c9130579f243e12451760976261416413742bd7c91d39ae087f46794062b8c239f2a74abf3918605a0e046a7890e049475ba7fbb78f5de6490bd22a710cc04d30088179a919d86c2da62cf37f59d8f258d2310d94c24891be2d7eeafaa32a8cb4b0cfe5f475ed778f45907dc8916a73f03635f233f7a77a00a3ec9ca6761a5bbd558a2318ecd0caa1c5016691523e7e1fa267dd35e70c66e84380bdcf7c0582f540174e572c41f81e93da0b757dff0b0fe23eb03aa19af0bdec3afb474216febaacb8d0381e631802683182b0fe72c28392539850650b70509f54980241dc175191a35d967288b532a7a8223ce2440d010615f70df269501944d4ec16fe4a3cb03d7a85909174757835187cb52e71934e6c07ef43b4c46fc30bbcd0bc72913068267c54a4aabebb493922492820babdeb7dc9b1558fcf7bd82c37c82d3147e455b623ab0efa752fe0b3a67ca6e4d126639e645a0bf417568adbb2a6a4eef62fa1fa29b2a5a43bebea1f82193a7dd98eb483d09bb595af1fa9c97c7f41f5649d976aee3e5e59e2329b43b13bea228d4a93f16ba139ccb511de521ffe747aa2eca664f7c9e33da59075cc335afcd2bf3ae09765f01ab5a7c3e3938ec168b74724b5074247d200d9970382f683d6059b94dbc336603d1dfee714e4b447ac2fa1d99ecb4961da2854e03795ed758220312d101e1e3d87d5313a6d052aebde75110363d", - "Expected": "1b280ecd6a6bf906b806d527c2a831e23b238f89da48449003a88ac3ac7150d6a5e9e6b3be4054c7da11dd1e470ec29a606f5115801b5bf53bc1900271d7c3ff3cd5ed790d1c219a9800437a689f2388ba1a11d68f6a8e5b74e9a3b1fac6ee85fc6afbac599f93c391f5dc82a759e3c6c0ab45ce3f5d25d9b0c1bf94cf701ea6466fc9a478dacc5754e593172b5111eeba88557048bceae401337cd4c1182ad9f700852bc8c99933a193f0b94cf1aedbefc48be3bc93ef5cb276d7c2d5462ac8bb0c8fe8923a1db2afe1c6b90d59c534994a6a633f0ead1d638fdc293486bb634ff2c8ec9e7297c04241a61c37e3ae95b11d53343d4ba2b4cc33d2cfa7eb705e", - "Name": "nagydani-3-qube", - "Gas": 1894, - "NoBenchmark": false - }, - { - "Input": "000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000100c9130579f243e12451760976261416413742bd7c91d39ae087f46794062b8c239f2a74abf3918605a0e046a7890e049475ba7fbb78f5de6490bd22a710cc04d30088179a919d86c2da62cf37f59d8f258d2310d94c24891be2d7eeafaa32a8cb4b0cfe5f475ed778f45907dc8916a73f03635f233f7a77a00a3ec9ca6761a5bbd558a2318ecd0caa1c5016691523e7e1fa267dd35e70c66e84380bdcf7c0582f540174e572c41f81e93da0b757dff0b0fe23eb03aa19af0bdec3afb474216febaacb8d0381e631802683182b0fe72c28392539850650b70509f54980241dc175191a35d967288b532a7a8223ce2440d010615f70df269501944d4ec16fe4a3cb010001d7a85909174757835187cb52e71934e6c07ef43b4c46fc30bbcd0bc72913068267c54a4aabebb493922492820babdeb7dc9b1558fcf7bd82c37c82d3147e455b623ab0efa752fe0b3a67ca6e4d126639e645a0bf417568adbb2a6a4eef62fa1fa29b2a5a43bebea1f82193a7dd98eb483d09bb595af1fa9c97c7f41f5649d976aee3e5e59e2329b43b13bea228d4a93f16ba139ccb511de521ffe747aa2eca664f7c9e33da59075cc335afcd2bf3ae09765f01ab5a7c3e3938ec168b74724b5074247d200d9970382f683d6059b94dbc336603d1dfee714e4b447ac2fa1d99ecb4961da2854e03795ed758220312d101e1e3d87d5313a6d052aebde75110363d", - "Expected": "37843d7c67920b5f177372fa56e2a09117df585f81df8b300fba245b1175f488c99476019857198ed459ed8d9799c377330e49f4180c4bf8e8f66240c64f65ede93d601f957b95b83efdee1e1bfde74169ff77002eaf078c71815a9220c80b2e3b3ff22c2f358111d816ebf83c2999026b6de50bfc711ff68705d2f40b753424aefc9f70f08d908b5a20276ad613b4ab4309a3ea72f0c17ea9df6b3367d44fb3acab11c333909e02e81ea2ed404a712d3ea96bba87461720e2d98723e7acd0520ac1a5212dbedcd8dc0c1abf61d4719e319ff4758a774790b8d463cdfe131d1b2dcfee52d002694e98e720cb6ae7ccea353bc503269ba35f0f63bf8d7b672a76", - "Name": "nagydani-3-pow0x10001", - "Gas": 30310, - "NoBenchmark": false - }, - { - "Input": "000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000200db34d0e438249c0ed685c949cc28776a05094e1c48691dc3f2dca5fc3356d2a0663bd376e4712839917eb9a19c670407e2c377a2de385a3ff3b52104f7f1f4e0c7bf7717fb913896693dc5edbb65b760ef1b00e42e9d8f9af17352385e1cd742c9b006c0f669995cb0bb21d28c0aced2892267637b6470d8cee0ab27fc5d42658f6e88240c31d6774aa60a7ebd25cd48b56d0da11209f1928e61005c6eb709f3e8e0aaf8d9b10f7d7e296d772264dc76897ccdddadc91efa91c1903b7232a9e4c3b941917b99a3bc0c26497dedc897c25750af60237aa67934a26a2bc491db3dcc677491944bc1f51d3e5d76b8d846a62db03dedd61ff508f91a56d71028125035c3a44cbb041497c83bf3e4ae2a9613a401cc721c547a2afa3b16a2969933d3626ed6d8a7428648f74122fd3f2a02a20758f7f693892c8fd798b39abac01d18506c45e71432639e9f9505719ee822f62ccbf47f6850f096ff77b5afaf4be7d772025791717dbe5abf9b3f40cff7d7aab6f67e38f62faf510747276e20a42127e7500c444f9ed92baf65ade9e836845e39c4316d9dce5f8e2c8083e2c0acbb95296e05e51aab13b6b8f53f06c9c4276e12b0671133218cc3ea907da3bd9a367096d9202128d14846cc2e20d56fc8473ecb07cecbfb8086919f3971926e7045b853d85a69d026195c70f9f7a823536e2a8f4b3e12e94d9b53a934353451094b8102df3143a0057457d75e8c708b6337a6f5a4fd1a06727acf9fb93e2993c62f3378b37d56c85e7b1e00f0145ebf8e4095bd723166293c60b6ac1252291ef65823c9e040ddad14969b3b340a4ef714db093a587c37766d68b8d6b5016e741587e7e6bf7e763b44f0247e64bae30f994d248bfd20541a333e5b225ef6a61199e301738b1e688f70ec1d7fb892c183c95dc543c3e12adf8a5e8b9ca9d04f9445cced3ab256f29e998e69efaa633a7b60e1db5a867924ccab0a171d9d6e1098dfa15acde9553de599eaa56490c8f411e4985111f3d40bddfc5e301edb01547b01a886550a61158f7e2033c59707789bf7c854181d0c2e2a42a93cf09209747d7082e147eb8544de25c3eb14f2e35559ea0c0f5877f2f3fc92132c0ae9da4e45b2f6c866a224ea6d1f28c05320e287750fbc647368d41116e528014cc1852e5531d53e4af938374daba6cee4baa821ed07117253bb3601ddd00d59a3d7fb2ef1f5a2fbba7c429f0cf9a5b3462410fd833a69118f8be9c559b1000cc608fd877fb43f8e65c2d1302622b944462579056874b387208d90623fcdaf93920ca7a9e4ba64ea208758222ad868501cc2c345e2d3a5ea2a17e5069248138c8a79c0251185d29ee73e5afab5354769142d2bf0cb6712727aa6bf84a6245fcdae66e4938d84d1b9dd09a884818622080ff5f98942fb20acd7e0c916c2d5ea7ce6f7e173315384518f", - "Expected": "8a5aea5f50dcc03dc7a7a272b5aeebc040554dbc1ffe36753c4fc75f7ed5f6c2cc0de3a922bf96c78bf0643a73025ad21f45a4a5cadd717612c511ab2bff1190fe5f1ae05ba9f8fe3624de1de2a817da6072ddcdb933b50216811dbe6a9ca79d3a3c6b3a476b079fd0d05f04fb154e2dd3e5cb83b148a006f2bcbf0042efb2ae7b916ea81b27aac25c3bf9a8b6d35440062ad8eae34a83f3ffa2cc7b40346b62174a4422584f72f95316f6b2bee9ff232ba9739301c97c99a9ded26c45d72676eb856ad6ecc81d36a6de36d7f9dafafee11baa43a4b0d5e4ecffa7b9b7dcefd58c397dd373e6db4acd2b2c02717712e6289bed7c813b670c4a0c6735aa7f3b0f1ce556eae9fcc94b501b2c8781ba50a8c6220e8246371c3c7359fe4ef9da786ca7d98256754ca4e496be0a9174bedbecb384bdf470779186d6a833f068d2838a88d90ef3ad48ff963b67c39cc5a3ee123baf7bf3125f64e77af7f30e105d72c4b9b5b237ed251e4c122c6d8c1405e736299c3afd6db16a28c6a9cfa68241e53de4cd388271fe534a6a9b0dbea6171d170db1b89858468885d08fecbd54c8e471c3e25d48e97ba450b96d0d87e00ac732aaa0d3ce4309c1064bd8a4c0808a97e0143e43a24cfa847635125cd41c13e0574487963e9d725c01375db99c31da67b4cf65eff555f0c0ac416c727ff8d438ad7c42030551d68c2e7adda0abb1ca7c10", - "Name": "nagydani-4-square", - "Gas": 5580, - "NoBenchmark": false - }, - { - "Input": "000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000200db34d0e438249c0ed685c949cc28776a05094e1c48691dc3f2dca5fc3356d2a0663bd376e4712839917eb9a19c670407e2c377a2de385a3ff3b52104f7f1f4e0c7bf7717fb913896693dc5edbb65b760ef1b00e42e9d8f9af17352385e1cd742c9b006c0f669995cb0bb21d28c0aced2892267637b6470d8cee0ab27fc5d42658f6e88240c31d6774aa60a7ebd25cd48b56d0da11209f1928e61005c6eb709f3e8e0aaf8d9b10f7d7e296d772264dc76897ccdddadc91efa91c1903b7232a9e4c3b941917b99a3bc0c26497dedc897c25750af60237aa67934a26a2bc491db3dcc677491944bc1f51d3e5d76b8d846a62db03dedd61ff508f91a56d71028125035c3a44cbb041497c83bf3e4ae2a9613a401cc721c547a2afa3b16a2969933d3626ed6d8a7428648f74122fd3f2a02a20758f7f693892c8fd798b39abac01d18506c45e71432639e9f9505719ee822f62ccbf47f6850f096ff77b5afaf4be7d772025791717dbe5abf9b3f40cff7d7aab6f67e38f62faf510747276e20a42127e7500c444f9ed92baf65ade9e836845e39c4316d9dce5f8e2c8083e2c0acbb95296e05e51aab13b6b8f53f06c9c4276e12b0671133218cc3ea907da3bd9a367096d9202128d14846cc2e20d56fc8473ecb07cecbfb8086919f3971926e7045b853d85a69d026195c70f9f7a823536e2a8f4b3e12e94d9b53a934353451094b8103df3143a0057457d75e8c708b6337a6f5a4fd1a06727acf9fb93e2993c62f3378b37d56c85e7b1e00f0145ebf8e4095bd723166293c60b6ac1252291ef65823c9e040ddad14969b3b340a4ef714db093a587c37766d68b8d6b5016e741587e7e6bf7e763b44f0247e64bae30f994d248bfd20541a333e5b225ef6a61199e301738b1e688f70ec1d7fb892c183c95dc543c3e12adf8a5e8b9ca9d04f9445cced3ab256f29e998e69efaa633a7b60e1db5a867924ccab0a171d9d6e1098dfa15acde9553de599eaa56490c8f411e4985111f3d40bddfc5e301edb01547b01a886550a61158f7e2033c59707789bf7c854181d0c2e2a42a93cf09209747d7082e147eb8544de25c3eb14f2e35559ea0c0f5877f2f3fc92132c0ae9da4e45b2f6c866a224ea6d1f28c05320e287750fbc647368d41116e528014cc1852e5531d53e4af938374daba6cee4baa821ed07117253bb3601ddd00d59a3d7fb2ef1f5a2fbba7c429f0cf9a5b3462410fd833a69118f8be9c559b1000cc608fd877fb43f8e65c2d1302622b944462579056874b387208d90623fcdaf93920ca7a9e4ba64ea208758222ad868501cc2c345e2d3a5ea2a17e5069248138c8a79c0251185d29ee73e5afab5354769142d2bf0cb6712727aa6bf84a6245fcdae66e4938d84d1b9dd09a884818622080ff5f98942fb20acd7e0c916c2d5ea7ce6f7e173315384518f", - "Expected": "5a2664252aba2d6e19d9600da582cdd1f09d7a890ac48e6b8da15ae7c6ff1856fc67a841ac2314d283ffa3ca81a0ecf7c27d89ef91a5a893297928f5da0245c99645676b481b7e20a566ee6a4f2481942bee191deec5544600bb2441fd0fb19e2ee7d801ad8911c6b7750affec367a4b29a22942c0f5f4744a4e77a8b654da2a82571037099e9c6d930794efe5cdca73c7b6c0844e386bdca8ea01b3d7807146bb81365e2cdc6475f8c23e0ff84463126189dc9789f72bbce2e3d2d114d728a272f1345122de23df54c922ec7a16e5c2a8f84da8871482bd258c20a7c09bbcd64c7a96a51029bbfe848736a6ba7bf9d931a9b7de0bcaf3635034d4958b20ae9ab3a95a147b0421dd5f7ebff46c971010ebfc4adbbe0ad94d5498c853e7142c450d8c71de4b2f84edbf8acd2e16d00c8115b150b1c30e553dbb82635e781379fe2a56360420ff7e9f70cc64c00aba7e26ed13c7c19622865ae07248daced36416080f35f8cc157a857ed70ea4f347f17d1bee80fa038abd6e39b1ba06b97264388b21364f7c56e192d4b62d9b161405f32ab1e2594e86243e56fcf2cb30d21adef15b9940f91af681da24328c883d892670c6aa47940867a81830a82b82716895db810df1b834640abefb7db2092dd92912cb9a735175bc447be40a503cf22dfe565b4ed7a3293ca0dfd63a507430b323ee248ec82e843b673c97ad730728cebc", - "Name": "nagydani-4-qube", - "Gas": 5580, - "NoBenchmark": false - }, - { - "Input": "000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000200db34d0e438249c0ed685c949cc28776a05094e1c48691dc3f2dca5fc3356d2a0663bd376e4712839917eb9a19c670407e2c377a2de385a3ff3b52104f7f1f4e0c7bf7717fb913896693dc5edbb65b760ef1b00e42e9d8f9af17352385e1cd742c9b006c0f669995cb0bb21d28c0aced2892267637b6470d8cee0ab27fc5d42658f6e88240c31d6774aa60a7ebd25cd48b56d0da11209f1928e61005c6eb709f3e8e0aaf8d9b10f7d7e296d772264dc76897ccdddadc91efa91c1903b7232a9e4c3b941917b99a3bc0c26497dedc897c25750af60237aa67934a26a2bc491db3dcc677491944bc1f51d3e5d76b8d846a62db03dedd61ff508f91a56d71028125035c3a44cbb041497c83bf3e4ae2a9613a401cc721c547a2afa3b16a2969933d3626ed6d8a7428648f74122fd3f2a02a20758f7f693892c8fd798b39abac01d18506c45e71432639e9f9505719ee822f62ccbf47f6850f096ff77b5afaf4be7d772025791717dbe5abf9b3f40cff7d7aab6f67e38f62faf510747276e20a42127e7500c444f9ed92baf65ade9e836845e39c4316d9dce5f8e2c8083e2c0acbb95296e05e51aab13b6b8f53f06c9c4276e12b0671133218cc3ea907da3bd9a367096d9202128d14846cc2e20d56fc8473ecb07cecbfb8086919f3971926e7045b853d85a69d026195c70f9f7a823536e2a8f4b3e12e94d9b53a934353451094b81010001df3143a0057457d75e8c708b6337a6f5a4fd1a06727acf9fb93e2993c62f3378b37d56c85e7b1e00f0145ebf8e4095bd723166293c60b6ac1252291ef65823c9e040ddad14969b3b340a4ef714db093a587c37766d68b8d6b5016e741587e7e6bf7e763b44f0247e64bae30f994d248bfd20541a333e5b225ef6a61199e301738b1e688f70ec1d7fb892c183c95dc543c3e12adf8a5e8b9ca9d04f9445cced3ab256f29e998e69efaa633a7b60e1db5a867924ccab0a171d9d6e1098dfa15acde9553de599eaa56490c8f411e4985111f3d40bddfc5e301edb01547b01a886550a61158f7e2033c59707789bf7c854181d0c2e2a42a93cf09209747d7082e147eb8544de25c3eb14f2e35559ea0c0f5877f2f3fc92132c0ae9da4e45b2f6c866a224ea6d1f28c05320e287750fbc647368d41116e528014cc1852e5531d53e4af938374daba6cee4baa821ed07117253bb3601ddd00d59a3d7fb2ef1f5a2fbba7c429f0cf9a5b3462410fd833a69118f8be9c559b1000cc608fd877fb43f8e65c2d1302622b944462579056874b387208d90623fcdaf93920ca7a9e4ba64ea208758222ad868501cc2c345e2d3a5ea2a17e5069248138c8a79c0251185d29ee73e5afab5354769142d2bf0cb6712727aa6bf84a6245fcdae66e4938d84d1b9dd09a884818622080ff5f98942fb20acd7e0c916c2d5ea7ce6f7e173315384518f", - "Expected": "bed8b970c4a34849fc6926b08e40e20b21c15ed68d18f228904878d4370b56322d0da5789da0318768a374758e6375bfe4641fca5285ec7171828922160f48f5ca7efbfee4d5148612c38ad683ae4e3c3a053d2b7c098cf2b34f2cb19146eadd53c86b2d7ccf3d83b2c370bfb840913ee3879b1057a6b4e07e110b6bcd5e958bc71a14798c91d518cc70abee264b0d25a4110962a764b364ac0b0dd1ee8abc8426d775ec0f22b7e47b32576afaf1b5a48f64573ed1c5c29f50ab412188d9685307323d990802b81dacc06c6e05a1e901830ba9fcc67688dc29c5e27bde0a6e845ca925f5454b6fb3747edfaa2a5820838fb759eadf57f7cb5cec57fc213ddd8a4298fa079c3c0f472b07fb15aa6a7f0a3780bd296ff6a62e58ef443870b02260bd4fd2bbc98255674b8e1f1f9f8d33c7170b0ebbea4523b695911abbf26e41885344823bd0587115fdd83b721a4e8457a31c9a84b3d3520a07e0e35df7f48e5a9d534d0ec7feef1ff74de6a11e7f93eab95175b6ce22c68d78a642ad642837897ec11349205d8593ac19300207572c38d29ca5dfa03bc14cdbc32153c80e5cc3e739403d34c75915e49beb43094cc6dcafb3665b305ddec9286934ae66ec6b777ca528728c851318eb0f207b39f1caaf96db6eeead6b55ed08f451939314577d42bcc9f97c0b52d0234f88fd07e4c1d7780fdebc025cfffcb572cb27a8c33963", - "Name": "nagydani-4-pow0x10001", - "Gas": 89292, - "NoBenchmark": false - }, - { - "Input": "000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000400c5a1611f8be90071a43db23cc2fe01871cc4c0e8ab5743f6378e4fef77f7f6db0095c0727e20225beb665645403453e325ad5f9aeb9ba99bf3c148f63f9c07cf4fe8847ad5242d6b7d4499f93bd47056ddab8f7dee878fc2314f344dbee2a7c41a5d3db91eff372c730c2fdd3a141a4b61999e36d549b9870cf2f4e632c4d5df5f024f81c028000073a0ed8847cfb0593d36a47142f578f05ccbe28c0c06aeb1b1da027794c48db880278f79ba78ae64eedfea3c07d10e0562668d839749dc95f40467d15cf65b9cfc52c7c4bcef1cda3596dd52631aac942f146c7cebd46065131699ce8385b0db1874336747ee020a5698a3d1a1082665721e769567f579830f9d259cec1a836845109c21cf6b25da572512bf3c42fd4b96e43895589042ab60dd41f497db96aec102087fe784165bb45f942859268fd2ff6c012d9d00c02ba83eace047cc5f7b2c392c2955c58a49f0338d6fc58749c9db2155522ac17914ec216ad87f12e0ee95574613942fa615898c4d9e8a3be68cd6afa4e7a003dedbdf8edfee31162b174f965b20ae752ad89c967b3068b6f722c16b354456ba8e280f987c08e0a52d40a2e8f3a59b94d590aeef01879eb7a90b3ee7d772c839c85519cbeaddc0c193ec4874a463b53fcaea3271d80ebfb39b33489365fc039ae549a17a9ff898eea2f4cb27b8dbee4c17b998438575b2b8d107e4a0d66ba7fca85b41a58a8d51f191a35c856dfbe8aef2b00048a694bbccff832d23c8ca7a7ff0b6c0b3011d00b97c86c0628444d267c951d9e4fb8f83e154b8f74fb51aa16535e498235c5597dac9606ed0be3173a3836baa4e7d756ffe1e2879b415d3846bccd538c05b847785699aefde3e305decb600cd8fb0e7d8de5efc26971a6ad4e6d7a2d91474f1023a0ac4b78dc937da0ce607a45974d2cac1c33a2631ff7fe6144a3b2e5cf98b531a9627dea92c1dc82204d09db0439b6a11dd64b484e1263aa45fd9539b6020b55e3baece3986a8bffc1003406348f5c61265099ed43a766ee4f93f5f9c5abbc32a0fd3ac2b35b87f9ec26037d88275bd7dd0a54474995ee34ed3727f3f97c48db544b1980193a4b76a8a3ddab3591ce527f16d91882e67f0103b5cda53f7da54d489fc4ac08b6ab358a5a04aa9daa16219d50bd672a7cb804ed769d218807544e5993f1c27427104b349906a0b654df0bf69328afd3013fbe430155339c39f236df5557bf92f1ded7ff609a8502f49064ec3d1dbfb6c15d3a4c11a4f8acd12278cbf68acd5709463d12e3338a6eddb8c112f199645e23154a8e60879d2a654e3ed9296aa28f134168619691cd2c6b9e2eba4438381676173fc63c2588a3c5910dc149cf3760f0aa9fa9c3f5faa9162b0bf1aac9dd32b706a60ef53cbdb394b6b40222b5bc80eea82ba8958386672564cae3794f977871ab62337cf02e30049201ec12937e7ce79d0f55d9c810e20acf52212aca1d3888949e0e4830aad88d804161230eb89d4d329cc83570fe257217d2119134048dd2ed167646975fc7d77136919a049ea74cf08ddd2b896890bb24a0ba18094a22baa351bf29ad96c66bbb1a598f2ca391749620e62d61c3561a7d3653ccc8892c7b99baaf76bf836e2991cb06d6bc0514568ff0d1ec8bb4b3d6984f5eaefb17d3ea2893722375d3ddb8e389a8eef7d7d198f8e687d6a513983df906099f9a2d23f4f9dec6f8ef2f11fc0a21fac45353b94e00486f5e17d386af42502d09db33cf0cf28310e049c07e88682aeeb00cb833c5174266e62407a57583f1f88b304b7c6e0c84bbe1c0fd423072d37a5bd0aacf764229e5c7cd02473460ba3645cd8e8ae144065bf02d0dd238593d8e230354f67e0b2f23012c23274f80e3ee31e35e2606a4a3f31d94ab755e6d163cff52cbb36b6d0cc67ffc512aeed1dce4d7a0d70ce82f2baba12e8d514dc92a056f994adfb17b5b9712bd5186f27a2fda1f7039c5df2c8587fdc62f5627580c13234b55be4df3056050e2d1ef3218f0dd66cb05265fe1acfb0989d8213f2c19d1735a7cf3fa65d88dad5af52dc2bba22b7abf46c3bc77b5091baab9e8f0ddc4d5e581037de91a9f8dcbc69309be29cc815cf19a20a7585b8b3073edf51fc9baeb3e509b97fa4ecfd621e0fd57bd61cac1b895c03248ff12bdbc57509250df3517e8a3fe1d776836b34ab352b973d932ef708b14f7418f9eceb1d87667e61e3e758649cb083f01b133d37ab2f5afa96d6c84bcacf4efc3851ad308c1e7d9113624fce29fab460ab9d2a48d92cdb281103a5250ad44cb2ff6e67ac670c02fdafb3e0f1353953d6d7d5646ca1568dea55275a050ec501b7c6250444f7219f1ba7521ba3b93d089727ca5f3bbe0d6c1300b423377004954c5628fdb65770b18ced5c9b23a4a5a6d6ef25fe01b4ce278de0bcc4ed86e28a0a68818ffa40970128cf2c38740e80037984428c1bd5113f40ff47512ee6f4e4d8f9b8e8e1b3040d2928d003bd1c1329dc885302fbce9fa81c23b4dc49c7c82d29b52957847898676c89aa5d32b5b0e1c0d5a2b79a19d67562f407f19425687971a957375879d90c5f57c857136c17106c9ab1b99d80e69c8c954ed386493368884b55c939b8d64d26f643e800c56f90c01079d7c534e3b2b7ae352cefd3016da55f6a85eb803b85e2304915fd2001f77c74e28746293c46e4f5f0fd49cf988aafd0026b8e7a3bab2da5cdce1ea26c2e29ec03f4807fac432662b2d6c060be1c7be0e5489de69d0a6e03a4b9117f9244b34a0f1ecba89884f781c6320412413a00c4980287409a2a78c2cd7e65cecebbe4ec1c28cac4dd95f6998e78fc6f1392384331c9436aa10e10e2bf8ad2c4eafbcf276aa7bae64b74428911b3269c749338b0fc5075ad", - "Expected": "d61fe4e3f32ac260915b5b03b78a86d11bfc41d973fce5b0cc59035cf8289a8a2e3878ea15fa46565b0d806e2f85b53873ea20ed653869b688adf83f3ef444535bf91598ff7e80f334fb782539b92f39f55310cc4b35349ab7b278346eda9bc37c0d8acd3557fae38197f412f8d9e57ce6a76b7205c23564cab06e5615be7c6f05c3d05ec690cba91da5e89d55b152ff8dd2157dc5458190025cf94b1ad98f7cbe64e9482faba95e6b33844afc640892872b44a9932096508f4a782a4805323808f23e54b6ff9b841dbfa87db3505ae4f687972c18ea0f0d0af89d36c1c2a5b14560c153c3fee406f5cf15cfd1c0bb45d767426d465f2f14c158495069d0c5955a00150707862ecaae30624ebacdd8ac33e4e6aab3ff90b6ba445a84689386b9e945d01823a65874444316e83767290fcff630d2477f49d5d8ffdd200e08ee1274270f86ed14c687895f6caf5ce528bd970c20d2408a9ba66216324c6a011ac4999098362dbd98a038129a2d40c8da6ab88318aa3046cb660327cc44236d9e5d2163bd0959062195c51ed93d0088b6f92051fc99050ece2538749165976233697ab4b610385366e5ce0b02ad6b61c168ecfbedcdf74278a38de340fd7a5fead8e588e294795f9b011e2e60377a89e25c90e145397cdeabc60fd32444a6b7642a611a83c464d8b8976666351b4865c37b02e6dc21dbcdf5f930341707b618cc0f03c3122646b3385c9df9f2ec730eec9d49e7dfc9153b6e6289da8c4f0ebea9ccc1b751948e3bb7171c9e4d57423b0eeeb79095c030cb52677b3f7e0b45c30f645391f3f9c957afa549c4e0b2465b03c67993cd200b1af01035962edbc4c9e89b31c82ac121987d6529dafdeef67a132dc04b6dc68e77f22862040b75e2ceb9ff16da0fca534e6db7bd12fa7b7f51b6c08c1e23dfcdb7acbd2da0b51c87ffbced065a612e9b1c8bba9b7e2d8d7a2f04fcc4aaf355b60d764879a76b5e16762d5f2f55d585d0c8e82df6940960cddfb72c91dfa71f6b4e1c6ca25dfc39a878e998a663c04fe29d5e83b9586d047b4d7ff70a9f0d44f127e7d741685ca75f11629128d916a0ffef4be586a30c4b70389cc746e84ebf177c01ee8a4511cfbb9d1ecf7f7b33c7dd8177896e10bbc82f838dcd6db7ac67de62bf46b6a640fb580c5d1d2708f3862e3d2b645d0d18e49ef088053e3a220adc0e033c2afcfe61c90e32151152eb3caaf746c5e377d541cafc6cbb0cc0fa48b5caf1728f2e1957f5addfc234f1a9d89e40d49356c9172d0561a695fce6dab1d412321bbf407f63766ffd7b6b3d79bcfa07991c5a9709849c1008689e3b47c50d613980bec239fb64185249d055b30375ccb4354d71fe4d05648fbf6c80634dfc3575f2f24abb714c1e4c95e8896763bf4316e954c7ad19e5780ab7a040ca6fb9271f90a8b22ae738daf6cb", - "Name": "nagydani-5-square", - "Gas": 17868, - "NoBenchmark": false - }, - { - "Input": "000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000400c5a1611f8be90071a43db23cc2fe01871cc4c0e8ab5743f6378e4fef77f7f6db0095c0727e20225beb665645403453e325ad5f9aeb9ba99bf3c148f63f9c07cf4fe8847ad5242d6b7d4499f93bd47056ddab8f7dee878fc2314f344dbee2a7c41a5d3db91eff372c730c2fdd3a141a4b61999e36d549b9870cf2f4e632c4d5df5f024f81c028000073a0ed8847cfb0593d36a47142f578f05ccbe28c0c06aeb1b1da027794c48db880278f79ba78ae64eedfea3c07d10e0562668d839749dc95f40467d15cf65b9cfc52c7c4bcef1cda3596dd52631aac942f146c7cebd46065131699ce8385b0db1874336747ee020a5698a3d1a1082665721e769567f579830f9d259cec1a836845109c21cf6b25da572512bf3c42fd4b96e43895589042ab60dd41f497db96aec102087fe784165bb45f942859268fd2ff6c012d9d00c02ba83eace047cc5f7b2c392c2955c58a49f0338d6fc58749c9db2155522ac17914ec216ad87f12e0ee95574613942fa615898c4d9e8a3be68cd6afa4e7a003dedbdf8edfee31162b174f965b20ae752ad89c967b3068b6f722c16b354456ba8e280f987c08e0a52d40a2e8f3a59b94d590aeef01879eb7a90b3ee7d772c839c85519cbeaddc0c193ec4874a463b53fcaea3271d80ebfb39b33489365fc039ae549a17a9ff898eea2f4cb27b8dbee4c17b998438575b2b8d107e4a0d66ba7fca85b41a58a8d51f191a35c856dfbe8aef2b00048a694bbccff832d23c8ca7a7ff0b6c0b3011d00b97c86c0628444d267c951d9e4fb8f83e154b8f74fb51aa16535e498235c5597dac9606ed0be3173a3836baa4e7d756ffe1e2879b415d3846bccd538c05b847785699aefde3e305decb600cd8fb0e7d8de5efc26971a6ad4e6d7a2d91474f1023a0ac4b78dc937da0ce607a45974d2cac1c33a2631ff7fe6144a3b2e5cf98b531a9627dea92c1dc82204d09db0439b6a11dd64b484e1263aa45fd9539b6020b55e3baece3986a8bffc1003406348f5c61265099ed43a766ee4f93f5f9c5abbc32a0fd3ac2b35b87f9ec26037d88275bd7dd0a54474995ee34ed3727f3f97c48db544b1980193a4b76a8a3ddab3591ce527f16d91882e67f0103b5cda53f7da54d489fc4ac08b6ab358a5a04aa9daa16219d50bd672a7cb804ed769d218807544e5993f1c27427104b349906a0b654df0bf69328afd3013fbe430155339c39f236df5557bf92f1ded7ff609a8502f49064ec3d1dbfb6c15d3a4c11a4f8acd12278cbf68acd5709463d12e3338a6eddb8c112f199645e23154a8e60879d2a654e3ed9296aa28f134168619691cd2c6b9e2eba4438381676173fc63c2588a3c5910dc149cf3760f0aa9fa9c3f5faa9162b0bf1aac9dd32b706a60ef53cbdb394b6b40222b5bc80eea82ba8958386672564cae3794f977871ab62337cf03e30049201ec12937e7ce79d0f55d9c810e20acf52212aca1d3888949e0e4830aad88d804161230eb89d4d329cc83570fe257217d2119134048dd2ed167646975fc7d77136919a049ea74cf08ddd2b896890bb24a0ba18094a22baa351bf29ad96c66bbb1a598f2ca391749620e62d61c3561a7d3653ccc8892c7b99baaf76bf836e2991cb06d6bc0514568ff0d1ec8bb4b3d6984f5eaefb17d3ea2893722375d3ddb8e389a8eef7d7d198f8e687d6a513983df906099f9a2d23f4f9dec6f8ef2f11fc0a21fac45353b94e00486f5e17d386af42502d09db33cf0cf28310e049c07e88682aeeb00cb833c5174266e62407a57583f1f88b304b7c6e0c84bbe1c0fd423072d37a5bd0aacf764229e5c7cd02473460ba3645cd8e8ae144065bf02d0dd238593d8e230354f67e0b2f23012c23274f80e3ee31e35e2606a4a3f31d94ab755e6d163cff52cbb36b6d0cc67ffc512aeed1dce4d7a0d70ce82f2baba12e8d514dc92a056f994adfb17b5b9712bd5186f27a2fda1f7039c5df2c8587fdc62f5627580c13234b55be4df3056050e2d1ef3218f0dd66cb05265fe1acfb0989d8213f2c19d1735a7cf3fa65d88dad5af52dc2bba22b7abf46c3bc77b5091baab9e8f0ddc4d5e581037de91a9f8dcbc69309be29cc815cf19a20a7585b8b3073edf51fc9baeb3e509b97fa4ecfd621e0fd57bd61cac1b895c03248ff12bdbc57509250df3517e8a3fe1d776836b34ab352b973d932ef708b14f7418f9eceb1d87667e61e3e758649cb083f01b133d37ab2f5afa96d6c84bcacf4efc3851ad308c1e7d9113624fce29fab460ab9d2a48d92cdb281103a5250ad44cb2ff6e67ac670c02fdafb3e0f1353953d6d7d5646ca1568dea55275a050ec501b7c6250444f7219f1ba7521ba3b93d089727ca5f3bbe0d6c1300b423377004954c5628fdb65770b18ced5c9b23a4a5a6d6ef25fe01b4ce278de0bcc4ed86e28a0a68818ffa40970128cf2c38740e80037984428c1bd5113f40ff47512ee6f4e4d8f9b8e8e1b3040d2928d003bd1c1329dc885302fbce9fa81c23b4dc49c7c82d29b52957847898676c89aa5d32b5b0e1c0d5a2b79a19d67562f407f19425687971a957375879d90c5f57c857136c17106c9ab1b99d80e69c8c954ed386493368884b55c939b8d64d26f643e800c56f90c01079d7c534e3b2b7ae352cefd3016da55f6a85eb803b85e2304915fd2001f77c74e28746293c46e4f5f0fd49cf988aafd0026b8e7a3bab2da5cdce1ea26c2e29ec03f4807fac432662b2d6c060be1c7be0e5489de69d0a6e03a4b9117f9244b34a0f1ecba89884f781c6320412413a00c4980287409a2a78c2cd7e65cecebbe4ec1c28cac4dd95f6998e78fc6f1392384331c9436aa10e10e2bf8ad2c4eafbcf276aa7bae64b74428911b3269c749338b0fc5075ad", - "Expected": "5f9c70ec884926a89461056ad20ac4c30155e817f807e4d3f5bb743d789c83386762435c3627773fa77da5144451f2a8aad8adba88e0b669f5377c5e9bad70e45c86fe952b613f015a9953b8a5de5eaee4566acf98d41e327d93a35bd5cef4607d025e58951167957df4ff9b1627649d3943805472e5e293d3efb687cfd1e503faafeb2840a3e3b3f85d016051a58e1c9498aab72e63b748d834b31eb05d85dcde65e27834e266b85c75cc4ec0135135e0601cb93eeeb6e0010c8ceb65c4c319623c5e573a2c8c9fbbf7df68a930beb412d3f4dfd146175484f45d7afaa0d2e60684af9b34730f7c8438465ad3e1d0c3237336722f2aa51095bd5759f4b8ab4dda111b684aa3dac62a761722e7ae43495b7709933512c81c4e3c9133a51f7ce9f2b51fcec064f65779666960b4e45df3900f54311f5613e8012dd1b8efd359eda31a778264c72aa8bb419d862734d769076bce2810011989a45374e5c5d8729fec21427f0bf397eacbb4220f603cf463a4b0c94efd858ffd9768cd60d6ce68d755e0fbad007ce5c2223d70c7018345a102e4ab3c60a13a9e7794303156d4c2063e919f2153c13961fb324c80b240742f47773a7a8e25b3e3fb19b00ce839346c6eb3c732fbc6b888df0b1fe0a3d07b053a2e9402c267b2d62f794d8a2840526e3ade15ce2264496ccd7519571dfde47f7a4bb16292241c20b2be59f3f8fb4f6383f232d838c5a22d8c95b6834d9d2ca493f5a505ebe8899503b0e8f9b19e6e2dd81c1628b80016d02097e0134de51054c4e7674824d4d758760fc52377d2cad145e259aa2ffaf54139e1a66b1e0c1c191e32ac59474c6b526f5b3ba07d3e5ec286eddf531fcd5292869be58c9f22ef91026159f7cf9d05ef66b4299f4da48cc1635bf2243051d342d378a22c83390553e873713c0454ce5f3234397111ac3fe3207b86f0ed9fc025c81903e1748103692074f83824fda6341be4f95ff00b0a9a208c267e12fa01825054cc0513629bf3dbb56dc5b90d4316f87654a8be18227978ea0a8a522760cad620d0d14fd38920fb7321314062914275a5f99f677145a6979b156bd82ecd36f23f8e1273cc2759ecc0b2c69d94dad5211d1bed939dd87ed9e07b91d49713a6e16ade0a98aea789f04994e318e4ff2c8a188cd8d43aeb52c6daa3bc29b4af50ea82a247c5cd67b573b34cbadcc0a376d3bbd530d50367b42705d870f2e27a8197ef46070528bfe408360faa2ebb8bf76e9f388572842bcb119f4d84ee34ae31f5cc594f23705a49197b181fb78ed1ec99499c690f843a4d0cf2e226d118e9372271054fbabdcc5c92ae9fefaef0589cd0e722eaf30c1703ec4289c7fd81beaa8a455ccee5298e31e2080c10c366a6fcf56f7d13582ad0bcad037c612b710fc595b70fbefaaca23623b60c6c39b11beb8e5843b6b3dac60f", - "Name": "nagydani-5-qube", - "Gas": 17868, - "NoBenchmark": false - }, - { - "Input": "000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000400c5a1611f8be90071a43db23cc2fe01871cc4c0e8ab5743f6378e4fef77f7f6db0095c0727e20225beb665645403453e325ad5f9aeb9ba99bf3c148f63f9c07cf4fe8847ad5242d6b7d4499f93bd47056ddab8f7dee878fc2314f344dbee2a7c41a5d3db91eff372c730c2fdd3a141a4b61999e36d549b9870cf2f4e632c4d5df5f024f81c028000073a0ed8847cfb0593d36a47142f578f05ccbe28c0c06aeb1b1da027794c48db880278f79ba78ae64eedfea3c07d10e0562668d839749dc95f40467d15cf65b9cfc52c7c4bcef1cda3596dd52631aac942f146c7cebd46065131699ce8385b0db1874336747ee020a5698a3d1a1082665721e769567f579830f9d259cec1a836845109c21cf6b25da572512bf3c42fd4b96e43895589042ab60dd41f497db96aec102087fe784165bb45f942859268fd2ff6c012d9d00c02ba83eace047cc5f7b2c392c2955c58a49f0338d6fc58749c9db2155522ac17914ec216ad87f12e0ee95574613942fa615898c4d9e8a3be68cd6afa4e7a003dedbdf8edfee31162b174f965b20ae752ad89c967b3068b6f722c16b354456ba8e280f987c08e0a52d40a2e8f3a59b94d590aeef01879eb7a90b3ee7d772c839c85519cbeaddc0c193ec4874a463b53fcaea3271d80ebfb39b33489365fc039ae549a17a9ff898eea2f4cb27b8dbee4c17b998438575b2b8d107e4a0d66ba7fca85b41a58a8d51f191a35c856dfbe8aef2b00048a694bbccff832d23c8ca7a7ff0b6c0b3011d00b97c86c0628444d267c951d9e4fb8f83e154b8f74fb51aa16535e498235c5597dac9606ed0be3173a3836baa4e7d756ffe1e2879b415d3846bccd538c05b847785699aefde3e305decb600cd8fb0e7d8de5efc26971a6ad4e6d7a2d91474f1023a0ac4b78dc937da0ce607a45974d2cac1c33a2631ff7fe6144a3b2e5cf98b531a9627dea92c1dc82204d09db0439b6a11dd64b484e1263aa45fd9539b6020b55e3baece3986a8bffc1003406348f5c61265099ed43a766ee4f93f5f9c5abbc32a0fd3ac2b35b87f9ec26037d88275bd7dd0a54474995ee34ed3727f3f97c48db544b1980193a4b76a8a3ddab3591ce527f16d91882e67f0103b5cda53f7da54d489fc4ac08b6ab358a5a04aa9daa16219d50bd672a7cb804ed769d218807544e5993f1c27427104b349906a0b654df0bf69328afd3013fbe430155339c39f236df5557bf92f1ded7ff609a8502f49064ec3d1dbfb6c15d3a4c11a4f8acd12278cbf68acd5709463d12e3338a6eddb8c112f199645e23154a8e60879d2a654e3ed9296aa28f134168619691cd2c6b9e2eba4438381676173fc63c2588a3c5910dc149cf3760f0aa9fa9c3f5faa9162b0bf1aac9dd32b706a60ef53cbdb394b6b40222b5bc80eea82ba8958386672564cae3794f977871ab62337cf010001e30049201ec12937e7ce79d0f55d9c810e20acf52212aca1d3888949e0e4830aad88d804161230eb89d4d329cc83570fe257217d2119134048dd2ed167646975fc7d77136919a049ea74cf08ddd2b896890bb24a0ba18094a22baa351bf29ad96c66bbb1a598f2ca391749620e62d61c3561a7d3653ccc8892c7b99baaf76bf836e2991cb06d6bc0514568ff0d1ec8bb4b3d6984f5eaefb17d3ea2893722375d3ddb8e389a8eef7d7d198f8e687d6a513983df906099f9a2d23f4f9dec6f8ef2f11fc0a21fac45353b94e00486f5e17d386af42502d09db33cf0cf28310e049c07e88682aeeb00cb833c5174266e62407a57583f1f88b304b7c6e0c84bbe1c0fd423072d37a5bd0aacf764229e5c7cd02473460ba3645cd8e8ae144065bf02d0dd238593d8e230354f67e0b2f23012c23274f80e3ee31e35e2606a4a3f31d94ab755e6d163cff52cbb36b6d0cc67ffc512aeed1dce4d7a0d70ce82f2baba12e8d514dc92a056f994adfb17b5b9712bd5186f27a2fda1f7039c5df2c8587fdc62f5627580c13234b55be4df3056050e2d1ef3218f0dd66cb05265fe1acfb0989d8213f2c19d1735a7cf3fa65d88dad5af52dc2bba22b7abf46c3bc77b5091baab9e8f0ddc4d5e581037de91a9f8dcbc69309be29cc815cf19a20a7585b8b3073edf51fc9baeb3e509b97fa4ecfd621e0fd57bd61cac1b895c03248ff12bdbc57509250df3517e8a3fe1d776836b34ab352b973d932ef708b14f7418f9eceb1d87667e61e3e758649cb083f01b133d37ab2f5afa96d6c84bcacf4efc3851ad308c1e7d9113624fce29fab460ab9d2a48d92cdb281103a5250ad44cb2ff6e67ac670c02fdafb3e0f1353953d6d7d5646ca1568dea55275a050ec501b7c6250444f7219f1ba7521ba3b93d089727ca5f3bbe0d6c1300b423377004954c5628fdb65770b18ced5c9b23a4a5a6d6ef25fe01b4ce278de0bcc4ed86e28a0a68818ffa40970128cf2c38740e80037984428c1bd5113f40ff47512ee6f4e4d8f9b8e8e1b3040d2928d003bd1c1329dc885302fbce9fa81c23b4dc49c7c82d29b52957847898676c89aa5d32b5b0e1c0d5a2b79a19d67562f407f19425687971a957375879d90c5f57c857136c17106c9ab1b99d80e69c8c954ed386493368884b55c939b8d64d26f643e800c56f90c01079d7c534e3b2b7ae352cefd3016da55f6a85eb803b85e2304915fd2001f77c74e28746293c46e4f5f0fd49cf988aafd0026b8e7a3bab2da5cdce1ea26c2e29ec03f4807fac432662b2d6c060be1c7be0e5489de69d0a6e03a4b9117f9244b34a0f1ecba89884f781c6320412413a00c4980287409a2a78c2cd7e65cecebbe4ec1c28cac4dd95f6998e78fc6f1392384331c9436aa10e10e2bf8ad2c4eafbcf276aa7bae64b74428911b3269c749338b0fc5075ad", - "Expected": "5a0eb2bdf0ac1cae8e586689fa16cd4b07dfdedaec8a110ea1fdb059dd5253231b6132987598dfc6e11f86780428982d50cf68f67ae452622c3b336b537ef3298ca645e8f89ee39a26758206a5a3f6409afc709582f95274b57b71fae5c6b74619ae6f089a5393c5b79235d9caf699d23d88fb873f78379690ad8405e34c19f5257d596580c7a6a7206a3712825afe630c76b31cdb4a23e7f0632e10f14f4e282c81a66451a26f8df2a352b5b9f607a7198449d1b926e27036810368e691a74b91c61afa73d9d3b99453e7c8b50fd4f09c039a2f2feb5c419206694c31b92df1d9586140cb3417b38d0c503c7b508cc2ed12e813a1c795e9829eb39ee78eeaf360a169b491a1d4e419574e712402de9d48d54c1ae5e03739b7156615e8267e1fb0a897f067afd11fb33f6e24182d7aaaaa18fe5bc1982f20d6b871e5a398f0f6f718181d31ec225cfa9a0a70124ed9a70031bdf0c1c7829f708b6e17d50419ef361cf77d99c85f44607186c8d683106b8bd38a49b5d0fb503b397a83388c5678dcfcc737499d84512690701ed621a6f0172aecf037184ddf0f2453e4053024018e5ab2e30d6d5363b56e8b41509317c99042f517247474ab3abc848e00a07f69c254f46f2a05cf6ed84e5cc906a518fdcfdf2c61ce731f24c5264f1a25fc04934dc28aec112134dd523f70115074ca34e3807aa4cb925147f3a0ce152d323bd8c675ace446d0fd1ae30c4b57f0eb2c23884bc18f0964c0114796c5b6d080c3d89175665fbf63a6381a6a9da39ad070b645c8bb1779506da14439a9f5b5d481954764ea114fac688930bc68534d403cff4210673b6a6ff7ae416b7cd41404c3d3f282fcd193b86d0f54d0006c2a503b40d5c3930da980565b8f9630e9493a79d1c03e74e5f93ac8e4dc1a901ec5e3b3e57049124c7b72ea345aa359e782285d9e6a5c144a378111dd02c40855ff9c2be9b48425cb0b2fd62dc8678fd151121cf26a65e917d65d8e0dacfae108eb5508b601fb8ffa370be1f9a8b749a2d12eeab81f41079de87e2d777994fa4d28188c579ad327f9957fb7bdecec5c680844dd43cb57cf87aeb763c003e65011f73f8c63442df39a92b946a6bd968a1c1e4d5fa7d88476a68bd8e20e5b70a99259c7d3f85fb1b65cd2e93972e6264e74ebf289b8b6979b9b68a85cd5b360c1987f87235c3c845d62489e33acf85d53fa3561fe3a3aee18924588d9c6eba4edb7a4d106b31173e42929f6f0c48c80ce6a72d54eca7c0fe870068b7a7c89c63cdda593f5b32d3cb4ea8a32c39f00ab449155757172d66763ed9527019d6de6c9f2416aa6203f4d11c9ebee1e1d3845099e55504446448027212616167eb36035726daa7698b075286f5379cd3e93cb3e0cf4f9cb8d017facbb5550ed32d5ec5400ae57e47e2bf78d1eaeff9480cc765ceff39db500", - "Name": "nagydani-5-pow0x10001", - "Gas": 285900, - "NoBenchmark": false - }, - { - "Input": "0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000409aaf0cd43ee868a92194c346bac7d5551e97439fb92163e38fbd2699ece0e817a8d70b67a7d39c975e9490645464d21a60e59eb4c1bc00784c294581c1cfbd41acab9ee2bb6dae4afaac402591ff8e2aeb0b3806413456ebd6931b7e8e1bd58ed74eb7a8c6ef5ff33754b9147bdbe74d9a1a96b597b6ff7855b20c285230bbded6b14e4247e664fbac45cfed7a4170fbabcee373851ff7204f3f5313e236a00798db3ec98ca406b4b69a0951e712fd1341117c844c4859b6ba2df30792501876", - "Expected": "97e3edb32d968a33cae520a37fe5cada129980885801e54cc5b45ae2f544711074408dd98174ddfe5b920222091dfc672e59f5001ef526f315726c9597a2f7397", - "Name": "random-1", - "Gas": 10901, - "NoBenchmark": false - }, - { - "Input": "000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100a562755a0b5a3c0dce5d2f99a3dadc496848d9894565eda1ebbe03a1219a253b561718ba823e8781bff41af6ba2910e9dc98ab32c866674075d46e4d579aeb3337f3438bc121c72ac058ca504bf7e6c2ad19c588eff273efb0d845aecf3a2a2408e6bfc6e58528bad18072709b16f57dedac9f3dd56343448053dae9dc195a862da647643820dc28f10ab76f80025499e2c7c0239bed4fa5a37a4592aa3fdeb725eb43f5ce9145cdcf774ccaabd3c37eff4006145937ea4056a2c0bdda4a7db22cff4994be5ecb5181f35423a085f9cfb7c7926938c95eee01039f2cd088f284f99a9dac8a2ebfa075b49266e3c69fd1a8f10613b8137962a05b93bbbf9e81f900cf2906e74d458807f1f38337f80b3a63ce83de82decce6203a0b2e9a03e1d7339965139c98e95bab7d0cc61ff52ba84f5957f11aa277210243e5ad4116ed03101c509d92f79dcbe5273304d206c62a0f63df41acefbc9022441159b33b1a958f08b502a58d1557bb8c0cf26f724efb7dba9ede37ab572160bf7b4ee64418a90d9d75ca51c385814d87861fe3c921aff515dbf89d3b5de3b093a2e611c671777463e5d1fd84aab9351c90b025383e969dcb59d1681f0bd1409119bd209e6f86150fab7fe450b2706b22c280aaacbd78550b48456da00e545713906b6aec9896ad099a168dbeb24d19e866465c8a2793d3a0681556291975005628d0bf46067e892cd3a012a7eb9758fb2c843ac8f7ccecfd98ca84834083f025153695e28ed2e2e7bc30b786812cb5d0bc5afd953b385e5be4c1ae3bfa06eb50b0ec91b401766c5aa2520bc715667b6c14b3c7e5865ae9ddd839fdcc24a6edb64467d5949a00cf45eea3f3e82d96467d464227463f06c95603b4dcc7789f35fb655583ad91e6d114e481f7e36700af41f38086e27fa6773e9d7f91e62407cc4e6df783d81398ec5f701261bd0ee6ee02049ad4f819537bbedd44101255eaefddb5a876707dd72e5a9327716c45b92fb6908fe28a33d335197bc5face88da098522840866707e852c6b7a65f1e20e7924155981c50865aae1735df4b7dd5fd1b91deb4ac1b1c9", - "Expected": "4aa808af385b8f843aaa63bff77929bcfab802cd8725c696668f00bc1e339438c2613892f1a9469d9b35c18234f33a6c6de477f0e716dcbc763fd2ff134a970576d92b587d0451f92bc47b6fcb0f7f67ddcfc7888868d8df3bf0126556cdbd262b334a15a661116882e211e8a22414172c6b016296b578b246fd967be5b1b2ec2a3154b77c16b55179f08dde77142421cd816649dfca87280e41cd65f8083e407dbc49d08a584b243443f574562965ae489a42076c721e06bd761af6b5a14bcc6082f5b6217519380a0b67af3f3dfde94affc20eec3d7afb97c46ee622f7a24193fe03b8d66850e745215a70989cdb5c4e2eb6eee34ecc050737155ffa228f04", - "Name": "random-2", - "Gas": 695978, - "NoBenchmark": false - }, - { - "Input": "000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000300fca65d7df0af69e7e334361bce8b5493cc610c06045ed7e1d86a097f5de3162cf7cf4ad5b48e2e75dc1a9aaea306eaffa967d2bc3e9b3d9ecf7ca585a5ea89001d0924fe417fdf3e33962ae9c3283dd17f0ad6f6115aed5b92ab0537e9a8cff2919a909ae2ebbd29889489a77154daa63fd3059b1393eec21cc86c9679a7558ac737582997a3ef944cad6d7dd145ea3dd05ff816a334defdabce7e197e27afe03ffee039fcb10e9ce3714e662671f0d6de2fc51aaf3ee793595b7ec924d61525fd8c3ed365b1411f505c3231e577d73adda73b4f61953100174ddfa03245770c5b296999331d712ceda6c9520cb5ade28344eb7d9ac5c3675b3dbb17d1a0ec0ae525d5bb0d3d06bf360e62bacbdff4629ffd1cee59f9729665013df562595b4cbabe6de6dff2d4463d2c468c62099c7c495877d383fdb1ebb33f550c00115dddb316000c710e83ad29d6b12db3e5335c65c1ac09e187c8bc0d81329f9cc8462bce69d84c08900a3bd5c9aaad4c8338ce0bf9a73e6553fb2c4d44fef0dbe3116190865e4a0ce654d4b7703417dc1b708a496493a32007c67b6dacffc391195ff1b8491cc625edc125a4d287f41ee44f32d474a777506e4089bfe3dd5fe790439d11435f93ffa9645ba26efe4e80d15c885dcdef1c72e7a1490893064210613e138eeae3db85bb322a0f4bd5e170f108ee86540219a1262a29a2158a6ba3224a4130eac096ed8103a19ac40d2612bfd9178a17bbbb5f247267bfba396f30c786ec0193b1863172010451607fdd190316e23c73e18c668ee20b7758d632489370d33d20257f0d53e51716b76afea5954ebba45633bce5fa8572b1a60ed89ccebcbdefab9ff8de97d5e98dc975af24e365e2091a8ef260b4ed429ab3cd67450c7b48fbac0ef9f556dd0d81492e1c85d64dcd402bcf813fca5c3bbe5d5d2bc96ea4804e2db477d56cedb33d81711785d1bdc465ff26193dfa083150d23b98f8b14312a5adce5822d6f8d43d1b43be5945b6ed9f99c6ca478a4353248227023155bb8c3d5e72d70264a28e0752db22b649d80a1c4df85feb79cb1a6a7a339faef6a2e860b780fad3dfea3bf637c2f4ae209ddbaa1de5e35c5ca0c492576c883103e011aff3c1ffc8dd363c63bd68b3b6d66b49dc58f49110bf8c0416bc687b736209f257b144bb5f9e12cde6a9809ff3ed0ebceb22abd90f4e00f066bde80c75bac900b3755c0491b0ea3e4626ab673fec1029aeab9050b630e308b15454a1b505582bdf7feb7d90092a3b376d92e8a399b07aacbf5ec92a794a829253533c5b498840cd7f88c0009398a4815418499dfa6517a3daf4f6a78f00653469ea3db6ede0eee4521a2311f0791927b947d66001e597ee3b98805592993e7f228b97a85bee93742a644bdf4106b361dacfed472a053384534e7a545f9852b9dca4ef65e170cbcbb362369c99b7ac35e51f7ac2abf6541d5713550c743f14911191039d164e7f6a032293c7ce96ea9ba2446f401e8f0ee54fd10dce1bbf57744ea58b08b40f1e979f10bf88638c4ec129ba6a2fd0d47281831d4d4541b14f44cb1f79290be2e79225d7a00ed08582c2834ca4605527a47a32098496c2d956eec17bbd431325b547d2d709f83364b1fe9b8ac1f40ceeeea47afff6025d50d04c81b24d55c73eaf5d965d8e7d1dab46cd5786fa371761e1d28c19c9132eb2e98206bd7681175c365ddb635daf607186ceb929aad756993420d07ac8ae759c2fe3730b765f35c5b6fb4f9d5cb30331721b93fa5a0508122b6d8956b09c9388e73e34793b54fa2699f472ae87b83c801c9e07ad1b7b412adb61e008d6de141968c7b51d7f89f61e216c606693598a733109391195e56c6cfd0a9eda73f150bbdf5846bf021f0093a8e88cae1adb9781d66dd7cca40384825b492075eb1caa2f1ca5863a13ca701208a669ac59bd5121731c03061a8316dcd4c364b9fe8ba88c3d5c9275545c6e0cfcc5c4fe99d7299df7fe01ce19a315988eaa664f65b6137dfedd6efc2bdccc16aef60a55bf1842fc9ac7c20089d9729a47f9e6a9f51ea645b146ffbc682c721a31ea1f2299c0d9766869b49ef413f3246ad4b431f523208f50c4a3781885946e55a7ce9eba500087206f418c6a08509e53da52937740250ec990d1d41d605ee3d546484d44546a19d42d1085e29425487304253d3200f61481bfd4297e2b6abf115db623bf0359fe7038bf4a2f9f2c356a8961183b20b0d55033cb8480419ba8c3507484de018870ab27cdf941abe5e2939fbef5ca5184f0ace1d28c37d47e2f9d1686de2ba7576900f06c1353b694a44ee9f1e082a5de71cc83d7fc2ffc38d6a99d5b2a2506b7eb4855f5d9e5719cf54d2e3d4ee39dacf8371512a7d05a3a03b7966ab65b697f483205972cb0058c5ae6e1af00bfeaf30bf063f210f30f1bee1bf1214e06e69ae3aef51cdd0580473288b7c0efaa3944cda25fc5f7766f5422eaa911bee33d540046cc51c9ce1505701bc0873b4e2c43e2ad54aca621a36c3fa1f9f35b6f884e4b63c0a8dee77aff8d5954dbb6e818d4bd662e118f91addea35f1228d421a90193713bd88e8364fa32541e4dcdc7b657882535f54077bfbab5e1057fd5522a6bb0524844ac40453a0133de3a726011dba8ba9fafebb3c11bb28123ac7ee525e02ab29c7a7f71ab48dffbf40c98844755d02ad61ab27a7ffc912d922a1d99bb1b0dfd10bfc3975b370f57cff0bfb4822d39cddc540e0b2eaf33a0e852de802b463fd8fe9b74879138ce9f0a5aab8f3cddaa64f14fbc670d02cf608c23ae09588f2c89b0e7b5e7b9b13ca3866f00d304a3630ba7798edc89d8cbfccb14fb6d8ac4467b2e21df5527c2ab3f1218e19d01fb5be9c0a261de004fffd71bb91ba5b6ce19c12985a5e2c40de4e5ce4fc970f72efad0b811ade763677ade2107396da6068843ff20747c567924b2be7c10b0868fe0edbe4beda420315ec10ac6c0bdd3763ec8c78571d7b97e793eedfb29e657c95892264cae5b19e323cdc1b2718fb867de473e48e9001d093340d1aeb725087769416e2d9687c7e2aee462a315070cea86851ce1a80fe057751c186e896a2bfdc5494930218ad057805b99059d7af42c33e727320826cf596016b87a6f595943b865decbbddcc8fcb4c5614c76dbbafa28eb3aa143f9f49e79efcf0ad156e82601554c389c286e571e2b7d43c583e3855cbe51831eb700bf703f51ce0cbd2a5edd3a4a208e815eff7ce2", - "Expected": "322095f875760be6e68ff243035d11bf24ba5efe065d6f1036756cb9dc71e8c889cc87f614f7e16e694cda1bb12357cb866f7dbd9917c7da6bbd0dcbdc0d923e79d35255a6fba56ae769e8acd80bb6fb55227021649ec00f67c476e88d582dd474100bb9c5e834b13e62d680812a8564e63e94347eb755a129da1e0a7fa33c82eaffcf2faaed039c28ce512df21f987621fe86a48d5a6be2a69f95c3385a8a70ba18a142446f13e1a5d617c84cf5f0d901545eaab402ae8dd15c91216624e67687fd7a2594a3cd8b0e6ed7ba56002a77a6e917561923a503c65fdbc34268daee52d4ec98fa92a0908c0bc5f04bde3a8dac2400d3284b4cf77f3f0929c6352fd242ceaab08afe7b1966afed11ad364bd76b31461559be396fdac25a2bcd8334fa3c43889b5514714e06088a3a3d2b368b8e594cb674a4df2627e2fda6514ddd0c622d627a1f87d14386906da0126c35bb4490f87d71f75d47038096de6a89b9209509385a15bb5dcff3e0d9d493159fdd206df13d34f778aeac9b69e9f2897c93ff587b86e10937c1d6cd7f640c30fe17e0716d74eeea25e18ab1b1aa08e63590261dcab0f247d1bc090dda80e8665109e9ca95f47a5dcecfa0e2bed9864e4dac15afb99d4d1d776d2f65362acb5ca14726d2f3a712f4ed43a1fad18a22f96f470b0ee4877f4820288587e01fd6ef81703776ac27081e9cdf0fba3ca5878f368dc6e06de9fdd2ccc10c9b1da1a3947a9cb87df4740db06fabc21f5082b5c580f1675c48834ab4cc0ff49e8c134f0a0c76b5d0820bc5f2691e7e3ce48a327c311921a8b746fc8192dd2abae3aff0c153af09367f49cbbc39c02984c8c077ddf8dcaf786fac7cc2f3aef8daec0a700172abcdbee72d830c6eaf5def5442658f6f878b581f213565ec085685804b658360366e024dae2de41c49ceb78399de7997d3a6bea66fff501ffd08695c9941a91a1d129d10c1d61b720e0f1f1f9d7c3d06e1304e8d8b7fc243cc9f361af4f75d007c6a7a8580f5af4e898c6644435697f70abf307ea519ef9a140668f145b6741fe1b3e0f14f3638158c6bb81c54b524c122", - "Name": "random-3", - "Gas": 18868224, - "NoBenchmark": false - } -] \ No newline at end of file diff --git a/src/bench_precompiles b/src/bench_precompiles index d083d17d367..c1089350ef0 160000 --- a/src/bench_precompiles +++ b/src/bench_precompiles @@ -1 +1 @@ -Subproject commit d083d17d3679b82585877a2d18829535d972546a +Subproject commit c1089350ef0daa3f0bd437ce9d1626de973f9a93 From a0d106c8194300a09107fb481405e5d0c153b140 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 9 Oct 2024 17:33:38 +0300 Subject: [PATCH 10/12] Fixes for P2P message disposing (#7578) Co-authored-by: lukasz.rozmej --- .../P2P/PacketSenderTests.cs | 10 ---- .../P2P/SessionTests.cs | 41 ++++++++++++---- .../Nethermind.Network/P2P/PacketSender.cs | 16 ++----- .../ZeroProtocolHandlerBase.cs | 48 +++++++++++-------- .../Nethermind.Network/P2P/Session.cs | 39 ++++++++------- 5 files changed, 87 insertions(+), 67 deletions(-) diff --git a/src/Nethermind/Nethermind.Network.Test/P2P/PacketSenderTests.cs b/src/Nethermind/Nethermind.Network.Test/P2P/PacketSenderTests.cs index 785f9ef49bc..7d7aa9c3165 100644 --- a/src/Nethermind/Nethermind.Network.Test/P2P/PacketSenderTests.cs +++ b/src/Nethermind/Nethermind.Network.Test/P2P/PacketSenderTests.cs @@ -38,7 +38,6 @@ public void Does_send_on_active_channel() PacketSender packetSender = new(serializer, LimboLogs.Instance, TimeSpan.Zero); packetSender.HandlerAdded(context); packetSender.Enqueue(testMessage); - testMessage.WasDisposed.Should().BeTrue(); context.Received(1).WriteAndFlushAsync(Arg.Any()); } @@ -62,7 +61,6 @@ public void Does_not_try_to_send_on_inactive_channel() PacketSender packetSender = new(serializer, LimboLogs.Instance, TimeSpan.Zero); packetSender.HandlerAdded(context); packetSender.Enqueue(testMessage); - testMessage.WasDisposed.Should().BeTrue(); context.Received(0).WriteAndFlushAsync(Arg.Any()); } @@ -88,7 +86,6 @@ public async Task Send_after_delay_if_specified() PacketSender packetSender = new(serializer, LimboLogs.Instance, delay); packetSender.HandlerAdded(context); packetSender.Enqueue(testMessage); - testMessage.WasDisposed.Should().BeTrue(); await context.Received(0).WriteAndFlushAsync(Arg.Any()); @@ -101,13 +98,6 @@ private class TestMessage : P2PMessage { public override int PacketType { get; } = 0; public override string Protocol { get; } = ""; - - public bool WasDisposed { get; set; } - public override void Dispose() - { - base.Dispose(); - WasDisposed = true; - } } } } diff --git a/src/Nethermind/Nethermind.Network.Test/P2P/SessionTests.cs b/src/Nethermind/Nethermind.Network.Test/P2P/SessionTests.cs index 95108ed1533..a9078b29656 100644 --- a/src/Nethermind/Nethermind.Network.Test/P2P/SessionTests.cs +++ b/src/Nethermind/Nethermind.Network.Test/P2P/SessionTests.cs @@ -15,7 +15,6 @@ using Nethermind.Network.Rlpx; using Nethermind.Stats.Model; using NSubstitute; -using NSubstitute.ReceivedExtensions; using NUnit.Framework; namespace Nethermind.Network.Test.P2P; @@ -452,9 +451,11 @@ public void Can_deliver_messages() session.AddProtocolHandler(bbb); session.AddProtocolHandler(ccc); - _packetSender.Enqueue(PingMessage.Instance).Returns(10); - session.DeliverMessage(PingMessage.Instance); - _packetSender.Received().Enqueue(PingMessage.Instance); + var message = new TestMessage(); + _packetSender.Enqueue(message).Returns(10); + session.DeliverMessage(message); + _packetSender.Received().Enqueue(message); + message.WasDisposed.Should().BeTrue(); Metrics.P2PBytesSent.Should().Be(10); } @@ -462,10 +463,12 @@ public void Can_deliver_messages() [Test] public void Cannot_deliver_before_initialized() { + var message = new TestMessage(); Session session = new(30312, new Node(TestItem.PublicKeyA, "127.0.0.1", 8545), _channel, NullDisconnectsAnalyzer.Instance, LimboLogs.Instance); - Assert.Throws(() => session.DeliverMessage(PingMessage.Instance)); + Assert.Throws(() => session.DeliverMessage(message)); session.Handshake(TestItem.PublicKeyA); - Assert.Throws(() => session.DeliverMessage(PingMessage.Instance)); + Assert.Throws(() => session.DeliverMessage(message)); + message.WasDisposed.Should().BeTrue(); session.Init(5, _channelHandlerContext, _packetSender); IProtocolHandler p2p = BuildHandler("p2p", 10); session.AddProtocolHandler(p2p); @@ -494,8 +497,10 @@ public void Stops_delivering_messages_after_disconnect() session.InitiateDisconnect(DisconnectReason.Other); - session.DeliverMessage(PingMessage.Instance); - _packetSender.DidNotReceive().Enqueue(Arg.Any()); + var message = new TestMessage(); + session.DeliverMessage(message); + _packetSender.DidNotReceive().Enqueue(Arg.Any()); + message.WasDisposed.Should().BeTrue(); } [Test] @@ -538,10 +543,11 @@ public void Protocol_handler_can_send_message_on_disconnect() IProtocolHandler p2p = BuildHandler("p2p", 10); session.AddProtocolHandler(p2p); + var message = new TestMessage(); p2p.When(it => it.DisconnectProtocol(Arg.Any(), Arg.Any())) .Do((_) => { - session.DeliverMessage(PingMessage.Instance); + session.DeliverMessage(message); }); session.Init(5, _channelHandlerContext, _packetSender); @@ -549,7 +555,9 @@ public void Protocol_handler_can_send_message_on_disconnect() _packetSender .Received() - .Enqueue(PingMessage.Instance); + .Enqueue(message); + + message.WasDisposed.Should().BeTrue(); } [Test, Retry(3)] @@ -619,4 +627,17 @@ public void Updates_local_and_remote_metrics_on_disconnects() Assert.That(afterLocal, Is.EqualTo(beforeLocal)); Assert.That(afterRemote, Is.EqualTo(beforeRemote + 1)); } + + private class TestMessage : P2PMessage + { + public override int PacketType => P2PMessageCode.Ping; + public override string Protocol => "p2p"; + + public bool WasDisposed { get; set; } + public override void Dispose() + { + base.Dispose(); + WasDisposed = true; + } + } } diff --git a/src/Nethermind/Nethermind.Network/P2P/PacketSender.cs b/src/Nethermind/Nethermind.Network/P2P/PacketSender.cs index 2201fb73fd2..3248eb98115 100644 --- a/src/Nethermind/Nethermind.Network/P2P/PacketSender.cs +++ b/src/Nethermind/Nethermind.Network/P2P/PacketSender.cs @@ -27,20 +27,12 @@ public PacketSender(IMessageSerializationService messageSerializationService, IL public int Enqueue(T message) where T : P2PMessage { - IByteBuffer buffer; - try + if (!_context.Channel.IsWritable || !_context.Channel.Active) { - if (!_context.Channel.IsWritable || !_context.Channel.Active) - { - return 0; - } - - buffer = _messageSerializationService.ZeroSerialize(message); - } - finally - { - message.Dispose(); + return 0; } + + IByteBuffer buffer = _messageSerializationService.ZeroSerialize(message); int length = buffer.ReadableBytes; // Running in background diff --git a/src/Nethermind/Nethermind.Network/P2P/ProtocolHandlers/ZeroProtocolHandlerBase.cs b/src/Nethermind/Nethermind.Network/P2P/ProtocolHandlers/ZeroProtocolHandlerBase.cs index 8bf24cc1ac3..9a4e07a900e 100644 --- a/src/Nethermind/Nethermind.Network/P2P/ProtocolHandlers/ZeroProtocolHandlerBase.cs +++ b/src/Nethermind/Nethermind.Network/P2P/ProtocolHandlers/ZeroProtocolHandlerBase.cs @@ -52,29 +52,39 @@ CancellationToken token ) { Task task = request.CompletionSource.Task; - using CancellationTokenSource delayCancellation = new(); - using CancellationTokenSource compositeCancellation = - CancellationTokenSource.CreateLinkedTokenSource(token, delayCancellation.Token); - Task firstTask = await Task.WhenAny(task, Task.Delay(Timeouts.Eth, compositeCancellation.Token)); - if (firstTask.IsCanceled) + bool success = false; + try { - token.ThrowIfCancellationRequested(); - } + using CancellationTokenSource delayCancellation = new(); + using CancellationTokenSource compositeCancellation = CancellationTokenSource.CreateLinkedTokenSource(token, delayCancellation.Token); + Task firstTask = await Task.WhenAny(task, Task.Delay(Timeouts.Eth, compositeCancellation.Token)); + if (firstTask.IsCanceled) + { + token.ThrowIfCancellationRequested(); + } - if (firstTask == task) - { - delayCancellation.Cancel(); - long elapsed = request.FinishMeasuringTime(); - long bytesPerMillisecond = (long)((decimal)request.ResponseSize / Math.Max(1, elapsed)); - if (Logger.IsTrace) Logger.Trace($"{this} speed is {request.ResponseSize}/{elapsed} = {bytesPerMillisecond}"); - StatsManager.ReportTransferSpeedEvent(Session.Node, speedType, bytesPerMillisecond); + if (firstTask == task) + { + await delayCancellation.CancelAsync(); + long elapsed = request.FinishMeasuringTime(); + long bytesPerMillisecond = (long)((decimal)request.ResponseSize / Math.Max(1, elapsed)); + if (Logger.IsTrace) Logger.Trace($"{this} speed is {request.ResponseSize}/{elapsed} = {bytesPerMillisecond}"); + StatsManager.ReportTransferSpeedEvent(Session.Node, speedType, bytesPerMillisecond); - return await task; - } + success = true; + return await task; + } - CleanupTimeoutTask(task); - StatsManager.ReportTransferSpeedEvent(Session.Node, speedType, 0L); - throw new TimeoutException($"{Session} Request timeout in {describeRequestFunc(request.Message)}"); + StatsManager.ReportTransferSpeedEvent(Session.Node, speedType, 0L); + throw new TimeoutException($"{Session} Request timeout in {describeRequestFunc(request.Message)}"); + } + finally + { + if (!success) + { + CleanupTimeoutTask(task); + } + } } private static void CleanupTimeoutTask(Task task) diff --git a/src/Nethermind/Nethermind.Network/P2P/Session.cs b/src/Nethermind/Nethermind.Network/P2P/Session.cs index f092fd41ce2..2efaa613de7 100644 --- a/src/Nethermind/Nethermind.Network/P2P/Session.cs +++ b/src/Nethermind/Nethermind.Network/P2P/Session.cs @@ -207,31 +207,38 @@ public void ReceiveMessage(ZeroPacket zeroPacket) public int DeliverMessage(T message) where T : P2PMessage { - lock (_sessionStateLock) + try { - if (State < SessionState.Initialized) + lock (_sessionStateLock) { - throw new InvalidOperationException($"{nameof(DeliverMessage)} called {this}"); - } + if (State < SessionState.Initialized) + { + throw new InvalidOperationException($"{nameof(DeliverMessage)} called {this}"); + } - // Must allow sending out packet when `DisconnectingProtocols` so that we can send out disconnect reason - // and hello (part of protocol) - if (IsClosed) - { - return 1; + // Must allow sending out packet when `DisconnectingProtocols` so that we can send out disconnect reason + // and hello (part of protocol) + if (IsClosed) + { + return 1; + } } - } - if (_logger.IsTrace) _logger.Trace($"P2P to deliver {message.Protocol}.{message.PacketType} on {this}"); + if (_logger.IsTrace) _logger.Trace($"P2P to deliver {message.Protocol}.{message.PacketType} on {this}"); - message.AdaptivePacketType = _resolver.ResolveAdaptiveId(message.Protocol, message.PacketType); - int size = _packetSender.Enqueue(message); + message.AdaptivePacketType = _resolver.ResolveAdaptiveId(message.Protocol, message.PacketType); + int size = _packetSender.Enqueue(message); - RecordOutgoingMessageMetric(message, size); + RecordOutgoingMessageMetric(message, size); - Interlocked.Add(ref Metrics.P2PBytesSent, size); + Interlocked.Add(ref Metrics.P2PBytesSent, size); - return size; + return size; + } + finally + { + message.Dispose(); + } } public void ReceiveMessage(Packet packet) From 76193788c0343a4a1417346fde510d7ddaee15e5 Mon Sep 17 00:00:00 2001 From: Ruben Buniatyan Date: Wed, 9 Oct 2024 16:34:00 +0200 Subject: [PATCH 11/12] Add status checks for tools (#7577) --- .github/workflows/build-tools.yml | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/build-tools.yml diff --git a/.github/workflows/build-tools.yml b/.github/workflows/build-tools.yml new file mode 100644 index 00000000000..751f75f2d4f --- /dev/null +++ b/.github/workflows/build-tools.yml @@ -0,0 +1,33 @@ +name: Build tools + +on: + merge_group: + types: [checks_requested] + pull_request: + branches: [master] + push: + branches: [master] + +jobs: + build: + name: Build + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + config: [release] + project: + - docgen/DocGen.sln + - HiveCompare/HiveCompare.sln + - HiveConsensusWorkflowGenerator/HiveConsensusWorkflowGenerator.csproj + - Nethermind.Tools.Kute/Nethermind.Tools.Kute.csproj + - SendBlobs/SendBlobs.sln + - TxParser/TxParser.csproj + steps: + - name: Check out repository + uses: actions/checkout@v4 + - name: Set up .NET + uses: actions/setup-dotnet@v4 + - name: Build ${{ matrix.project }} + working-directory: tools + run: dotnet build ./${{ matrix.project }} -c ${{ matrix.config }} From 522debac470927cf4511ad9737229aef91afdadc Mon Sep 17 00:00:00 2001 From: Ruben Buniatyan Date: Wed, 9 Oct 2024 16:40:10 +0200 Subject: [PATCH 12/12] Revise configuration docs (#7576) --- src/Nethermind/Nethermind.Config/IBlocksConfig.cs | 4 ++-- .../CensorshipDetector/ICensorshipDetectorConfig.cs | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Nethermind/Nethermind.Config/IBlocksConfig.cs b/src/Nethermind/Nethermind.Config/IBlocksConfig.cs index f7a929174d6..72b5446a97d 100644 --- a/src/Nethermind/Nethermind.Config/IBlocksConfig.cs +++ b/src/Nethermind/Nethermind.Config/IBlocksConfig.cs @@ -37,10 +37,10 @@ public interface IBlocksConfig : IConfig [ConfigItem(Description = "Whether to pre-warm the state when processing blocks. This can lead to an up to 2x speed-up in the main loop block processing.", DefaultValue = "True")] bool PreWarmStateOnBlockProcessing { get; set; } - [ConfigItem(Description = "Block Production timeout, in milliseconds.", DefaultValue = "4000")] + [ConfigItem(Description = "The block production timeout, in milliseconds.", DefaultValue = "4000")] int BlockProductionTimeoutMs { get; set; } - [ConfigItem(Description = "Genesis block load timeout, in milliseconds.", DefaultValue = "40000")] + [ConfigItem(Description = "The genesis block load timeout, in milliseconds.", DefaultValue = "40000")] int GenesisTimeoutMs { get; set; } byte[] GetExtraDataBytes(); diff --git a/src/Nethermind/Nethermind.Consensus/Processing/CensorshipDetector/ICensorshipDetectorConfig.cs b/src/Nethermind/Nethermind.Consensus/Processing/CensorshipDetector/ICensorshipDetectorConfig.cs index 259636bb7ca..e71ffff02e1 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/CensorshipDetector/ICensorshipDetectorConfig.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/CensorshipDetector/ICensorshipDetectorConfig.cs @@ -7,15 +7,13 @@ namespace Nethermind.Consensus.Processing.CensorshipDetector; public interface ICensorshipDetectorConfig : IConfig { - [ConfigItem(DefaultValue = "false", - Description = "Enabling censorship detection feature")] + [ConfigItem(DefaultValue = "false", Description = "Whether to enable censorship detection.")] bool Enabled { get; set; } [ConfigItem(DefaultValue = "2", - Description = "Number of consecutive blocks with detected potential censorship to report censorship attempt")] + Description = "The number of the consecutive blocks with detected potential censorship to report.")] uint BlockCensorshipThreshold { get; set; } - [ConfigItem(DefaultValue = "null", - Description = "The addresses for which censorship is being detected.")] + [ConfigItem(DefaultValue = "null", Description = "The addresses to detect censorship for.")] string[]? AddressesForCensorshipDetection { get; set; } }