Skip to content

Commit df8aa67

Browse files
committed
Allow users to specify the PaymentId for new outbound payments
In c986e52, an `MppId` was added to `HTLCSource` objects as a way of correlating HTLCs which belong to the same payment when the `ChannelManager` sees an HTLC succeed/fail. This allows it to have awareness of the state of all HTLCs in a payment when it generates the ultimate user-facing payment success/failure events. This was used in the same PR to avoid generating duplicative success/failure events for a single payment. Because the field was only used as an internal token to correlate HTLCs, and retries were not supported, it was generated randomly by calling the `KeysInterface`'s 32-byte random-fetching function. This also provided a backwards-compatibility story as the existing HTLC randomization key was re-used for older clients. In 28eea12 `MppId` was renamed to the current `PaymentId` which was then used expose the `retry_payment` interface, allowing users to send new HTLCs which are considered a part of an existing payment. At no point has the payment-sending API seriously considered idempotency, a major drawback which leaves the API unsafe in most deployments. Luckily, there is a simple solution - because the `PaymentId` must be unique, and because payment information for a given payment is held for several blocks after a payment completes/fails, it represents an obvious idempotency token. Here we simply require the user provide the `PaymentId` directly in `send_payment`, allowing them to use whatever token they may already have for a payment's idempotency token.
1 parent 559ed20 commit df8aa67

15 files changed

+328
-271
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 71 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use lightning::chain::transaction::OutPoint;
3838
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
3939
use lightning::chain::keysinterface::{KeyMaterial, KeysInterface, InMemorySigner, Recipient};
4040
use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
41-
use lightning::ln::channelmanager::{self, ChainParameters, ChannelManager, PaymentSendFailure, ChannelManagerReadArgs};
41+
use lightning::ln::channelmanager::{self, ChainParameters, ChannelManager, PaymentSendFailure, ChannelManagerReadArgs, PaymentId};
4242
use lightning::ln::channel::FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE;
4343
use lightning::ln::msgs::{CommitmentUpdate, ChannelMessageHandler, DecodeError, UpdateAddHTLC, Init};
4444
use lightning::ln::script::ShutdownScript;
@@ -308,9 +308,12 @@ fn get_payment_secret_hash(dest: &ChanMan, payment_id: &mut u8) -> Option<(Payme
308308
}
309309

