Skip to content

Commit 4760323

Browse files
committed
Handle re-establishment next_funding_txid
1 parent 8b4978b commit 4760323

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

lightning/src/ln/channel.rs

+22-4
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,10 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
13751375
/// If we can't release a [`ChannelMonitorUpdate`] until some external action completes, we
13761376
/// store it here and only release it to the `ChannelManager` once it asks for it.
13771377
blocked_monitor_updates: Vec<PendingChannelMonitorUpdate>,
1378+
// If we've sent `commtiment_signed` for an interactive transaction construction,
1379+
// but have not received `tx_signatures` we MUST set `next_funding_txid` to the
1380+
// txid of that interactive transaction, else we MUST NOT set it.
1381+
next_funding_txid: Option<Txid>,
13781382
}
13791383

13801384
#[cfg(any(dual_funding, splicing))]
@@ -1939,6 +1943,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
19391943
local_initiated_shutdown: None,
19401944

19411945
blocked_monitor_updates: Vec::new(),
1946+
next_funding_txid: None,
19421947
};
19431948

19441949
Ok(channel_context)
@@ -2159,6 +2164,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
21592164

21602165
blocked_monitor_updates: Vec::new(),
21612166
local_initiated_shutdown: None,
2167+
next_funding_txid: None,
21622168
})
21632169
}
21642170

@@ -4332,6 +4338,16 @@ impl<SP: Deref> Channel<SP> where
43324338
self.context.channel_state.clear_waiting_for_batch();
43334339
}
43344340

4341+
#[cfg(any(dual_funding, splicing))]
4342+
pub fn set_next_funding_txid(&mut self, txid: &Txid) {
4343+
self.context.next_funding_txid = Some(*txid);
4344+
}
4345+
4346+
#[cfg(any(dual_funding, splicing))]
4347+
pub fn clear_next_funding_txid(&mut self) {
4348+
self.context.next_funding_txid = None;
4349+
}
4350+
43354351
/// Unsets the existing funding information.
43364352
///
43374353
/// This must only be used if the channel has not yet completed funding and has not been used.
@@ -7318,10 +7334,7 @@ impl<SP: Deref> Channel<SP> where
73187334
next_remote_commitment_number: INITIAL_COMMITMENT_NUMBER - self.context.cur_counterparty_commitment_transaction_number - 1,
73197335
your_last_per_commitment_secret: remote_last_secret,
73207336
my_current_per_commitment_point: dummy_pubkey,
7321-
// TODO(dual_funding): If we've sent `commtiment_signed` for an interactive transaction
7322-
// construction but have not received `tx_signatures` we MUST set `next_funding_txid` to the
7323-
// txid of that interactive transaction, else we MUST NOT set it.
7324-
next_funding_txid: None,
7337+
next_funding_txid: self.context.next_funding_txid,
73257338
}
73267339
}
73277340

@@ -9248,6 +9261,7 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
92489261
(43, malformed_htlcs, optional_vec), // Added in 0.0.119
92499262
// 45 and 47 are reserved for async signing
92509263
(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
9264+
(51, self.context.next_funding_txid, option), // Added in 0.0.124
92519265
});
92529266

92539267
Ok(())
@@ -9823,6 +9837,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
98239837
local_initiated_shutdown,
98249838

98259839
blocked_monitor_updates: blocked_monitor_updates.unwrap(),
9840+
// If we've sent `commtiment_signed` for an interactive transaction construction,
9841+
// but have not received `tx_signatures` we MUST set `next_funding_txid` to the
9842+
// txid of that interactive transaction, else we MUST NOT set it.
9843+
next_funding_txid: None,
98269844
},
98279845
#[cfg(any(dual_funding, splicing))]
98289846
dual_funding_channel_context: None,

lightning/src/ln/channelmanager.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -7719,6 +7719,7 @@ where
77197719
peer_state.pending_msg_events.push(msg_send_event);
77207720
}
77217721
if let Some(signing_session) = signing_session_opt {
7722+
let funding_txid = signing_session.unsigned_tx.txid();
77227723
let (channel_id, channel_phase) = chan_phase_entry.remove_entry();
77237724
let res = match channel_phase {
77247725
ChannelPhase::UnfundedOutboundV2(chan) => {
@@ -7740,7 +7741,7 @@ where
77407741
.into()))),
77417742
};
77427743
match res {
7743-
Ok((channel, commitment_signed, funding_ready_for_sig_event_opt)) => {
7744+
Ok((mut channel, commitment_signed, funding_ready_for_sig_event_opt)) => {
77447745
if let Some(funding_ready_for_sig_event) = funding_ready_for_sig_event_opt {
77457746
let mut pending_events = self.pending_events.lock().unwrap();
77467747
pending_events.push_back((funding_ready_for_sig_event, None));
@@ -7756,6 +7757,7 @@ where
77567757
update_fee: None,
77577758
},
77587759
});
7760+
channel.set_next_funding_txid(&funding_txid);
77597761
peer_state.channel_by_id.insert(channel_id.clone(), ChannelPhase::Funded(channel));
77607762
},
77617763
Err((channel_phase, err)) => {
@@ -7791,6 +7793,7 @@ where
77917793
match channel_phase {
77927794
ChannelPhase::Funded(chan) => {
77937795
let (tx_signatures_opt, funding_tx_opt) = try_chan_phase_entry!(self, chan.tx_signatures(&msg), chan_phase_entry);
7796+
chan.clear_next_funding_txid();
77947797
if let Some(tx_signatures) = tx_signatures_opt {
77957798
peer_state.pending_msg_events.push(events::MessageSendEvent::SendTxSignatures {
77967799
node_id: *counterparty_node_id,

0 commit comments

Comments
 (0)