Skip to content

Commit f0503c9

Browse files
committed
Add pending funding scopes to FundedChannel
Once a channel is funded, it may be spliced to add or remove funds. The new funding transaction is pending until confirmed on chain and thus needs to be tracked. Additionally, it may be replaced by another transaction using RBF with a higher fee. Hence, there may be more than one pending FundingScope to track for a splice. This commit adds support for tracking pending funding scopes. The following commits will account for any pending scopes where applicable (e.g., when handling commitment_signed).
1 parent e9f3e4d commit f0503c9

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

lightning/src/ln/channel.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,6 +1513,7 @@ impl<SP: Deref> Channel<SP> where
15131513
};
15141514
let mut funded_channel = FundedChannel {
15151515
funding: chan.funding,
1516+
pending_funding: vec![],
15161517
context: chan.context,
15171518
interactive_tx_signing_session: chan.interactive_tx_signing_session,
15181519
holder_commitment_point,
@@ -1657,6 +1658,30 @@ pub(super) struct FundingScope {
16571658
funding_transaction: Option<Transaction>,
16581659
}
16591660

1661+
#[cfg(not(any(test, fuzzing)))]
1662+
impl_writeable_tlv_based!(FundingScope, {
1663+
(0, value_to_self_msat, required),
1664+
(1, counterparty_selected_channel_reserve_satoshis, option),
1665+
(2, holder_selected_channel_reserve_satoshis, required),
1666+
(3, holder_max_commitment_tx_output, required),
1667+
(4, counterparty_max_commitment_tx_output, required),
1668+
(5, channel_transaction_parameters, (required: ReadableArgs, 0)), // FIXME: This won't work
1669+
(6, funding_transaction, option),
1670+
});
1671+
1672+
#[cfg(any(test, fuzzing))]
1673+
impl_writeable_tlv_based!(FundingScope, {
1674+
(0, value_to_self_msat, required),
1675+
(1, counterparty_selected_channel_reserve_satoshis, option),
1676+
(2, holder_selected_channel_reserve_satoshis, required),
1677+
(3, holder_max_commitment_tx_output, required),
1678+
(4, counterparty_max_commitment_tx_output, required),
1679+
(5, channel_transaction_parameters, (required: ReadableArgs, 0)),
1680+
(6, funding_transaction, option),
1681+
(126, next_local_commitment_tx_fee_info_cached, required), // FIXME: This won't work
1682+
(127, next_remote_commitment_tx_fee_info_cached, required), // FIXME: This won't work
1683+
});
1684+
16601685
impl FundingScope {
16611686
pub fn get_value_satoshis(&self) -> u64 {
16621687
self.channel_transaction_parameters.channel_value_satoshis
@@ -4820,6 +4845,7 @@ pub(super) struct DualFundingChannelContext {
48204845
// Counterparty designates channel data owned by the another channel participant entity.
48214846
pub(super) struct FundedChannel<SP: Deref> where SP::Target: SignerProvider {
48224847
pub funding: FundingScope,
4848+
pending_funding: Vec<FundingScope>,
48234849
pub context: ChannelContext<SP>,
48244850
pub interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
48254851
holder_commitment_point: HolderCommitmentPoint,
@@ -9278,6 +9304,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
92789304

92799305
let mut channel = FundedChannel {
92809306
funding: self.funding,
9307+
pending_funding: vec![],
92819308
context: self.context,
92829309
interactive_tx_signing_session: None,
92839310
is_v2_established: false,
@@ -9545,6 +9572,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
95459572
// `ChannelMonitor`.
95469573
let mut channel = FundedChannel {
95479574
funding: self.funding,
9575+
pending_funding: vec![],
95489576
context: self.context,
95499577
interactive_tx_signing_session: None,
95509578
is_v2_established: false,
@@ -10330,6 +10358,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1033010358
(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
1033110359
(51, is_manual_broadcast, option), // Added in 0.0.124
1033210360
(53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
10361+
(55, self.pending_funding, optional_vec), // Added in 0.2
1033310362
});
1033410363

1033510364
Ok(())
@@ -10609,6 +10638,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1060910638
let mut next_holder_commitment_point_opt: Option<PublicKey> = None;
1061010639
let mut is_manual_broadcast = None;
1061110640

10641+
let mut pending_funding = Some(Vec::new());
10642+
1061210643
read_tlv_fields!(reader, {
1061310644
(0, announcement_sigs, option),
1061410645
(1, minimum_depth, option),
@@ -10644,6 +10675,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1064410675
(49, local_initiated_shutdown, option),
1064510676
(51, is_manual_broadcast, option),
1064610677
(53, funding_tx_broadcast_safe_event_emitted, option),
10678+
(55, pending_funding, optional_vec), // Added in 0.2
1064710679
});
1064810680

1064910681
let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
@@ -10785,6 +10817,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1078510817
channel_transaction_parameters: channel_parameters,
1078610818
funding_transaction,
1078710819
},
10820+
pending_funding: pending_funding.unwrap(),
1078810821
context: ChannelContext {
1078910822
user_id,
1079010823

0 commit comments

Comments
 (0)