Skip to content

Commit 5eb912c

Browse files
committed
Move PendingSpliceInfoPre to Channel (from ChannelContext)
1 parent 2eb392c commit 5eb912c

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

lightning/src/ln/channel.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,10 +1599,6 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
15991599
secp_ctx: Secp256k1<secp256k1::All>,
16001600
channel_value_satoshis: u64,
16011601

1602-
/// Info about an in-progress, pending splice (if any), on the pre-splice channel
1603-
#[cfg(splicing)]
1604-
pending_splice_pre: Option<PendingSpliceInfoPre>,
1605-
16061602
latest_monitor_update_id: u64,
16071603

16081604
holder_signer: ChannelSignerType<SP>,
@@ -2315,6 +2311,8 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
23152311
context: self.context,
23162312
interactive_tx_signing_session: Some(signing_session),
23172313
holder_commitment_point,
2314+
#[cfg(splicing)]
2315+
pending_splice_pre: None,
23182316
};
23192317
Ok((funded_chan, commitment_signed, funding_ready_for_sig_event))
23202318
},
@@ -2665,9 +2663,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
26652663
is_manual_broadcast: false,
26662664

26672665
next_funding_txid: None,
2668-
2669-
#[cfg(splicing)]
2670-
pending_splice_pre: None,
26712666
};
26722667

26732668
Ok(channel_context)
@@ -2895,9 +2890,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
28952890
local_initiated_shutdown: None,
28962891
is_manual_broadcast: false,
28972892
next_funding_txid: None,
2898-
2899-
#[cfg(splicing)]
2900-
pending_splice_pre: None,
29012893
})
29022894
}
29032895

@@ -4733,6 +4725,9 @@ pub(super) struct FundedChannel<SP: Deref> where SP::Target: SignerProvider {
47334725
pub context: ChannelContext<SP>,
47344726
pub interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
47354727
holder_commitment_point: HolderCommitmentPoint,
4728+
/// Info about an in-progress, pending splice (if any), on the pre-splice channel
4729+
#[cfg(splicing)]
4730+
pending_splice_pre: Option<PendingSpliceInfoPre>,
47364731
}
47374732

47384733
#[cfg(any(test, fuzzing))]
@@ -8319,7 +8314,7 @@ impl<SP: Deref> FundedChannel<SP> where
83198314
) -> Result<msgs::SpliceInit, ChannelError> {
83208315
// Check if a splice has been initiated already.
83218316
// Note: this could be handled more nicely, and support multiple outstanding splice's, the incoming splice_ack matters anyways.
8322-
if let Some(splice_info) = &self.context.pending_splice_pre {
8317+
if let Some(splice_info) = &self.pending_splice_pre {
83238318
return Err(ChannelError::Warn(format!(
83248319
"Channel has already a splice pending, contribution {}", splice_info.our_funding_contribution
83258320
)));
@@ -8348,7 +8343,7 @@ impl<SP: Deref> FundedChannel<SP> where
83488343
// Note: post-splice channel value is not yet known at this point, counterpary contribution is not known
83498344
// (Cannot test for miminum required post-splice channel value)
83508345

8351-
self.context.pending_splice_pre = Some(PendingSpliceInfoPre {
8346+
self.pending_splice_pre = Some(PendingSpliceInfoPre {
83528347
our_funding_contribution: our_funding_contribution_satoshis,
83538348
});
83548349

@@ -8365,7 +8360,7 @@ impl<SP: Deref> FundedChannel<SP> where
83658360

83668361
// Check if a splice has been initiated already.
83678362
// Note: this could be handled more nicely, and support multiple outstanding splice's, the incoming splice_ack matters anyways.
8368-
if let Some(splice_info) = &self.context.pending_splice_pre {
8363+
if let Some(splice_info) = &self.pending_splice_pre {
83698364
return Err(ChannelError::Warn(format!(
83708365
"Channel has already a splice pending, contribution {}", splice_info.our_funding_contribution,
83718366
)));
@@ -8414,7 +8409,7 @@ impl<SP: Deref> FundedChannel<SP> where
84148409
let their_funding_contribution_satoshis = msg.funding_contribution_satoshis;
84158410

84168411
// check if splice is pending
8417-
let pending_splice = if let Some(pending_splice) = &self.context.pending_splice_pre {
8412+
let pending_splice = if let Some(pending_splice) = &self.pending_splice_pre {
84188413
pending_splice
84198414
} else {
84208415
return Err(ChannelError::Warn(format!("Channel is not in pending splice")));
@@ -9124,6 +9119,8 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
91249119
context: self.context,
91259120
interactive_tx_signing_session: None,
91269121
holder_commitment_point,
9122+
#[cfg(splicing)]
9123+
pending_splice_pre: None,
91279124
};
91289125

91299126
let need_channel_ready = channel.check_get_channel_ready(0, logger).is_some()
@@ -9389,6 +9386,8 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
93899386
context: self.context,
93909387
interactive_tx_signing_session: None,
93919388
holder_commitment_point,
9389+
#[cfg(splicing)]
9390+
pending_splice_pre: None,
93929391
};
93939392
let need_channel_ready = channel.check_get_channel_ready(0, logger).is_some()
93949393
|| channel.context.signer_pending_channel_ready;
@@ -10769,12 +10768,11 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1076910768
// during a signing session, but have not received `tx_signatures` we MUST set `next_funding_txid`
1077010769
// to the txid of that interactive transaction, else we MUST NOT set it.
1077110770
next_funding_txid: None,
10772-
10773-
#[cfg(splicing)]
10774-
pending_splice_pre: None,
1077510771
},
1077610772
interactive_tx_signing_session: None,
1077710773
holder_commitment_point,
10774+
#[cfg(splicing)]
10775+
pending_splice_pre: None,
1077810776
})
1077910777
}
1078010778
}

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4256,7 +4256,7 @@ where
42564256
// Look for the channel
42574257
match peer_state.channel_by_id.entry(*channel_id) {
42584258
hash_map::Entry::Occupied(mut chan_phase_entry) => {
4259-
if let ChannelPhase::Funded(chan) = chan_phase_entry.get_mut() {
4259+
if let Some(chan) = chan_phase_entry.get_mut().as_funded_mut() {
42604260
let msg = match chan.splice_channel(our_funding_contribution_satoshis, funding_feerate_perkw, locktime) {
42614261
Ok(msg) => msg,
42624262
Err(err) => return Err(APIError::APIMisuseError {
@@ -9378,7 +9378,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
93789378
counterparty_node_id, msg.channel_id,
93799379
), msg.channel_id)),
93809380
hash_map::Entry::Occupied(mut chan_entry) => {
9381-
if let ChannelPhase::Funded(chan) = chan_entry.get_mut() {
9381+
if let Some(chan) = chan_entry.get_mut().as_funded_mut() {
93829382
match chan.splice_init(msg) {
93839383
Ok(splice_ack_msg) => {
93849384
peer_state.pending_msg_events.push(events::MessageSendEvent::SendSpliceAck {
@@ -9423,7 +9423,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
94239423
counterparty_node_id
94249424
), msg.channel_id)),
94259425
hash_map::Entry::Occupied(mut chan) => {
9426-
if let ChannelPhase::Funded(chan) = chan.get_mut() {
9426+
if let Some(chan) = chan.get_mut().as_funded_mut() {
94279427
match chan.splice_ack(msg) {
94289428
Ok(_) => {}
94299429
Err(err) => {

0 commit comments

Comments
 (0)