Skip to content

Commit 778141f

Browse files
Add MPPFragmentFailed event
This will be used in upcoming commits to improve our interface for failed payments.
1 parent c5e963b commit 778141f

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lightning/src/routing/router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use core::cmp;
2828
use core::ops::Deref;
2929

3030
/// A hop in a route
31-
#[derive(Clone, Hash, PartialEq, Eq)]
31+
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
3232
pub struct RouteHop {
3333
/// The node_id of the node at this hop.
3434
pub pubkey: PublicKey,

lightning/src/util/events.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use ln::msgs;
1818
use ln::{PaymentPreimage, PaymentHash, PaymentSecret};
1919
use chain::keysinterface::SpendableOutputDescriptor;
20+
use routing::router::RouteHop;
2021
use util::ser::{Writeable, Writer, MaybeReadable, Readable, VecReadWrapper, VecWriteWrapper};
2122

2223
use bitcoin::blockdata::script::Script;
@@ -137,6 +138,14 @@ pub enum Event {
137138
#[cfg(test)]
138139
error_data: Option<Vec<u8>>,
139140
},
141+
/// Indicates an outbound MPP payment partially failed. Probably some intermediary node dropped
142+
/// something. You may wish to retry this portion of the payment with a different path.
143+
MPPFragmentFailed {
144+
/// The hash which was given to ChannelManager::send_payment.
145+
payment_hash: PaymentHash,
146+
/// The path that failed.
147+
payment_path: Vec<RouteHop>,
148+
},
140149
/// Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a
141150
/// time in the future.
142151
PendingHTLCsForwardable {
@@ -250,6 +259,13 @@ impl Writeable for Event {
250259
(2, claim_from_onchain_tx, required),
251260
});
252261
},
262+
&Event::MPPFragmentFailed { ref payment_hash, ref payment_path } => {
263+
9u8.write(writer)?;
264+
write_tlv_fields!(writer, {
265+
(0, payment_hash, required),
266+
(2, payment_path, vec_type),
267+
});
268+
},
253269
}
254270
Ok(())
255271
}
@@ -357,6 +373,18 @@ impl MaybeReadable for Event {
357373
};
358374
f()
359375
},
376+
9u8 => {
377+
let f = || {
378+
let mut payment_hash = PaymentHash([0; 32]);
379+
let mut payment_path = None;
380+
read_tlv_fields!(reader, {
381+
(0, payment_hash, required),
382+
(2, payment_path, vec_type),
383+
});
384+
Ok(Some(Event::MPPFragmentFailed { payment_hash, payment_path: payment_path.unwrap() }))
385+
};
386+
f()
387+
}
360388
// Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue.
361389
x if x % 2 == 1 => Ok(None),
362390
_ => Err(msgs::DecodeError::InvalidValue)

0 commit comments

Comments
 (0)