Skip to content

Commit 7f4b466

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 9ff6b79 commit 7f4b466

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
@@ -1053,6 +1053,8 @@ impl Readable for ChannelInfo {
10531053
pub struct DirectedChannelInfo<'a> {
10541054
channel: &'a ChannelInfo,
10551055
direction: &'a ChannelUpdateInfo,
1056+
source_counter: u32,
1057+
target_counter: u32,
10561058
/// The direction this channel is in - if set, it indicates that we're traversing the channel
10571059
/// from [`ChannelInfo::node_one`] to [`ChannelInfo::node_two`].
10581060
from_node_one: bool,
@@ -1061,7 +1063,12 @@ pub struct DirectedChannelInfo<'a> {
10611063
impl<'a> DirectedChannelInfo<'a> {
10621064
#[inline]
10631065
fn new(channel: &'a ChannelInfo, direction: &'a ChannelUpdateInfo, from_node_one: bool) -> Self {
1064-
Self { channel, direction, from_node_one }
1066+
let (source_counter, target_counter) = if from_node_one {
1067+
(channel.node_one_counter, channel.node_two_counter)
1068+
} else {
1069+
(channel.node_two_counter, channel.node_one_counter)
1070+
};
1071+
Self { channel, direction, from_node_one, source_counter, target_counter }
10651072
}
10661073

10671074
/// Returns information for the channel.
@@ -1104,12 +1111,12 @@ impl<'a> DirectedChannelInfo<'a> {
11041111
pub fn target(&self) -> &'a NodeId { if self.from_node_one { &self.channel.node_two } else { &self.channel.node_one } }
11051112

11061113
/// Returns the source node's counter
1107-
#[inline]
1108-
pub(super) fn source_counter(&self) -> u32 { if self.from_node_one { self.channel.node_one_counter } else { self.channel.node_two_counter } }
1114+
#[inline(always)]
1115+
pub(super) fn source_counter(&self) -> u32 { self.source_counter }
11091116

11101117
/// Returns the target node's counter
1111-
#[inline]
1112-
pub(super) fn target_counter(&self) -> u32 { if self.from_node_one { self.channel.node_two_counter } else { self.channel.node_one_counter } }
1118+
#[inline(always)]
1119+
pub(super) fn target_counter(&self) -> u32 { self.target_counter }
11131120
}
11141121

11151122
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
@@ -1437,7 +1437,7 @@ impl<'a> CandidateRouteHop<'a> {
14371437
}
14381438
}
14391439

1440-
#[inline]
1440+
#[inline(always)]
14411441
fn src_node_counter(&self) -> u32 {
14421442
match self {
14431443
CandidateRouteHop::FirstHop(hop) => hop.payer_node_counter,

0 commit comments

Comments
 (0)