Skip to content

Commit 03aaec8

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 823e251 commit 03aaec8

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
@@ -1821,7 +1821,8 @@ where
18211821
ChannelPhase::Funded(mut funded_channel) => {
18221822
#[cfg(splicing)]
18231823
let has_negotiated_pending_splice = funded_channel.pending_splice.as_ref()
1824-
.map(|pending_splice| pending_splice.funding.is_some())
1824+
.and_then(|pending_splice| pending_splice.funding_negotiation.as_ref())
1825+
.map(|funding_negotiation| funding_negotiation.as_funding().is_some())
18251826
.unwrap_or(false);
18261827
#[cfg(splicing)]
18271828
let session_received_commitment_signed = funded_channel
@@ -2171,7 +2172,7 @@ impl FundingScope {
21712172
#[cfg(splicing)]
21722173
struct PendingSplice {
21732174
pub our_funding_contribution: i64,
2174-
funding: Option<FundingScope>,
2175+
funding_negotiation: Option<FundingNegotiation>,
21752176

21762177
/// The funding txid used in the `splice_locked` sent to the counterparty.
21772178
sent_funding_txid: Option<Txid>,
@@ -2180,6 +2181,24 @@ struct PendingSplice {
21802181
received_funding_txid: Option<Txid>,
21812182
}
21822183

2184+
#[cfg(splicing)]
2185+
enum FundingNegotiation {
2186+
AwaitingAck(FundingNegotiationContext),
2187+
Pending(FundingScope, InteractiveTxConstructor),
2188+
AwaitingSignatures(FundingScope),
2189+
}
2190+
2191+
#[cfg(splicing)]
2192+
impl FundingNegotiation {
2193+
fn as_funding(&self) -> Option<&FundingScope> {
2194+
match self {
2195+
FundingNegotiation::AwaitingAck(_) => None,
2196+
FundingNegotiation::Pending(funding, _) => Some(funding),
2197+
FundingNegotiation::AwaitingSignatures(funding) => Some(funding),
2198+
}
2199+
}
2200+
}
2201+
21832202
#[cfg(splicing)]
21842203
impl PendingSplice {
21852204
fn check_get_splice_locked<SP: Deref>(
@@ -6808,7 +6827,8 @@ where
68086827
let pending_splice_funding = self
68096828
.pending_splice
68106829
.as_ref()
6811-
.and_then(|pending_splice| pending_splice.funding.as_ref())
6830+
.and_then(|pending_splice| pending_splice.funding_negotiation.as_ref())
6831+
.and_then(|funding_negotiation| funding_negotiation.as_funding())
68126832
.expect("Funding must exist for negotiated pending splice");
68136833
let (holder_commitment_tx, _) = self.context.validate_commitment_signed(
68146834
pending_splice_funding,
@@ -10436,7 +10456,7 @@ where
1043610456

1043710457
self.pending_splice = Some(PendingSplice {
1043810458
our_funding_contribution: our_funding_contribution_satoshis,
10439-
funding: None,
10459+
funding_negotiation: None,
1044010460
sent_funding_txid: None,
1044110461
received_funding_txid: None,
1044210462
});

0 commit comments

Comments
 (0)