Skip to content

Commit c75d07f

Browse files
authored
Merge pull request #93 from TheBlueMatt/2018-07-announce-bug
Properly calculate Channel::announce_publicly
2 parents 731aeab + 78023d6 commit c75d07f

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

fuzz/fuzz_targets/channel_target.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ pub fn do_test(data: &[u8]) {
213213
} else {
214214
decode_msg!(msgs::OpenChannel, 2*32+6*8+4+2*2+6*33+1)
215215
};
216-
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) {
216+
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) {
217217
Ok(chan) => chan,
218218
Err(_) => return,
219219
};

src/ln/channel.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ impl Channel {
445445
/// Assumes chain_hash has already been checked and corresponds with what we expect!
446446
/// Generally prefers to take the DisconnectPeer action on failure, as a notice to the sender
447447
/// that we're rejecting the new channel.
448-
pub fn new_from_req(fee_estimator: &FeeEstimator, chan_keys: ChannelKeys, their_node_id: PublicKey, msg: &msgs::OpenChannel, user_id: u64, announce_publicly: bool) -> Result<Channel, HandleError> {
448+
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) -> Result<Channel, HandleError> {
449449
// Check sanity of message fields:
450450
if msg.funding_satoshis >= MAX_FUNDING_SATOSHIS {
451451
return Err(HandleError{err: "funding value > 2^24", action: Some(msgs::ErrorAction::DisconnectPeer{ msg: None })});
@@ -476,6 +476,12 @@ impl Channel {
476476
// Convert things into internal flags and prep our state:
477477

478478
let their_announce = if (msg.channel_flags & 1) == 1 { true } else { false };
479+
if require_announce && !their_announce {
480+
return Err(HandleError{err: "Peer tried to open unannounced channel, but we require public ones", action: Some(msgs::ErrorAction::IgnoreError) });
481+
}
482+
if !allow_announce && their_announce {
483+
return Err(HandleError{err: "Peer tried to open announced channel, but we require private ones", action: Some(msgs::ErrorAction::IgnoreError) });
484+
}
479485

480486
let background_feerate = fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::Background);
481487

@@ -496,7 +502,7 @@ impl Channel {
496502
channel_state: (ChannelState::OurInitSent as u32) | (ChannelState::TheirInitSent as u32),
497503
channel_outbound: false,
498504
secp_ctx: secp_ctx,
499-
announce_publicly: their_announce && announce_publicly,
505+
announce_publicly: their_announce,
500506

501507
local_keys: chan_keys,
502508
cur_local_commitment_transaction_number: (1 << 48) - 1,

src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ impl ChannelMessageHandler for ChannelManager {
11851185
}
11861186
};
11871187

1188-
let channel = Channel::new_from_req(&*self.fee_estimator, chan_keys, their_node_id.clone(), msg, 0, self.announce_channels_publicly)?;
1188+
let channel = Channel::new_from_req(&*self.fee_estimator, chan_keys, their_node_id.clone(), msg, 0, false, self.announce_channels_publicly)?;
11891189
let accept_msg = channel.get_accept_channel()?;
11901190
channel_state.by_id.insert(channel.channel_id(), channel);
11911191
Ok(accept_msg)

src/ln/router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ impl Router {
433433
($directional_info.fee_base_msat as u64).checked_add(part / 1000000) })
434434
{
435435
let mut total_fee = $starting_fee_msat as u64;
436-
let mut hm_entry = dist.entry(&$directional_info.src_node_id);
436+
let hm_entry = dist.entry(&$directional_info.src_node_id);
437437
let old_entry = hm_entry.or_insert_with(|| {
438438
let node = network.nodes.get(&$directional_info.src_node_id).unwrap();
439439
(u64::max_value(),

0 commit comments

Comments
 (0)