Skip to content

Commit c3c1050

Browse files
authored
Merge pull request #2351 from TheBlueMatt/2023-04-remove-legacy-recv
Drop `create_inbound_payment*_legacy` breaking downgrade to 0.0.103
2 parents ae9e96e + 942d776 commit c3c1050

File tree

4 files changed

+9
-126
lines changed

4 files changed

+9
-126
lines changed

lightning/src/events/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ impl Writeable for Event {
855855
(3, via_channel_id, option),
856856
(4, amount_msat, required),
857857
(5, via_user_channel_id, option),
858-
(6, 0u64, required), // user_payment_id required for compatibility with 0.0.103 and earlier
858+
// Type 6 was `user_payment_id` on 0.0.103 and earlier
859859
(7, claim_deadline, option),
860860
(8, payment_preimage, option),
861861
(9, onion_fields, option),
@@ -1059,7 +1059,7 @@ impl MaybeReadable for Event {
10591059
let mut payment_secret = None;
10601060
let mut amount_msat = 0;
10611061
let mut receiver_node_id = None;
1062-
let mut _user_payment_id = None::<u64>; // For compatibility with 0.0.103 and earlier
1062+
let mut _user_payment_id = None::<u64>; // Used in 0.0.103 and earlier, no longer written in 0.0.116+.
10631063
let mut via_channel_id = None;
10641064
let mut claim_deadline = None;
10651065
let mut via_user_channel_id = None;

lightning/src/ln/channelmanager.rs

+1-63
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use crate::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParame
5050
use crate::ln::msgs;
5151
use crate::ln::onion_utils;
5252
use crate::ln::onion_utils::HTLCFailReason;
53-
use crate::ln::msgs::{ChannelMessageHandler, DecodeError, LightningError, MAX_VALUE_MSAT};
53+
use crate::ln::msgs::{ChannelMessageHandler, DecodeError, LightningError};
5454
#[cfg(test)]
5555
use crate::ln::outbound_payment;
5656
use crate::ln::outbound_payment::{OutboundPayments, PaymentAttempts, PendingOutboundPayment};
@@ -6005,37 +6005,6 @@ where
60056005
}
60066006
}
60076007

6008-
fn set_payment_hash_secret_map(&self, payment_hash: PaymentHash, payment_preimage: Option<PaymentPreimage>, min_value_msat: Option<u64>, invoice_expiry_delta_secs: u32) -> Result<PaymentSecret, APIError> {
6009-
assert!(invoice_expiry_delta_secs <= 60*60*24*365); // Sadly bitcoin timestamps are u32s, so panic before 2106
6010-
6011-
if min_value_msat.is_some() && min_value_msat.unwrap() > MAX_VALUE_MSAT {
6012-
return Err(APIError::APIMisuseError { err: format!("min_value_msat of {} greater than total 21 million bitcoin supply", min_value_msat.unwrap()) });
6013-
}
6014-
6015-
let payment_secret = PaymentSecret(self.entropy_source.get_secure_random_bytes());
6016-
6017-
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
6018-
let mut payment_secrets = self.pending_inbound_payments.lock().unwrap();
6019-
match payment_secrets.entry(payment_hash) {
6020-
hash_map::Entry::Vacant(e) => {
6021-
e.insert(PendingInboundPayment {
6022-
payment_secret, min_value_msat, payment_preimage,
6023-
user_payment_id: 0, // For compatibility with version 0.0.103 and earlier
6024-
// We assume that highest_seen_timestamp is pretty close to the current time -
6025-
// it's updated when we receive a new block with the maximum time we've seen in
6026-
// a header. It should never be more than two hours in the future.
6027-
// Thus, we add two hours here as a buffer to ensure we absolutely
6028-
// never fail a payment too early.
6029-
// Note that we assume that received blocks have reasonably up-to-date
6030-
// timestamps.
6031-
expiry_time: self.highest_seen_timestamp.load(Ordering::Acquire) as u64 + invoice_expiry_delta_secs as u64 + 7200,
6032-
});
6033-
},
6034-
hash_map::Entry::Occupied(_) => return Err(APIError::APIMisuseError { err: "Duplicate payment hash".to_owned() }),
6035-
}
6036-
Ok(payment_secret)
6037-
}
6038-
60396008
/// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
60406009
/// to pay us.
60416010
///
@@ -6075,23 +6044,6 @@ where
60756044
min_final_cltv_expiry_delta)
60766045
}
60776046

6078-
/// Legacy version of [`create_inbound_payment`]. Use this method if you wish to share
6079-
/// serialized state with LDK node(s) running 0.0.103 and earlier.
6080-
///
6081-
/// May panic if `invoice_expiry_delta_secs` is greater than one year.
6082-
///
6083-
/// # Note
6084-
/// This method is deprecated and will be removed soon.
6085-
///
6086-
/// [`create_inbound_payment`]: Self::create_inbound_payment
6087-
#[deprecated]
6088-
pub fn create_inbound_payment_legacy(&self, min_value_msat: Option<u64>, invoice_expiry_delta_secs: u32) -> Result<(PaymentHash, PaymentSecret), APIError> {
6089-
let payment_preimage = PaymentPreimage(self.entropy_source.get_secure_random_bytes());
6090-
let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0).into_inner());
6091-
let payment_secret = self.set_payment_hash_secret_map(payment_hash, Some(payment_preimage), min_value_msat, invoice_expiry_delta_secs)?;
6092-
Ok((payment_hash, payment_secret))
6093-
}
6094-
60956047
/// Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
60966048
/// stored external to LDK.
60976049
///
@@ -6145,20 +6097,6 @@ where
61456097
min_final_cltv_expiry)
61466098
}
61476099

