Skip to content

Commit

Permalink
Add manually_broadcast_outbound_channels
Browse files Browse the repository at this point in the history
  Add a new flag to `UserConfig` and `ChannelContext`
  to allow users to broadcast an outbound channel funding transaction
  manually and halt the automatic broadcasting from LDK.
  • Loading branch information
jbesraa committed Apr 29, 2024
1 parent 8701b1b commit 7feebc5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,16 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
/// If we can't release a [`ChannelMonitorUpdate`] until some external action completes, we
/// store it here and only release it to the `ChannelManager` once it asks for it.
blocked_monitor_updates: Vec<PendingChannelMonitorUpdate>,

/// Upon receving a `FundingSigned` message, if the channel is
/// outbound and we are ready to broadcast the funding
/// transaction, LDK will broadcast it and set the channel state
/// to `ChannelPending`.
///
/// Using this flag will allow you to halt the broadcast of the
/// funding transaction and the channel state will be set to
/// `FundingSigned`.
manually_broadcast_outbound_channels: Option<()>,
}

impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
Expand Down Expand Up @@ -1872,6 +1882,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
local_initiated_shutdown: None,

blocked_monitor_updates: Vec::new(),

manually_broadcast_outbound_channels: None,
};

Ok(channel_context)
Expand Down Expand Up @@ -2092,6 +2104,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {

blocked_monitor_updates: Vec::new(),
local_initiated_shutdown: None,
manually_broadcast_outbound_channels: if config.manually_broadcast_outbound_channels { Some(()) } else { None }
})
}

Expand Down Expand Up @@ -2333,6 +2346,10 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
self.config.options.forwarding_fee_proportional_millionths
}

pub fn get_manually_broadcast_outbound_channels(&self) -> Option<()> {
self.manually_broadcast_outbound_channels
}

pub fn get_cltv_expiry_delta(&self) -> u16 {
cmp::max(self.config.options.cltv_expiry_delta, MIN_CLTV_EXPIRY_DELTA)
}
Expand Down Expand Up @@ -9047,6 +9064,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
let mut holding_cell_skimmed_fees_opt: Option<Vec<Option<u64>>> = None;

let mut is_batch_funding: Option<()> = None;
let mut manually_broadcast_outbound_channels: Option<()> = None;

let mut local_initiated_shutdown: Option<()> = None;

Expand Down Expand Up @@ -9088,6 +9106,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
(43, malformed_htlcs, optional_vec), // Added in 0.0.119
// 45 and 47 are reserved for async signing
(49, local_initiated_shutdown, option),
(51, manually_broadcast_outbound_channels, option),
});

let (channel_keys_id, holder_signer) = if let Some(channel_keys_id) = channel_keys_id {
Expand Down Expand Up @@ -9322,6 +9341,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
local_initiated_shutdown,

blocked_monitor_updates: blocked_monitor_updates.unwrap(),
manually_broadcast_outbound_channels,
},
#[cfg(any(dual_funding, splicing))]
dual_funding_channel_context: None,
Expand Down
4 changes: 4 additions & 0 deletions lightning/src/util/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,8 @@ pub struct UserConfig {
///
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
pub accept_mpp_keysend: bool,
/// broadcast funding transaction manually
pub manually_broadcast_outbound_channels: bool,
}

impl Default for UserConfig {
Expand All @@ -823,6 +825,7 @@ impl Default for UserConfig {
manually_accept_inbound_channels: false,
accept_intercept_htlcs: false,
accept_mpp_keysend: false,
manually_broadcast_outbound_channels: false,
}
}
}
Expand All @@ -842,6 +845,7 @@ impl Readable for UserConfig {
manually_accept_inbound_channels: Readable::read(reader)?,
accept_intercept_htlcs: Readable::read(reader)?,
accept_mpp_keysend: Readable::read(reader)?,
manually_broadcast_outbound_channels: Readable::read(reader)?,
})
}
}

0 comments on commit 7feebc5

Please sign in to comment.