Skip to content

Commit 1c8acb8

Browse files
committed
refactor require announce and local announce of channels
1 parent 3f9dc5b commit 1c8acb8

File tree

5 files changed

+27
-21
lines changed

5 files changed

+27
-21
lines changed

fuzz/fuzz_targets/channel_target.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ pub fn do_test(data: &[u8]) {
195195
let chan_value = slice_to_be24(get_slice!(3));
196196
let push_msat = slice_to_be24(get_slice!(3));
197197
let mut config = UserConfigurations::new();
198-
config.channel_options.annouce_channel = (get_slice!(1)[0] == 0);
198+
config.channel_options.announced_channel = (get_slice!(1)[0] == 0);
199199
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) {
200200
Ok(chan) => chan,
201201
Err(_) => return,
@@ -222,8 +222,8 @@ pub fn do_test(data: &[u8]) {
222222
decode_msg!(msgs::OpenChannel, 2*32+6*8+4+2*2+6*33+1)
223223
};
224224
let mut chan_config = UserConfigurations::new();
225-
chan_config.channel_options.allow_annouce_channel = false;
226-
chan_config.channel_options.annouce_channel = get_slice!(1)[0] == 0;
225+
chan_config.channel_options.force_announced_channel_preference = false;
226+
chan_config.channel_options.announced_channel = get_slice!(1)[0] == 0;
227227
let mut chan = match Channel::new_from_req(&fee_est, chan_keys!(), their_pubkey, &open_chan, slice_to_be64(get_slice!(8)), Arc::clone(&logger),&chan_config) {
228228
Ok(chan) => chan,
229229
Err(_) => return,

fuzz/fuzz_targets/full_stack_target.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ pub fn do_test(data: &[u8], logger: &Arc<Logger>) {
238238
let monitor = channelmonitor::SimpleManyChannelMonitor::new(watch.clone(), broadcast.clone());
239239
let mut config = UserConfigurations::new();
240240
config.channel_options.fee_proportional_millionths = slice_to_be32(get_slice!(4));
241-
config.channel_options.annouce_channel = (get_slice!(1)[0] != 0);
241+
config.channel_options.announced_channel = (get_slice!(1)[0] != 0);
242242
let channelmanager = ChannelManager::new(our_network_key,Network::Bitcoin, fee_est.clone(), monitor.clone(), watch.clone(), broadcast.clone(), Arc::clone(&logger), config).unwrap();
243243
let router = Arc::new(Router::new(PublicKey::from_secret_key(&secp_ctx, &our_network_key), watch.clone(), Arc::clone(&logger)));
244244

src/ln/channel.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ impl Channel {
507507
return Err(HandleError{err: $msg, action: Some(msgs::ErrorAction::SendErrorMessage{ msg: msgs::ErrorMessage { channel_id: msg.temporary_channel_id, data: $msg.to_string() }})});
508508
}
509509
}
510+
let mut local_config = (*configurations).clone();
510511

511512
// Check sanity of message fields:
512513
if msg.funding_satoshis >= MAX_FUNDING_SATOSHIS {
@@ -564,12 +565,16 @@ impl Channel {
564565
// Convert things into internal flags and prep our state:
565566

566567
let their_announce = if (msg.channel_flags & 1) == 1 { true } else { false };
567-
if configurations.channel_options.annouce_channel && !their_announce {
568-
return_error_message!("Peer tried to open unannounced channel, but we require public ones");
569-
}
570-
if !configurations.channel_options.allow_annouce_channel && their_announce {
571-
return_error_message!("Peer tried to open announced channel, but we require private ones");
568+
if local_config.channel_options.force_announced_channel_preference{
569+
if local_config.channel_options.announced_channel && !their_announce {
570+
return_error_message!("Peer tried to open unannounced channel, but we require public ones");
571+
}
572+
if !local_config.channel_options.announced_channel && their_announce {
573+
return_error_message!("Peer tried to open announced channel, but we require private ones");
574+
}
572575
}
576+
//we either accept their preference or the preferences match
577+
local_config.channel_options.announced_channel = their_announce;
573578

574579
let background_feerate = fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::Background);
575580

@@ -610,7 +615,7 @@ impl Channel {
610615

611616
let mut chan = Channel {
612617
user_id: user_id,
613-
config: (*configurations).clone(),
618+
config: local_config,
614619
channel_id: msg.temporary_channel_id,
615620
channel_state: (ChannelState::OurInitSent as u32) | (ChannelState::TheirInitSent as u32),
616621
channel_outbound: false,
@@ -2251,7 +2256,7 @@ impl Channel {
22512256
}
22522257

22532258
pub fn should_announce(&self) -> bool {
2254-
self.config.channel_options.annouce_channel
2259+
self.config.channel_options.announced_channel
22552260
}
22562261

22572262
/// Gets the fee we'd want to charge for adding an HTLC output to this Channel
@@ -2437,7 +2442,7 @@ impl Channel {
24372442
delayed_payment_basepoint: PublicKey::from_secret_key(&self.secp_ctx, &self.local_keys.delayed_payment_base_key),
24382443
htlc_basepoint: PublicKey::from_secret_key(&self.secp_ctx, &self.local_keys.htlc_base_key),
24392444
first_per_commitment_point: PublicKey::from_secret_key(&self.secp_ctx, &local_commitment_secret),
2440-
channel_flags: if self.config.channel_options.allow_annouce_channel {1} else {0},
2445+
channel_flags: if self.config.channel_options.announced_channel {1} else {0},
24412446
shutdown_scriptpubkey: None,
24422447
}
24432448
}
@@ -2541,7 +2546,7 @@ impl Channel {
25412546
/// Note that the "channel must be funded" requirement is stricter than BOLT 7 requires - see
25422547
/// https://github.com/lightningnetwork/lightning-rfc/issues/468
25432548
pub fn get_channel_announcement(&self, our_node_id: PublicKey, chain_hash: Sha256dHash) -> Result<(msgs::UnsignedChannelAnnouncement, Signature), HandleError> {
2544-
if !self.config.channel_options.allow_annouce_channel {
2549+
if !self.config.channel_options.force_announced_channel_preference {
25452550
return Err(HandleError{err: "Channel is not available for public announcements", action: Some(msgs::ErrorAction::IgnoreError)});
25462551
}
25472552
if self.channel_state & (ChannelState::ChannelFunded as u32) == 0 {
@@ -2904,7 +2909,7 @@ mod tests {
29042909

29052910
let their_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap());
29062911
let mut config = UserConfigurations::new();
2907-
config.channel_options.annouce_channel= false;
2912+
config.channel_options.announced_channel= false;
29082913
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
29092914
chan.their_to_self_delay = 144;
29102915
chan.our_dust_limit_satoshis = 546;

src/ln/channelmanager.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3012,8 +3012,9 @@ mod tests {
30123012
SecretKey::from_slice(&secp_ctx, &key_slice).unwrap()
30133013
};
30143014
let mut config = UserConfigurations::new();
3015-
config.channel_options.annouce_channel = true;
3015+
config.channel_options.announced_channel = true;
30163016
config.channel_options.fee_proportional_millionths = 0;
3017+
config.channel_options.force_announced_channel_preference = true;
30173018
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();
30183019
let router = Router::new(PublicKey::from_secret_key(&secp_ctx, &node_id), chain_monitor.clone(), Arc::clone(&logger));
30193020
nodes.push(Node { chain_monitor, tx_broadcaster, chan_monitor, node, router,

src/util/configurations.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,19 @@ impl ChannelLimits {
5858
pub struct ChannelOptions{
5959
/// Amount (in millionths of a satoshi) channel will charge per transferred satoshi.
6060
pub fee_proportional_millionths : u32,
61-
///should we require the channel be annouced or not
62-
pub annouce_channel : bool,
63-
///do we allow incomming channel to be announced
64-
pub allow_annouce_channel : bool,
61+
///Is this channel an annouced channe;
62+
pub announced_channel : bool,
63+
///do we force the incomming channel to match our announced channel preference
64+
pub force_announced_channel_preference : bool,
6565
}
6666
impl ChannelOptions {
6767
/// creating a struct with values.
6868
/// fee_proportional_millionths should be changed afterwords
6969
pub fn new() -> Self{
7070
ChannelOptions {
7171
fee_proportional_millionths : 0,
72-
annouce_channel : true,
73-
allow_annouce_channel : true,
72+
announced_channel : true,
73+
force_announced_channel_preference : false,
7474
}
7575
}
7676
}

0 commit comments

Comments
 (0)