6148-
/// Legacy version of [`create_inbound_payment_for_hash`]. Use this method if you wish to share
6149-
/// serialized state with LDK node(s) running 0.0.103 and earlier.
6150-
///
6151-
/// May panic if `invoice_expiry_delta_secs` is greater than one year.
6152-
///
6153-
/// # Note
6154-
/// This method is deprecated and will be removed soon.
6155-
///
6156-
/// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
6157-
#[deprecated]
6158-
pub fn create_inbound_payment_for_hash_legacy(&self, payment_hash: PaymentHash, min_value_msat: Option<u64>, invoice_expiry_delta_secs: u32) -> Result<PaymentSecret, APIError> {
6159-
self.set_payment_hash_secret_map(payment_hash, None, min_value_msat, invoice_expiry_delta_secs)
6160-
}
6161-
61626100
/// Gets an LDK-generated payment preimage from a payment hash and payment secret that were
61636101
/// previously returned from [`create_inbound_payment`].
61646102
///

lightning/src/ln/functional_tests.rs

-61
Original file line numberDiff line numberDiff line change
@@ -8202,67 +8202,6 @@ fn test_preimage_storage() {
82028202
}
82038203
}
82048204

8205-
#[test]
8206-
#[allow(deprecated)]
8207-
fn test_secret_timeout() {
8208-
// Simple test of payment secret storage time outs. After
8209-
// `create_inbound_payment(_for_hash)_legacy` is removed, this test will be removed as well.
8210-
let chanmon_cfgs = create_chanmon_cfgs(2);
8211-
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
8212-
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
8213-
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
8214-
8215-
create_announced_chan_between_nodes(&nodes, 0, 1).0.contents.short_channel_id;
8216-
8217-
let (payment_hash, payment_secret_1) = nodes[1].node.create_inbound_payment_legacy(Some(100_000), 2).unwrap();
8218-
8219-
// We should fail to register the same payment hash twice, at least until we've connected a
8220-
// block with time 7200 + CHAN_CONFIRM_DEPTH + 1.
8221-
if let Err(APIError::APIMisuseError { err }) = nodes[1].node.create_inbound_payment_for_hash_legacy(payment_hash, Some(100_000), 2) {
8222-
assert_eq!(err, "Duplicate payment hash");
8223-
} else { panic!(); }
8224-
let mut block = {
8225-
let node_1_blocks = nodes[1].blocks.lock().unwrap();
8226-
create_dummy_block(node_1_blocks.last().unwrap().0.block_hash(), node_1_blocks.len() as u32 + 7200, Vec::new())
8227-
};
8228-
connect_block(&nodes[1], &block);
8229-
if let Err(APIError::APIMisuseError { err }) = nodes[1].node.create_inbound_payment_for_hash_legacy(payment_hash, Some(100_000), 2) {
8230-
assert_eq!(err, "Duplicate payment hash");
8231-
} else { panic!(); }
8232-
8233-
// If we then connect the second block, we should be able to register the same payment hash
8234-
// again (this time getting a new payment secret).
8235-
block.header.prev_blockhash = block.header.block_hash();
8236-
block.header.time += 1;
8237-
connect_block(&nodes[1], &block);
8238-
let our_payment_secret = nodes[1].node.create_inbound_payment_for_hash_legacy(payment_hash, Some(100_000), 2).unwrap();
8239-
assert_ne!(payment_secret_1, our_payment_secret);
8240-
8241-
{
8242-
let (route, _, _, _) = get_route_and_payment_hash!(nodes[0], nodes[1], 100_000);
8243-
nodes[0].node.send_payment_with_route(&route, payment_hash,
8244-
RecipientOnionFields::secret_only(our_payment_secret), PaymentId(payment_hash.0)).unwrap();
8245-
check_added_monitors!(nodes[0], 1);
8246-
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
8247-
let mut payment_event = SendEvent::from_event(events.pop().unwrap());
8248-
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]);
8249-
commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false);
8250-
}
8251-
// Note that after leaving the above scope we have no knowledge of any arguments or return
8252-
// values from previous calls.
8253-
expect_pending_htlcs_forwardable!(nodes[1]);
8254-
let events = nodes[1].node.get_and_clear_pending_events();
8255-
assert_eq!(events.len(), 1);
8256-
match events[0] {
8257-
Event::PaymentClaimable { purpose: PaymentPurpose::InvoicePayment { payment_preimage, payment_secret }, .. } => {
8258-
assert!(payment_preimage.is_none());
8259-
assert_eq!(payment_secret, our_payment_secret);
8260-
// We don't actually have the payment preimage with which to claim this payment!
8261-
},
8262-
_ => panic!("Unexpected event"),
8263-
}
8264-
}
8265-
82668205
#[test]
82678206
fn test_bad_secret_hash() {
82688207
// Simple test of unregistered payment hash/invalid payment secret handling
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
* Legacy inbound payment creation has been removed, thus there is no way to
2+
create a pending inbound payment which will still be claimable on LDK
3+
0.0.103 or earlier. Support for claiming such payments is still retained,
4+
however is likely to be removed in the next release (#2351).
5+
* Some fields required in 0.0.103 and earlier are no longer written, thus
6+
deserializing objects written in 0.0.116 with 0.0.103 may now fail (#2351).

0 commit comments

Comments
 (0)