Skip to content

Commit a90ccb6

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 a49e299 commit a90ccb6

File tree

2 files changed

+58
-37
lines changed

2 files changed

+58
-37
lines changed

lightning/src/ln/channel.rs

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,7 +2074,6 @@ impl FundingScope {
20742074
self.channel_transaction_parameters.funding_outpoint
20752075
}
20762076

2077-
#[cfg(splicing)]
20782077
fn get_funding_txid(&self) -> Option<Txid> {
20792078
self.channel_transaction_parameters.funding_outpoint.map(|txo| txo.txid)
20802079
}
@@ -9315,7 +9314,7 @@ where
93159314

93169315
#[cfg(splicing)]
93179316
if let Some(confirmed_funding_index) = confirmed_funding_index {
9318-
let pending_splice = match self.pending_splice.as_ref() {
9317+
let pending_splice = match self.pending_splice.as_mut() {
93199318
Some(pending_splice) => pending_splice,
93209319
None => {
93219320
// TODO: Move pending_funding into pending_splice
@@ -9324,8 +9323,26 @@ where
93249323
return Err(ClosureReason::ProcessingError { err });
93259324
},
93269325
};
9327-
let funding = self.pending_funding.get(confirmed_funding_index).unwrap();
9326+
let funding = self.pending_funding.get_mut(confirmed_funding_index).unwrap();
9327+
9328+
// Check if the splice funding transaction was unconfirmed
9329+
if funding.get_funding_tx_confirmations(height) == 0 {
9330+
funding.funding_tx_confirmation_height = 0;
9331+
if let Some(sent_funding_txid) = pending_splice.sent_funding_txid {
9332+
if Some(sent_funding_txid) == funding.get_funding_txid() {
9333+
log_warn!(
9334+
logger,
9335+
"Unconfirming sent splice_locked txid {} for channel {}",
9336+
sent_funding_txid,
9337+
&self.context.channel_id,
9338+
);
9339+
pending_splice.sent_funding_txid = None;
9340+
}
9341+
}
9342+
}
93289343

9344+
let pending_splice = self.pending_splice.as_ref().unwrap();
9345+
let funding = self.pending_funding.get(confirmed_funding_index).unwrap();
93299346
if let Some(splice_locked) = self.check_get_splice_locked(pending_splice, funding, height) {
93309347
log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
93319348

@@ -9348,31 +9365,45 @@ where
93489365
Ok((None, timed_out_htlcs, announcement_sigs))
93499366
}
93509367

9351-
/// Indicates the funding transaction is no longer confirmed in the main chain. This may
9368+
/// Checks if any funding transaction is no longer confirmed in the main chain. This may
93529369
/// force-close the channel, but may also indicate a harmless reorganization of a block or two
9353-
/// before the channel has reached channel_ready and we can just wait for more blocks.
9354-
#[rustfmt::skip]
9355-
pub fn funding_transaction_unconfirmed<L: Deref>(&mut self, logger: &L) -> Result<(), ClosureReason> where L::Target: Logger {
9356-
if self.funding.funding_tx_confirmation_height != 0 {
9357-
// We handle the funding disconnection by calling best_block_updated with a height one
9358-
// below where our funding was connected, implying a reorg back to conf_height - 1.
9359-
let reorg_height = self.funding.funding_tx_confirmation_height - 1;
9360-
// We use the time field to bump the current time we set on channel updates if its
9361-
// larger. If we don't know that time has moved forward, we can just set it to the last
9362-
// time we saw and it will be ignored.
9363-
let best_time = self.context.update_time_counter;
9364-
9365-
match self.do_best_block_updated(reorg_height, best_time, None::<(ChainHash, &&dyn NodeSigner, &UserConfig)>, logger) {
9366-
Ok((channel_ready, timed_out_htlcs, announcement_sigs)) => {
9367-
assert!(channel_ready.is_none(), "We can't generate a funding with 0 confirmations?");
9368-
assert!(timed_out_htlcs.is_empty(), "We can't have accepted HTLCs with a timeout before our funding confirmation?");
9369-
assert!(announcement_sigs.is_none(), "We can't generate an announcement_sigs with 0 confirmations?");
9370-
Ok(())
9371-
},
9372-
Err(e) => Err(e)
9370+
/// before the channel has reached channel_ready or splice_locked, and we can just wait for more
9371+
/// blocks.
9372+
#[rustfmt::skip]
9373+
pub fn transaction_unconfirmed<L: Deref>(
9374+
&mut self, txid: &Txid, logger: &L,
9375+
) -> Result<(), ClosureReason>
9376+
where
9377+
L::Target: Logger,
9378+
{
9379+
let unconfirmed_funding = core::iter::once(&mut self.funding)
9380+
.chain(self.pending_funding.iter_mut())
9381+
.find(|funding| funding.get_funding_txid() == Some(*txid));
9382+
9383+
if let Some(funding) = unconfirmed_funding {
9384+
if funding.funding_tx_confirmation_height != 0 {
9385+
// We handle the funding disconnection by calling best_block_updated with a height one
9386+
// below where our funding was connected, implying a reorg back to conf_height - 1.
9387+
let reorg_height = funding.funding_tx_confirmation_height - 1;
9388+
// We use the time field to bump the current time we set on channel updates if its
9389+
// larger. If we don't know that time has moved forward, we can just set it to the last
9390+
// time we saw and it will be ignored.
9391+
let best_time = self.context.update_time_counter;
9392+
9393+
match self.do_best_block_updated(reorg_height, best_time, None::<(ChainHash, &&dyn NodeSigner, &UserConfig)>, logger) {
9394+
Ok((channel_ready, timed_out_htlcs, announcement_sigs)) => {
9395+
assert!(channel_ready.is_none(), "We can't generate a funding with 0 confirmations?");
9396+
assert!(timed_out_htlcs.is_empty(), "We can't have accepted HTLCs with a timeout before our funding confirmation?");
9397+
assert!(announcement_sigs.is_none(), "We can't generate an announcement_sigs with 0 confirmations?");
9398+
Ok(())
9399+
},
9400+
Err(e) => Err(e),
9401+
}
9402+
} else {
9403+
// We never learned about the funding confirmation anyway, just ignore
9404+
Ok(())
93739405
}
93749406
} else {
9375-
// We never learned about the funding confirmation anyway, just ignore
93769407
Ok(())
93779408
}
93789409
}

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12115,18 +12115,8 @@ where
1211512115
|| -> NotifyOption { NotifyOption::DoPersist },
1211612116
);
1211712117
self.do_chain_event(None, |channel| {
12118-
if let Some(funding_txo) = channel.funding.get_funding_txo() {
12119-
if funding_txo.txid == *txid {
12120-
let chan_context =
12121-
WithChannelContext::from(&self.logger, &channel.context, None);
12122-
let res = channel.funding_transaction_unconfirmed(&&chan_context);
12123-
res.map(|()| (None, Vec::new(), None))
12124-
} else {
12125-
Ok((None, Vec::new(), None))
12126-
}
12127-
} else {
12128-
Ok((None, Vec::new(), None))
12129-
}
12118+
let logger = WithChannelContext::from(&self.logger, &channel.context, None);
12119+
channel.transaction_unconfirmed(txid, &&logger).map(|()| (None, Vec::new(), None))
1213012120
});
1213112121
}
1213212122
}

0 commit comments

Comments
 (0)