Skip to content

Commit 5fecde5

Browse files
committed
Use struct syntax for FundingNegotiation variants
To use impl_writeable_tlv_based_enum_upgradable with unread_variants, currently tuple syntax can't be used enum variants. Update FundingNegotiation to use this syntax so that it can be used with that macro.
1 parent 4ba6452 commit 5fecde5

File tree

1 file changed

+39
-30
lines changed

1 file changed

+39
-30
lines changed

lightning/src/ln/channel.rs

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,10 +1749,10 @@ where
17491749
.as_mut()
17501750
.and_then(|pending_splice| pending_splice.funding_negotiation.take())
17511751
.and_then(|funding_negotiation| {
1752-
if let FundingNegotiation::ConstructingTransaction(
1753-
_,
1752+
if let FundingNegotiation::ConstructingTransaction {
17541753
interactive_tx_constructor,
1755-
) = funding_negotiation
1754+
..
1755+
} = funding_negotiation
17561756
{
17571757
Some(interactive_tx_constructor)
17581758
} else {
@@ -1970,10 +1970,10 @@ where
19701970
ChannelPhase::Funded(chan) => {
19711971
if let Some(pending_splice) = chan.pending_splice.as_mut() {
19721972
if let Some(funding_negotiation) = pending_splice.funding_negotiation.take() {
1973-
if let FundingNegotiation::ConstructingTransaction(
1973+
if let FundingNegotiation::ConstructingTransaction {
19741974
mut funding,
19751975
interactive_tx_constructor,
1976-
) = funding_negotiation
1976+
} = funding_negotiation
19771977
{
19781978
let mut signing_session =
19791979
interactive_tx_constructor.into_signing_session();
@@ -1987,7 +1987,7 @@ where
19871987

19881988
chan.interactive_tx_signing_session = Some(signing_session);
19891989
pending_splice.funding_negotiation =
1990-
Some(FundingNegotiation::AwaitingSignatures(funding));
1990+
Some(FundingNegotiation::AwaitingSignatures { funding });
19911991

19921992
return Ok(commitment_signed);
19931993
} else {
@@ -2058,7 +2058,7 @@ where
20582058
let has_negotiated_pending_splice = funded_channel.pending_splice.as_ref()
20592059
.and_then(|pending_splice| pending_splice.funding_negotiation.as_ref())
20602060
.filter(|funding_negotiation| {
2061-
matches!(funding_negotiation, FundingNegotiation::AwaitingSignatures(_))
2061+
matches!(funding_negotiation, FundingNegotiation::AwaitingSignatures { .. })
20622062
})
20632063
.map(|funding_negotiation| funding_negotiation.as_funding().is_some())
20642064
.unwrap_or(false);
@@ -2564,17 +2564,24 @@ struct PendingFunding {
25642564
}
25652565

25662566
enum FundingNegotiation {
2567-
AwaitingAck(FundingNegotiationContext),
2568-
ConstructingTransaction(FundingScope, InteractiveTxConstructor),
2569-
AwaitingSignatures(FundingScope),
2567+
AwaitingAck {
2568+
context: FundingNegotiationContext,
2569+
},
2570+
ConstructingTransaction {
2571+
funding: FundingScope,
2572+
interactive_tx_constructor: InteractiveTxConstructor,
2573+
},
2574+
AwaitingSignatures {
2575+
funding: FundingScope,
2576+
},
25702577
}
25712578

25722579
impl FundingNegotiation {
25732580
fn as_funding(&self) -> Option<&FundingScope> {
25742581
match self {
2575-
FundingNegotiation::AwaitingAck(_) => None,
2576-
FundingNegotiation::ConstructingTransaction(funding, _) => Some(funding),
2577-
FundingNegotiation::AwaitingSignatures(funding) => Some(funding),
2582+
FundingNegotiation::AwaitingAck { .. } => None,
2583+
FundingNegotiation::ConstructingTransaction { funding, .. } => Some(funding),
2584+
FundingNegotiation::AwaitingSignatures { funding } => Some(funding),
25782585
}
25792586
}
25802587
}
@@ -6760,8 +6767,10 @@ where
67606767
.as_mut()
67616768
.and_then(|pending_splice| pending_splice.funding_negotiation.as_mut())
67626769
.and_then(|funding_negotiation| {
6763-
if let FundingNegotiation::ConstructingTransaction(_, interactive_tx_constructor) =
6764-
funding_negotiation
6770+
if let FundingNegotiation::ConstructingTransaction {
6771+
interactive_tx_constructor,
6772+
..
6773+
} = funding_negotiation
67656774
{
67666775
Some(interactive_tx_constructor)
67676776
} else {
@@ -7580,7 +7589,7 @@ where
75807589
.as_ref()
75817590
.and_then(|pending_splice| pending_splice.funding_negotiation.as_ref())
75827591
.filter(|funding_negotiation| {
7583-
matches!(funding_negotiation, FundingNegotiation::AwaitingSignatures(_))
7592+
matches!(funding_negotiation, FundingNegotiation::AwaitingSignatures { .. })
75847593
})
75857594
.and_then(|funding_negotiation| funding_negotiation.as_funding())
75867595
.expect("Funding must exist for negotiated pending splice");
@@ -8571,7 +8580,7 @@ where
85718580
.funding_negotiation
85728581
.as_ref()
85738582
.map(|funding_negotiation| {
8574-
matches!(funding_negotiation, FundingNegotiation::AwaitingSignatures(_))
8583+
matches!(funding_negotiation, FundingNegotiation::AwaitingSignatures { .. })
85758584
})
85768585
.unwrap_or(false)
85778586
{
@@ -9435,7 +9444,7 @@ where
94359444
.as_ref()
94369445
.and_then(|pending_splice| pending_splice.funding_negotiation.as_ref())
94379446
.and_then(|funding_negotiation| {
9438-
if let FundingNegotiation::AwaitingSignatures(funding) = &funding_negotiation {
9447+
if let FundingNegotiation::AwaitingSignatures { funding } = &funding_negotiation {
94399448
Some(funding)
94409449
} else {
94419450
None
@@ -11515,7 +11524,7 @@ where
1151511524
}
1151611525

1151711526
let prev_funding_input = self.funding.to_splice_funding_input();
11518-
let funding_negotiation_context = FundingNegotiationContext {
11527+
let context = FundingNegotiationContext {
1151911528
is_initiator: true,
1152011529
our_funding_contribution: adjusted_funding_contribution,
1152111530
funding_tx_locktime: LockTime::from_consensus(locktime),
@@ -11527,7 +11536,7 @@ where
1152711536
};
1152811537

1152911538
self.pending_splice = Some(PendingFunding {
11530-
funding_negotiation: Some(FundingNegotiation::AwaitingAck(funding_negotiation_context)),
11539+
funding_negotiation: Some(FundingNegotiation::AwaitingAck { context }),
1153111540
negotiated_candidates: vec![],
1153211541
sent_funding_txid: None,
1153311542
received_funding_txid: None,
@@ -11747,10 +11756,10 @@ where
1174711756
let funding_pubkey = splice_funding.get_holder_pubkeys().funding_pubkey;
1174811757

1174911758
self.pending_splice = Some(PendingFunding {
11750-
funding_negotiation: Some(FundingNegotiation::ConstructingTransaction(
11751-
splice_funding,
11759+
funding_negotiation: Some(FundingNegotiation::ConstructingTransaction {
11760+
funding: splice_funding,
1175211761
interactive_tx_constructor,
11753-
)),
11762+
}),
1175411763
negotiated_candidates: Vec::new(),
1175511764
received_funding_txid: None,
1175611765
sent_funding_txid: None,
@@ -11785,7 +11794,7 @@ where
1178511794
let pending_splice =
1178611795
self.pending_splice.as_mut().expect("We should have returned an error earlier!");
1178711796
// TODO: Good candidate for a let else statement once MSRV >= 1.65
11788-
let funding_negotiation_context = if let Some(FundingNegotiation::AwaitingAck(context)) =
11797+
let funding_negotiation_context = if let Some(FundingNegotiation::AwaitingAck { context }) =
1178911798
pending_splice.funding_negotiation.take()
1179011799
{
1179111800
context
@@ -11811,10 +11820,10 @@ where
1181111820

1181211821
debug_assert!(self.interactive_tx_signing_session.is_none());
1181311822

11814-
pending_splice.funding_negotiation = Some(FundingNegotiation::ConstructingTransaction(
11815-
splice_funding,
11823+
pending_splice.funding_negotiation = Some(FundingNegotiation::ConstructingTransaction {
11824+
funding: splice_funding,
1181611825
interactive_tx_constructor,
11817-
));
11826+
});
1181811827

1181911828
Ok(tx_msg_opt)
1182011829
}
@@ -11828,9 +11837,9 @@ where
1182811837
.ok_or(ChannelError::Ignore("Channel is not in pending splice".to_owned()))?
1182911838
.funding_negotiation
1183011839
{
11831-
Some(FundingNegotiation::AwaitingAck(context)) => context,
11832-
Some(FundingNegotiation::ConstructingTransaction(_, _))
11833-
| Some(FundingNegotiation::AwaitingSignatures(_)) => {
11840+
Some(FundingNegotiation::AwaitingAck { context }) => context,
11841+
Some(FundingNegotiation::ConstructingTransaction { .. })
11842+
| Some(FundingNegotiation::AwaitingSignatures { .. }) => {
1183411843
return Err(ChannelError::WarnAndDisconnect(
1183511844
"Got unexpected splice_ack; splice negotiation already in progress".to_owned(),
1183611845
));

0 commit comments

Comments
 (0)