Skip to content

Commit 5a8dbb4

Browse files
committed
Handle re-establishment next_funding_txid
1 parent fe2e15a commit 5a8dbb4

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
/// A channel struct implementing this trait can receive an initial counterparty commitment
@@ -2148,6 +2152,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
21482152
blocked_monitor_updates: Vec::new(),
21492153

21502154
is_manual_broadcast: false,
2155+
2156+
next_funding_txid: None,
21512157
};
21522158

21532159
Ok(channel_context)
@@ -2379,6 +2385,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
23792385
blocked_monitor_updates: Vec::new(),
23802386
local_initiated_shutdown: None,
23812387
is_manual_broadcast: false,
2388+
next_funding_txid: None,
23822389
})
23832390
}
23842391

@@ -4584,6 +4591,14 @@ impl<SP: Deref> Channel<SP> where
45844591
self.context.channel_state.clear_waiting_for_batch();
45854592
}
45864593

4594+
pub fn set_next_funding_txid(&mut self, txid: &Txid) {
4595+
self.context.next_funding_txid = Some(*txid);
4596+
}
4597+
4598+
pub fn clear_next_funding_txid(&mut self) {
4599+
self.context.next_funding_txid = None;
4600+
}
4601+
45874602
/// Unsets the existing funding information.
45884603
///
45894604
/// This must only be used if the channel has not yet completed funding and has not been used.
@@ -7665,10 +7680,7 @@ impl<SP: Deref> Channel<SP> where
76657680
next_remote_commitment_number: INITIAL_COMMITMENT_NUMBER - self.context.cur_counterparty_commitment_transaction_number - 1,
76667681
your_last_per_commitment_secret: remote_last_secret,
76677682
my_current_per_commitment_point: dummy_pubkey,
7668-
// TODO(dual_funding): If we've sent `commtiment_signed` for an interactive transaction
7669-
// construction but have not received `tx_signatures` we MUST set `next_funding_txid` to the
7670-
// txid of that interactive transaction, else we MUST NOT set it.
7671-
next_funding_txid: None,
7683+
next_funding_txid: self.context.next_funding_txid,
76727684
}
76737685
}
76747686

@@ -9450,7 +9462,8 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
94509462
(47, next_holder_commitment_point, option),
94519463
(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
94529464
(51, is_manual_broadcast, option), // Added in 0.0.124
9453-
(53, funding_tx_broadcast_safe_event_emitted, option) // Added in 0.0.124
9465+
(53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
9466+
(55, self.context.next_funding_txid, option) // Added in 0.0.125
94549467
});
94559468

94569469
Ok(())
@@ -9740,6 +9753,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
97409753
let mut channel_pending_event_emitted = None;
97419754
let mut channel_ready_event_emitted = None;
97429755
let mut funding_tx_broadcast_safe_event_emitted = None;
9756+
let mut next_funding_txid = None;
97439757

97449758
let mut user_id_high_opt: Option<u64> = None;
97459759
let mut channel_keys_id: Option<[u8; 32]> = None;
@@ -9800,6 +9814,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
98009814
(49, local_initiated_shutdown, option),
98019815
(51, is_manual_broadcast, option),
98029816
(53, funding_tx_broadcast_safe_event_emitted, option),
9817+
(55, next_funding_txid, option) // Added in 0.0.125
98039818
});
98049819

98059820
let (channel_keys_id, holder_signer) = if let Some(channel_keys_id) = channel_keys_id {
@@ -10059,6 +10074,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1005910074

1006010075
blocked_monitor_updates: blocked_monitor_updates.unwrap(),
1006110076
is_manual_broadcast: is_manual_broadcast.unwrap_or(false),
10077+
// If we've sent `commtiment_signed` for an interactive transaction construction,
10078+
// but have not received `tx_signatures` we MUST set `next_funding_txid` to the
10079+
// txid of that interactive transaction, else we MUST NOT set it.
10080+
next_funding_txid,
1006210081
},
1006310082
dual_funding_channel_context: None,
1006410083
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)