From: Matt Corallo Date: Fri, 8 Dec 2023 01:49:20 +0000 (+0000) Subject: Store source/target `node_counter`s in `DirectionalChannelInfo` X-Git-Tag: v0.0.124-beta~45^2~3 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=98f9e8bbf80c5f7d3bb37da92aef0f12d57c075f;p=rust-lightning Store source/target `node_counter`s 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. --- diff --git a/lightning/src/routing/gossip.rs b/lightning/src/routing/gossip.rs index 04aa174f3..b0117cd68 100644 --- a/lightning/src/routing/gossip.rs +++ b/lightning/src/routing/gossip.rs @@ -1053,6 +1053,8 @@ impl Readable for ChannelInfo { pub struct DirectedChannelInfo<'a> { channel: &'a ChannelInfo, direction: &'a ChannelUpdateInfo, + source_counter: u32, + target_counter: u32, /// The direction this channel is in - if set, it indicates that we're traversing the channel /// from [`ChannelInfo::node_one`] to [`ChannelInfo::node_two`]. from_node_one: bool, @@ -1061,7 +1063,12 @@ pub struct DirectedChannelInfo<'a> { impl<'a> DirectedChannelInfo<'a> { #[inline] fn new(channel: &'a ChannelInfo, direction: &'a ChannelUpdateInfo, from_node_one: bool) -> Self { - Self { channel, direction, from_node_one } + let (source_counter, target_counter) = if from_node_one { + (channel.node_one_counter, channel.node_two_counter) + } else { + (channel.node_two_counter, channel.node_one_counter) + }; + Self { channel, direction, from_node_one, source_counter, target_counter } } /// Returns information for the channel. @@ -1104,12 +1111,12 @@ impl<'a> DirectedChannelInfo<'a> { pub fn target(&self) -> &'a NodeId { if self.from_node_one { &self.channel.node_two } else { &self.channel.node_one } } /// Returns the source node's counter - #[inline] - pub(super) fn source_counter(&self) -> u32 { if self.from_node_one { self.channel.node_one_counter } else { self.channel.node_two_counter } } + #[inline(always)] + pub(super) fn source_counter(&self) -> u32 { self.source_counter } /// Returns the target node's counter - #[inline] - pub(super) fn target_counter(&self) -> u32 { if self.from_node_one { self.channel.node_two_counter } else { self.channel.node_one_counter } } + #[inline(always)] + pub(super) fn target_counter(&self) -> u32 { self.target_counter } } impl<'a> fmt::Debug for DirectedChannelInfo<'a> { diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index bbf73e531..58486c3da 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -1437,7 +1437,7 @@ impl<'a> CandidateRouteHop<'a> { } } - #[inline] + #[inline(always)] fn src_node_counter(&self) -> u32 { match self { CandidateRouteHop::FirstHop(hop) => hop.payer_node_counter,