Skip to content

Commit 56d4807

Browse files
committed
Store source/target node_counters in DirectionalChannelInfo
Because we now have some slack space in `PathBuildingHop`, we can use it to cache some additional hot values. Here we use it to cache the source and target `node_counter`s for public channels, effectively prefetching the values from the channel state.
1 parent f7f6dbf commit 56d4807

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

lightning/src/routing/gossip.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,8 @@ impl Readable for ChannelInfo {
10181018
pub struct DirectedChannelInfo<'a> {
10191019
channel: &'a ChannelInfo,
10201020
direction: &'a ChannelUpdateInfo,
1021+
source_counter: u32,
1022+
target_counter: u32,
10211023
/// The direction this channel is in - if set, it indicates that we're traversing the channel
10221024
/// from [`ChannelInfo::node_one`] to [`ChannelInfo::node_two`].
10231025
from_node_one: bool,
@@ -1026,7 +1028,12 @@ pub struct DirectedChannelInfo<'a> {
10261028
impl<'a> DirectedChannelInfo<'a> {
10271029
#[inline]
10281030
fn new(channel: &'a ChannelInfo, direction: &'a ChannelUpdateInfo, from_node_one: bool) -> Self {
1029-
Self { channel, direction, from_node_one }
1031+
let (source_counter, target_counter) = if from_node_one {
1032+
(channel.node_one_counter, channel.node_two_counter)
1033+
} else {
1034+
(channel.node_two_counter, channel.node_one_counter)
1035+
};
1036+
Self { channel, direction, from_node_one, source_counter, target_counter }
10301037
}
10311038

10321039
/// Returns information for the channel.
@@ -1069,12 +1076,12 @@ impl<'a> DirectedChannelInfo<'a> {
10691076
pub fn target(&self) -> &'a NodeId { if self.from_node_one { &self.channel.node_two } else { &self.channel.node_one } }
10701077

10711078
/// Returns the source node's counter
1072-
#[inline]
1073-
pub(super) fn source_counter(&self) -> u32 { if self.from_node_one { self.channel.node_one_counter } else { self.channel.node_two_counter } }
1079+
#[inline(always)]
1080+
pub(super) fn source_counter(&self) -> u32 { self.source_counter }
10741081

10751082
/// Returns the target node's counter
1076-
#[inline]
1077-
pub(super) fn target_counter(&self) -> u32 { if self.from_node_one { self.channel.node_two_counter } else { self.channel.node_one_counter } }
1083+
#[inline(always)]
1084+
pub(super) fn target_counter(&self) -> u32 { self.target_counter }
10781085
}
10791086

10801087
impl<'a> fmt::Debug for DirectedChannelInfo<'a> {

lightning/src/routing/router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,7 @@ impl<'a> CandidateRouteHop<'a> {
13911391
}
13921392
}
13931393

1394-
#[inline]
1394+
#[inline(always)]
13951395
fn src_node_counter(&self) -> u32 {
13961396
match self {
13971397
CandidateRouteHop::FirstHop(hop) => hop.payer_node_counter,

0 commit comments

Comments
 (0)