Skip to content

Expose more info in PaymentForwarded #1391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TheBlueMatt opened this issue Mar 27, 2022 · 8 comments · Fixed by #1419 or #1475
Closed

Expose more info in PaymentForwarded #1391

TheBlueMatt opened this issue Mar 27, 2022 · 8 comments · Fixed by #1419 or #1475
Labels
good first issue Good for newcomers
Milestone

Comments

@TheBlueMatt
Copy link
Collaborator

When this was added I figured we should be conservative to avoid users logging exact forwarding history (this is bad for network-wide privacy!) but that doesn't mean important info isn't missing from them that users will want. Ultimately I think we have to air on the side of features, not privacy, sadly - while we shouldn't bother to include the payment hash, I think, we should include things like the source + sink nodes/channels in the event.

@TheBlueMatt TheBlueMatt added the good first issue Good for newcomers label Mar 27, 2022
@TheBlueMatt TheBlueMatt added this to the 0.1.1 milestone Mar 27, 2022
@atalw
Copy link
Contributor

atalw commented Mar 29, 2022

Do we want the source key to be a PublicKey type or HTLCSource type? Don't have easy access to data for both so I think we'll have to move things around a bit. Also could you please elaborate a little on what sink nodes and sink channels are?

@TheBlueMatt
Copy link
Collaborator Author

No, HTLCSource is an internal type with a bunch of additional data and cryptographic material we need to fail backwards. We'll want to use a PublicKey and/or channel id (as a [u8; 32]) maybe both.

@keyuebao
Copy link
Contributor

Having a channel id here would be super helpful 👍

@ghost
Copy link

ghost commented Apr 3, 2022

If no one is already working on this, I'd like to take this on. I can probably have this completed by next weekend.

(p.s. I appreciate the good first issue labels, ty)

Notes for self

Event is described here

/// This event is generated when a payment has been successfully forwarded through us and a
/// forwarding fee earned.
PaymentForwarded {
/// The fee, in milli-satoshis, which was earned as a result of the payment.
///
/// Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC
/// was pending, the amount the next hop claimed will have been rounded down to the nearest
/// whole satoshi. Thus, the fee calculated here may be higher than expected as we still
/// claimed the full value in millisatoshis from the source. In this case,
/// `claim_from_onchain_tx` will be set.
///
/// If the channel which sent us the payment has been force-closed, we will claim the funds
/// via an on-chain transaction. In that case we do not yet know the on-chain transaction
/// fees which we will spend and will instead set this to `None`. It is possible duplicate
/// `PaymentForwarded` events are generated for the same payment iff `fee_earned_msat` is
/// `None`.
fee_earned_msat: Option<u64>,
/// If this is `true`, the forwarded HTLC was claimed by our counterparty via an on-chain
/// transaction.
claim_from_onchain_tx: bool,
},

and at quick glance, the references to update are

&Event::PaymentForwarded { fee_earned_msat, claim_from_onchain_tx } => {
7u8.write(writer)?;
write_tlv_fields!(writer, {
(0, fee_earned_msat, option),
(2, claim_from_onchain_tx, required),
});

and
7u8 => {
let f = || {
let mut fee_earned_msat = None;
let mut claim_from_onchain_tx = false;
read_tlv_fields!(reader, {
(0, fee_earned_msat, option),
(2, claim_from_onchain_tx, required),
});
Ok(Some(Event::PaymentForwarded { fee_earned_msat, claim_from_onchain_tx }))
};
f()
},

and
pending_events.push(events::Event::PaymentForwarded {
fee_earned_msat,
claim_from_onchain_tx: from_onchain,
});

There's also tests, mostly calling this macro

macro_rules! expect_payment_forwarded {
($node: expr, $expected_fee: expr, $upstream_force_closed: expr) => {
let events = $node.node.get_and_clear_pending_events();
assert_eq!(events.len(), 1);
match events[0] {
Event::PaymentForwarded { fee_earned_msat, claim_from_onchain_tx } => {
assert_eq!(fee_earned_msat, $expected_fee);
assert_eq!(claim_from_onchain_tx, $upstream_force_closed);
},
_ => panic!("Unexpected event"),
}
}
}

@atalw
Copy link
Contributor

atalw commented Apr 4, 2022

I've been working on this and am nearing completion. There is one bug (unexpected behaviour?) which is causing a few tests to fail so maybe you could help out. Please refer to these comments:
Comment one
Comment two

@TheBlueMatt
Copy link
Collaborator Author

We should still expose the destination/sink channel id, #1419 only exposed the source.

@TheBlueMatt TheBlueMatt reopened this Apr 20, 2022
@atalw
Copy link
Contributor

atalw commented Apr 20, 2022

I'll add that next!

@TheBlueMatt
Copy link
Collaborator Author

You may want to take a look at #1231, which had actually implemented that half as well, but wasn't actively being worked on. Should be able to copy a bunch of that work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
3 participants