From c2f907a36a160ddb0cd2256f390b69c545fd18d6 Mon Sep 17 00:00:00 2001 From: viraladmin <00purple@gmail.com> Date: Tue, 26 May 2026 17:33:03 -0600 Subject: [PATCH] fixed debugging --- src/orphans/add_genesis.rs | 14 +++++++++++--- src/orphans/save_blocks.rs | 2 ++ src/orphans/sync_check.rs | 1 + src/rpc/client/syncing.rs | 1 + src/rpc/commands/receive_torrent.rs | 9 +++++++++ src/torrent/torrenting_system/torrent_requests.rs | 9 ++++++--- 6 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/orphans/add_genesis.rs b/src/orphans/add_genesis.rs index 3bf1cfd..93ecc7a 100644 --- a/src/orphans/add_genesis.rs +++ b/src/orphans/add_genesis.rs @@ -38,9 +38,17 @@ pub async fn create_genesis_block( return; } }; - handle_response_and_save_torrent(0, &db, torrent, wallet_key, map.clone(), false) - .await - .ok(); + handle_response_and_save_torrent( + 0, + &db, + torrent, + wallet_key, + map.clone(), + false, + false, + ) + .await + .ok(); } } } diff --git a/src/orphans/save_blocks.rs b/src/orphans/save_blocks.rs index b755da0..65d58a4 100644 --- a/src/orphans/save_blocks.rs +++ b/src/orphans/save_blocks.rs @@ -73,6 +73,7 @@ pub async fn save_new_blocks( wallet_key, params.map.clone(), true, + true, ) .await { @@ -191,6 +192,7 @@ pub async fn save_new_blocks( wallet_key, params.map.clone(), true, + true, ) .await?; if get_height(¶ms.db) <= local_height_before { diff --git a/src/orphans/sync_check.rs b/src/orphans/sync_check.rs index 09500ae..3023ca9 100644 --- a/src/orphans/sync_check.rs +++ b/src/orphans/sync_check.rs @@ -117,6 +117,7 @@ async fn replay_staged_torrents(params: &OrphanCheckup2, wallet_key: &str) -> Re wallet_key, params.map.clone(), true, + true, ) .await { diff --git a/src/rpc/client/syncing.rs b/src/rpc/client/syncing.rs index 0f6af1d..060546b 100644 --- a/src/rpc/client/syncing.rs +++ b/src/rpc/client/syncing.rs @@ -79,6 +79,7 @@ pub async fn node_syncing( wallet_key, map.clone(), false, + false, ) .await { diff --git a/src/rpc/commands/receive_torrent.rs b/src/rpc/commands/receive_torrent.rs index 2cc11ba..6b8d652 100644 --- a/src/rpc/commands/receive_torrent.rs +++ b/src/rpc/commands/receive_torrent.rs @@ -132,6 +132,15 @@ pub async fn torrent_submission( let reorganizing = is_reorganizing_mode(); let process_now = !syncing && !reorganizing && height == expected_height; + if height < expected_height && !(height > 0 && within_orphan_window(local_height, height)) { + // Far-stale torrents cannot affect the orphan window. Ignore them + // before parsing or staging so syncing peers do not flood old + // metadata into local replay storage. + return TorrentSubmissionOutcome::Accepted(RpcResponse::Binary( + "Torrent ignored as stale.".as_bytes().to_vec(), + )); + } + // The sender receives an acknowledgement for staging even when the // torrent cannot be processed immediately. let staged_response = if syncing { diff --git a/src/torrent/torrenting_system/torrent_requests.rs b/src/torrent/torrenting_system/torrent_requests.rs index 76fb1d3..94eceb5 100644 --- a/src/torrent/torrenting_system/torrent_requests.rs +++ b/src/torrent/torrenting_system/torrent_requests.rs @@ -40,6 +40,7 @@ pub async fn handle_response_and_save_torrent( wallet_key: &str, map: Arc>, allow_during_reorg: bool, + rebroadcast: bool, ) -> Result<(), String> { let Some((torrent, staged_path)) = stage_and_verify_torrent(height, db, torrent, wallet_key, true).await? @@ -58,9 +59,11 @@ pub async fn handle_response_and_save_torrent( ) .await?; - // A requested torrent is only forwarded after this node has the - // complete validated block available for piece requests. - broadcast_new_torrent_to_peers(height, &torrent_bytes, map).await; + if rebroadcast { + // A requested torrent is only forwarded after this node has the + // complete validated block available for piece requests. + broadcast_new_torrent_to_peers(height, &torrent_bytes, map).await; + } Ok(()) }