@@ -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};
@@ -2009,22 +2008,6 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
20092008 /// store it here and only release it to the `ChannelManager` once it asks for it.
20102009 blocked_monitor_updates: Vec<PendingChannelMonitorUpdate>,
20112010
2012- // The `next_funding_txid` field allows peers to finalize the signing steps of an interactive
2013- // transaction construction, or safely abort that transaction if it was not signed by one of the
2014- // peers, who has thus already removed it from its state.
2015- //
2016- // If we've sent `commtiment_signed` for an interactively constructed transaction
2017- // during a signing session, but have not received `tx_signatures` we MUST set `next_funding_txid`
2018- // to the txid of that interactive transaction, else we MUST NOT set it.
2019- //
2020- // See the spec for further details on this:
2021- // * `channel_reestablish`-sending node: https://github.com/lightning/bolts/blob/247e83d/02-peer-protocol.md?plain=1#L2466-L2470
2022- // * `channel_reestablish`-receiving node: https://github.com/lightning/bolts/blob/247e83d/02-peer-protocol.md?plain=1#L2520-L2531
2023- //
2024- // TODO(dual_funding): Persist this when we actually contribute funding inputs. For now we always
2025- // send an empty witnesses array in `tx_signatures` as a V2 channel acceptor
2026- next_funding_txid: Option<Txid>,
2027-
20282011 /// Only set when a counterparty `stfu` has been processed to track which node is allowed to
20292012 /// propose "something fundamental" upon becoming quiescent.
20302013 is_holder_quiescence_initiator: Option<bool>,
@@ -2283,10 +2266,6 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
22832266 }
22842267 };
22852268
2286- if let HandleTxCompleteValue::SendTxComplete(_, ref signing_session) = tx_complete {
2287- self.context.next_funding_txid = Some(signing_session.unsigned_tx.compute_txid());
2288- };
2289-
22902269 HandleTxCompleteResult(Ok(tx_complete))
22912270 }
22922271
@@ -2723,8 +2702,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
27232702
27242703 is_manual_broadcast: false,
27252704
2726- next_funding_txid: None,
2727-
27282705 is_holder_quiescence_initiator: None,
27292706 };
27302707
@@ -2957,7 +2934,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
29572934 blocked_monitor_updates: Vec::new(),
29582935 local_initiated_shutdown: None,
29592936 is_manual_broadcast: false,
2960- next_funding_txid: None,
29612937
29622938 is_holder_quiescence_initiator: None,
29632939 };
@@ -6293,7 +6269,6 @@ impl<SP: Deref> FundedChannel<SP> where
62936269 // We have a finalized funding transaction, so we can set the funding transaction and reset the
62946270 // signing session fields.
62956271 self.funding.funding_transaction = funding_tx_opt;
6296- self.context.next_funding_txid = None;
62976272 self.interactive_tx_signing_session = None;
62986273 }
62996274
@@ -8348,6 +8323,25 @@ impl<SP: Deref> FundedChannel<SP> where
83488323 }
83498324 }
83508325
8326+ fn maybe_get_next_funding_txid(&self) -> Option<Txid> {
8327+ // If we've sent `commtiment_signed` for an interactively constructed transaction
8328+ // during a signing session, but have not received `tx_signatures` we MUST set `next_funding_txid`
8329+ // to the txid of that interactive transaction, else we MUST NOT set it.
8330+ if let Some(signing_session) = &self.interactive_tx_signing_session {
8331+ // Since we have a signing_session, this implies we've sent an initial `commitment_signed`...
8332+ if !signing_session.counterparty_sent_tx_signatures {
8333+ // ...but we didn't receive a `tx_signatures` from the counterparty yet.
8334+ Some(self.funding_outpoint().txid)
8335+ } else {
8336+ // ...and we received a `tx_signatures` from the counterparty.
8337+ None
8338+ }
8339+ } else {
8340+ // We don't have an active signing session.
8341+ None
8342+ }
8343+ }
8344+
83518345 /// May panic if called on a channel that wasn't immediately-previously
83528346 /// self.remove_uncommitted_htlcs_and_mark_paused()'d
83538347 fn get_channel_reestablish<L: Deref>(&mut self, logger: &L) -> msgs::ChannelReestablish where L::Target: Logger {
@@ -8397,7 +8391,7 @@ impl<SP: Deref> FundedChannel<SP> where
83978391 next_remote_commitment_number: INITIAL_COMMITMENT_NUMBER - self.context.cur_counterparty_commitment_transaction_number - 1,
83988392 your_last_per_commitment_secret: remote_last_secret,
83998393 my_current_per_commitment_point: dummy_pubkey,
8400- next_funding_txid: self.context.next_funding_txid ,
8394+ next_funding_txid: self.maybe_get_next_funding_txid() ,
84018395 }
84028396 }
84038397
@@ -11103,14 +11097,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1110311097 blocked_monitor_updates: blocked_monitor_updates.unwrap(),
1110411098 is_manual_broadcast: is_manual_broadcast.unwrap_or(false),
1110511099
11106- // TODO(dual_funding): Instead of getting this from persisted value, figure it out based on the
11107- // funding transaction and other channel state.
11108- //
11109- // If we've sent `commtiment_signed` for an interactively constructed transaction
11110- // during a signing session, but have not received `tx_signatures` we MUST set `next_funding_txid`
11111- // to the txid of that interactive transaction, else we MUST NOT set it.
11112- next_funding_txid: None,
11113-
1111411100 is_holder_quiescence_initiator: None,
1111511101 },
1111611102 interactive_tx_signing_session: None,
0 commit comments