Skip to content

Commit 5b1fd04

Browse files
committed
refactor: Drop fork reconciliation memory limit
There is already a memory limit being enforced implicitly, namely through: 1. Requiring that every block have a size less than or equal to `MAX_BLOCK_SIZE_IN_FORK_RECONCILIATION`. 2. Requiring that the number of blocks being reconciled does not exceed `self.global_state_lock.cli().sync_mode_threshold`. This commit removes the memory limit in `try_ensure_path` as well as the state variable used to track memory use for fork reconciliation.
1 parent db28953 commit 5b1fd04

File tree

2 files changed

+0
-31
lines changed

2 files changed

+0
-31
lines changed

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

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ const MINIMUM_BLOCK_BATCH_SIZE: usize = 2;
7676
const MAX_BLOCK_SIZE_IN_FORK_RECONCILIATION: usize =
7777
2 * 8 * ConsensusRuleSet::HardforkAlpha.max_block_size();
7878

79-
/// Maximum total bytes for all blocks in fork_reconciliation_blocks.
80-
/// This caps overall memory usage during fork resolution.
81-
const MAX_FORK_RECONCILIATION_TOTAL_BYTES: usize = 100 * 1024 * 1024;
82-
8379
/// Maximum size of a single announcement, in BFieldElements. Typical encrypted
8480
/// UTXO notifications are ~400 BFEs. This limit provides headroom while
8581
/// preventing DoS via oversized announcements.
@@ -456,25 +452,6 @@ impl PeerLoopHandler {
456452
);
457453
self.punish(NegativePeerSanction::OversizedBlock).await?;
458454
peer_state.fork_reconciliation_blocks.clear();
459-
peer_state.fork_reconciliation_bytes = 0;
460-
return Ok(());
461-
}
462-
463-
// Reject if total memory budget would be exceeded
464-
let new_total_bytes = peer_state
465-
.fork_reconciliation_bytes
466-
.saturating_add(block_size);
467-
if new_total_bytes > MAX_FORK_RECONCILIATION_TOTAL_BYTES {
468-
warn!(
469-
"Fork reconciliation memory budget exceeded: {} + {} = {} bytes (max: {} bytes)",
470-
peer_state.fork_reconciliation_bytes,
471-
block_size,
472-
new_total_bytes,
473-
MAX_FORK_RECONCILIATION_TOTAL_BYTES
474-
);
475-
self.punish(NegativePeerSanction::OversizedBlock).await?;
476-
peer_state.fork_reconciliation_blocks.clear();
477-
peer_state.fork_reconciliation_bytes = 0;
478455
return Ok(());
479456
}
480457

@@ -519,13 +496,11 @@ impl PeerLoopHandler {
519496
)))
520497
.await?;
521498
peer_state.fork_reconciliation_blocks = vec![];
522-
peer_state.fork_reconciliation_bytes = 0;
523499
return Ok(());
524500
}
525501

526502
// otherwise, append
527503
peer_state.fork_reconciliation_blocks.push(*received_block);
528-
peer_state.fork_reconciliation_bytes = new_total_bytes;
529504

530505
// Try fetch parent
531506
let received_block_header = *peer_state
@@ -559,7 +534,6 @@ impl PeerLoopHandler {
559534
let Some(parent_block) = parent_block else {
560535
if parent_height.is_genesis() {
561536
peer_state.fork_reconciliation_blocks.clear();
562-
peer_state.fork_reconciliation_bytes = 0;
563537
self.punish(NegativePeerSanction::DifferentGenesis).await?;
564538
return Ok(());
565539
}
@@ -584,7 +558,6 @@ impl PeerLoopHandler {
584558
// block that we have.
585559
let fork_reconciliation_event = !peer_state.fork_reconciliation_blocks.is_empty();
586560
peer_state.fork_reconciliation_blocks.clear();
587-
peer_state.fork_reconciliation_bytes = 0;
588561

589562
if let Some(new_block_height) = self.handle_blocks(new_blocks, parent_block).await? {
590563
// If `BlockNotification` was received during a block reconciliation

neptune-core/src/protocol/peer.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -624,9 +624,6 @@ impl PeerMessage {
624624
pub struct MutablePeerState {
625625
pub highest_shared_block_height: BlockHeight,
626626
pub fork_reconciliation_blocks: Vec<Block>,
627-
/// Total estimated bytes of blocks in fork_reconciliation_blocks.
628-
/// Used to cap memory usage during fork resolution.
629-
pub(crate) fork_reconciliation_bytes: usize,
630627
pub(crate) sync_challenge: Option<IssuedSyncChallenge>,
631628

632629
/// Timestamp for the last successful sync challenge response.
@@ -640,7 +637,6 @@ impl MutablePeerState {
640637
Self {
641638
highest_shared_block_height: block_height,
642639
fork_reconciliation_blocks: vec![],
643-
fork_reconciliation_bytes: 0,
644640
sync_challenge: None,
645641
successful_sync_challenge_response_time: None,
646642
}

0 commit comments

Comments
 (0)