Skip to content

Commit 470dd2c

Browse files
committed
Move interactive signing session into ChannelContext
Since the `InteractiveTxSigningSession` already tracks everything we need, we can remove the duplicate interactive signing state tracking within `ChannelState`.
1 parent 1644a78 commit 470dd2c

File tree

2 files changed

+37
-39
lines changed

2 files changed

+37
-39
lines changed

lightning/src/ln/channel.rs

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,21 +1969,19 @@ where
19691969
let logger = WithChannelContext::from(logger, self.context(), None);
19701970
match &mut self.phase {
19711971
ChannelPhase::UnfundedV2(chan) => {
1972-
let mut signing_session = chan
1972+
let signing_session = chan
19731973
.interactive_tx_constructor
19741974
.take()
19751975
.expect("PendingV2Channel::interactive_tx_constructor should be set")
19761976
.into_signing_session();
19771977
let commitment_signed = chan.context.funding_tx_constructed(
19781978
&mut chan.funding,
1979-
&mut signing_session,
1979+
signing_session,
19801980
false,
19811981
chan.unfunded_context.transaction_number(),
19821982
&&logger,
19831983
)?;
19841984

1985-
chan.interactive_tx_signing_session = Some(signing_session);
1986-
19871985
return Ok(commitment_signed);
19881986
},
19891987
ChannelPhase::Funded(chan) => {
@@ -1994,17 +1992,15 @@ where
19941992
interactive_tx_constructor,
19951993
} = funding_negotiation
19961994
{
1997-
let mut signing_session =
1998-
interactive_tx_constructor.into_signing_session();
1995+
let signing_session = interactive_tx_constructor.into_signing_session();
19991996
let commitment_signed = chan.context.funding_tx_constructed(
20001997
&mut funding,
2001-
&mut signing_session,
1998+
signing_session,
20021999
true,
20032000
chan.holder_commitment_point.next_transaction_number(),
20042001
&&logger,
20052002
)?;
20062003

2007-
chan.interactive_tx_signing_session = Some(signing_session);
20082004
pending_splice.funding_negotiation =
20092005
Some(FundingNegotiation::AwaitingSignatures { funding });
20102006

@@ -2057,7 +2053,6 @@ where
20572053
let mut funded_channel = FundedChannel {
20582054
funding: chan.funding,
20592055
context: chan.context,
2060-
interactive_tx_signing_session: chan.interactive_tx_signing_session,
20612056
holder_commitment_point,
20622057
pending_splice: None,
20632058
quiescent_action: None,
@@ -2082,6 +2077,7 @@ where
20822077
.map(|funding_negotiation| funding_negotiation.as_funding().is_some())
20832078
.unwrap_or(false);
20842079
let session_received_commitment_signed = funded_channel
2080+
.context
20852081
.interactive_tx_signing_session
20862082
.as_ref()
20872083
.map(|session| session.has_received_commitment_signed())
@@ -2993,6 +2989,16 @@ where
29932989
/// If we can't release a [`ChannelMonitorUpdate`] until some external action completes, we
29942990
/// store it here and only release it to the `ChannelManager` once it asks for it.
29952991
blocked_monitor_updates: Vec<PendingChannelMonitorUpdate>,
2992+
2993+
/// The signing session for the current interactive tx construction, if any.
2994+
///
2995+
/// This is populated when the interactive tx construction phase completes
2996+
/// (i.e., upon receiving a consecutive `tx_complete`) and the channel enters
2997+
/// the signing phase (`FundingNegotiated` state with the `INTERACTIVE_SIGNING` flag set).
2998+
///
2999+
/// This field is cleared once our counterparty sends a `channel_ready` or upon splice funding
3000+
/// promotion.
3001+
pub interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
29963002
}
29973003

29983004
/// A channel struct implementing this trait can receive an initial counterparty commitment
@@ -3567,6 +3573,8 @@ where
35673573
blocked_monitor_updates: Vec::new(),
35683574

35693575
is_manual_broadcast: false,
3576+
3577+
interactive_tx_signing_session: None,
35703578
};
35713579

35723580
Ok((funding, channel_context))
@@ -3803,6 +3811,8 @@ where
38033811
blocked_monitor_updates: Vec::new(),
38043812
local_initiated_shutdown: None,
38053813
is_manual_broadcast: false,
3814+
3815+
interactive_tx_signing_session: None,
38063816
};
38073817

38083818
Ok((funding, channel_context))
@@ -6112,7 +6122,7 @@ where
61126122

61136123
#[rustfmt::skip]
61146124
fn funding_tx_constructed<L: Deref>(
6115-
&mut self, funding: &mut FundingScope, signing_session: &mut InteractiveTxSigningSession,
6125+
&mut self, funding: &mut FundingScope, signing_session: InteractiveTxSigningSession,
61166126
is_splice: bool, holder_commitment_transaction_number: u64, logger: &L
61176127
) -> Result<msgs::CommitmentSigned, AbortReason>
61186128
where
@@ -6135,7 +6145,7 @@ where
61356145
};
61366146
funding
61376147
.channel_transaction_parameters.funding_outpoint = Some(outpoint);
6138-
6148+
self.interactive_tx_signing_session = Some(signing_session);
61396149
self.channel_state = ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
61406150
self.channel_state.set_interactive_signing();
61416151

