Skip to content

Commit ee576ca

Browse files
f use member var for features
1 parent 98ccbcc commit ee576ca

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

lightning/src/ln/features.rs

-6
Original file line numberDiff line numberDiff line change
@@ -548,12 +548,6 @@ impl InitFeatures {
548548
pub(crate) fn to_context<C: sealed::Context>(&self) -> Features<C> {
549549
self.to_context_internal()
550550
}
551-
552-
pub(crate) fn known_without_onion_messages() -> Self {
553-
let mut features = Self::known();
554-
features.flags[4] &= 0b00111111;
555-
features
556-
}
557551
}
558552

559553
impl InvoiceFeatures {

lightning/src/ln/peer_handler.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ pub struct PeerManager<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: D
508508
/// when an event process call is waiting.
509509
blocked_event_processors: AtomicBool,
510510
our_node_secret: SecretKey,
511+
our_features: InitFeatures,
511512
ephemeral_key_midstate: Sha256Engine,
512513
custom_message_handler: CMH,
513514

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

645-
if message_handler.onion_message_handler.supports_onion_message_forwarding() {
646+
let our_features = if message_handler.onion_message_handler.supports_onion_message_forwarding() {
646647
message_handler.chan_handler.advertise_onion_message_support();
647-
}
648+
InitFeatures::known()
649+
} else { InitFeatures::known().clear_onion_messages() };
648650
PeerManager {
649651
message_handler,
650652
peers: FairRwLock::new(HashMap::new()),
651653
node_id_to_descriptor: Mutex::new(HashMap::new()),
652654
event_processing_lock: Mutex::new(()),
653655
blocked_event_processors: AtomicBool::new(false),
654656
our_node_secret,
657+
our_features,
655658
ephemeral_key_midstate,
656659
peer_counter: AtomicCounter::new(),
657660
logger,
@@ -1033,9 +1036,10 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
10331036

10341037
peer.their_node_id = Some(their_node_id);
10351038
insert_node_id!();
1036-
let features = if self.message_handler.onion_message_handler.supports_onion_message_forwarding()
1037-
{ InitFeatures::known() } else { InitFeatures::known_without_onion_messages() };
1038-
let resp = msgs::Init { features, remote_network_address: filter_addresses(peer.their_net_address.clone()) };
1039+
let resp = msgs::Init {
1040+
features: self.our_features.clone(),
1041+
remote_network_address: filter_addresses(peer.their_net_address.clone())
1042+
};
10391043
self.enqueue_message(peer, &resp);
10401044
peer.awaiting_pong_timer_tick_intervals = 0;
10411045
},
@@ -1046,9 +1050,10 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
10461050
peer.pending_read_is_header = true;
10471051
peer.their_node_id = Some(their_node_id);
10481052
insert_node_id!();
1049-
let features = if self.message_handler.onion_message_handler.supports_onion_message_forwarding()
1050-
{ InitFeatures::known() } else { InitFeatures::known_without_onion_messages() };
1051-
let resp = msgs::Init { features, remote_network_address: filter_addresses(peer.their_net_address.clone()) };
1053+
let resp = msgs::Init {
1054+
features: self.our_features.clone(),
1055+
remote_network_address: filter_addresses(peer.their_net_address.clone())
1056+
};
10521057
self.enqueue_message(peer, &resp);
10531058
peer.awaiting_pong_timer_tick_intervals = 0;
10541059
},

0 commit comments

Comments
 (0)