Skip to content

Commit 4fdefbb

Browse files
committed
adds 'our_node_id' to 'Event::Payment{Received,Claimed}' and includes updates to functional test cases
1 parent 7269fa2 commit 4fdefbb

File tree

5 files changed

+39
-12
lines changed

5 files changed

+39
-12
lines changed

lightning/src/ln/chanmon_update_fail_tests.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,10 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool) {
200200
let events_3 = nodes[1].node.get_and_clear_pending_events();
201201
assert_eq!(events_3.len(), 1);
202202
match events_3[0] {
203-
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
203+
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat, node_id } => {
204204
assert_eq!(payment_hash_1, *payment_hash);
205205
assert_eq!(amount_msat, 1_000_000);
206+
assert_eq!(node_id.unwrap(), nodes[1].node.get_our_node_id());
206207
match &purpose {
207208
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
208209
assert!(payment_preimage.is_none());
@@ -568,9 +569,10 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) {
568569
let events_5 = nodes[1].node.get_and_clear_pending_events();
569570
assert_eq!(events_5.len(), 1);
570571
match events_5[0] {
571-
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
572+
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat, node_id } => {
572573
assert_eq!(payment_hash_2, *payment_hash);
573574
assert_eq!(amount_msat, 1_000_000);
575+
assert_eq!(node_id.unwrap(), nodes[1].node.get_our_node_id());
574576
match &purpose {
575577
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
576578
assert!(payment_preimage.is_none());
@@ -685,9 +687,10 @@ fn test_monitor_update_fail_cs() {
685687
let events = nodes[1].node.get_and_clear_pending_events();
686688
assert_eq!(events.len(), 1);
687689
match events[0] {
688-
Event::PaymentReceived { payment_hash, ref purpose, amount_msat } => {
690+
Event::PaymentReceived { payment_hash, ref purpose, amount_msat, node_id } => {
689691
assert_eq!(payment_hash, our_payment_hash);
690692
assert_eq!(amount_msat, 1_000_000);
693+
assert_eq!(node_id.unwrap(), nodes[1].node.get_our_node_id());
691694
match &purpose {
692695
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
693696
assert!(payment_preimage.is_none());
@@ -1659,9 +1662,10 @@ fn test_monitor_update_fail_claim() {
16591662
let events = nodes[0].node.get_and_clear_pending_events();
16601663
assert_eq!(events.len(), 2);
16611664
match events[0] {
1662-
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
1665+
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat, node_id } => {
16631666
assert_eq!(payment_hash_2, *payment_hash);
16641667
assert_eq!(1_000_000, amount_msat);
1668+
assert_eq!(node_id.unwrap(), nodes[0].node.get_our_node_id());
16651669
match &purpose {
16661670
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
16671671
assert!(payment_preimage.is_none());
@@ -1673,9 +1677,10 @@ fn test_monitor_update_fail_claim() {
16731677
_ => panic!("Unexpected event"),
16741678
}
16751679
match events[1] {
1676-
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
1680+
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat, node_id } => {
16771681
assert_eq!(payment_hash_3, *payment_hash);
16781682
assert_eq!(1_000_000, amount_msat);
1683+
assert_eq!(node_id.unwrap(), nodes[0].node.get_our_node_id());
16791684
match &purpose {
16801685
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
16811686
assert!(payment_preimage.is_none());

lightning/src/ln/channelmanager.rs

+4
Original file line numberDiff line numberDiff line change
@@ -3486,6 +3486,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
34863486
} else if total_value == $payment_data.total_msat {
34873487
htlcs.push(claimable_htlc);
34883488
new_events.push(events::Event::PaymentReceived {
3489+
node_id: Some(self.our_network_pubkey),
34893490
payment_hash,
34903491
purpose: purpose(),
34913492
amount_msat: total_value,
@@ -3528,6 +3529,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
35283529
let purpose = events::PaymentPurpose::SpontaneousPayment(preimage);
35293530
e.insert((purpose.clone(), vec![claimable_htlc]));
35303531
new_events.push(events::Event::PaymentReceived {
3532+
node_id: Some(self.our_network_pubkey),
35313533
payment_hash,
35323534
amount_msat: outgoing_amt_msat,
35333535
purpose,
@@ -4274,6 +4276,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
42744276

42754277
if claimed_any_htlcs {
42764278
self.pending_events.lock().unwrap().push(events::Event::PaymentClaimed {
4279+
node_id: Some(self.our_network_pubkey),
42774280
payment_hash,
42784281
purpose: payment_purpose,
42794282
amount_msat: claimable_amt_msat,
@@ -7514,6 +7517,7 @@ impl<'a, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
75147517
}
75157518
}
75167519
pending_events_read.push(events::Event::PaymentClaimed {
7520+
node_id: Some(our_network_pubkey),
75177521
payment_hash,
75187522
purpose: payment_purpose,
75197523
amount_msat: claimable_amt_msat,

lightning/src/ln/functional_test_utils.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1444,9 +1444,10 @@ macro_rules! expect_payment_received {
14441444
let events = $node.node.get_and_clear_pending_events();
14451445
assert_eq!(events.len(), 1);
14461446
match events[0] {
1447-
$crate::util::events::Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
1447+
$crate::util::events::Event::PaymentReceived {ref payment_hash, ref purpose, amount_msat, node_id } => {
14481448
assert_eq!($expected_payment_hash, *payment_hash);
14491449
assert_eq!($expected_recv_value, amount_msat);
1450+
assert_eq!($node.node.get_our_node_id(), node_id.unwrap());
14501451
match purpose {
14511452
$crate::util::events::PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
14521453
assert_eq!(&$expected_payment_preimage, payment_preimage);
@@ -1738,8 +1739,9 @@ pub fn do_pass_along_path<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_p
17381739
if payment_received_expected {
17391740
assert_eq!(events_2.len(), 1);
17401741
match events_2[0] {
1741-
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
1742+
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat, node_id } => {
17421743
assert_eq!(our_payment_hash, *payment_hash);
1744+
assert_eq!(node.node.get_our_node_id(), node_id.unwrap());
17431745
match &purpose {
17441746
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
17451747
assert_eq!(expected_preimage, *payment_preimage);

lightning/src/ln/functional_tests.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1956,9 +1956,10 @@ fn test_channel_reserve_holding_cell_htlcs() {
19561956
let events = nodes[2].node.get_and_clear_pending_events();
19571957
assert_eq!(events.len(), 2);
19581958
match events[0] {
1959-
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
1959+
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat, node_id } => {
19601960
assert_eq!(our_payment_hash_21, *payment_hash);
19611961
assert_eq!(recv_value_21, amount_msat);
1962+
assert_eq!(nodes[2].node.get_our_node_id(), node_id.unwrap());
19621963
match &purpose {
19631964
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
19641965
assert!(payment_preimage.is_none());
@@ -1970,9 +1971,10 @@ fn test_channel_reserve_holding_cell_htlcs() {
19701971
_ => panic!("Unexpected event"),
19711972
}
19721973
match events[1] {
1973-
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
1974+
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat, node_id } => {
19741975
assert_eq!(our_payment_hash_22, *payment_hash);
19751976
assert_eq!(recv_value_22, amount_msat);
1977+
assert_eq!(nodes[2].node.get_our_node_id(), node_id.unwrap());
19761978
match &purpose {
19771979
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
19781980
assert!(payment_preimage.is_none());
@@ -3723,9 +3725,10 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8, simulate_broken
37233725
let events_2 = nodes[1].node.get_and_clear_pending_events();
37243726
assert_eq!(events_2.len(), 1);
37253727
match events_2[0] {
3726-
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
3728+
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat, node_id } => {
37273729
assert_eq!(payment_hash_1, *payment_hash);
37283730
assert_eq!(amount_msat, 1_000_000);
3731+
assert_eq!(node_id.unwrap(), nodes[1].node.get_our_node_id());
37293732
match &purpose {
37303733
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
37313734
assert!(payment_preimage.is_none());

lightning/src/util/events.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ pub enum Event {
342342
/// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
343343
/// [`ChannelManager::fail_htlc_backwards`]: crate::ln::channelmanager::ChannelManager::fail_htlc_backwards
344344
PaymentReceived {
345+
/// The received node, ie whether the node was a phantom node or not.
346+
node_id: Option<PublicKey>,
345347
/// The hash for which the preimage should be handed to the ChannelManager. Note that LDK will
346348
/// not stop you from registering duplicate payment hashes for inbound payments.
347349
payment_hash: PaymentHash,
@@ -366,6 +368,8 @@ pub enum Event {
366368
///
367369
/// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
368370
PaymentClaimed {
371+
/// The received node, ie whether the node was a phantom node or not.
372+
node_id: Option<PublicKey>,
369373
/// The payment hash of the claimed payment. Note that LDK will not stop you from
370374
/// registering duplicate payment hashes for inbound payments.
371375
payment_hash: PaymentHash,
@@ -739,7 +743,7 @@ impl Writeable for Event {
739743
// We never write out FundingGenerationReady events as, upon disconnection, peers
740744
// drop any channels which have not yet exchanged funding_signed.
741745
},
742-
&Event::PaymentReceived { ref payment_hash, ref amount_msat, ref purpose } => {
746+
&Event::PaymentReceived { ref node_id, ref payment_hash, ref amount_msat, ref purpose } => {
743747
1u8.write(writer)?;
744748
let mut payment_secret = None;
745749
let payment_preimage;
@@ -758,6 +762,7 @@ impl Writeable for Event {
758762
(4, amount_msat, required),
759763
(6, 0u64, required), // user_payment_id required for compatibility with 0.0.103 and earlier
760764
(8, payment_preimage, option),
765+
(10, node_id, required),
761766
});
762767
},
763768
&Event::PaymentSent { ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat } => {
@@ -854,12 +859,13 @@ impl Writeable for Event {
854859
// We never write the OpenChannelRequest events as, upon disconnection, peers
855860
// drop any channels which have not yet exchanged funding_signed.
856861
},
857-
&Event::PaymentClaimed { ref payment_hash, ref amount_msat, ref purpose } => {
862+
&Event::PaymentClaimed { ref node_id, ref payment_hash, ref amount_msat, ref purpose } => {
858863
19u8.write(writer)?;
859864
write_tlv_fields!(writer, {
860865
(0, payment_hash, required),
861866
(2, purpose, required),
862867
(4, amount_msat, required),
868+
(6, node_id, required),
863869
});
864870
},
865871
&Event::ProbeSuccessful { ref payment_id, ref payment_hash, ref path } => {
@@ -923,13 +929,15 @@ impl MaybeReadable for Event {
923929
let mut payment_preimage = None;
924930
let mut payment_secret = None;
925931
let mut amount_msat = 0;
932+
let mut node_id = None;
926933
let mut _user_payment_id = None::<u64>; // For compatibility with 0.0.103 and earlier
927934
read_tlv_fields!(reader, {
928935
(0, payment_hash, required),
929936
(2, payment_secret, option),
930937
(4, amount_msat, required),
931938
(6, _user_payment_id, option),
932939
(8, payment_preimage, option),
940+
(10, node_id, required),
933941
});
934942
let purpose = match payment_secret {
935943
Some(secret) => PaymentPurpose::InvoicePayment {
@@ -940,6 +948,7 @@ impl MaybeReadable for Event {
940948
None => return Err(msgs::DecodeError::InvalidValue),
941949
};
942950
Ok(Some(Event::PaymentReceived {
951+
node_id,
943952
payment_hash,
944953
amount_msat,
945954
purpose,
@@ -1117,13 +1126,17 @@ impl MaybeReadable for Event {
11171126
let mut payment_hash = PaymentHash([0; 32]);
11181127
let mut purpose = None;
11191128
let mut amount_msat = 0;
1129+
let mut node_id = None;
11201130
read_tlv_fields!(reader, {
11211131
(0, payment_hash, required),
11221132
(2, purpose, ignorable),
11231133
(4, amount_msat, required),
1134+
(6, node_id, required),
11241135
});
11251136
if purpose.is_none() { return Ok(None); }
1137+
11261138
Ok(Some(Event::PaymentClaimed {
1139+
node_id,
11271140
payment_hash,
11281141
purpose: purpose.unwrap(),
11291142
amount_msat,

0 commit comments

Comments
 (0)