Skip to content

Commit

Permalink
Conditionally advertise onion msgs in node features in ChannelManager
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinewallace committed Sep 2, 2022
1 parent 532f7e0 commit fd6dd31
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2973,8 +2973,10 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
// addresses be sorted for future compatibility.
addresses.sort_by_key(|addr| addr.get_id());

let node_features = if self.advertise_onion_message_support.load(Ordering::Acquire) {
NodeFeatures::known() } else { NodeFeatures::known_without_onion_messages() };
let announcement = msgs::UnsignedNodeAnnouncement {
features: NodeFeatures::known(),
features: node_features,
timestamp: self.last_node_announcement_serial.fetch_add(1, Ordering::AcqRel) as u32,
node_id: self.get_our_node_id(),
rgb, alias, addresses,
Expand Down
10 changes: 10 additions & 0 deletions lightning/src/ln/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,14 @@ impl InitFeatures {
}
}

impl NodeFeatures {
pub(crate) fn known_without_onion_messages() -> Self {
let mut features = Self::known();
features.flags[4] &= 0b00111111;
features
}
}

impl InvoiceFeatures {
/// Converts `InvoiceFeatures` to `Features<C>`. Only known `InvoiceFeatures` relevant to
/// context `C` are included in the result.
Expand Down Expand Up @@ -913,6 +921,8 @@ mod tests {
assert!(NodeFeatures::known().supports_onion_messages());
assert!(!InitFeatures::known().requires_onion_messages());
assert!(!NodeFeatures::known().requires_onion_messages());
assert!(!NodeFeatures::known_without_onion_messages().supports_onion_messages());
assert!(!NodeFeatures::known_without_onion_messages().requires_onion_messages());

assert!(InitFeatures::known().supports_zero_conf());
assert!(!InitFeatures::known().requires_zero_conf());
Expand Down

0 comments on commit fd6dd31

Please sign in to comment.