From: Wilmer Paulino Date: Mon, 13 Jun 2022 19:53:56 +0000 (-0700) Subject: Rename UserConfig and LegacyChannelConfig fields X-Git-Tag: v0.0.109~16^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=44fa3acae85888982b2c808bc4b401e96d33822f;p=rust-lightning Rename UserConfig and LegacyChannelConfig fields The current names aren't very clear to what each field represents, this commit aims to improve that. --- diff --git a/fuzz/src/chanmon_consistency.rs b/fuzz/src/chanmon_consistency.rs index 8e70ba42..615f3aad 100644 --- a/fuzz/src/chanmon_consistency.rs +++ b/fuzz/src/chanmon_consistency.rs @@ -356,8 +356,8 @@ pub fn do_test(data: &[u8], underlying_out: Out) { Arc::new(TestPersister { update_ret: Mutex::new(Ok(())) }), Arc::clone(&keys_manager))); let mut config = UserConfig::default(); - config.channel_options.forwarding_fee_proportional_millionths = 0; - config.own_channel_config.announced_channel = true; + config.channel_config.forwarding_fee_proportional_millionths = 0; + config.channel_handshake_config.announced_channel = true; let network = Network::Bitcoin; let params = ChainParameters { network, @@ -376,8 +376,8 @@ pub fn do_test(data: &[u8], underlying_out: Out) { Arc::new(TestPersister { update_ret: Mutex::new(Ok(())) }), Arc::clone(& $keys_manager))); let mut config = UserConfig::default(); - config.channel_options.forwarding_fee_proportional_millionths = 0; - config.own_channel_config.announced_channel = true; + config.channel_config.forwarding_fee_proportional_millionths = 0; + config.channel_handshake_config.announced_channel = true; let mut monitors = HashMap::new(); let mut old_monitors = $old_monitors.latest_monitors.lock().unwrap(); diff --git a/fuzz/src/full_stack.rs b/fuzz/src/full_stack.rs index 782457cf..fae14de5 100644 --- a/fuzz/src/full_stack.rs +++ b/fuzz/src/full_stack.rs @@ -382,8 +382,8 @@ pub fn do_test(data: &[u8], logger: &Arc) { 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) }); let mut config = UserConfig::default(); - config.channel_options.forwarding_fee_proportional_millionths = slice_to_be32(get_slice!(4)); - config.own_channel_config.announced_channel = get_slice!(1)[0] != 0; + config.channel_config.forwarding_fee_proportional_millionths = slice_to_be32(get_slice!(4)); + config.channel_handshake_config.announced_channel = get_slice!(1)[0] != 0; let network = Network::Bitcoin; let params = ChainParameters { network, diff --git a/lightning-invoice/src/utils.rs b/lightning-invoice/src/utils.rs index c79e5904..e09fd836 100644 --- a/lightning-invoice/src/utils.rs +++ b/lightning-invoice/src/utils.rs @@ -659,7 +659,7 @@ mod test { // `msgs::ChannelUpdate` is never handled for the node(s). As the `msgs::ChannelUpdate` // is never handled, the `channel.counterparty.forwarding_info` is never assigned. let mut private_chan_cfg = UserConfig::default(); - private_chan_cfg.own_channel_config.announced_channel = false; + private_chan_cfg.channel_handshake_config.announced_channel = false; 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(); let open_channel = get_event_msg!(nodes[2], MessageSendEvent::SendOpenChannel, nodes[0].node.get_our_node_id()); nodes[0].node.handle_open_channel(&nodes[2].node.get_our_node_id(), InitFeatures::known(), &open_channel); @@ -1046,7 +1046,7 @@ mod test { // `msgs::ChannelUpdate` is never handled for the node(s). As the `msgs::ChannelUpdate` // is never handled, the `channel.counterparty.forwarding_info` is never assigned. let mut private_chan_cfg = UserConfig::default(); - private_chan_cfg.own_channel_config.announced_channel = false; + private_chan_cfg.channel_handshake_config.announced_channel = false; 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(); let open_channel = get_event_msg!(nodes[1], MessageSendEvent::SendOpenChannel, nodes[3].node.get_our_node_id()); nodes[3].node.handle_open_channel(&nodes[1].node.get_our_node_id(), InitFeatures::known(), &open_channel); diff --git a/lightning/src/ln/chanmon_update_fail_tests.rs b/lightning/src/ln/chanmon_update_fail_tests.rs index 71002770..91575195 100644 --- a/lightning/src/ln/chanmon_update_fail_tests.rs +++ b/lightning/src/ln/chanmon_update_fail_tests.rs @@ -2541,7 +2541,7 @@ fn test_temporary_error_during_shutdown() { // Test that temporary failures when updating the monitor's shutdown script delay cooperative // close. let mut config = test_default_channel_config(); - config.own_channel_config.commit_upfront_shutdown_pubkey = false; + config.channel_handshake_config.commit_upfront_shutdown_pubkey = false; let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); @@ -2596,7 +2596,7 @@ fn test_permanent_error_during_sending_shutdown() { // Test that permanent failures when updating the monitor's shutdown script result in a force // close when initiating a cooperative close. let mut config = test_default_channel_config(); - config.own_channel_config.commit_upfront_shutdown_pubkey = false; + config.channel_handshake_config.commit_upfront_shutdown_pubkey = false; let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); @@ -2617,7 +2617,7 @@ fn test_permanent_error_during_handling_shutdown() { // Test that permanent failures when updating the monitor's shutdown script result in a force // close when handling a cooperative close. let mut config = test_default_channel_config(); - config.own_channel_config.commit_upfront_shutdown_pubkey = false; + config.channel_handshake_config.commit_upfront_shutdown_pubkey = false; let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index f50865dc..9b47770f 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -855,7 +855,7 @@ impl Channel { // available. If it's private, we first try `scid_privacy` as it provides better privacy // with no other changes, and fall back to `only_static_remotekey` let mut ret = ChannelTypeFeatures::only_static_remote_key(); - if !config.own_channel_config.announced_channel && config.own_channel_config.negotiate_scid_privacy { + if !config.channel_handshake_config.announced_channel && config.channel_handshake_config.negotiate_scid_privacy { ret.set_scid_privacy_required(); } ret @@ -885,7 +885,7 @@ impl Channel { { let opt_anchors = false; // TODO - should be based on features - let holder_selected_contest_delay = config.own_channel_config.our_to_self_delay; + let holder_selected_contest_delay = config.channel_handshake_config.our_to_self_delay; let holder_signer = keys_provider.get_channel_signer(false, channel_value_satoshis); let pubkeys = holder_signer.pubkeys().clone(); @@ -918,7 +918,7 @@ impl Channel { let mut secp_ctx = Secp256k1::new(); secp_ctx.seeded_randomize(&keys_provider.get_secure_random_bytes()); - let shutdown_scriptpubkey = if config.own_channel_config.commit_upfront_shutdown_pubkey { + let shutdown_scriptpubkey = if config.channel_handshake_config.commit_upfront_shutdown_pubkey { Some(keys_provider.get_shutdown_scriptpubkey()) } else { None }; @@ -932,12 +932,12 @@ impl Channel { user_id, config: LegacyChannelConfig { - mutable: config.channel_options.clone(), - announced_channel: config.own_channel_config.announced_channel, - commit_upfront_shutdown_pubkey: config.own_channel_config.commit_upfront_shutdown_pubkey, + options: config.channel_config.clone(), + announced_channel: config.channel_handshake_config.announced_channel, + commit_upfront_shutdown_pubkey: config.channel_handshake_config.commit_upfront_shutdown_pubkey, }, - inbound_handshake_limits_override: Some(config.peer_channel_config_limits.clone()), + inbound_handshake_limits_override: Some(config.channel_handshake_limits.clone()), channel_id: keys_provider.get_secure_random_bytes(), channel_state: ChannelState::OurInitSent as u32, @@ -994,11 +994,11 @@ impl Channel { counterparty_dust_limit_satoshis: 0, holder_dust_limit_satoshis: MIN_CHAN_DUST_LIMIT_SATOSHIS, counterparty_max_htlc_value_in_flight_msat: 0, - holder_max_htlc_value_in_flight_msat: Self::get_holder_max_htlc_value_in_flight_msat(channel_value_satoshis, &config.own_channel_config), + holder_max_htlc_value_in_flight_msat: Self::get_holder_max_htlc_value_in_flight_msat(channel_value_satoshis, &config.channel_handshake_config), counterparty_selected_channel_reserve_satoshis: None, // Filled in in accept_channel holder_selected_channel_reserve_satoshis, counterparty_htlc_minimum_msat: 0, - holder_htlc_minimum_msat: if config.own_channel_config.our_htlc_minimum_msat == 0 { 1 } else { config.own_channel_config.our_htlc_minimum_msat }, + holder_htlc_minimum_msat: if config.channel_handshake_config.our_htlc_minimum_msat == 0 { 1 } else { config.channel_handshake_config.our_htlc_minimum_msat }, counterparty_max_accepted_htlcs: 0, minimum_depth: None, // Filled in in accept_channel @@ -1006,7 +1006,7 @@ impl Channel { channel_transaction_parameters: ChannelTransactionParameters { holder_pubkeys: pubkeys, - holder_selected_contest_delay: config.own_channel_config.our_to_self_delay, + holder_selected_contest_delay: config.channel_handshake_config.our_to_self_delay, is_outbound_from_holder: true, counterparty_parameters: None, funding_outpoint: None, @@ -1124,13 +1124,13 @@ impl Channel { htlc_basepoint: msg.htlc_basepoint }; - if config.own_channel_config.our_to_self_delay < BREAKDOWN_TIMEOUT { - return Err(ChannelError::Close(format!("Configured with an unreasonable our_to_self_delay ({}) putting user funds at risks. It must be greater than {}", config.own_channel_config.our_to_self_delay, BREAKDOWN_TIMEOUT))); + if config.channel_handshake_config.our_to_self_delay < BREAKDOWN_TIMEOUT { + return Err(ChannelError::Close(format!("Configured with an unreasonable our_to_self_delay ({}) putting user funds at risks. It must be greater than {}", config.channel_handshake_config.our_to_self_delay, BREAKDOWN_TIMEOUT))); } // Check sanity of message fields: - if msg.funding_satoshis > config.peer_channel_config_limits.max_funding_satoshis { - return Err(ChannelError::Close(format!("Per our config, funding must be at most {}. It was {}", config.peer_channel_config_limits.max_funding_satoshis, msg.funding_satoshis))); + if msg.funding_satoshis > config.channel_handshake_limits.max_funding_satoshis { + return Err(ChannelError::Close(format!("Per our config, funding must be at most {}. It was {}", config.channel_handshake_limits.max_funding_satoshis, msg.funding_satoshis))); } if msg.funding_satoshis >= TOTAL_BITCOIN_SUPPLY_SATOSHIS { return Err(ChannelError::Close(format!("Funding must be smaller than the total bitcoin supply. It was {}", msg.funding_satoshis))); @@ -1150,7 +1150,7 @@ impl Channel { } Channel::::check_remote_fee(fee_estimator, msg.feerate_per_kw)?; - let max_counterparty_selected_contest_delay = u16::min(config.peer_channel_config_limits.their_to_self_delay, MAX_LOCAL_BREAKDOWN_TIMEOUT); + let max_counterparty_selected_contest_delay = u16::min(config.channel_handshake_limits.their_to_self_delay, MAX_LOCAL_BREAKDOWN_TIMEOUT); if msg.to_self_delay > max_counterparty_selected_contest_delay { return Err(ChannelError::Close(format!("They wanted our payments to be delayed by a needlessly long period. Upper limit: {}. Actual: {}", max_counterparty_selected_contest_delay, msg.to_self_delay))); } @@ -1162,20 +1162,20 @@ impl Channel { } // Now check against optional parameters as set by config... - if msg.funding_satoshis < config.peer_channel_config_limits.min_funding_satoshis { - return Err(ChannelError::Close(format!("Funding satoshis ({}) is less than the user specified limit ({})", msg.funding_satoshis, config.peer_channel_config_limits.min_funding_satoshis))); + if msg.funding_satoshis < config.channel_handshake_limits.min_funding_satoshis { + return Err(ChannelError::Close(format!("Funding satoshis ({}) is less than the user specified limit ({})", msg.funding_satoshis, config.channel_handshake_limits.min_funding_satoshis))); } - if msg.htlc_minimum_msat > config.peer_channel_config_limits.max_htlc_minimum_msat { - return Err(ChannelError::Close(format!("htlc_minimum_msat ({}) is higher than the user specified limit ({})", msg.htlc_minimum_msat, config.peer_channel_config_limits.max_htlc_minimum_msat))); + if msg.htlc_minimum_msat > config.channel_handshake_limits.max_htlc_minimum_msat { + return Err(ChannelError::Close(format!("htlc_minimum_msat ({}) is higher than the user specified limit ({})", msg.htlc_minimum_msat, config.channel_handshake_limits.max_htlc_minimum_msat))); } - if msg.max_htlc_value_in_flight_msat < config.peer_channel_config_limits.min_max_htlc_value_in_flight_msat { - return Err(ChannelError::Close(format!("max_htlc_value_in_flight_msat ({}) is less than the user specified limit ({})", msg.max_htlc_value_in_flight_msat, config.peer_channel_config_limits.min_max_htlc_value_in_flight_msat))); + if msg.max_htlc_value_in_flight_msat < config.channel_handshake_limits.min_max_htlc_value_in_flight_msat { + return Err(ChannelError::Close(format!("max_htlc_value_in_flight_msat ({}) is less than the user specified limit ({})", msg.max_htlc_value_in_flight_msat, config.channel_handshake_limits.min_max_htlc_value_in_flight_msat))); } - if msg.channel_reserve_satoshis > config.peer_channel_config_limits.max_channel_reserve_satoshis { - return Err(ChannelError::Close(format!("channel_reserve_satoshis ({}) is higher than the user specified limit ({})", msg.channel_reserve_satoshis, config.peer_channel_config_limits.max_channel_reserve_satoshis))); + if msg.channel_reserve_satoshis > config.channel_handshake_limits.max_channel_reserve_satoshis { + return Err(ChannelError::Close(format!("channel_reserve_satoshis ({}) is higher than the user specified limit ({})", msg.channel_reserve_satoshis, config.channel_handshake_limits.max_channel_reserve_satoshis))); } - if msg.max_accepted_htlcs < config.peer_channel_config_limits.min_max_accepted_htlcs { - return Err(ChannelError::Close(format!("max_accepted_htlcs ({}) is less than the user specified limit ({})", msg.max_accepted_htlcs, config.peer_channel_config_limits.min_max_accepted_htlcs))); + if msg.max_accepted_htlcs < config.channel_handshake_limits.min_max_accepted_htlcs { + return Err(ChannelError::Close(format!("max_accepted_htlcs ({}) is less than the user specified limit ({})", msg.max_accepted_htlcs, config.channel_handshake_limits.min_max_accepted_htlcs))); } if msg.dust_limit_satoshis < MIN_CHAN_DUST_LIMIT_SATOSHIS { return Err(ChannelError::Close(format!("dust_limit_satoshis ({}) is less than the implementation limit ({})", msg.dust_limit_satoshis, MIN_CHAN_DUST_LIMIT_SATOSHIS))); @@ -1186,8 +1186,8 @@ impl Channel { // Convert things into internal flags and prep our state: - if config.peer_channel_config_limits.force_announced_channel_preference { - if config.own_channel_config.announced_channel != announced_channel { + if config.channel_handshake_limits.force_announced_channel_preference { + if config.channel_handshake_config.announced_channel != announced_channel { return Err(ChannelError::Close("Peer tried to open channel but their announcement preference is different from ours".to_owned())); } } @@ -1242,7 +1242,7 @@ impl Channel { } } else { None }; - let shutdown_scriptpubkey = if config.own_channel_config.commit_upfront_shutdown_pubkey { + let shutdown_scriptpubkey = if config.channel_handshake_config.commit_upfront_shutdown_pubkey { Some(keys_provider.get_shutdown_scriptpubkey()) } else { None }; @@ -1259,9 +1259,9 @@ impl Channel { user_id, config: LegacyChannelConfig { - mutable: config.channel_options.clone(), + options: config.channel_config.clone(), announced_channel, - commit_upfront_shutdown_pubkey: config.own_channel_config.commit_upfront_shutdown_pubkey, + commit_upfront_shutdown_pubkey: config.channel_handshake_config.commit_upfront_shutdown_pubkey, }, inbound_handshake_limits_override: None, @@ -1321,19 +1321,19 @@ impl Channel { counterparty_dust_limit_satoshis: msg.dust_limit_satoshis, holder_dust_limit_satoshis: MIN_CHAN_DUST_LIMIT_SATOSHIS, counterparty_max_htlc_value_in_flight_msat: cmp::min(msg.max_htlc_value_in_flight_msat, msg.funding_satoshis * 1000), - holder_max_htlc_value_in_flight_msat: Self::get_holder_max_htlc_value_in_flight_msat(msg.funding_satoshis, &config.own_channel_config), + holder_max_htlc_value_in_flight_msat: Self::get_holder_max_htlc_value_in_flight_msat(msg.funding_satoshis, &config.channel_handshake_config), counterparty_selected_channel_reserve_satoshis: Some(msg.channel_reserve_satoshis), holder_selected_channel_reserve_satoshis, counterparty_htlc_minimum_msat: msg.htlc_minimum_msat, - holder_htlc_minimum_msat: if config.own_channel_config.our_htlc_minimum_msat == 0 { 1 } else { config.own_channel_config.our_htlc_minimum_msat }, + holder_htlc_minimum_msat: if config.channel_handshake_config.our_htlc_minimum_msat == 0 { 1 } else { config.channel_handshake_config.our_htlc_minimum_msat }, counterparty_max_accepted_htlcs: msg.max_accepted_htlcs, - minimum_depth: Some(cmp::max(config.own_channel_config.minimum_depth, 1)), + minimum_depth: Some(cmp::max(config.channel_handshake_config.minimum_depth, 1)), counterparty_forwarding_info: None, channel_transaction_parameters: ChannelTransactionParameters { holder_pubkeys: pubkeys, - holder_selected_contest_delay: config.own_channel_config.our_to_self_delay, + holder_selected_contest_delay: config.channel_handshake_config.our_to_self_delay, is_outbound_from_holder: false, counterparty_parameters: Some(CounterpartyChannelTransactionParameters { selected_contest_delay: msg.to_self_delay, @@ -4020,7 +4020,7 @@ impl Channel { // We always add force_close_avoidance_max_fee_satoshis to our normal // feerate-calculated fee, but allow the max to be overridden if we're using a // target feerate-calculated fee. - cmp::max(normal_feerate as u64 * tx_weight / 1000 + self.config.mutable.force_close_avoidance_max_fee_satoshis, + cmp::max(normal_feerate as u64 * tx_weight / 1000 + self.config.options.force_close_avoidance_max_fee_satoshis, proposed_max_feerate as u64 * tx_weight / 1000) } else { self.channel_value_satoshis - (self.value_to_self_msat + 999) / 1000 @@ -4480,15 +4480,15 @@ impl Channel { } pub fn get_fee_proportional_millionths(&self) -> u32 { - self.config.mutable.forwarding_fee_proportional_millionths + self.config.options.forwarding_fee_proportional_millionths } pub fn get_cltv_expiry_delta(&self) -> u16 { - cmp::max(self.config.mutable.cltv_expiry_delta, MIN_CLTV_EXPIRY_DELTA) + cmp::max(self.config.options.cltv_expiry_delta, MIN_CLTV_EXPIRY_DELTA) } pub fn get_max_dust_htlc_exposure_msat(&self) -> u64 { - self.config.mutable.max_dust_htlc_exposure_msat + self.config.options.max_dust_htlc_exposure_msat } pub fn get_feerate(&self) -> u32 { @@ -4575,7 +4575,7 @@ impl Channel { /// Gets the fee we'd want to charge for adding an HTLC output to this Channel /// Allowed in any state (including after shutdown) pub fn get_outbound_forwarding_fee_base_msat(&self) -> u32 { - self.config.mutable.forwarding_fee_base_msat + self.config.options.forwarding_fee_base_msat } /// Returns true if we've ever received a message from the remote end for this Channel @@ -5996,7 +5996,7 @@ impl Writeable for Channel { if self.holder_selected_channel_reserve_satoshis != Self::get_holder_selected_channel_reserve_satoshis(self.channel_value_satoshis) { Some(self.holder_selected_channel_reserve_satoshis) } else { None }; - let mut old_max_in_flight_percent_config = UserConfig::default().own_channel_config; + let mut old_max_in_flight_percent_config = UserConfig::default().channel_handshake_config; old_max_in_flight_percent_config.max_inbound_htlc_value_in_flight_percent_of_channel = MAX_IN_FLIGHT_PERCENT_LEGACY; let serialized_holder_htlc_max_in_flight = if self.holder_max_htlc_value_in_flight_msat != Self::get_holder_max_htlc_value_in_flight_msat(self.channel_value_satoshis, &old_max_in_flight_percent_config) @@ -6042,8 +6042,8 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel let mut config = Some(LegacyChannelConfig::default()); if ver == 1 { // Read the old serialization of the ChannelConfig from version 0.0.98. - config.as_mut().unwrap().mutable.forwarding_fee_proportional_millionths = Readable::read(reader)?; - config.as_mut().unwrap().mutable.cltv_expiry_delta = Readable::read(reader)?; + config.as_mut().unwrap().options.forwarding_fee_proportional_millionths = Readable::read(reader)?; + config.as_mut().unwrap().options.cltv_expiry_delta = Readable::read(reader)?; config.as_mut().unwrap().announced_channel = Readable::read(reader)?; config.as_mut().unwrap().commit_upfront_shutdown_pubkey = Readable::read(reader)?; } else { @@ -6269,7 +6269,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel let mut target_closing_feerate_sats_per_kw = None; let mut monitor_pending_finalized_fulfills = Some(Vec::new()); let mut holder_selected_channel_reserve_satoshis = Some(Self::get_holder_selected_channel_reserve_satoshis(channel_value_satoshis)); - let mut holder_max_htlc_value_in_flight_msat = Some(Self::get_holder_max_htlc_value_in_flight_msat(channel_value_satoshis, &UserConfig::default().own_channel_config)); + let mut holder_max_htlc_value_in_flight_msat = Some(Self::get_holder_max_htlc_value_in_flight_msat(channel_value_satoshis, &UserConfig::default().channel_handshake_config)); // Prior to supporting channel type negotiation, all of our channels were static_remotekey // only, so we default to that if none was written. let mut channel_type = Some(ChannelTypeFeatures::only_static_remote_key()); @@ -6614,7 +6614,7 @@ mod tests { // Node B --> Node A: accept channel, explicitly setting B's dust limit. let mut accept_channel_msg = node_b_chan.accept_inbound_channel(0); accept_channel_msg.dust_limit_satoshis = 546; - node_a_chan.accept_channel(&accept_channel_msg, &config.peer_channel_config_limits, &InitFeatures::known()).unwrap(); + node_a_chan.accept_channel(&accept_channel_msg, &config.channel_handshake_limits, &InitFeatures::known()).unwrap(); node_a_chan.holder_dust_limit_satoshis = 1560; // Put some inbound and outbound HTLCs in A's channel. @@ -6731,7 +6731,7 @@ mod tests { // Node B --> Node A: accept channel let accept_channel_msg = node_b_chan.accept_inbound_channel(0); - node_a_chan.accept_channel(&accept_channel_msg, &config.peer_channel_config_limits, &InitFeatures::known()).unwrap(); + node_a_chan.accept_channel(&accept_channel_msg, &config.channel_handshake_limits, &InitFeatures::known()).unwrap(); // Node A --> Node B: funding created let output_script = node_a_chan.get_funding_redeemscript(); @@ -6784,13 +6784,13 @@ mod tests { let inbound_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[7; 32]).unwrap()); let mut config_2_percent = UserConfig::default(); - config_2_percent.own_channel_config.max_inbound_htlc_value_in_flight_percent_of_channel = 2; + config_2_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 2; let mut config_99_percent = UserConfig::default(); - config_99_percent.own_channel_config.max_inbound_htlc_value_in_flight_percent_of_channel = 99; + config_99_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 99; let mut config_0_percent = UserConfig::default(); - config_0_percent.own_channel_config.max_inbound_htlc_value_in_flight_percent_of_channel = 0; + config_0_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 0; let mut config_101_percent = UserConfig::default(); - config_101_percent.own_channel_config.max_inbound_htlc_value_in_flight_percent_of_channel = 101; + config_101_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 101; // Test that `new_outbound` creates a channel with the correct value for // `holder_max_htlc_value_in_flight_msat`, when configured with a valid percentage value, @@ -6935,7 +6935,7 @@ mod tests { let counterparty_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap()); let mut config = UserConfig::default(); - config.own_channel_config.announced_channel = false; + config.channel_handshake_config.announced_channel = false; let mut chan = Channel::::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 chan.holder_dust_limit_satoshis = 546; chan.counterparty_selected_channel_reserve_satoshis = Some(0); // Filled in in accept_channel diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index d19e3008..cf593068 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -4346,7 +4346,7 @@ impl ChannelMana if chan.get().get_counterparty_node_id() != *counterparty_node_id { return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.temporary_channel_id)); } - try_chan_entry!(self, chan.get_mut().accept_channel(&msg, &self.default_configuration.peer_channel_config_limits, &their_features), channel_state, chan); + try_chan_entry!(self, chan.get_mut().accept_channel(&msg, &self.default_configuration.channel_handshake_limits, &their_features), channel_state, chan); (chan.get().get_value_satoshis(), chan.get().get_funding_redeemscript().to_v0_p2wsh(), chan.get().get_user_id()) }, hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.temporary_channel_id)) @@ -7630,7 +7630,7 @@ pub mod bench { let fee_estimator = test_utils::TestFeeEstimator { sat_per_kw: Mutex::new(253) }; let mut config: UserConfig = Default::default(); - config.own_channel_config.minimum_depth = 1; + config.channel_handshake_config.minimum_depth = 1; let logger_a = test_utils::TestLogger::with_id("node a".to_owned()); let chain_monitor_a = ChainMonitor::new(None, &tx_broadcaster, &logger_a, &fee_estimator, &persister_a); diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index 4b00c9b7..38c05998 100644 --- a/lightning/src/ln/functional_test_utils.rs +++ b/lightning/src/ln/functional_test_utils.rs @@ -772,7 +772,7 @@ pub fn create_announced_chan_between_nodes_with_value<'a, 'b, 'c, 'd>(nodes: &'a pub fn create_unannounced_chan_between_nodes_with_value<'a, 'b, 'c, 'd>(nodes: &'a Vec>, a: usize, b: usize, channel_value: u64, push_msat: u64, a_flags: InitFeatures, b_flags: InitFeatures) -> (msgs::ChannelReady, Transaction) { let mut no_announce_cfg = test_default_channel_config(); - no_announce_cfg.own_channel_config.announced_channel = false; + no_announce_cfg.channel_handshake_config.announced_channel = false; nodes[a].node.create_channel(nodes[b].node.get_our_node_id(), channel_value, push_msat, 42, Some(no_announce_cfg)).unwrap(); let open_channel = get_event_msg!(nodes[a], MessageSendEvent::SendOpenChannel, nodes[b].node.get_our_node_id()); nodes[b].node.handle_open_channel(&nodes[a].node.get_our_node_id(), a_flags, &open_channel); @@ -1691,7 +1691,7 @@ pub fn do_claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, $node.node.handle_update_fulfill_htlc(&$prev_node.node.get_our_node_id(), &next_msgs.as_ref().unwrap().0); let fee = $node.node.channel_state.lock().unwrap() .by_id.get(&next_msgs.as_ref().unwrap().0.channel_id).unwrap() - .config.mutable.forwarding_fee_base_msat; + .config.options.forwarding_fee_base_msat; expect_payment_forwarded!($node, $next_node, $prev_node, Some(fee as u64), false, false); expected_total_fee_msat += fee as u64; check_added_monitors!($node, 1); @@ -1967,15 +1967,15 @@ pub fn test_default_channel_config() -> UserConfig { let mut default_config = UserConfig::default(); // Set cltv_expiry_delta slightly lower to keep the final CLTV values inside one byte in our // tests so that our script-length checks don't fail (see ACCEPTED_HTLC_SCRIPT_WEIGHT). - default_config.channel_options.cltv_expiry_delta = MIN_CLTV_EXPIRY_DELTA; - default_config.own_channel_config.announced_channel = true; - default_config.peer_channel_config_limits.force_announced_channel_preference = false; + default_config.channel_config.cltv_expiry_delta = MIN_CLTV_EXPIRY_DELTA; + default_config.channel_handshake_config.announced_channel = true; + default_config.channel_handshake_limits.force_announced_channel_preference = false; // When most of our tests were written, the default HTLC minimum was fixed at 1000. // It now defaults to 1, so we simply set it to the expected value here. - default_config.own_channel_config.our_htlc_minimum_msat = 1000; + default_config.channel_handshake_config.our_htlc_minimum_msat = 1000; // When most of our tests were written, we didn't have the notion of a `max_dust_htlc_exposure_msat`, // It now defaults to 5_000_000 msat; to avoid interfering with tests we bump it to 50_000_000 msat. - default_config.channel_options.max_dust_htlc_exposure_msat = 50_000_000; + default_config.channel_config.max_dust_htlc_exposure_msat = 50_000_000; default_config } diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index a716d806..76487ddc 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -61,7 +61,7 @@ fn test_insane_channel_opens() { // Stand up a network of 2 nodes use ln::channel::TOTAL_BITCOIN_SUPPLY_SATOSHIS; let mut cfg = UserConfig::default(); - cfg.peer_channel_config_limits.max_funding_satoshis = TOTAL_BITCOIN_SUPPLY_SATOSHIS + 1; + cfg.channel_handshake_limits.max_funding_satoshis = TOTAL_BITCOIN_SUPPLY_SATOSHIS + 1; let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, Some(cfg)]); @@ -1790,7 +1790,7 @@ fn test_channel_reserve_holding_cell_htlcs() { // When this test was written, the default base fee floated based on the HTLC count. // It is now fixed, so we simply set the fee to the expected value here. let mut config = test_default_channel_config(); - config.channel_options.forwarding_fee_base_msat = 239; + config.channel_config.forwarding_fee_base_msat = 239; let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[Some(config.clone()), Some(config.clone()), Some(config.clone())]); let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); let chan_1 = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 190000, 1001, InitFeatures::known(), InitFeatures::known()); @@ -2362,13 +2362,13 @@ fn channel_monitor_network_test() { fn test_justice_tx() { // Test justice txn built on revoked HTLC-Success tx, against both sides let mut alice_config = UserConfig::default(); - alice_config.own_channel_config.announced_channel = true; - alice_config.peer_channel_config_limits.force_announced_channel_preference = false; - alice_config.own_channel_config.our_to_self_delay = 6 * 24 * 5; + alice_config.channel_handshake_config.announced_channel = true; + alice_config.channel_handshake_limits.force_announced_channel_preference = false; + alice_config.channel_handshake_config.our_to_self_delay = 6 * 24 * 5; let mut bob_config = UserConfig::default(); - bob_config.own_channel_config.announced_channel = true; - bob_config.peer_channel_config_limits.force_announced_channel_preference = false; - bob_config.own_channel_config.our_to_self_delay = 6 * 24 * 3; + bob_config.channel_handshake_config.announced_channel = true; + bob_config.channel_handshake_limits.force_announced_channel_preference = false; + bob_config.channel_handshake_config.our_to_self_delay = 6 * 24 * 3; let user_cfgs = [Some(alice_config), Some(bob_config)]; let mut chanmon_cfgs = create_chanmon_cfgs(2); chanmon_cfgs[0].keys_manager.disable_revocation_policy_check = true; @@ -5275,7 +5275,7 @@ fn test_duplicate_payment_hash_one_failure_one_success() { // When this test was written, the default base fee floated based on the HTLC count. // It is now fixed, so we simply set the fee to the expected value here. let mut config = test_default_channel_config(); - config.channel_options.forwarding_fee_base_msat = 196; + config.channel_config.forwarding_fee_base_msat = 196; let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[Some(config.clone()), Some(config.clone()), Some(config.clone()), Some(config.clone())]); let mut nodes = create_network(4, &node_cfgs, &node_chanmgrs); @@ -5487,7 +5487,7 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno // When this test was written, the default base fee floated based on the HTLC count. // It is now fixed, so we simply set the fee to the expected value here. let mut config = test_default_channel_config(); - config.channel_options.forwarding_fee_base_msat = 196; + config.channel_config.forwarding_fee_base_msat = 196; let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &[Some(config.clone()), Some(config.clone()), Some(config.clone()), Some(config.clone()), Some(config.clone()), Some(config.clone())]); let nodes = create_network(6, &node_cfgs, &node_chanmgrs); @@ -6369,7 +6369,7 @@ fn test_fail_holding_cell_htlc_upon_free_multihop() { // When this test was written, the default base fee floated based on the HTLC count. // It is now fixed, so we simply set the fee to the expected value here. let mut config = test_default_channel_config(); - config.channel_options.forwarding_fee_base_msat = 196; + config.channel_config.forwarding_fee_base_msat = 196; let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[Some(config.clone()), Some(config.clone()), Some(config.clone())]); let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); let chan_0_1 = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000, InitFeatures::known(), InitFeatures::known()); @@ -7328,9 +7328,9 @@ fn test_user_configurable_csv_delay() { // We test our channel constructors yield errors when we pass them absurd csv delay let mut low_our_to_self_config = UserConfig::default(); - low_our_to_self_config.own_channel_config.our_to_self_delay = 6; + low_our_to_self_config.channel_handshake_config.our_to_self_delay = 6; let mut high_their_to_self_config = UserConfig::default(); - high_their_to_self_config.peer_channel_config_limits.their_to_self_delay = 100; + high_their_to_self_config.channel_handshake_limits.their_to_self_delay = 100; let user_cfgs = [Some(high_their_to_self_config.clone()), None]; let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); @@ -8245,7 +8245,7 @@ fn test_override_channel_config() { // Node0 initiates a channel to node1 using the override config. let mut override_config = UserConfig::default(); - override_config.own_channel_config.our_to_self_delay = 200; + override_config.channel_handshake_config.our_to_self_delay = 200; nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 16_000_000, 12_000_000, 42, Some(override_config)).unwrap(); @@ -8258,7 +8258,7 @@ fn test_override_channel_config() { #[test] fn test_override_0msat_htlc_minimum() { let mut zero_config = UserConfig::default(); - zero_config.own_channel_config.our_htlc_minimum_msat = 0; + zero_config.channel_handshake_config.our_htlc_minimum_msat = 0; let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, Some(zero_config.clone())]); @@ -8282,17 +8282,17 @@ fn test_channel_update_has_correct_htlc_maximum_msat() { // 2. MUST be set to less than or equal to the `max_htlc_value_in_flight_msat` received from the peer. let mut config_30_percent = UserConfig::default(); - config_30_percent.own_channel_config.announced_channel = true; - config_30_percent.own_channel_config.max_inbound_htlc_value_in_flight_percent_of_channel = 30; + config_30_percent.channel_handshake_config.announced_channel = true; + config_30_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 30; let mut config_50_percent = UserConfig::default(); - config_50_percent.own_channel_config.announced_channel = true; - config_50_percent.own_channel_config.max_inbound_htlc_value_in_flight_percent_of_channel = 50; + config_50_percent.channel_handshake_config.announced_channel = true; + config_50_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 50; let mut config_95_percent = UserConfig::default(); - config_95_percent.own_channel_config.announced_channel = true; - config_95_percent.own_channel_config.max_inbound_htlc_value_in_flight_percent_of_channel = 95; + config_95_percent.channel_handshake_config.announced_channel = true; + config_95_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 95; let mut config_100_percent = UserConfig::default(); - config_100_percent.own_channel_config.announced_channel = true; - config_100_percent.own_channel_config.max_inbound_htlc_value_in_flight_percent_of_channel = 100; + config_100_percent.channel_handshake_config.announced_channel = true; + config_100_percent.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 100; let chanmon_cfgs = create_chanmon_cfgs(4); let node_cfgs = create_node_cfgs(4, &chanmon_cfgs); @@ -10182,7 +10182,7 @@ fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, exposure_breach_e let chanmon_cfgs = create_chanmon_cfgs(2); let mut config = test_default_channel_config(); - config.channel_options.max_dust_htlc_exposure_msat = 5_000_000; // default setting value + config.channel_config.max_dust_htlc_exposure_msat = 5_000_000; // default setting value let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(config), None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); @@ -10225,13 +10225,13 @@ fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, exposure_breach_e chan.get_dust_buffer_feerate(None) as u64 }; let dust_outbound_htlc_on_holder_tx_msat: u64 = (dust_buffer_feerate * htlc_timeout_tx_weight(opt_anchors) / 1000 + open_channel.dust_limit_satoshis - 1) * 1000; - let dust_outbound_htlc_on_holder_tx: u64 = config.channel_options.max_dust_htlc_exposure_msat / dust_outbound_htlc_on_holder_tx_msat; + let dust_outbound_htlc_on_holder_tx: u64 = config.channel_config.max_dust_htlc_exposure_msat / dust_outbound_htlc_on_holder_tx_msat; let dust_inbound_htlc_on_holder_tx_msat: u64 = (dust_buffer_feerate * htlc_success_tx_weight(opt_anchors) / 1000 + open_channel.dust_limit_satoshis - 1) * 1000; - let dust_inbound_htlc_on_holder_tx: u64 = config.channel_options.max_dust_htlc_exposure_msat / dust_inbound_htlc_on_holder_tx_msat; + let dust_inbound_htlc_on_holder_tx: u64 = config.channel_config.max_dust_htlc_exposure_msat / dust_inbound_htlc_on_holder_tx_msat; let dust_htlc_on_counterparty_tx: u64 = 25; - let dust_htlc_on_counterparty_tx_msat: u64 = config.channel_options.max_dust_htlc_exposure_msat / dust_htlc_on_counterparty_tx; + let dust_htlc_on_counterparty_tx_msat: u64 = config.channel_config.max_dust_htlc_exposure_msat / dust_htlc_on_counterparty_tx; if on_holder_tx { if dust_outbound_balance { @@ -10275,9 +10275,9 @@ fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, exposure_breach_e if on_holder_tx { let dust_outbound_overflow = dust_outbound_htlc_on_holder_tx_msat * (dust_outbound_htlc_on_holder_tx + 1); let dust_inbound_overflow = dust_inbound_htlc_on_holder_tx_msat * dust_inbound_htlc_on_holder_tx + dust_outbound_htlc_on_holder_tx_msat; - unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret)), true, APIError::ChannelUnavailable { ref err }, assert_eq!(err, &format!("Cannot send value that would put our exposure to dust HTLCs at {} over the limit {} on holder commitment tx", if dust_outbound_balance { dust_outbound_overflow } else { dust_inbound_overflow }, config.channel_options.max_dust_htlc_exposure_msat))); + unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret)), true, APIError::ChannelUnavailable { ref err }, assert_eq!(err, &format!("Cannot send value that would put our exposure to dust HTLCs at {} over the limit {} on holder commitment tx", if dust_outbound_balance { dust_outbound_overflow } else { dust_inbound_overflow }, config.channel_config.max_dust_htlc_exposure_msat))); } else { - unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret)), true, APIError::ChannelUnavailable { ref err }, assert_eq!(err, &format!("Cannot send value that would put our exposure to dust HTLCs at {} over the limit {} on counterparty commitment tx", dust_overflow, config.channel_options.max_dust_htlc_exposure_msat))); + unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret)), true, APIError::ChannelUnavailable { ref err }, assert_eq!(err, &format!("Cannot send value that would put our exposure to dust HTLCs at {} over the limit {} on counterparty commitment tx", dust_overflow, config.channel_config.max_dust_htlc_exposure_msat))); } } else if exposure_breach_event == ExposureEvent::AtHTLCReception { let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[1], nodes[0], if on_holder_tx { dust_inbound_htlc_on_holder_tx_msat } else { dust_htlc_on_counterparty_tx_msat }); @@ -10292,10 +10292,10 @@ fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, exposure_breach_e // Outbound dust balance: 6399 sats let dust_inbound_overflow = dust_inbound_htlc_on_holder_tx_msat * (dust_inbound_htlc_on_holder_tx + 1); let dust_outbound_overflow = dust_outbound_htlc_on_holder_tx_msat * dust_outbound_htlc_on_holder_tx + dust_inbound_htlc_on_holder_tx_msat; - nodes[0].logger.assert_log("lightning::ln::channel".to_string(), format!("Cannot accept value that would put our exposure to dust HTLCs at {} over the limit {} on holder commitment tx", if dust_outbound_balance { dust_outbound_overflow } else { dust_inbound_overflow }, config.channel_options.max_dust_htlc_exposure_msat), 1); + nodes[0].logger.assert_log("lightning::ln::channel".to_string(), format!("Cannot accept value that would put our exposure to dust HTLCs at {} over the limit {} on holder commitment tx", if dust_outbound_balance { dust_outbound_overflow } else { dust_inbound_overflow }, config.channel_config.max_dust_htlc_exposure_msat), 1); } else { // Outbound dust balance: 5200 sats - nodes[0].logger.assert_log("lightning::ln::channel".to_string(), format!("Cannot accept value that would put our exposure to dust HTLCs at {} over the limit {} on counterparty commitment tx", dust_overflow, config.channel_options.max_dust_htlc_exposure_msat), 1); + nodes[0].logger.assert_log("lightning::ln::channel".to_string(), format!("Cannot accept value that would put our exposure to dust HTLCs at {} over the limit {} on counterparty commitment tx", dust_overflow, config.channel_config.max_dust_htlc_exposure_msat), 1); } } else if exposure_breach_event == ExposureEvent::AtUpdateFeeOutbound { let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 2_500_000); diff --git a/lightning/src/ln/onion_route_tests.rs b/lightning/src/ln/onion_route_tests.rs index 51a3e048..1e340d4a 100644 --- a/lightning/src/ln/onion_route_tests.rs +++ b/lightning/src/ln/onion_route_tests.rs @@ -262,7 +262,7 @@ fn test_fee_failures() { // When this test was written, the default base fee floated based on the HTLC count. // It is now fixed, so we simply set the fee to the expected value here. let mut config = test_default_channel_config(); - config.channel_options.forwarding_fee_base_msat = 196; + config.channel_config.forwarding_fee_base_msat = 196; let chanmon_cfgs = create_chanmon_cfgs(3); let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); @@ -307,14 +307,14 @@ fn test_onion_failure() { // This exposed a previous bug because we were using the wrong value all the way down in // Channel::get_counterparty_htlc_minimum_msat(). let mut node_2_cfg: UserConfig = Default::default(); - node_2_cfg.own_channel_config.our_htlc_minimum_msat = 2000; - node_2_cfg.own_channel_config.announced_channel = true; - node_2_cfg.peer_channel_config_limits.force_announced_channel_preference = false; + node_2_cfg.channel_handshake_config.our_htlc_minimum_msat = 2000; + node_2_cfg.channel_handshake_config.announced_channel = true; + node_2_cfg.channel_handshake_limits.force_announced_channel_preference = false; // When this test was written, the default base fee floated based on the HTLC count. // It is now fixed, so we simply set the fee to the expected value here. let mut config = test_default_channel_config(); - config.channel_options.forwarding_fee_base_msat = 196; + config.channel_config.forwarding_fee_base_msat = 196; let chanmon_cfgs = create_chanmon_cfgs(3); let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); @@ -600,7 +600,7 @@ fn test_default_to_onion_payload_tlv_format() { // `features` for a node in the `network_graph` exists, or when the node isn't in the // `network_graph`, and no other known `features` for the node exists. let mut priv_channels_conf = UserConfig::default(); - priv_channels_conf.own_channel_config.announced_channel = false; + priv_channels_conf.channel_handshake_config.announced_channel = false; let chanmon_cfgs = create_chanmon_cfgs(5); let node_cfgs = create_node_cfgs(5, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(5, &node_cfgs, &[None, None, None, None, Some(priv_channels_conf)]); @@ -1084,8 +1084,8 @@ fn test_phantom_dust_exposure_failure() { // Set the max dust exposure to the dust limit. let max_dust_exposure = 546; let mut receiver_config = UserConfig::default(); - receiver_config.channel_options.max_dust_htlc_exposure_msat = max_dust_exposure; - receiver_config.own_channel_config.announced_channel = true; + receiver_config.channel_config.max_dust_htlc_exposure_msat = max_dust_exposure; + receiver_config.channel_handshake_config.announced_channel = true; let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); diff --git a/lightning/src/ln/payment_tests.rs b/lightning/src/ln/payment_tests.rs index 3d208dd2..935cb8f9 100644 --- a/lightning/src/ln/payment_tests.rs +++ b/lightning/src/ln/payment_tests.rs @@ -532,7 +532,7 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) { // and not the original fee. We also update node[1]'s relevant config as // do_claim_payment_along_route expects us to never overpay. nodes[1].node.channel_state.lock().unwrap().by_id.get_mut(&chan_id_2).unwrap() - .config.mutable.forwarding_fee_base_msat += 100_000; + .config.options.forwarding_fee_base_msat += 100_000; new_route.paths[0][0].fee_msat += 100_000; assert!(nodes[0].node.retry_payment(&new_route, payment_id_1).is_err()); // Shouldn't be allowed to retry a fulfilled payment diff --git a/lightning/src/ln/priv_short_conf_tests.rs b/lightning/src/ln/priv_short_conf_tests.rs index 6b2a3612..237a7fa3 100644 --- a/lightning/src/ln/priv_short_conf_tests.rs +++ b/lightning/src/ln/priv_short_conf_tests.rs @@ -170,13 +170,13 @@ fn do_test_1_conf_open(connect_style: ConnectStyle) { // Previously, if the minium_depth config was set to 1, we'd never send a channel_ready. This // tests that we properly send one in that case. let mut alice_config = UserConfig::default(); - alice_config.own_channel_config.minimum_depth = 1; - alice_config.own_channel_config.announced_channel = true; - alice_config.peer_channel_config_limits.force_announced_channel_preference = false; + alice_config.channel_handshake_config.minimum_depth = 1; + alice_config.channel_handshake_config.announced_channel = true; + alice_config.channel_handshake_limits.force_announced_channel_preference = false; let mut bob_config = UserConfig::default(); - bob_config.own_channel_config.minimum_depth = 1; - bob_config.own_channel_config.announced_channel = true; - bob_config.peer_channel_config_limits.force_announced_channel_preference = false; + bob_config.channel_handshake_config.minimum_depth = 1; + bob_config.channel_handshake_config.announced_channel = true; + bob_config.channel_handshake_limits.force_announced_channel_preference = false; let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(alice_config), Some(bob_config)]); @@ -308,8 +308,8 @@ fn test_scid_privacy_on_pub_channel() { let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); let mut scid_privacy_cfg = test_default_channel_config(); - scid_privacy_cfg.own_channel_config.announced_channel = true; - scid_privacy_cfg.own_channel_config.negotiate_scid_privacy = true; + scid_privacy_cfg.channel_handshake_config.announced_channel = true; + scid_privacy_cfg.channel_handshake_config.negotiate_scid_privacy = true; nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, Some(scid_privacy_cfg)).unwrap(); let mut open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); @@ -332,8 +332,8 @@ fn test_scid_privacy_negotiation() { let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); let mut scid_privacy_cfg = test_default_channel_config(); - scid_privacy_cfg.own_channel_config.announced_channel = false; - scid_privacy_cfg.own_channel_config.negotiate_scid_privacy = true; + scid_privacy_cfg.channel_handshake_config.announced_channel = false; + scid_privacy_cfg.channel_handshake_config.negotiate_scid_privacy = true; nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, Some(scid_privacy_cfg)).unwrap(); let init_open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); @@ -378,8 +378,8 @@ fn test_inbound_scid_privacy() { create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, InitFeatures::known(), InitFeatures::known()); let mut no_announce_cfg = test_default_channel_config(); - no_announce_cfg.own_channel_config.announced_channel = false; - no_announce_cfg.own_channel_config.negotiate_scid_privacy = true; + no_announce_cfg.channel_handshake_config.announced_channel = false; + no_announce_cfg.channel_handshake_config.negotiate_scid_privacy = true; nodes[1].node.create_channel(nodes[2].node.get_our_node_id(), 100_000, 10_000, 42, Some(no_announce_cfg)).unwrap(); let mut open_channel = get_event_msg!(nodes[1], MessageSendEvent::SendOpenChannel, nodes[2].node.get_our_node_id()); @@ -521,7 +521,7 @@ fn test_scid_alias_returned() { short_channel_id: last_hop[0].inbound_scid_alias.unwrap(), timestamp: 21, flags: 1, - cltv_expiry_delta: accept_forward_cfg.channel_options.cltv_expiry_delta, + cltv_expiry_delta: accept_forward_cfg.channel_config.cltv_expiry_delta, htlc_minimum_msat: 1_000, htlc_maximum_msat: OptionalField::Present(1_000_000), // Defaults to 10% of the channel value fee_base_msat: last_hop[0].counterparty.forwarding_info.as_ref().unwrap().fee_base_msat, @@ -665,7 +665,7 @@ fn test_0conf_channel_with_async_monitor() { create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 1_000_000, 0, InitFeatures::known(), InitFeatures::known()); - chan_config.own_channel_config.announced_channel = false; + chan_config.channel_handshake_config.announced_channel = false; nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, Some(chan_config)).unwrap(); let open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); @@ -811,7 +811,7 @@ fn test_0conf_close_no_early_chan_update() { let nodes = create_network(2, &node_cfgs, &node_chanmgrs); // This is the default but we force it on anyway - chan_config.own_channel_config.announced_channel = true; + chan_config.channel_handshake_config.announced_channel = true; open_zero_conf_channel(&nodes[0], &nodes[1], Some(chan_config)); // 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() { let nodes = create_network(2, &node_cfgs, &node_chanmgrs); // This is the default but we force it on anyway - chan_config.own_channel_config.announced_channel = true; + chan_config.channel_handshake_config.announced_channel = true; let tx = open_zero_conf_channel(&nodes[0], &nodes[1], Some(chan_config)); // 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() { let nodes = create_network(2, &node_cfgs, &node_chanmgrs); // This is the default but we force it on anyway - chan_config.own_channel_config.announced_channel = true; + chan_config.channel_handshake_config.announced_channel = true; let tx = open_zero_conf_channel(&nodes[0], &nodes[1], Some(chan_config)); // We can use the channel immediately, but we can't announce it until we get 6+ confirmations @@ -974,7 +974,7 @@ fn test_zero_conf_accept_reject() { assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); let events = nodes[1].node.get_and_clear_pending_events(); - + match events[0] { Event::OpenChannelRequest { temporary_channel_id, .. } => { // Assert we fail to accept via the non-0conf method @@ -1004,7 +1004,7 @@ fn test_zero_conf_accept_reject() { &open_channel_msg); let events = nodes[1].node.get_and_clear_pending_events(); - + match events[0] { Event::OpenChannelRequest { temporary_channel_id, .. } => { // Assert we can accept via the 0conf method diff --git a/lightning/src/ln/shutdown_tests.rs b/lightning/src/ln/shutdown_tests.rs index edfa596f..3e9f7e34 100644 --- a/lightning/src/ln/shutdown_tests.rs +++ b/lightning/src/ln/shutdown_tests.rs @@ -409,9 +409,9 @@ fn test_upfront_shutdown_script() { // enforce it at shutdown message let mut config = UserConfig::default(); - config.own_channel_config.announced_channel = true; - config.peer_channel_config_limits.force_announced_channel_preference = false; - config.own_channel_config.commit_upfront_shutdown_pubkey = false; + config.channel_handshake_config.announced_channel = true; + config.channel_handshake_limits.force_announced_channel_preference = false; + config.channel_handshake_config.commit_upfront_shutdown_pubkey = false; let user_cfgs = [None, Some(config), None]; let chanmon_cfgs = create_chanmon_cfgs(3); let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); @@ -574,9 +574,9 @@ fn test_invalid_upfront_shutdown_script() { #[test] fn test_segwit_v0_shutdown_script() { let mut config = UserConfig::default(); - config.own_channel_config.announced_channel = true; - config.peer_channel_config_limits.force_announced_channel_preference = false; - config.own_channel_config.commit_upfront_shutdown_pubkey = false; + config.channel_handshake_config.announced_channel = true; + config.channel_handshake_limits.force_announced_channel_preference = false; + config.channel_handshake_config.commit_upfront_shutdown_pubkey = false; let user_cfgs = [None, Some(config), None]; let chanmon_cfgs = create_chanmon_cfgs(3); let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); @@ -609,9 +609,9 @@ fn test_segwit_v0_shutdown_script() { #[test] fn test_anysegwit_shutdown_script() { let mut config = UserConfig::default(); - config.own_channel_config.announced_channel = true; - config.peer_channel_config_limits.force_announced_channel_preference = false; - config.own_channel_config.commit_upfront_shutdown_pubkey = false; + config.channel_handshake_config.announced_channel = true; + config.channel_handshake_limits.force_announced_channel_preference = false; + config.channel_handshake_config.commit_upfront_shutdown_pubkey = false; let user_cfgs = [None, Some(config), None]; let chanmon_cfgs = create_chanmon_cfgs(3); let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); @@ -644,9 +644,9 @@ fn test_anysegwit_shutdown_script() { #[test] fn test_unsupported_anysegwit_shutdown_script() { let mut config = UserConfig::default(); - config.own_channel_config.announced_channel = true; - config.peer_channel_config_limits.force_announced_channel_preference = false; - config.own_channel_config.commit_upfront_shutdown_pubkey = false; + config.channel_handshake_config.announced_channel = true; + config.channel_handshake_limits.force_announced_channel_preference = false; + config.channel_handshake_config.commit_upfront_shutdown_pubkey = false; let user_cfgs = [None, Some(config), None]; let chanmon_cfgs = create_chanmon_cfgs(3); let mut node_cfgs = create_node_cfgs(3, &chanmon_cfgs); @@ -686,9 +686,9 @@ fn test_unsupported_anysegwit_shutdown_script() { #[test] fn test_invalid_shutdown_script() { let mut config = UserConfig::default(); - config.own_channel_config.announced_channel = true; - config.peer_channel_config_limits.force_announced_channel_preference = false; - config.own_channel_config.commit_upfront_shutdown_pubkey = false; + config.channel_handshake_config.announced_channel = true; + config.channel_handshake_limits.force_announced_channel_preference = false; + config.channel_handshake_config.commit_upfront_shutdown_pubkey = false; let user_cfgs = [None, Some(config), None]; let chanmon_cfgs = create_chanmon_cfgs(3); let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); diff --git a/lightning/src/util/config.rs b/lightning/src/util/config.rs index 570e570a..a76f7162 100644 --- a/lightning/src/util/config.rs +++ b/lightning/src/util/config.rs @@ -350,7 +350,7 @@ impl Default for ChannelConfig { /// [`ChannelHandshakeConfig::commit_upfront_shutdown_pubkey`] fields. #[derive(Copy, Clone, Debug)] pub(crate) struct LegacyChannelConfig { - pub(crate) mutable: ChannelConfig, + pub(crate) options: ChannelConfig, /// Deprecated but may still be read from. See [`ChannelHandshakeConfig::announced_channel`] to /// set this when opening/accepting a channel. pub(crate) announced_channel: bool, @@ -363,7 +363,7 @@ pub(crate) struct LegacyChannelConfig { impl Default for LegacyChannelConfig { fn default() -> Self { Self { - mutable: ChannelConfig::default(), + options: ChannelConfig::default(), announced_channel: false, commit_upfront_shutdown_pubkey: true, } @@ -373,13 +373,13 @@ impl Default for LegacyChannelConfig { impl ::util::ser::Writeable for LegacyChannelConfig { fn write(&self, writer: &mut W) -> Result<(), ::io::Error> { write_tlv_fields!(writer, { - (0, self.mutable.forwarding_fee_proportional_millionths, required), - (1, self.mutable.max_dust_htlc_exposure_msat, (default_value, 5_000_000)), - (2, self.mutable.cltv_expiry_delta, required), - (3, self.mutable.force_close_avoidance_max_fee_satoshis, (default_value, 1000)), + (0, self.options.forwarding_fee_proportional_millionths, required), + (1, self.options.max_dust_htlc_exposure_msat, (default_value, 5_000_000)), + (2, self.options.cltv_expiry_delta, required), + (3, self.options.force_close_avoidance_max_fee_satoshis, (default_value, 1000)), (4, self.announced_channel, required), (6, self.commit_upfront_shutdown_pubkey, required), - (8, self.mutable.forwarding_fee_base_msat, required), + (8, self.options.forwarding_fee_base_msat, required), }); Ok(()) } @@ -404,7 +404,7 @@ impl ::util::ser::Readable for LegacyChannelConfig { (8, forwarding_fee_base_msat, required), }); Ok(Self { - mutable: ChannelConfig { + options: ChannelConfig { forwarding_fee_proportional_millionths, max_dust_htlc_exposure_msat, cltv_expiry_delta, @@ -423,12 +423,12 @@ impl ::util::ser::Readable for LegacyChannelConfig { /// (but currently with 0 relay fees!) #[derive(Copy, Clone, Debug)] pub struct UserConfig { - /// Channel config that we propose to our counterparty. - pub own_channel_config: ChannelHandshakeConfig, - /// Limits applied to our counterparty's proposed channel config settings. - pub peer_channel_config_limits: ChannelHandshakeLimits, + /// Channel handshake config that we propose to our counterparty. + pub channel_handshake_config: ChannelHandshakeConfig, + /// Limits applied to our counterparty's proposed channel handshake config settings. + pub channel_handshake_limits: ChannelHandshakeLimits, /// Channel config which affects behavior during channel lifetime. - pub channel_options: ChannelConfig, + pub channel_config: ChannelConfig, /// If this is set to false, we will reject any HTLCs which were to be forwarded over private /// channels. This prevents us from taking on HTLC-forwarding risk when we intend to run as a /// node which is not online reliably. @@ -468,9 +468,9 @@ pub struct UserConfig { impl Default for UserConfig { fn default() -> Self { UserConfig { - own_channel_config: ChannelHandshakeConfig::default(), - peer_channel_config_limits: ChannelHandshakeLimits::default(), - channel_options: ChannelConfig::default(), + channel_handshake_config: ChannelHandshakeConfig::default(), + channel_handshake_limits: ChannelHandshakeLimits::default(), + channel_config: ChannelConfig::default(), accept_forwards_to_priv_channels: false, accept_inbound_channels: true, manually_accept_inbound_channels: false,