Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/Nethermind/Nethermind.Core/Buffers/CappedArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,10 @@ public readonly Span<T> 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<T> AsArraySegment()
{
Expand Down
1 change: 1 addition & 0 deletions src/Nethermind/Nethermind.Logging.NLog/NLogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions src/Nethermind/Nethermind.Logging/StaticLoggerFactory.cs
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,26 @@ namespace Nethermind.Merge.Plugin.Data;
///
/// <seealso cref="https://github.com/ethereum/execution-apis/blob/main/src/engine/specification.md#forkchoicestatev1"/>
/// </summary>
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;
}

/// <summary>
/// Hash of the head of the canonical chain.
/// </summary>
public Hash256 HeadBlockHash { get; set; }
public Hash256 HeadBlockHash { get; set; } = headBlockHash;

/// <summary>
/// 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.
/// </summary>
/// <remarks>Can be <see cref="Keccak.Zero"/> when transition block is not finalized yet.</remarks>
public Hash256 SafeBlockHash { get; set; }
public Hash256 SafeBlockHash { get; set; } = safeBlockHash;

/// <summary>
/// Hash of the most recent finalized block
/// </summary>
/// <remarks>Can be <see cref="Keccak.Zero"/> when transition block is not finalized yet.</remarks>
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Nethermind.Network.P2P.Subprotocols.Eth.V63.Messages
{
public class ReceiptsMessageSerializer : IZeroInnerMessageSerializer<ReceiptsMessage>
{
private static readonly RlpLimit RlpLimit = RlpLimit.For<ReceiptsMessage>(NethermindSyncLimits.MaxReceiptFetch, nameof(ReceiptsMessage.TxReceipts));
private static readonly RlpLimit RlpLimit = RlpLimit.For<ReceiptsMessage>(NethermindSyncLimits.MaxReceiptFetch * 4, nameof(ReceiptsMessage.TxReceipts));
private readonly ISpecProvider _specProvider;
private readonly IRlpStreamDecoder<TxReceipt> _decoder;
private readonly Func<RlpStream, TxReceipt[]> _decodeArrayFunc;
Expand Down
4 changes: 3 additions & 1 deletion src/Nethermind/Nethermind.Runner/NLog.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true" throwExceptions="false">
autoReload="true"
throwExceptions="false"
flushAllBeforeShutdown="true">

<extensions>
<add assembly="NLog.Targets.Seq" />
Expand Down
11 changes: 9 additions & 2 deletions src/Nethermind/Nethermind.Serialization.Rlp/Rlp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Nethermind.Core.Crypto;
using Nethermind.Core.Extensions;
using Nethermind.Int256;
using Nethermind.Logging;

namespace Nethermind.Serialization.Rlp
{
Expand Down Expand Up @@ -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<Rlp>();

[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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down