-
Notifications
You must be signed in to change notification settings - Fork 339
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
Payment Retries #1059
Payment Retries #1059
Changes from 2 commits
a3a4e61
3410f18
73f601f
5feb4dc
2d102a3
ad4f16b
e523e58
d9b9916
010436d
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 |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
//! few other things. | ||
|
||
use chain::keysinterface::SpendableOutputDescriptor; | ||
use ln::channelmanager::PaymentId; | ||
use ln::msgs; | ||
use ln::msgs::DecodeError; | ||
use ln::{PaymentPreimage, PaymentHash, PaymentSecret}; | ||
|
@@ -178,6 +179,12 @@ pub enum Event { | |
/// Note for MPP payments: in rare cases, this event may be preceded by a `PaymentPathFailed` | ||
/// event. In this situation, you SHOULD treat this payment as having succeeded. | ||
PaymentSent { | ||
/// The id returned by [`ChannelManager::send_payment`] and used with | ||
/// [`ChannelManager::retry_payment`]. | ||
/// | ||
/// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment | ||
/// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment | ||
payment_id: Option<PaymentId>, | ||
/// The preimage to the hash given to ChannelManager::send_payment. | ||
/// Note that this serves as a payment receipt, if you wish to have such a thing, you must | ||
/// store it somehow! | ||
|
@@ -322,11 +329,12 @@ impl Writeable for Event { | |
(8, payment_preimage, option), | ||
}); | ||
}, | ||
&Event::PaymentSent { ref payment_preimage, ref payment_hash} => { | ||
&Event::PaymentSent { ref payment_id, ref payment_preimage, ref payment_hash} => { | ||
2u8.write(writer)?; | ||
write_tlv_fields!(writer, { | ||
(0, payment_preimage, required), | ||
(1, payment_hash, required), | ||
(3, payment_id, option), | ||
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. I think it'd be a little nicer public API-wise if 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. Maybe we leave it an 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. Fine by me! 🙂 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, maybe that is why we decided to key by |
||
}); | ||
}, | ||
&Event::PaymentPathFailed { | ||
|
@@ -435,14 +443,17 @@ impl MaybeReadable for Event { | |
let f = || { | ||
let mut payment_preimage = PaymentPreimage([0; 32]); | ||
let mut payment_hash = None; | ||
let mut payment_id = None; | ||
read_tlv_fields!(reader, { | ||
(0, payment_preimage, required), | ||
(1, payment_hash, option), | ||
(3, payment_id, option), | ||
}); | ||
if payment_hash.is_none() { | ||
payment_hash = Some(PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner())); | ||
} | ||
Ok(Some(Event::PaymentSent { | ||
payment_id, | ||
payment_preimage, | ||
payment_hash: payment_hash.unwrap(), | ||
})) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ use bitcoin::secp256k1::key::PublicKey; | |
|
||
use routing::router::Route; | ||
use ln::chan_utils::HTLCType; | ||
use util::logger::DebugBytes; | ||
|
||
pub(crate) struct DebugPubKey<'a>(pub &'a PublicKey); | ||
impl<'a> core::fmt::Display for DebugPubKey<'a> { | ||
|
@@ -32,18 +33,11 @@ macro_rules! log_pubkey { | |
} | ||
} | ||
|
||
pub(crate) struct DebugBytes<'a>(pub &'a [u8]); | ||
impl<'a> core::fmt::Display for DebugBytes<'a> { | ||
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> { | ||
for i in self.0 { | ||
write!(f, "{:02x}", i)?; | ||
} | ||
Ok(()) | ||
} | ||
} | ||
/// Logs a byte slice in hex format. | ||
#[macro_export] | ||
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. Can we actually 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. I could see 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. Hmm, I guess I was mostly figuring the logging stuff is a one-way street - the lightning crates log stuff, and users consume it and put it somewhere. I suppose there's no real reason to require that, though, so, ok, fair enough. Please do add it to the internal one, though. |
||
macro_rules! log_bytes { | ||
($obj: expr) => { | ||
::util::macro_logger::DebugBytes(&$obj) | ||
$crate::util::logger::DebugBytes(&$obj) | ||
} | ||
} | ||
|
||
|
@@ -157,6 +151,7 @@ macro_rules! log_spendable { | |
|
||
/// Create a new Record and log it. You probably don't want to use this macro directly, | ||
/// but it needs to be exported so `log_trace` etc can use it in external crates. | ||
#[doc(hidden)] | ||
#[macro_export] | ||
macro_rules! log_internal { | ||
($logger: expr, $lvl:expr, $($arg:tt)+) => ( | ||
|
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.
Hmm, I just noticed that documentation for
payment_id
seems to be missing fromChannelMannager::send_payment
. It would be nice to (a) document that the id should be stored for a retry, and (b) that it's needed because technicallyPaymentHash
s can be non-unique.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.
Leaving unresolved pending discussions around changes to
send_payment
.