diff --git a/src/Nethermind/Nethermind.Core/Buffers/CappedArray.cs b/src/Nethermind/Nethermind.Core/Buffers/CappedArray.cs index 504129823990..8b93eb277542 100644 --- a/src/Nethermind/Nethermind.Core/Buffers/CappedArray.cs +++ b/src/Nethermind/Nethermind.Core/Buffers/CappedArray.cs @@ -113,12 +113,10 @@ public readonly Span AsSpan(int start, int length) return AsSpan().ToArray(); } - public override string? ToString() - { - return typeof(T) == typeof(byte) ? - SpanExtensions.ToHexString(MemoryMarshal.AsBytes(AsSpan()), withZeroX: true) : + public override string? ToString() => + typeof(T) == typeof(byte) ? + MemoryMarshal.AsBytes(AsSpan()).ToHexString(withZeroX: true) : base.ToString(); - } public readonly ArraySegment AsArraySegment() { diff --git a/src/Nethermind/Nethermind.Logging.NLog/NLogManager.cs b/src/Nethermind/Nethermind.Logging.NLog/NLogManager.cs index 830e25fd2ab3..4497f7cf0487 100644 --- a/src/Nethermind/Nethermind.Logging.NLog/NLogManager.cs +++ b/src/Nethermind/Nethermind.Logging.NLog/NLogManager.cs @@ -31,6 +31,7 @@ public NLogManager(string logFileName, string logDirectory = null, string logRul // Required since 'NLog.config' could change during runtime, we need to re-apply the configuration _logManagerOnConfigurationChanged = (sender, args) => Setup(logFileName, logDirectory, logRules); LogManager.ConfigurationChanged += _logManagerOnConfigurationChanged; + Static.LogManager = this; } private static void Setup(string logFileName, string logDirectory = null, string logRules = null) diff --git a/src/Nethermind/Nethermind.Logging/StaticLoggerFactory.cs b/src/Nethermind/Nethermind.Logging/StaticLoggerFactory.cs new file mode 100644 index 000000000000..c38d81648b9b --- /dev/null +++ b/src/Nethermind/Nethermind.Logging/StaticLoggerFactory.cs @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: 2025 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using System; + +namespace Nethermind.Logging; + +public static class Static +{ + public static ILogManager LogManager { get; set; } = LimboLogs.Instance; +} diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V1.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V1.cs index 8ee688de990a..3396aa0844d6 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V1.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V1.cs @@ -140,7 +140,7 @@ public async Task can_parse_forkchoiceUpdated_with_implicit_null_payloadAttribut public void ForkchoiceV1_ToString_returns_correct_results() { ForkchoiceStateV1 forkchoiceState = new(TestItem.KeccakA, TestItem.KeccakF, TestItem.KeccakC); - forkchoiceState.ToString().Should().Be("ForkChoice: 0x03783f...35b760, Safe: 0x017e66...b18f72, Finalized: 0xe61d9a...97c37a"); + forkchoiceState.ToString().Should().Be("ForkChoice: 0x03783fac2efed8fbc9ad443e592ee30e61d65f471140c10ca155e937b435b760, Safe: 0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72, Finalized: 0xe61d9a3d3848fb2cdd9a2ab61e2f21a10ea431275aed628a0557f9dee697c37a"); } [Test] diff --git a/src/Nethermind/Nethermind.Merge.Plugin/Data/ForkchoiceStateV1.cs b/src/Nethermind/Nethermind.Merge.Plugin/Data/ForkchoiceStateV1.cs index 546e2fe4df9d..1eb47a3018ff 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/Data/ForkchoiceStateV1.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/Data/ForkchoiceStateV1.cs @@ -10,33 +10,26 @@ namespace Nethermind.Merge.Plugin.Data; /// /// /// -public class ForkchoiceStateV1 +public class ForkchoiceStateV1(Hash256 headBlockHash, Hash256 finalizedBlockHash, Hash256 safeBlockHash) { - public ForkchoiceStateV1(Hash256 headBlockHash, Hash256 finalizedBlockHash, Hash256 safeBlockHash) - { - HeadBlockHash = headBlockHash; - FinalizedBlockHash = finalizedBlockHash; - SafeBlockHash = safeBlockHash; - } - /// /// Hash of the head of the canonical chain. /// - public Hash256 HeadBlockHash { get; set; } + public Hash256 HeadBlockHash { get; set; } = headBlockHash; /// /// Safe block hash of the canonical chain under certain synchrony and honesty assumptions. This value MUST be either equal to or an ancestor of headBlockHash. /// /// Can be when transition block is not finalized yet. - public Hash256 SafeBlockHash { get; set; } + public Hash256 SafeBlockHash { get; set; } = safeBlockHash; /// /// Hash of the most recent finalized block /// /// Can be when transition block is not finalized yet. - public Hash256 FinalizedBlockHash { get; set; } + public Hash256 FinalizedBlockHash { get; set; } = finalizedBlockHash; - public override string ToString() => $"ForkChoice: {HeadBlockHash.ToShortString()}, Safe: {SafeBlockHash.ToShortString()}, Finalized: {FinalizedBlockHash.ToShortString()}"; + public override string ToString() => $"ForkChoice: {HeadBlockHash}, Safe: {SafeBlockHash}, Finalized: {FinalizedBlockHash}"; public string ToString(long? headNumber, long? safeNumber, long? finalizedNumber) => headNumber is null || safeNumber is null || finalizedNumber is null ? ToString() diff --git a/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V63/Messages/ReceiptsMessageSerializer.cs b/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V63/Messages/ReceiptsMessageSerializer.cs index c5e4047623c1..e59dceb9c214 100644 --- a/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V63/Messages/ReceiptsMessageSerializer.cs +++ b/src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/V63/Messages/ReceiptsMessageSerializer.cs @@ -14,7 +14,7 @@ namespace Nethermind.Network.P2P.Subprotocols.Eth.V63.Messages { public class ReceiptsMessageSerializer : IZeroInnerMessageSerializer { - private static readonly RlpLimit RlpLimit = RlpLimit.For(NethermindSyncLimits.MaxReceiptFetch, nameof(ReceiptsMessage.TxReceipts)); + private static readonly RlpLimit RlpLimit = RlpLimit.For(NethermindSyncLimits.MaxReceiptFetch * 4, nameof(ReceiptsMessage.TxReceipts)); private readonly ISpecProvider _specProvider; private readonly IRlpStreamDecoder _decoder; private readonly Func _decodeArrayFunc; diff --git a/src/Nethermind/Nethermind.Runner/NLog.config b/src/Nethermind/Nethermind.Runner/NLog.config index 308420fbc7c8..1dd703dcb039 100644 --- a/src/Nethermind/Nethermind.Runner/NLog.config +++ b/src/Nethermind/Nethermind.Runner/NLog.config @@ -2,7 +2,9 @@ + autoReload="true" + throwExceptions="false" + flushAllBeforeShutdown="true"> diff --git a/src/Nethermind/Nethermind.Serialization.Rlp/Rlp.cs b/src/Nethermind/Nethermind.Serialization.Rlp/Rlp.cs index bbcb2566b88b..5f796e5db26d 100644 --- a/src/Nethermind/Nethermind.Serialization.Rlp/Rlp.cs +++ b/src/Nethermind/Nethermind.Serialization.Rlp/Rlp.cs @@ -18,6 +18,7 @@ using Nethermind.Core.Crypto; using Nethermind.Core.Extensions; using Nethermind.Int256; +using Nethermind.Logging; namespace Nethermind.Serialization.Rlp { @@ -1836,21 +1837,27 @@ public sealed class DecoderAttribute(string key = RlpDecoderKey.Default) : Attri public string Key { get; } = key; } + private static ILogger _logger = Static.LogManager.GetClassLogger(); + [StackTraceHidden] public static void GuardLimit(int count, int bytesLeft, RlpLimit? limit = null) { RlpLimit l = limit ?? RlpLimit.DefaultLimit; if (count > bytesLeft || count > l.Limit) + { ThrowCountOverLimit(count, bytesLeft, l); + } } [DoesNotReturn] [StackTraceHidden] private static void ThrowCountOverLimit(int count, int bytesLeft, RlpLimit limit) { - throw new RlpLimitException(string.IsNullOrEmpty(limit.CollectionExpression) + string message = string.IsNullOrEmpty(limit.CollectionExpression) ? $"Collection count of {count} is over limit {limit.Limit} or {bytesLeft} bytes left" - : $"Collection count {limit.CollectionExpression} of {count} is over limit {limit.Limit} or {bytesLeft} bytes left"); + : $"Collection count {limit.CollectionExpression} of {count} is over limit {limit.Limit} or {bytesLeft} bytes left"; + if (_logger.IsDebug) _logger.Error($"DEBUG/ERROR: {message}; {new StackTrace()}"); + throw new RlpLimitException(message); } } diff --git a/src/Nethermind/Nethermind.Synchronization/SnapSync/ProgressTracker.cs b/src/Nethermind/Nethermind.Synchronization/SnapSync/ProgressTracker.cs index e3f4715ced9d..5e681453fd2a 100644 --- a/src/Nethermind/Nethermind.Synchronization/SnapSync/ProgressTracker.cs +++ b/src/Nethermind/Nethermind.Synchronization/SnapSync/ProgressTracker.cs @@ -407,6 +407,7 @@ public void EnqueueNextSlot(StorageRange parentRequest, int accountIndex, ValueH public void RetryStorageRange(StorageRange storageRange) { + bool dispose = false; if (storageRange.Accounts.Count == 1) { EnqueueNextSlot(storageRange); @@ -417,9 +418,12 @@ public void RetryStorageRange(StorageRange storageRange) { EnqueueAccountStorage(account); } + + dispose = true; } Interlocked.Add(ref _activeStorageRequests, -(storageRange?.Accounts.Count ?? 0)); + if (dispose) storageRange.Dispose(); } public void ReportAccountRangePartitionFinished(in ValueHash256 hashLimit)