Skip to content

Commit 4783498

Browse files
committed
Handle re-establishment next_funding_txid
1 parent f317b65 commit 4783498

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
@@ -1446,6 +1446,10 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
14461446
/// If we can't release a [`ChannelMonitorUpdate`] until some external action completes, we
14471447
/// store it here and only release it to the `ChannelManager` once it asks for it.
14481448
blocked_monitor_updates: Vec<PendingChannelMonitorUpdate>,
1449+
// If we've sent `commtiment_signed` for an interactive transaction construction,
1450+
// but have not received `tx_signatures` we MUST set `next_funding_txid` to the
1451+
// txid of that interactive transaction, else we MUST NOT set it.
1452+
next_funding_txid: Option<Txid>,
14491453
}
14501454

14511455
pub(super) trait InteractivelyFunded<SP: Deref> where SP::Target: SignerProvider {
@@ -1986,6 +1990,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
19861990
local_initiated_shutdown: None,
19871991

19881992
blocked_monitor_updates: Vec::new(),
1993+
next_funding_txid: None,
19891994
};
19901995

19911996
Ok(channel_context)
@@ -2210,6 +2215,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
22102215

22112216
blocked_monitor_updates: Vec::new(),
22122217
local_initiated_shutdown: None,
2218+
next_funding_txid: None,
22132219
})
22142220
}
22152221

@@ -4391,6 +4397,14 @@ impl<SP: Deref> Channel<SP> where
43914397
self.context.channel_state.clear_waiting_for_batch();
43924398
}
43934399

4400+
pub fn set_next_funding_txid(&mut self, txid: &Txid) {
4401+
self.context.next_funding_txid = Some(*txid);
4402+
}
4403+
4404+
pub fn clear_next_funding_txid(&mut self) {
4405+
self.context.next_funding_txid = None;
4406+
}
4407+
43944408
/// Unsets the existing funding information.
43954409
///
43964410
/// This must only be used if the channel has not yet completed funding and has not been used.
@@ -7452,10 +7466,7 @@ impl<SP: Deref> Channel<SP> where
74527466
next_remote_commitment_number: INITIAL_COMMITMENT_NUMBER - self.context.cur_counterparty_commitment_transaction_number - 1,
74537467
your_last_per_commitment_secret: remote_last_secret,
74547468
my_current_per_commitment_point: dummy_pubkey,
7455-
// TODO(dual_funding): If we've sent `commtiment_signed` for an interactive transaction
7456-
// construction but have not received `tx_signatures` we MUST set `next_funding_txid` to the
7457-
// txid of that interactive transaction, else we MUST NOT set it.
7458-
next_funding_txid: None,
7469+
next_funding_txid: self.context.next_funding_txid,
74597470
}
74607471
}
74617472

@@ -9384,6 +9395,7 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
93849395
(45, cur_holder_commitment_point, option),
93859396
(47, next_holder_commitment_point, option),
93869397
(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
9398+
(51, self.context.next_funding_txid, option), // Added in 0.0.124
93879399
});
93889400

93899401
Ok(())
@@ -9982,6 +9994,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
99829994
local_initiated_shutdown,
99839995

99849996
blocked_monitor_updates: blocked_monitor_updates.unwrap(),
9997+
// If we've sent `commtiment_signed` for an interactive transaction construction,
9998+
// but have not received `tx_signatures` we MUST set `next_funding_txid` to the
9999+
// txid of that interactive transaction, else we MUST NOT set it.
10000+
next_funding_txid: None,
998510001
},
998610002
dual_funding_channel_context: None,
998710003
interactive_tx_constructor: None,

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7762,6 +7762,7 @@ where
77627762
peer_state.pending_msg_events.push(msg_send_event);
77637763
}
77647764
if let Some(signing_session) = signing_session_opt {
7765+
let funding_txid = signing_session.unsigned_tx.txid();
77657766
let (channel_id, channel_phase) = chan_phase_entry.remove_entry();
77667767
let res = match channel_phase {
77677768
ChannelPhase::UnfundedOutboundV2(chan) => {
@@ -7783,7 +7784,7 @@ where
77837784
.into()))),
77847785
};
77857786
match res {
7786-
Ok((channel, commitment_signed, funding_ready_for_sig_event_opt)) => {
7787+
Ok((mut channel, commitment_signed, funding_ready_for_sig_event_opt)) => {
77877788
if let Some(funding_ready_for_sig_event) = funding_ready_for_sig_event_opt {
77887789
let mut pending_events = self.pending_events.lock().unwrap();
77897790
pending_events.push_back((funding_ready_for_sig_event, None));
@@ -7799,6 +7800,7 @@ where
77997800
update_fee: None,
78007801
},
78017802
});
7803+
channel.set_next_funding_txid(&funding_txid);
78027804
peer_state.channel_by_id.insert(channel_id.clone(), ChannelPhase::Funded(channel));
78037805
},
78047806
Err((channel_phase, err)) => {
@@ -7833,6 +7835,7 @@ where
78337835
match channel_phase {
78347836
ChannelPhase::Funded(chan) => {
78357837
let (tx_signatures_opt, funding_tx_opt) = try_chan_phase_entry!(self, chan.tx_signatures(&msg), chan_phase_entry);
7838+
chan.clear_next_funding_txid();
78367839
if let Some(tx_signatures) = tx_signatures_opt {
78377840
peer_state.pending_msg_events.push(events::MessageSendEvent::SendTxSignatures {
78387841
node_id: *counterparty_node_id,

0 commit comments

Comments
 (0)