Skip to content

Commit 99174bb

Browse files
committed
Replace PaymentSecret with RecipientOnionFields in the pub API
This moves the public payment sending API from passing an explicit `PaymentSecret` to a new `RecipientOnionFields` struct (which currently only contains the `PaymentSecret`). This gives us substantial additional flexibility as we look at add both `PaymentMetadata`, a new (well, year-or-two-old) BOLT11 invoice extension to provide additional data sent to the recipient. In the future, we should also add the ability to add custom TLV entries in the `RecipientOnionFields` struct.
1 parent 256aab4 commit 99174bb

16 files changed

+423
-216
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use lightning::chain::keysinterface::{KeyMaterial, InMemorySigner, Recipient, En
4141
use lightning::events;
4242
use lightning::events::MessageSendEventsProvider;
4343
use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
44-
use lightning::ln::channelmanager::{ChainParameters, ChannelDetails, ChannelManager, PaymentSendFailure, ChannelManagerReadArgs, PaymentId};
44+
use lightning::ln::channelmanager::{ChainParameters, ChannelDetails, ChannelManager, PaymentSendFailure, ChannelManagerReadArgs, PaymentId, RecipientOnionFields};
4545
use lightning::ln::channel::FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE;
4646
use lightning::ln::msgs::{self, CommitmentUpdate, ChannelMessageHandler, DecodeError, UpdateAddHTLC, Init};
4747
use lightning::ln::script::ShutdownScript;
@@ -361,7 +361,7 @@ fn send_payment(source: &ChanMan, dest: &ChanMan, dest_chan_id: u64, amt: u64, p
361361
cltv_expiry_delta: 200,
362362
}]],
363363
payment_params: None,
364-
}, payment_hash, &Some(payment_secret), PaymentId(payment_id)) {
364+
}, payment_hash, RecipientOnionFields::secret_only(payment_secret), PaymentId(payment_id)) {
365365
check_payment_err(err);
366366
false
367367
} else { true }
@@ -390,7 +390,7 @@ fn send_hop_payment(source: &ChanMan, middle: &ChanMan, middle_chan_id: u64, des
390390
cltv_expiry_delta: 200,
391391
}]],
392392
payment_params: None,
393-
}, payment_hash, &Some(payment_secret), PaymentId(payment_id)) {
393+
}, payment_hash, RecipientOnionFields::secret_only(payment_secret), PaymentId(payment_id)) {
394394
check_payment_err(err);
395395
false
396396
} else { true }