310310
#[inline]
311-
fn send_payment(source: &ChanMan, dest: &ChanMan, dest_chan_id: u64, amt: u64, payment_id: &mut u8) -> bool {
311+
fn send_payment(source: &ChanMan, dest: &ChanMan, dest_chan_id: u64, amt: u64, payment_id: &mut u8, payment_idx: &mut u64) -> bool {
312312
let (payment_secret, payment_hash) =
313313
if let Some((secret, hash)) = get_payment_secret_hash(dest, payment_id) { (secret, hash) } else { return true; };
314+
let mut payment_id = [0; 32];
315+
payment_id[0..8].copy_from_slice(&payment_idx.to_ne_bytes());
316+
*payment_idx += 1;
314317
if let Err(err) = source.send_payment(&Route {
315318
paths: vec![vec![RouteHop {
316319
pubkey: dest.get_our_node_id(),
@@ -321,15 +324,18 @@ fn send_payment(source: &ChanMan, dest: &ChanMan, dest_chan_id: u64, amt: u64, p
321324
cltv_expiry_delta: 200,
322325
}]],
323326
payment_params: None,
324-
}, payment_hash, &Some(payment_secret)) {
327+
}, payment_hash, &Some(payment_secret), PaymentId(payment_id)) {
325328
check_payment_err(err);
326329
false
327330
} else { true }
328331
}
329332
#[inline]
330-
fn send_hop_payment(source: &ChanMan, middle: &ChanMan, middle_chan_id: u64, dest: &ChanMan, dest_chan_id: u64, amt: u64, payment_id: &mut u8) -> bool {
333+
fn send_hop_payment(source: &ChanMan, middle: &ChanMan, middle_chan_id: u64, dest: &ChanMan, dest_chan_id: u64, amt: u64, payment_id: &mut u8, payment_idx: &mut u64) -> bool {
331334
let (payment_secret, payment_hash) =
332335
if let Some((secret, hash)) = get_payment_secret_hash(dest, payment_id) { (secret, hash) } else { return true; };
336+
let mut payment_id = [0; 32];
337+
payment_id[0..8].copy_from_slice(&payment_idx.to_ne_bytes());
338+
*payment_idx += 1;
333339
if let Err(err) = source.send_payment(&Route {
334340
paths: vec![vec![RouteHop {
335341
pubkey: middle.get_our_node_id(),
@@ -347,7 +353,7 @@ fn send_hop_payment(source: &ChanMan, middle: &ChanMan, middle_chan_id: u64, des
347353
cltv_expiry_delta: 200,
348354
}]],
349355
payment_params: None,
350-
}, payment_hash, &Some(payment_secret)) {
356+
}, payment_hash, &Some(payment_secret), PaymentId(payment_id)) {
351357
check_payment_err(err);
352358
false
353359
} else { true }
@@ -553,6 +559,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {
553559
let chan_b = nodes[2].list_usable_channels()[0].short_channel_id.unwrap();
554560

555561
let mut payment_id: u8 = 0;
562+
let mut payment_idx: u64 = 0;
556563

557564
let mut chan_a_disconnected = false;
558565
let mut chan_b_disconnected = false;
@@ -1036,61 +1043,61 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {
10361043
},
10371044

10381045
// 1/10th the channel size:
1039-
0x30 => { send_payment(&nodes[0], &nodes[1], chan_a, 10_000_000, &mut payment_id); },
1040-
0x31 => { send_payment(&nodes[1], &nodes[0], chan_a, 10_000_000, &mut payment_id); },
1041-
0x32 => { send_payment(&nodes[1], &nodes[2], chan_b, 10_000_000, &mut payment_id); },
1042-
0x33 => { send_payment(&nodes[2], &nodes[1], chan_b, 10_000_000, &mut payment_id); },
1043-
0x34 => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 10_000_000, &mut payment_id); },
1044-
0x35 => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 10_000_000, &mut payment_id); },
1045-
1046-
0x38 => { send_payment(&nodes[0], &nodes[1], chan_a, 1_000_000, &mut payment_id); },
1047-
0x39 => { send_payment(&nodes[1], &nodes[0], chan_a, 1_000_000, &mut payment_id); },
1048-
0x3a => { send_payment(&nodes[1], &nodes[2], chan_b, 1_000_000, &mut payment_id); },
1049-
0x3b => { send_payment(&nodes[2], &nodes[1], chan_b, 1_000_000, &mut payment_id); },
1050-
0x3c => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 1_000_000, &mut payment_id); },
1051-
0x3d => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 1_000_000, &mut payment_id); },
1052-
1053-
0x40 => { send_payment(&nodes[0], &nodes[1], chan_a, 100_000, &mut payment_id); },
1054-
0x41 => { send_payment(&nodes[1], &nodes[0], chan_a, 100_000, &mut payment_id); },
1055-
0x42 => { send_payment(&nodes[1], &nodes[2], chan_b, 100_000, &mut payment_id); },
1056-
0x43 => { send_payment(&nodes[2], &nodes[1], chan_b, 100_000, &mut payment_id); },
1057-
0x44 => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 100_000, &mut payment_id); },
1058-
0x45 => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 100_000, &mut payment_id); },
1059-
1060-
0x48 => { send_payment(&nodes[0], &nodes[1], chan_a, 10_000, &mut payment_id); },
1061-
0x49 => { send_payment(&nodes[1], &nodes[0], chan_a, 10_000, &mut payment_id); },
1062-
0x4a => { send_payment(&nodes[1], &nodes[2], chan_b, 10_000, &mut payment_id); },
1063-
0x4b => { send_payment(&nodes[2], &nodes[1], chan_b, 10_000, &mut payment_id); },
1064-
0x4c => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 10_000, &mut payment_id); },
1065-
0x4d => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 10_000, &mut payment_id); },
1066-
1067-
0x50 => { send_payment(&nodes[0], &nodes[1], chan_a, 1_000, &mut payment_id); },
1068-
0x51 => { send_payment(&nodes[1], &nodes[0], chan_a, 1_000, &mut payment_id); },
1069-
0x52 => { send_payment(&nodes[1], &nodes[2], chan_b, 1_000, &mut payment_id); },
1070-
0x53 => { send_payment(&nodes[2], &nodes[1], chan_b, 1_000, &mut payment_id); },
1071-
0x54 => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 1_000, &mut payment_id); },
1072-
0x55 => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 1_000, &mut payment_id); },
1073-
1074-
0x58 => { send_payment(&nodes[0], &nodes[1], chan_a, 100, &mut payment_id); },
1075-
0x59 => { send_payment(&nodes[1], &nodes[0], chan_a, 100, &mut payment_id); },
1076-
0x5a => { send_payment(&nodes[1], &nodes[2], chan_b, 100, &mut payment_id); },
1077-
0x5b => { send_payment(&nodes[2], &nodes[1], chan_b, 100, &mut payment_id); },
1078-
0x5c => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 100, &mut payment_id); },
1079-
0x5d => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 100, &mut payment_id); },
1080-
1081-
0x60 => { send_payment(&nodes[0], &nodes[1], chan_a, 10, &mut payment_id); },
1082-
0x61 => { send_payment(&nodes[1], &nodes[0], chan_a, 10, &mut payment_id); },
1083-
0x62 => { send_payment(&nodes[1], &nodes[2], chan_b, 10, &mut payment_id); },
1084-
0x63 => { send_payment(&nodes[2], &nodes[1], chan_b, 10, &mut payment_id); },
1085-
0x64 => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 10, &mut payment_id); },
1086-
0x65 => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 10, &mut payment_id); },
1087-
1088-
0x68 => { send_payment(&nodes[0], &nodes[1], chan_a, 1, &mut payment_id); },
1089-
0x69 => { send_payment(&nodes[1], &nodes[0], chan_a, 1, &mut payment_id); },
1090-
0x6a => { send_payment(&nodes[1], &nodes[2], chan_b, 1, &mut payment_id); },
1091-
0x6b => { send_payment(&nodes[2], &nodes[1], chan_b, 1, &mut payment_id); },
1092-
0x6c => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 1, &mut payment_id); },
1093-
0x6d => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 1, &mut payment_id); },
1046+
0x30 => { send_payment(&nodes[0], &nodes[1], chan_a, 10_000_000, &mut payment_id, &mut payment_idx); },
1047+
0x31 => { send_payment(&nodes[1], &nodes[0], chan_a, 10_000_000, &mut payment_id, &mut payment_idx); },
1048+
0x32 => { send_payment(&nodes[1], &nodes[2], chan_b, 10_000_000, &mut payment_id, &mut payment_idx); },
1049+
0x33 => { send_payment(&nodes[2], &nodes[1], chan_b, 10_000_000, &mut payment_id, &mut payment_idx); },
1050+
0x34 => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 10_000_000, &mut payment_id, &mut payment_idx); },
1051+
0x35 => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 10_000_000, &mut payment_id, &mut payment_idx); },
1052+
1053+
0x38 => { send_payment(&nodes[0], &nodes[1], chan_a, 1_000_000, &mut payment_id, &mut payment_idx); },
1054+
0x39 => { send_payment(&nodes[1], &nodes[0], chan_a, 1_000_000, &mut payment_id, &mut payment_idx); },
1055+
0x3a => { send_payment(&nodes[1], &nodes[2], chan_b, 1_000_000, &mut payment_id, &mut payment_idx); },
1056+
0x3b => { send_payment(&nodes[2], &nodes[1], chan_b, 1_000_000, &mut payment_id, &mut payment_idx); },
1057+
0x3c => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 1_000_000, &mut payment_id, &mut payment_idx); },
1058+
0x3d => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 1_000_000, &mut payment_id, &mut payment_idx); },
1059+
1060+
0x40 => { send_payment(&nodes[0], &nodes[1], chan_a, 100_000, &mut payment_id, &mut payment_idx); },
1061+
0x41 => { send_payment(&nodes[1], &nodes[0], chan_a, 100_000, &mut payment_id, &mut payment_idx); },
1062+
0x42 => { send_payment(&nodes[1], &nodes[2], chan_b, 100_000, &mut payment_id, &mut payment_idx); },
1063+
0x43 => { send_payment(&nodes[2], &nodes[1], chan_b, 100_000, &mut payment_id, &mut payment_idx); },
1064+
0x44 => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 100_000, &mut payment_id, &mut payment_idx); },
1065+
0x45 => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 100_000, &mut payment_id, &mut payment_idx); },
1066+
1067+
0x48 => { send_payment(&nodes[0], &nodes[1], chan_a, 10_000, &mut payment_id, &mut payment_idx); },
1068+
0x49 => { send_payment(&nodes[1], &nodes[0], chan_a, 10_000, &mut payment_id, &mut payment_idx); },
1069+
0x4a => { send_payment(&nodes[1], &nodes[2], chan_b, 10_000, &mut payment_id, &mut payment_idx); },
1070+
0x4b => { send_payment(&nodes[2], &nodes[1], chan_b, 10_000, &mut payment_id, &mut payment_idx); },
1071+
0x4c => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 10_000, &mut payment_id, &mut payment_idx); },
1072+
0x4d => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 10_000, &mut payment_id, &mut payment_idx); },
1073+
1074+
0x50 => { send_payment(&nodes[0], &nodes[1], chan_a, 1_000, &mut payment_id, &mut payment_idx); },
1075+
0x51 => { send_payment(&nodes[1], &nodes[0], chan_a, 1_000, &mut payment_id, &mut payment_idx); },
1076+
0x52 => { send_payment(&nodes[1], &nodes[2], chan_b, 1_000, &mut payment_id, &mut payment_idx); },
1077+
0x53 => { send_payment(&nodes[2], &nodes[1], chan_b, 1_000, &mut payment_id, &mut payment_idx); },
1078+
0x54 => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 1_000, &mut payment_id, &mut payment_idx); },
1079+
0x55 => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 1_000, &mut payment_id, &mut payment_idx); },
1080+
1081+
0x58 => { send_payment(&nodes[0], &nodes[1], chan_a, 100, &mut payment_id, &mut payment_idx); },
1082+
0x59 => { send_payment(&nodes[1], &nodes[0], chan_a, 100, &mut payment_id, &mut payment_idx); },
1083+
0x5a => { send_payment(&nodes[1], &nodes[2], chan_b, 100, &mut payment_id, &mut payment_idx); },
1084+
0x5b => { send_payment(&nodes[2], &nodes[1], chan_b, 100, &mut payment_id, &mut payment_idx); },
1085+
0x5c => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 100, &mut payment_id, &mut payment_idx); },
1086+
0x5d => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 100, &mut payment_id, &mut payment_idx); },
1087+
1088+
0x60 => { send_payment(&nodes[0], &nodes[1], chan_a, 10, &mut payment_id, &mut payment_idx); },
1089+
0x61 => { send_payment(&nodes[1], &nodes[0], chan_a, 10, &mut payment_id, &mut payment_idx); },
1090+
0x62 => { send_payment(&nodes[1], &nodes[2], chan_b, 10, &mut payment_id, &mut payment_idx); },
1091+
0x63 => { send_payment(&nodes[2], &nodes[1], chan_b, 10, &mut payment_id, &mut payment_idx); },
1092+
0x64 => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 10, &mut payment_id, &mut payment_idx); },
1093+
0x65 => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 10, &mut payment_id, &mut payment_idx); },
1094+
1095+
0x68 => { send_payment(&nodes[0], &nodes[1], chan_a, 1, &mut payment_id, &mut payment_idx); },
1096+
0x69 => { send_payment(&nodes[1], &nodes[0], chan_a, 1, &mut payment_id, &mut payment_idx); },
1097+
0x6a => { send_payment(&nodes[1], &nodes[2], chan_b, 1, &mut payment_id, &mut payment_idx); },
1098+
0x6b => { send_payment(&nodes[2], &nodes[1], chan_b, 1, &mut payment_id, &mut payment_idx); },
1099+
0x6c => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 1, &mut payment_id, &mut payment_idx); },
1100+
0x6d => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 1, &mut payment_id, &mut payment_idx); },
10941101

