From ba123df0ff9a7fbae8c22645f003c8f474845dd0 Mon Sep 17 00:00:00 2001 From: ardocrat Date: Thu, 14 May 2026 16:01:39 +0300 Subject: [PATCH 1/3] fix: include last height into batch on scan --- libwallet/src/api_impl/owner.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libwallet/src/api_impl/owner.rs b/libwallet/src/api_impl/owner.rs index f77ecb2..a9db1b0 100644 --- a/libwallet/src/api_impl/owner.rs +++ b/libwallet/src/api_impl/owner.rs @@ -979,7 +979,7 @@ where // Scan every 10k heights to save data between batches in case of interruption. let mut total_pmmr_range = None; - for h in (start_height..tip.0).step_by(10001) { + for h in (start_height..=tip.0).step_by(10001) { let (mut info, range) = scan::scan( wallet_inst.clone(), keychain_mask, @@ -1142,7 +1142,7 @@ where // Scan every 10k heights to save data between batches in case of interruption. let mut total_pmmr_range = None; - for h in (start_height..tip.0).step_by(10001) { + for h in (start_height..=tip.0).step_by(10001) { let (mut info, range) = scan::scan( wallet_inst.clone(), keychain_mask, From a1646fa6ea53842df538b000a565339e96c3d1de Mon Sep 17 00:00:00 2001 From: ardocrat Date: Thu, 14 May 2026 21:20:46 +0300 Subject: [PATCH 2/3] scan: save hash of last block --- libwallet/src/api_impl/owner.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/libwallet/src/api_impl/owner.rs b/libwallet/src/api_impl/owner.rs index a9db1b0..4cc0193 100644 --- a/libwallet/src/api_impl/owner.rs +++ b/libwallet/src/api_impl/owner.rs @@ -979,19 +979,24 @@ where // Scan every 10k heights to save data between batches in case of interruption. let mut total_pmmr_range = None; - for h in (start_height..=tip.0).step_by(10001) { + for h in (start_height..tip.0).step_by(10001) { + let batch_end_height = cmp::min(tip.0, h + 10000); let (mut info, range) = scan::scan( wallet_inst.clone(), keychain_mask, delete_unconfirmed, h, - cmp::min(tip.0, h + 10000), + batch_end_height, start_height, tip.0, total_pmmr_range, status_send_channel, )?; - info.hash = tip.1.clone(); + info.hash = if batch_end_height == tip.0 { + tip.1.clone() + } else { + "".to_owned() + }; total_pmmr_range = Some(range); wallet_lock!(wallet_inst, w); @@ -1142,19 +1147,24 @@ where // Scan every 10k heights to save data between batches in case of interruption. let mut total_pmmr_range = None; - for h in (start_height..=tip.0).step_by(10001) { + for h in (start_height..tip.0).step_by(10001) { + let batch_end_height = cmp::min(tip.0, h + 10000); let (mut info, range) = scan::scan( wallet_inst.clone(), keychain_mask, false, h, - cmp::min(tip.0, h + 10000), + batch_end_height, start_height, tip.0, total_pmmr_range, status_send_channel, )?; - info.hash = tip.1.clone(); + info.hash = if batch_end_height == tip.0 { + tip.1.clone() + } else { + "".to_owned() + }; total_pmmr_range = Some(range); wallet_lock!(wallet_inst, w); From 643670072c94107d66c4d6e012fbf909ae2622fb Mon Sep 17 00:00:00 2001 From: ardocrat Date: Thu, 14 May 2026 21:28:47 +0300 Subject: [PATCH 3/3] scan: add larger window (2880 blocks) to scan outputs when updating wallet state --- libwallet/src/api_impl/owner.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libwallet/src/api_impl/owner.rs b/libwallet/src/api_impl/owner.rs index 4cc0193..9ff8e0f 100644 --- a/libwallet/src/api_impl/owner.rs +++ b/libwallet/src/api_impl/owner.rs @@ -1043,6 +1043,9 @@ where } } +/// Wallet scan window in blocks (48 hours). +pub const REORG_RESCAN_WINDOW: u64 = 24 * 60 * 2; + /// Experimental, wrap the entire definition of how a wallet's state is updated pub fn update_wallet_state<'a, L, C, K>( wallet_inst: Arc>>>, @@ -1131,7 +1134,9 @@ where } }; - let start_height = last_scanned_block.height.saturating_sub(100); + let start_height = last_scanned_block + .height + .saturating_sub(REORG_RESCAN_WINDOW); debug!( "update_wallet_state: last_scanned_block: {:?}",