Skip to content

Commit db28953

Browse files
committed
refactor: Define fork reconciliation policy const in terms of consensus const
Const `MAX_BLOCK_SIZE_IN_FORK_RECONCILIATION` is enforced in the course of fork reconciliation. Previously it was set to 10 MB, now it is set to 2x 8 MB, where the 8 MB comes from the block size. Also: clarify purpose.
1 parent 3e5f736 commit db28953

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

neptune-core/src/application/loops/peer_loop.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,16 @@ const STANDARD_BLOCK_BATCH_SIZE: usize = 35;
6565
const MAX_PEER_LIST_LENGTH: usize = 10;
6666
const MINIMUM_BLOCK_BATCH_SIZE: usize = 2;
6767

68-
/// Maximum size in bytes for a single block during fork reconciliation.
69-
/// Blocks larger than this are rejected to prevent RAM exhaustion attacks.
70-
/// 10MB is generous - legitimate blocks with many transactions are typically 1-2MB.
71-
const MAX_BLOCK_SIZE_IN_FORK_RECONCILIATION: usize = 10 * 1024 * 1024;
68+
/// Maximum size in bytes for a single block during fork reconciliation. Blocks
69+
/// larger than this are rejected to prevent RAM exhaustion attacks.
70+
///
71+
/// This constant is defined for the peer to heuristically enforce a safe upper
72+
/// bound as a matter of policy, and does not have to determine which consensus
73+
/// rule set we are on to get an exact value. Note that this policy is only
74+
/// enforced during fork reconciliation -- in particular, it does not contribute
75+
/// to block (in)validity as defined in [`Block::validate`].
76+
const MAX_BLOCK_SIZE_IN_FORK_RECONCILIATION: usize =
77+
2 * 8 * ConsensusRuleSet::HardforkAlpha.max_block_size();
7278

7379
/// Maximum total bytes for all blocks in fork_reconciliation_blocks.
7480
/// This caps overall memory usage during fork resolution.

0 commit comments

Comments
 (0)