Skip to content

Commit

Permalink
f use member var for features
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinewallace committed Sep 6, 2022
1 parent 98ccbcc commit ee576ca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
6 changes: 0 additions & 6 deletions lightning/src/ln/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,12 +548,6 @@ impl InitFeatures {
pub(crate) fn to_context<C: sealed::Context>(&self) -> Features<C> {
self.to_context_internal()
}

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

impl InvoiceFeatures {
Expand Down
21 changes: 13 additions & 8 deletions lightning/src/ln/peer_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ pub struct PeerManager<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: D
/// when an event process call is waiting.
blocked_event_processors: AtomicBool,
our_node_secret: SecretKey,
our_features: InitFeatures,
ephemeral_key_midstate: Sha256Engine,
custom_message_handler: CMH,

Expand Down Expand Up @@ -642,16 +643,18 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
let ephemeral_hash = Sha256::from_engine(ephemeral_key_midstate.clone()).into_inner();
secp_ctx.seeded_randomize(&ephemeral_hash);

if message_handler.onion_message_handler.supports_onion_message_forwarding() {
let our_features = if message_handler.onion_message_handler.supports_onion_message_forwarding() {
message_handler.chan_handler.advertise_onion_message_support();
}
InitFeatures::known()
} else { InitFeatures::known().clear_onion_messages() };
PeerManager {
message_handler,
peers: FairRwLock::new(HashMap::new()),
node_id_to_descriptor: Mutex::new(HashMap::new()),
event_processing_lock: Mutex::new(()),
blocked_event_processors: AtomicBool::new(false),
our_node_secret,
our_features,
ephemeral_key_midstate,
peer_counter: AtomicCounter::new(),
logger,
Expand Down Expand Up @@ -1033,9 +1036,10 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM

peer.their_node_id = Some(their_node_id);
insert_node_id!();
let features = if self.message_handler.onion_message_handler.supports_onion_message_forwarding()
{ InitFeatures::known() } else { InitFeatures::known_without_onion_messages() };
let resp = msgs::Init { features, remote_network_address: filter_addresses(peer.their_net_address.clone()) };
let resp = msgs::Init {
features: self.our_features.clone(),
remote_network_address: filter_addresses(peer.their_net_address.clone())
};
self.enqueue_message(peer, &resp);
peer.awaiting_pong_timer_tick_intervals = 0;
},
Expand All @@ -1046,9 +1050,10 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
peer.pending_read_is_header = true;
peer.their_node_id = Some(their_node_id);
insert_node_id!();
let features = if self.message_handler.onion_message_handler.supports_onion_message_forwarding()
{ InitFeatures::known() } else { InitFeatures::known_without_onion_messages() };
let resp = msgs::Init { features, remote_network_address: filter_addresses(peer.their_net_address.clone()) };
let resp = msgs::Init {
features: self.our_features.clone(),
remote_network_address: filter_addresses(peer.their_net_address.clone())
};
self.enqueue_message(peer, &resp);
peer.awaiting_pong_timer_tick_intervals = 0;
},
Expand Down

0 comments on commit ee576ca

Please sign in to comment.