Skip to content

Commit 1039dcc

Browse files
committed
Handle re-establishment next_funding_txid
1 parent 7571b36 commit 1039dcc

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

14991503
/// A channel struct implementing this trait can receive an initial counterparty commitment
@@ -2154,6 +2158,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
21542158
blocked_monitor_updates: Vec::new(),
21552159

21562160
is_manual_broadcast: false,
2161+
2162+
next_funding_txid: None,
21572163
};
21582164

21592165
Ok(channel_context)
@@ -2385,6 +2391,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
23852391
blocked_monitor_updates: Vec::new(),
23862392
local_initiated_shutdown: None,
23872393
is_manual_broadcast: false,
2394+
next_funding_txid: None,
23882395
})
23892396
}
23902397

@@ -4590,6 +4597,14 @@ impl<SP: Deref> Channel<SP> where
45904597
self.context.channel_state.clear_waiting_for_batch();
45914598
}
45924599

4600+
pub fn set_next_funding_txid(&mut self, txid: &Txid) {
4601+
self.context.next_funding_txid = Some(*txid);
4602+
}
4603+
4604+
pub fn clear_next_funding_txid(&mut self) {
4605+
self.context.next_funding_txid = None;
4606+
}
4607+
45934608
/// Unsets the existing funding information.
45944609
///
45954610
/// This must only be used if the channel has not yet completed funding and has not been used.
@@ -7664,10 +7679,7 @@ impl<SP: Deref> Channel<SP> where
76647679
next_remote_commitment_number: INITIAL_COMMITMENT_NUMBER - self.context.cur_counterparty_commitment_transaction_number - 1,
76657680
your_last_per_commitment_secret: remote_last_secret,
76667681
my_current_per_commitment_point: dummy_pubkey,
7667-
// TODO(dual_funding): If we've sent `commtiment_signed` for an interactive transaction
7668-
// construction but have not received `tx_signatures` we MUST set `next_funding_txid` to the
7669-
// txid of that interactive transaction, else we MUST NOT set it.
7670-
next_funding_txid: None,
7682+
next_funding_txid: self.context.next_funding_txid,
76717683
}
76727684
}
76737685

@@ -9437,7 +9449,8 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
94379449
(47, next_holder_commitment_point, option),
94389450
(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
94399451
(51, is_manual_broadcast, option), // Added in 0.0.124
9440-
(53, funding_tx_broadcast_safe_event_emitted, option) // Added in 0.0.124
9452+
(53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
9453+
(55, self.context.next_funding_txid, option) // Added in 0.0.125
94419454
});
94429455

94439456
Ok(())
@@ -9727,6 +9740,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
97279740
let mut channel_pending_event_emitted = None;
97289741
let mut channel_ready_event_emitted = None;
97299742
let mut funding_tx_broadcast_safe_event_emitted = None;
9743+
let mut next_funding_txid = None;
97309744

97319745
let mut user_id_high_opt: Option<u64> = None;
97329746
let mut channel_keys_id: Option<[u8; 32]> = None;
@@ -9787,6 +9801,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
97879801
(49, local_initiated_shutdown, option),
97889802
(51, is_manual_broadcast, option),
97899803
(53, funding_tx_broadcast_safe_event_emitted, option),
9804+
(55, next_funding_txid, option) // Added in 0.0.125
97909805
});
97919806

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

1004710062
blocked_monitor_updates: blocked_monitor_updates.unwrap(),
1004810063
is_manual_broadcast: is_manual_broadcast.unwrap_or(false),
10064+
// If we've sent `commtiment_signed` for an interactive transaction construction,
10065+
// but have not received `tx_signatures` we MUST set `next_funding_txid` to the
10066+
// txid of that interactive transaction, else we MUST NOT set it.
10067+
next_funding_txid,
1004910068
},
1005010069
dual_funding_channel_context: None,
1005110070
interactive_tx_constructor: None,

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8148,6 +8148,7 @@ where
81488148
peer_state.pending_msg_events.push(msg_send_event);
81498149
};
81508150
if let Some(mut signing_session) = signing_session_opt {
8151+
let funding_txid = signing_session.unsigned_tx.txid();
81518152
let (commitment_signed, funding_ready_for_sig_event_opt) = match chan_phase_entry.get_mut() {
81528153
ChannelPhase::UnfundedOutboundV2(chan) => {
81538154
chan.funding_tx_constructed(&mut signing_session, &self.logger)
@@ -8160,7 +8161,7 @@ where
81608161
.into())),
81618162
}.map_err(|err| MsgHandleErrInternal::send_err_msg_no_close(format!("{}", err), msg.channel_id))?;
81628163
let (channel_id, channel_phase) = chan_phase_entry.remove_entry();
8163-
let channel = match channel_phase {
8164+
let mut channel = match channel_phase {
81648165
ChannelPhase::UnfundedOutboundV2(chan) => chan.into_channel(signing_session),
81658166
ChannelPhase::UnfundedInboundV2(chan) => chan.into_channel(signing_session),
81668167
_ => {
@@ -8170,6 +8171,7 @@ where
81708171
.into()))
81718172
},
81728173
}.map_err(|err| MsgHandleErrInternal::send_err_msg_no_close(format!("{}", err), msg.channel_id))?;
8174+
channel.set_next_funding_txid(&funding_txid);
81738175
peer_state.channel_by_id.insert(channel_id, ChannelPhase::Funded(channel));
81748176
if let Some(funding_ready_for_sig_event) = funding_ready_for_sig_event_opt {
81758177
let mut pending_events = self.pending_events.lock().unwrap();
@@ -8213,6 +8215,7 @@ where
82138215
match channel_phase {
82148216
ChannelPhase::Funded(chan) => {
82158217
let (tx_signatures_opt, funding_tx_opt) = try_chan_phase_entry!(self, chan.tx_signatures(msg), chan_phase_entry);
8218+
chan.clear_next_funding_txid();
82168219
if let Some(tx_signatures) = tx_signatures_opt {
82178220
peer_state.pending_msg_events.push(events::MessageSendEvent::SendTxSignatures {
82188221
node_id: *counterparty_node_id,

0 commit comments

Comments
 (0)