Skip to content

Commit 6f0e551

Browse files
committed
Handle re-establishment next_funding_txid
1 parent 6e8fd90 commit 6f0e551

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

lightning/src/ln/channel.rs

+22-4
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))]
@@ -1999,6 +2003,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
19992003
local_initiated_shutdown: None,
20002004

20012005
blocked_monitor_updates: Vec::new(),
2006+
next_funding_txid: None,
20022007
};
20032008

20042009
Ok(channel_context)
@@ -2222,6 +2227,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
22222227

22232228
blocked_monitor_updates: Vec::new(),
22242229
local_initiated_shutdown: None,
2230+
next_funding_txid: None,
22252231
})
22262232
}
22272233

@@ -4393,6 +4399,16 @@ impl<SP: Deref> Channel<SP> where
43934399
self.context.channel_state.clear_waiting_for_batch();
43944400
}
43954401

4402+
#[cfg(any(dual_funding, splicing))]
4403+
pub fn set_next_funding_txid(&mut self, txid: &Txid) {
4404+
self.context.next_funding_txid = Some(*txid);
4405+
}
4406+
4407+
#[cfg(any(dual_funding, splicing))]
4408+
pub fn clear_next_funding_txid(&mut self) {
4409+
self.context.next_funding_txid = None;
4410+
}
4411+
43964412
/// Unsets the existing funding information.
43974413
///
43984414
/// This must only be used if the channel has not yet completed funding and has not been used.
@@ -7433,10 +7449,7 @@ impl<SP: Deref> Channel<SP> where
74337449
next_remote_commitment_number: INITIAL_COMMITMENT_NUMBER - self.context.cur_counterparty_commitment_transaction_number - 1,
74347450
your_last_per_commitment_secret: remote_last_secret,
74357451
my_current_per_commitment_point: dummy_pubkey,
7436-
// TODO(dual_funding): If we've sent `commtiment_signed` for an interactive transaction
7437-
// construction but have not received `tx_signatures` we MUST set `next_funding_txid` to the
7438-
// txid of that interactive transaction, else we MUST NOT set it.
7439-
next_funding_txid: None,
7452+
next_funding_txid: self.context.next_funding_txid,
74407453
}
74417454
}
74427455

@@ -9415,6 +9428,7 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
94159428
(45, cur_holder_commitment_point, option),
94169429
(47, next_holder_commitment_point, option),
94179430
(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
9431+
(51, self.context.next_funding_txid, option), // Added in 0.0.124
94189432
});
94199433

94209434
Ok(())
@@ -10012,6 +10026,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1001210026
local_initiated_shutdown,
1001310027

1001410028
blocked_monitor_updates: blocked_monitor_updates.unwrap(),
10029+
// If we've sent `commtiment_signed` for an interactive transaction construction,
10030+
// but have not received `tx_signatures` we MUST set `next_funding_txid` to the
10031+
// txid of that interactive transaction, else we MUST NOT set it.
10032+
next_funding_txid: None,
1001510033
},
1001610034
#[cfg(any(dual_funding, splicing))]
1001710035
dual_funding_channel_context: None,

lightning/src/ln/channelmanager.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -7774,6 +7774,7 @@ where
77747774
peer_state.pending_msg_events.push(msg_send_event);
77757775
}
77767776
if let Some(signing_session) = signing_session_opt {
7777+
let funding_txid = signing_session.unsigned_tx.txid();
77777778
let (channel_id, channel_phase) = chan_phase_entry.remove_entry();
77787779
let res = match channel_phase {
77797780
ChannelPhase::UnfundedOutboundV2(chan) => {
@@ -7795,7 +7796,7 @@ where
77957796
.into()))),
77967797
};
77977798
match res {
7798-
Ok((channel, commitment_signed, funding_ready_for_sig_event_opt)) => {
7799+
Ok((mut channel, commitment_signed, funding_ready_for_sig_event_opt)) => {
77997800
if let Some(funding_ready_for_sig_event) = funding_ready_for_sig_event_opt {
78007801
let mut pending_events = self.pending_events.lock().unwrap();
78017802
pending_events.push_back((funding_ready_for_sig_event, None));
@@ -7811,6 +7812,7 @@ where
78117812
update_fee: None,
78127813
},
78137814
});
7815+
channel.set_next_funding_txid(&funding_txid);
78147816
peer_state.channel_by_id.insert(channel_id.clone(), ChannelPhase::Funded(channel));
78157817
},
78167818
Err((channel_phase, err)) => {
@@ -7846,6 +7848,7 @@ where
78467848
match channel_phase {
78477849
ChannelPhase::Funded(chan) => {
78487850
let (tx_signatures_opt, funding_tx_opt) = try_chan_phase_entry!(self, chan.tx_signatures(&msg), chan_phase_entry);
7851+
chan.clear_next_funding_txid();
78497852
if let Some(tx_signatures) = tx_signatures_opt {
78507853
peer_state.pending_msg_events.push(events::MessageSendEvent::SendTxSignatures {
78517854
node_id: *counterparty_node_id,

0 commit comments

Comments
 (0)