Skip to content

Commit fa867f3

Browse files
committed
Move funding_transaction to FundingScope
Since the funding transactions changes for each new FudningScope, include it there instead of ChannelContext.
1 parent d796878 commit fa867f3

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

lightning/src/ln/channel.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,10 @@ pub(super) struct FundingScope {
16501650
next_remote_commitment_tx_fee_info_cached: Mutex<Option<CommitmentTxInfoCached>>,
16511651

16521652
pub(super) channel_transaction_parameters: ChannelTransactionParameters,
1653+
1654+
/// The transaction which funds this channel. Note that for manually-funded channels (i.e.,
1655+
/// [`ChannelContext::is_manual_broadcast`] is true) this will be a dummy empty transaction.
1656+
funding_transaction: Option<Transaction>,
16531657
}
16541658

16551659
impl FundingScope {
@@ -1902,9 +1906,6 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
19021906

19031907
counterparty_forwarding_info: Option<CounterpartyForwardingInfo>,
19041908

1905-
/// The transaction which funds this channel. Note that for manually-funded channels (i.e.,
1906-
/// is_manual_broadcast is true) this will be a dummy empty transaction.
1907-
funding_transaction: Option<Transaction>,
19081909
/// This flag indicates that it is the user's responsibility to validated and broadcast the
19091910
/// funding transaction.
19101911
is_manual_broadcast: bool,
@@ -2321,7 +2322,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
23212322
let commitment_signed = self.context.get_initial_commitment_signed(&self.funding, logger);
23222323
let commitment_signed = match commitment_signed {
23232324
Ok(commitment_signed) => {
2324-
self.context.funding_transaction = Some(signing_session.unsigned_tx.build_unsigned_tx());
2325+
self.funding.funding_transaction = Some(signing_session.unsigned_tx.build_unsigned_tx());
23252326
commitment_signed
23262327
},
23272328
Err(err) => {
@@ -2598,6 +2599,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
25982599
funding_outpoint: None,
25992600
channel_type_features: channel_type.clone()
26002601
},
2602+
funding_transaction: None,
26012603
};
26022604
let channel_context = ChannelContext {
26032605
user_id,
@@ -2679,7 +2681,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
26792681

26802682
counterparty_forwarding_info: None,
26812683

2682-
funding_transaction: None,
26832684
is_batch_funding: None,
26842685

26852686
counterparty_cur_commitment_point: Some(open_channel_fields.first_per_commitment_point),
@@ -2833,6 +2834,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
28332834
funding_outpoint: None,
28342835
channel_type_features: channel_type.clone()
28352836
},
2837+
funding_transaction: None,
28362838
};
28372839
let channel_context = Self {
28382840
user_id,
@@ -2914,7 +2916,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
29142916

29152917
counterparty_forwarding_info: None,
29162918

2917-
funding_transaction: None,
29182919
is_batch_funding: None,
29192920

29202921
counterparty_cur_commitment_point: None,
@@ -4327,8 +4328,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
43274328
///
43284329
/// Note that if [`Self::is_manual_broadcast`] is true the transaction will be a dummy
43294330
/// transaction.
4330-
pub fn unbroadcasted_funding(&self) -> Option<Transaction> {
4331-
self.if_unbroadcasted_funding(|| self.funding_transaction.clone())
4331+
pub fn unbroadcasted_funding(&self, funding: &FundingScope) -> Option<Transaction> {
4332+
self.if_unbroadcasted_funding(|| funding.funding_transaction.clone())
43324333
}
43334334

43344335
/// Returns the transaction ID if there is a pending funding transaction that is yet to be
@@ -4392,8 +4393,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
43924393
}))
43934394
} else { None }
43944395
} else { None };
4395-
let unbroadcasted_batch_funding_txid = self.unbroadcasted_batch_funding_txid(&funding);
4396-
let unbroadcasted_funding_tx = self.unbroadcasted_funding();
4396+
let unbroadcasted_batch_funding_txid = self.unbroadcasted_batch_funding_txid(funding);
4397+
let unbroadcasted_funding_tx = self.unbroadcasted_funding(funding);
43974398

