Skip to content

Commit 2175be4

Browse files
TheBlueMattandozw
authored andcommitted
Expose payment metadata in the sending path via send_payment.
1 parent 3c6399a commit 2175be4

15 files changed

+152
-153
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ fn send_payment(source: &ChanMan, dest: &ChanMan, dest_chan_id: u64, amt: u64, p
311311
cltv_expiry_delta: 200,
312312
}]],
313313
payment_params: None,
314-
}, payment_hash, &Some(payment_secret)) {
314+
}, payment_hash, &Some(payment_secret), None) {
315315
check_payment_err(err);
316316
false
317317
} else { true }
@@ -337,7 +337,7 @@ fn send_hop_payment(source: &ChanMan, middle: &ChanMan, middle_chan_id: u64, des
337337
cltv_expiry_delta: 200,
338338
}]],
339339
payment_params: None,
340-
}, payment_hash, &Some(payment_secret)) {
340+
}, payment_hash, &Some(payment_secret), None) {
341341
check_payment_err(err);
342342
false
343343
} else { true }

fuzz/src/full_stack.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
470470
sha.input(&payment_hash.0[..]);
471471
payment_hash.0 = Sha256::from_engine(sha).into_inner();
472472
payments_sent += 1;
473-
match channelmanager.send_payment(&route, payment_hash, &None) {
473+
match channelmanager.send_payment(&route, payment_hash, &None, None) {
474474
Ok(_) => {},
475475
Err(_) => return,
476476
}
@@ -498,7 +498,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
498498
let mut payment_secret = PaymentSecret([0; 32]);
499499
payment_secret.0[0..8].copy_from_slice(&be64_to_array(payments_sent));
500500
payments_sent += 1;
501-
match channelmanager.send_payment(&route, payment_hash, &Some(payment_secret)) {
501+
match channelmanager.send_payment(&route, payment_hash, &Some(payment_secret), None) {
502502
Ok(_) => {},
503503
Err(_) => return,
504504
}

lightning-invoice/src/payment.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@
6464
//! # impl Payer for FakePayer {
6565
//! # fn node_id(&self) -> PublicKey { unimplemented!() }
6666
//! # fn first_hops(&self) -> Vec<ChannelDetails> { unimplemented!() }
67-
//! # fn send_payment(
68-
//! # &self, route: &Route, payment_hash: PaymentHash, payment_secret: &Option<PaymentSecret>
67+
//! # fn send_payment(&self, route: &Route, payment_hash: PaymentHash,
68+
//! # payment_secret: &Option<PaymentSecret>, payment_metadata: Option<Vec<u8>>
6969
//! # ) -> Result<PaymentId, PaymentSendFailure> { unimplemented!() }
7070
//! # fn send_spontaneous_payment(
7171
//! # &self, route: &Route, payment_preimage: PaymentPreimage
@@ -186,8 +186,8 @@ pub trait Payer {
186186
fn first_hops(&self) -> Vec<ChannelDetails>;
187187

188188
/// Sends a payment over the Lightning Network using the given [`Route`].
189-
fn send_payment(
190-
&self, route: &Route, payment_hash: PaymentHash, payment_secret: &Option<PaymentSecret>
189+
fn send_payment(&self, route: &Route, payment_hash: PaymentHash,
190+
payment_secret: &Option<PaymentSecret>, payment_metadata: Option<Vec<u8>>
191191
) -> Result<PaymentId, PaymentSendFailure>;
192192

193193
/// Sends a spontaneous payment over the Lightning Network using the given [`Route`].
@@ -309,7 +309,7 @@ where
309309
};
310310

311311
let send_payment = |route: &Route| {
312-
self.payer.send_payment(route, payment_hash, &payment_secret)
312+
self.payer.send_payment(route, payment_hash, &payment_secret, invoice.payment_metadata().cloned())
313313
};
314314
self.pay_internal(&route_params, payment_hash, send_payment)
315315
.map_err(|e| { self.payment_cache.lock().unwrap().remove(&payment_hash); e })
@@ -1463,9 +1463,8 @@ mod tests {
14631463
Vec::new()
14641464
}
14651465

1466-
fn send_payment(
1467-
&self, route: &Route, _payment_hash: PaymentHash,
1468-
_payment_secret: &Option<PaymentSecret>
1466+
fn send_payment(&self, route: &Route, _payment_hash: PaymentHash,
1467+
_payment_secret: &Option<PaymentSecret>, _payment_metadata: Option<Vec<u8>>
14691468
) -> Result<PaymentId, PaymentSendFailure> {
14701469
self.check_value_msats(Amount::ForInvoice(route.get_total_amount()));
14711470
self.check_attempts()

lightning-invoice/src/utils.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,10 @@ where
474474
self.list_usable_channels()
475475
}
476476

477-
fn send_payment(
478-
&self, route: &Route, payment_hash: PaymentHash, payment_secret: &Option<PaymentSecret>
477+
fn send_payment(&self, route: &Route, payment_hash: PaymentHash,
478+
payment_secret: &Option<PaymentSecret>, payment_metadata: Option<Vec<u8>>
479479
) -> Result<PaymentId, PaymentSendFailure> {
480-
self.send_payment(route, payment_hash, payment_secret)
480+
self.send_payment(route, payment_hash, payment_secret, payment_metadata)
481481
}
482482

483483
fn send_spontaneous_payment(
@@ -564,7 +564,7 @@ mod test {
564564
let payment_event = {
565565
let mut payment_hash = PaymentHash([0; 32]);
566566
payment_hash.0.copy_from_slice(&invoice.payment_hash().as_ref()[0..32]);
567-
nodes[0].node.send_payment(&route, payment_hash, &Some(invoice.payment_secret().clone())).unwrap();
567+
nodes[0].node.send_payment(&route, payment_hash, &Some(invoice.payment_secret().clone()), None).unwrap();
568568
let mut added_monitors = nodes[0].chain_monitor.added_monitors.lock().unwrap();
569569
assert_eq!(added_monitors.len(), 1);
570570
added_monitors.clear();
@@ -833,7 +833,7 @@ mod test {
833833
let (payment_event, fwd_idx) = {
834834
let mut payment_hash = PaymentHash([0; 32]);
835835
payment_hash.0.copy_from_slice(&invoice.payment_hash().as_ref()[0..32]);
836-
nodes[0].node.send_payment(&route, payment_hash, &Some(invoice.payment_secret().clone())).unwrap();
836+
nodes[0].node.send_payment(&route, payment_hash, &Some(invoice.payment_secret().clone()), None).unwrap();
837837
let mut added_monitors = nodes[0].chain_monitor.added_monitors.lock().unwrap();
838838
assert_eq!(added_monitors.len(), 1);
839839
added_monitors.clear();

lightning/src/chain/chainmonitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ mod tests {
901901
// If the ChannelManager tries to update the channel, however, the ChainMonitor will pass
902902
// the update through to the ChannelMonitor which will refuse it (as the channel is closed).
903903
chanmon_cfgs[0].persister.set_update_ret(Ok(()));
904-
unwrap_send_err!(nodes[0].node.send_payment(&route, second_payment_hash, &Some(second_payment_secret)),
904+
unwrap_send_err!(nodes[0].node.send_payment(&route, second_payment_hash, &Some(second_payment_secret), None),
905905
true, APIError::ChannelUnavailable { ref err },
906906
assert!(err.contains("ChannelMonitor storage failure")));
907907
check_added_monitors!(nodes[0], 2); // After the failure we generate a close-channel monitor update

lightning/src/chain/channelmonitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3411,7 +3411,7 @@ mod tests {
34113411
// If the ChannelManager tries to update the channel, however, the ChainMonitor will pass
34123412
// the update through to the ChannelMonitor which will refuse it (as the channel is closed).
34133413
let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[1], nodes[0], 100_000);
3414-
unwrap_send_err!(nodes[1].node.send_payment(&route, payment_hash, &Some(payment_secret)),
3414+
unwrap_send_err!(nodes[1].node.send_payment(&route, payment_hash, &Some(payment_secret), None),
34153415
true, APIError::ChannelUnavailable { ref err },
34163416
assert!(err.contains("ChannelMonitor storage failure")));
34173417
check_added_monitors!(nodes[1], 2); // After the failure we generate a close-channel monitor update

0 commit comments

Comments
 (0)