Skip to content

Move ChannelConfig static fields to ChannelHandshakeConfig #1529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions fuzz/src/chanmon_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {

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

let mut config = UserConfig::default();
config.channel_options.forwarding_fee_proportional_millionths = 0;
config.channel_options.announced_channel = true;
config.own_channel_config.announced_channel = true;

let mut monitors = HashMap::new();
let mut old_monitors = $old_monitors.latest_monitors.lock().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/full_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
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.channel_options.announced_channel = get_slice!(1)[0] != 0;
config.own_channel_config.announced_channel = get_slice!(1)[0] != 0;
let network = Network::Bitcoin;
let params = ChainParameters {
network,
Expand Down
4 changes: 2 additions & 2 deletions lightning-invoice/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.channel_options.announced_channel = false;
private_chan_cfg.own_channel_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);
Expand Down Expand Up @@ -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.channel_options.announced_channel = false;
private_chan_cfg.own_channel_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);
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/ln/chanmon_update_fail_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.channel_options.commit_upfront_shutdown_pubkey = false;
config.own_channel_config.commit_upfront_shutdown_pubkey = false;

let chanmon_cfgs = create_chanmon_cfgs(2);
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
Expand Down Expand Up @@ -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.channel_options.commit_upfront_shutdown_pubkey = false;
config.own_channel_config.commit_upfront_shutdown_pubkey = false;

let chanmon_cfgs = create_chanmon_cfgs(2);
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
Expand All @@ -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.channel_options.commit_upfront_shutdown_pubkey = false;
config.own_channel_config.commit_upfront_shutdown_pubkey = false;

let chanmon_cfgs = create_chanmon_cfgs(2);
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
Expand Down
51 changes: 30 additions & 21 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use util::events::ClosureReason;
use util::ser::{Readable, ReadableArgs, Writeable, Writer, VecWriter};
use util::logger::Logger;
use util::errors::APIError;
use util::config::{UserConfig, ChannelConfig, ChannelHandshakeConfig, ChannelHandshakeLimits};
use util::config::{UserConfig, LegacyChannelConfig, ChannelHandshakeConfig, ChannelHandshakeLimits};
use util::scid_utils::scid_from_parts;

