Skip to content

Commit f8a329d

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 3a05947 commit f8a329d

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
@@ -1950,21 +1950,19 @@ where
19501950
let logger = WithChannelContext::from(logger, self.context(), None);
19511951
match &mut self.phase {
19521952
ChannelPhase::UnfundedV2(chan) => {
1953-
let mut signing_session = chan
1953+
let signing_session = chan
19541954
.interactive_tx_constructor
19551955
.take()
19561956
.expect("PendingV2Channel::interactive_tx_constructor should be set")
19571957
.into_signing_session();
19581958
let commitment_signed = chan.context.funding_tx_constructed(
19591959
&mut chan.funding,
1960-
&mut signing_session,
1960+
signing_session,
19611961
false,
19621962
chan.unfunded_context.transaction_number(),
19631963
&&logger,
19641964
)?;
19651965

1966-
chan.interactive_tx_signing_session = Some(signing_session);
1967-
19681966
return Ok(commitment_signed);
19691967
},
19701968
ChannelPhase::Funded(chan) => {
@@ -1975,17 +1973,15 @@ where
19751973
interactive_tx_constructor,
19761974
) = funding_negotiation
19771975
{
1978-
let mut signing_session =
1979-
interactive_tx_constructor.into_signing_session();
1976+
let signing_session = interactive_tx_constructor.into_signing_session();
19801977
let commitment_signed = chan.context.funding_tx_constructed(
19811978
&mut funding,
1982-
&mut signing_session,
1979+
signing_session,
19831980
true,
19841981
chan.holder_commitment_point.next_transaction_number(),
19851982
&&logger,
19861983
)?;
19871984

1988-
chan.interactive_tx_signing_session = Some(signing_session);
19891985
pending_splice.funding_negotiation =
19901986
Some(FundingNegotiation::AwaitingSignatures(funding));
19911987

@@ -2039,7 +2035,6 @@ where
20392035
funding: chan.funding,
20402036
pending_funding: vec![],
20412037
context: chan.context,
2042-
interactive_tx_signing_session: chan.interactive_tx_signing_session,
20432038
holder_commitment_point,
20442039
pending_splice: None,
20452040
quiescent_action: None,
@@ -2064,6 +2059,7 @@ where
20642059
.map(|funding_negotiation| funding_negotiation.as_funding().is_some())
20652060
.unwrap_or(false);
20662061
let session_received_commitment_signed = funded_channel
2062+
.context
20672063
.interactive_tx_signing_session
20682064
.as_ref()
20692065
.map(|session| session.has_received_commitment_signed())
@@ -2945,6 +2941,16 @@ where
29452941
/// If we can't release a [`ChannelMonitorUpdate`] until some external action completes, we
29462942
/// store it here and only release it to the `ChannelManager` once it asks for it.
29472943
blocked_monitor_updates: Vec<PendingChannelMonitorUpdate>,
2944+
2945+
/// The signing session for the current interactive tx construction, if any.
2946+
///
2947+
/// This is populated when the interactive tx construction phase completes
2948+
/// (i.e., upon receiving a consecutive `tx_complete`) and the channel enters
2949+
/// the signing phase (`FundingNegotiated` state with the `INTERACTIVE_SIGNING` flag set).
2950+
///
2951+
/// This field is cleared once our counterparty sends a `channel_ready` or upon splice funding
2952+
/// promotion.
2953+
pub interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
29482954
}
29492955

29502956
/// A channel struct implementing this trait can receive an initial counterparty commitment
@@ -3519,6 +3525,8 @@ where
35193525
blocked_monitor_updates: Vec::new(),
35203526

35213527
is_manual_broadcast: false,
3528+
3529+
interactive_tx_signing_session: None,
35223530
};
35233531

35243532
Ok((funding, channel_context))
@@ -3755,6 +3763,8 @@ where
37553763
blocked_monitor_updates: Vec::new(),
37563764
local_initiated_shutdown: None,
37573765
is_manual_broadcast: false,
3766+
3767+
interactive_tx_signing_session: None,
37583768
};
37593769

37603770
Ok((funding, channel_context))
@@ -6064,7 +6074,7 @@ where
60646074

60656075
#[rustfmt::skip]
60666076
fn funding_tx_constructed<L: Deref>(
6067-
&mut self, funding: &mut FundingScope, signing_session: &mut InteractiveTxSigningSession,
6077+
&mut self, funding: &mut FundingScope, signing_session: InteractiveTxSigningSession,
60686078
is_splice: bool, holder_commitment_transaction_number: u64, logger: &L
60696079
) -> Result<msgs::CommitmentSigned, AbortReason>
60706080
where
@@ -6087,7 +6097,7 @@ where
60876097
};
60886098
funding
60896099
.channel_transaction_parameters.funding_outpoint = Some(outpoint);
6090-
6100+
self.interactive_tx_signing_session = Some(signing_session);
60916101
self.channel_state = ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
60926102
self.channel_state.set_interactive_signing();
60936103