@@ -6226,7 +6236,7 @@ where
62266236
}
62276237

62286238
fn get_initial_commitment_signed_v2<L: Deref>(
6229-
&mut self, funding: &FundingScope, logger: &L,
6239+
&self, funding: &FundingScope, logger: &L,
62306240
) -> Option<msgs::CommitmentSigned>
62316241
where
62326242
SP::Target: SignerProvider,
@@ -6668,14 +6678,6 @@ where
66686678
{
66696679
pub funding: FundingScope,
66706680
pub context: ChannelContext<SP>,
6671-
/// The signing session for the current interactive tx construction, if any.
6672-
///
6673-
/// This is populated when the interactive tx construction phase completes
6674-
/// (i.e., upon receiving a consecutive `tx_complete`) and the channel enters
6675-
/// the signing phase (`FundingNegotiated` state with the `INTERACTIVE_SIGNING` flag set).
6676-
///
6677-
/// This field is cleared once our counterparty sends a `channel_ready`.
6678-
pub interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
66796681
holder_commitment_point: HolderCommitmentPoint,
66806682

66816683
/// Information about any pending splice candidates, including RBF attempts.
@@ -7408,8 +7410,7 @@ where
74087410

74097411
self.context.counterparty_current_commitment_point = self.context.counterparty_next_commitment_point;
74107412
self.context.counterparty_next_commitment_point = Some(msg.next_per_commitment_point);
7411-
// Clear any interactive signing session.
7412-
self.interactive_tx_signing_session = None;
7413+
self.context.interactive_tx_signing_session = None;
74137414

74147415
log_info!(logger, "Received channel_ready from peer for channel {}", &self.context.channel_id());
74157416

@@ -7575,7 +7576,7 @@ where
75757576
log_info!(logger, "Received initial commitment_signed from peer for channel {}", &self.context.channel_id());
75767577

75777578
self.monitor_updating_paused(false, false, false, Vec::new(), Vec::new(), Vec::new());
7578-
self.interactive_tx_signing_session.as_mut().expect("signing session should be present").received_commitment_signed();
7579+
self.context.interactive_tx_signing_session.as_mut().expect("signing session should be present").received_commitment_signed();
75797580
Ok(channel_monitor)
75807581
}
75817582

@@ -7668,7 +7669,8 @@ where
76687669
channel_id: Some(self.context.channel_id()),
76697670
};
76707671

7671-
self.interactive_tx_signing_session
7672+
self.context
7673+
.interactive_tx_signing_session
76727674
.as_mut()
76737675
.expect("Signing session must exist for negotiated pending splice")
76747676
.received_commitment_signed();
@@ -8615,6 +8617,7 @@ where
86158617
}
86168618

