Skip to content

Commit ff2acb6

Browse files
committed
add announce to config
1 parent 741eac9 commit ff2acb6

File tree

5 files changed

+37
-29
lines changed

5 files changed

+37
-29
lines changed

fuzz/fuzz_targets/channel_target.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,10 @@ pub fn do_test(data: &[u8]) {
193193

194194
let mut channel = if get_slice!(1)[0] != 0 {
195195
let chan_value = slice_to_be24(get_slice!(3));
196-
197-
let mut chan = match Channel::new_outbound(&fee_est, chan_keys!(), their_pubkey, chan_value, slice_to_be24(get_slice!(3)), get_slice!(1)[0] == 0, slice_to_be64(get_slice!(8)), Arc::clone(&logger), &UserConfigurations::new()) {
196+
let push_msat = slice_to_be24(get_slice!(3));
197+
let mut config = UserConfigurations::new();
198+
config.channel_options.annouce_channel = (get_slice!(1)[0] == 0);
199+
let mut chan = match Channel::new_outbound(&fee_est, chan_keys!(), their_pubkey, chan_value, push_msat, slice_to_be64(get_slice!(8)), Arc::clone(&logger), &config) {
198200
Ok(chan) => chan,
199201
Err(_) => return,
200202
};
@@ -219,7 +221,9 @@ pub fn do_test(data: &[u8]) {
219221
} else {
220222
decode_msg!(msgs::OpenChannel, 2*32+6*8+4+2*2+6*33+1)
221223
};
222-
let mut chan = match Channel::new_from_req(&fee_est, chan_keys!(), their_pubkey, &open_chan, slice_to_be64(get_slice!(8)), false, get_slice!(1)[0] == 0, Arc::clone(&logger),&UserConfigurations::new()) {
224+
let mut chan_config = UserConfigurations::new();
225+
chan_config.channel_options.annouce_channel = false;
226+
let mut chan = match Channel::new_from_req(&fee_est, chan_keys!(), their_pubkey, &open_chan, slice_to_be64(get_slice!(8)), get_slice!(1)[0] == 0, Arc::clone(&logger),&chan_config) {
223227
Ok(chan) => chan,
224228
Err(_) => return,
225229
};

fuzz/fuzz_targets/full_stack_target.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,10 @@ pub fn do_test(data: &[u8], logger: &Arc<Logger>) {
236236
let watch = Arc::new(ChainWatchInterfaceUtil::new(Network::Bitcoin, Arc::clone(&logger)));
237237
let broadcast = Arc::new(TestBroadcaster{});
238238
let monitor = channelmonitor::SimpleManyChannelMonitor::new(watch.clone(), broadcast.clone());
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();
239+
let mut config = UserConfigurations::new();
240+
config.channel_options.fee_proportional_millionths = slice_to_be32(get_slice!(4));
241+
config.channel_options.annouce_channel = (get_slice!(1)[0] != 0);
242+
let channelmanager = ChannelManager::new(our_network_key,Network::Bitcoin, fee_est.clone(), monitor.clone(), watch.clone(), broadcast.clone(), Arc::clone(&logger), config).unwrap();
241243
let router = Arc::new(Router::new(PublicKey::from_secret_key(&secp_ctx, &our_network_key), watch.clone(), Arc::clone(&logger)));
242244

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

src/ln/channel.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ pub struct Channel {
276276
channel_state: u32,
277277
channel_outbound: bool,
278278
secp_ctx: Secp256k1<secp256k1::All>,
279-
announce_publicly: bool,
280279
channel_value_satoshis: u64,
281280

282281
local_keys: ChannelKeys,
@@ -409,7 +408,7 @@ impl Channel {
409408
}
410409

411410
// Constructors:
412-
pub fn new_outbound(fee_estimator: &FeeEstimator, chan_keys: ChannelKeys, their_node_id: PublicKey, channel_value_satoshis: u64, push_msat: u64, announce_publicly: bool, user_id: u64, logger: Arc<Logger>, configurations: &UserConfigurations) -> Result<Channel, APIError> {
411+
pub fn new_outbound(fee_estimator: &FeeEstimator, chan_keys: ChannelKeys, their_node_id: PublicKey, channel_value_satoshis: u64, push_msat: u64, user_id: u64, logger: Arc<Logger>, configurations: &UserConfigurations) -> Result<Channel, APIError> {
413412
if channel_value_satoshis >= MAX_FUNDING_SATOSHIS {
414413
return Err(APIError::APIMisuseError{err: "funding value > 2^24"});
415414
}
@@ -441,7 +440,6 @@ impl Channel {
441440
channel_state: ChannelState::OurInitSent as u32,
442441
channel_outbound: true,
443442
secp_ctx: secp_ctx,
444-
announce_publicly: announce_publicly,
445443
channel_value_satoshis: channel_value_satoshis,
446444

447445
local_keys: chan_keys,
@@ -506,7 +504,7 @@ impl Channel {
506504
/// Assumes chain_hash has already been checked and corresponds with what we expect!
507505
/// Generally prefers to take the DisconnectPeer action on failure, as a notice to the sender
508506
/// that we're rejecting the new channel.
509-
pub fn new_from_req(fee_estimator: &FeeEstimator, chan_keys: ChannelKeys, their_node_id: PublicKey, msg: &msgs::OpenChannel, user_id: u64, require_announce: bool, allow_announce: bool, logger: Arc<Logger>, configurations : &UserConfigurations) -> Result<Channel, HandleError> {
507+
pub fn new_from_req(fee_estimator: &FeeEstimator, chan_keys: ChannelKeys, their_node_id: PublicKey, msg: &msgs::OpenChannel, user_id: u64, logger: Arc<Logger>, configurations : &UserConfigurations) -> Result<Channel, HandleError> {
510508
macro_rules! return_error_message {
511509
( $msg: expr ) => {
512510
return Err(HandleError{err: $msg, action: Some(msgs::ErrorAction::SendErrorMessage{ msg: msgs::ErrorMessage { channel_id: msg.temporary_channel_id, data: $msg.to_string() }})});
@@ -569,10 +567,10 @@ impl Channel {
569567
// Convert things into internal flags and prep our state:
570568

571569
let their_announce = if (msg.channel_flags & 1) == 1 { true } else { false };
572-
if require_announce && !their_announce {
570+
if configurations.channel_options.annouce_channel && !their_announce {
573571
return_error_message!("Peer tried to open unannounced channel, but we require public ones");
574572
}
575-
if !allow_announce && their_announce {
573+
if !configurations.channel_options.allow_annouce_channel && their_announce {
576574
return_error_message!("Peer tried to open announced channel, but we require private ones");
577575
}
578576

@@ -620,7 +618,6 @@ impl Channel {
620618
channel_state: (ChannelState::OurInitSent as u32) | (ChannelState::TheirInitSent as u32),
621619
channel_outbound: false,
622620
secp_ctx: secp_ctx,
623-
announce_publicly: their_announce,
624621

625622
local_keys: chan_keys,
626623
cur_local_commitment_transaction_number: INITIAL_COMMITMENT_NUMBER,
@@ -2254,7 +2251,7 @@ impl Channel {
22542251
}
22552252

22562253
pub fn should_announce(&self) -> bool {
2257-
self.announce_publicly
2254+
self.config.channel_options.annouce_channel
22582255
}
22592256

22602257
/// Gets the fee we'd want to charge for adding an HTLC output to this Channel
@@ -2440,7 +2437,7 @@ impl Channel {
24402437
delayed_payment_basepoint: PublicKey::from_secret_key(&self.secp_ctx, &self.local_keys.delayed_payment_base_key),
24412438
htlc_basepoint: PublicKey::from_secret_key(&self.secp_ctx, &self.local_keys.htlc_base_key),
24422439
first_per_commitment_point: PublicKey::from_secret_key(&self.secp_ctx, &local_commitment_secret),
2443-
channel_flags: if self.announce_publicly {1} else {0},
2440+
channel_flags: if self.config.channel_options.allow_annouce_channel {1} else {0},
24442441
shutdown_scriptpubkey: None,
24452442
}
24462443
}
@@ -2544,7 +2541,7 @@ impl Channel {
25442541
/// Note that the "channel must be funded" requirement is stricter than BOLT 7 requires - see
25452542
/// https://github.com/lightningnetwork/lightning-rfc/issues/468
25462543
pub fn get_channel_announcement(&self, our_node_id: PublicKey, chain_hash: Sha256dHash) -> Result<(msgs::UnsignedChannelAnnouncement, Signature), HandleError> {
2547-
if !self.announce_publicly {
2544+
if !self.self.config.channel_options.allow_annouce_channel {
25482545
return Err(HandleError{err: "Channel is not available for public announcements", action: Some(msgs::ErrorAction::IgnoreError)});
25492546
}
25502547
if self.channel_state & (ChannelState::ChannelFunded as u32) == 0 {
@@ -2906,7 +2903,9 @@ mod tests {
29062903
hex::decode("023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb").unwrap()[..]);
29072904

29082905
let their_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap());
2909-
let mut chan = Channel::new_outbound(&feeest, chan_keys, their_node_id, 10000000, 100000, false, 42, Arc::clone(&logger), &UserConfigurations::new()).unwrap(); // Nothing uses their network key in this test
2906+
let mut config = UserConfigurations::new();
2907+
config.channel_options.annouce_channel= false;
2908+
let mut chan = Channel::new_outbound(&feeest, chan_keys, their_node_id, 10000000, 100000, 42, Arc::clone(&logger), &config).unwrap(); // Nothing uses their network key in this test
29102909
chan.their_to_self_delay = 144;
29112910
chan.our_dust_limit_satoshis = 546;
29122911

src/ln/channelmanager.rs

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

258-
announce_channels_publicly: bool,
259258
latest_block_height: AtomicUsize,
260259
secp_ctx: Secp256k1<secp256k1::All>,
261260

@@ -308,7 +307,7 @@ impl ChannelManager {
308307
/// the main "logic hub" for all channel-related actions, and implements ChannelMessageHandler.
309308
/// Non-proportional fees are fixed according to our risk using the provided fee estimator.
310309
/// panics if channel_value_satoshis is >= `MAX_FUNDING_SATOSHIS`!
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> {
310+
pub fn new(our_network_key: SecretKey, 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> {
312311
let secp_ctx = Secp256k1::new();
313312
let res = Arc::new(ChannelManager {
314313
configuration : config,
@@ -317,8 +316,7 @@ impl ChannelManager {
317316
monitor: monitor.clone(),
318317
chain_monitor,
319318
tx_broadcaster,
320-
321-
announce_channels_publicly,
319+
322320
latest_block_height: AtomicUsize::new(0), //TODO: Get an init value (generally need to replay recent chain on chain_monitor registration)
323321
secp_ctx,
324322

@@ -369,7 +367,7 @@ impl ChannelManager {
369367
}
370368
};
371369

372-
let channel = Channel::new_outbound(&*self.fee_estimator, chan_keys, their_network_key, channel_value_satoshis, push_msat, self.announce_channels_publicly, user_id, Arc::clone(&self.logger), &self.configuration)?;
370+
let channel = Channel::new_outbound(&*self.fee_estimator, chan_keys, their_network_key, channel_value_satoshis, push_msat, user_id, Arc::clone(&self.logger), &self.configuration)?;
373371
let res = channel.get_open_channel(self.genesis_hash.clone(), &*self.fee_estimator);
374372
let mut channel_state = self.channel_state.lock().unwrap();
375373
match channel_state.by_id.insert(channel.channel_id(), channel) {
@@ -1456,7 +1454,7 @@ impl ChannelManager {
14561454
}
14571455
};
14581456

1459-
let channel = Channel::new_from_req(&*self.fee_estimator, chan_keys, their_node_id.clone(), msg, 0, false, self.announce_channels_publicly, Arc::clone(&self.logger), &self.configuration).map_err(|e| MsgHandleErrInternal::from_no_close(e))?;
1457+
let channel = Channel::new_from_req(&*self.fee_estimator, chan_keys, their_node_id.clone(), msg, 0, Arc::clone(&self.logger), &self.configuration).map_err(|e| MsgHandleErrInternal::from_no_close(e))?;
14601458
let accept_msg = channel.get_accept_channel();
14611459
channel_state.by_id.insert(channel.channel_id(), channel);
14621460
Ok(accept_msg)
@@ -2994,7 +2992,7 @@ mod tests {
29942992

29952993
fn create_network(node_count: usize) -> Vec<Node> {
29962994
use util::UserConfigurations;
2997-
2995+
29982996
let mut nodes = Vec::new();
29992997
let mut rng = thread_rng();
30002998
let secp_ctx = Secp256k1::new();
@@ -3013,8 +3011,10 @@ mod tests {
30133011
rng.fill_bytes(&mut key_slice);
30143012
SecretKey::from_slice(&secp_ctx, &key_slice).unwrap()
30153013
};
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();
3014+
let mut config = UserConfigurations::new();
3015+
config.channel_options.annouce_channel = true;
3016+
config.channel_options.fee_proportional_millionths = 0;
3017+
let node = ChannelManager::new(node_id.clone(), 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/util/configurations.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// This is the main user configuration
22
/// This struct should contain all user customizable options as this is passed to the channel to be accessed
3-
#[derive(Copy, Clone)]
3+
#[derive(Copy, Clone, Debug)]
44
pub struct UserConfigurations{
55
/// optional user spesefied channel limits
66
/// These should stay the same for a channel and cannot change during the life of a channel
@@ -20,7 +20,7 @@ impl UserConfigurations {
2020

2121
/// This struct contains all the optional bolt 2 channel limits.
2222
/// If the user wants to check a value, the value needs to be filled in, as by default they are not checked
23-
#[derive(Copy, Clone)]
23+
#[derive(Copy, Clone, Debug)]
2424
pub struct ChannelLimits{
2525
/// minimum allowed funding_satoshis
2626
pub funding_satoshis :u64,
@@ -51,12 +51,14 @@ impl ChannelLimits {
5151
}
5252

5353
/// This struct contains all the custom channel options.
54-
#[derive(Copy, Clone)]
54+
#[derive(Copy, Clone, Debug)]
5555
pub struct ChannelOptions{
5656
/// Amount (in millionths of a satoshi) channel will charge per transferred satoshi.
5757
pub fee_proportional_millionths : u32,
58-
///should the channel be annouced or not
58+
///should we require the channel be annouced or not
5959
pub annouce_channel : bool,
60+
///do we allow incomming channel to be announced
61+
pub allow_annouce_channel : bool,
6062
}
6163
impl ChannelOptions {
6264
/// creating a struct with values.
@@ -65,6 +67,7 @@ impl ChannelOptions {
6567
ChannelOptions {
6668
fee_proportional_millionths : 0,
6769
annouce_channel : true,
70+
allow_annouce_channel : true,
6871
}
6972
}
7073
}

0 commit comments

Comments
 (0)