Skip to content

Commit 960c199

Browse files
committed
Generate PaymentFailed events for outbound payments we fail
1 parent ffc2544 commit 960c199

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

src/ln/channelmanager.rs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,6 +1559,10 @@ impl ChannelManager {
15591559
});
15601560
} else {
15611561
//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+
});
15621566
}
15631567
},
15641568
HTLCSource::PreviousHopData(HTLCPreviousHopData { short_channel_id, htlc_id, incoming_packet_shared_secret }) => {
@@ -5993,7 +5997,7 @@ mod tests {
59935997
send_payment(&nodes[0], &vec!(&nodes[1])[..], 8000000);
59945998
// 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
59955999
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);
59976001

59986002
// Get the will-be-revoked local txn from node[0]
59996003
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 {
60106014

60116015
{
60126016
let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
6013-
60146017
nodes[0].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![revoked_local_txn[0].clone()] }, 1);
6015-
60166018
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+
60176029
let node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap();
60186030
assert_eq!(node_txn.len(), 4);
60196031

@@ -6059,7 +6071,7 @@ mod tests {
60596071
// 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
60606072
// time as two different claim transactions as we're gonna to timeout htlc with given a high current height
60616073
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);
60636075

60646076
// Get the will-be-revoked local txn from node[0]
60656077
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 {
60696081

60706082
{
60716083
let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
6072-
60736084
nodes[0].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![revoked_local_txn[0].clone()] }, 200);
6074-
60756085
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+
60766096
let node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap();
60776097
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)
60786098

0 commit comments

Comments
 (0)