Skip to content

Commit aafabfa

Browse files
committed
Handle re-establishment next_funding_txid
1 parent 4bcbbb9 commit aafabfa

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

lightning/src/ln/channel.rs

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

14971501
pub(super) trait InteractivelyFunded<SP: Deref> where SP::Target: SignerProvider {
@@ -1992,6 +1996,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
19921996
blocked_monitor_updates: Vec::new(),
19931997

19941998
is_manual_broadcast: false,
1999+
2000+
next_funding_txid: None,
19952001
};
19962002

19972003
Ok(channel_context)
@@ -2223,6 +2229,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
22232229
blocked_monitor_updates: Vec::new(),
22242230
local_initiated_shutdown: None,
22252231
is_manual_broadcast: false,
2232+
next_funding_txid: None,
22262233
})
22272234
}
22282235

@@ -4426,6 +4433,14 @@ impl<SP: Deref> Channel<SP> where
44264433
self.context.channel_state.clear_waiting_for_batch();
44274434
}
44284435

4436+
pub fn set_next_funding_txid(&mut self, txid: &Txid) {
4437+
self.context.next_funding_txid = Some(*txid);
4438+
}
4439+
4440+
pub fn clear_next_funding_txid(&mut self) {
4441+
self.context.next_funding_txid = None;
4442+
}
4443+
44294444
/// Unsets the existing funding information.
44304445
///
44314446
/// This must only be used if the channel has not yet completed funding and has not been used.
@@ -7569,10 +7584,7 @@ impl<SP: Deref> Channel<SP> where
75697584
next_remote_commitment_number: INITIAL_COMMITMENT_NUMBER - self.context.cur_counterparty_commitment_transaction_number - 1,
75707585
your_last_per_commitment_secret: remote_last_secret,
75717586
my_current_per_commitment_point: dummy_pubkey,
7572-
// TODO(dual_funding): If we've sent `commtiment_signed` for an interactive transaction
7573-
// construction but have not received `tx_signatures` we MUST set `next_funding_txid` to the
7574-
// txid of that interactive transaction, else we MUST NOT set it.
7575-
next_funding_txid: None,
7587+
next_funding_txid: self.context.next_funding_txid,
75767588
}
75777589
}
75787590

@@ -9475,7 +9487,8 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
94759487
(47, next_holder_commitment_point, option),
94769488
(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
94779489
(51, is_manual_broadcast, option), // Added in 0.0.124
9478-
(53, funding_tx_broadcast_safe_event_emitted, option) // Added in 0.0.124
9490+
(53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
9491+
(55, self.context.next_funding_txid, option) // Added in 0.0.125
94799492
});
94809493

94819494
Ok(())
@@ -10084,6 +10097,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1008410097

1008510098
blocked_monitor_updates: blocked_monitor_updates.unwrap(),
1008610099
is_manual_broadcast: is_manual_broadcast.unwrap_or(false),
10100+
// If we've sent `commtiment_signed` for an interactive transaction construction,
10101+
// but have not received `tx_signatures` we MUST set `next_funding_txid` to the
10102+
// txid of that interactive transaction, else we MUST NOT set it.
10103+
next_funding_txid: None,
1008710104
},
1008810105
dual_funding_channel_context: None,
1008910106
interactive_tx_constructor: None,

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8063,6 +8063,7 @@ where
80638063
peer_state.pending_msg_events.push(msg_send_event);
80648064
};
80658065
if let Some(mut signing_session) = signing_session_opt {
8066+
let funding_txid = signing_session.unsigned_tx.txid();
80668067
let (commitment_signed, funding_ready_for_sig_event_opt) = match chan_phase_entry.get_mut() {
80678068
ChannelPhase::UnfundedOutboundV2(chan) => {
80688069
chan.funding_tx_constructed(&mut signing_session, &self.logger)
@@ -8075,7 +8076,7 @@ where
80758076
.into())),
80768077
}.map_err(|err| MsgHandleErrInternal::send_err_msg_no_close(format!("{}", err), msg.channel_id))?;
80778078
let (channel_id, channel_phase) = chan_phase_entry.remove_entry();
8078-
let channel = match channel_phase {
8079+
let mut channel = match channel_phase {
80798080
ChannelPhase::UnfundedOutboundV2(chan) => chan.into_channel(signing_session),
80808081
ChannelPhase::UnfundedInboundV2(chan) => chan.into_channel(signing_session),
80818082
_ => {
@@ -8085,6 +8086,7 @@ where
80858086
.into()))
80868087
},
80878088
}.map_err(|err| MsgHandleErrInternal::send_err_msg_no_close(format!("{}", err), msg.channel_id))?;
8089+
channel.set_next_funding_txid(&funding_txid);
80888090
peer_state.channel_by_id.insert(channel_id, ChannelPhase::Funded(channel));
80898091
if let Some(funding_ready_for_sig_event) = funding_ready_for_sig_event_opt {
80908092
let mut pending_events = self.pending_events.lock().unwrap();
@@ -8128,6 +8130,7 @@ where
81288130
match channel_phase {
81298131
ChannelPhase::Funded(chan) => {
81308132
let (tx_signatures_opt, funding_tx_opt) = try_chan_phase_entry!(self, chan.tx_signatures(msg), chan_phase_entry);
8133+
chan.clear_next_funding_txid();
81318134
if let Some(tx_signatures) = tx_signatures_opt {
81328135
peer_state.pending_msg_events.push(events::MessageSendEvent::SendTxSignatures {
81338136
node_id: *counterparty_node_id,

0 commit comments

Comments
 (0)