Skip to content

Commit 9d16611

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 9d16611

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

lightning/src/ln/channel.rs

Lines changed: 22 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,22 @@ struct PendingSplice {
21852186
received_funding_txid: Option<Txid>,
21862187
}
21872188

2189+
enum FundingNegotiation {
2190+
AwaitingAck(FundingNegotiationContext),
2191+
Pending(FundingScope, InteractiveTxConstructor),
2192+
AwaitingSignatures(FundingScope),
2193+
}
2194+
2195+
impl FundingNegotiation {
2196+
fn as_funding(&self) -> Option<&FundingScope> {
2197+
match self {
2198+
FundingNegotiation::AwaitingAck(_) => None,
2199+
FundingNegotiation::Pending(funding, _) => Some(funding),
2200+
FundingNegotiation::AwaitingSignatures(funding) => Some(funding),
2201+
}
2202+
}
2203+
}
2204+
21882205
#[cfg(splicing)]
21892206
impl PendingSplice {
21902207
fn check_get_splice_locked<SP: Deref>(
@@ -6711,7 +6728,8 @@ where
67116728
let pending_splice_funding = self
67126729
.pending_splice
67136730
.as_ref()
6714-
.and_then(|pending_splice| pending_splice.funding.as_ref())
6731+
.and_then(|pending_splice| pending_splice.funding_negotiation.as_ref())
6732+
.and_then(|funding_negotiation| funding_negotiation.as_funding())
67156733
.expect("Funding must exist for negotiated pending splice");
67166734
let (holder_commitment_tx, _) = self.context.validate_commitment_signed(
67176735
pending_splice_funding,
@@ -10212,7 +10230,7 @@ where
1021210230

1021310231
self.pending_splice = Some(PendingSplice {
1021410232
our_funding_contribution: our_funding_contribution_satoshis,
10215-
funding: None,
10233+
funding_negotiation: None,
1021610234
sent_funding_txid: None,
1021710235
received_funding_txid: None,
1021810236
});

0 commit comments

Comments
 (0)