Skip to content

Commit 5be081a

Browse files
committed
fix(cbf): call best_block_updated per matched block instead of once at tip
Pairs each transactions_confirmed call with an immediate best_block_updated for the same height so LDK processes per-block state transitions (claimable balances, Filter script registrations) correctly.
1 parent 9291422 commit 5be081a

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/chain/cbf.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,12 @@ impl CbfChainSource {
867867
// The compact block filter already matched our scripts (covering both
868868
// created outputs and spent inputs), so we confirm every transaction
869869
// from matched blocks and let LDK determine relevance.
870+
//
871+
// Each block's `transactions_confirmed` is immediately followed by
872+
// `best_block_updated` for the same height, so LDK processes
873+
// per-block state transitions (claimable balances, Filter script
874+
// registrations) correctly instead of collapsing them into a single
875+
// update at the tip.
870876
let per_request_timeout =
871877
Duration::from_secs(self.sync_config.timeouts_config.per_request_timeout_secs.into());
872878
for (height, block_hash) in &matched {
@@ -881,7 +887,9 @@ impl CbfChainSource {
881887
.await?;
882888
}
883889

884-
// Update the best block tip.
890+
// Advance to the chain tip. For blocks between the last matched
891+
// block and the tip this is the only `best_block_updated` call,
892+
// which is sufficient since those blocks contain no relevant txs.
885893
let tip = sync_update.tip();
886894
if let Some(tip_header) = sync_update.recent_history().get(&tip.height) {
887895
for confirmable in &confirmables {
@@ -1299,10 +1307,11 @@ async fn confirm_block_transactions(
12991307
let block = &indexed_block.block;
13001308
let header = &block.header;
13011309
let txdata: Vec<(usize, &Transaction)> = block.txdata.iter().enumerate().collect();
1302-
if !txdata.is_empty() {
1303-
for confirmable in confirmables {
1310+
for confirmable in confirmables {
1311+
if !txdata.is_empty() {
13041312
confirmable.transactions_confirmed(header, &txdata, height);
13051313
}
1314+
confirmable.best_block_updated(header, height);
13061315
}
13071316
Ok(())
13081317
}

0 commit comments

Comments
 (0)