@@ -30,9 +30,8 @@ use crate::ln::types::ChannelId;
3030use crate::types::payment::{PaymentPreimage, PaymentHash};
3131use crate::types::features::{ChannelTypeFeatures, InitFeatures};
3232use crate::ln::interactivetxs::{
33- get_output_weight, HandleTxCompleteValue, HandleTxCompleteResult, InteractiveTxConstructor,
34- InteractiveTxConstructorArgs, InteractiveTxSigningSession, InteractiveTxMessageSendResult,
35- TX_COMMON_FIELDS_WEIGHT,
33+ get_output_weight, HandleTxCompleteResult, InteractiveTxConstructor, InteractiveTxConstructorArgs,
34+ InteractiveTxSigningSession, InteractiveTxMessageSendResult, TX_COMMON_FIELDS_WEIGHT,
3635};
3736use crate::ln::msgs;
3837use crate::ln::msgs::{ClosingSigned, ClosingSignedFeeRange, DecodeError, OnionErrorPacket};
@@ -2006,22 +2005,6 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
20062005 /// store it here and only release it to the `ChannelManager` once it asks for it.
20072006 blocked_monitor_updates: Vec<PendingChannelMonitorUpdate>,
20082007
2009- // The `next_funding_txid` field allows peers to finalize the signing steps of an interactive
2010- // transaction construction, or safely abort that transaction if it was not signed by one of the
2011- // peers, who has thus already removed it from its state.
2012- //
2013- // If we've sent `commtiment_signed` for an interactively constructed transaction
2014- // during a signing session, but have not received `tx_signatures` we MUST set `next_funding_txid`
2015- // to the txid of that interactive transaction, else we MUST NOT set it.
2016- //
2017- // See the spec for further details on this:
2018- // * `channel_reestablish`-sending node: https://github.com/lightning/bolts/blob/247e83d/02-peer-protocol.md?plain=1#L2466-L2470
2019- // * `channel_reestablish`-receiving node: https://github.com/lightning/bolts/blob/247e83d/02-peer-protocol.md?plain=1#L2520-L2531
2020- //
2021- // TODO(dual_funding): Persist this when we actually contribute funding inputs. For now we always
2022- // send an empty witnesses array in `tx_signatures` as a V2 channel acceptor
2023- next_funding_txid: Option<Txid>,
2024-
20252008 /// Only set when a counterparty `stfu` has been processed to track which node is allowed to
20262009 /// propose "something fundamental" upon becoming quiescent.
20272010 is_holder_quiescence_initiator: Option<bool>,
@@ -2276,10 +2259,6 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
22762259 }
22772260 };
22782261
2279- if let HandleTxCompleteValue::SendTxComplete(_, ref signing_session) = tx_complete {
2280- self.context.next_funding_txid = Some(signing_session.unsigned_tx.compute_txid());
2281- };
2282-
22832262 HandleTxCompleteResult(Ok(tx_complete))
22842263 }
22852264
@@ -2716,8 +2695,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
27162695
27172696 is_manual_broadcast: false,
27182697
2719- next_funding_txid: None,
2720-
27212698 is_holder_quiescence_initiator: None,
27222699 };
27232700
@@ -2950,7 +2927,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
29502927 blocked_monitor_updates: Vec::new(),
29512928 local_initiated_shutdown: None,
29522929 is_manual_broadcast: false,
2953- next_funding_txid: None,
29542930
29552931 is_holder_quiescence_initiator: None,
29562932 };
@@ -6313,7 +6289,6 @@ impl<SP: Deref> FundedChannel<SP> where
63136289 // We have a finalized funding transaction, so we can set the funding transaction and reset the
63146290 // signing session fields.
63156291 self.funding.funding_transaction = funding_tx_opt;
6316- self.context.next_funding_txid = None;
63176292 self.interactive_tx_signing_session = None;
63186293 }
63196294
@@ -8365,6 +8340,25 @@ impl<SP: Deref> FundedChannel<SP> where
83658340 }
83668341 }
83678342
8343+ fn maybe_get_next_funding_txid(&self) -> Option<Txid> {
8344+ // If we've sent `commtiment_signed` for an interactively constructed transaction
8345+ // during a signing session, but have not received `tx_signatures` we MUST set `next_funding_txid`
8346+ // to the txid of that interactive transaction, else we MUST NOT set it.
8347+ if let Some(signing_session) = &self.interactive_tx_signing_session {
8348+ // Since we have a signing_session, this implies we've sent an initial `commitment_signed`...
8349+ if !signing_session.counterparty_sent_tx_signatures {
8350+ // ...but we didn't receive a `tx_signatures` from the counterparty yet.
8351+ Some(self.funding_outpoint().txid)
8352+ } else {
8353+ // ...and we received a `tx_signatures` from the counterparty.
8354+ None
8355+ }
8356+ } else {
8357+ // We don't have an active signing session.
8358+ None
8359+ }
8360+ }
8361+
83688362 /// May panic if called on a channel that wasn't immediately-previously
83698363 /// self.remove_uncommitted_htlcs_and_mark_paused()'d
83708364 fn get_channel_reestablish<L: Deref>(&mut self, logger: &L) -> msgs::ChannelReestablish where L::Target: Logger {
@@ -8414,7 +8408,7 @@ impl<SP: Deref> FundedChannel<SP> where
84148408 next_remote_commitment_number: INITIAL_COMMITMENT_NUMBER - self.context.cur_counterparty_commitment_transaction_number - 1,
84158409 your_last_per_commitment_secret: remote_last_secret,
84168410 my_current_per_commitment_point: dummy_pubkey,
8417- next_funding_txid: self.context.next_funding_txid ,
8411+ next_funding_txid: self.maybe_get_next_funding_txid() ,
84188412 }
84198413 }
84208414
@@ -11118,14 +11112,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1111811112 blocked_monitor_updates: blocked_monitor_updates.unwrap(),
1111911113 is_manual_broadcast: is_manual_broadcast.unwrap_or(false),
1112011114
11121- // TODO(dual_funding): Instead of getting this from persisted value, figure it out based on the
11122- // funding transaction and other channel state.
11123- //
11124- // If we've sent `commtiment_signed` for an interactively constructed transaction
11125- // during a signing session, but have not received `tx_signatures` we MUST set `next_funding_txid`
11126- // to the txid of that interactive transaction, else we MUST NOT set it.
11127- next_funding_txid: None,
11128-
1112911115 is_holder_quiescence_initiator: None,
1113011116 },
1113111117 interactive_tx_signing_session: None,
0 commit comments