@@ -449,6 +449,7 @@ pub(crate) enum PendingOutboundPayment {
449
449
/// and add a pending payment that was already fulfilled.
450
450
Fulfilled {
451
451
session_privs : HashSet < [ u8 ; 32 ] > ,
452
+ payment_hash : Option < PaymentHash > ,
452
453
} ,
453
454
}
454
455
@@ -472,23 +473,32 @@ impl PendingOutboundPayment {
472
473
}
473
474
}
474
475
476
+ fn payment_hash ( & self ) -> Option < PaymentHash > {
477
+ match self {
478
+ PendingOutboundPayment :: Legacy { .. } => None ,
479
+ PendingOutboundPayment :: Retryable { payment_hash, .. } => Some ( * payment_hash) ,
480
+ PendingOutboundPayment :: Fulfilled { payment_hash, .. } => * payment_hash,
481
+ }
482
+ }
483
+
475
484
fn mark_fulfilled ( & mut self ) {
476
485
let mut session_privs = HashSet :: new ( ) ;
477
486
core:: mem:: swap ( & mut session_privs, match self {
478
487
PendingOutboundPayment :: Legacy { session_privs } |
479
488
PendingOutboundPayment :: Retryable { session_privs, .. } |
480
- PendingOutboundPayment :: Fulfilled { session_privs }
489
+ PendingOutboundPayment :: Fulfilled { session_privs, .. }
481
490
=> session_privs
482
491
} ) ;
483
- * self = PendingOutboundPayment :: Fulfilled { session_privs } ;
492
+ let payment_hash = self . payment_hash ( ) ;
493
+ * self = PendingOutboundPayment :: Fulfilled { session_privs, payment_hash } ;
484
494
}
485
495
486
496
/// panics if path is None and !self.is_fulfilled
487
497
fn remove ( & mut self , session_priv : & [ u8 ; 32 ] , path : Option < & Vec < RouteHop > > ) -> bool {
488
498
let remove_res = match self {
489
499
PendingOutboundPayment :: Legacy { session_privs } |
490
500
PendingOutboundPayment :: Retryable { session_privs, .. } |
491
- PendingOutboundPayment :: Fulfilled { session_privs } => {
501
+ PendingOutboundPayment :: Fulfilled { session_privs, .. } => {
492
502
session_privs. remove ( session_priv)
493
503
}
494
504
} ;
@@ -529,7 +539,7 @@ impl PendingOutboundPayment {
529
539
match self {
530
540
PendingOutboundPayment :: Legacy { session_privs } |
531
541
PendingOutboundPayment :: Retryable { session_privs, .. } |
532
- PendingOutboundPayment :: Fulfilled { session_privs } => {
542
+ PendingOutboundPayment :: Fulfilled { session_privs, .. } => {
533
543
session_privs. len ( )
534
544
}
535
545
}
@@ -3503,6 +3513,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3503
3513
pending_events. push (
3504
3514
events:: Event :: PaymentPathSuccessful {
3505
3515
payment_id,
3516
+ payment_hash : payment. get ( ) . payment_hash ( ) ,
3506
3517
path,
3507
3518
}
3508
3519
) ;
@@ -3546,9 +3557,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3546
3557
// TODO: We should have a second monitor event that informs us of payments
3547
3558
// irrevocably fulfilled.
3548
3559
if payment. get_mut ( ) . remove ( & session_priv_bytes, Some ( & path) ) {
3560
+ let payment_hash = Some ( PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 ) . into_inner ( ) ) ) ;
3549
3561
pending_events. push (
3550
3562
events:: Event :: PaymentPathSuccessful {
3551
3563
payment_id,
3564
+ payment_hash,
3552
3565
path,
3553
3566
}
3554
3567
) ;
@@ -5576,6 +5589,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
5576
5589
} ,
5577
5590
( 1 , Fulfilled ) => {
5578
5591
( 0 , session_privs, required) ,
5592
+ ( 1 , payment_hash, option) ,
5579
5593
} ,
5580
5594
( 2 , Retryable ) => {
5581
5595
( 0 , session_privs, required) ,
@@ -6355,15 +6369,17 @@ mod tests {
6355
6369
_ => panic ! ( "Unexpected event" ) ,
6356
6370
}
6357
6371
match events[ 1 ] {
6358
- Event :: PaymentPathSuccessful { payment_id : ref actual_payment_id, ref path } => {
6372
+ Event :: PaymentPathSuccessful { payment_id : ref actual_payment_id, ref payment_hash , ref path } => {
6359
6373
assert_eq ! ( payment_id, * actual_payment_id) ;
6374
+ assert_eq ! ( our_payment_hash, * payment_hash. as_ref( ) . unwrap( ) ) ;
6360
6375
assert_eq ! ( route. paths[ 0 ] , * path) ;
6361
6376
} ,
6362
6377
_ => panic ! ( "Unexpected event" ) ,
6363
6378
}
6364
6379
match events[ 2 ] {
6365
- Event :: PaymentPathSuccessful { payment_id : ref actual_payment_id, ref path } => {
6380
+ Event :: PaymentPathSuccessful { payment_id : ref actual_payment_id, ref payment_hash , ref path } => {
6366
6381
assert_eq ! ( payment_id, * actual_payment_id) ;
6382
+ assert_eq ! ( our_payment_hash, * payment_hash. as_ref( ) . unwrap( ) ) ;
6367
6383
assert_eq ! ( route. paths[ 0 ] , * path) ;
6368
6384
} ,
6369
6385
_ => panic ! ( "Unexpected event" ) ,
0 commit comments