Skip to content

Commit 3dad1ab

Browse files
committed
Track funding negotiation state with an enum
PendingSplice holds a FundingScope being negotiated. However, when implementing funding negotiation, other states are possible depending on which party initiated the splice. Using an enum prevents needing various Option fields which may result in invalid states. When the user initiates the splice, the FundingNegotiationContext must be held until the counterparty responds with splice_ack. At that point enough information becomes available to create a new FundingScope and an InteractiveTxConstructor. When the counterparty initiates the splice, both a new FundingScope and an InteractiveTxConstructor can be created immediately when responding with splice_ack. After the transaction is constructed, those are no longer needed. At that point an InteractiveTxSigningSession is tracked until signatures are exchanged.
1 parent 445fb74 commit 3dad1ab

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

lightning/src/ln/channel.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,8 @@ where
18261826
ChannelPhase::Funded(mut funded_channel) => {
18271827
#[cfg(splicing)]
18281828
let has_negotiated_pending_splice = funded_channel.pending_splice.as_ref()
1829-
.map(|pending_splice| pending_splice.funding.is_some())
1829+
.and_then(|pending_splice| pending_splice.funding_negotiation.as_ref())
1830+
.map(|funding_negotiation| funding_negotiation.as_funding().is_some())
18301831
.unwrap_or(false);
18311832
#[cfg(splicing)]
18321833
let session_received_commitment_signed = funded_channel
@@ -2176,7 +2177,7 @@ impl FundingScope {
21762177
#[cfg(splicing)]
21772178
struct PendingSplice {
21782179
pub our_funding_contribution: i64,
2179-
funding: Option<FundingScope>,
2180+
funding_negotiation: Option<FundingNegotiation>,
21802181

21812182
/// The funding txid used in the `splice_locked` sent to the counterparty.
21822183
sent_funding_txid: Option<Txid>,
@@ -2185,6 +2186,24 @@ struct PendingSplice {
21852186
received_funding_txid: Option<Txid>,
21862187
}
21872188

2189+
#[cfg(splicing)]
2190+
enum FundingNegotiation {
2191+
AwaitingAck(FundingNegotiationContext),
2192+
Pending(FundingScope, InteractiveTxConstructor),
2193+
AwaitingSignatures(FundingScope),
2194+
}
2195+
2196+
#[cfg(splicing)]
2197+
impl FundingNegotiation {
2198+
fn as_funding(&self) -> Option<&FundingScope> {
2199+
match self {
2200+
FundingNegotiation::AwaitingAck(_) => None,
2201+
FundingNegotiation::Pending(funding, _) => Some(funding),
2202+
FundingNegotiation::AwaitingSignatures(funding) => Some(funding),
2203+
}
2204+
}
2205+
}
2206+
21882207
#[cfg(splicing)]
21892208
impl PendingSplice {
21902209
fn check_get_splice_locked<SP: Deref>(
@@ -6711,7 +6730,8 @@ where
67116730
let pending_splice_funding = self
67126731
.pending_splice
67136732
.as_ref()
6714-
.and_then(|pending_splice| pending_splice.funding.as_ref())
6733+
.and_then(|pending_splice| pending_splice.funding_negotiation.as_ref())
6734+
.and_then(|funding_negotiation| funding_negotiation.as_funding())
67156735
.expect("Funding must exist for negotiated pending splice");
67166736
let (holder_commitment_tx, _) = self.context.validate_commitment_signed(
67176737
pending_splice_funding,
@@ -10212,7 +10232,7 @@ where
1021210232

1021310233
self.pending_splice = Some(PendingSplice {
1021410234
our_funding_contribution: our_funding_contribution_satoshis,
10215-
funding: None,
10235+
funding_negotiation: None,
1021610236
sent_funding_txid: None,
1021710237
received_funding_txid: None,
1021810238
});

0 commit comments

Comments
 (0)