@@ -4963,8 +4963,11 @@ pub(crate) mod test_utils {
4963
4963
#[ cfg( all( test, feature = "unstable" , not( feature = "no-std" ) ) ) ]
4964
4964
mod benches {
4965
4965
use super :: * ;
4966
- use bitcoin:: secp256k1:: PublicKey ;
4967
- use ln:: features:: InvoiceFeatures ;
4966
+ use bitcoin:: hashes:: Hash ;
4967
+ use bitcoin:: secp256k1:: { PublicKey , Secp256k1 , SecretKey } ;
4968
+ use chain:: transaction:: OutPoint ;
4969
+ use ln:: channelmanager:: { ChannelCounterparty , ChannelDetails } ;
4970
+ use ln:: features:: { InitFeatures , InvoiceFeatures } ;
4968
4971
use routing:: scoring:: Scorer ;
4969
4972
use util:: logger:: { Logger , Record } ;
4970
4973
@@ -4980,6 +4983,40 @@ mod benches {
4980
4983
NetworkGraph :: read ( & mut d) . unwrap ( )
4981
4984
}
4982
4985
4986
+ fn payer_pubkey ( ) -> PublicKey {
4987
+ let secp_ctx = Secp256k1 :: new ( ) ;
4988
+ PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) )
4989
+ }
4990
+
4991
+ #[ inline]
4992
+ fn first_hop ( node_id : PublicKey ) -> ChannelDetails {
4993
+ ChannelDetails {
4994
+ channel_id : [ 0 ; 32 ] ,
4995
+ counterparty : ChannelCounterparty {
4996
+ features : InitFeatures :: known ( ) ,
4997
+ node_id,
4998
+ unspendable_punishment_reserve : 0 ,
4999
+ forwarding_info : None ,
5000
+ } ,
5001
+ funding_txo : Some ( OutPoint {
5002
+ txid : bitcoin:: Txid :: from_slice ( & [ 0 ; 32 ] ) . unwrap ( ) , index : 0
5003
+ } ) ,
5004
+ short_channel_id : Some ( 1 ) ,
5005
+ channel_value_satoshis : 10_000_000 ,
5006
+ user_channel_id : 0 ,
5007
+ balance_msat : 10_000_000 ,
5008
+ outbound_capacity_msat : 10_000_000 ,
5009
+ inbound_capacity_msat : 0 ,
5010
+ unspendable_punishment_reserve : None ,
5011
+ confirmations_required : None ,
5012
+ force_close_spend_delay : None ,
5013
+ is_outbound : true ,
5014
+ is_funding_locked : true ,
5015
+ is_usable : true ,
5016
+ is_public : true ,
5017
+ }
5018
+ }
5019
+
4983
5020
#[ bench]
4984
5021
fn generate_routes_with_default_scorer ( bench : & mut Bencher ) {
4985
5022
let network_graph = read_network_graph ( ) ;
@@ -4998,6 +5035,7 @@ mod benches {
4998
5035
bench : & mut Bencher , graph : & NetworkGraph , scorer : S , features : InvoiceFeatures
4999
5036
) {
5000
5037
let nodes = graph. read_only ( ) . nodes ( ) . clone ( ) ;
5038
+ let payer = payer_pubkey ( ) ;
5001
5039
5002
5040
// First, get 100 (source, destination) pairs for which route-getting actually succeeds...
5003
5041
let mut path_endpoints = Vec :: new ( ) ;
@@ -5009,9 +5047,10 @@ mod benches {
5009
5047
seed *= 0xdeadbeef ;
5010
5048
let dst = PublicKey :: from_slice ( nodes. keys ( ) . skip ( seed % nodes. len ( ) ) . next ( ) . unwrap ( ) . as_slice ( ) ) . unwrap ( ) ;
5011
5049
let params = PaymentParameters :: from_node_id ( dst) . with_features ( features. clone ( ) ) ;
5050
+ let first_hop = first_hop ( src) ;
5012
5051
let amt = seed as u64 % 1_000_000 ;
5013
- if get_route ( & src , & params, & graph, None , amt, 42 , & DummyLogger { } , & scorer) . is_ok ( ) {
5014
- path_endpoints. push ( ( src , dst , amt) ) ;
5052
+ if get_route ( & payer , & params, & graph, Some ( & [ & first_hop ] ) , amt, 42 , & DummyLogger { } , & scorer) . is_ok ( ) {
5053
+ path_endpoints. push ( ( first_hop , params , amt) ) ;
5015
5054
continue ' load_endpoints;
5016
5055
}
5017
5056
}
@@ -5020,9 +5059,8 @@ mod benches {
5020
5059
// ...then benchmark finding paths between the nodes we learned.
5021
5060
let mut idx = 0 ;
5022
5061
bench. iter ( || {
5023
- let ( src, dst, amt) = path_endpoints[ idx % path_endpoints. len ( ) ] ;
5024
- let params = PaymentParameters :: from_node_id ( dst) . with_features ( features. clone ( ) ) ;
5025
- assert ! ( get_route( & src, & params, & graph, None , amt, 42 , & DummyLogger { } , & scorer) . is_ok( ) ) ;
5062
+ let ( first_hop, params, amt) = & path_endpoints[ idx % path_endpoints. len ( ) ] ;
5063
+ assert ! ( get_route( & payer, params, & graph, Some ( & [ first_hop] ) , * amt, 42 , & DummyLogger { } , & scorer) . is_ok( ) ) ;
5026
5064
idx += 1 ;
5027
5065
} ) ;
5028
5066
}
0 commit comments