Skip to content

Commit 657093f

Browse files
committed
adds 'our_node_id' to 'Event::Payment{Received,Claimed}' and includes updates to functional test cases
1 parent 8abf02c commit 657093f

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
@@ -201,9 +201,10 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool) {
201201
let events_3 = nodes[1].node.get_and_clear_pending_events();
202202
assert_eq!(events_3.len(), 1);
203203
match events_3[0] {
204-
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
204+
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat, node_id } => {
205205
assert_eq!(payment_hash_1, *payment_hash);
206206
assert_eq!(amount_msat, 1_000_000);
207+
assert_eq!(node_id.unwrap(), nodes[1].node.get_our_node_id());
207208
match &purpose {
208209
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
209210
assert!(payment_preimage.is_none());
@@ -569,9 +570,10 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) {
569570
let events_5 = nodes[1].node.get_and_clear_pending_events();
570571
assert_eq!(events_5.len(), 1);
571572
match events_5[0] {
572-
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
573+
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat, node_id } => {
573574
assert_eq!(payment_hash_2, *payment_hash);
574575
assert_eq!(amount_msat, 1_000_000);
576+
assert_eq!(node_id.unwrap(), nodes[1].node.get_our_node_id());
575577
match &purpose {
576578
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
577579
assert!(payment_preimage.is_none());
@@ -686,9 +688,10 @@ fn test_monitor_update_fail_cs() {
686688
let events = nodes[1].node.get_and_clear_pending_events();
687689
assert_eq!(events.len(), 1);
688690
match events[0] {
689-
Event::PaymentReceived { payment_hash, ref purpose, amount_msat } => {
691+
Event::PaymentReceived { payment_hash, ref purpose, amount_msat, node_id } => {
690692
assert_eq!(payment_hash, our_payment_hash);
691693
assert_eq!(amount_msat, 1_000_000);
694+
assert_eq!(node_id.unwrap(), nodes[1].node.get_our_node_id());
692695
match &purpose {
693696
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
694697
assert!(payment_preimage.is_none());
@@ -1660,9 +1663,10 @@ fn test_monitor_update_fail_claim() {
16601663
let events = nodes[0].node.get_and_clear_pending_events();
16611664
assert_eq!(events.len(), 2);
16621665
match events[0] {
1663-
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
1666+
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat, node_id } => {
16641667
assert_eq!(payment_hash_2, *payment_hash);
16651668
assert_eq!(1_000_000, amount_msat);
1669+
assert_eq!(node_id.unwrap(), nodes[0].node.get_our_node_id());
16661670
match &purpose {
16671671
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
16681672
assert!(payment_preimage.is_none());
@@ -1674,9 +1678,10 @@ fn test_monitor_update_fail_claim() {
16741678
_ => panic!("Unexpected event"),
16751679
}
16761680
match events[1] {
1677-
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
1681+
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat, node_id } => {
16781682
assert_eq!(payment_hash_3, *payment_hash);
16791683
assert_eq!(1_000_000, amount_msat);
1684+
assert_eq!(node_id.unwrap(), nodes[0].node.get_our_node_id());
16801685
match &purpose {
16811686
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
16821687
assert!(payment_preimage.is_none());

lightning/src/ln/channelmanager.rs

+4
Original file line numberDiff line numberDiff line change
@@ -3360,6 +3360,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
33603360
} else if total_value == $payment_data.total_msat {
33613361
htlcs.push(claimable_htlc);
33623362
new_events.push(events::Event::PaymentReceived {
3363+
node_id: Some(self.our_network_pubkey),
33633364
payment_hash,
33643365
purpose: purpose(),
33653366
amount_msat: total_value,
@@ -3402,6 +3403,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
34023403
let purpose = events::PaymentPurpose::SpontaneousPayment(preimage);
34033404
e.insert((purpose.clone(), vec![claimable_htlc]));
34043405
new_events.push(events::Event::PaymentReceived {
3406+
node_id: Some(self.our_network_pubkey),
34053407
payment_hash,
34063408
amount_msat: amt_to_forward,
34073409
purpose,
@@ -4099,6 +4101,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
40994101

41004102
if claimed_any_htlcs {
41014103
self.pending_events.lock().unwrap().push(events::Event::PaymentClaimed {
4104+
node_id: Some(self.our_network_pubkey),
41024105
payment_hash,
41034106
purpose: payment_purpose,
41044107
amount_msat: claimable_amt_msat,
@@ -7225,6 +7228,7 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
72257228
}
72267229
}
72277230
pending_events_read.push(events::Event::PaymentClaimed {
7231+
node_id: Some(our_network_pubkey),
72287232
payment_hash,
72297233
purpose: payment_purpose,
72307234
amount_msat: claimable_amt_msat,

lightning/src/ln/functional_test_utils.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1380,9 +1380,10 @@ macro_rules! expect_payment_received {
13801380
let events = $node.node.get_and_clear_pending_events();
13811381
assert_eq!(events.len(), 1);
13821382
match events[0] {
1383-
$crate::util::events::Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
1383+
$crate::util::events::Event::PaymentReceived {ref payment_hash, ref purpose, amount_msat, node_id } => {
13841384
assert_eq!($expected_payment_hash, *payment_hash);
13851385
assert_eq!($expected_recv_value, amount_msat);
1386+
assert_eq!($node.node.get_our_node_id(), node_id.unwrap());
13861387
match purpose {
13871388
$crate::util::events::PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
13881389
assert_eq!(&$expected_payment_preimage, payment_preimage);
@@ -1660,8 +1661,9 @@ pub fn do_pass_along_path<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_p
16601661
if payment_received_expected {
16611662
assert_eq!(events_2.len(), 1);
16621663
match events_2[0] {
1663-
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
1664+
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat, node_id } => {
16641665
assert_eq!(our_payment_hash, *payment_hash);
1666+
assert_eq!(node.node.get_our_node_id(), node_id.unwrap());
16651667
match &purpose {
16661668
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
16671669
assert_eq!(expected_preimage, *payment_preimage);

lightning/src/ln/functional_tests.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1955,9 +1955,10 @@ fn test_channel_reserve_holding_cell_htlcs() {
19551955
let events = nodes[2].node.get_and_clear_pending_events();
19561956
assert_eq!(events.len(), 2);
19571957
match events[0] {
1958-
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
1958+
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat, node_id } => {
19591959
assert_eq!(our_payment_hash_21, *payment_hash);
19601960
assert_eq!(recv_value_21, amount_msat);
1961+
assert_eq!(nodes[2].node.get_our_node_id(), node_id.unwrap());
19611962
match &purpose {
19621963
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
19631964
assert!(payment_preimage.is_none());
@@ -1969,9 +1970,10 @@ fn test_channel_reserve_holding_cell_htlcs() {
19691970
_ => panic!("Unexpected event"),
19701971
}
19711972
match events[1] {
1972-
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
1973+
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat, node_id } => {
19731974
assert_eq!(our_payment_hash_22, *payment_hash);
19741975
assert_eq!(recv_value_22, amount_msat);
1976+
assert_eq!(nodes[2].node.get_our_node_id(), node_id.unwrap());
19751977
match &purpose {
19761978
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
19771979
assert!(payment_preimage.is_none());
@@ -3726,9 +3728,10 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8, simulate_broken
37263728
let events_2 = nodes[1].node.get_and_clear_pending_events();
37273729
assert_eq!(events_2.len(), 1);
37283730
match events_2[0] {
3729-
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
3731+
Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat, node_id } => {
37303732
assert_eq!(payment_hash_1, *payment_hash);
37313733
assert_eq!(amount_msat, 1_000_000);
3734+
assert_eq!(node_id.unwrap(), nodes[1].node.get_our_node_id());
37323735
match &purpose {
37333736
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
37343737
assert!(payment_preimage.is_none());

lightning/src/util/events.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ pub enum Event {
249249
/// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
250250
/// [`ChannelManager::fail_htlc_backwards`]: crate::ln::channelmanager::ChannelManager::fail_htlc_backwards
251251
PaymentReceived {
252+
/// The received node, ie whether the node was a phantom node or not.
253+
node_id: Option<PublicKey>,
252254
/// The hash for which the preimage should be handed to the ChannelManager. Note that LDK will
253255
/// not stop you from registering duplicate payment hashes for inbound payments.
254256
payment_hash: PaymentHash,
@@ -273,6 +275,8 @@ pub enum Event {
273275
///
274276
/// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
275277
PaymentClaimed {
278+
/// The received node, ie whether the node was a phantom node or not.
279+
node_id: Option<PublicKey>,
276280
/// The payment hash of the claimed payment. Note that LDK will not stop you from
277281
/// registering duplicate payment hashes for inbound payments.
278282
payment_hash: PaymentHash,
@@ -612,7 +616,7 @@ impl Writeable for Event {
612616
// We never write out FundingGenerationReady events as, upon disconnection, peers
613617
// drop any channels which have not yet exchanged funding_signed.
614618
},
615-
&Event::PaymentReceived { ref payment_hash, ref amount_msat, ref purpose } => {
619+
&Event::PaymentReceived { ref node_id, ref payment_hash, ref amount_msat, ref purpose } => {
616620
1u8.write(writer)?;
617621
let mut payment_secret = None;
618622
let payment_preimage;
@@ -631,6 +635,7 @@ impl Writeable for Event {
631635
(4, amount_msat, required),
632636
(6, 0u64, required), // user_payment_id required for compatibility with 0.0.103 and earlier
633637
(8, payment_preimage, option),
638+
(10, node_id, required),
634639
});
635640
},
636641
&Event::PaymentSent { ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat } => {
@@ -721,12 +726,13 @@ impl Writeable for Event {
721726
// We never write the OpenChannelRequest events as, upon disconnection, peers
722727
// drop any channels which have not yet exchanged funding_signed.
723728
},
724-
&Event::PaymentClaimed { ref payment_hash, ref amount_msat, ref purpose } => {
729+
&Event::PaymentClaimed { ref node_id, ref payment_hash, ref amount_msat, ref purpose } => {
725730
19u8.write(writer)?;
726731
write_tlv_fields!(writer, {
727732
(0, payment_hash, required),
728733
(2, purpose, required),
729734
(4, amount_msat, required),
735+
(6, node_id, required),
730736
});
731737
},
732738
&Event::ProbeSuccessful { ref payment_id, ref payment_hash, ref path } => {
@@ -772,13 +778,15 @@ impl MaybeReadable for Event {
772778
let mut payment_preimage = None;
773779
let mut payment_secret = None;
774780
let mut amount_msat = 0;
781+
let mut node_id = None;
775782
let mut _user_payment_id = None::<u64>; // For compatibility with 0.0.103 and earlier
776783
read_tlv_fields!(reader, {
777784
(0, payment_hash, required),
778785
(2, payment_secret, option),
779786
(4, amount_msat, required),
780787
(6, _user_payment_id, option),
781788
(8, payment_preimage, option),
789+
(10, node_id, required),
782790
});
783791
let purpose = match payment_secret {
784792
Some(secret) => PaymentPurpose::InvoicePayment {
@@ -789,6 +797,7 @@ impl MaybeReadable for Event {
789797
None => return Err(msgs::DecodeError::InvalidValue),
790798
};
791799
Ok(Some(Event::PaymentReceived {
800+
node_id,
792801
payment_hash,
793802
amount_msat,
794803
purpose,
@@ -958,13 +967,17 @@ impl MaybeReadable for Event {
958967
let mut payment_hash = PaymentHash([0; 32]);
959968
let mut purpose = None;
960969
let mut amount_msat = 0;
970+
let mut node_id = None;
961971
read_tlv_fields!(reader, {
962972
(0, payment_hash, required),
963973
(2, purpose, ignorable),
964974
(4, amount_msat, required),
975+
(6, node_id, required),
965976
});
966977
if purpose.is_none() { return Ok(None); }
978+
967979
Ok(Some(Event::PaymentClaimed {
980+
node_id,
968981
payment_hash,
969982
purpose: purpose.unwrap(),
970983
amount_msat,

0 commit comments

Comments
 (0)