-
Notifications
You must be signed in to change notification settings - Fork 666
Expand file tree
/
Copy pathSnapMessageLimits.cs
More file actions
30 lines (25 loc) · 1.91 KB
/
SnapMessageLimits.cs
File metadata and controls
30 lines (25 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// SPDX-FileCopyrightText: 2026 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only
using System;
using Nethermind.Network.P2P.Subprotocols.Snap.Messages;
using Nethermind.Serialization.Rlp;
using Nethermind.State.Snap;
namespace Nethermind.Network.P2P.Subprotocols.Snap;
internal static class SnapMessageLimits
{
public const int MaxRequestHashes = 4_096;
public const int MaxRequestAccounts = 4_096;
public const int MaxRequestPathGroups = 4_096;
public const int MaxRequestPathsPerGroup = 1_024;
public const int MaxResponseAccounts = 131_072;
public const int MaxResponseSlotsPerAccount = 131_072;
public const long MaxResponseBytes = 3_145_728; // 3 MiB
public static readonly RlpLimit GetByteCodesHashesRlpLimit = RlpLimit.For<GetByteCodesMessage>(MaxRequestHashes, nameof(GetByteCodesMessage.Hashes));
public static readonly RlpLimit GetStorageRangeAccountsRlpLimit = RlpLimit.For<GetStorageRangeMessage>(MaxRequestAccounts, nameof(GetStorageRangeMessage.StorageRange));
public static readonly RlpLimit GetTrieNodesPathGroupsRlpLimit = RlpLimit.For<GetTrieNodesMessage>(MaxRequestPathGroups, nameof(GetTrieNodesMessage.Paths));
public static readonly RlpLimit GetTrieNodesPathsPerGroupRlpLimit = RlpLimit.For<PathGroup>(MaxRequestPathsPerGroup, nameof(PathGroup.Group));
public static readonly RlpLimit AccountRangeEntriesRlpLimit = RlpLimit.For<AccountRangeMessage>(MaxResponseAccounts, nameof(AccountRangeMessage.PathsWithAccounts));
public static readonly RlpLimit StorageRangeAccountsRlpLimit = RlpLimit.For<StorageRangeMessage>(MaxRequestAccounts, nameof(StorageRangeMessage.Slots));
public static readonly RlpLimit StorageRangeSlotsPerAccountRlpLimit = RlpLimit.For<PathWithStorageSlot>(MaxResponseSlotsPerAccount, nameof(StorageRangeMessage.Slots));
public static long ClampResponseBytes(long requestedBytes) => Math.Clamp(requestedBytes, 1L, MaxResponseBytes);
}