10951102
0x80 => {
10961103
let max_feerate = last_htlc_clear_fee_a * FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE as u32;
@@ -1173,11 +1180,11 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {
11731180

11741181
// Finally, make sure that at least one end of each channel can make a substantial payment
11751182
assert!(
1176-
send_payment(&nodes[0], &nodes[1], chan_a, 10_000_000, &mut payment_id) ||
1177-
send_payment(&nodes[1], &nodes[0], chan_a, 10_000_000, &mut payment_id));
1183+
send_payment(&nodes[0], &nodes[1], chan_a, 10_000_000, &mut payment_id, &mut payment_idx) ||
1184+
send_payment(&nodes[1], &nodes[0], chan_a, 10_000_000, &mut payment_id, &mut payment_idx));
11781185
assert!(
1179-
send_payment(&nodes[1], &nodes[2], chan_b, 10_000_000, &mut payment_id) ||
1180-
send_payment(&nodes[2], &nodes[1], chan_b, 10_000_000, &mut payment_id));
1186+
send_payment(&nodes[1], &nodes[2], chan_b, 10_000_000, &mut payment_id, &mut payment_idx) ||
1187+
send_payment(&nodes[2], &nodes[1], chan_b, 10_000_000, &mut payment_id, &mut payment_idx));
11811188

