Skip to content

Commit 8819084

Browse files
committed
Handle re-establishment next_funding_txid
1 parent c2f4583 commit 8819084

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

lightning/src/ln/channel.rs

Lines changed: 20 additions & 4 deletions
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

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

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

@@ -9321,6 +9332,7 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
93219332
(45, cur_holder_commitment_point, option),
93229333
(47, next_holder_commitment_point, option),
93239334
(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
9335+
(51, self.context.next_funding_txid, option), // Added in 0.0.124
93249336
});
93259337

93269338
Ok(())
@@ -9918,6 +9930,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
99189930
local_initiated_shutdown,
99199931

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

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7566,6 +7566,7 @@ where
75667566
peer_state.pending_msg_events.push(msg_send_event);
75677567
}
75687568
if let Some(signing_session) = signing_session_opt {
7569+
let funding_txid = signing_session.unsigned_tx.txid();
75697570
let (channel_id, channel_phase) = chan_phase_entry.remove_entry();
75707571
let res = match channel_phase {
75717572
ChannelPhase::UnfundedOutboundV2(chan) => {
@@ -7587,7 +7588,7 @@ where
75877588
.into()))),
75887589
};
75897590
match res {
7590-
Ok((channel, commitment_signed, funding_ready_for_sig_event_opt)) => {
7591+
Ok((mut channel, commitment_signed, funding_ready_for_sig_event_opt)) => {
75917592
if let Some(funding_ready_for_sig_event) = funding_ready_for_sig_event_opt {
75927593
let mut pending_events = self.pending_events.lock().unwrap();
75937594
pending_events.push_back((funding_ready_for_sig_event, None));
@@ -7603,6 +7604,7 @@ where
76037604
update_fee: None,
76047605
},
76057606
});
7607+
channel.set_next_funding_txid(&funding_txid);
76067608
peer_state.channel_by_id.insert(channel_id.clone(), ChannelPhase::Funded(channel));
76077609
},
76087610
Err((channel_phase, err)) => {
@@ -7637,6 +7639,7 @@ where
76377639
match channel_phase {
76387640
ChannelPhase::Funded(chan) => {
76397641
let (tx_signatures_opt, funding_tx_opt) = try_chan_phase_entry!(self, chan.tx_signatures(&msg), chan_phase_entry);
7642+
chan.clear_next_funding_txid();
76407643
if let Some(tx_signatures) = tx_signatures_opt {
76417644
peer_state.pending_msg_events.push(events::MessageSendEvent::SendTxSignatures {
76427645
node_id: *counterparty_node_id,

0 commit comments

Comments
 (0)