Skip to content

Commit 0ea629a

Browse files
committed
Handle re-establishment next_funding_txid
1 parent 7d4fed7 commit 0ea629a

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

lightning/src/ln/channel.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,10 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
14361436
/// If we can't release a [`ChannelMonitorUpdate`] until some external action completes, we
14371437
/// store it here and only release it to the `ChannelManager` once it asks for it.
14381438
blocked_monitor_updates: Vec<PendingChannelMonitorUpdate>,
1439+
// If we've sent `commtiment_signed` for an interactive transaction construction,
1440+
// but have not received `tx_signatures` we MUST set `next_funding_txid` to the
1441+
// txid of that interactive transaction, else we MUST NOT set it.
1442+
next_funding_txid: Option<Txid>,
14391443
}
14401444

14411445
pub(super) trait InteractivelyFunded<SP: Deref> where SP::Target: SignerProvider {
@@ -1975,6 +1979,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
19751979
local_initiated_shutdown: None,
19761980

19771981
blocked_monitor_updates: Vec::new(),
1982+
next_funding_txid: None,
19781983
};
19791984

19801985
Ok(channel_context)
@@ -2198,6 +2203,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
21982203

21992204
blocked_monitor_updates: Vec::new(),
22002205
local_initiated_shutdown: None,
2206+
next_funding_txid: None,
22012207
})
22022208
}
22032209

@@ -4370,6 +4376,14 @@ impl<SP: Deref> Channel<SP> where
43704376
self.context.channel_state.clear_waiting_for_batch();
43714377
}
43724378

4379+
pub fn set_next_funding_txid(&mut self, txid: &Txid) {
4380+
self.context.next_funding_txid = Some(*txid);
4381+
}
4382+
4383+
pub fn clear_next_funding_txid(&mut self) {
4384+
self.context.next_funding_txid = None;
4385+
}
4386+
43734387
/// Unsets the existing funding information.
43744388
///
43754389
/// This must only be used if the channel has not yet completed funding and has not been used.
@@ -7397,10 +7411,7 @@ impl<SP: Deref> Channel<SP> where
73977411
next_remote_commitment_number: INITIAL_COMMITMENT_NUMBER - self.context.cur_counterparty_commitment_transaction_number - 1,
73987412
your_last_per_commitment_secret: remote_last_secret,
73997413
my_current_per_commitment_point: dummy_pubkey,
7400-
// TODO(dual_funding): If we've sent `commtiment_signed` for an interactive transaction
7401-
// construction but have not received `tx_signatures` we MUST set `next_funding_txid` to the
7402-
// txid of that interactive transaction, else we MUST NOT set it.
7403-
next_funding_txid: None,
7414+
next_funding_txid: self.context.next_funding_txid,
74047415
}
74057416
}
74067417

@@ -9314,6 +9325,7 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
93149325
(45, cur_holder_commitment_point, option),
93159326
(47, next_holder_commitment_point, option),
93169327
(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
9328+
(51, self.context.next_funding_txid, option), // Added in 0.0.124
93179329
});
93189330

93199331
Ok(())
@@ -9911,6 +9923,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
99119923
local_initiated_shutdown,
99129924

99139925
blocked_monitor_updates: blocked_monitor_updates.unwrap(),
9926+
// If we've sent `commtiment_signed` for an interactive transaction construction,
9927+
// but have not received `tx_signatures` we MUST set `next_funding_txid` to the
9928+
// txid of that interactive transaction, else we MUST NOT set it.
9929+
next_funding_txid: None,
99149930
},
99159931
dual_funding_channel_context: None,
99169932
interactive_tx_constructor: None,

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7566,6 +7566,7 @@ where
75667566
peer_state.pending_msg_events.push(msg_send_event);
75677567
}
75687568
if let Some(signing_session) = signing_session_opt {
7569+
let funding_txid = signing_session.unsigned_tx.txid();
75697570
let (channel_id, channel_phase) = chan_phase_entry.remove_entry();
75707571
let res = match channel_phase {
75717572
ChannelPhase::UnfundedOutboundV2(chan) => {
@@ -7587,7 +7588,7 @@ where
75877588
.into()))),
75887589
};
75897590
match res {
7590-
Ok((channel, commitment_signed, funding_ready_for_sig_event_opt)) => {
7591+
Ok((mut channel, commitment_signed, funding_ready_for_sig_event_opt)) => {
75917592
if let Some(funding_ready_for_sig_event) = funding_ready_for_sig_event_opt {
75927593
let mut pending_events = self.pending_events.lock().unwrap();
75937594
pending_events.push_back((funding_ready_for_sig_event, None));
@@ -7603,6 +7604,7 @@ where
76037604
update_fee: None,
76047605
},
76057606
});
7607+
channel.set_next_funding_txid(&funding_txid);
76067608
peer_state.channel_by_id.insert(channel_id.clone(), ChannelPhase::Funded(channel));
76077609
},
76087610
Err((channel_phase, err)) => {
@@ -7637,6 +7639,7 @@ where
76377639
match channel_phase {
76387640
ChannelPhase::Funded(chan) => {
76397641
let (tx_signatures_opt, funding_tx_opt) = try_chan_phase_entry!(self, chan.tx_signatures(&msg), chan_phase_entry);
7642+
chan.clear_next_funding_txid();
76407643
if let Some(tx_signatures) = tx_signatures_opt {
76417644
peer_state.pending_msg_events.push(events::MessageSendEvent::SendTxSignatures {
76427645
node_id: *counterparty_node_id,

0 commit comments

Comments
 (0)