-
Notifications
You must be signed in to change notification settings - Fork 418
Remove user_payment_id #1180
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
Remove user_payment_id #1180
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -413,6 +413,9 @@ struct PeerState { | |
/// | ||
/// For users who don't want to bother doing their own payment preimage storage, we also store that | ||
/// here. | ||
/// | ||
/// Note that this struct will be removed entirely soon, in favor of storing no inbound payment data | ||
/// and instead encoding it in the payment secret. | ||
struct PendingInboundPayment { | ||
/// The payment secret that the sender must use for us to accept this payment | ||
payment_secret: PaymentSecret, | ||
|
@@ -2887,7 +2890,6 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana | |
purpose: events::PaymentPurpose::InvoicePayment { | ||
payment_preimage: inbound_payment.get().payment_preimage, | ||
payment_secret: payment_data.payment_secret, | ||
user_payment_id: inbound_payment.get().user_payment_id, | ||
}, | ||
amt: total_value, | ||
}); | ||
|
@@ -4523,7 +4525,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana | |
} | ||
} | ||
|
||
fn set_payment_hash_secret_map(&self, payment_hash: PaymentHash, payment_preimage: Option<PaymentPreimage>, min_value_msat: Option<u64>, invoice_expiry_delta_secs: u32, user_payment_id: u64) -> Result<PaymentSecret, APIError> { | ||
fn set_payment_hash_secret_map(&self, payment_hash: PaymentHash, payment_preimage: Option<PaymentPreimage>, min_value_msat: Option<u64>, invoice_expiry_delta_secs: u32) -> Result<PaymentSecret, APIError> { | ||
assert!(invoice_expiry_delta_secs <= 60*60*24*365); // Sadly bitcoin timestamps are u32s, so panic before 2106 | ||
|
||
let payment_secret = PaymentSecret(self.keys_manager.get_secure_random_bytes()); | ||
|
@@ -4533,7 +4535,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana | |
match payment_secrets.entry(payment_hash) { | ||
hash_map::Entry::Vacant(e) => { | ||
e.insert(PendingInboundPayment { | ||
payment_secret, min_value_msat, user_payment_id, payment_preimage, | ||
payment_secret, min_value_msat, payment_preimage, | ||
user_payment_id: 0, // For compatibility with version 0.0.103 and earlier | ||
// We assume that highest_seen_timestamp is pretty close to the current time - | ||
// its updated when we receive a new block with the maximum time we've seen in | ||
// a header. It should never be more than two hours in the future. | ||
|
@@ -4565,12 +4568,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana | |
/// [`PaymentReceived`]: events::Event::PaymentReceived | ||
/// [`PaymentReceived::payment_preimage`]: events::Event::PaymentReceived::payment_preimage | ||
/// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash | ||
pub fn create_inbound_payment(&self, min_value_msat: Option<u64>, invoice_expiry_delta_secs: u32, user_payment_id: u64) -> (PaymentHash, PaymentSecret) { | ||
pub fn create_inbound_payment(&self, min_value_msat: Option<u64>, invoice_expiry_delta_secs: u32) -> (PaymentHash, PaymentSecret) { | ||
let payment_preimage = PaymentPreimage(self.keys_manager.get_secure_random_bytes()); | ||
let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0).into_inner()); | ||
|
||
(payment_hash, | ||
self.set_payment_hash_secret_map(payment_hash, Some(payment_preimage), min_value_msat, invoice_expiry_delta_secs, user_payment_id) | ||
self.set_payment_hash_secret_map(payment_hash, Some(payment_preimage), min_value_msat, invoice_expiry_delta_secs) | ||
.expect("RNG Generated Duplicate PaymentHash")) | ||
} | ||
|
||
|
@@ -4584,12 +4587,6 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana | |
/// The [`PaymentHash`] (and corresponding [`PaymentPreimage`]) must be globally unique. This | ||
/// method may return an Err if another payment with the same payment_hash is still pending. | ||
/// | ||
/// `user_payment_id` will be provided back in [`PaymentPurpose::InvoicePayment::user_payment_id`] events to | ||
/// allow tracking of which events correspond with which calls to this and | ||
/// [`create_inbound_payment`]. `user_payment_id` has no meaning inside of LDK, it is simply | ||
/// copied to events and otherwise ignored. It may be used to correlate PaymentReceived events | ||
/// with invoice metadata stored elsewhere. | ||
/// | ||
Comment on lines
-4587
to
-4592
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be correct to say that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yeah I guess we won't duplicate those |
||
/// `min_value_msat` should be set if the invoice being generated contains a value. Any payment | ||
/// received for the returned [`PaymentHash`] will be required to be at least `min_value_msat` | ||
/// before a [`PaymentReceived`] event will be generated, ensuring that we do not provide the | ||
|
@@ -4618,9 +4615,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana | |
/// | ||
/// [`create_inbound_payment`]: Self::create_inbound_payment | ||
/// [`PaymentReceived`]: events::Event::PaymentReceived | ||
/// [`PaymentPurpose::InvoicePayment::user_payment_id`]: events::PaymentPurpose::InvoicePayment::user_payment_id | ||
pub fn create_inbound_payment_for_hash(&self, payment_hash: PaymentHash, min_value_msat: Option<u64>, invoice_expiry_delta_secs: u32, user_payment_id: u64) -> Result<PaymentSecret, APIError> { | ||
self.set_payment_hash_secret_map(payment_hash, None, min_value_msat, invoice_expiry_delta_secs, user_payment_id) | ||
pub fn create_inbound_payment_for_hash(&self, payment_hash: PaymentHash, min_value_msat: Option<u64>, invoice_expiry_delta_secs: u32) -> Result<PaymentSecret, APIError> { | ||
self.set_payment_hash_secret_map(payment_hash, None, min_value_msat, invoice_expiry_delta_secs) | ||
} | ||
|
||
#[cfg(any(test, feature = "fuzztarget", feature = "_test_utils"))] | ||
|
@@ -6680,7 +6676,7 @@ pub mod bench { | |
payment_preimage.0[0..8].copy_from_slice(&payment_count.to_le_bytes()); | ||
payment_count += 1; | ||
let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner()); | ||
let payment_secret = $node_b.create_inbound_payment_for_hash(payment_hash, None, 7200, 0).unwrap(); | ||
let payment_secret = $node_b.create_inbound_payment_for_hash(payment_hash, None, 7200).unwrap(); | ||
|
||
$node_a.send_payment(&route, payment_hash, &Some(payment_secret)).unwrap(); | ||
let payment_event = SendEvent::from_event($node_a.get_and_clear_pending_msg_events().pop().unwrap()); | ||
|
Uh oh!
There was an error while loading. Please reload this page.