Skip to content

Commit 886c7f1

Browse files
committed
Check unconfirmation of pending funding transactions
When a splice funding transaction is unconfirmed, update the corresponding FundingScope just as is done when the initial funding transaction is unconfirmed.
1 parent 90966a9 commit 886c7f1

File tree

2 files changed

+57
-29
lines changed

2 files changed

+57
-29
lines changed

lightning/src/ln/channel.rs

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,7 +1931,6 @@ impl FundingScope {
19311931
self.channel_transaction_parameters.funding_outpoint
19321932
}
19331933

1934-
#[cfg(splicing)]
19351934
fn get_funding_txid(&self) -> Option<Txid> {
19361935
self.channel_transaction_parameters.funding_outpoint.map(|txo| txo.txid)
19371936
}
@@ -8984,7 +8983,7 @@ impl<SP: Deref> FundedChannel<SP> where
89848983

89858984
#[cfg(splicing)]
89868985
if let Some(confirmed_funding_index) = confirmed_funding_index {
8987-
let pending_splice = match self.pending_splice.as_ref() {
8986+
let pending_splice = match self.pending_splice.as_mut() {
89888987
Some(pending_splice) => pending_splice,
89898988
None => {
89908989
// TODO: Move pending_funding into pending_splice
@@ -8993,8 +8992,26 @@ impl<SP: Deref> FundedChannel<SP> where
89938992
return Err(ClosureReason::ProcessingError { err });
89948993
},
89958994
};
8996-
let funding = self.pending_funding.get(confirmed_funding_index).unwrap();
8995+
let funding = self.pending_funding.get_mut(confirmed_funding_index).unwrap();
89978996

8997+
// Check if the splice funding transaction was unconfirmed
8998+
if funding.get_funding_tx_confirmations(height) == 0 {
8999+
funding.funding_tx_confirmation_height = 0;
9000+
if let Some(sent_funding_txid) = pending_splice.sent_funding_txid {
9001+
if Some(sent_funding_txid) == funding.get_funding_txid() {
9002+
log_warn!(
9003+
logger,
9004+
"Unconfirming sent splice_locked txid {} for channel {}",
9005+
sent_funding_txid,
9006+
&self.context.channel_id,
9007+
);
9008+
pending_splice.sent_funding_txid = None;
9009+
}
9010+
}
9011+
}
9012+
9013+
let pending_splice = self.pending_splice.as_ref().unwrap();
9014+
let funding = self.pending_funding.get(confirmed_funding_index).unwrap();
89989015
if let Some(splice_locked) = self.check_get_splice_locked(pending_splice, funding, height) {
89999016
log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
90009017

@@ -9017,30 +9034,44 @@ impl<SP: Deref> FundedChannel<SP> where
90179034
Ok((None, timed_out_htlcs, announcement_sigs))
90189035
}
90199036

9020-
/// Indicates the funding transaction is no longer confirmed in the main chain. This may
9037+
/// Checks if any funding transaction is no longer confirmed in the main chain. This may
90219038
/// force-close the channel, but may also indicate a harmless reorganization of a block or two
9022-
/// before the channel has reached channel_ready and we can just wait for more blocks.
9023-
pub fn funding_transaction_unconfirmed<L: Deref>(&mut self, logger: &L) -> Result<(), ClosureReason> where L::Target: Logger {
9024-
if self.funding.funding_tx_confirmation_height != 0 {
9025-
// We handle the funding disconnection by calling best_block_updated with a height one
9026-
// below where our funding was connected, implying a reorg back to conf_height - 1.
9027-
let reorg_height = self.funding.funding_tx_confirmation_height - 1;
9028-
// We use the time field to bump the current time we set on channel updates if its
9029-
// larger. If we don't know that time has moved forward, we can just set it to the last
9030-
// time we saw and it will be ignored.
9031-
let best_time = self.context.update_time_counter;
9032-
9033-
match self.do_best_block_updated(reorg_height, best_time, None::<(ChainHash, &&dyn NodeSigner, &UserConfig)>, logger) {
9034-
Ok((channel_ready, timed_out_htlcs, announcement_sigs)) => {
9035-
assert!(channel_ready.is_none(), "We can't generate a funding with 0 confirmations?");
9036-
assert!(timed_out_htlcs.is_empty(), "We can't have accepted HTLCs with a timeout before our funding confirmation?");
9037-
assert!(announcement_sigs.is_none(), "We can't generate an announcement_sigs with 0 confirmations?");
9038-
Ok(())
9039-
},
9040-
Err(e) => Err(e)
9039+
/// before the channel has reached channel_ready or splice_locked, and we can just wait for more
9040+
/// blocks.
9041+
pub fn transaction_unconfirmed<L: Deref>(
9042+
&mut self, txid: &Txid, logger: &L,
9043+
) -> Result<(), ClosureReason>
9044+
where
9045+
L::Target: Logger,
9046+
{
9047+
let unconfirmed_funding = core::iter::once(&mut self.funding)
9048+
.chain(self.pending_funding.iter_mut())
9049+
.find(|funding| funding.get_funding_txid() == Some(*txid));
9050+
9051+
if let Some(funding) = unconfirmed_funding {
9052+
if funding.funding_tx_confirmation_height != 0 {
9053+
// We handle the funding disconnection by calling best_block_updated with a height one
9054+
// below where our funding was connected, implying a reorg back to conf_height - 1.
9055+
let reorg_height = funding.funding_tx_confirmation_height - 1;
9056+
// We use the time field to bump the current time we set on channel updates if its
9057+
// larger. If we don't know that time has moved forward, we can just set it to the last
9058+
// time we saw and it will be ignored.
9059+
let best_time = self.context.update_time_counter;
9060+
9061+
match self.do_best_block_updated(reorg_height, best_time, None::<(ChainHash, &&dyn NodeSigner, &UserConfig)>, logger) {
9062+
Ok((channel_ready, timed_out_htlcs, announcement_sigs)) => {
9063+
assert!(channel_ready.is_none(), "We can't generate a funding with 0 confirmations?");
9064+
assert!(timed_out_htlcs.is_empty(), "We can't have accepted HTLCs with a timeout before our funding confirmation?");
9065+
assert!(announcement_sigs.is_none(), "We can't generate an announcement_sigs with 0 confirmations?");
9066+
Ok(())
9067+
},
9068+
Err(e) => Err(e),
9069+
}
9070+
} else {
9071+
// We never learned about the funding confirmation anyway, just ignore
9072+
Ok(())
90419073
}
90429074
} else {
9043-
// We never learned about the funding confirmation anyway, just ignore
90449075
Ok(())
90459076
}
90469077
}

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11957,11 +11957,8 @@ where
1195711957
PersistenceNotifierGuard::optionally_notify_skipping_background_events(
1195811958
self, || -> NotifyOption { NotifyOption::DoPersist });
1195911959
self.do_chain_event(None, |channel| {
11960-
if let Some(funding_txo) = channel.funding.get_funding_txo() {
11961-
if funding_txo.txid == *txid {
11962-
channel.funding_transaction_unconfirmed(&&WithChannelContext::from(&self.logger, &channel.context, None)).map(|()| (None, Vec::new(), None))
11963-
} else { Ok((None, Vec::new(), None)) }
11964-
} else { Ok((None, Vec::new(), None)) }
11960+
let logger = WithChannelContext::from(&self.logger, &channel.context, None);
11961+
channel.transaction_unconfirmed(txid, &&logger).map(|()| (None, Vec::new(), None))
1196511962
});
1196611963
}
1196711964
}

0 commit comments

Comments
 (0)