Skip to content

Commit efdd221

Browse files
committed
Update min-inbound-fee values on NetworkGraph load
Historically we've had various bugs in keeping the `lowest_inbound_channel_fees` field in `NodeInfo` up-to-date as we go. This leaves the A* routing less efficient as it can't prune hops as aggressively. In order to get accurate benchmarks, this commit updates the minimum-inbound-fees field on load. This is not the most efficient way of doing so, but suffices for fetching benchmarks and will be removed in the coming commits. Note that this is *slower* than the non-updating version in the previous commit. While I haven't dug into this incredibly deeply, the graph snapshot in use has min-fee info for only 9,618 of 20,818 nodes. Thus, it is my guess that with the graph snapshot as-is the branch predictor is able to largely remove the A* heuristic lookups, but with this change it is forced to wait for A* heuristic map lookups to complete, causing a performance regression. ``` test routing::router::benches::generate_mpp_routes_with_probabilistic_scorer ... bench: 182,980,059 ns/iter (+/- 32,662,047) test routing::router::benches::generate_mpp_routes_with_zero_penalty_scorer ... bench: 151,170,457 ns/iter (+/- 75,351,011) test routing::router::benches::generate_routes_with_probabilistic_scorer ... bench: 58,187,277 ns/iter (+/- 11,606,440) test routing::router::benches::generate_routes_with_zero_penalty_scorer ... bench: 41,210,193 ns/iter (+/- 18,103,320) ```
1 parent 608c8ad commit efdd221

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

lightning/src/routing/gossip.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,14 +1156,14 @@ impl<L: Deref> ReadableArgs<L> for NetworkGraph<L> where L::Target: Logger {
11561156

11571157
let genesis_hash: BlockHash = Readable::read(reader)?;
11581158
let channels_count: u64 = Readable::read(reader)?;
1159-
let mut channels = BTreeMap::new();
1159+
let mut channels: BTreeMap<u64, ChannelInfo> = BTreeMap::new();
11601160
for _ in 0..channels_count {
11611161
let chan_id: u64 = Readable::read(reader)?;
11621162
let chan_info = Readable::read(reader)?;
11631163
channels.insert(chan_id, chan_info);
11641164
}
11651165
let nodes_count: u64 = Readable::read(reader)?;
1166-
let mut nodes = BTreeMap::new();
1166+
let mut nodes: BTreeMap<NodeId, NodeInfo> = BTreeMap::new();
11671167
for _ in 0..nodes_count {
11681168
let node_id = Readable::read(reader)?;
11691169
let node_info = Readable::read(reader)?;
@@ -1175,6 +1175,22 @@ impl<L: Deref> ReadableArgs<L> for NetworkGraph<L> where L::Target: Logger {
11751175
(1, last_rapid_gossip_sync_timestamp, option),
11761176
});
11771177

1178+
// Regenerate inbound fees for all channels. The live-updating of these has been broken in
1179+
// various ways historically, so this ensures that we have up-to-date limits.
1180+
for (node_id, node) in nodes.iter_mut() {
1181+
let mut best_fees = RoutingFees { base_msat: u32::MAX, proportional_millionths: u32::MAX };
1182+
for channel in node.channels.iter() {
1183+
if let Some(chan) = channels.get(channel) {
1184+
let dir_opt = if *node_id == chan.node_one { &chan.two_to_one } else { &chan.one_to_two };
1185+
if let Some(dir) = dir_opt {
1186+
best_fees.base_msat = cmp::min(best_fees.base_msat, dir.fees.base_msat);
1187+
best_fees.proportional_millionths = cmp::min(best_fees.proportional_millionths, dir.fees.proportional_millionths);
1188+
}
1189+
} else { return Err(DecodeError::InvalidValue); }
1190+
}
1191+
node.lowest_inbound_channel_fees = Some(best_fees);
1192+
}
1193+
11781194
Ok(NetworkGraph {
11791195
secp_ctx: Secp256k1::verification_only(),
11801196
genesis_hash,

0 commit comments

Comments
 (0)