Skip to content

Commit dc3447a

Browse files
committed
Add a test of the new channel saturation limit
1 parent 9af04d5 commit dc3447a

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

lightning/src/routing/router.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5723,6 +5723,50 @@ mod tests {
57235723
}
57245724
}
57255725

5726+
#[test]
5727+
fn avoids_saturating_channels() {
5728+
let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph();
5729+
let (_, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
5730+
5731+
let scorer = ProbabilisticScorer::new(Default::default(), &*network_graph, Arc::clone(&logger));
5732+
5733+
// Set the fee on channel 13 to 100% to match channel 4 giving us two equivalent paths (us
5734+
// -> node 7 -> node2 and us -> node 1 -> node 2) which we should balance over.
5735+
update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate {
5736+
chain_hash: genesis_block(Network::Testnet).header.block_hash(),
5737+
short_channel_id: 4,
5738+
timestamp: 2,
5739+
flags: 0,
5740+
cltv_expiry_delta: (4 << 4) | 1,
5741+
htlc_minimum_msat: 0,
5742+
htlc_maximum_msat: OptionalField::Present(200_000_000),
5743+
fee_base_msat: 0,
5744+
fee_proportional_millionths: 0,
5745+
excess_data: Vec::new()
5746+
});
5747+
update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate {
5748+
chain_hash: genesis_block(Network::Testnet).header.block_hash(),
5749+
short_channel_id: 13,
5750+
timestamp: 2,
5751+
flags: 0,
5752+
cltv_expiry_delta: (13 << 4) | 1,
5753+
htlc_minimum_msat: 0,
5754+
htlc_maximum_msat: OptionalField::Present(200_000_000),
5755+
fee_base_msat: 0,
5756+
fee_proportional_millionths: 0,
5757+
excess_data: Vec::new()
5758+
});
5759+
5760+
let payment_params = PaymentParameters::from_node_id(nodes[2]).with_features(InvoiceFeatures::known());
5761+
let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
5762+
let random_seed_bytes = keys_manager.get_secure_random_bytes();
5763+
// 150,000 msat is less than the available liquidity on each channel, set above.
5764+
let route = get_route(&our_id, &payment_params, &network_graph.read_only(), None, 150_000_000, 42, Arc::clone(&logger), &scorer, &random_seed_bytes).unwrap();
5765+
assert_eq!(route.paths.len(), 2);
5766+
assert!((route.paths[0][1].short_channel_id == 4 && route.paths[1][1].short_channel_id == 13) ||
5767+
(route.paths[1][1].short_channel_id == 4 && route.paths[0][1].short_channel_id == 13));
5768+
}
5769+
57265770
#[cfg(not(feature = "no-std"))]
57275771
pub(super) fn random_init_seed() -> u64 {
57285772
// Because the default HashMap in std pulls OS randomness, we can use it as a (bad) RNG.

0 commit comments

Comments
 (0)