43984399
self.channel_state = ChannelState::ShutdownComplete;
43994400
self.update_time_counter += 1;
@@ -6219,7 +6220,7 @@ impl<SP: Deref> FundedChannel<SP> where
62196220
if funding_tx_opt.is_some() {
62206221
// We have a finalized funding transaction, so we can set the funding transaction and reset the
62216222
// signing session fields.
6222-
self.context.funding_transaction = funding_tx_opt;
6223+
self.funding.funding_transaction = funding_tx_opt;
62236224
self.context.next_funding_txid = None;
62246225
self.interactive_tx_signing_session = None;
62256226
}
@@ -6451,7 +6452,7 @@ impl<SP: Deref> FundedChannel<SP> where
64516452
// try to (re-)broadcast the funding transaction as we may have declined to broadcast it when we
64526453
// first received the funding_signed.
64536454
let mut funding_broadcastable = None;
6454-
if let Some(funding_transaction) = &self.context.funding_transaction {
6455+
if let Some(funding_transaction) = &self.funding.funding_transaction {
64556456
if (self.funding.is_outbound() || self.is_v2_established()) &&
64566457
(matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(flags) if !flags.is_set(AwaitingChannelReadyFlags::WAITING_FOR_BATCH)) ||
64576458
matches!(self.context.channel_state, ChannelState::ChannelReady(_)))
@@ -7326,7 +7327,7 @@ impl<SP: Deref> FundedChannel<SP> where
73267327
user_channel_id: self.context.user_id,
73277328
channel_capacity_satoshis: self.funding.channel_value_satoshis,
73287329
counterparty_node_id: self.context.counterparty_node_id,
7329-
unbroadcasted_funding_tx: self.context.unbroadcasted_funding(),
7330+
unbroadcasted_funding_tx: self.context.unbroadcasted_funding(&self.funding),
73307331
is_manual_broadcast: self.context.is_manual_broadcast,
73317332
channel_funding_txo: self.funding.get_funding_txo(),
73327333
last_local_balance_msat: self.funding.value_to_self_msat,
@@ -7734,7 +7735,7 @@ impl<SP: Deref> FundedChannel<SP> where
77347735
// Because deciding we're awaiting initial broadcast spuriously could result in
77357736
// funds-loss (as we don't have a monitor, but have the funding transaction confirmed),
77367737
// we hard-assert here, even in production builds.
7737-
if self.funding.is_outbound() { assert!(self.context.funding_transaction.is_some()); }
7738+
if self.funding.is_outbound() { assert!(self.funding.funding_transaction.is_some()); }
77387739
assert!(self.context.monitor_pending_channel_ready);
77397740
assert_eq!(self.context.latest_monitor_update_id, 0);
77407741
return true;
@@ -9109,8 +9110,8 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
91099110
self.context.minimum_depth = Some(COINBASE_MATURITY);
91109111
}
91119112

9112-
debug_assert!(self.context.funding_transaction.is_none());
9113-
self.context.funding_transaction = Some(funding_transaction);
9113+
debug_assert!(self.funding.funding_transaction.is_none());
9114+
self.funding.funding_transaction = Some(funding_transaction);
91149115
self.context.is_batch_funding = Some(()).filter(|_| is_batch_funding);
91159116

91169117
let funding_created = self.get_funding_created_msg(logger);
@@ -10195,7 +10196,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1019510196
}
1019610197

1019710198
self.funding.channel_transaction_parameters.write(writer)?;
10198-
self.context.funding_transaction.write(writer)?;
10199+
self.funding.funding_transaction.write(writer)?;
1019910200

1020010201
self.context.counterparty_cur_commitment_point.write(writer)?;
1020110202
self.context.counterparty_prev_commitment_point.write(writer)?;
@@ -10782,6 +10783,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1078210783
next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
1078310784

1078410785
channel_transaction_parameters: channel_parameters,
10786+
funding_transaction,
1078510787
},
1078610788
context: ChannelContext {
1078710789
user_id,
@@ -10860,7 +10862,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1086010862

1086110863
counterparty_forwarding_info,
1086210864

10863-
funding_transaction,
1086410865
is_batch_funding,
1086510866

1086610867
counterparty_cur_commitment_point,

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3296,7 +3296,7 @@ macro_rules! handle_monitor_update_completion {
32963296
.get_mut(&channel_id)
32973297
.and_then(Channel::as_funded_mut)
32983298
{
3299-
batch_funding_tx = batch_funding_tx.or_else(|| funded_chan.context.unbroadcasted_funding());
3299+
batch_funding_tx = batch_funding_tx.or_else(|| funded_chan.context.unbroadcasted_funding(&funded_chan.funding));
33003300
funded_chan.set_batch_ready();
33013301
let mut pending_events = $self.pending_events.lock().unwrap();
33023302
emit_channel_pending_event!(pending_events, funded_chan);
@@ -8531,7 +8531,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
85318531
msg: tx_signatures,
85328532
});
85338533
}
8534-
if let Some(ref funding_tx) = chan.context.unbroadcasted_funding() {
8534+
if let Some(ref funding_tx) = chan.context.unbroadcasted_funding(&chan.funding) {
85358535
self.tx_broadcaster.broadcast_transactions(&[funding_tx]);
85368536
{
85378537
let mut pending_events = self.pending_events.lock().unwrap();

0 commit comments

Comments
 (0)