@@ -1494,6 +1494,21 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
14941494 /// If we can't release a [`ChannelMonitorUpdate`] until some external action completes, we
14951495 /// store it here and only release it to the `ChannelManager` once it asks for it.
14961496 blocked_monitor_updates: Vec<PendingChannelMonitorUpdate>,
1497+ // The `next_funding_txid` field allows peers to finalize the signing steps of an interactive
1498+ // transaction construction, or safely abort that transaction if it was not signed by one of the
1499+ // peers, who has thus already removed it from its state.
1500+ //
1501+ // If we've sent `commtiment_signed` for an interactive an interactively constructed transaction
1502+ // during a signing session, but have not received `tx_signatures` we MUST set `next_funding_txid`
1503+ // to the txid of that interactive transaction, else we MUST NOT set it.
1504+ //
1505+ // See the spec for further details on this:
1506+ // * `channel_reestablish`-sending node: https://github.com/lightning/bolts/blob/247e83d/02-peer-protocol.md?plain=1#L2466-L2470
1507+ // * `channel_reestablish`-receiving node: https://github.com/lightning/bolts/blob/247e83d/02-peer-protocol.md?plain=1#L2520-L2531
1508+ //
1509+ // TODO(dual_funding): Persist this when we actually contribute funding inputs. For now we always
1510+ // send an empty witnesses array in `tx_signatures` as a V2 channel acceptor
1511+ next_funding_txid: Option<Txid>,
14971512}
14981513
14991514/// A channel struct implementing this trait can receive an initial counterparty commitment
@@ -2159,6 +2174,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
21592174 blocked_monitor_updates: Vec::new(),
21602175
21612176 is_manual_broadcast: false,
2177+
2178+ next_funding_txid: None,
21622179 };
21632180
21642181 Ok(channel_context)
@@ -2390,6 +2407,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
23902407 blocked_monitor_updates: Vec::new(),
23912408 local_initiated_shutdown: None,
23922409 is_manual_broadcast: false,
2410+ next_funding_txid: None,
23932411 })
23942412 }
23952413
@@ -4601,6 +4619,14 @@ impl<SP: Deref> Channel<SP> where
46014619 self.context.channel_state.clear_waiting_for_batch();
46024620 }
46034621
4622+ pub fn set_next_funding_txid(&mut self, txid: &Txid) {
4623+ self.context.next_funding_txid = Some(*txid);
4624+ }
4625+
4626+ pub fn clear_next_funding_txid(&mut self) {
4627+ self.context.next_funding_txid = None;
4628+ }
4629+
46044630 /// Unsets the existing funding information.
46054631 ///
46064632 /// This must only be used if the channel has not yet completed funding and has not been used.
@@ -7680,10 +7706,7 @@ impl<SP: Deref> Channel<SP> where
76807706 next_remote_commitment_number: INITIAL_COMMITMENT_NUMBER - self.context.cur_counterparty_commitment_transaction_number - 1,
76817707 your_last_per_commitment_secret: remote_last_secret,
76827708 my_current_per_commitment_point: dummy_pubkey,
7683- // TODO(dual_funding): If we've sent `commtiment_signed` for an interactive transaction
7684- // construction but have not received `tx_signatures` we MUST set `next_funding_txid` to the
7685- // txid of that interactive transaction, else we MUST NOT set it.
7686- next_funding_txid: None,
7709+ next_funding_txid: self.context.next_funding_txid,
76877710 }
76887711 }
76897712
@@ -9439,7 +9462,8 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
94399462 (47, next_holder_commitment_point, option),
94409463 (49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
94419464 (51, is_manual_broadcast, option), // Added in 0.0.124
9442- (53, funding_tx_broadcast_safe_event_emitted, option) // Added in 0.0.124
9465+ (53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
9466+ (55, self.context.next_funding_txid, option) // Added in 0.0.125
94439467 });
94449468
94459469 Ok(())
@@ -9729,6 +9753,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
97299753 let mut channel_pending_event_emitted = None;
97309754 let mut channel_ready_event_emitted = None;
97319755 let mut funding_tx_broadcast_safe_event_emitted = None;
9756+ let mut next_funding_txid = None;
97329757
97339758 let mut user_id_high_opt: Option<u64> = None;
97349759 let mut channel_keys_id: Option<[u8; 32]> = None;
@@ -9789,6 +9814,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
97899814 (49, local_initiated_shutdown, option),
97909815 (51, is_manual_broadcast, option),
97919816 (53, funding_tx_broadcast_safe_event_emitted, option),
9817+ (55, next_funding_txid, option) // Added in 0.0.125
97929818 });
97939819
97949820 let (channel_keys_id, holder_signer) = if let Some(channel_keys_id) = channel_keys_id {
@@ -10048,6 +10074,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1004810074
1004910075 blocked_monitor_updates: blocked_monitor_updates.unwrap(),
1005010076 is_manual_broadcast: is_manual_broadcast.unwrap_or(false),
10077+ // If we've sent `commtiment_signed` for an interactive transaction construction,
10078+ // but have not received `tx_signatures` we MUST set `next_funding_txid` to the
10079+ // txid of that interactive transaction, else we MUST NOT set it.
10080+ next_funding_txid,
1005110081 },
1005210082 interactive_tx_signing_session: None,
1005310083 })
0 commit comments