Skip to content

Commit cdc4ebf

Browse files
Add manual-funding broadcast tracking to ChannelMonitor
Adds `is_manual_broadcast` and `funding_seen_onchain` flags to track whether the channel uses manual funding broadcasts and whether we've seen the funding tx confirm. This enables deferring holder commitment broadcasts until after the funding tx is actually broadcast. For example, in LSPS2 with client_trusts_lsp=true, the LSP may defer broadcasting the funding tx until the client claims an HTLC, so we need to avoid broadcasting commitments that reference outputs that don't exist yet.
1 parent 8376197 commit cdc4ebf

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,15 @@ pub(crate) struct ChannelMonitorImpl<Signer: EcdsaChannelSigner> {
11871187
funding: FundingScope,
11881188
pending_funding: Vec<FundingScope>,
11891189

1190+
/// True if this channel was configured for manual funding broadcasts. Monitors written by
1191+
/// versions prior to LDK 0.2 load with `false` until a new update persists it.
1192+
is_manual_broadcast: bool,
1193+
/// True once we've observed either funding transaction on-chain. Older monitors prior to LDK 0.2
1194+
/// assume this is `true` when absent during upgrade so holder broadcasts aren't gated unexpectedly.
1195+
/// In manual-broadcast channels we also use this to trigger deferred holder
1196+
/// broadcasts once the funding transaction finally appears on-chain.
1197+
funding_seen_onchain: bool,
1198+
11901199
latest_update_id: u64,
11911200
commitment_transaction_number_obscure_factor: u64,
11921201

@@ -1725,6 +1734,8 @@ pub(crate) fn write_chanmon_internal<Signer: EcdsaChannelSigner, W: Writer>(
17251734
(32, channel_monitor.pending_funding, optional_vec),
17261735
(33, channel_monitor.htlcs_resolved_to_user, required),
17271736
(34, channel_monitor.alternative_funding_confirmed, option),
1737+
(35, channel_monitor.is_manual_broadcast, required),
1738+
(37, channel_monitor.funding_seen_onchain, required),
17281739
});
17291740

17301741
Ok(())
@@ -1853,6 +1864,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
18531864
commitment_transaction_number_obscure_factor: u64,
18541865
initial_holder_commitment_tx: HolderCommitmentTransaction, best_block: BestBlock,
18551866
counterparty_node_id: PublicKey, channel_id: ChannelId,
1867+
is_manual_broadcast: bool,
18561868
) -> ChannelMonitor<Signer> {
18571869

18581870
assert!(commitment_transaction_number_obscure_factor <= (1 << 48));
@@ -1899,6 +1911,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
18991911
},
19001912
pending_funding: vec![],
19011913

1914+
is_manual_broadcast,
1915+
funding_seen_onchain: false,
1916+
19021917
latest_update_id: 0,
19031918
commitment_transaction_number_obscure_factor,
19041919

@@ -6456,6 +6471,8 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
64566471
let mut channel_parameters = None;
64576472
let mut pending_funding = None;
64586473
let mut alternative_funding_confirmed = None;
6474+
let mut is_manual_broadcast = RequiredWrapper(None);
6475+
let mut funding_seen_onchain = RequiredWrapper(None);
64596476
read_tlv_fields!(reader, {
64606477
(1, funding_spend_confirmed, option),
64616478
(3, htlcs_resolved_on_chain, optional_vec),
@@ -6476,6 +6493,8 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
64766493
(32, pending_funding, optional_vec),
64776494
(33, htlcs_resolved_to_user, option),
64786495
(34, alternative_funding_confirmed, option),
6496+
(35, is_manual_broadcast, (default_value, false)),
6497+
(37, funding_seen_onchain, (default_value, true)),
64796498
});
64806499
// Note that `payment_preimages_with_info` was added (and is always written) in LDK 0.1, so
64816500
// we can use it to determine if this monitor was last written by LDK 0.1 or later.
@@ -6593,6 +6612,10 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
65936612
prev_holder_commitment_tx,
65946613
},
65956614
pending_funding: pending_funding.unwrap_or(vec![]),
6615+
is_manual_broadcast: is_manual_broadcast.0.unwrap(),
6616+
// Older monitors prior to LDK 0.2 assume this is `true` when absent
6617+
// during upgrade so holder broadcasts aren't gated unexpectedly.
6618+
funding_seen_onchain: funding_seen_onchain.0.unwrap(),
65966619

65976620
latest_update_id,
65986621
commitment_transaction_number_obscure_factor,

lightning/src/ln/channel.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3058,6 +3058,7 @@ where
30583058
funding.get_holder_selected_contest_delay(), &context.destination_script,
30593059
&funding.channel_transaction_parameters, funding.is_outbound(), obscure_factor,
30603060
holder_commitment_tx, best_block, context.counterparty_node_id, context.channel_id(),
3061+
context.is_manual_broadcast,
30613062
);
30623063
channel_monitor.provide_initial_counterparty_commitment_tx(
30633064
counterparty_initial_commitment_tx.clone(),

0 commit comments

Comments
 (0)