Skip to content

Commit f5c926a

Browse files
Helper for confirmed_funding_spend_past_anti_reorg
DRYs code in an upcoming commit.
1 parent dcea175 commit f5c926a

1 file changed

Lines changed: 19 additions & 13 deletions

File tree

lightning/src/chain/channelmonitor.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3371,19 +3371,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
33713371
// We only want HTLCs with ANTI_REORG_DELAY confirmations, which implies the commitment
33723372
// transaction has least ANTI_REORG_DELAY confirmations for any dependent HTLC transactions
33733373
// to have been confirmed.
3374-
let confirmed_txid = us.funding_spend_confirmed.or_else(|| {
3375-
us.onchain_events_awaiting_threshold_conf.iter().find_map(|event| {
3376-
if let OnchainEvent::FundingSpendConfirmation { .. } = event.event {
3377-
if event.height + ANTI_REORG_DELAY - 1 <= us.best_block.height {
3378-
Some(event.txid)
3379-
} else {
3380-
None
3381-
}
3382-
} else {
3383-
None
3384-
}
3385-
})
3386-
});
3374+
let confirmed_txid = us.confirmed_funding_spend_past_anti_reorg();
33873375

33883376
let confirmed_txid = if let Some(txid) = confirmed_txid {
33893377
txid
@@ -6774,6 +6762,24 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
67746762
fn channel_type_features(&self) -> &ChannelTypeFeatures {
67756763
&self.funding.channel_parameters.channel_type_features
67766764
}
6765+
6766+
/// Returns the txid of the confirmed funding spend if it has reached `ANTI_REORG_DELAY`
6767+
/// confirmations.
6768+
fn confirmed_funding_spend_past_anti_reorg(&self) -> Option<Txid> {
6769+
self.funding_spend_confirmed.or_else(|| {
6770+
self.onchain_events_awaiting_threshold_conf.iter().find_map(|event| {
6771+
if let OnchainEvent::FundingSpendConfirmation { .. } = event.event {
6772+
if event.height + ANTI_REORG_DELAY - 1 <= self.best_block.height {
6773+
Some(event.txid)
6774+
} else {
6775+
None
6776+
}
6777+
} else {
6778+
None
6779+
}
6780+
})
6781+
})
6782+
}
67776783
}
67786784

67796785
impl<Signer: EcdsaChannelSigner, T: BroadcasterInterface, F: FeeEstimator, L: Logger> chain::Listen

0 commit comments

Comments
 (0)