fuzz/src/full_stack.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use lightning::chain::transaction::OutPoint;
3737
use lightning::chain::keysinterface::{InMemorySigner, Recipient, KeyMaterial, EntropySource, NodeSigner, SignerProvider};
3838
use lightning::events::Event;
3939
use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
40-
use lightning::ln::channelmanager::{ChainParameters, ChannelDetails, ChannelManager, PaymentId};
40+
use lightning::ln::channelmanager::{ChainParameters, ChannelDetails, ChannelManager, PaymentId, RecipientOnionFields};
4141
use lightning::ln::peer_handler::{MessageHandler,PeerManager,SocketDescriptor,IgnoringMessageHandler};
4242
use lightning::ln::msgs::{self, DecodeError};
4343
use lightning::ln::script::ShutdownScript;
@@ -525,7 +525,9 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
525525
sha.input(&payment_hash.0[..]);
526526
payment_hash.0 = Sha256::from_engine(sha).into_inner();
527527
payments_sent += 1;
528-
match channelmanager.send_payment(&route, payment_hash, &None, PaymentId(payment_hash.0)) {
528+
match channelmanager.send_payment(&route, payment_hash,
529+
RecipientOnionFields::spontaneous_empty(), PaymentId(payment_hash.0))
530+
{
529531
Ok(_) => {},
530532
Err(_) => return,
531533
}
@@ -552,7 +554,9 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
552554
let mut payment_secret = PaymentSecret([0; 32]);
553555
payment_secret.0[0..8].copy_from_slice(&be64_to_array(payments_sent));
554556
payments_sent += 1;
555-
match channelmanager.send_payment(&route, payment_hash, &Some(payment_secret), PaymentId(payment_hash.0)) {
557+
match channelmanager.send_payment(&route, payment_hash,
558+
RecipientOnionFields::secret_only(payment_secret), PaymentId(payment_hash.0))
559+
{
556560
Ok(_) => {},
557561
Err(_) => return,
558562
}

lightning-invoice/src/payment.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use bitcoin_hashes::Hash;
1616
use lightning::chain;
1717
use lightning::chain::chaininterface::{BroadcasterInterface, FeeEstimator};
1818
use lightning::chain::keysinterface::{NodeSigner, SignerProvider, EntropySource};
19-
use lightning::ln::{PaymentHash, PaymentSecret};
20-
use lightning::ln::channelmanager::{ChannelManager, PaymentId, Retry, RetryableSendFailure};
19+
use lightning::ln::PaymentHash;
20+
use lightning::ln::channelmanager::{ChannelManager, PaymentId, Retry, RetryableSendFailure, RecipientOnionFields};
2121
use lightning::routing::router::{PaymentParameters, RouteParameters, Router};
2222
use lightning::util::logger::Logger;
2323

@@ -146,6 +146,7 @@ fn pay_invoice_using_amount<P: Deref>(
146146
) -> Result<(), PaymentError> where P::Target: Payer {
147147
let payment_hash = PaymentHash((*invoice.payment_hash()).into_inner());
148148
let payment_secret = Some(*invoice.payment_secret());
149+
let recipient_info = RecipientOnionFields { payment_secret };
149150
let mut payment_params = PaymentParameters::from_node_id(invoice.recover_payee_pub_key(),
150151
invoice.min_final_cltv_expiry_delta() as u32)
151152
.with_expiry_time(expiry_time_from_unix_epoch(invoice).as_secs())
@@ -158,7 +159,7 @@ fn pay_invoice_using_amount<P: Deref>(
158159
final_value_msat: amount_msats,
159160
};
160161

161-
payer.send_payment(payment_hash, &payment_secret, payment_id, route_params, retry_strategy)
162+
payer.send_payment(payment_hash, recipient_info, payment_id, route_params, retry_strategy)
162163
}
163164

164165
fn expiry_time_from_unix_epoch(invoice: &Invoice) -> Duration {
@@ -182,7 +183,7 @@ trait Payer {
182183
///
183184
/// [`Route`]: lightning::routing::router::Route
184185
fn send_payment(
185-
&self, payment_hash: PaymentHash, payment_secret: &Option<PaymentSecret>,
186+
&self, payment_hash: PaymentHash, recipient_info: RecipientOnionFields,
186187
payment_id: PaymentId, route_params: RouteParameters, retry_strategy: Retry
187188
) -> Result<(), PaymentError>;
188189
}
@@ -199,10 +200,10 @@ where
199200
L::Target: Logger,
200201
{
201202
fn send_payment(
202-
&self, payment_hash: PaymentHash, payment_secret: &Option<PaymentSecret>,
203+
&self, payment_hash: PaymentHash, recipient_info: RecipientOnionFields,
203204
payment_id: PaymentId, route_params: RouteParameters, retry_strategy: Retry
204205
) -> Result<(), PaymentError> {
205-
self.send_payment_with_retry(payment_hash, payment_secret, payment_id, route_params, retry_strategy)
206+
self.send_payment_with_retry(payment_hash, recipient_info, payment_id, route_params, retry_strategy)
206207
.map_err(PaymentError::Sending)
207208
}
208209
}
@@ -212,7 +213,7 @@ mod tests {
212213
use super::*;
213214
use crate::{InvoiceBuilder, Currency};
214215
use bitcoin_hashes::sha256::Hash as Sha256;
215-
use lightning::ln::PaymentPreimage;
216+
use lightning::ln::{PaymentPreimage, PaymentSecret};
216217
use lightning::ln::functional_test_utils::*;
217218
use secp256k1::{SecretKey, Secp256k1};
218219
use std::collections::VecDeque;
@@ -249,7 +250,7 @@ mod tests {
249250

250251
impl Payer for TestPayer {
251252
fn send_payment(
252-
&self, _payment_hash: PaymentHash, _payment_secret: &Option<PaymentSecret>,
253+
&self, _payment_hash: PaymentHash, _recipient_info: RecipientOnionFields,
253254
_payment_id: PaymentId, route_params: RouteParameters, _retry_strategy: Retry
254255
) -> Result<(), PaymentError> {
255256
self.check_value_msats(Amount(route_params.final_value_msat));

lightning-invoice/src/utils.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ mod test {
667667
use lightning::chain::keysinterface::{EntropySource, PhantomKeysManager};
668668
use lightning::events::{MessageSendEvent, MessageSendEventsProvider, Event};
669669
use lightning::ln::{PaymentPreimage, PaymentHash};
670-
use lightning::ln::channelmanager::{PhantomRouteHints, MIN_FINAL_CLTV_EXPIRY_DELTA, PaymentId};
670+
use lightning::ln::channelmanager::{PhantomRouteHints, MIN_FINAL_CLTV_EXPIRY_DELTA, PaymentId, RecipientOnionFields};
671671
use lightning::ln::functional_test_utils::*;
672672
use lightning::ln::msgs::ChannelMessageHandler;
673673
use lightning::routing::router::{PaymentParameters, RouteParameters, find_route};
@@ -725,7 +725,8 @@ mod test {
725725
let payment_event = {
726726
let mut payment_hash = PaymentHash([0; 32]);
727727
payment_hash.0.copy_from_slice(&invoice.payment_hash().as_ref()[0..32]);
728-
nodes[0].node.send_payment(&route, payment_hash, &Some(*invoice.payment_secret()), PaymentId(payment_hash.0)).unwrap();
728+
nodes[0].node.send_payment(&route, payment_hash,
729+
RecipientOnionFields::secret_only(*invoice.payment_secret()), PaymentId(payment_hash.0)).unwrap();
729730
let mut added_monitors = nodes[0].chain_monitor.added_monitors.lock().unwrap();
730731
assert_eq!(added_monitors.len(), 1);
731732
added_monitors.clear();
@@ -1144,7 +1145,8 @@ mod test {
11441145
let (payment_event, fwd_idx) = {
11451146
let mut payment_hash = PaymentHash([0; 32]);
11461147
payment_hash.0.copy_from_slice(&invoice.payment_hash().as_ref()[0..32]);
1147-
nodes[0].node.send_payment(&route, payment_hash, &Some(*invoice.payment_secret()), PaymentId(payment_hash.0)).unwrap();
1148+
nodes[0].node.send_payment(&route, payment_hash,
1149+
RecipientOnionFields::secret_only(*invoice.payment_secret()), PaymentId(payment_hash.0)).unwrap();
11481150
let mut added_monitors = nodes[0].chain_monitor.added_monitors.lock().unwrap();
11491151
assert_eq!(added_monitors.len(), 1);
11501152
added_monitors.clear();

lightning/src/chain/chainmonitor.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ mod tests {
812812
use crate::chain::{ChannelMonitorUpdateStatus, Confirm, Watch};
813813
use crate::chain::channelmonitor::LATENCY_GRACE_PERIOD_BLOCKS;
814814
use crate::events::{Event, ClosureReason, MessageSendEvent, MessageSendEventsProvider};
815-
use crate::ln::channelmanager::{PaymentSendFailure, PaymentId};
815+
use crate::ln::channelmanager::{PaymentSendFailure, PaymentId, RecipientOnionFields};
816816
use crate::ln::functional_test_utils::*;
817817
use crate::ln::msgs::ChannelMessageHandler;
818818
use crate::util::errors::APIError;
@@ -964,7 +964,8 @@ mod tests {
964964
// If the ChannelManager tries to update the channel, however, the ChainMonitor will pass
965965
// the update through to the ChannelMonitor which will refuse it (as the channel is closed).
966966
chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed);
967-
unwrap_send_err!(nodes[0].node.send_payment(&route, second_payment_hash, &Some(second_payment_secret), PaymentId(second_payment_hash.0)),
967+
unwrap_send_err!(nodes[0].node.send_payment(&route, second_payment_hash,
968+
RecipientOnionFields::secret_only(second_payment_secret), PaymentId(second_payment_hash.0)),
968969
true, APIError::ChannelUnavailable { ref err },
969970
assert!(err.contains("ChannelMonitor storage failure")));
970971
check_added_monitors!(nodes[0], 2); // After the failure we generate a close-channel monitor update

lightning/src/chain/channelmonitor.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4016,7 +4016,7 @@ mod tests {
40164016
use crate::ln::{PaymentPreimage, PaymentHash};
40174017
use crate::ln::chan_utils;
40184018
use crate::ln::chan_utils::{HTLCOutputInCommitment, ChannelPublicKeys, ChannelTransactionParameters, HolderCommitmentTransaction, CounterpartyChannelTransactionParameters};
4019-
use crate::ln::channelmanager::{PaymentSendFailure, PaymentId};
4019+
use crate::ln::channelmanager::{PaymentSendFailure, PaymentId, RecipientOnionFields};
40204020
use crate::ln::functional_test_utils::*;
40214021
use crate::ln::script::ShutdownScript;
40224022
use crate::util::errors::APIError;
@@ -4078,7 +4078,8 @@ mod tests {
40784078
// If the ChannelManager tries to update the channel, however, the ChainMonitor will pass
40794079
// the update through to the ChannelMonitor which will refuse it (as the channel is closed).
40804080
let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[1], nodes[0], 100_000);
4081-
unwrap_send_err!(nodes[1].node.send_payment(&route, payment_hash, &Some(payment_secret), PaymentId(payment_hash.0)),
4081+
unwrap_send_err!(nodes[1].node.send_payment(&route, payment_hash,
4082+
RecipientOnionFields::secret_only(payment_secret), PaymentId(payment_hash.0)),
40824083
true, APIError::ChannelUnavailable { ref err },
40834084
assert!(err.contains("ChannelMonitor storage failure")));
40844085
check_added_monitors!(nodes[1], 2); // After the failure we generate a close-channel monitor update

0 commit comments

Comments
 (0)