Skip to content

Commit 011ce95

Browse files
Add MPPFragmentFailed event
This will be used in upcoming commits to improve our interface for failed payments.
1 parent 847c511 commit 011ce95

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
@@ -18,6 +18,7 @@ use chain::keysinterface::SpendableOutputDescriptor;
1818
use ln::msgs;
1919
use ln::{PaymentPreimage, PaymentHash, PaymentSecret};
2020
use routing::network_graph::NetworkUpdate;
21+
use routing::router::RouteHop;
2122
use util::ser::{Writeable, Writer, MaybeReadable, Readable, VecReadWrapper, VecWriteWrapper};
2223

2324
use bitcoin::blockdata::script::Script;
@@ -147,6 +148,14 @@ pub enum Event {
147148
#[cfg(test)]
148149
error_data: Option<Vec<u8>>,
149150
},
151+
/// Indicates an outbound MPP payment partially failed. Probably some intermediary node dropped
152+
/// something. You may wish to retry this portion of the payment with a different path.
153+
MPPFragmentFailed {
154+
/// The hash which was given to ChannelManager::send_payment.
155+
payment_hash: PaymentHash,
156+
/// The path that failed.
157+
payment_path: Vec<RouteHop>,
158+
},
150159
/// Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a
151160
/// time in the future.
152161
PendingHTLCsForwardable {
@@ -261,6 +270,13 @@ impl Writeable for Event {
261270
(2, claim_from_onchain_tx, required),
262271
});
263272
},
273+
&Event::MPPFragmentFailed { ref payment_hash, ref payment_path } => {
274+
9u8.write(writer)?;
275+
write_tlv_fields!(writer, {
276+
(0, payment_hash, required),
277+
(2, payment_path, vec_type),
278+
});
279+
},
264280
}
265281
Ok(())
266282
}
@@ -371,6 +387,18 @@ impl MaybeReadable for Event {
371387
};
372388
f()
373389
},
390+
9u8 => {
391+
let f = || {
392+
let mut payment_hash = PaymentHash([0; 32]);
393+
let mut payment_path = None;
394+
read_tlv_fields!(reader, {
395+
(0, payment_hash, required),
396+
(2, payment_path, vec_type),
397+
});
398+
Ok(Some(Event::MPPFragmentFailed { payment_hash, payment_path: payment_path.unwrap() }))
399+
};
400+
f()
401+
}
374402
// Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue.
375403
x if x % 2 == 1 => Ok(None),
376404
_ => Err(msgs::DecodeError::InvalidValue)

0 commit comments

Comments
 (0)