@@ -1091,15 +1091,15 @@ impl SimNetwork for SimGraph {
1091
1091
} ,
1092
1092
} ;
1093
1093
1094
- self . tasks . spawn ( propagate_payment (
1095
- self . channels . clone ( ) ,
1094
+ self . tasks . spawn ( propagate_payment ( PropagatePaymentRequest {
1095
+ nodes : Arc :: clone ( & self . channels ) ,
1096
1096
source,
1097
- path. clone ( ) ,
1097
+ route : path. clone ( ) ,
1098
1098
payment_hash,
1099
1099
sender,
1100
- self . interceptors . clone ( ) ,
1101
- self . shutdown_signal . clone ( ) ,
1102
- ) ) ;
1100
+ interceptors : self . interceptors . clone ( ) ,
1101
+ shutdown_signal : self . shutdown_signal . clone ( ) ,
1102
+ } ) ) ;
1103
1103
}
1104
1104
1105
1105
/// lookup_node fetches a node's information and channel capacities.
@@ -1338,43 +1338,45 @@ async fn remove_htlcs(
1338
1338
Ok ( ( ) )
1339
1339
}
1340
1340
1341
- /// Finds a payment path from the source to destination nodes provided, and propagates the appropriate htlcs through
1342
- /// the simulated network, notifying the sender channel provided of the payment outcome. If a critical error occurs,
1343
- /// ie a breakdown of our state machine, it will still notify the payment outcome and will use the shutdown trigger
1344
- /// to signal that we should exit.
1345
- async fn propagate_payment (
1341
+ struct PropagatePaymentRequest {
1346
1342
nodes : Arc < Mutex < HashMap < ShortChannelID , SimulatedChannel > > > ,
1347
1343
source : PublicKey ,
1348
1344
route : Path ,
1349
1345
payment_hash : PaymentHash ,
1350
1346
sender : Sender < Result < PaymentResult , LightningError > > ,
1351
1347
interceptors : Vec < Arc < dyn Interceptor > > ,
1352
1348
shutdown_signal : ( Trigger , Listener ) ,
1353
- ) {
1349
+ }
1350
+
1351
+ /// Finds a payment path from the source to destination nodes provided, and propagates the appropriate htlcs through
1352
+ /// the simulated network, notifying the sender channel provided of the payment outcome. If a critical error occurs,
1353
+ /// ie a breakdown of our state machine, it will still notify the payment outcome and will use the shutdown trigger
1354
+ /// to signal that we should exit.
1355
+ async fn propagate_payment ( request : PropagatePaymentRequest ) {
1354
1356
let notify_result = match add_htlcs (
1355
- nodes. clone ( ) ,
1356
- source,
1357
- route. clone ( ) ,
1358
- payment_hash,
1359
- interceptors. clone ( ) ,
1360
- shutdown_signal. 1 ,
1357
+ request . nodes . clone ( ) ,
1358
+ request . source ,
1359
+ request . route . clone ( ) ,
1360
+ request . payment_hash ,
1361
+ request . interceptors . clone ( ) ,
1362
+ request . shutdown_signal . 1 ,
1361
1363
)
1362
1364
. await
1363
1365
{
1364
1366
Ok ( Ok ( _) ) => {
1365
1367
// If we successfully added the htlc, go ahead and remove all the htlcs in the route with successful resolution.
1366
1368
if let Err ( e) = remove_htlcs (
1367
- nodes,
1368
- route. hops . len ( ) - 1 ,
1369
- source,
1370
- route,
1371
- payment_hash,
1369
+ request . nodes ,
1370
+ request . route . hops . len ( ) - 1 ,
1371
+ request . source ,
1372
+ request . route ,
1373
+ request . payment_hash ,
1372
1374
true ,
1373
- interceptors,
1375
+ request . interceptors ,
1374
1376
)
1375
1377
. await
1376
1378
{
1377
- shutdown_signal. 0 . trigger ( ) ;
1379
+ request . shutdown_signal . 0 . trigger ( ) ;
1378
1380
log:: error!( "Could not remove htlcs from channel: {e}." ) ;
1379
1381
}
1380
1382
PaymentResult {
@@ -1387,35 +1389,35 @@ async fn propagate_payment(
1387
1389
// state. It's possible that we failed with the very first add, and then we don't need to clean anything up.
1388
1390
if let Some ( resolution_idx) = fail_idx {
1389
1391
if remove_htlcs (
1390
- nodes,
1392
+ request . nodes ,
1391
1393
resolution_idx,
1392
- source,
1393
- route,
1394
- payment_hash,
1394
+ request . source ,
1395
+ request . route ,
1396
+ request . payment_hash ,
1395
1397
false ,
1396
- interceptors,
1398
+ request . interceptors ,
1397
1399
)
1398
1400
. await
1399
1401
. is_err ( )
1400
1402
{
1401
- shutdown_signal. 0 . trigger ( ) ;
1403
+ request . shutdown_signal . 0 . trigger ( ) ;
1402
1404
}
1403
1405
}
1404
1406
1405
1407
log:: debug!(
1406
1408
"Forwarding failure for simulated payment {}: {fwd_err}" ,
1407
- hex:: encode( payment_hash. 0 )
1409
+ hex:: encode( request . payment_hash. 0 )
1408
1410
) ;
1409
1411
PaymentResult {
1410
1412
htlc_count : 0 ,
1411
1413
payment_outcome : PaymentOutcome :: Unknown ,
1412
1414
}
1413
1415
} ,
1414
1416
Err ( critical_err) => {
1415
- shutdown_signal. 0 . trigger ( ) ;
1417
+ request . shutdown_signal . 0 . trigger ( ) ;
1416
1418
log:: debug!(
1417
1419
"Critical error in simulated payment {}: {critical_err}" ,
1418
- hex:: encode( payment_hash. 0 )
1420
+ hex:: encode( request . payment_hash. 0 )
1419
1421
) ;
1420
1422
PaymentResult {
1421
1423
htlc_count : 0 ,
@@ -1424,7 +1426,7 @@ async fn propagate_payment(
1424
1426
} ,
1425
1427
} ;
1426
1428
1427
- if let Err ( e) = sender. send ( Ok ( notify_result) ) {
1429
+ if let Err ( e) = request . sender . send ( Ok ( notify_result) ) {
1428
1430
log:: error!( "Could not notify payment result: {:?}." , e) ;
1429
1431
}
1430
1432
}
0 commit comments