Skip to content

Commit 5421e1a

Browse files
authored
Merge pull request #1529 from wpaulino/move-channel-config-static-fields
Move ChannelConfig static fields to ChannelHandshakeConfig
2 parents 716539e + ec7ccf0 commit 5421e1a

12 files changed

+176
-102
lines changed

fuzz/src/chanmon_consistency.rs

+2-2
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

+1-1
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

+2-2
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/chanmon_update_fail_tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2541,7 +2541,7 @@ fn test_temporary_error_during_shutdown() {
25412541
// Test that temporary failures when updating the monitor's shutdown script delay cooperative
25422542
// close.
25432543
let mut config = test_default_channel_config();
2544-
config.channel_options.commit_upfront_shutdown_pubkey = false;
2544+
config.own_channel_config.commit_upfront_shutdown_pubkey = false;
25452545

25462546
let chanmon_cfgs = create_chanmon_cfgs(2);
25472547
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
@@ -2596,7 +2596,7 @@ fn test_permanent_error_during_sending_shutdown() {
25962596
// Test that permanent failures when updating the monitor's shutdown script result in a force
25972597
// close when initiating a cooperative close.
25982598
let mut config = test_default_channel_config();
2599-
config.channel_options.commit_upfront_shutdown_pubkey = false;
2599+
config.own_channel_config.commit_upfront_shutdown_pubkey = false;
26002600

26012601
let chanmon_cfgs = create_chanmon_cfgs(2);
26022602
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
@@ -2617,7 +2617,7 @@ fn test_permanent_error_during_handling_shutdown() {
26172617
// Test that permanent failures when updating the monitor's shutdown script result in a force
26182618
// close when handling a cooperative close.
26192619
let mut config = test_default_channel_config();
2620-
config.channel_options.commit_upfront_shutdown_pubkey = false;
2620+
config.own_channel_config.commit_upfront_shutdown_pubkey = false;
26212621

26222622
let chanmon_cfgs = create_chanmon_cfgs(2);
26232623
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);

lightning/src/ln/channel.rs

+30-21
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use util::events::ClosureReason;
3939
use util::ser::{Readable, ReadableArgs, Writeable, Writer, VecWriter};
4040
use util::logger::Logger;
4141
use util::errors::APIError;
42-
use util::config::{UserConfig, ChannelConfig, ChannelHandshakeConfig, ChannelHandshakeLimits};
42+
use util::config::{UserConfig, LegacyChannelConfig, ChannelHandshakeConfig, ChannelHandshakeLimits};
4343
use util::scid_utils::scid_from_parts;
4444

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

498498
inbound_handshake_limits_override: Option<ChannelHandshakeLimits>,
499499

@@ -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
@@ -918,7 +918,7 @@ impl<Signer: Sign> Channel<Signer> {
918918
let mut secp_ctx = Secp256k1::new();
919919
secp_ctx.seeded_randomize(&keys_provider.get_secure_random_bytes());
920920

921-
let shutdown_scriptpubkey = if config.channel_options.commit_upfront_shutdown_pubkey {
921+
let shutdown_scriptpubkey = if config.own_channel_config.commit_upfront_shutdown_pubkey {
922922
Some(keys_provider.get_shutdown_scriptpubkey())
923923
} else { None };
924924

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

931931
Ok(Channel {
932932
user_id,
933-
config: config.channel_options.clone(),
933+
934+
config: LegacyChannelConfig {
935+
mutable: config.channel_options.clone(),
936+
announced_channel: config.own_channel_config.announced_channel,
937+
commit_upfront_shutdown_pubkey: config.own_channel_config.commit_upfront_shutdown_pubkey,
938+
},
939+
934940
inbound_handshake_limits_override: Some(config.peer_channel_config_limits.clone()),
935941

936942
channel_id: keys_provider.get_secure_random_bytes(),
@@ -1117,7 +1123,6 @@ impl<Signer: Sign> Channel<Signer> {
11171123
delayed_payment_basepoint: msg.delayed_payment_basepoint,
11181124
htlc_basepoint: msg.htlc_basepoint
11191125
};
1120-
let mut local_config = (*config).channel_options.clone();
11211126

11221127
if config.own_channel_config.our_to_self_delay < BREAKDOWN_TIMEOUT {
11231128
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)));
@@ -1182,12 +1187,10 @@ impl<Signer: Sign> Channel<Signer> {
11821187
// Convert things into internal flags and prep our state:
11831188

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

11921195
let holder_selected_channel_reserve_satoshis = Channel::<Signer>::get_holder_selected_channel_reserve_satoshis(msg.funding_satoshis);
11931196
if holder_selected_channel_reserve_satoshis < MIN_CHAN_DUST_LIMIT_SATOSHIS {
@@ -1239,7 +1242,7 @@ impl<Signer: Sign> Channel<Signer> {
12391242
}
12401243
} else { None };
12411244

1242-
let shutdown_scriptpubkey = if config.channel_options.commit_upfront_shutdown_pubkey {
1245+
let shutdown_scriptpubkey = if config.own_channel_config.commit_upfront_shutdown_pubkey {
12431246
Some(keys_provider.get_shutdown_scriptpubkey())
12441247
} else { None };
12451248

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

12551258
let chan = Channel {
12561259
user_id,
1257-
config: local_config,
1260+
1261+
config: LegacyChannelConfig {
1262+
mutable: config.channel_options.clone(),
1263+
announced_channel,
1264+
commit_upfront_shutdown_pubkey: config.own_channel_config.commit_upfront_shutdown_pubkey,
1265+
},
1266+
12581267
inbound_handshake_limits_override: None,
12591268

12601269
channel_id: msg.temporary_channel_id,
@@ -4011,7 +4020,7 @@ impl<Signer: Sign> Channel<Signer> {
40114020
// We always add force_close_avoidance_max_fee_satoshis to our normal
40124021
// feerate-calculated fee, but allow the max to be overridden if we're using a
40134022
// target feerate-calculated fee.
4014-
cmp::max(normal_feerate as u64 * tx_weight / 1000 + self.config.force_close_avoidance_max_fee_satoshis,
4023+
cmp::max(normal_feerate as u64 * tx_weight / 1000 + self.config.mutable.force_close_avoidance_max_fee_satoshis,
40154024
proposed_max_feerate as u64 * tx_weight / 1000)
40164025
} else {
40174026
self.channel_value_satoshis - (self.value_to_self_msat + 999) / 1000
@@ -4471,15 +4480,15 @@ impl<Signer: Sign> Channel<Signer> {
44714480
}
44724481

44734482
pub fn get_fee_proportional_millionths(&self) -> u32 {
4474-
self.config.forwarding_fee_proportional_millionths
4483+
self.config.mutable.forwarding_fee_proportional_millionths
44754484
}
44764485

44774486
pub fn get_cltv_expiry_delta(&self) -> u16 {
4478-
cmp::max(self.config.cltv_expiry_delta, MIN_CLTV_EXPIRY_DELTA)
4487+
cmp::max(self.config.mutable.cltv_expiry_delta, MIN_CLTV_EXPIRY_DELTA)
44794488
}
44804489

44814490
pub fn get_max_dust_htlc_exposure_msat(&self) -> u64 {
4482-
self.config.max_dust_htlc_exposure_msat
4491+
self.config.mutable.max_dust_htlc_exposure_msat
44834492
}
44844493

44854494
pub fn get_feerate(&self) -> u32 {
@@ -4566,7 +4575,7 @@ impl<Signer: Sign> Channel<Signer> {
45664575
/// Gets the fee we'd want to charge for adding an HTLC output to this Channel
45674576
/// Allowed in any state (including after shutdown)
45684577
pub fn get_outbound_forwarding_fee_base_msat(&self) -> u32 {
4569-
self.config.forwarding_fee_base_msat
4578+
self.config.mutable.forwarding_fee_base_msat
45704579
}
45714580

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

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

6033-
let mut config = Some(ChannelConfig::default());
6042+
let mut config = Some(LegacyChannelConfig::default());
60346043
if ver == 1 {
60356044
// Read the old serialization of the ChannelConfig from version 0.0.98.
6036-
config.as_mut().unwrap().forwarding_fee_proportional_millionths = Readable::read(reader)?;
6037-
config.as_mut().unwrap().cltv_expiry_delta = Readable::read(reader)?;
6045+
config.as_mut().unwrap().mutable.forwarding_fee_proportional_millionths = Readable::read(reader)?;
6046+
config.as_mut().unwrap().mutable.cltv_expiry_delta = Readable::read(reader)?;
60386047
config.as_mut().unwrap().announced_channel = Readable::read(reader)?;
60396048
config.as_mut().unwrap().commit_upfront_shutdown_pubkey = Readable::read(reader)?;
60406049
} else {
@@ -6926,7 +6935,7 @@ mod tests {
69266935

69276936
let counterparty_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
69286937
let mut config = UserConfig::default();
6929-
config.channel_options.announced_channel = false;
6938+
config.own_channel_config.announced_channel = false;
69306939
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
69316940
chan.holder_dust_limit_satoshis = 546;
69326941
chan.counterparty_selected_channel_reserve_satoshis = Some(0); // Filled in in accept_channel

lightning/src/ln/functional_test_utils.rs

+5-3
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);
@@ -1689,7 +1689,9 @@ pub fn do_claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>,
16891689
($node: expr, $prev_node: expr, $next_node: expr, $new_msgs: expr) => {
16901690
{
16911691
$node.node.handle_update_fulfill_htlc(&$prev_node.node.get_our_node_id(), &next_msgs.as_ref().unwrap().0);
1692-
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;
1692+
let fee = $node.node.channel_state.lock().unwrap()
1693+
.by_id.get(&next_msgs.as_ref().unwrap().0.channel_id).unwrap()
1694+
.config.mutable.forwarding_fee_base_msat;
16931695
expect_payment_forwarded!($node, $next_node, $prev_node, Some(fee as u64), false, false);
16941696
expected_total_fee_msat += fee as u64;
16951697
check_added_monitors!($node, 1);
@@ -1966,7 +1968,7 @@ pub fn test_default_channel_config() -> UserConfig {
19661968
// Set cltv_expiry_delta slightly lower to keep the final CLTV values inside one byte in our
19671969
// tests so that our script-length checks don't fail (see ACCEPTED_HTLC_SCRIPT_WEIGHT).
19681970
default_config.channel_options.cltv_expiry_delta = MIN_CLTV_EXPIRY_DELTA;
1969-
default_config.channel_options.announced_channel = true;
1971+
default_config.own_channel_config.announced_channel = true;
19701972
default_config.peer_channel_config_limits.force_announced_channel_preference = false;
19711973
// When most of our tests were written, the default HTLC minimum was fixed at 1000.
19721974
// It now defaults to 1, so we simply set it to the expected value here.

lightning/src/ln/functional_tests.rs

+6-6
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

+3-3
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/payment_tests.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,8 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) {
531531
// Update the fee on the middle hop to ensure PaymentSent events have the correct (retried) fee
532532
// and not the original fee. We also update node[1]'s relevant config as
533533
// do_claim_payment_along_route expects us to never overpay.
534-
nodes[1].node.channel_state.lock().unwrap().by_id.get_mut(&chan_id_2).unwrap().config.forwarding_fee_base_msat += 100_000;
534+
nodes[1].node.channel_state.lock().unwrap().by_id.get_mut(&chan_id_2).unwrap()
535+
.config.mutable.forwarding_fee_base_msat += 100_000;
535536
new_route.paths[0][0].fee_msat += 100_000;
536537

537538
assert!(nodes[0].node.retry_payment(&new_route, payment_id_1).is_err()); // Shouldn't be allowed to retry a fulfilled payment

0 commit comments

Comments
 (0)