@@ -507,7 +507,7 @@ pub struct SimNode<T: SimNetwork, C: Clock> {
507507 /// The underlying execution network that will be responsible for dispatching payments.
508508 network : Arc < Mutex < T > > ,
509509 /// Tracks the channel that will provide updates for payments by hash.
510- in_flight : HashMap < PaymentHash , InFlightPayment > ,
510+ in_flight : Mutex < HashMap < PaymentHash , InFlightPayment > > ,
511511 /// A read-only graph used for pathfinding.
512512 pathfinding_graph : Arc < LdkNetworkGraph > ,
513513 /// Probabilistic scorer used to rank paths through the network for routing. This is reused across
@@ -538,7 +538,7 @@ impl<T: SimNetwork, C: Clock> SimNode<T, C> {
538538 Ok ( SimNode {
539539 info,
540540 network : payment_network,
541- in_flight : HashMap :: new ( ) ,
541+ in_flight : Mutex :: new ( HashMap :: new ( ) ) ,
542542 pathfinding_graph,
543543 scorer,
544544 clock,
@@ -569,7 +569,7 @@ impl<T: SimNetwork, C: Clock> SimNode<T, C> {
569569 }
570570
571571 // Check for payment hash collision, failing the payment if we happen to repeat one.
572- match self . in_flight . entry ( payment_hash) {
572+ match self . in_flight . lock ( ) . await . entry ( payment_hash) {
573573 Entry :: Occupied ( _) => {
574574 return Err ( LightningError :: SendPaymentError (
575575 "payment hash exists" . to_string ( ) ,
@@ -651,7 +651,7 @@ impl<T: SimNetwork, C: Clock> LightningNode for SimNode<T, C> {
651651 /// send_payment picks a random preimage for a payment, dispatches it in the network and adds a tracking channel
652652 /// to our node state to be used for subsequent track_payment calls.
653653 async fn send_payment (
654- & mut self ,
654+ & self ,
655655 dest : PublicKey ,
656656 amount_msat : u64 ,
657657 ) -> Result < PaymentHash , LightningError > {
@@ -662,7 +662,8 @@ impl<T: SimNetwork, C: Clock> LightningNode for SimNode<T, C> {
662662 let payment_hash = preimage. into ( ) ;
663663
664664 // Check for payment hash collision, failing the payment if we happen to repeat one.
665- let entry = match self . in_flight . entry ( payment_hash) {
665+ let mut in_flight_guard = self . in_flight . lock ( ) . await ;
666+ let entry = match in_flight_guard. entry ( payment_hash) {
666667 Entry :: Occupied ( _) => {
667668 return Err ( LightningError :: SendPaymentError (
668669 "payment hash exists" . to_string ( ) ,
@@ -724,11 +725,11 @@ impl<T: SimNetwork, C: Clock> LightningNode for SimNode<T, C> {
724725 /// provided is triggered. This call will fail if the hash provided was not obtained from send_payment or passed
725726 /// into send_to_route first.
726727 async fn track_payment (
727- & mut self ,
728+ & self ,
728729 hash : & PaymentHash ,
729730 listener : Listener ,
730731 ) -> Result < PaymentResult , LightningError > {
731- match self . in_flight . remove ( hash) {
732+ match self . in_flight . lock ( ) . await . remove ( hash) {
732733 Some ( in_flight) => {
733734 select ! {
734735 biased;
@@ -2050,7 +2051,7 @@ mod tests {
20502051
20512052 // Create a simulated node for the first channel in our network.
20522053 let pk = channels[ 0 ] . node_1 . policy . pubkey ;
2053- let mut node = SimNode :: new (
2054+ let node = SimNode :: new (
20542055 node_info ( pk, String :: default ( ) ) ,
20552056 sim_network. clone ( ) ,
20562057 Arc :: new ( graph) ,
0 commit comments