Skip to content

Commit 1010efd

Browse files
committed
fix(electrum): fixed chain sync issue
Fixed a logic error in `construct_update_tip` in `electrum_ext.rs` that caused the local chain tip to always be a block behind the newest confirmed block.
1 parent 0a7b60f commit 1010efd

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

crates/electrum/src/electrum_ext.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use std::{
1111
str::FromStr,
1212
};
1313

14-
/// We assume that a block of this depth and deeper cannot be reorged.
15-
const ASSUME_FINAL_DEPTH: u32 = 8;
14+
/// We include a chain suffix of a certain length for the purpose of robustness.
15+
const CHAIN_SUFFIX_LENGTH: u32 = 8;
1616

1717
/// Represents updates fetched from an Electrum server, but excludes full transactions.
1818
///
@@ -302,12 +302,12 @@ fn construct_update_tip(
302302
}
303303
}
304304

305-
// Atomically fetch the latest `ASSUME_FINAL_DEPTH` count of blocks from Electrum. We use this
305+
// Atomically fetch the latest `CHAIN_SUFFIX_LENGTH` count of blocks from Electrum. We use this
306306
// to construct our checkpoint update.
307307
let mut new_blocks = {
308-
let start_height = new_tip_height.saturating_sub(ASSUME_FINAL_DEPTH);
308+
let start_height = new_tip_height.saturating_sub(CHAIN_SUFFIX_LENGTH - 1);
309309
let hashes = client
310-
.block_headers(start_height as _, ASSUME_FINAL_DEPTH as _)?
310+
.block_headers(start_height as _, CHAIN_SUFFIX_LENGTH as _)?
311311
.headers
312312
.into_iter()
313313
.map(|h| h.block_hash());

0 commit comments

Comments
 (0)