Skip to content

Commit 14e1803

Browse files
committed
Replace EventHandler impl for NetworkGraph with reference'd version
This allows us to avoid extra event clones when intercepting events for the NetworkGraph.
1 parent 6ed9190 commit 14e1803

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

lightning-background-processor/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl<
226226
where A::Target: chain::Access, L::Target: Logger {
227227
fn handle_event(&self, event: Event) {
228228
if let Some(network_graph) = self.gossip_sync.network_graph() {
229-
network_graph.handle_event(event.clone());
229+
network_graph.handle_event(&event);
230230
}
231231
self.event_handler.handle_event(event);
232232
}
@@ -262,7 +262,7 @@ where A::Target: chain::Access, L::Target: Logger {
262262
fn handle_event_async<'b>(&'b self, event: Event) -> Pin<Box<dyn StdFuture<Output = ()> + '_>> {
263263
Box::pin(async move {
264264
if let Some(network_graph) = self.gossip_sync.network_graph() {
265-
network_graph.handle_event(event.clone()); // TODO: Also make async?
265+
network_graph.handle_event(&event);
266266
}
267267
self.async_event_handler.handle_event_async(event).await;
268268
})

lightning/src/routing/gossip.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::ln::msgs::{QueryChannelRange, ReplyChannelRange, QueryShortChannelIds
2929
use crate::ln::msgs;
3030
use crate::util::ser::{Readable, ReadableArgs, Writeable, Writer, MaybeReadable};
3131
use crate::util::logger::{Logger, Level};
32-
use crate::util::events::{Event, EventHandler, MessageSendEvent, MessageSendEventsProvider};
32+
use crate::util::events::{Event, MessageSendEvent, MessageSendEventsProvider};
3333
use crate::util::scid_utils::{block_from_scid, scid_from_parts, MAX_SCID_BLOCK};
3434

3535
use crate::io;
@@ -213,8 +213,8 @@ impl_writeable_tlv_based_enum_upgradable!(NetworkUpdate,
213213
/// Provides interface to help with initial routing sync by
214214
/// serving historical announcements.
215215
///
216-
/// Serves as an [`EventHandler`] for applying updates from [`Event::PaymentPathFailed`] to the
217-
/// [`NetworkGraph`].
216+
/// Implements a referenced version of [`EventHandler`] for applying updates from
217+
/// [`Event::PaymentPathFailed`] to the [`NetworkGraph`].
218218
pub struct P2PGossipSync<G: Deref<Target=NetworkGraph<L>>, C: Deref, L: Deref>
219219
where C::Target: chain::Access, L::Target: Logger
220220
{
@@ -274,8 +274,8 @@ where C::Target: chain::Access, L::Target: Logger
274274
}
275275
}
276276

277-
impl<L: Deref> EventHandler for NetworkGraph<L> where L::Target: Logger {
278-
fn handle_event(&self, event: Event) {
277+
impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
278+
pub fn handle_event(&self, event: &Event) {
279279
if let Event::PaymentPathFailed { network_update, .. } = event {
280280
if let Some(network_update) = network_update {
281281
match network_update {
@@ -287,12 +287,12 @@ impl<L: Deref> EventHandler for NetworkGraph<L> where L::Target: Logger {
287287
let _ = self.update_channel(msg);
288288
},
289289
NetworkUpdate::ChannelFailure { short_channel_id, is_permanent } => {
290-
let action = if is_permanent { "Removing" } else { "Disabling" };
290+
let action = if *is_permanent { "Removing" } else { "Disabling" };
291291
log_debug!(self.logger, "{} channel graph entry for {} due to a payment failure.", action, short_channel_id);
292-
self.channel_failed(short_channel_id, is_permanent);
292+
self.channel_failed(*short_channel_id, *is_permanent);
293293
},
294294
NetworkUpdate::NodeFailure { ref node_id, is_permanent } => {
295-
if is_permanent {
295+
if *is_permanent {
296296
log_debug!(self.logger,
297297
"Removed node graph entry for {} due to a payment failure.", log_pubkey!(node_id));
298298
self.node_failed_permanent(node_id);
@@ -1980,7 +1980,7 @@ mod tests {
19801980
ReplyChannelRange, QueryChannelRange, QueryShortChannelIds, MAX_VALUE_MSAT};
19811981
use crate::util::test_utils;
19821982
use crate::util::ser::{ReadableArgs, Writeable};
1983-
use crate::util::events::{Event, EventHandler, MessageSendEvent, MessageSendEventsProvider};
1983+
use crate::util::events::{Event, MessageSendEvent, MessageSendEventsProvider};
19841984
use crate::util::scid_utils::scid_from_parts;
19851985

19861986
use crate::routing::gossip::REMOVED_ENTRIES_TRACKING_AGE_LIMIT_SECS;
@@ -2424,7 +2424,7 @@ mod tests {
24242424
let valid_channel_update = get_signed_channel_update(|_| {}, node_1_privkey, &secp_ctx);
24252425
assert!(network_graph.read_only().channels().get(&short_channel_id).unwrap().one_to_two.is_none());
24262426

2427-
network_graph.handle_event(Event::PaymentPathFailed {
2427+
network_graph.handle_event(&Event::PaymentPathFailed {
24282428
payment_id: None,
24292429
payment_hash: PaymentHash([0; 32]),
24302430
payment_failed_permanently: false,
@@ -2451,7 +2451,7 @@ mod tests {
24512451
}
24522452
};
24532453

2454-
network_graph.handle_event(Event::PaymentPathFailed {
2454+
network_graph.handle_event(&Event::PaymentPathFailed {
24552455
payment_id: None,
24562456
payment_hash: PaymentHash([0; 32]),
24572457
payment_failed_permanently: false,
@@ -2476,7 +2476,7 @@ mod tests {
24762476
}
24772477

24782478
// Permanent closing deletes a channel
2479-
network_graph.handle_event(Event::PaymentPathFailed {
2479+
network_graph.handle_event(&Event::PaymentPathFailed {
24802480
payment_id: None,
24812481
payment_hash: PaymentHash([0; 32]),
24822482
payment_failed_permanently: false,
@@ -2508,7 +2508,7 @@ mod tests {
25082508
assert!(network_graph.read_only().channels().get(&short_channel_id).is_some());
25092509

25102510
// Non-permanent node failure does not delete any nodes or channels
2511-
network_graph.handle_event(Event::PaymentPathFailed {
2511+
network_graph.handle_event(&Event::PaymentPathFailed {
25122512
payment_id: None,
25132513
payment_hash: PaymentHash([0; 32]),
25142514
payment_failed_permanently: false,
@@ -2528,7 +2528,7 @@ mod tests {
25282528
assert!(network_graph.read_only().nodes().get(&NodeId::from_pubkey(&node_2_id)).is_some());
25292529

25302530
// Permanent node failure deletes node and its channels
2531-
network_graph.handle_event(Event::PaymentPathFailed {
2531+
network_graph.handle_event(&Event::PaymentPathFailed {
25322532
payment_id: None,
25332533
payment_hash: PaymentHash([0; 32]),
25342534
payment_failed_permanently: false,

0 commit comments

Comments
 (0)