Skip to content

Commit 6bccdaa

Browse files
committed
Move forwarding_fee_proportional_millionths, forwarding_fee_base_msat to ChannelHandshakeConfig
1 parent 34cdca9 commit 6bccdaa

8 files changed

+62
-42
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {
354354
Arc::new(TestPersister { update_ret: Mutex::new(Ok(())) }), Arc::clone(&keys_manager)));
355355

356356
let mut config = UserConfig::default();
357-
config.channel_options.forwarding_fee_proportional_millionths = 0;
357+
config.own_channel_config.forwarding_fee_proportional_millionths = 0;
358358
config.channel_options.announced_channel = true;
359359
let network = Network::Bitcoin;
360360
let params = ChainParameters {
@@ -374,7 +374,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {
374374
Arc::new(TestPersister { update_ret: Mutex::new(Ok(())) }), Arc::clone(& $keys_manager)));
375375

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

380380
let mut monitors = HashMap::new();

fuzz/src/full_stack.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
379379

380380
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) });
381381
let mut config = UserConfig::default();
382-
config.channel_options.forwarding_fee_proportional_millionths = slice_to_be32(get_slice!(4));
382+
config.own_channel_config.forwarding_fee_proportional_millionths = slice_to_be32(get_slice!(4));
383383
config.channel_options.announced_channel = get_slice!(1)[0] != 0;
384384
let network = Network::Bitcoin;
385385
let params = ChainParameters {

lightning/src/ln/channel.rs

Lines changed: 29 additions & 7 deletions
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};
42+
use util::config::{UserConfig,ChannelConfig,ChannelHandshakeConfig};
4343
use util::scid_utils::scid_from_parts;
4444

4545
use io;
@@ -426,6 +426,13 @@ pub(super) struct Channel<Signer: Sign> {
426426
#[cfg(not(any(test, feature = "_test_utils")))]
427427
config: ChannelConfig,
428428

429+
#[cfg(any(test, feature = "_test_utils"))]
430+
pub(crate) forwarding_fee_base_msat: u32,
431+
#[cfg(not(any(test, feature = "_test_utils")))]
432+
forwarding_fee_base_msat: u32,
433+
forwarding_fee_proportional_millionths: u32,
434+
cltv_expiry_delta: u16,
435+
429436
user_id: u64,
430437

431438
channel_id: [u8; 32],
@@ -760,11 +767,16 @@ impl<Signer: Sign> Channel<Signer> {
760767
return Err(APIError::IncompatibleShutdownScript { script: shutdown_scriptpubkey.clone() });
761768
}
762769
}
770+
let handshake_config = config.own_channel_config.clone();
763771