11821189
last_htlc_clear_fee_a = fee_est_a.ret_val.load(atomic::Ordering::Acquire);
11831190
last_htlc_clear_fee_b = fee_est_b.ret_val.load(atomic::Ordering::Acquire);

fuzz/src/full_stack.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use lightning::chain::chainmonitor;
3535
use lightning::chain::transaction::OutPoint;
3636
use lightning::chain::keysinterface::{InMemorySigner, Recipient, KeyMaterial, KeysInterface};
3737
use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
38-
use lightning::ln::channelmanager::{ChainParameters, ChannelManager};
38+
use lightning::ln::channelmanager::{ChainParameters, ChannelManager, PaymentId};
3939
use lightning::ln::peer_handler::{MessageHandler,PeerManager,SocketDescriptor,IgnoringMessageHandler};
4040
use lightning::ln::msgs::DecodeError;
4141
use lightning::ln::script::ShutdownScript;
@@ -482,7 +482,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
482482
sha.input(&payment_hash.0[..]);
483483
payment_hash.0 = Sha256::from_engine(sha).into_inner();
484484
payments_sent += 1;
485-
match channelmanager.send_payment(&route, payment_hash, &None) {
485+
match channelmanager.send_payment(&route, payment_hash, &None, PaymentId(payment_hash.0)) {
486486
Ok(_) => {},
487487
Err(_) => return,
488488
}
@@ -510,7 +510,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
510510
let mut payment_secret = PaymentSecret([0; 32]);
511511
payment_secret.0[0..8].copy_from_slice(&be64_to_array(payments_sent));
512512
payments_sent += 1;
513-
match channelmanager.send_payment(&route, payment_hash, &Some(payment_secret)) {
513+
match channelmanager.send_payment(&route, payment_hash, &Some(payment_secret), PaymentId(payment_hash.0)) {
514514
Ok(_) => {},
515515
Err(_) => return,
516516
}

lightning-invoice/src/payment.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ impl<T: Time> Display for PaymentAttempts<T> {
242242
}
243243

244244
/// A trait defining behavior of an [`Invoice`] payer.
245+
///
246+
/// Note that in order to provide idempotency across restarts duplicate `send_*payment` calls with
247+
/// the same `payment_hash` should be rejected. In order to accomplish this, it is likely good to
248+
/// reuse the [`PaymentHash`] bytes as the [`PaymentId`].
245249
pub trait Payer {
246250
/// Returns the payer's node id.
247251
fn node_id(&self) -> PublicKey;

lightning-invoice/src/utils.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -519,14 +519,16 @@ where
519519
fn send_payment(
520520
&self, route: &Route, payment_hash: PaymentHash, payment_secret: &Option<PaymentSecret>
521521
) -> Result<PaymentId, PaymentSendFailure> {
522-
self.send_payment(route, payment_hash, payment_secret)
522+
let payment_id = PaymentId(payment_hash.0);
523+
self.send_payment(route, payment_hash, payment_secret, payment_id).map(|()| payment_id)
523524
}
524525

525526
fn send_spontaneous_payment(
526527
&self, route: &Route, payment_preimage: PaymentPreimage,
527528
) -> Result<PaymentId, PaymentSendFailure> {
528-
self.send_spontaneous_payment(route, Some(payment_preimage))
529-
.map(|(_, payment_id)| payment_id)
529+
let payment_id = PaymentId(sha256::Hash::hash(&payment_preimage.0).into_inner());
530+
self.send_spontaneous_payment(route, Some(payment_preimage), payment_id)
531+
.map(|_| payment_id)
530532
}
531533

532534
fn retry_payment(
@@ -596,7 +598,7 @@ mod test {
596598
use bitcoin_hashes::sha256::Hash as Sha256;
597599
use lightning::chain::keysinterface::PhantomKeysManager;
598600
use lightning::ln::{PaymentPreimage, PaymentHash};
599-
use lightning::ln::channelmanager::{self, PhantomRouteHints, MIN_FINAL_CLTV_EXPIRY};
601+
use lightning::ln::channelmanager::{self, PhantomRouteHints, MIN_FINAL_CLTV_EXPIRY, PaymentId};
600602
use lightning::ln::functional_test_utils::*;
601603
use lightning::ln::msgs::ChannelMessageHandler;
602604
use lightning::routing::router::{PaymentParameters, RouteParameters, find_route};
@@ -655,7 +657,7 @@ mod test {
655657
let payment_event = {
656658
let mut payment_hash = PaymentHash([0; 32]);
657659
payment_hash.0.copy_from_slice(&invoice.payment_hash().as_ref()[0..32]);
658-
nodes[0].node.send_payment(&route, payment_hash, &Some(invoice.payment_secret().clone())).unwrap();
660+
nodes[0].node.send_payment(&route, payment_hash, &Some(invoice.payment_secret().clone()), PaymentId(payment_hash.0)).unwrap();
659661
let mut added_monitors = nodes[0].chain_monitor.added_monitors.lock().unwrap();
660662
assert_eq!(added_monitors.len(), 1);
661663
added_monitors.clear();
@@ -930,7 +932,7 @@ mod test {
930932
let (payment_event, fwd_idx) = {
931933
let mut payment_hash = PaymentHash([0; 32]);
932934
payment_hash.0.copy_from_slice(&invoice.payment_hash().as_ref()[0..32]);
933-
nodes[0].node.send_payment(&route, payment_hash, &Some(invoice.payment_secret().clone())).unwrap();
935+
nodes[0].node.send_payment(&route, payment_hash, &Some(invoice.payment_secret().clone()), PaymentId(payment_hash.0)).unwrap();
934936
let mut added_monitors = nodes[0].chain_monitor.added_monitors.lock().unwrap();
935937
assert_eq!(added_monitors.len(), 1);
936938
added_monitors.clear();

lightning/src/chain/chainmonitor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ mod tests {
733733
use ::{get_htlc_update_msgs, get_local_commitment_txn, get_revoke_commit_msgs, get_route_and_payment_hash, unwrap_send_err};
734734
use chain::{ChannelMonitorUpdateStatus, Confirm, Watch};
735735
use chain::channelmonitor::LATENCY_GRACE_PERIOD_BLOCKS;
736-
use ln::channelmanager::{self, PaymentSendFailure};
736+
use ln::channelmanager::{self, PaymentSendFailure, PaymentId};
737737
use ln::functional_test_utils::*;
738738
use ln::msgs::ChannelMessageHandler;
739739
use util::errors::APIError;
@@ -859,7 +859,7 @@ mod tests {
859859
// If the ChannelManager tries to update the channel, however, the ChainMonitor will pass
860860
// the update through to the ChannelMonitor which will refuse it (as the channel is closed).
861861
chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed);
862-
unwrap_send_err!(nodes[0].node.send_payment(&route, second_payment_hash, &Some(second_payment_secret)),
862+
unwrap_send_err!(nodes[0].node.send_payment(&route, second_payment_hash, &Some(second_payment_secret), PaymentId(second_payment_hash.0)),
863863
true, APIError::ChannelUnavailable { ref err },
864864
assert!(err.contains("ChannelMonitor storage failure")));
865865
check_added_monitors!(nodes[0], 2); // After the failure we generate a close-channel monitor update

0 commit comments

Comments
 (0)