@@ -864,7 +864,7 @@ mod tests {
864
864
use lightning:: ln:: peer_handler:: { PeerManager , MessageHandler , SocketDescriptor , IgnoringMessageHandler } ;
865
865
use lightning:: routing:: gossip:: { NetworkGraph , NodeId , P2PGossipSync } ;
866
866
use lightning:: routing:: router:: { DefaultRouter , Path , RouteHop } ;
867
- use lightning:: routing:: scoring:: { ChannelUsage , ScoreUpdate , ScoreLookUp } ;
867
+ use lightning:: routing:: scoring:: { ChannelUsage , ScoreUpdate , ScoreLookUp , LockableScore } ;
868
868
use lightning:: util:: config:: UserConfig ;
869
869
use lightning:: util:: ser:: Writeable ;
870
870
use lightning:: util:: test_utils;
@@ -894,6 +894,11 @@ mod tests {
894
894
fn disconnect_socket ( & mut self ) { }
895
895
}
896
896
897
+ #[ cfg( c_bindings) ]
898
+ type LockingWrapper < T > = lightning:: routing:: scoring:: MultiThreadedLockableScore < T > ;
899
+ #[ cfg( not( c_bindings) ) ]
900
+ type LockingWrapper < T > = Mutex < T > ;
901
+
897
902
type ChannelManager =
898
903
channelmanager:: ChannelManager <
899
904
Arc < ChainMonitor > ,
@@ -905,7 +910,7 @@ mod tests {
905
910
Arc < DefaultRouter <
906
911
Arc < NetworkGraph < Arc < test_utils:: TestLogger > > > ,
907
912
Arc < test_utils:: TestLogger > ,
908
- Arc < Mutex < TestScorer > > ,
913
+ Arc < LockingWrapper < TestScorer > > ,
909
914
( ) ,
910
915
TestScorer >
911
916
> ,
@@ -927,7 +932,7 @@ mod tests {
927
932
network_graph : Arc < NetworkGraph < Arc < test_utils:: TestLogger > > > ,
928
933
logger : Arc < test_utils:: TestLogger > ,
929
934
best_block : BestBlock ,
930
- scorer : Arc < Mutex < TestScorer > > ,
935
+ scorer : Arc < LockingWrapper < TestScorer > > ,
931
936
}
932
937
933
938
impl Node {
@@ -1148,6 +1153,9 @@ mod tests {
1148
1153
}
1149
1154
}
1150
1155
1156
+ #[ cfg( c_bindings) ]
1157
+ impl lightning:: routing:: scoring:: Score for TestScorer { }
1158
+
1151
1159
impl Drop for TestScorer {
1152
1160
fn drop ( & mut self ) {
1153
1161
if std:: thread:: panicking ( ) {
@@ -1179,7 +1187,7 @@ mod tests {
1179
1187
let logger = Arc :: new ( test_utils:: TestLogger :: with_id ( format ! ( "node {}" , i) ) ) ;
1180
1188
let genesis_block = genesis_block ( network) ;
1181
1189
let network_graph = Arc :: new ( NetworkGraph :: new ( network, logger. clone ( ) ) ) ;
1182
- let scorer = Arc :: new ( Mutex :: new ( TestScorer :: new ( ) ) ) ;
1190
+ let scorer = Arc :: new ( LockingWrapper :: new ( TestScorer :: new ( ) ) ) ;
1183
1191
let seed = [ i as u8 ; 32 ] ;
1184
1192
let router = Arc :: new ( DefaultRouter :: new ( network_graph. clone ( ) , logger. clone ( ) , seed, scorer. clone ( ) , Default :: default ( ) ) ) ;
1185
1193
let chain_source = Arc :: new ( test_utils:: TestChainSource :: new ( Network :: Bitcoin ) ) ;
@@ -1689,7 +1697,7 @@ mod tests {
1689
1697
maybe_announced_channel: true ,
1690
1698
} ] , blinded_tail: None } ;
1691
1699
1692
- $nodes[ 0 ] . scorer. lock ( ) . unwrap ( ) . expect( TestResult :: PaymentFailure { path: path. clone( ) , short_channel_id: scored_scid } ) ;
1700
+ $nodes[ 0 ] . scorer. write_lock ( ) . expect( TestResult :: PaymentFailure { path: path. clone( ) , short_channel_id: scored_scid } ) ;
1693
1701
$nodes[ 0 ] . node. push_pending_event( Event :: PaymentPathFailed {
1694
1702
payment_id: None ,
1695
1703
payment_hash: PaymentHash ( [ 42 ; 32 ] ) ,
@@ -1706,7 +1714,7 @@ mod tests {
1706
1714
1707
1715
// Ensure we'll score payments that were explicitly failed back by the destination as
1708
1716
// ProbeSuccess.
1709
- $nodes[ 0 ] . scorer. lock ( ) . unwrap ( ) . expect( TestResult :: ProbeSuccess { path: path. clone( ) } ) ;
1717
+ $nodes[ 0 ] . scorer. write_lock ( ) . expect( TestResult :: ProbeSuccess { path: path. clone( ) } ) ;
1710
1718
$nodes[ 0 ] . node. push_pending_event( Event :: PaymentPathFailed {
1711
1719
payment_id: None ,
1712
1720
payment_hash: PaymentHash ( [ 42 ; 32 ] ) ,
@@ -1721,7 +1729,7 @@ mod tests {
1721
1729
_ => panic!( "Unexpected event" ) ,
1722
1730
}
1723
1731
1724
- $nodes[ 0 ] . scorer. lock ( ) . unwrap ( ) . expect( TestResult :: PaymentSuccess { path: path. clone( ) } ) ;
1732
+ $nodes[ 0 ] . scorer. write_lock ( ) . expect( TestResult :: PaymentSuccess { path: path. clone( ) } ) ;
1725
1733
$nodes[ 0 ] . node. push_pending_event( Event :: PaymentPathSuccessful {
1726
1734
payment_id: PaymentId ( [ 42 ; 32 ] ) ,
1727
1735
payment_hash: None ,
@@ -1733,7 +1741,7 @@ mod tests {
1733
1741
_ => panic!( "Unexpected event" ) ,
1734
1742
}
1735
1743
1736
- $nodes[ 0 ] . scorer. lock ( ) . unwrap ( ) . expect( TestResult :: ProbeSuccess { path: path. clone( ) } ) ;
1744
+ $nodes[ 0 ] . scorer. write_lock ( ) . expect( TestResult :: ProbeSuccess { path: path. clone( ) } ) ;
1737
1745
$nodes[ 0 ] . node. push_pending_event( Event :: ProbeSuccessful {
1738
1746
payment_id: PaymentId ( [ 42 ; 32 ] ) ,
1739
1747
payment_hash: PaymentHash ( [ 42 ; 32 ] ) ,
@@ -1745,7 +1753,7 @@ mod tests {
1745
1753
_ => panic!( "Unexpected event" ) ,
1746
1754
}
1747
1755
1748
- $nodes[ 0 ] . scorer. lock ( ) . unwrap ( ) . expect( TestResult :: ProbeFailure { path: path. clone( ) } ) ;
1756
+ $nodes[ 0 ] . scorer. write_lock ( ) . expect( TestResult :: ProbeFailure { path: path. clone( ) } ) ;
1749
1757
$nodes[ 0 ] . node. push_pending_event( Event :: ProbeFailed {
1750
1758
payment_id: PaymentId ( [ 42 ; 32 ] ) ,
1751
1759
payment_hash: PaymentHash ( [ 42 ; 32 ] ) ,
0 commit comments