-
Notifications
You must be signed in to change notification settings - Fork 407
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
Conversation
Ups, seems like I was working on a very old |
88e4998
to
d2589bc
Compare
Rebased 😅 |
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
lightning/src/util/events.rs
Outdated
2u8.write(writer)?; | ||
write_tlv_fields!(writer, { | ||
(0, payment_preimage, required), | ||
(2, payment_hash, required), |
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
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.
d2589bc
to
46d4568
Compare
Pushed a new commit. It should address all the comments raised so far. |
lightning/src/util/events.rs
Outdated
@@ -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. |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>,
46d4568
to
38cce30
Compare
There was a problem hiding this 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
lightning/src/util/events.rs
Outdated
/// 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`. |
There was a problem hiding this comment.
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
5ccd140
to
1f9788a
Compare
@TheBlueMatt @valentinewallace rebased and pushed a new commit addressing all your latests comments. |
There was a problem hiding this 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
lightning/src/util/events.rs
Outdated
/// 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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: 100char lines
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :\
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
1f9788a
to
df04817
Compare
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. |
df04817
to
af1ce40
Compare
Hmmm, I think I forgot to push. Should be done now. |
lightning/src/util/events.rs
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this 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.
af1ce40
to
d9f55be
Compare
d9f55be
to
204bfd2
Compare
events::Event::PaymentSent { payment_preimage } | ||
events::Event::PaymentSent { | ||
payment_preimage, | ||
payment_hash: payment_hash |
There was a problem hiding this comment.
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
Implementation for the
payment_hash
part of #999.