Skip to content

Commit 8e4879f

Browse files
committed
Handle re-establishment next_funding_txid
1 parent 7e8c3dd commit 8e4879f

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

lightning/src/ln/channel.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,6 +1450,10 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
14501450
/// If we can't release a [`ChannelMonitorUpdate`] until some external action completes, we
14511451
/// store it here and only release it to the `ChannelManager` once it asks for it.
14521452
blocked_monitor_updates: Vec<PendingChannelMonitorUpdate>,
1453+
// If we've sent `commtiment_signed` for an interactive transaction construction,
1454+
// but have not received `tx_signatures` we MUST set `next_funding_txid` to the
1455+
// txid of that interactive transaction, else we MUST NOT set it.
1456+
next_funding_txid: Option<Txid>,
14531457
}
14541458

14551459
#[cfg(any(dual_funding, splicing))]
@@ -2000,6 +2004,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
20002004
local_initiated_shutdown: None,
20012005

20022006
blocked_monitor_updates: Vec::new(),
2007+
next_funding_txid: None,
20032008
};
20042009

20052010
Ok(channel_context)
@@ -2223,6 +2228,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
22232228

22242229
blocked_monitor_updates: Vec::new(),
22252230
local_initiated_shutdown: None,
2231+
next_funding_txid: None,
22262232
})
22272233
}
22282234

@@ -4400,6 +4406,16 @@ impl<SP: Deref> Channel<SP> where
44004406
self.context.channel_state.clear_waiting_for_batch();
44014407
}
44024408

4409+
#[cfg(any(dual_funding, splicing))]
4410+
pub fn set_next_funding_txid(&mut self, txid: &Txid) {
4411+
self.context.next_funding_txid = Some(*txid);
4412+
}
4413+
4414+
#[cfg(any(dual_funding, splicing))]
4415+
pub fn clear_next_funding_txid(&mut self) {
4416+
self.context.next_funding_txid = None;
4417+
}
4418+
44034419
/// Unsets the existing funding information.
44044420
///
44054421
/// This must only be used if the channel has not yet completed funding and has not been used.
@@ -7440,10 +7456,7 @@ impl<SP: Deref> Channel<SP> where
74407456
next_remote_commitment_number: INITIAL_COMMITMENT_NUMBER - self.context.cur_counterparty_commitment_transaction_number - 1,
74417457
your_last_per_commitment_secret: remote_last_secret,
74427458
my_current_per_commitment_point: dummy_pubkey,
7443-
// TODO(dual_funding): If we've sent `commtiment_signed` for an interactive transaction
7444-
// construction but have not received `tx_signatures` we MUST set `next_funding_txid` to the
7445-
// txid of that interactive transaction, else we MUST NOT set it.
7446-
next_funding_txid: None,
7459+
next_funding_txid: self.context.next_funding_txid,
74477460
}
74487461
}
74497462

@@ -9425,6 +9438,7 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
94259438
(45, cur_holder_commitment_point, option),
94269439
(47, next_holder_commitment_point, option),
94279440
(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
9441+
(51, self.context.next_funding_txid, option), // Added in 0.0.124
94289442
});
94299443

94309444
Ok(())
@@ -10022,6 +10036,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1002210036
local_initiated_shutdown,
1002310037

1002410038
blocked_monitor_updates: blocked_monitor_updates.unwrap(),
10039+
// If we've sent `commtiment_signed` for an interactive transaction construction,
10040+
// but have not received `tx_signatures` we MUST set `next_funding_txid` to the
10041+
// txid of that interactive transaction, else we MUST NOT set it.
10042+
next_funding_txid: None,
1002510043
},
1002610044
#[cfg(any(dual_funding, splicing))]
1002710045
dual_funding_channel_context: None,

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7791,6 +7791,7 @@ where
77917791
peer_state.pending_msg_events.push(msg_send_event);
77927792
}
77937793
if let Some(signing_session) = signing_session_opt {
7794+
let funding_txid = signing_session.unsigned_tx.txid();
77947795
let (channel_id, channel_phase) = chan_phase_entry.remove_entry();
77957796
let res = match channel_phase {
77967797
ChannelPhase::UnfundedOutboundV2(chan) => {
@@ -7812,7 +7813,7 @@ where
78127813
.into()))),
78137814
};
78147815
match res {
7815-
Ok((channel, commitment_signed, funding_ready_for_sig_event_opt)) => {
7816+
Ok((mut channel, commitment_signed, funding_ready_for_sig_event_opt)) => {
78167817
if let Some(funding_ready_for_sig_event) = funding_ready_for_sig_event_opt {
78177818
let mut pending_events = self.pending_events.lock().unwrap();
78187819
pending_events.push_back((funding_ready_for_sig_event, None));
@@ -7828,6 +7829,7 @@ where
78287829
update_fee: None,
78297830
},
78307831
});
7832+
channel.set_next_funding_txid(&funding_txid);
78317833
peer_state.channel_by_id.insert(channel_id.clone(), ChannelPhase::Funded(channel));
78327834
},
78337835
Err((channel_phase, err)) => {
@@ -7863,6 +7865,7 @@ where
78637865
match channel_phase {
78647866
ChannelPhase::Funded(chan) => {
78657867
let (tx_signatures_opt, funding_tx_opt) = try_chan_phase_entry!(self, chan.tx_signatures(&msg), chan_phase_entry);
7868+
chan.clear_next_funding_txid();
78667869
if let Some(tx_signatures) = tx_signatures_opt {
78677870
peer_state.pending_msg_events.push(events::MessageSendEvent::SendTxSignatures {
78687871
node_id: *counterparty_node_id,

0 commit comments

Comments
 (0)