Skip to content

Commit c88a292

Browse files
committed
Handle re-establishment next_funding_txid
1 parent bec62d7 commit c88a292

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

lightning/src/ln/channel.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,10 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
14931493
/// If we can't release a [`ChannelMonitorUpdate`] until some external action completes, we
14941494
/// store it here and only release it to the `ChannelManager` once it asks for it.
14951495
blocked_monitor_updates: Vec<PendingChannelMonitorUpdate>,
1496+
// If we've sent `commtiment_signed` for an interactive transaction construction,
1497+
// but have not received `tx_signatures` we MUST set `next_funding_txid` to the
1498+
// txid of that interactive transaction, else we MUST NOT set it.
1499+
next_funding_txid: Option<Txid>,
14961500
}
14971501

14981502
pub(super) trait InteractivelyFunded<SP: Deref> where SP::Target: SignerProvider {
@@ -2152,6 +2156,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
21522156
blocked_monitor_updates: Vec::new(),
21532157

21542158
is_manual_broadcast: false,
2159+
2160+
next_funding_txid: None,
21552161
};
21562162

21572163
Ok(channel_context)
@@ -2383,6 +2389,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
23832389
blocked_monitor_updates: Vec::new(),
23842390
local_initiated_shutdown: None,
23852391
is_manual_broadcast: false,
2392+
next_funding_txid: None,
23862393
})
23872394
}
23882395

@@ -4588,6 +4595,14 @@ impl<SP: Deref> Channel<SP> where
45884595
self.context.channel_state.clear_waiting_for_batch();
45894596
}
45904597

4598+
pub fn set_next_funding_txid(&mut self, txid: &Txid) {
4599+
self.context.next_funding_txid = Some(*txid);
4600+
}
4601+
4602+
pub fn clear_next_funding_txid(&mut self) {
4603+
self.context.next_funding_txid = None;
4604+
}
4605+
45914606
/// Unsets the existing funding information.
45924607
///
45934608
/// This must only be used if the channel has not yet completed funding and has not been used.
@@ -7669,10 +7684,7 @@ impl<SP: Deref> Channel<SP> where
76697684
next_remote_commitment_number: INITIAL_COMMITMENT_NUMBER - self.context.cur_counterparty_commitment_transaction_number - 1,
76707685
your_last_per_commitment_secret: remote_last_secret,
76717686
my_current_per_commitment_point: dummy_pubkey,
7672-
// TODO(dual_funding): If we've sent `commtiment_signed` for an interactive transaction
7673-
// construction but have not received `tx_signatures` we MUST set `next_funding_txid` to the
7674-
// txid of that interactive transaction, else we MUST NOT set it.
7675-
next_funding_txid: None,
7687+
next_funding_txid: self.context.next_funding_txid,
76767688
}
76777689
}
76787690

@@ -9452,7 +9464,8 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
94529464
(47, next_holder_commitment_point, option),
94539465
(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
94549466
(51, is_manual_broadcast, option), // Added in 0.0.124
9455-
(53, funding_tx_broadcast_safe_event_emitted, option) // Added in 0.0.124
9467+
(53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
9468+
(55, self.context.next_funding_txid, option) // Added in 0.0.125
94569469
});
94579470

94589471
Ok(())
@@ -9742,6 +9755,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
97429755
let mut channel_pending_event_emitted = None;
97439756
let mut channel_ready_event_emitted = None;
97449757
let mut funding_tx_broadcast_safe_event_emitted = None;
9758+
let mut next_funding_txid = None;
97459759

97469760
let mut user_id_high_opt: Option<u64> = None;
97479761
let mut channel_keys_id: Option<[u8; 32]> = None;
@@ -9802,6 +9816,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
98029816
(49, local_initiated_shutdown, option),
98039817
(51, is_manual_broadcast, option),
98049818
(53, funding_tx_broadcast_safe_event_emitted, option),
9819+
(55, next_funding_txid, option) // Added in 0.0.125
98059820
});
98069821

98079822
let (channel_keys_id, holder_signer) = if let Some(channel_keys_id) = channel_keys_id {
@@ -10061,6 +10076,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1006110076

1006210077
blocked_monitor_updates: blocked_monitor_updates.unwrap(),
1006310078
is_manual_broadcast: is_manual_broadcast.unwrap_or(false),
10079+
// If we've sent `commtiment_signed` for an interactive transaction construction,
10080+
// but have not received `tx_signatures` we MUST set `next_funding_txid` to the
10081+
// txid of that interactive transaction, else we MUST NOT set it.
10082+
next_funding_txid,
1006410083
},
1006510084
dual_funding_channel_context: None,
1006610085
interactive_tx_constructor: None,

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8147,6 +8147,7 @@ where
81478147
peer_state.pending_msg_events.push(msg_send_event);
81488148
};
81498149
if let Some(mut signing_session) = signing_session_opt {
8150+
let funding_txid = signing_session.unsigned_tx.txid();
81508151
let (commitment_signed, funding_ready_for_sig_event_opt) = match chan_phase_entry.get_mut() {
81518152
ChannelPhase::UnfundedOutboundV2(chan) => {
81528153
chan.funding_tx_constructed(&mut signing_session, &self.logger)
@@ -8159,7 +8160,7 @@ where
81598160
.into())),
81608161
}.map_err(|err| MsgHandleErrInternal::send_err_msg_no_close(format!("{}", err), msg.channel_id))?;
81618162
let (channel_id, channel_phase) = chan_phase_entry.remove_entry();
8162-
let channel = match channel_phase {
8163+
let mut channel = match channel_phase {
81638164
ChannelPhase::UnfundedOutboundV2(chan) => chan.into_channel(signing_session),
81648165
ChannelPhase::UnfundedInboundV2(chan) => chan.into_channel(signing_session),
81658166
_ => {
@@ -8169,6 +8170,7 @@ where
81698170
.into()))
81708171
},
81718172
}.map_err(|err| MsgHandleErrInternal::send_err_msg_no_close(format!("{}", err), msg.channel_id))?;
8173+
channel.set_next_funding_txid(&funding_txid);
81728174
peer_state.channel_by_id.insert(channel_id, ChannelPhase::Funded(channel));
81738175
if let Some(funding_ready_for_sig_event) = funding_ready_for_sig_event_opt {
81748176
let mut pending_events = self.pending_events.lock().unwrap();
@@ -8212,6 +8214,7 @@ where
82128214
match channel_phase {
82138215
ChannelPhase::Funded(chan) => {
82148216
let (tx_signatures_opt, funding_tx_opt) = try_chan_phase_entry!(self, chan.tx_signatures(msg), chan_phase_entry);
8217+
chan.clear_next_funding_txid();
82158218
if let Some(tx_signatures) = tx_signatures_opt {
82168219
peer_state.pending_msg_events.push(events::MessageSendEvent::SendTxSignatures {
82178220
node_id: *counterparty_node_id,

0 commit comments

Comments
 (0)