Skip to content

Commit 51069ba

Browse files
committed
Add reason to Event::PaymentFailed
1 parent 980b14c commit 51069ba

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

bindings/ldk_node.udl

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,21 @@ enum BuildError {
157157

158158
[Enum]
159159
interface Event {
160-
PaymentSuccessful( PaymentHash payment_hash );
161-
PaymentFailed( PaymentHash payment_hash );
162-
PaymentReceived( PaymentHash payment_hash, u64 amount_msat);
163-
ChannelPending ( ChannelId channel_id, UserChannelId user_channel_id, ChannelId former_temporary_channel_id, PublicKey counterparty_node_id, OutPoint funding_txo );
164-
ChannelReady ( ChannelId channel_id, UserChannelId user_channel_id, PublicKey? counterparty_node_id );
165-
ChannelClosed ( ChannelId channel_id, UserChannelId user_channel_id, PublicKey? counterparty_node_id );
160+
PaymentSuccessful(PaymentHash payment_hash);
161+
PaymentFailed(PaymentHash payment_hash, PaymentFailureReason? reason);
162+
PaymentReceived(PaymentHash payment_hash, u64 amount_msat);
163+
ChannelPending(ChannelId channel_id, UserChannelId user_channel_id, ChannelId former_temporary_channel_id, PublicKey counterparty_node_id, OutPoint funding_txo);
164+
ChannelReady(ChannelId channel_id, UserChannelId user_channel_id, PublicKey? counterparty_node_id);
165+
ChannelClosed(ChannelId channel_id, UserChannelId user_channel_id, PublicKey? counterparty_node_id);
166+
};
167+
168+
enum PaymentFailureReason {
169+
"RecipientRejected",
170+
"UserAbandoned",
171+
"RetriesExhausted",
172+
"PaymentExpired",
173+
"RouteNotFound",
174+
"UnexpectedError",
166175
};
167176

168177
enum PaymentDirection {

src/event.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use crate::io::{
1414
use crate::logger::{log_error, log_info, Logger};
1515

1616
use lightning::chain::chaininterface::ConfirmationTarget;
17-
use lightning::events::Event as LdkEvent;
1817
use lightning::events::PaymentPurpose;
18+
use lightning::events::{Event as LdkEvent, PaymentFailureReason};
1919
use lightning::impl_writeable_tlv_based_enum;
2020
use lightning::ln::{ChannelId, PaymentHash};
2121
use lightning::routing::gossip::NodeId;
@@ -52,6 +52,10 @@ pub enum Event {
5252
PaymentFailed {
5353
/// The hash of the payment.
5454
payment_hash: PaymentHash,
55+
/// The reason why the payment failed.
56+
///
57+
/// This will be `None` for events serialized by LDK Node v0.2.1 and prior.
58+
reason: Option<PaymentFailureReason>,
5559
},
5660
/// A payment has been received.
5761
PaymentReceived {
@@ -103,6 +107,7 @@ impl_writeable_tlv_based_enum!(Event,
103107
},
104108
(1, PaymentFailed) => {
105109
(0, payment_hash, required),
110+
(1, reason, option),
106111
},
107112
(2, PaymentReceived) => {
108113
(0, payment_hash, required),
@@ -609,11 +614,12 @@ where
609614
panic!("Failed to push to event queue");
610615
});
611616
}
612-
LdkEvent::PaymentFailed { payment_hash, .. } => {
617+
LdkEvent::PaymentFailed { payment_hash, reason, .. } => {
613618
log_info!(
614619
self.logger,
615-
"Failed to send payment to payment hash {:?}.",
616-
hex_utils::to_string(&payment_hash.0)
620+
"Failed to send payment to payment hash {:?} due to {:?}.",
621+
hex_utils::to_string(&payment_hash.0),
622+
reason
617623
);
618624

619625
let update = PaymentDetailsUpdate {
@@ -624,12 +630,12 @@ where
624630
log_error!(self.logger, "Failed to access payment store: {}", e);
625631
panic!("Failed to access payment store");
626632
});
627-
self.event_queue.add_event(Event::PaymentFailed { payment_hash }).unwrap_or_else(
628-
|e| {
633+
self.event_queue
634+
.add_event(Event::PaymentFailed { payment_hash, reason })
635+
.unwrap_or_else(|e| {
629636
log_error!(self.logger, "Failed to push to event queue: {}", e);
630637
panic!("Failed to push to event queue");
631-
},
632-
);
638+
});
633639
}
634640

635641
LdkEvent::PaymentPathSuccessful { .. } => {}

src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ pub use types::ChannelConfig;
108108
pub use io::utils::generate_entropy_mnemonic;
109109

110110
#[cfg(feature = "uniffi")]
111-
use {bip39::Mnemonic, bitcoin::OutPoint, lightning::ln::PaymentSecret, uniffi_types::*};
111+
use {
112+
bip39::Mnemonic, bitcoin::OutPoint, lightning::events::PaymentFailureReason,
113+
lightning::ln::ChannelId, lightning::ln::PaymentSecret, uniffi_types::*,
114+
};
112115

113116
#[cfg(feature = "uniffi")]
114117
pub use builder::ArcedNodeBuilder as Builder;
@@ -135,8 +138,6 @@ use lightning::ln::channelmanager::{self, PaymentId, RecipientOnionFields, Retry
135138
use lightning::ln::msgs::SocketAddress;
136139
use lightning::ln::{PaymentHash, PaymentPreimage};
137140

138-
#[cfg(feature = "uniffi")]
139-
use lightning::ln::ChannelId;
140141
use lightning::sign::EntropySource;
141142

142143
use lightning::util::persist::KVStore;

0 commit comments

Comments
 (0)