electrum: common ancestor is before first changed block
This commit is contained in:
parent
51fef98b55
commit
86965c188e
@ -212,7 +212,12 @@ 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)
|
||||
.expect("height of first change is greater than 0"),
|
||||
)
|
||||
};
|
||||
}
|
||||
Some((_, None)) => continue,
|
||||
|
||||
@ -295,17 +295,20 @@ 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 `height`.
|
||||
///
|
||||
/// As the local chain will always contain the genesis block, this returns
|
||||
/// `None` only if `height` is 0.
|
||||
pub fn find_block_before_height(&self, height: u32) -> Option<BlockChainTip> {
|
||||
for cp in self.local_chain.iter_checkpoints() {
|
||||
if cp.height() <= height {
|
||||
return BlockChainTip {
|
||||
if cp.height() < height {
|
||||
return Some(BlockChainTip {
|
||||
height: height_i32_from_u32(cp.height()),
|
||||
hash: cp.hash(),
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
unreachable!("There must be at least the genesis block.")
|
||||
None
|
||||
}
|
||||
|
||||
/// Apply an update to the local chain.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user