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