Skip to content

Commit ac0ccf2

Browse files
committed
refactor require announce and local announce of channels
1 parent 3522a36 commit ac0ccf2

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
@@ -506,6 +506,7 @@ impl Channel {
506506
return Err(HandleError{err: $msg, action: Some(msgs::ErrorAction::SendErrorMessage{ msg: msgs::ErrorMessage { channel_id: msg.temporary_channel_id, data: $msg.to_string() }})});
507507
}
508508
}
509+
let mut local_config = (*configurations).clone();
509510

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

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

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

@@ -609,7 +614,7 @@ impl Channel {
609614

610615
let mut chan = Channel {
611616
user_id: user_id,
612-
config: (*configurations).clone(),
617+
config: local_config,
613618
channel_id: msg.temporary_channel_id,
614619
channel_state: (ChannelState::OurInitSent as u32) | (ChannelState::TheirInitSent as u32),
615620
channel_outbound: false,
@@ -2250,7 +2255,7 @@ impl Channel {
22502255
}
22512256

22522257
pub fn should_announce(&self) -> bool {
2253-
self.config.channel_options.annouce_channel
2258+
self.config.channel_options.announced_channel
22542259
}
22552260

22562261
/// Gets the fee we'd want to charge for adding an HTLC output to this Channel
@@ -2436,7 +2441,7 @@ impl Channel {
24362441
delayed_payment_basepoint: PublicKey::from_secret_key(&self.secp_ctx, &self.local_keys.delayed_payment_base_key),
24372442
htlc_basepoint: PublicKey::from_secret_key(&self.secp_ctx, &self.local_keys.htlc_base_key),
24382443
first_per_commitment_point: PublicKey::from_secret_key(&self.secp_ctx, &local_commitment_secret),
2439-
channel_flags: if self.config.channel_options.allow_annouce_channel {1} else {0},
2444+
channel_flags: if self.config.channel_options.announced_channel {1} else {0},
24402445
shutdown_scriptpubkey: None,
24412446
}
24422447
}
@@ -2540,7 +2545,7 @@ impl Channel {
25402545
/// Note that the "channel must be funded" requirement is stricter than BOLT 7 requires - see
25412546
/// https://github.com/lightningnetwork/lightning-rfc/issues/468
25422547
pub fn get_channel_announcement(&self, our_node_id: PublicKey, chain_hash: Sha256dHash) -> Result<(msgs::UnsignedChannelAnnouncement, Signature), HandleError> {
2543-
if !self.config.channel_options.allow_annouce_channel {
2548+
if !self.config.channel_options.force_announced_channel_preference {
25442549
return Err(HandleError{err: "Channel is not available for public announcements", action: Some(msgs::ErrorAction::IgnoreError)});
25452550
}
25462551
if self.channel_state & (ChannelState::ChannelFunded as u32) == 0 {
@@ -2903,7 +2908,7 @@ mod tests {
29032908

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

src/ln/channelmanager.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3009,8 +3009,9 @@ mod tests {
30093009
SecretKey::from_slice(&secp_ctx, &key_slice).unwrap()
30103010
};
30113011
let mut config = UserConfigurations::new();
3012-
config.channel_options.annouce_channel = true;
3012+
config.channel_options.announced_channel = true;
30133013
config.channel_options.fee_proportional_millionths = 0;
3014+
config.channel_options.force_announced_channel_preference = true;
30143015
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();
30153016
let router = Router::new(PublicKey::from_secret_key(&secp_ctx, &node_id), chain_monitor.clone(), Arc::clone(&logger));
30163017
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)