Skip to content

Commit 7b3d73e

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 a6475a1 commit 7b3d73e

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
@@ -1004,6 +1004,8 @@ impl Readable for ChannelInfo {
10041004
pub struct DirectedChannelInfo<'a> {
10051005
channel: &'a ChannelInfo,
10061006
direction: &'a ChannelUpdateInfo,
1007+
source_counter: u32,
1008+
target_counter: u32,
10071009
/// The direction this channel is in - if set, it indicates that we're traversing the channel
10081010
/// from [`ChannelInfo::node_one`] to [`ChannelInfo::node_two`].
10091011
from_node_one: bool,
@@ -1012,7 +1014,12 @@ pub struct DirectedChannelInfo<'a> {
10121014
impl<'a> DirectedChannelInfo<'a> {
10131015
#[inline]
10141016
fn new(channel: &'a ChannelInfo, direction: &'a ChannelUpdateInfo, from_node_one: bool) -> Self {
1015-
Self { channel, direction, from_node_one }
1017+
let (source_counter, target_counter) = if from_node_one {
1018+
(channel.node_one_counter, channel.node_two_counter)
1019+
} else {
1020+
(channel.node_two_counter, channel.node_one_counter)
1021+
};
1022+
Self { channel, direction, from_node_one, source_counter, target_counter }
10161023
}
10171024

10181025
/// Returns information for the channel.
@@ -1055,12 +1062,12 @@ impl<'a> DirectedChannelInfo<'a> {
10551062
pub(super) fn target(&self) -> &'a NodeId { if self.from_node_one { &self.channel.node_two } else { &self.channel.node_one } }
10561063

10571064
/// Returns the source node's counter
1058-
#[inline]
1059-
pub(super) fn source_counter(&self) -> u32 { if self.from_node_one { self.channel.node_one_counter } else { self.channel.node_two_counter } }
1065+
#[inline(always)]
1066+
pub(super) fn source_counter(&self) -> u32 { self.source_counter }
10601067

10611068
/// Returns the target node's counter
1062-
#[inline]
1063-
pub(super) fn target_counter(&self) -> u32 { if self.from_node_one { self.channel.node_two_counter } else { self.channel.node_one_counter } }
1069+
#[inline(always)]
1070+
pub(super) fn target_counter(&self) -> u32 { self.target_counter }
10641071
}
10651072

10661073
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
@@ -1341,7 +1341,7 @@ impl<'a> CandidateRouteHop<'a> {
13411341
}
13421342
}
13431343

1344-
#[inline]
1344+
#[inline(always)]
13451345
fn src_node_counter(&self) -> u32 {
13461346
match self {
13471347
CandidateRouteHop::FirstHop(hop) => hop.payer_node_counter,

0 commit comments

Comments
 (0)