Skip to content

Commit 0fdbe9d

Browse files
evanlinjinLagginTimes
authored andcommitted
fix(electrum): Return error on incorrect network
1 parent 2b56f1a commit 0fdbe9d

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

crates/electrum/src/bdk_electrum_client.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -647,25 +647,19 @@ fn fetch_tip_and_latest_blocks(
647647
}
648648
}
649649
agreement_cp
650+
.ok_or_else(|| Error::Message("cannot find agreement block with server".to_string()))?
650651
};
651652

652-
let agreement_height = agreement_cp.as_ref().map(CheckPoint::height);
653-
654-
let new_tip = new_blocks
653+
let extension = new_blocks
655654
.iter()
656-
// Prune `new_blocks` to only include blocks that are actually new.
657-
.filter(|(height, _)| Some(*<&u32>::clone(height)) > agreement_height)
658-
.map(|(height, hash)| BlockId {
659-
height: *height,
660-
hash: *hash,
661-
})
662-
.fold(agreement_cp, |prev_cp, block| {
663-
Some(match prev_cp {
664-
Some(cp) => cp.push(block).ok()?,
665-
None => CheckPoint::new(block),
666-
})
655+
.filter({
656+
let agreement_height = agreement_cp.height();
657+
move |(height, _)| **height > agreement_height
667658
})
668-
.ok_or_else(|| Error::Message("failed to construct new checkpoint tip".to_string()))?;
659+
.map(|(&height, &hash)| BlockId { height, hash });
660+
let new_tip = agreement_cp
661+
.extend(extension)
662+
.expect("extension heights already checked to be greater than agreement height");
669663

670664
Ok((new_tip, new_blocks))
671665
}

0 commit comments

Comments
 (0)