Skip to content

Add payment_hash to PaymentSent #999 #1062

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

Merged
merged 1 commit into from
Oct 8, 2021

Conversation

galderz
Copy link
Contributor

@galderz galderz commented Aug 27, 2021

Implementation for the payment_hash part of #999.

@galderz
Copy link
Contributor Author

galderz commented Aug 27, 2021

Ups, seems like I was working on a very old main. I'll rebase asap.

@galderz galderz force-pushed the t_payment_hash_999 branch from 88e4998 to d2589bc Compare August 27, 2021 14:30
@galderz
Copy link
Contributor Author

galderz commented Aug 27, 2021

Rebased 😅

@codecov
Copy link

codecov bot commented Aug 27, 2021

Codecov Report

Merging #1062 (204bfd2) into main (801d6e5) will decrease coverage by 0.09%.
The diff coverage is 90.90%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1062      +/-   ##
==========================================
- Coverage   90.76%   90.66%   -0.10%     
==========================================
  Files          65       66       +1     
  Lines       33894    34631     +737     
==========================================
+ Hits        30764    31399     +635     
- Misses       3130     3232     +102     
Impacted Files Coverage Δ
lightning/src/ln/functional_test_utils.rs 95.08% <ø> (+0.01%) ⬆️
lightning/src/ln/reorg_tests.rs 100.00% <ø> (ø)
lightning/src/util/events.rs 32.16% <50.00%> (+4.67%) ⬆️
lightning/src/ln/channelmanager.rs 84.90% <75.00%> (-0.10%) ⬇️
lightning/src/ln/functional_tests.rs 97.39% <92.30%> (-0.15%) ⬇️
lightning/src/ln/chanmon_update_fail_tests.rs 97.77% <100.00%> (+0.01%) ⬆️
lightning/src/ln/shutdown_tests.rs 95.89% <100.00%> (+0.17%) ⬆️
lightning/src/util/ser.rs 89.14% <0.00%> (-2.79%) ⬇️
lightning-block-sync/src/lib.rs 93.49% <0.00%> (-1.69%) ⬇️
lightning/src/ln/script.rs 92.64% <0.00%> (-1.11%) ⬇️
... and 23 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 801d6e5...204bfd2. Read the comment docs.

