Skip to content

Commit

Permalink
electrum: common ancestor is before first changed block
Browse files Browse the repository at this point in the history
  • Loading branch information
jp1ac4 committed Sep 8, 2024
1 parent 161299d commit 60e9ff4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/bitcoin/electrum/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ impl Electrum {
None
} else {
log::info!("Block chain reorganization detected.");
Some(self.bdk_wallet.find_block_at_or_before_height(height))
// We can assume height is positive as genesis block will not have changed.
Some(self.bdk_wallet.find_block_before_height(height))
};
}
Some((_, None)) => continue,
Expand Down
6 changes: 3 additions & 3 deletions src/bitcoin/electrum/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,10 @@ impl BdkWallet {
})
}

/// Find the first block in the local chain whose height is less than or equal to this.
pub fn find_block_at_or_before_height(&self, height: u32) -> BlockChainTip {
/// Find the highest block in the local chain whose height is below this.
pub fn find_block_before_height(&self, height: u32) -> BlockChainTip {
for cp in self.local_chain.iter_checkpoints() {
if cp.height() <= height {
if cp.height() < height {
return BlockChainTip {
height: height_i32_from_u32(cp.height()),
hash: cp.hash(),
Expand Down

0 comments on commit 60e9ff4

Please sign in to comment.