Skip to content

Commit 850ca13

Browse files
committed
Move announced_channel to ChannelHandshakeConfig
In the near future, we plan to allow users to update their `ChannelConfig` after the initial channel handshake. In order to reuse the same struct and expose it to users, we opt to move out all static fields that cannot be updated after the initial channel handshake.
1 parent a551a62 commit 850ca13

File tree

10 files changed

+48
-37
lines changed

10 files changed

+48
-37
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {
357357

358358
let mut config = UserConfig::default();
359359
config.channel_options.forwarding_fee_proportional_millionths = 0;
360-
config.channel_options.announced_channel = true;
360+
config.own_channel_config.announced_channel = true;
361361
let network = Network::Bitcoin;
362362
let params = ChainParameters {
363363
network,
@@ -377,7 +377,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {
377377

378378
let mut config = UserConfig::default();
379379
config.channel_options.forwarding_fee_proportional_millionths = 0;
380-
config.channel_options.announced_channel = true;
380+
config.own_channel_config.announced_channel = true;
381381

382382
let mut monitors = HashMap::new();
383383
let mut old_monitors = $old_monitors.latest_monitors.lock().unwrap();

fuzz/src/full_stack.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
383383
let keys_manager = Arc::new(KeyProvider { node_secret: our_network_key.clone(), inbound_payment_key: KeyMaterial(inbound_payment_key.try_into().unwrap()), counter: AtomicU64::new(0) });
384384
let mut config = UserConfig::default();
385385
config.channel_options.forwarding_fee_proportional_millionths = slice_to_be32(get_slice!(4));
386-
config.channel_options.announced_channel = get_slice!(1)[0] != 0;
386+
config.own_channel_config.announced_channel = get_slice!(1)[0] != 0;
387387
let network = Network::Bitcoin;
388388
let params = ChainParameters {
389389
network,

lightning-invoice/src/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ mod test {
659659
// `msgs::ChannelUpdate` is never handled for the node(s). As the `msgs::ChannelUpdate`
660660
// is never handled, the `channel.counterparty.forwarding_info` is never assigned.
661661
let mut private_chan_cfg = UserConfig::default();
662-
private_chan_cfg.channel_options.announced_channel = false;
662+
private_chan_cfg.own_channel_config.announced_channel = false;
663663
let temporary_channel_id = nodes[2].node.create_channel(nodes[0].node.get_our_node_id(), 1_000_000, 500_000_000, 42, Some(private_chan_cfg)).unwrap();
664664
let open_channel = get_event_msg!(nodes[2], MessageSendEvent::SendOpenChannel, nodes[0].node.get_our_node_id());
665665
nodes[0].node.handle_open_channel(&nodes[2].node.get_our_node_id(), InitFeatures::known(), &open_channel);
@@ -1046,7 +1046,7 @@ mod test {
10461046
// `msgs::ChannelUpdate` is never handled for the node(s). As the `msgs::ChannelUpdate`
10471047
// is never handled, the `channel.counterparty.forwarding_info` is never assigned.
10481048
let mut private_chan_cfg = UserConfig::default();
1049-
private_chan_cfg.channel_options.announced_channel = false;
1049+
private_chan_cfg.own_channel_config.announced_channel = false;
10501050
let temporary_channel_id = nodes[1].node.create_channel(nodes[3].node.get_our_node_id(), 1_000_000, 500_000_000, 42, Some(private_chan_cfg)).unwrap();
10511051
let open_channel = get_event_msg!(nodes[1], MessageSendEvent::SendOpenChannel, nodes[3].node.get_our_node_id());
10521052
nodes[3].node.handle_open_channel(&nodes[1].node.get_our_node_id(), InitFeatures::known(), &open_channel);

lightning/src/ln/channel.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ impl<Signer: Sign> Channel<Signer> {
855855
// available. If it's private, we first try `scid_privacy` as it provides better privacy
856856
// with no other changes, and fall back to `only_static_remotekey`
857857
let mut ret = ChannelTypeFeatures::only_static_remote_key();
858-
if !config.channel_options.announced_channel && config.own_channel_config.negotiate_scid_privacy {
858+
if !config.own_channel_config.announced_channel && config.own_channel_config.negotiate_scid_privacy {
859859
ret.set_scid_privacy_required();
860860
}
861861
ret
@@ -1182,7 +1182,7 @@ impl<Signer: Sign> Channel<Signer> {
11821182
// Convert things into internal flags and prep our state:
11831183

11841184
if config.peer_channel_config_limits.force_announced_channel_preference {
1185-
if local_config.announced_channel != announced_channel {
1185+
if config.own_channel_config.announced_channel != announced_channel {
11861186
return Err(ChannelError::Close("Peer tried to open channel but their announcement preference is different from ours".to_owned()));
11871187
}
11881188
}
@@ -6918,7 +6918,7 @@ mod tests {
69186918

69196919
let counterparty_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
69206920
let mut config = UserConfig::default();
6921-
config.channel_options.announced_channel = false;
6921+
config.own_channel_config.announced_channel = false;
69226922
let mut chan = Channel::<InMemorySigner>::new_outbound(&&feeest, &&keys_provider, counterparty_node_id, &InitFeatures::known(), 10_000_000, 100000, 42, &config, 0, 42).unwrap(); // Nothing uses their network key in this test
69236923
chan.holder_dust_limit_satoshis = 546;
69246924
chan.counterparty_selected_channel_reserve_satoshis = Some(0); // Filled in in accept_channel

lightning/src/ln/functional_test_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ pub fn create_announced_chan_between_nodes_with_value<'a, 'b, 'c, 'd>(nodes: &'a
772772

773773
pub fn create_unannounced_chan_between_nodes_with_value<'a, 'b, 'c, 'd>(nodes: &'a Vec<Node<'b, 'c, 'd>>, a: usize, b: usize, channel_value: u64, push_msat: u64, a_flags: InitFeatures, b_flags: InitFeatures) -> (msgs::ChannelReady, Transaction) {
774774
let mut no_announce_cfg = test_default_channel_config();
775-
no_announce_cfg.channel_options.announced_channel = false;
775+
no_announce_cfg.own_channel_config.announced_channel = false;
776776
nodes[a].node.create_channel(nodes[b].node.get_our_node_id(), channel_value, push_msat, 42, Some(no_announce_cfg)).unwrap();
777777
let open_channel = get_event_msg!(nodes[a], MessageSendEvent::SendOpenChannel, nodes[b].node.get_our_node_id());
778778
nodes[b].node.handle_open_channel(&nodes[a].node.get_our_node_id(), a_flags, &open_channel);
@@ -1956,7 +1956,7 @@ pub fn test_default_channel_config() -> UserConfig {
19561956
// Set cltv_expiry_delta slightly lower to keep the final CLTV values inside one byte in our
19571957
// tests so that our script-length checks don't fail (see ACCEPTED_HTLC_SCRIPT_WEIGHT).
19581958
default_config.channel_options.cltv_expiry_delta = MIN_CLTV_EXPIRY_DELTA;
1959-
default_config.channel_options.announced_channel = true;
1959+
default_config.own_channel_config.announced_channel = true;
19601960
default_config.peer_channel_config_limits.force_announced_channel_preference = false;
19611961
// When most of our tests were written, the default HTLC minimum was fixed at 1000.
19621962
// It now defaults to 1, so we simply set it to the expected value here.

lightning/src/ln/functional_tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,11 +2362,11 @@ fn channel_monitor_network_test() {
23622362
fn test_justice_tx() {
23632363
// Test justice txn built on revoked HTLC-Success tx, against both sides
23642364
let mut alice_config = UserConfig::default();
2365-
alice_config.channel_options.announced_channel = true;
2365+
alice_config.own_channel_config.announced_channel = true;
23662366
alice_config.peer_channel_config_limits.force_announced_channel_preference = false;
23672367
alice_config.own_channel_config.our_to_self_delay = 6 * 24 * 5;
23682368
let mut bob_config = UserConfig::default();
2369-
bob_config.channel_options.announced_channel = true;
2369+
bob_config.own_channel_config.announced_channel = true;
23702370
bob_config.peer_channel_config_limits.force_announced_channel_preference = false;
23712371
bob_config.own_channel_config.our_to_self_delay = 6 * 24 * 3;
23722372
let user_cfgs = [Some(alice_config), Some(bob_config)];
@@ -8282,16 +8282,16 @@ fn test_channel_update_has_correct_htlc_maximum_msat() {
82828282
// 2. MUST be set to less than or equal to the `max_htlc_value_in_flight_msat` received from the peer.
82838283

82848284
let mut config_30_percent = UserConfig::default();
8285-
config_30_percent.channel_options.announced_channel = true;
8285+
config_30_percent.own_channel_config.announced_channel = true;
82868286
config_30_percent.own_channel_config.max_inbound_htlc_value_in_flight_percent_of_channel = 30;
82878287
let mut config_50_percent = UserConfig::default();
8288-
config_50_percent.channel_options.announced_channel = true;
8288+
config_50_percent.own_channel_config.announced_channel = true;
82898289
config_50_percent.own_channel_config.max_inbound_htlc_value_in_flight_percent_of_channel = 50;
82908290
let mut config_95_percent = UserConfig::default();
8291-
config_95_percent.channel_options.announced_channel = true;
8291+
config_95_percent.own_channel_config.announced_channel = true;
82928292
config_95_percent.own_channel_config.max_inbound_htlc_value_in_flight_percent_of_channel = 95;
82938293
let mut config_100_percent = UserConfig::default();
8294-
config_100_percent.channel_options.announced_channel = true;
8294+
config_100_percent.own_channel_config.announced_channel = true;
82958295
config_100_percent.own_channel_config.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
82968296

82978297
let chanmon_cfgs = create_chanmon_cfgs(4);

lightning/src/ln/onion_route_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ fn test_onion_failure() {
308308
// Channel::get_counterparty_htlc_minimum_msat().
309309
let mut node_2_cfg: UserConfig = Default::default();
310310
node_2_cfg.own_channel_config.our_htlc_minimum_msat = 2000;
311-
node_2_cfg.channel_options.announced_channel = true;
311+
node_2_cfg.own_channel_config.announced_channel = true;
312312
node_2_cfg.peer_channel_config_limits.force_announced_channel_preference = false;
313313

314314
// When this test was written, the default base fee floated based on the HTLC count.
@@ -600,7 +600,7 @@ fn test_default_to_onion_payload_tlv_format() {
600600
// `features` for a node in the `network_graph` exists, or when the node isn't in the
601601
// `network_graph`, and no other known `features` for the node exists.
602602
let mut priv_channels_conf = UserConfig::default();
603-
priv_channels_conf.channel_options.announced_channel = false;
603+
priv_channels_conf.own_channel_config.announced_channel = false;
604604
let chanmon_cfgs = create_chanmon_cfgs(5);
605605
let node_cfgs = create_node_cfgs(5, &chanmon_cfgs);
606606
let node_chanmgrs = create_node_chanmgrs(5, &node_cfgs, &[None, None, None, None, Some(priv_channels_conf)]);
@@ -1085,7 +1085,7 @@ fn test_phantom_dust_exposure_failure() {
10851085
let max_dust_exposure = 546;
10861086
let mut receiver_config = UserConfig::default();
10871087
receiver_config.channel_options.max_dust_htlc_exposure_msat = max_dust_exposure;
1088-
receiver_config.channel_options.announced_channel = true;
1088+
receiver_config.own_channel_config.announced_channel = true;
10891089

10901090
let chanmon_cfgs = create_chanmon_cfgs(2);
10911091
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);

lightning/src/ln/priv_short_conf_tests.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ fn do_test_1_conf_open(connect_style: ConnectStyle) {
171171
// tests that we properly send one in that case.
172172
let mut alice_config = UserConfig::default();
173173
alice_config.own_channel_config.minimum_depth = 1;
174-
alice_config.channel_options.announced_channel = true;
174+
alice_config.own_channel_config.announced_channel = true;
175175
alice_config.peer_channel_config_limits.force_announced_channel_preference = false;
176176
let mut bob_config = UserConfig::default();
177177
bob_config.own_channel_config.minimum_depth = 1;
178-
bob_config.channel_options.announced_channel = true;
178+
bob_config.own_channel_config.announced_channel = true;
179179
bob_config.peer_channel_config_limits.force_announced_channel_preference = false;
180180
let chanmon_cfgs = create_chanmon_cfgs(2);
181181
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
@@ -308,7 +308,7 @@ fn test_scid_privacy_on_pub_channel() {
308308
let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
309309

310310
let mut scid_privacy_cfg = test_default_channel_config();
311-
scid_privacy_cfg.channel_options.announced_channel = true;
311+
scid_privacy_cfg.own_channel_config.announced_channel = true;
312312
scid_privacy_cfg.own_channel_config.negotiate_scid_privacy = true;
313313
nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, Some(scid_privacy_cfg)).unwrap();
314314
let mut open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
@@ -332,7 +332,7 @@ fn test_scid_privacy_negotiation() {
332332
let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
333333

334334
let mut scid_privacy_cfg = test_default_channel_config();
335-
scid_privacy_cfg.channel_options.announced_channel = false;
335+
scid_privacy_cfg.own_channel_config.announced_channel = false;
336336
scid_privacy_cfg.own_channel_config.negotiate_scid_privacy = true;
337337
nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, Some(scid_privacy_cfg)).unwrap();
338338

@@ -378,7 +378,7 @@ fn test_inbound_scid_privacy() {
378378
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, InitFeatures::known(), InitFeatures::known());
379379

380380
let mut no_announce_cfg = test_default_channel_config();
381-
no_announce_cfg.channel_options.announced_channel = false;
381+
no_announce_cfg.own_channel_config.announced_channel = false;
382382
no_announce_cfg.own_channel_config.negotiate_scid_privacy = true;
383383
nodes[1].node.create_channel(nodes[2].node.get_our_node_id(), 100_000, 10_000, 42, Some(no_announce_cfg)).unwrap();
384384
let mut open_channel = get_event_msg!(nodes[1], MessageSendEvent::SendOpenChannel, nodes[2].node.get_our_node_id());
@@ -665,7 +665,7 @@ fn test_0conf_channel_with_async_monitor() {
665665

666666
create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 1_000_000, 0, InitFeatures::known(), InitFeatures::known());
667667

668-
chan_config.channel_options.announced_channel = false;
668+
chan_config.own_channel_config.announced_channel = false;
669669
nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, Some(chan_config)).unwrap();
670670
let open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
671671

@@ -811,7 +811,7 @@ fn test_0conf_close_no_early_chan_update() {
811811
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
812812

813813
// This is the default but we force it on anyway
814-
chan_config.channel_options.announced_channel = true;
814+
chan_config.own_channel_config.announced_channel = true;
815815
open_zero_conf_channel(&nodes[0], &nodes[1], Some(chan_config));
816816

817817
// We can use the channel immediately, but won't generate a channel_update until we get confs
@@ -835,7 +835,7 @@ fn test_public_0conf_channel() {
835835
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
836836

837837
// This is the default but we force it on anyway
838-
chan_config.channel_options.announced_channel = true;
838+
chan_config.own_channel_config.announced_channel = true;
839839
let tx = open_zero_conf_channel(&nodes[0], &nodes[1], Some(chan_config));
840840

841841
// We can use the channel immediately, but we can't announce it until we get 6+ confirmations
@@ -888,7 +888,7 @@ fn test_0conf_channel_reorg() {
888888
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
889889

890890
// This is the default but we force it on anyway
891-
chan_config.channel_options.announced_channel = true;
891+
chan_config.own_channel_config.announced_channel = true;
892892
let tx = open_zero_conf_channel(&nodes[0], &nodes[1], Some(chan_config));
893893

894894
// We can use the channel immediately, but we can't announce it until we get 6+ confirmations

lightning/src/ln/shutdown_tests.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ fn test_upfront_shutdown_script() {
409409
// enforce it at shutdown message
410410

411411
let mut config = UserConfig::default();
412-
config.channel_options.announced_channel = true;
412+
config.own_channel_config.announced_channel = true;
413413
config.peer_channel_config_limits.force_announced_channel_preference = false;
414414
config.channel_options.commit_upfront_shutdown_pubkey = false;
415415
let user_cfgs = [None, Some(config), None];
@@ -574,7 +574,7 @@ fn test_invalid_upfront_shutdown_script() {
574574
#[test]
575575
fn test_segwit_v0_shutdown_script() {
576576
let mut config = UserConfig::default();
577-
config.channel_options.announced_channel = true;
577+
config.own_channel_config.announced_channel = true;
578578
config.peer_channel_config_limits.force_announced_channel_preference = false;
579579
config.channel_options.commit_upfront_shutdown_pubkey = false;
580580
let user_cfgs = [None, Some(config), None];
@@ -609,7 +609,7 @@ fn test_segwit_v0_shutdown_script() {
609609
#[test]
610610
fn test_anysegwit_shutdown_script() {
611611
let mut config = UserConfig::default();
612-
config.channel_options.announced_channel = true;
612+
config.own_channel_config.announced_channel = true;
613613
config.peer_channel_config_limits.force_announced_channel_preference = false;
614614
config.channel_options.commit_upfront_shutdown_pubkey = false;
615615
let user_cfgs = [None, Some(config), None];
@@ -644,7 +644,7 @@ fn test_anysegwit_shutdown_script() {
644644
#[test]
645645
fn test_unsupported_anysegwit_shutdown_script() {
646646
let mut config = UserConfig::default();
647-
config.channel_options.announced_channel = true;
647+
config.own_channel_config.announced_channel = true;
648648
config.peer_channel_config_limits.force_announced_channel_preference = false;
649649
config.channel_options.commit_upfront_shutdown_pubkey = false;
650650
let user_cfgs = [None, Some(config), None];
@@ -686,7 +686,7 @@ fn test_unsupported_anysegwit_shutdown_script() {
686686
#[test]
687687
fn test_invalid_shutdown_script() {
688688
let mut config = UserConfig::default();
689-
config.channel_options.announced_channel = true;
689+
config.own_channel_config.announced_channel = true;
690690
config.peer_channel_config_limits.force_announced_channel_preference = false;
691691
config.channel_options.commit_upfront_shutdown_pubkey = false;
692692
let user_cfgs = [None, Some(config), None];

lightning/src/util/config.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,24 @@ pub struct ChannelHandshakeConfig {
9494
/// private channel without that option.
9595
///
9696
/// Ignored if the channel is negotiated to be announced, see
97-
/// [`ChannelConfig::announced_channel`] and
97+
/// [`ChannelHandshakeConfig::announced_channel`] and
9898
/// [`ChannelHandshakeLimits::force_announced_channel_preference`] for more.
9999
///
100100
/// Default value: false. This value is likely to change to true in the future.
101101
///
102102
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
103103
/// [`DecodeError:InvalidValue`]: crate::ln::msgs::DecodeError::InvalidValue
104104
pub negotiate_scid_privacy: bool,
105+
/// Set to announce the channel publicly and notify all nodes that they can route via this
106+
/// channel.
107+
///
108+
/// This should only be set to true for nodes which expect to be online reliably.
109+
///
110+
/// As the node which funds a channel picks this value this will only apply for new outbound
111+
/// channels unless [`ChannelHandshakeLimits::force_announced_channel_preference`] is set.
112+
///
113+
/// Default value: false.
114+
pub announced_channel: bool,
105115
}
106116

107117
impl Default for ChannelHandshakeConfig {
@@ -112,6 +122,7 @@ impl Default for ChannelHandshakeConfig {
112122
our_htlc_minimum_msat: 1,
113123
max_inbound_htlc_value_in_flight_percent_of_channel: 10,
114124
negotiate_scid_privacy: false,
125+
announced_channel: false,
115126
}
116127
}
117128
}
@@ -186,10 +197,10 @@ pub struct ChannelHandshakeLimits {
186197
/// Default value: true
187198
pub trust_own_funding_0conf: bool,
188199
/// Set to force an incoming channel to match our announced channel preference in
189-
/// [`ChannelConfig::announced_channel`].
200+
/// [`ChannelHandshakeConfig::announced_channel`].
190201
///
191202
/// For a node which is not online reliably, this should be set to true and
192-
/// [`ChannelConfig::announced_channel`] set to false, ensuring that no announced (aka public)
203+
/// [`ChannelHandshakeConfig::announced_channel`] set to false, ensuring that no announced (aka public)
193204
/// channels will ever be opened.
194205
///
195206
/// Default value: true.
@@ -372,7 +383,7 @@ pub struct UserConfig {
372383
/// node which is not online reliably.
373384
///
374385
/// For nodes which are not online reliably, you should set all channels to *not* be announced
375-
/// (using [`ChannelConfig::announced_channel`] and
386+
/// (using [`ChannelHandshakeConfig::announced_channel`] and
376387
/// [`ChannelHandshakeLimits::force_announced_channel_preference`]) and set this to false to
377388
/// ensure you are not exposed to any forwarding risk.
378389
///

0 commit comments

Comments
 (0)