@@ -6178,7 +6188,7 @@ where
61786188
}
61796189

61806190
fn get_initial_commitment_signed_v2<L: Deref>(
6181-
&mut self, funding: &FundingScope, logger: &L,
6191+
&self, funding: &FundingScope, logger: &L,
61826192
) -> Option<msgs::CommitmentSigned>
61836193
where
61846194
SP::Target: SignerProvider,
@@ -6621,14 +6631,6 @@ where
66216631
pub funding: FundingScope,
66226632
pending_funding: Vec<FundingScope>,
66236633
pub context: ChannelContext<SP>,
6624-
/// The signing session for the current interactive tx construction, if any.
6625-
///
6626-
/// This is populated when the interactive tx construction phase completes
6627-
/// (i.e., upon receiving a consecutive `tx_complete`) and the channel enters
6628-
/// the signing phase (`FundingNegotiated` state with the `INTERACTIVE_SIGNING` flag set).
6629-
///
6630-
/// This field is cleared once our counterparty sends a `channel_ready`.
6631-
pub interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
66326634
holder_commitment_point: HolderCommitmentPoint,
66336635
/// Info about an in-progress, pending splice (if any), on the pre-splice channel
66346636
pending_splice: Option<PendingSplice>,
@@ -6647,7 +6649,7 @@ macro_rules! promote_splice_funding {
66476649
$self.context.historical_scids.push(scid);
66486650
}
66496651
core::mem::swap(&mut $self.funding, $funding);
6650-
$self.interactive_tx_signing_session = None;
6652+
$self.context.interactive_tx_signing_session = None;
66516653
$self.pending_splice = None;
66526654
$self.context.announcement_sigs = None;
66536655
$self.context.announcement_sigs_state = AnnouncementSigsState::NotSent;
@@ -7373,8 +7375,7 @@ where
73737375

73747376
self.context.counterparty_current_commitment_point = self.context.counterparty_next_commitment_point;
73757377
self.context.counterparty_next_commitment_point = Some(msg.next_per_commitment_point);
7376-
// Clear any interactive signing session.
7377-
self.interactive_tx_signing_session = None;
7378+
self.context.interactive_tx_signing_session = None;
73787379

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

@@ -7540,7 +7541,7 @@ where
75407541
log_info!(logger, "Received initial commitment_signed from peer for channel {}", &self.context.channel_id());
75417542

75427543
self.monitor_updating_paused(false, false, false, Vec::new(), Vec::new(), Vec::new());
7543-
self.interactive_tx_signing_session.as_mut().expect("signing session should be present").received_commitment_signed();
7544+
self.context.interactive_tx_signing_session.as_mut().expect("signing session should be present").received_commitment_signed();
75447545
Ok(channel_monitor)
75457546
}
75467547

@@ -7633,7 +7634,8 @@ where
76337634
channel_id: Some(self.context.channel_id()),
76347635
};
76357636

7636-
self.interactive_tx_signing_session
7637+
self.context
7638+
.interactive_tx_signing_session
76377639
.as_mut()
76387640
.expect("Signing session must exist for negotiated pending splice")
76397641
.received_commitment_signed();
@@ -8580,6 +8582,7 @@ where
85808582
}
85818583

