Skip to content

Commit 4b8e447

Browse files
committed
Handle re-establishment next_funding_txid
1 parent 72eaed3 commit 4b8e447

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
@@ -1562,6 +1562,10 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
15621562
/// If we can't release a [`ChannelMonitorUpdate`] until some external action completes, we
15631563
/// store it here and only release it to the `ChannelManager` once it asks for it.
15641564
blocked_monitor_updates: Vec<PendingChannelMonitorUpdate>,
1565+
// If we've sent `commtiment_signed` for an interactive transaction construction,
1566+
// but have not received `tx_signatures` we MUST set `next_funding_txid` to the
1567+
// txid of that interactive transaction, else we MUST NOT set it.
1568+
next_funding_txid: Option<Txid>,
15651569
}
15661570

15671571
#[cfg(any(dual_funding, splicing))]
@@ -2126,6 +2130,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
21262130
local_initiated_shutdown: None,
21272131

21282132
blocked_monitor_updates: Vec::new(),
2133+
next_funding_txid: None,
21292134
};
21302135

21312136
Ok(channel_context)
@@ -2346,6 +2351,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
23462351

23472352
blocked_monitor_updates: Vec::new(),
23482353
local_initiated_shutdown: None,
2354+
next_funding_txid: None,
23492355
})
23502356
}
23512357

@@ -4519,6 +4525,16 @@ impl<SP: Deref> Channel<SP> where
45194525
self.context.channel_state.clear_waiting_for_batch();
45204526
}
45214527

4528+
#[cfg(any(dual_funding, splicing))]
4529+
pub fn set_next_funding_txid(&mut self, txid: &Txid) {
4530+
self.context.next_funding_txid = Some(*txid);
4531+
}
4532+
4533+
#[cfg(any(dual_funding, splicing))]
4534+
pub fn clear_next_funding_txid(&mut self) {
4535+
self.context.next_funding_txid = None;
4536+
}
4537+
45224538
/// Unsets the existing funding information.
45234539
///
45244540
/// This must only be used if the channel has not yet completed funding and has not been used.
@@ -7505,10 +7521,7 @@ impl<SP: Deref> Channel<SP> where
75057521
next_remote_commitment_number: INITIAL_COMMITMENT_NUMBER - self.context.cur_counterparty_commitment_transaction_number - 1,
75067522
your_last_per_commitment_secret: remote_last_secret,
75077523
my_current_per_commitment_point: dummy_pubkey,
7508-
// TODO(dual_funding): If we've sent `commtiment_signed` for an interactive transaction
7509-
// construction but have not received `tx_signatures` we MUST set `next_funding_txid` to the
7510-
// txid of that interactive transaction, else we MUST NOT set it.
7511-
next_funding_txid: None,
7524+
next_funding_txid: self.context.next_funding_txid,
75127525
}
75137526
}
75147527

@@ -9435,6 +9448,7 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
94359448
(43, malformed_htlcs, optional_vec), // Added in 0.0.119
94369449
// 45 and 47 are reserved for async signing
94379450
(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
9451+
(51, self.context.next_funding_txid, option), // Added in 0.0.124
94389452
});
94399453

94409454
Ok(())
@@ -10010,6 +10024,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1001010024
local_initiated_shutdown,
1001110025

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

lightning/src/ln/channelmanager.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -8033,6 +8033,7 @@ where
80338033
peer_state.pending_msg_events.push(msg_send_event);
80348034
}
80358035
if let Some(signing_session) = signing_session_opt {
8036+
let funding_txid = signing_session.unsigned_tx.txid();
80368037
let (channel_id, channel_phase) = chan_phase_entry.remove_entry();
80378038
let res = match channel_phase {
80388039
ChannelPhase::UnfundedOutboundV2(chan) => {
@@ -8054,7 +8055,7 @@ where
80548055
.into()))),
80558056
};
80568057
match res {
8057-
Ok((channel, commitment_signed, funding_ready_for_sig_event_opt)) => {
8058+
Ok((mut channel, commitment_signed, funding_ready_for_sig_event_opt)) => {
80588059
if let Some(funding_ready_for_sig_event) = funding_ready_for_sig_event_opt {
80598060
let mut pending_events = self.pending_events.lock().unwrap();
80608061
pending_events.push_back((funding_ready_for_sig_event, None));
@@ -8070,6 +8071,7 @@ where
80708071
update_fee: None,
80718072
},
80728073
});
8074+
channel.set_next_funding_txid(&funding_txid);
80738075
peer_state.channel_by_id.insert(channel_id.clone(), ChannelPhase::Funded(channel));
80748076
},
80758077
Err((channel_phase, err)) => {
@@ -8105,6 +8107,7 @@ where
81058107
match channel_phase {
81068108
ChannelPhase::Funded(chan) => {
81078109
let (tx_signatures_opt, funding_tx_opt) = try_chan_phase_entry!(self, chan.tx_signatures(&msg), chan_phase_entry);
8110+
chan.clear_next_funding_txid();
81088111
if let Some(tx_signatures) = tx_signatures_opt {
81098112
peer_state.pending_msg_events.push(events::MessageSendEvent::SendTxSignatures {
81108113
node_id: *counterparty_node_id,

0 commit comments

Comments
 (0)