Skip to content

Commit c41c287

Browse files
committed
(XXX TEST) Optionally reject HTLC forwards over priv chans with a new config
Private nodes should never wish to forward HTLCs at all, which we support here by disabling forwards out over private channels by default. As private nodes should not have any public channels, this suffices, without allowing users to disable forwarding over channels announced in the routing graph already. Closes lightningdevkit#969
1 parent 291872a commit c41c287

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,15 +1519,23 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
15191519
// short_channel_id is non-0 in any ::Forward.
15201520
if let &PendingHTLCRouting::Forward { ref short_channel_id, .. } = routing {
15211521
let id_option = channel_state.as_ref().unwrap().short_to_id.get(&short_channel_id).cloned();
1522-
let forwarding_id = match id_option {
1523-
None => { // unknown_next_peer
1524-
return_err!("Don't have available channel for forwarding as requested.", 0x4000 | 10, &[0;0]);
1525-
},
1526-
Some(id) => id.clone(),
1527-
};
15281522
if let Some((err, code, chan_update)) = loop {
1523+
let forwarding_id = match id_option {
1524+
None => { // unknown_next_peer
1525+
break Some(("Don't have available channel for forwarding as requested.", 0x4000 | 10, None));
1526+
},
1527+
Some(id) => id.clone(),
1528+
};
1529+
15291530
let chan = channel_state.as_mut().unwrap().by_id.get_mut(&forwarding_id).unwrap();
15301531

1532+
if !chan.should_announce() && !self.default_configuration.accept_forwards_to_priv_channels {
1533+
// Note that the behavior here should be identical to the above block - we
1534+
// should NOT reveal the existence or non-existence of a private channel if
1535+
// we don't allow forwards outbound over them.
1536+
break Some(("Don't have available channel for forwarding as requested.", 0x4000 | 10, None));
1537+
}
1538+
15311539
// Note that we could technically not return an error yet here and just hope
15321540
// that the connection is reestablished or monitor updated by the time we get
15331541
// around to doing the actual forward, but better to fail early if we can and

lightning/src/util/config.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,14 @@ pub struct ChannelHandshakeLimits {
105105
///
106106
/// Default value: 144, or roughly one day and only applies to outbound channels.
107107
pub max_minimum_depth: u32,
108-
/// Set to force the incoming channel to match our announced channel preference in
109-
/// ChannelConfig.
108+
/// Set to force an incoming channel to match our announced channel preference in
109+
/// [`ChannelConfig::announced_channel`].
110110
///
111-
/// Default value: true, to make the default that no announced channels are possible (which is
112-
/// appropriate for any nodes which are not online very reliably).
111+
/// For a node which is not online reliably, this should be set to true and
112+
/// [`ChannelConfig::announced_channel`] set to false, ensuring that no announced (aka public)
113+
/// channels will ever be opened.
114+
///
115+
/// Default value: true.
113116
pub force_announced_channel_preference: bool,
114117
/// Set to the amount of time we're willing to wait to claim money back to us.
115118
///
@@ -179,7 +182,7 @@ pub struct ChannelConfig {
179182
/// This should only be set to true for nodes which expect to be online reliably.
180183
///
181184
/// As the node which funds a channel picks this value this will only apply for new outbound
182-
/// channels unless ChannelHandshakeLimits::force_announced_channel_preferences is set.
185+
/// channels unless [`ChannelHandshakeLimits::force_announced_channel_preference`] is set.
183186
///
184187
/// This cannot be changed after the initial channel handshake.
185188
///
@@ -233,6 +236,23 @@ pub struct UserConfig {
233236
pub peer_channel_config_limits: ChannelHandshakeLimits,
234237
/// Channel config which affects behavior during channel lifetime.
235238
pub channel_options: ChannelConfig,
239+
/// If a channel is not set to be publicly announced, we reject HTLCs which were set to be
240+
/// forwarded over the channel if this is set to false. This prevents use from taking on
241+
/// HTLC-forwarding risk when we intend to run as a node which is not online reliably.
242+
///
243+
/// For nodes which are not online reliably, you should set all channels to *not* be announced
244+
/// (using [`ChannelConfig::announced_channel`] and
245+
/// [`ChannelHandshakeLimits::force_announced_channel_preference`]) and set this to false to
246+
/// ensure you are not exposed to any forwarding risk.
247+
///
248+
/// Note that because you cannot change a channel's announced state after creation, there is no
249+
/// way to disable forwarding on public channels retroactively. Thus, in order to change a node
250+
/// from a publicly-announced forwarding node to a private non-forwarding node you must close
251+
/// all your channels and open new ones. For privacy, you should also change your node_id
252+
/// (swapping all private and public key material for new ones) at that time.
253+
///
254+
/// Default value: false.
255+
pub accept_forwards_to_priv_channels: bool,
236256
}
237257

238258
impl Default for UserConfig {
@@ -241,6 +261,7 @@ impl Default for UserConfig {
241261
own_channel_config: ChannelHandshakeConfig::default(),
242262
peer_channel_config_limits: ChannelHandshakeLimits::default(),
243263
channel_options: ChannelConfig::default(),
264+
accept_forwards_to_priv_channels: false,
244265
}
245266
}
246267
}

0 commit comments

Comments
 (0)