Skip to content

Commit 6dfce75

Browse files
committed
Handle re-establishment next_funding_txid
1 parent e9763aa commit 6dfce75

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
@@ -2146,6 +2150,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
21462150
blocked_monitor_updates: Vec::new(),
21472151

21482152
is_manual_broadcast: false,
2153+
2154+
next_funding_txid: None,
21492155
};
21502156

21512157
Ok(channel_context)
@@ -2377,6 +2383,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
23772383
blocked_monitor_updates: Vec::new(),
23782384
local_initiated_shutdown: None,
23792385
is_manual_broadcast: false,
2386+
next_funding_txid: None,
23802387
})
23812388
}
23822389

@@ -4579,6 +4586,14 @@ impl<SP: Deref> Channel<SP> where
45794586
self.context.channel_state.clear_waiting_for_batch();
45804587
}
45814588

4589+
pub fn set_next_funding_txid(&mut self, txid: &Txid) {
4590+
self.context.next_funding_txid = Some(*txid);
4591+
}
4592+
4593+
pub fn clear_next_funding_txid(&mut self) {
4594+
self.context.next_funding_txid = None;
4595+
}
4596+
45824597
/// Unsets the existing funding information.
45834598
///
45844599
/// This must only be used if the channel has not yet completed funding and has not been used.
@@ -7653,10 +7668,7 @@ impl<SP: Deref> Channel<SP> where
76537668
next_remote_commitment_number: INITIAL_COMMITMENT_NUMBER - self.context.cur_counterparty_commitment_transaction_number - 1,
76547669
your_last_per_commitment_secret: remote_last_secret,
76557670
my_current_per_commitment_point: dummy_pubkey,
7656-
// TODO(dual_funding): If we've sent `commtiment_signed` for an interactive transaction
7657-
// construction but have not received `tx_signatures` we MUST set `next_funding_txid` to the
7658-
// txid of that interactive transaction, else we MUST NOT set it.
7659-
next_funding_txid: None,
7671+
next_funding_txid: self.context.next_funding_txid,
76607672
}
76617673
}
76627674

@@ -9411,7 +9423,8 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
94119423
(47, next_holder_commitment_point, option),
94129424
(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
94139425
(51, is_manual_broadcast, option), // Added in 0.0.124
9414-
(53, funding_tx_broadcast_safe_event_emitted, option) // Added in 0.0.124
9426+
(53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
9427+
(55, self.context.next_funding_txid, option) // Added in 0.0.125
94159428
});
94169429

94179430
Ok(())
@@ -9701,6 +9714,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
97019714
let mut channel_pending_event_emitted = None;
97029715
let mut channel_ready_event_emitted = None;
97039716
let mut funding_tx_broadcast_safe_event_emitted = None;
9717+
let mut next_funding_txid = None;
97049718

97059719
let mut user_id_high_opt: Option<u64> = None;
97069720
let mut channel_keys_id: Option<[u8; 32]> = None;
@@ -9761,6 +9775,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
97619775
(49, local_initiated_shutdown, option),
97629776
(51, is_manual_broadcast, option),
97639777
(53, funding_tx_broadcast_safe_event_emitted, option),
9778+
(55, next_funding_txid, option) // Added in 0.0.125
97649779
});
97659780

97669781
let (channel_keys_id, holder_signer) = if let Some(channel_keys_id) = channel_keys_id {
@@ -10020,6 +10035,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1002010035

1002110036
blocked_monitor_updates: blocked_monitor_updates.unwrap(),
1002210037
is_manual_broadcast: is_manual_broadcast.unwrap_or(false),
10038+
// If we've sent `commtiment_signed` for an interactive transaction construction,
10039+
// but have not received `tx_signatures` we MUST set `next_funding_txid` to the
10040+
// txid of that interactive transaction, else we MUST NOT set it.
10041+
next_funding_txid,
1002310042
},
1002410043
interactive_tx_signing_session: None,
1002510044
})

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)