2u8.write(writer)?;
write_tlv_fields!(writer, {
(0, payment_preimage, required),
(2, payment_hash, required),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be an odd number (implying that old versions will ignore it and be fine with that), and probably also an option at least for the first version (implying that if we deserialize a paymentsent written by an old version we'll just treat it as None. In a future version, we could probably break compat and say "we cannot read old PaymentSent events that are pending".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not do something like this so the payment_hash field doesn't have to be an Option?

diff --git a/lightning/src/util/events.rs b/lightning/src/util/events.rs
index 03553651..8bcb3f2b 100644
--- a/lightning/src/util/events.rs
+++ b/lightning/src/util/events.rs
@@ -21,6 +21,7 @@ use routing::network_graph::NetworkUpdate;
 use util::ser::{Writeable, Writer, MaybeReadable, Readable, VecReadWrapper, VecWriteWrapper};

 use bitcoin::blockdata::script::Script;
+use bitcoin::hashes::sha256::Hash as Sha256;

 use bitcoin::secp256k1::key::PublicKey;

@@ -128,7 +129,7 @@ pub enum Event {
                /// in which case the value of this field will be `None`.
                ///
                /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
-               payment_hash: Option<PaymentHash>,
+               payment_hash: PaymentHash,
        },
        /// Indicates an outbound payment we made failed. Probably some intermediary node dropped
        /// something. You may wish to retry with a different route.
@@ -233,7 +234,7 @@ impl Writeable for Event {
                                2u8.write(writer)?;
                                write_tlv_fields!(writer, {
                                        (0, payment_preimage, required),
-                                       (1, payment_hash, option),
+                                       (1, payment_hash, required),
                                });
                        },
                        &Event::PaymentFailed { ref payment_hash, ref rejected_by_dest, ref network_update, ref all_paths_failed,
@@ -322,9 +323,12 @@ impl MaybeReadable for Event {
                                                (0, payment_preimage, required),
                                                (1, payment_hash, option),
                                        });
+                                       if payment_hash.is_none() {
+                                               payment_hash = Some(PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner()));
+                                       }
                                        Ok(Some(Event::PaymentSent {
                                                payment_preimage,
-                                               payment_hash,
+                                               payment_hash: payment_hash.unwrap(),
                                        }))
                                };
                                f()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yea, actually that's a good idea, would prefer that.

@galderz galderz force-pushed the t_payment_hash_999 branch from d2589bc to 46d4568 Compare August 31, 2021 07:56
@galderz
Copy link
Contributor Author

galderz commented Aug 31, 2021

Pushed a new commit. It should address all the comments raised so far.

@@ -118,6 +118,8 @@ pub enum Event {
/// Note that this serves as a payment receipt, if you wish to have such a thing, you must
/// store it somehow!
payment_preimage: PaymentPreimage,
/// The hash which was given to ChannelManager::send_payment.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a link (ie wrapped in [` and ]). Also, should mention when its None` and when its not (reading old events)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've extended the comment. See the latest update.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Links are resolved locally, so you need to provide a full path at the end which tells cargo doc exactly where to look, eg:

--- a/lightning/src/util/events.rs
+++ b/lightning/src/util/events.rs
@@ -120,5 +120,7 @@ pub enum Event {
                payment_preimage: PaymentPreimage,
-               /// The hash which was given to [ChannelManager::send_payment].
+               /// The hash which was given to [`ChannelManager::send_payment`].
                /// When the payment sent message comes from an older library version,
                /// the payment hash will be missing, in which case the value of this field will be `None`.
+               ///
+               /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
                payment_hash: Option<PaymentHash>,

Copy link
Contributor

@valentinewallace valentinewallace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK mod fixing CI

Comment on lines 122 to 123
/// When the payment sent message comes from an older library version,
/// the payment hash will be missing, in which case the value of this field will be `None`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/payment sent/PaymentSent

nit: 100char lines plz

@galderz galderz force-pushed the t_payment_hash_999 branch 2 times, most recently from 5ccd140 to 1f9788a Compare September 21, 2021 07:57
@galderz
Copy link
Contributor Author

galderz commented Sep 21, 2021

@TheBlueMatt @valentinewallace rebased and pushed a new commit addressing all your latests comments.

Copy link
Contributor

@valentinewallace valentinewallace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last actual question here: #1062 (comment)
Otherwise LGTM

Comment on lines 125 to 128
/// The hash which was given to [`ChannelManager::send_payment`].
/// When the `PaymentSent` message comes from an older library version,
/// the payment hash will be missing,
/// in which case the value of this field will be `None`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: 100char lines

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmm? What line are you exactly complaining about?

The only one that exceeds 100 chars is the last of these:

		/// The hash which was given to [`ChannelManager::send_payment`].
		/// When the `PaymentSent` message comes from an older library version,
		/// the payment hash will be missing,
		/// in which case the value of this field will be `None`.
		///
		/// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment

But, there are plenty of those earlier in the source file

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the diff I'm looking for:

diff --git a/lightning/src/util/events.rs b/lightning/src/util/events.rs
index 03553651..cc54f9b1 100644
--- a/lightning/src/util/events.rs
+++ b/lightning/src/util/events.rs
@@ -122,10 +122,9 @@ pub enum Event {
                /// Note that this serves as a payment receipt, if you wish to have such a thing, you must
                /// store it somehow!
                payment_preimage: PaymentPreimage,
-               /// The hash which was given to [`ChannelManager::send_payment`].
-               /// When the `PaymentSent` message comes from an older library version,
-               /// the payment hash will be missing,
-               /// in which case the value of this field will be `None`.
+               /// The hash which was given to [`ChannelManager::send_payment`]. When the `PaymentSent` message
+               /// comes from an older library version, the payment hash will be missing, in which case the
+               /// value of this field will be `None`.
                ///
                /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
                payment_hash: Option<PaymentHash>,

So we want lines to not be too short or too long.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry but that's not really very helpful feedback. You might as well the exact format that you want :\

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed a change based on your proposal.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the idea is that we want to fit as much text as is reasonable onto the page (hence avoiding too-short lines) in while also allowing multiple terminals side-by-side (hence the line length limit). Vim makes this super easy. Not sure how to be more helpful.

That said, it was a nit so you can ignore it if you really want.

@galderz
Copy link
Contributor Author

galderz commented Sep 28, 2021

Update the commit to address #1062 (comment)

@TheBlueMatt
Copy link
Collaborator

Update the commit to address #1062 (comment)

Hmm, I don't see any change and github seems to think the last push was 6 days ago.

@galderz galderz force-pushed the t_payment_hash_999 branch from df04817 to af1ce40 Compare October 1, 2021 12:06
@galderz
Copy link
Contributor Author

galderz commented Oct 1, 2021

Hmmm, I think I forgot to push. Should be done now.

@@ -122,6 +123,12 @@ pub enum Event {
/// Note that this serves as a payment receipt, if you wish to have such a thing, you must
/// store it somehow!
payment_preimage: PaymentPreimage,
/// The hash which was given to [`ChannelManager::send_payment`]. When the `PaymentSent` message
/// comes from an older library version, the payment hash will be missing, in which case the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latter part of the documentation here should be dropped.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One note on docs, but otherwise looks good.

@galderz galderz force-pushed the t_payment_hash_999 branch from af1ce40 to d9f55be Compare October 4, 2021 20:37
@galderz galderz force-pushed the t_payment_hash_999 branch from d9f55be to 204bfd2 Compare October 8, 2021 04:59
events::Event::PaymentSent { payment_preimage }
events::Event::PaymentSent {
payment_preimage,
payment_hash: payment_hash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/payment_hash: payment_hash/payment_hash

@TheBlueMatt TheBlueMatt merged commit e635db0 into lightningdevkit:main Oct 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants