Skip to content

Commit 1b2ae3b

Browse files
committed
Get next_funding_txid from the funding_outpoint based on state
Instead of having an explicit `ChannelContext::next_funding_txid` to set and read, we can get this value on the fly when it is appropriate to do so.
1 parent 46cb5ff commit 1b2ae3b

File tree

3 files changed

+34
-35
lines changed

3 files changed

+34
-35
lines changed

lightning/src/ln/channel.rs

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::ln::types::ChannelId;
3030
use crate::types::payment::{PaymentPreimage, PaymentHash};
3131
use crate::types::features::{ChannelTypeFeatures, InitFeatures};
3232
use crate::ln::interactivetxs::{
33-
calculate_change_output_value, get_output_weight, AbortReason, HandleTxCompleteValue, HandleTxCompleteResult, InteractiveTxConstructor,
33+
calculate_change_output_value, get_output_weight, AbortReason, HandleTxCompleteResult, InteractiveTxConstructor,
3434
InteractiveTxConstructorArgs, InteractiveTxMessageSend, InteractiveTxSigningSession, InteractiveTxMessageSendResult,
3535
OutputOwned, SharedOwnedOutput, TX_COMMON_FIELDS_WEIGHT,
3636
};
@@ -2082,22 +2082,6 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
20822082
/// store it here and only release it to the `ChannelManager` once it asks for it.
20832083
blocked_monitor_updates: Vec<PendingChannelMonitorUpdate>,
20842084

2085-
// The `next_funding_txid` field allows peers to finalize the signing steps of an interactive
2086-
// transaction construction, or safely abort that transaction if it was not signed by one of the
2087-
// peers, who has thus already removed it from its state.
2088-
//
2089-
// If we've sent `commtiment_signed` for an interactively constructed transaction
2090-
// during a signing session, but have not received `tx_signatures` we MUST set `next_funding_txid`
2091-
// to the txid of that interactive transaction, else we MUST NOT set it.
2092-
//
2093-
// See the spec for further details on this:
2094-
// * `channel_reestablish`-sending node: https://github.com/lightning/bolts/blob/247e83d/02-peer-protocol.md?plain=1#L2466-L2470
2095-
// * `channel_reestablish`-receiving node: https://github.com/lightning/bolts/blob/247e83d/02-peer-protocol.md?plain=1#L2520-L2531
2096-
//
2097-
// TODO(dual_funding): Persist this when we actually contribute funding inputs. For now we always
2098-
// send an empty witnesses array in `tx_signatures` as a V2 channel acceptor
2099-
next_funding_txid: Option<Txid>,
2100-
21012085
/// Only set when a counterparty `stfu` has been processed to track which node is allowed to
21022086
/// propose "something fundamental" upon becoming quiescent.
21032087
is_holder_quiescence_initiator: Option<bool>,
@@ -2445,10 +2429,6 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
24452429
}
24462430
};
24472431

2448-
if let HandleTxCompleteValue::SendTxComplete(_, ref signing_session) = tx_complete {
2449-
self.context.next_funding_txid = Some(signing_session.unsigned_tx.compute_txid());
2450-
};
2451-
24522432
HandleTxCompleteResult(Ok(tx_complete))
24532433
}
24542434

@@ -2884,8 +2864,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
28842864

28852865
is_manual_broadcast: false,
28862866

2887-
next_funding_txid: None,
2888-
28892867
is_holder_quiescence_initiator: None,
28902868
};
28912869

@@ -3117,7 +3095,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
31173095
blocked_monitor_updates: Vec::new(),
31183096
local_initiated_shutdown: None,
31193097
is_manual_broadcast: false,
3120-
next_funding_txid: None,
31213098

31223099
is_holder_quiescence_initiator: None,
31233100
};
@@ -6497,7 +6474,6 @@ impl<SP: Deref> FundedChannel<SP> where
64976474
// We have a finalized funding transaction, so we can set the funding transaction and reset the
64986475
// signing session fields.
64996476
self.funding.funding_transaction = funding_tx_opt;
6500-
self.context.next_funding_txid = None;
65016477
self.interactive_tx_signing_session = None;
65026478
}
65036479

@@ -8551,6 +8527,25 @@ impl<SP: Deref> FundedChannel<SP> where
85518527
self.sign_channel_announcement(node_signer, announcement).ok()
85528528
}
85538529

8530+
fn maybe_get_next_funding_txid(&self) -> Option<Txid> {
8531+
// If we've sent `commtiment_signed` for an interactively constructed transaction
8532+
// during a signing session, but have not received `tx_signatures` we MUST set `next_funding_txid`
8533+
// to the txid of that interactive transaction, else we MUST NOT set it.
8534+
if let Some(signing_session) = &self.interactive_tx_signing_session {
8535+
// Since we have a signing_session, this implies we've sent an initial `commitment_signed`...
8536+
if !signing_session.counterparty_sent_tx_signatures {
8537+
// ...but we didn't receive a `tx_signatures` from the counterparty yet.
8538+
Some(self.funding_outpoint().txid)
8539+
} else {
8540+
// ...and we received a `tx_signatures` from the counterparty.
8541+
None
8542+
}
8543+
} else {
8544+
// We don't have an active signing session.
8545+
None
8546+
}
8547+
}
8548+
85548549
/// May panic if called on a channel that wasn't immediately-previously
85558550
/// self.remove_uncommitted_htlcs_and_mark_paused()'d
85568551
fn get_channel_reestablish<L: Deref>(&mut self, logger: &L) -> msgs::ChannelReestablish where L::Target: Logger {
@@ -8600,7 +8595,7 @@ impl<SP: Deref> FundedChannel<SP> where
86008595
next_remote_commitment_number: INITIAL_COMMITMENT_NUMBER - self.context.cur_counterparty_commitment_transaction_number - 1,
86018596
your_last_per_commitment_secret: remote_last_secret,
86028597
my_current_per_commitment_point: dummy_pubkey,
8603-
next_funding_txid: self.context.next_funding_txid,
8598+
next_funding_txid: self.maybe_get_next_funding_txid(),
86048599
}
86058600
}
86068601

@@ -11438,14 +11433,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1143811433
blocked_monitor_updates: blocked_monitor_updates.unwrap(),
1143911434
is_manual_broadcast: is_manual_broadcast.unwrap_or(false),
1144011435

11441-
// TODO(dual_funding): Instead of getting this from persisted value, figure it out based on the
11442-
// funding transaction and other channel state.
11443-
//
11444-
// If we've sent `commtiment_signed` for an interactively constructed transaction
11445-
// during a signing session, but have not received `tx_signatures` we MUST set `next_funding_txid`
11446-
// to the txid of that interactive transaction, else we MUST NOT set it.
11447-
next_funding_txid: None,
11448-
1144911436
is_holder_quiescence_initiator: None,
1145011437
},
1145111438
interactive_tx_signing_session: None,

lightning/src/ln/interactivetxs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,10 @@ impl ConstructedTransaction {
310310
#[derive(Debug, Clone, PartialEq)]
311311
pub(crate) struct InteractiveTxSigningSession {
312312
pub unsigned_tx: ConstructedTransaction,
313+
pub counterparty_sent_tx_signatures: bool,
313314
holder_sends_tx_signatures_first: bool,
314315
received_commitment_signed: bool,
315316
holder_tx_signatures: Option<TxSignatures>,
316-
counterparty_sent_tx_signatures: bool,
317317
}
318318

319319
impl InteractiveTxSigningSession {

lightning/src/ln/msgs.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,18 @@ pub struct ChannelReestablish {
857857
/// The sender's per-commitment point for their current commitment transaction
858858
pub my_current_per_commitment_point: PublicKey,
859859
/// The next funding transaction ID
860+
///
861+
/// Allows peers to finalize the signing steps of an interactive transaction construction, or
862+
/// safely abort that transaction if it was not signed by one of the peers, who has thus already
863+
/// removed it from its state.
864+
///
865+
/// If we've sent `commtiment_signed` for an interactively constructed transaction
866+
/// during a signing session, but have not received `tx_signatures` we MUST set `next_funding_txid`
867+
/// to the txid of that interactive transaction, else we MUST NOT set it.
868+
///
869+
/// See the spec for further details on this:
870+
/// * `channel_reestablish`-sending node: https:///github.com/lightning/bolts/blob/247e83d/02-peer-protocol.md?plain=1#L2466-L2470
871+
/// * `channel_reestablish`-receiving node: https:///github.com/lightning/bolts/blob/247e83d/02-peer-protocol.md?plain=1#L2520-L2531
860872
pub next_funding_txid: Option<Txid>,
861873
}
862874

0 commit comments

Comments
 (0)