Skip to content

Commit e0d81ca

Browse files
authored
Merge pull request #3458 from shaavan/i3455
Include counterparty node ids in PaymentForwarded
2 parents ddeaab6 + e454525 commit e0d81ca

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

lightning/src/events/mod.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,16 @@ pub enum Event {
11841184
/// caveat described for the `total_fee_earned_msat` field. Moreover it will be `None` for
11851185
/// events generated or serialized by versions prior to 0.0.122.
11861186
next_user_channel_id: Option<u128>,
1187+
/// The node id of the previous node.
1188+
///
1189+
/// This is only `None` for HTLCs received prior to 0.1 or for events serialized by
1190+
/// versions prior to 0.1
1191+
prev_node_id: Option<PublicKey>,
1192+
/// The node id of the next node.
1193+
///
1194+
/// This is only `None` for HTLCs received prior to 0.1 or for events serialized by
1195+
/// versions prior to 0.1
1196+
next_node_id: Option<PublicKey>,
11871197
/// The total fee, in milli-satoshis, which was earned as a result of the payment.
11881198
///
11891199
/// Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC
@@ -1601,8 +1611,8 @@ impl Writeable for Event {
16011611
}
16021612
&Event::PaymentForwarded {
16031613
prev_channel_id, next_channel_id, prev_user_channel_id, next_user_channel_id,
1604-
total_fee_earned_msat, skimmed_fee_msat, claim_from_onchain_tx,
1605-
outbound_amount_forwarded_msat,
1614+
prev_node_id, next_node_id, total_fee_earned_msat, skimmed_fee_msat,
1615+
claim_from_onchain_tx, outbound_amount_forwarded_msat,
16061616
} => {
16071617
7u8.write(writer)?;
16081618
write_tlv_fields!(writer, {
@@ -1614,6 +1624,8 @@ impl Writeable for Event {
16141624
(7, skimmed_fee_msat, option),
16151625
(9, prev_user_channel_id, option),
16161626
(11, next_user_channel_id, option),
1627+
(13, prev_node_id, option),
1628+
(15, next_node_id, option),
16171629
});
16181630
},
16191631
&Event::ChannelClosed { ref channel_id, ref user_channel_id, ref reason,
@@ -1981,6 +1993,8 @@ impl MaybeReadable for Event {
19811993
let mut next_channel_id = None;
19821994
let mut prev_user_channel_id = None;
19831995
let mut next_user_channel_id = None;
1996+
let mut prev_node_id = None;
1997+
let mut next_node_id = None;
19841998
let mut total_fee_earned_msat = None;
19851999
let mut skimmed_fee_msat = None;
19862000
let mut claim_from_onchain_tx = false;
@@ -1994,11 +2008,14 @@ impl MaybeReadable for Event {
19942008
(7, skimmed_fee_msat, option),
19952009
(9, prev_user_channel_id, option),
19962010
(11, next_user_channel_id, option),
2011+
(13, prev_node_id, option),
2012+
(15, next_node_id, option),
19972013
});
19982014
Ok(Some(Event::PaymentForwarded {
19992015
prev_channel_id, next_channel_id, prev_user_channel_id,
2000-
next_user_channel_id, total_fee_earned_msat, skimmed_fee_msat,
2001-
claim_from_onchain_tx, outbound_amount_forwarded_msat,
2016+
next_user_channel_id, prev_node_id, next_node_id,
2017+
total_fee_earned_msat, skimmed_fee_msat, claim_from_onchain_tx,
2018+
outbound_amount_forwarded_msat,
20022019
}))
20032020
};
20042021
f()

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7309,6 +7309,7 @@ where
73097309
HTLCSource::PreviousHopData(hop_data) => {
73107310
let prev_channel_id = hop_data.channel_id;
73117311
let prev_user_channel_id = hop_data.user_channel_id;
7312+
let prev_node_id = hop_data.counterparty_node_id;
73127313
let completed_blocker = RAAMonitorUpdateBlockingAction::from_prev_hop_data(&hop_data);
73137314
self.claim_funds_from_hop(hop_data, payment_preimage, None,
73147315
|htlc_claim_value_msat, definitely_duplicate| {
@@ -7358,6 +7359,8 @@ where
73587359
next_channel_id: Some(next_channel_id),
73597360
prev_user_channel_id,
73607361
next_user_channel_id,
7362+
prev_node_id,
7363+
next_node_id: next_channel_counterparty_node_id,
73617364
total_fee_earned_msat,
73627365
skimmed_fee_msat,
73637366
claim_from_onchain_tx: from_onchain,

lightning/src/ln/functional_test_utils.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2360,7 +2360,8 @@ pub fn expect_payment_forwarded<CM: AChannelManager, H: NodeHolder<CM=CM>>(
23602360
match event {
23612361
Event::PaymentForwarded {
23622362
prev_channel_id, next_channel_id, prev_user_channel_id, next_user_channel_id,
2363-
total_fee_earned_msat, skimmed_fee_msat, claim_from_onchain_tx, ..
2363+
prev_node_id, next_node_id, total_fee_earned_msat,
2364+
skimmed_fee_msat, claim_from_onchain_tx, ..
23642365
} => {
23652366
if allow_1_msat_fee_overpay {
23662367
// Aggregating fees for blinded paths may result in a rounding error, causing slight
@@ -2379,6 +2380,7 @@ pub fn expect_payment_forwarded<CM: AChannelManager, H: NodeHolder<CM=CM>>(
23792380
// Is the event prev_channel_id in one of the channels between the two nodes?
23802381
assert!(node.node().list_channels().iter().any(|x|
23812382
x.counterparty.node_id == prev_node.node().get_our_node_id() &&
2383+
prev_node.node().get_our_node_id() == prev_node_id.unwrap() &&
23822384
x.channel_id == prev_channel_id.unwrap() &&
23832385
x.user_channel_id == prev_user_channel_id.unwrap()
23842386
));
@@ -2393,11 +2395,13 @@ pub fn expect_payment_forwarded<CM: AChannelManager, H: NodeHolder<CM=CM>>(
23932395
if total_fee_earned_msat.is_none() {
23942396
assert!(node.node().list_channels().iter().any(|x|
23952397
x.counterparty.node_id == next_node.node().get_our_node_id() &&
2398+
next_node.node().get_our_node_id() == next_node_id.unwrap() &&
23962399
x.channel_id == next_channel_id.unwrap()
23972400
));
23982401
} else {
23992402
assert!(node.node().list_channels().iter().any(|x|
24002403
x.counterparty.node_id == next_node.node().get_our_node_id() &&
2404+
next_node.node().get_our_node_id() == next_node_id.unwrap() &&
24012405
x.channel_id == next_channel_id.unwrap() &&
24022406
x.user_channel_id == next_user_channel_id.unwrap()
24032407
));
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
API Updates
2+
===========
3+
4+
To improve clarity and uniqueness in identifying forwarded payments, the `PaymentForwarded`
5+
event now includes counterparty node IDs alongside `ChannelIds`. This change resolves
6+
potential ambiguity in cases like v1 0conf channel opens, where `ChannelIds` alone may not
7+
be unique.

0 commit comments

Comments
 (0)