@@ -8703,32 +8703,46 @@ impl<SP: Deref> FundedChannel<SP> where
87038703 Ok((None, timed_out_htlcs, announcement_sigs))
87048704 }
87058705
8706- /// Indicates the funding transaction is no longer confirmed in the main chain. This may
8706+ /// Checks if any funding transaction is no longer confirmed in the main chain. This may
87078707 /// force-close the channel, but may also indicate a harmless reorganization of a block or two
8708- /// before the channel has reached channel_ready and we can just wait for more blocks.
8709- pub fn funding_transaction_unconfirmed<L: Deref>(&mut self, logger: &L) -> Result<(), ClosureReason> where L::Target: Logger {
8710- if self.funding.funding_tx_confirmation_height != 0 {
8711- // We handle the funding disconnection by calling best_block_updated with a height one
8712- // below where our funding was connected, implying a reorg back to conf_height - 1.
8713- let reorg_height = self.funding.funding_tx_confirmation_height - 1;
8714- // We use the time field to bump the current time we set on channel updates if its
8715- // larger. If we don't know that time has moved forward, we can just set it to the last
8716- // time we saw and it will be ignored.
8717- let best_time = self.context.update_time_counter;
8718-
8719- self.funding.funding_tx_confirmation_height = 0;
8720-
8721- match self.do_best_block_updated(reorg_height, best_time, None::<(ChainHash, &&dyn NodeSigner, &UserConfig)>, logger) {
8722- Ok((channel_ready, timed_out_htlcs, announcement_sigs)) => {
8723- assert!(channel_ready.is_none(), "We can't generate a funding with 0 confirmations?");
8724- assert!(timed_out_htlcs.is_empty(), "We can't have accepted HTLCs with a timeout before our funding confirmation?");
8725- assert!(announcement_sigs.is_none(), "We can't generate an announcement_sigs with 0 confirmations?");
8726- Ok(())
8727- },
8728- Err(e) => Err(e)
8708+ /// before the channel has reached channel_ready or splice_locked, and we can just wait for more
8709+ /// blocks.
8710+ pub fn transaction_unconfirmed<L: Deref>(
8711+ &mut self, txid: &Txid, logger: &L,
8712+ ) -> Result<(), ClosureReason>
8713+ where
8714+ L::Target: Logger,
8715+ {
8716+ let unconfirmed_funding = core::iter::once(&mut self.funding)
8717+ .chain(self.pending_funding.iter_mut())
8718+ .find(|funding| funding.get_funding_txid() == Some(*txid));
8719+
8720+ if let Some(funding) = unconfirmed_funding {
8721+ if funding.funding_tx_confirmation_height != 0 {
8722+ // We handle the funding disconnection by calling best_block_updated with a height one
8723+ // below where our funding was connected, implying a reorg back to conf_height - 1.
8724+ let reorg_height = funding.funding_tx_confirmation_height - 1;
8725+ // We use the time field to bump the current time we set on channel updates if its
8726+ // larger. If we don't know that time has moved forward, we can just set it to the last
8727+ // time we saw and it will be ignored.
8728+ let best_time = self.context.update_time_counter;
8729+
8730+ funding.funding_tx_confirmation_height = 0;
8731+
8732+ match self.do_best_block_updated(reorg_height, best_time, None::<(ChainHash, &&dyn NodeSigner, &UserConfig)>, logger) {
8733+ Ok((channel_ready, timed_out_htlcs, announcement_sigs)) => {
8734+ assert!(channel_ready.is_none(), "We can't generate a funding with 0 confirmations?");
8735+ assert!(timed_out_htlcs.is_empty(), "We can't have accepted HTLCs with a timeout before our funding confirmation?");
8736+ assert!(announcement_sigs.is_none(), "We can't generate an announcement_sigs with 0 confirmations?");
8737+ Ok(())
8738+ },
8739+ Err(e) => Err(e),
8740+ }
8741+ } else {
8742+ // We never learned about the funding confirmation anyway, just ignore
8743+ Ok(())
87298744 }
87308745 } else {
8731- // We never learned about the funding confirmation anyway, just ignore
87328746 Ok(())
87338747 }
87348748 }
0 commit comments