@@ -1559,6 +1559,10 @@ impl ChannelManager {
1559
1559
} ) ;
1560
1560
} else {
1561
1561
//TODO: Pass this back (see GH #243)
1562
+ self . pending_events . lock ( ) . unwrap ( ) . push ( events:: Event :: PaymentFailed {
1563
+ payment_hash : payment_hash. clone ( ) ,
1564
+ rejected_by_dest : false , // We failed it ourselves, can't blame them
1565
+ } ) ;
1562
1566
}
1563
1567
} ,
1564
1568
HTLCSource :: PreviousHopData ( HTLCPreviousHopData { short_channel_id, htlc_id, incoming_packet_shared_secret } ) => {
@@ -5993,7 +5997,7 @@ mod tests {
5993
5997
send_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 8000000 ) ;
5994
5998
// node[0] is gonna to revoke an old state thus node[1] should be able to claim both offered/received HTLC outputs on top of commitment tx
5995
5999
let payment_preimage_1 = route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 3000000 ) . 0 ;
5996
- let _payment_preimage_2 = route_payment ( & nodes[ 1 ] , & vec ! ( & nodes[ 0 ] ) [ ..] , 3000000 ) . 0 ;
6000
+ let ( _payment_preimage_2, payment_hash_2 ) = route_payment ( & nodes[ 1 ] , & vec ! ( & nodes[ 0 ] ) [ ..] , 3000000 ) ;
5997
6001
5998
6002
// Get the will-be-revoked local txn from node[0]
5999
6003
let revoked_local_txn = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
@@ -6010,10 +6014,18 @@ mod tests {
6010
6014
6011
6015
{
6012
6016
let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
6013
-
6014
6017
nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 1 ) ;
6015
-
6016
6018
nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 1 ) ;
6019
+
6020
+ let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
6021
+ assert_eq ! ( events. len( ) , 1 ) ;
6022
+ match events[ 0 ] {
6023
+ Event :: PaymentFailed { payment_hash, .. } => {
6024
+ assert_eq ! ( payment_hash, payment_hash_2) ;
6025
+ } ,
6026
+ _ => panic ! ( "Unexpected event" ) ,
6027
+ }
6028
+
6017
6029
let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
6018
6030
assert_eq ! ( node_txn. len( ) , 4 ) ;
6019
6031
@@ -6059,7 +6071,7 @@ mod tests {
6059
6071
// node[0] is gonna to revoke an old state thus node[1] should be able to claim both offered/received HTLC outputs on top of commitment tx, but this
6060
6072
// time as two different claim transactions as we're gonna to timeout htlc with given a high current height
6061
6073
let payment_preimage_1 = route_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , 3000000 ) . 0 ;
6062
- let _payment_preimage_2 = route_payment ( & nodes[ 1 ] , & vec ! ( & nodes[ 0 ] ) [ ..] , 3000000 ) . 0 ;
6074
+ let ( _payment_preimage_2, payment_hash_2 ) = route_payment ( & nodes[ 1 ] , & vec ! ( & nodes[ 0 ] ) [ ..] , 3000000 ) ;
6063
6075
6064
6076
// Get the will-be-revoked local txn from node[0]
6065
6077
let revoked_local_txn = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
@@ -6069,10 +6081,18 @@ mod tests {
6069
6081
6070
6082
{
6071
6083
let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
6072
-
6073
6084
nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 200 ) ;
6074
-
6075
6085
nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 200 ) ;
6086
+
6087
+ let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
6088
+ assert_eq ! ( events. len( ) , 1 ) ;
6089
+ match events[ 0 ] {
6090
+ Event :: PaymentFailed { payment_hash, .. } => {
6091
+ assert_eq ! ( payment_hash, payment_hash_2) ;
6092
+ } ,
6093
+ _ => panic ! ( "Unexpected event" ) ,
6094
+ }
6095
+
6076
6096
let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
6077
6097
assert_eq ! ( node_txn. len( ) , 12 ) ; // ChannelManager : 2, ChannelMontitor: 8 (1 standard revoked output, 2 revocation htlc tx, 1 local commitment tx + 1 htlc timeout tx) * 2 (block-rescan)
6078
6098
0 commit comments