Skip to content

Commit 741eac9

Browse files
committed
address code review issues
added fee_proportional_millionths and annouce_channel to config file
1 parent bfd0c2d commit 741eac9

File tree

6 files changed

+58
-24
lines changed

6 files changed

+58
-24
lines changed

fuzz/fuzz_targets/full_stack_target.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use lightning::util::events::{EventsProvider,Event};
2222
use lightning::util::reset_rng_state;
2323
use lightning::util::logger::Logger;
2424
use lightning::util::sha2::Sha256;
25+
use lightning::util::UserConfigurations;
2526

2627
mod utils;
2728

@@ -235,8 +236,8 @@ pub fn do_test(data: &[u8], logger: &Arc<Logger>) {
235236
let watch = Arc::new(ChainWatchInterfaceUtil::new(Network::Bitcoin, Arc::clone(&logger)));
236237
let broadcast = Arc::new(TestBroadcaster{});
237238
let monitor = channelmonitor::SimpleManyChannelMonitor::new(watch.clone(), broadcast.clone());
238-
239-
let channelmanager = ChannelManager::new(our_network_key, slice_to_be32(get_slice!(4)), get_slice!(1)[0] != 0, Network::Bitcoin, fee_est.clone(), monitor.clone(), watch.clone(), broadcast.clone(), Arc::clone(&logger)).unwrap();
239+
let config = UserConfigurations::new();
240+
let channelmanager = ChannelManager::new(our_network_key, slice_to_be32(get_slice!(4)), get_slice!(1)[0] != 0, Network::Bitcoin, fee_est.clone(), monitor.clone(), watch.clone(), broadcast.clone(), Arc::clone(&logger), config).unwrap();
240241
let router = Arc::new(Router::new(PublicKey::from_secret_key(&secp_ctx, &our_network_key), watch.clone(), Arc::clone(&logger)));
241242

242243
let peers = RefCell::new([false; 256]);

src/ln/channel.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,10 @@ const INITIAL_COMMITMENT_NUMBER: u64 = (1 << 48) - 1;
266266
// calling channel_id() before we're set up or things like get_outbound_funding_signed on an
267267
// inbound channel.
268268
pub struct Channel {
269-
270-
config : UserConfigurations,
269+
///TODO: split limits and runtime setting here
270+
/// channel limits cant change during channel existence
271+
/// but other settings can, but they need an update broadcast before they can change.
272+
config : UserConfigurations,
271273
user_id: u64,
272274

273275
channel_id: [u8; 32],
@@ -613,7 +615,7 @@ impl Channel {
613615

614616
let mut chan = Channel {
615617
user_id: user_id,
616-
config: (*configurations).clone(),
618+
config: (*configurations).clone(),
617619
channel_id: msg.temporary_channel_id,
618620
channel_state: (ChannelState::OurInitSent as u32) | (ChannelState::TheirInitSent as u32),
619621
channel_outbound: false,

src/ln/channelmanager.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ pub struct ChannelManager {
256256
tx_broadcaster: Arc<BroadcasterInterface>,
257257

258258
announce_channels_publicly: bool,
259-
fee_proportional_millionths: u32,
260259
latest_block_height: AtomicUsize,
261260
secp_ctx: Secp256k1<secp256k1::All>,
262261

@@ -307,22 +306,19 @@ pub struct ChannelDetails {
307306
impl ChannelManager {
308307
/// Constructs a new ChannelManager to hold several channels and route between them. This is
309308
/// the main "logic hub" for all channel-related actions, and implements ChannelMessageHandler.
310-
/// fee_proportional_millionths is an optional fee to charge any payments routed through us.
311309
/// Non-proportional fees are fixed according to our risk using the provided fee estimator.
312310
/// panics if channel_value_satoshis is >= `MAX_FUNDING_SATOSHIS`!
313-
pub fn new(our_network_key: SecretKey, fee_proportional_millionths: u32, announce_channels_publicly: bool, network: Network, feeest: Arc<FeeEstimator>, monitor: Arc<ManyChannelMonitor>, chain_monitor: Arc<ChainWatchInterface>, tx_broadcaster: Arc<BroadcasterInterface>, logger: Arc<Logger>) -> Result<Arc<ChannelManager>, secp256k1::Error> {
311+
pub fn new(our_network_key: SecretKey, fee_proportional_millionths: u32, announce_channels_publicly: bool, network: Network, feeest: Arc<FeeEstimator>, monitor: Arc<ManyChannelMonitor>, chain_monitor: Arc<ChainWatchInterface>, tx_broadcaster: Arc<BroadcasterInterface>, logger: Arc<Logger>, config : UserConfigurations) -> Result<Arc<ChannelManager>, secp256k1::Error> {
314312
let secp_ctx = Secp256k1::new();
315-
316313
let res = Arc::new(ChannelManager {
317-
configuration : UserConfigurations::new(),
314+
configuration : config,
318315
genesis_hash: genesis_block(network).header.bitcoin_hash(),
319316
fee_estimator: feeest.clone(),
320317
monitor: monitor.clone(),
321318
chain_monitor,
322319
tx_broadcaster,
323320

324-
announce_channels_publicly,
325-
fee_proportional_millionths,
321+
announce_channels_publicly,
326322
latest_block_height: AtomicUsize::new(0), //TODO: Get an init value (generally need to replay recent chain on chain_monitor registration)
327323
secp_ctx,
328324

@@ -917,7 +913,7 @@ impl ChannelManager {
917913
if !chan.is_live() {
918914
Some(("Forwarding channel is not in a ready state.", 0x1000 | 7, self.get_channel_update(chan).unwrap()))
919915
} else {
920-
let fee = amt_to_forward.checked_mul(self.fee_proportional_millionths as u64).and_then(|prop_fee| { (prop_fee / 1000000).checked_add(chan.get_our_fee_base_msat(&*self.fee_estimator) as u64) });
916+
let fee = amt_to_forward.checked_mul(self.configuration.channel_options.fee_proportional_millionths as u64).and_then(|prop_fee| { (prop_fee / 1000000).checked_add(chan.get_our_fee_base_msat(&*self.fee_estimator) as u64) });
921917
if fee.is_none() || msg.amount_msat < fee.unwrap() || (msg.amount_msat - fee.unwrap()) < *amt_to_forward {
922918
Some(("Prior hop has deviated from specified fees parameters or origin node has obsolete ones", 0x1000 | 12, self.get_channel_update(chan).unwrap()))
923919
} else {
@@ -954,7 +950,7 @@ impl ChannelManager {
954950
cltv_expiry_delta: CLTV_EXPIRY_DELTA,
955951
htlc_minimum_msat: chan.get_our_htlc_minimum_msat(),
956952
fee_base_msat: chan.get_our_fee_base_msat(&*self.fee_estimator),
957-
fee_proportional_millionths: self.fee_proportional_millionths,
953+
fee_proportional_millionths: self.configuration.channel_options.fee_proportional_millionths,
958954
excess_data: Vec::new(),
959955
};
960956

@@ -1486,7 +1482,8 @@ impl ChannelManager {
14861482
pending_events.push(events::Event::FundingGenerationReady {
14871483
temporary_channel_id: msg.temporary_channel_id,
14881484
channel_value_satoshis: value,
1489-
output_script: output_script, user_channel_id: user_id,
1485+
output_script: output_script,
1486+
user_channel_id: user_id,
14901487
});
14911488
Ok(())
14921489
}
@@ -2996,6 +2993,8 @@ mod tests {
29962993
}
29972994

29982995
fn create_network(node_count: usize) -> Vec<Node> {
2996+
use util::UserConfigurations;
2997+
29992998
let mut nodes = Vec::new();
30002999
let mut rng = thread_rng();
30013000
let secp_ctx = Secp256k1::new();
@@ -3014,7 +3013,8 @@ mod tests {
30143013
rng.fill_bytes(&mut key_slice);
30153014
SecretKey::from_slice(&secp_ctx, &key_slice).unwrap()
30163015
};
3017-
let node = ChannelManager::new(node_id.clone(), 0, true, Network::Testnet, feeest.clone(), chan_monitor.clone(), chain_monitor.clone(), tx_broadcaster.clone(), Arc::clone(&logger)).unwrap();
3016+
let config = UserConfigurations::new();
3017+
let node = ChannelManager::new(node_id.clone(), 0, true, Network::Testnet, feeest.clone(), chan_monitor.clone(), chain_monitor.clone(), tx_broadcaster.clone(), Arc::clone(&logger), config).unwrap();
30183018
let router = Router::new(PublicKey::from_secret_key(&secp_ctx, &node_id), chain_monitor.clone(), Arc::clone(&logger));
30193019
nodes.push(Node { chain_monitor, tx_broadcaster, chan_monitor, node, router,
30203020
network_payment_count: payment_count.clone(),

src/ln/router.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ impl std::fmt::Display for ChannelInfo {
7171
}
7272
}
7373

74-
75-
7674
struct NodeInfo {
7775
#[cfg(feature = "non_bitcoin_chain_hash_routing")]
7876
channels: Vec<(u64, Sha256dHash)>,

src/util/configurations.rs

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
1-
#[derive(Copy, Clone)]
1+
/// This is the main user configuration
2+
/// This struct should contain all user customizable options as this is passed to the channel to be accessed
3+
#[derive(Copy, Clone)]
24
pub struct UserConfigurations{
5+
/// optional user spesefied channel limits
6+
/// These should stay the same for a channel and cannot change during the life of a channel
37
pub channel_limits : ChannelLimits,
8+
/// Channel options
9+
pub channel_options : ChannelOptions,
410
}
511

612
impl UserConfigurations {
713
pub fn new() -> Self{
814
UserConfigurations {
915
channel_limits : ChannelLimits::new(),
16+
channel_options : ChannelOptions::new(),
1017
}
1118
}
1219
}
1320

21+
/// This struct contains all the optional bolt 2 channel limits.
22+
/// If the user wants to check a value, the value needs to be filled in, as by default they are not checked
1423
#[derive(Copy, Clone)]
15-
pub struct ChannelLimits
16-
{
24+
pub struct ChannelLimits{
25+
/// minimum allowed funding_satoshis
1726
pub funding_satoshis :u64,
27+
/// maximum allowed htlc_minimum_msat
1828
pub htlc_minimum_msat : u64,
29+
/// min allowed max_htlc_value_in_flight_msat
1930
pub max_htlc_value_in_flight_msat : u64,
31+
/// max allowed channel_reserve_satashis
2032
pub channel_reserve_satoshis : u64,
33+
/// min allowed max_accepted_htlcs
2134
pub max_accepted_htlcs : u16,
35+
/// min allowed dust_limit_satashis
2236
pub dust_limit_satoshis : u64,
2337
}
2438

2539
impl ChannelLimits {
26-
//creating max and min possible values because if they are not set, means we should not check them.
40+
//creating max and min possible values because if they are not set, means we should not check them.
2741
pub fn new() -> Self{
2842
ChannelLimits {
2943
funding_satoshis : 0,
@@ -34,4 +48,23 @@ impl ChannelLimits {
3448
dust_limit_satoshis : 0,
3549
}
3650
}
51+
}
52+
53+
/// This struct contains all the custom channel options.
54+
#[derive(Copy, Clone)]
55+
pub struct ChannelOptions{
56+
/// Amount (in millionths of a satoshi) channel will charge per transferred satoshi.
57+
pub fee_proportional_millionths : u32,
58+
///should the channel be annouced or not
59+
pub annouce_channel : bool,
60+
}
61+
impl ChannelOptions {
62+
/// creating a struct with values.
63+
/// fee_proportional_millionths should be changed afterwords
64+
pub fn new() -> Self{
65+
ChannelOptions {
66+
fee_proportional_millionths : 0,
67+
annouce_channel : true,
68+
}
69+
}
3770
}

src/util/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ pub use self::rng::reset_rng_state;
2727
#[cfg(test)]
2828
pub(crate) mod test_utils;
2929

30-
pub use self::configurations::{UserConfigurations, ChannelLimits};
31-
pub mod configurations;
30+
pub use self::configurations::UserConfigurations;
31+
pub mod configurations;

0 commit comments

Comments
 (0)