use io;
Expand Down Expand Up @@ -491,9 +491,9 @@ pub(crate) const MIN_AFFORDABLE_HTLC_COUNT: usize = 4;
// Counterparty designates channel data owned by the another channel participant entity.
pub(super) struct Channel<Signer: Sign> {
#[cfg(any(test, feature = "_test_utils"))]
pub(crate) config: ChannelConfig,
pub(crate) config: LegacyChannelConfig,
#[cfg(not(any(test, feature = "_test_utils")))]
config: ChannelConfig,
config: LegacyChannelConfig,

inbound_handshake_limits_override: Option<ChannelHandshakeLimits>,

Expand Down Expand Up @@ -855,7 +855,7 @@ impl<Signer: Sign> Channel<Signer> {
// 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.channel_options.announced_channel && config.own_channel_config.negotiate_scid_privacy {
if !config.own_channel_config.announced_channel && config.own_channel_config.negotiate_scid_privacy {
ret.set_scid_privacy_required();
}
ret
Expand Down Expand Up @@ -918,7 +918,7 @@ impl<Signer: Sign> Channel<Signer> {
let mut secp_ctx = Secp256k1::new();
secp_ctx.seeded_randomize(&keys_provider.get_secure_random_bytes());

let shutdown_scriptpubkey = if config.channel_options.commit_upfront_shutdown_pubkey {
let shutdown_scriptpubkey = if config.own_channel_config.commit_upfront_shutdown_pubkey {
Some(keys_provider.get_shutdown_scriptpubkey())
} else { None };

Expand All @@ -930,7 +930,13 @@ impl<Signer: Sign> Channel<Signer> {

Ok(Channel {
user_id,
config: config.channel_options.clone(),

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,
},

inbound_handshake_limits_override: Some(config.peer_channel_config_limits.clone()),

channel_id: keys_provider.get_secure_random_bytes(),
Expand Down Expand Up @@ -1117,7 +1123,6 @@ impl<Signer: Sign> Channel<Signer> {
delayed_payment_basepoint: msg.delayed_payment_basepoint,
htlc_basepoint: msg.htlc_basepoint
};
let mut local_config = (*config).channel_options.clone();

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)));
Expand Down Expand Up @@ -1182,12 +1187,10 @@ impl<Signer: Sign> Channel<Signer> {
// Convert things into internal flags and prep our state:

if config.peer_channel_config_limits.force_announced_channel_preference {
if local_config.announced_channel != announced_channel {
if config.own_channel_config.announced_channel != announced_channel {
return Err(ChannelError::Close("Peer tried to open channel but their announcement preference is different from ours".to_owned()));
}
}
// we either accept their preference or the preferences match
local_config.announced_channel = announced_channel;

let holder_selected_channel_reserve_satoshis = Channel::<Signer>::get_holder_selected_channel_reserve_satoshis(msg.funding_satoshis);
if holder_selected_channel_reserve_satoshis < MIN_CHAN_DUST_LIMIT_SATOSHIS {
Expand Down Expand Up @@ -1239,7 +1242,7 @@ impl<Signer: Sign> Channel<Signer> {
}
} else { None };

let shutdown_scriptpubkey = if config.channel_options.commit_upfront_shutdown_pubkey {
let shutdown_scriptpubkey = if config.own_channel_config.commit_upfront_shutdown_pubkey {
Some(keys_provider.get_shutdown_scriptpubkey())
} else { None };

Expand All @@ -1254,7 +1257,13 @@ impl<Signer: Sign> Channel<Signer> {

let chan = Channel {
user_id,
config: local_config,

config: LegacyChannelConfig {
mutable: config.channel_options.clone(),
announced_channel,
commit_upfront_shutdown_pubkey: config.own_channel_config.commit_upfront_shutdown_pubkey,
},

inbound_handshake_limits_override: None,

channel_id: msg.temporary_channel_id,
Expand Down Expand Up @@ -4011,7 +4020,7 @@ impl<Signer: Sign> Channel<Signer> {
// 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.force_close_avoidance_max_fee_satoshis,
cmp::max(normal_feerate as u64 * tx_weight / 1000 + self.config.mutable.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
Expand Down Expand Up @@ -4471,15 +4480,15 @@ impl<Signer: Sign> Channel<Signer> {
}

pub fn get_fee_proportional_millionths(&self) -> u32 {
self.config.forwarding_fee_proportional_millionths
self.config.mutable.forwarding_fee_proportional_millionths
}

pub fn get_cltv_expiry_delta(&self) -> u16 {
cmp::max(self.config.cltv_expiry_delta, MIN_CLTV_EXPIRY_DELTA)
cmp::max(self.config.mutable.cltv_expiry_delta, MIN_CLTV_EXPIRY_DELTA)
}

pub fn get_max_dust_htlc_exposure_msat(&self) -> u64 {
self.config.max_dust_htlc_exposure_msat
self.config.mutable.max_dust_htlc_exposure_msat
}

pub fn get_feerate(&self) -> u32 {
Expand Down Expand Up @@ -4566,7 +4575,7 @@ impl<Signer: Sign> Channel<Signer> {
/// 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.forwarding_fee_base_msat
self.config.mutable.forwarding_fee_base_msat
}

/// Returns true if we've ever received a message from the remote end for this Channel
Expand Down Expand Up @@ -6022,11 +6031,11 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>

let user_id = Readable::read(reader)?;

let mut config = Some(ChannelConfig::default());
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().forwarding_fee_proportional_millionths = Readable::read(reader)?;
config.as_mut().unwrap().cltv_expiry_delta = Readable::read(reader)?;
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().announced_channel = Readable::read(reader)?;
config.as_mut().unwrap().commit_upfront_shutdown_pubkey = Readable::read(reader)?;
} else {
Expand Down Expand Up @@ -6918,7 +6927,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.channel_options.announced_channel = false;
config.own_channel_config.announced_channel = false;
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
chan.holder_dust_limit_satoshis = 546;
chan.counterparty_selected_channel_reserve_satoshis = Some(0); // Filled in in accept_channel
Expand Down
8 changes: 5 additions & 3 deletions lightning/src/ln/functional_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Node<'b, 'c, 'd>>, 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.channel_options.announced_channel = false;
no_announce_cfg.own_channel_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);
Expand Down Expand Up @@ -1679,7 +1679,9 @@ pub fn do_claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>,
($node: expr, $prev_node: expr, $next_node: expr, $new_msgs: expr) => {
{
$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.forwarding_fee_base_msat;
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;
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);
Expand Down Expand Up @@ -1956,7 +1958,7 @@ pub fn test_default_channel_config() -> UserConfig {
// 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.channel_options.announced_channel = true;
default_config.own_channel_config.announced_channel = true;
default_config.peer_channel_config_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.
Expand Down
12 changes: 6 additions & 6 deletions lightning/src/ln/functional_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2362,11 +2362,11 @@ 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.channel_options.announced_channel = true;
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;
let mut bob_config = UserConfig::default();
bob_config.channel_options.announced_channel = true;
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;
let user_cfgs = [Some(alice_config), Some(bob_config)];
Expand Down Expand Up @@ -8282,16 +8282,16 @@ 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.channel_options.announced_channel = true;
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;
let mut config_50_percent = UserConfig::default();
config_50_percent.channel_options.announced_channel = true;
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;
let mut config_95_percent = UserConfig::default();
config_95_percent.channel_options.announced_channel = true;
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;
let mut config_100_percent = UserConfig::default();
config_100_percent.channel_options.announced_channel = true;
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;

let chanmon_cfgs = create_chanmon_cfgs(4);
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/ln/onion_route_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ fn test_onion_failure() {
// 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.channel_options.announced_channel = true;
node_2_cfg.own_channel_config.announced_channel = true;
node_2_cfg.peer_channel_config_limits.force_announced_channel_preference = false;

// When this test was written, the default base fee floated based on the HTLC count.
Expand Down Expand Up @@ -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.channel_options.announced_channel = false;
priv_channels_conf.own_channel_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)]);
Expand Down Expand Up @@ -1085,7 +1085,7 @@ fn test_phantom_dust_exposure_failure() {
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.channel_options.announced_channel = true;
receiver_config.own_channel_config.announced_channel = true;

let chanmon_cfgs = create_chanmon_cfgs(2);
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
Expand Down
3 changes: 2 additions & 1 deletion lightning/src/ln/payment_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,8 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) {
// Update the fee on the middle hop to ensure PaymentSent events have the correct (retried) fee
// 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.forwarding_fee_base_msat += 100_000;
nodes[1].node.channel_state.lock().unwrap().by_id.get_mut(&chan_id_2).unwrap()
.config.mutable.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
Expand Down
Loading