85828584
let (tx_signatures_opt, funding_tx_opt) = self
8585+
.context
85838586
.interactive_tx_signing_session
85848587
.as_mut()
85858588
.ok_or_else(|| APIError::APIMisuseError {
@@ -8647,7 +8650,7 @@ where
86478650
return Err(ChannelError::Ignore("Ignoring tx_signatures received outside of interactive signing".to_owned()));
86488651
}
86498652

8650-
if let Some(ref mut signing_session) = self.interactive_tx_signing_session {
8653+
if let Some(ref mut signing_session) = self.context.interactive_tx_signing_session {
86518654
if msg.tx_hash != signing_session.unsigned_tx().compute_txid() {
86528655
let msg = "The txid for the transaction does not match";
86538656
let reason = ClosureReason::ProcessingError { err: msg.to_owned() };
@@ -8919,7 +8922,7 @@ where
89198922
// An active interactive signing session or an awaiting channel_ready state implies that a
89208923
// commitment_signed retransmission is an initial one for funding negotiation. Thus, the
89218924
// signatures should be sent before channel_ready.
8922-
let channel_ready_order = if self.interactive_tx_signing_session.is_some() {
8925+
let channel_ready_order = if self.context.interactive_tx_signing_session.is_some() {
89238926
ChannelReadyOrder::SignaturesFirst
89248927
} else if matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(_)) {
89258928
ChannelReadyOrder::SignaturesFirst
@@ -9410,7 +9413,7 @@ where
94109413
if let Some(next_funding) = &msg.next_funding {
94119414
// - if `next_funding` matches the latest interactive funding transaction
94129415
// or the current channel funding transaction:
9413-
if let Some(session) = &self.interactive_tx_signing_session {
9416+
if let Some(session) = &self.context.interactive_tx_signing_session {
94149417
let our_next_funding_txid = session.unsigned_tx().compute_txid();
94159418
if our_next_funding_txid != next_funding.txid {
94169419
return Err(ChannelError::close(format!(
@@ -11246,7 +11249,7 @@ where
1124611249
// Since we have a signing_session, this implies we've sent an initial `commitment_signed`...
1124711250
if !self.context.channel_state.is_their_tx_signatures_sent() {
1124811251
// ...but we didn't receive a `tx_signatures` from the counterparty yet.
11249-
self.interactive_tx_signing_session
11252+
self.context.interactive_tx_signing_session
1125011253
.as_ref()
1125111254
.map(|signing_session| {
1125211255
let mut next_funding = msgs::NextFunding {
@@ -11781,7 +11784,7 @@ where
1178111784
})?;
1178211785
let tx_msg_opt = interactive_tx_constructor.take_initiator_first_message();
1178311786

11784-
debug_assert!(self.interactive_tx_signing_session.is_none());
11787+
debug_assert!(self.context.interactive_tx_signing_session.is_none());
1178511788

1178611789
pending_splice.funding_negotiation = Some(FundingNegotiation::ConstructingTransaction(
1178711790
splice_funding,
@@ -13053,7 +13056,6 @@ where
1305313056
funding: self.funding,
1305413057
pending_funding: vec![],
1305513058
context: self.context,
13056-
interactive_tx_signing_session: None,
1305713059
holder_commitment_point,
1305813060
pending_splice: None,
1305913061
quiescent_action: None,
@@ -13339,7 +13341,6 @@ where
1333913341
funding: self.funding,
1334013342
pending_funding: vec![],
1334113343
context: self.context,
13342-
interactive_tx_signing_session: None,
1334313344
holder_commitment_point,
1334413345
pending_splice: None,
1334513346
quiescent_action: None,
@@ -13383,8 +13384,6 @@ where
1338313384
pub funding_negotiation_context: FundingNegotiationContext,
1338413385
/// The current interactive transaction construction session under negotiation.
1338513386
pub interactive_tx_constructor: Option<InteractiveTxConstructor>,
13386-
/// The signing session created after `tx_complete` handling
13387-
pub interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
1338813387
}
1338913388

1339013389
impl<SP: Deref> PendingV2Channel<SP>
@@ -13459,7 +13458,6 @@ where
1345913458
unfunded_context,
1346013459
funding_negotiation_context,
1346113460
interactive_tx_constructor: None,
13462-
interactive_tx_signing_session: None,
1346313461
};
1346413462
Ok(chan)
1346513463
}
@@ -13647,7 +13645,6 @@ where
1364713645
context,
1364813646
funding_negotiation_context,
1364913647
interactive_tx_constructor,
13650-
interactive_tx_signing_session: None,
1365113648
unfunded_context,
1365213649
})
1365313650
}
@@ -14255,7 +14252,7 @@ where
1425514252
(54, self.pending_funding, optional_vec), // Added in 0.2
1425614253
(55, removed_htlc_attribution_data, optional_vec), // Added in 0.2
1425714254
(57, holding_cell_attribution_data, optional_vec), // Added in 0.2
14258-
(58, self.interactive_tx_signing_session, option), // Added in 0.2
14255+
(58, self.context.interactive_tx_signing_session, option), // Added in 0.2
1425914256
(59, self.funding.minimum_depth_override, option), // Added in 0.2
1426014257
(60, self.context.historical_scids, optional_vec), // Added in 0.2
1426114258
(61, fulfill_attribution_data, optional_vec), // Added in 0.2
@@ -15025,8 +15022,9 @@ where
1502515022

1502615023
blocked_monitor_updates: blocked_monitor_updates.unwrap(),
1502715024
is_manual_broadcast: is_manual_broadcast.unwrap_or(false),
15025+
15026+
interactive_tx_signing_session,
1502815027
},
15029-
interactive_tx_signing_session,
1503015028
holder_commitment_point,
1503115029
pending_splice: None,
1503215030
quiescent_action,

lightning/src/ln/channelmanager.rs

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

90289028
if let Some(signing_session) = (!channel.is_awaiting_monitor_update())
90299029
.then(|| ())
9030-
.and_then(|_| channel.interactive_tx_signing_session.as_mut())
9030+
.and_then(|_| channel.context.interactive_tx_signing_session.as_mut())
90319031
.filter(|signing_session| signing_session.holder_tx_signatures().is_none())
90329032
{
90339033
if signing_session.has_local_contribution() {

0 commit comments

Comments
 (0)