86178619
let (tx_signatures_opt, funding_tx_opt) = self
8620+
.context
86188621
.interactive_tx_signing_session
86198622
.as_mut()
86208623
.ok_or_else(|| APIError::APIMisuseError {
@@ -8682,7 +8685,7 @@ where
86828685
return Err(ChannelError::Ignore("Ignoring tx_signatures received outside of interactive signing".to_owned()));
86838686
}
86848687

8685-
if let Some(ref mut signing_session) = self.interactive_tx_signing_session {
8688+
if let Some(ref mut signing_session) = self.context.interactive_tx_signing_session {
86868689
if msg.tx_hash != signing_session.unsigned_tx().compute_txid() {
86878690
let msg = "The txid for the transaction does not match";
86888691
let reason = ClosureReason::ProcessingError { err: msg.to_owned() };
@@ -8955,7 +8958,7 @@ where
89558958
// An active interactive signing session or an awaiting channel_ready state implies that a
89568959
// commitment_signed retransmission is an initial one for funding negotiation. Thus, the
89578960
// signatures should be sent before channel_ready.
8958-
let channel_ready_order = if self.interactive_tx_signing_session.is_some() {
8961+
let channel_ready_order = if self.context.interactive_tx_signing_session.is_some() {
89598962
ChannelReadyOrder::SignaturesFirst
89608963
} else if matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(_)) {
89618964
ChannelReadyOrder::SignaturesFirst
@@ -9463,7 +9466,7 @@ where
94639466
if let Some(next_funding) = &msg.next_funding {
94649467
// - if `next_funding` matches the latest interactive funding transaction
94659468
// or the current channel funding transaction:
9466-
if let Some(session) = &self.interactive_tx_signing_session {
9469+
if let Some(session) = &self.context.interactive_tx_signing_session {
94679470
let our_next_funding_txid = session.unsigned_tx().compute_txid();
94689471
if our_next_funding_txid != next_funding.txid {
94699472
return Err(ChannelError::close(format!(
@@ -10763,7 +10766,7 @@ where
1076310766
.collect::<Vec<_>>()
1076410767
};
1076510768

10766-
self.interactive_tx_signing_session = None;
10769+
self.context.interactive_tx_signing_session = None;
1076710770
self.pending_splice = None;
1076810771
self.context.announcement_sigs = None;
1076910772
self.context.announcement_sigs_state = AnnouncementSigsState::NotSent;
@@ -11320,7 +11323,7 @@ where
1132011323
// Since we have a signing_session, this implies we've sent an initial `commitment_signed`...
1132111324
if !self.context.channel_state.is_their_tx_signatures_sent() {
1132211325
// ...but we didn't receive a `tx_signatures` from the counterparty yet.
11323-
self.interactive_tx_signing_session
11326+
self.context.interactive_tx_signing_session
1132411327
.as_ref()
1132511328
.map(|signing_session| {
1132611329
let mut next_funding = msgs::NextFunding {
@@ -11857,7 +11860,7 @@ where
1185711860
})?;
1185811861
let tx_msg_opt = interactive_tx_constructor.take_initiator_first_message();
1185911862

11860-
debug_assert!(self.interactive_tx_signing_session.is_none());
11863+
debug_assert!(self.context.interactive_tx_signing_session.is_none());
1186111864

1186211865
pending_splice.funding_negotiation = Some(FundingNegotiation::ConstructingTransaction {
1186311866
funding: splice_funding,
@@ -13128,7 +13131,6 @@ where
1312813131
let mut channel = FundedChannel {
1312913132
funding: self.funding,
1313013133
context: self.context,
13131-
interactive_tx_signing_session: None,
1313213134
holder_commitment_point,
1313313135
pending_splice: None,
1313413136
quiescent_action: None,
@@ -13413,7 +13415,6 @@ where
1341313415
let mut channel = FundedChannel {
1341413416
funding: self.funding,
1341513417
context: self.context,
13416-
interactive_tx_signing_session: None,
1341713418
holder_commitment_point,
1341813419
pending_splice: None,
1341913420
quiescent_action: None,
@@ -13457,8 +13458,6 @@ where
1345713458
pub funding_negotiation_context: FundingNegotiationContext,
1345813459
/// The current interactive transaction construction session under negotiation.
1345913460
pub interactive_tx_constructor: Option<InteractiveTxConstructor>,
13460-
/// The signing session created after `tx_complete` handling
13461-
pub interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
1346213461
}
1346313462

1346413463
impl<SP: Deref> PendingV2Channel<SP>
@@ -13533,7 +13532,6 @@ where
1353313532
unfunded_context,
1353413533
funding_negotiation_context,
1353513534
interactive_tx_constructor: None,
13536-
interactive_tx_signing_session: None,
1353713535
};
1353813536
Ok(chan)
1353913537
}
@@ -13721,7 +13719,6 @@ where
1372113719
context,
1372213720
funding_negotiation_context,
1372313721
interactive_tx_constructor,
13724-
interactive_tx_signing_session: None,
1372513722
unfunded_context,
1372613723
})
1372713724
}
@@ -14328,7 +14325,7 @@ where
1432814325
(53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
1432914326
(55, removed_htlc_attribution_data, optional_vec), // Added in 0.2
1433014327
(57, holding_cell_attribution_data, optional_vec), // Added in 0.2
14331-
(58, self.interactive_tx_signing_session, option), // Added in 0.2
14328+
(58, self.context.interactive_tx_signing_session, option), // Added in 0.2
1433214329
(59, self.funding.minimum_depth_override, option), // Added in 0.2
1433314330
(60, self.context.historical_scids, optional_vec), // Added in 0.2
1433414331
(61, fulfill_attribution_data, optional_vec), // Added in 0.2
@@ -15098,8 +15095,9 @@ where
1509815095

1509915096
blocked_monitor_updates: blocked_monitor_updates.unwrap(),
1510015097
is_manual_broadcast: is_manual_broadcast.unwrap_or(false),
15098+
15099+
interactive_tx_signing_session,
1510115100
},
15102-
interactive_tx_signing_session,
1510315101
holder_commitment_point,
1510415102
pending_splice,
1510515103
quiescent_action,

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9132,7 +9132,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
91329132

91339133
if let Some(signing_session) = (!channel.is_awaiting_monitor_update())
91349134
.then(|| ())
9135-
.and_then(|_| channel.interactive_tx_signing_session.as_mut())
9135+
.and_then(|_| channel.context.interactive_tx_signing_session.as_mut())
91369136
.filter(|signing_session| signing_session.holder_tx_signatures().is_none())
91379137
{
91389138
if signing_session.has_local_contribution() {

0 commit comments

Comments
 (0)