Skip to content

Commit cc2c3a2

Browse files
committed
Handle re-establishment next_funding_txid
1 parent a147e3a commit cc2c3a2

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
@@ -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 {
@@ -1993,6 +1997,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
19931997
blocked_monitor_updates: Vec::new(),
19941998

19951999
is_manual_broadcast: false,
2000+
2001+
next_funding_txid: None,
19962002
};
19972003

19982004
Ok(channel_context)
@@ -2224,6 +2230,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
22242230
blocked_monitor_updates: Vec::new(),
22252231
local_initiated_shutdown: None,
22262232
is_manual_broadcast: false,
2233+
next_funding_txid: None,
22272234
})
22282235
}
22292236

@@ -4400,6 +4407,14 @@ impl<SP: Deref> Channel<SP> where
44004407
self.context.channel_state.clear_waiting_for_batch();
44014408
}
44024409

4410+
pub fn set_next_funding_txid(&mut self, txid: &Txid) {
4411+
self.context.next_funding_txid = Some(*txid);
4412+
}
4413+
4414+
pub fn clear_next_funding_txid(&mut self) {
4415+
self.context.next_funding_txid = None;
4416+
}
4417+
44034418
/// Unsets the existing funding information.
44044419
///
44054420
/// This must only be used if the channel has not yet completed funding and has not been used.
@@ -7550,10 +7565,7 @@ impl<SP: Deref> Channel<SP> where
75507565
next_remote_commitment_number: INITIAL_COMMITMENT_NUMBER - self.context.cur_counterparty_commitment_transaction_number - 1,
75517566
your_last_per_commitment_secret: remote_last_secret,
75527567
my_current_per_commitment_point: dummy_pubkey,
7553-
// TODO(dual_funding): If we've sent `commtiment_signed` for an interactive transaction
7554-
// construction but have not received `tx_signatures` we MUST set `next_funding_txid` to the
7555-
// txid of that interactive transaction, else we MUST NOT set it.
7556-
next_funding_txid: None,
7568+
next_funding_txid: self.context.next_funding_txid,
75577569
}
75587570
}
75597571

@@ -9514,7 +9526,8 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
95149526
(47, next_holder_commitment_point, option),
95159527
(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
95169528
(51, is_manual_broadcast, option), // Added in 0.0.124
9517-
(53, funding_tx_broadcast_safe_event_emitted, option) // Added in 0.0.124
9529+
(53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
9530+
(55, self.context.next_funding_txid, option) // Added in 0.0.125
95189531
});
95199532

95209533
Ok(())
@@ -10123,6 +10136,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1012310136

1012410137
blocked_monitor_updates: blocked_monitor_updates.unwrap(),
1012510138
is_manual_broadcast: is_manual_broadcast.unwrap_or(false),
10139+
// If we've sent `commtiment_signed` for an interactive transaction construction,
10140+
// but have not received `tx_signatures` we MUST set `next_funding_txid` to the
10141+
// txid of that interactive transaction, else we MUST NOT set it.
10142+
next_funding_txid: None,
1012610143
},
1012710144
dual_funding_channel_context: None,
1012810145
interactive_tx_constructor: None,

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8110,6 +8110,7 @@ where
81108110
peer_state.pending_msg_events.push(msg_send_event);
81118111
};
81128112
if let Some(mut signing_session) = signing_session_opt {
8113+
let funding_txid = signing_session.unsigned_tx.txid();
81138114
match chan_phase_entry.get_mut() {
81148115
ChannelPhase::UnfundedOutboundV2(chan) => {
81158116
chan.funding_tx_constructed(&mut signing_session, &self.logger)
@@ -8136,7 +8137,8 @@ where
81368137
.into()))
81378138
}
81388139
}.map(|channel| (channel_id, channel, funding_ready_for_sig_event_opt, commitment_signed))
8139-
}).map(|(channel_id, channel, funding_ready_for_sig_event_opt, commitment_signed)| {
8140+
}).map(|(channel_id, mut channel, funding_ready_for_sig_event_opt, commitment_signed)| {
8141+
channel.set_next_funding_txid(&funding_txid);
81408142
peer_state.channel_by_id.insert(channel_id, ChannelPhase::Funded(channel));
81418143
if let Some(funding_ready_for_sig_event) = funding_ready_for_sig_event_opt {
81428144
let mut pending_events = self.pending_events.lock().unwrap();
@@ -8183,6 +8185,7 @@ where
81838185
match channel_phase {
81848186
ChannelPhase::Funded(chan) => {
81858187
let (tx_signatures_opt, funding_tx_opt) = try_chan_phase_entry!(self, chan.tx_signatures(msg), chan_phase_entry);
8188+
chan.clear_next_funding_txid();
81868189
if let Some(tx_signatures) = tx_signatures_opt {
81878190
peer_state.pending_msg_events.push(events::MessageSendEvent::SendTxSignatures {
81888191
node_id: *counterparty_node_id,

0 commit comments

Comments
 (0)