764772
Ok(Channel {
765773
user_id,
766774
config: config.channel_options.clone(),
767775

776+
forwarding_fee_base_msat: handshake_config.forwarding_fee_base_msat,
777+
forwarding_fee_proportional_millionths: handshake_config.forwarding_fee_proportional_millionths,
778+
cltv_expiry_delta: config.channel_options.clone().cltv_expiry_delta,
779+
768780
channel_id: keys_provider.get_secure_random_bytes(),
769781
channel_state: ChannelState::OurInitSent as u32,
770782
secp_ctx,
@@ -929,6 +941,7 @@ impl<Signer: Sign> Channel<Signer> {
929941
htlc_basepoint: msg.htlc_basepoint
930942
};
931943
let mut local_config = (*config).channel_options.clone();
944+
let handshake_config = (*config).own_channel_config.clone();
932945

933946
if config.own_channel_config.our_to_self_delay < BREAKDOWN_TIMEOUT {
934947
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)));
@@ -1063,6 +1076,10 @@ impl<Signer: Sign> Channel<Signer> {
10631076
user_id,
10641077
config: local_config,
10651078

1079+
forwarding_fee_base_msat: handshake_config.forwarding_fee_base_msat,
1080+
forwarding_fee_proportional_millionths: handshake_config.forwarding_fee_proportional_millionths,
1081+
cltv_expiry_delta: local_config.cltv_expiry_delta,
1082+
10661083
channel_id: msg.temporary_channel_id,
10671084
channel_state: (ChannelState::OurInitSent as u32) | (ChannelState::TheirInitSent as u32),
10681085
secp_ctx,
@@ -4052,11 +4069,11 @@ impl<Signer: Sign> Channel<Signer> {
40524069
}
40534070

40544071
pub fn get_fee_proportional_millionths(&self) -> u32 {
4055-
self.config.forwarding_fee_proportional_millionths
4072+
self.forwarding_fee_proportional_millionths
40564073
}
40574074

40584075
pub fn get_cltv_expiry_delta(&self) -> u16 {
4059-
cmp::max(self.config.cltv_expiry_delta, MIN_CLTV_EXPIRY_DELTA)
4076+
cmp::max(self.cltv_expiry_delta, MIN_CLTV_EXPIRY_DELTA)
40604077
}
40614078

40624079
pub fn get_max_dust_htlc_exposure_msat(&self) -> u64 {
@@ -4147,7 +4164,7 @@ impl<Signer: Sign> Channel<Signer> {
41474164
/// Gets the fee we'd want to charge for adding an HTLC output to this Channel
41484165
/// Allowed in any state (including after shutdown)
41494166
pub fn get_outbound_forwarding_fee_base_msat(&self) -> u32 {
4150-
self.config.forwarding_fee_base_msat
4167+
self.forwarding_fee_base_msat
41514168
}
41524169

41534170
/// Returns true if we've ever received a message from the remote end for this Channel
@@ -5188,7 +5205,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
51885205

51895206
// Write out the old serialization for the config object. This is read by version-1
51905207
// deserializers, but we will read the version in the TLV at the end instead.
5191-
self.config.forwarding_fee_proportional_millionths.write(writer)?;
5208+
self.forwarding_fee_proportional_millionths.write(writer)?;
51925209
self.config.cltv_expiry_delta.write(writer)?;
51935210
self.config.announced_channel.write(writer)?;
51945211
self.config.commit_upfront_shutdown_pubkey.write(writer)?;
@@ -5450,9 +5467,10 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
54505467
let user_id = Readable::read(reader)?;
54515468

54525469
let mut config = Some(ChannelConfig::default());
5470+
let handshake_config = Some(ChannelHandshakeConfig::default());
5471+
54535472
if ver == 1 {
5454-
// Read the old serialization of the ChannelConfig from version 0.0.98.
5455-
config.as_mut().unwrap().forwarding_fee_proportional_millionths = Readable::read(reader)?;
5473+
// Read the old serialization of the ChannelConfig from version 0.0.98.handshake_config.as_mut().unwrap().forwarding_fee_proportional_millionths = Readable::read(reader)?;
54565474
config.as_mut().unwrap().cltv_expiry_delta = Readable::read(reader)?;
54575475
config.as_mut().unwrap().announced_channel = Readable::read(reader)?;
54585476
config.as_mut().unwrap().commit_upfront_shutdown_pubkey = Readable::read(reader)?;
@@ -5708,6 +5726,10 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
57085726
user_id,
57095727

57105728
config: config.unwrap(),
5729+
forwarding_fee_base_msat: handshake_config.unwrap().forwarding_fee_base_msat,
5730+
forwarding_fee_proportional_millionths: handshake_config.unwrap().forwarding_fee_proportional_millionths,
5731+
cltv_expiry_delta: config.unwrap().cltv_expiry_delta,
5732+
57115733
channel_id,
57125734
channel_state,
57135735
secp_ctx,

lightning/src/ln/functional_test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,7 @@ pub fn do_claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>,
14681468
($node: expr, $prev_node: expr, $new_msgs: expr) => {
14691469
{
14701470
$node.node.handle_update_fulfill_htlc(&$prev_node.node.get_our_node_id(), &next_msgs.as_ref().unwrap().0);
1471-
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;
1471+
let fee = $node.node.channel_state.lock().unwrap().by_id.get(&next_msgs.as_ref().unwrap().0.channel_id).unwrap().forwarding_fee_base_msat;
14721472
expect_payment_forwarded!($node, Some(fee as u64), false);
14731473
expected_total_fee_msat += fee as u64;
14741474
check_added_monitors!($node, 1);

lightning/src/ln/functional_tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,7 +1787,7 @@ fn test_channel_reserve_holding_cell_htlcs() {
17871787
// When this test was written, the default base fee floated based on the HTLC count.
17881788
// It is now fixed, so we simply set the fee to the expected value here.
17891789
let mut config = test_default_channel_config();
1790-
config.channel_options.forwarding_fee_base_msat = 239;
1790+
config.own_channel_config.forwarding_fee_base_msat = 239;
17911791
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[Some(config.clone()), Some(config.clone()), Some(config.clone())]);
17921792
let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs);
17931793
let chan_1 = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 190000, 1001, InitFeatures::known(), InitFeatures::known());
@@ -5135,7 +5135,7 @@ fn test_duplicate_payment_hash_one_failure_one_success() {
51355135
// When this test was written, the default base fee floated based on the HTLC count.
51365136
// It is now fixed, so we simply set the fee to the expected value here.
51375137
let mut config = test_default_channel_config();
5138-
config.channel_options.forwarding_fee_base_msat = 196;
5138+
config.own_channel_config.forwarding_fee_base_msat = 196;
51395139
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs,
51405140
&[Some(config.clone()), Some(config.clone()), Some(config.clone()), Some(config.clone())]);
51415141
let mut nodes = create_network(4, &node_cfgs, &node_chanmgrs);
@@ -5332,7 +5332,7 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno
53325332
// When this test was written, the default base fee floated based on the HTLC count.
53335333
// It is now fixed, so we simply set the fee to the expected value here.
53345334
let mut config = test_default_channel_config();
5335-
config.channel_options.forwarding_fee_base_msat = 196;
5335+
config.own_channel_config.forwarding_fee_base_msat = 196;
53365336
let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs,
53375337
&[Some(config.clone()), Some(config.clone()), Some(config.clone()), Some(config.clone()), Some(config.clone()), Some(config.clone())]);
53385338
let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
@@ -6208,7 +6208,7 @@ fn test_fail_holding_cell_htlc_upon_free_multihop() {
62086208
// When this test was written, the default base fee floated based on the HTLC count.
62096209
// It is now fixed, so we simply set the fee to the expected value here.
62106210
let mut config = test_default_channel_config();
6211-
config.channel_options.forwarding_fee_base_msat = 196;
6211+
config.own_channel_config.forwarding_fee_base_msat = 196;
62126212
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[Some(config.clone()), Some(config.clone()), Some(config.clone())]);
62136213
let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs);
62146214
let chan_0_1 = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000, InitFeatures::known(), InitFeatures::known());

lightning/src/ln/onion_route_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ fn test_fee_failures() {
258258
// When this test was written, the default base fee floated based on the HTLC count.
259259
// It is now fixed, so we simply set the fee to the expected value here.
260260
let mut config = test_default_channel_config();
261-
config.channel_options.forwarding_fee_base_msat = 196;
261+
config.own_channel_config.forwarding_fee_base_msat = 196;
262262

263263
let chanmon_cfgs = create_chanmon_cfgs(3);
264264
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
@@ -310,7 +310,7 @@ fn test_onion_failure() {
310310
// When this test was written, the default base fee floated based on the HTLC count.
311311
// It is now fixed, so we simply set the fee to the expected value here.
312312
let mut config = test_default_channel_config();
313-
config.channel_options.forwarding_fee_base_msat = 196;
313+
config.own_channel_config.forwarding_fee_base_msat = 196;
314314

315315
let chanmon_cfgs = create_chanmon_cfgs(3);
316316
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);

lightning/src/ln/payment_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) {
448448
// Update the fee on the middle hop to ensure PaymentSent events have the correct (retried) fee
449449
// and not the original fee. We also update node[1]'s relevant config as
450450
// do_claim_payment_along_route expects us to never overpay.
451-
nodes[1].node.channel_state.lock().unwrap().by_id.get_mut(&chan_id_2).unwrap().config.forwarding_fee_base_msat += 100_000;
451+
nodes[1].node.channel_state.lock().unwrap().by_id.get_mut(&chan_id_2).unwrap().forwarding_fee_base_msat += 100_000;
452452
new_route.paths[0][0].fee_msat += 100_000;
453453

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

lightning/src/util/config.rs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,26 @@ pub struct ChannelHandshakeConfig {
4747
/// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
4848
/// by the protocol.
4949
pub our_htlc_minimum_msat: u64,
50+
/// Amount (in millionths of a satoshi) charged per satoshi for payments forwarded outbound
51+
/// over the channel.
52+
/// This may be allowed to change at runtime in a later update, however doing so must result in
53+
/// update messages sent to notify all nodes of our updated relay fee.
54+
///
55+
/// Default value: 0.
56+
pub forwarding_fee_proportional_millionths: u32,
57+
/// Amount (in milli-satoshi) charged for payments forwarded outbound over the channel, in
58+
/// excess of [`forwarding_fee_proportional_millionths`].
59+
/// This may be allowed to change at runtime in a later update, however doing so must result in
60+
/// update messages sent to notify all nodes of our updated relay fee.
61+
///
62+
/// The default value of a single satoshi roughly matches the market rate on many routing nodes
63+
/// as of July 2021. Adjusting it upwards or downwards may change whether nodes route through
64+
/// this node.
65+
///
66+
/// Default value: 1000.
67+
///
68+
/// [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
69+
pub forwarding_fee_base_msat: u32,
5070
}
5171

5272
impl Default for ChannelHandshakeConfig {
@@ -55,6 +75,8 @@ impl Default for ChannelHandshakeConfig {
5575
minimum_depth: 6,
5676
our_to_self_delay: BREAKDOWN_TIMEOUT,
5777
our_htlc_minimum_msat: 1,
78+
forwarding_fee_base_msat: 1000,
79+
forwarding_fee_proportional_millionths: 0,
5880
}
5981
}
6082
}
@@ -143,26 +165,6 @@ impl Default for ChannelHandshakeLimits {
143165
/// with our counterparty.
144166
#[derive(Copy, Clone, Debug)]
145167
pub struct ChannelConfig {
146-
/// Amount (in millionths of a satoshi) charged per satoshi for payments forwarded outbound
147-
/// over the channel.
148-
/// This may be allowed to change at runtime in a later update, however doing so must result in
149-
/// update messages sent to notify all nodes of our updated relay fee.
150-
///
151-
/// Default value: 0.
152-
pub forwarding_fee_proportional_millionths: u32,
153-
/// Amount (in milli-satoshi) charged for payments forwarded outbound over the channel, in
154-
/// excess of [`forwarding_fee_proportional_millionths`].
155-
/// This may be allowed to change at runtime in a later update, however doing so must result in
156-
/// update messages sent to notify all nodes of our updated relay fee.
157-
///
158-
/// The default value of a single satoshi roughly matches the market rate on many routing nodes
159-
/// as of July 2021. Adjusting it upwards or downwards may change whether nodes route through
160-
/// this node.
161-
///
162-
/// Default value: 1000.
163-
///
164-
/// [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
165-
pub forwarding_fee_base_msat: u32,
166168
/// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
167169
/// the channel this config applies to.
168170
///
@@ -252,8 +254,6 @@ impl Default for ChannelConfig {
252254
/// Provides sane defaults for most configurations (but with zero relay fees!).
253255
fn default() -> Self {
254256
ChannelConfig {
255-
forwarding_fee_proportional_millionths: 0,
256-
forwarding_fee_base_msat: 1000,
257257
cltv_expiry_delta: 6 * 12, // 6 blocks/hour * 12 hours
258258
announced_channel: false,
259259
commit_upfront_shutdown_pubkey: true,
@@ -264,13 +264,11 @@ impl Default for ChannelConfig {
264264
}
265265

266266
impl_writeable_tlv_based!(ChannelConfig, {
267-
(0, forwarding_fee_proportional_millionths, required),
268267
(1, max_dust_htlc_exposure_msat, (default_value, 5_000_000)),
269268
(2, cltv_expiry_delta, required),
270269
(3, force_close_avoidance_max_fee_satoshis, (default_value, 1000)),
271270
(4, announced_channel, required),
272271
(6, commit_upfront_shutdown_pubkey, required),
273-
(8, forwarding_fee_base_msat, required),
274272
});
275273

276274
/// Top-level config which holds ChannelHandshakeLimits and ChannelConfig.

0 commit comments

Comments
 (0)