Skip to content

Commit 6a03c5e

Browse files
committed
Handle re-establishment next_funding_txid
1 parent 6efb2b7 commit 6a03c5e

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

lightning/src/ln/channel.rs

+20-4
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,10 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
14361436
/// If we can't release a [`ChannelMonitorUpdate`] until some external action completes, we
14371437
/// store it here and only release it to the `ChannelManager` once it asks for it.
14381438
blocked_monitor_updates: Vec<PendingChannelMonitorUpdate>,
1439+
// If we've sent `commtiment_signed` for an interactive transaction construction,
1440+
// but have not received `tx_signatures` we MUST set `next_funding_txid` to the
1441+
// txid of that interactive transaction, else we MUST NOT set it.
1442+
next_funding_txid: Option<Txid>,
14391443
}
14401444

14411445
pub(super) trait InteractivelyFunded<SP: Deref> where SP::Target: SignerProvider {
@@ -1983,6 +1987,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
19831987
local_initiated_shutdown: None,
19841988

19851989
blocked_monitor_updates: Vec::new(),
1990+
next_funding_txid: None,
19861991
};
19871992

19881993
Ok(channel_context)
@@ -2206,6 +2211,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
22062211

22072212
blocked_monitor_updates: Vec::new(),
22082213
local_initiated_shutdown: None,
2214+
next_funding_txid: None,
22092215
})
22102216
}
22112217

@@ -4377,6 +4383,14 @@ impl<SP: Deref> Channel<SP> where
43774383
self.context.channel_state.clear_waiting_for_batch();
43784384
}
43794385

4386+
pub fn set_next_funding_txid(&mut self, txid: &Txid) {
4387+
self.context.next_funding_txid = Some(*txid);
4388+
}
4389+
4390+
pub fn clear_next_funding_txid(&mut self) {
4391+
self.context.next_funding_txid = None;
4392+
}
4393+
43804394
/// Unsets the existing funding information.
43814395
///
43824396
/// This must only be used if the channel has not yet completed funding and has not been used.
@@ -7404,10 +7418,7 @@ impl<SP: Deref> Channel<SP> where
74047418
next_remote_commitment_number: INITIAL_COMMITMENT_NUMBER - self.context.cur_counterparty_commitment_transaction_number - 1,
74057419
your_last_per_commitment_secret: remote_last_secret,
74067420
my_current_per_commitment_point: dummy_pubkey,
7407-
// TODO(dual_funding): If we've sent `commtiment_signed` for an interactive transaction
7408-
// construction but have not received `tx_signatures` we MUST set `next_funding_txid` to the
7409-
// txid of that interactive transaction, else we MUST NOT set it.
7410-
next_funding_txid: None,
7421+
next_funding_txid: self.context.next_funding_txid,
74117422
}
74127423
}
74137424

@@ -9319,6 +9330,7 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
93199330
(45, cur_holder_commitment_point, option),
93209331
(47, next_holder_commitment_point, option),
93219332
(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
9333+
(51, self.context.next_funding_txid, option), // Added in 0.0.124
93229334
});
93239335

93249336
Ok(())
@@ -9916,6 +9928,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
99169928
local_initiated_shutdown,
99179929

99189930
blocked_monitor_updates: blocked_monitor_updates.unwrap(),
9931+
// If we've sent `commtiment_signed` for an interactive transaction construction,
9932+
// but have not received `tx_signatures` we MUST set `next_funding_txid` to the
9933+
// txid of that interactive transaction, else we MUST NOT set it.
9934+
next_funding_txid: None,
99199935
},
99209936
dual_funding_channel_context: None,
99219937
interactive_tx_constructor: None,

lightning/src/ln/channelmanager.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -7512,6 +7512,7 @@ where
75127512
peer_state.pending_msg_events.push(msg_send_event);
75137513
}
75147514
if let Some(signing_session) = signing_session_opt {
7515+
let funding_txid = signing_session.unsigned_tx.txid();
75157516
let (channel_id, channel_phase) = chan_phase_entry.remove_entry();
75167517
let res = match channel_phase {
75177518
ChannelPhase::UnfundedOutboundV2(chan) => {
@@ -7533,7 +7534,7 @@ where
75337534
.into()))),
75347535
};
75357536
match res {
7536-
Ok((channel, commitment_signed, funding_ready_for_sig_event_opt)) => {
7537+
Ok((mut channel, commitment_signed, funding_ready_for_sig_event_opt)) => {
75377538
if let Some(funding_ready_for_sig_event) = funding_ready_for_sig_event_opt {
75387539
let mut pending_events = self.pending_events.lock().unwrap();
75397540
pending_events.push_back((funding_ready_for_sig_event, None));
@@ -7549,6 +7550,7 @@ where
75497550
update_fee: None,
75507551
},
75517552
});
7553+
channel.set_next_funding_txid(&funding_txid);
75527554
peer_state.channel_by_id.insert(channel_id.clone(), ChannelPhase::Funded(channel));
75537555
},
75547556
Err((channel_phase, err)) => {
@@ -7583,6 +7585,7 @@ where
75837585
match channel_phase {
75847586
ChannelPhase::Funded(chan) => {
75857587
let (tx_signatures_opt, funding_tx_opt) = try_chan_phase_entry!(self, chan.tx_signatures(&msg), chan_phase_entry);
7588+
chan.clear_next_funding_txid();
75867589
if let Some(tx_signatures) = tx_signatures_opt {
75877590
peer_state.pending_msg_events.push(events::MessageSendEvent::SendTxSignatures {
75887591
node_id: *counterparty_node_id,

0 commit comments

Comments
 (0)