Skip to content

Commit 6535627

Browse files
committed
Drop create_inbound_payment*_legacy breaking downgrade to 0.0.103
0.0.103 is now downright ancient, and certainly shouldn't exist in production anywhere today. Thus, it seems fine to remove the ability to create legacy stateful inbound payment entries. Users downgrading to 0.0.103 will thus not be able to claim any payments created on modern LDK, though we still retain the ability to claim such payments at least for one more release.
1 parent 42e2f1d commit 6535627

File tree

3 files changed

+5
-124
lines changed

3 files changed

+5
-124
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 63 deletions
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};
@@ -5874,37 +5874,6 @@ where
58745874
}
58755875
}
58765876

5877-
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> {
5878-
assert!(invoice_expiry_delta_secs <= 60*60*24*365); // Sadly bitcoin timestamps are u32s, so panic before 2106
5879-
5880-
if min_value_msat.is_some() && min_value_msat.unwrap() > MAX_VALUE_MSAT {
5881-
return Err(APIError::APIMisuseError { err: format!("min_value_msat of {} greater than total 21 million bitcoin supply", min_value_msat.unwrap()) });
5882-
}
5883-
5884-
let payment_secret = PaymentSecret(self.entropy_source.get_secure_random_bytes());
5885-
5886-
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
5887-
let mut payment_secrets = self.pending_inbound_payments.lock().unwrap();
5888-
match payment_secrets.entry(payment_hash) {
5889-
hash_map::Entry::Vacant(e) => {
5890-
e.insert(PendingInboundPayment {
5891-
payment_secret, min_value_msat, payment_preimage,
5892-
user_payment_id: 0, // For compatibility with version 0.0.103 and earlier
5893-
// We assume that highest_seen_timestamp is pretty close to the current time -
5894-
// it's updated when we receive a new block with the maximum time we've seen in
5895-
// a header. It should never be more than two hours in the future.
5896-
// Thus, we add two hours here as a buffer to ensure we absolutely
5897-
// never fail a payment too early.
5898-
// Note that we assume that received blocks have reasonably up-to-date
5899-
// timestamps.
5900-
expiry_time: self.highest_seen_timestamp.load(Ordering::Acquire) as u64 + invoice_expiry_delta_secs as u64 + 7200,
5901-
});
5902-
},
5903-
hash_map::Entry::Occupied(_) => return Err(APIError::APIMisuseError { err: "Duplicate payment hash".to_owned() }),
5904-
}
5905-
Ok(payment_secret)
5906-
}
5907-
59085877
/// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
59095878
/// to pay us.
59105879
///
@@ -5944,23 +5913,6 @@ where
59445913
min_final_cltv_expiry_delta)
59455914
}
59465915

5947-
/// Legacy version of [`create_inbound_payment`]. Use this method if you wish to share
5948-
/// serialized state with LDK node(s) running 0.0.103 and earlier.
5949-
///
5950-
/// May panic if `invoice_expiry_delta_secs` is greater than one year.
5951-
///
5952-
/// # Note
5953-
/// This method is deprecated and will be removed soon.
5954-
///
5955-
/// [`create_inbound_payment`]: Self::create_inbound_payment
5956-
#[deprecated]
5957-
pub fn create_inbound_payment_legacy(&self, min_value_msat: Option<u64>, invoice_expiry_delta_secs: u32) -> Result<(PaymentHash, PaymentSecret), APIError> {
5958-
let payment_preimage = PaymentPreimage(self.entropy_source.get_secure_random_bytes());
5959-
let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0).into_inner());
5960-
let payment_secret = self.set_payment_hash_secret_map(payment_hash, Some(payment_preimage), min_value_msat, invoice_expiry_delta_secs)?;
5961-
Ok((payment_hash, payment_secret))
5962-
}
5963-
59645916
/// Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
59655917
/// stored external to LDK.
59665918
///
@@ -6014,20 +5966,6 @@ where
60145966
min_final_cltv_expiry)
60155967
}
60165968

6017-
/// Legacy version of [`create_inbound_payment_for_hash`]. Use this method if you wish to share
6018-
/// serialized state with LDK node(s) running 0.0.103 and earlier.
6019-
///
6020-
/// May panic if `invoice_expiry_delta_secs` is greater than one year.
6021-
///
6022-
/// # Note
6023-
/// This method is deprecated and will be removed soon.
6024-
///
6025-
/// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
6026-
#[deprecated]
6027-
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> {
6028-
self.set_payment_hash_secret_map(payment_hash, None, min_value_msat, invoice_expiry_delta_secs)
6029-
}
6030-
60315969
/// Gets an LDK-generated payment preimage from a payment hash and payment secret that were
60325970
/// previously returned from [`create_inbound_payment`].
60335971
///

lightning/src/ln/functional_tests.rs

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -8196,67 +8196,6 @@ fn test_preimage_storage() {
81968196
}
81978197
}
81988198

8199-
#[test]
8200-
#[allow(deprecated)]
8201-
fn test_secret_timeout() {
8202-
// Simple test of payment secret storage time outs. After
8203-
// `create_inbound_payment(_for_hash)_legacy` is removed, this test will be removed as well.
8204-
let chanmon_cfgs = create_chanmon_cfgs(2);
8205-
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
8206-
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
8207-
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
8208-
8209-
create_announced_chan_between_nodes(&nodes, 0, 1).0.contents.short_channel_id;
8210-
8211-
let (payment_hash, payment_secret_1) = nodes[1].node.create_inbound_payment_legacy(Some(100_000), 2).unwrap();
8212-
8213-
// We should fail to register the same payment hash twice, at least until we've connected a
8214-
// block with time 7200 + CHAN_CONFIRM_DEPTH + 1.
8215-
if let Err(APIError::APIMisuseError { err }) = nodes[1].node.create_inbound_payment_for_hash_legacy(payment_hash, Some(100_000), 2) {
8216-
assert_eq!(err, "Duplicate payment hash");
8217-
} else { panic!(); }
8218-
let mut block = {
8219-
let node_1_blocks = nodes[1].blocks.lock().unwrap();
8220-
create_dummy_block(node_1_blocks.last().unwrap().0.block_hash(), node_1_blocks.len() as u32 + 7200, Vec::new())
8221-
};
8222-
connect_block(&nodes[1], &block);
8223-
if let Err(APIError::APIMisuseError { err }) = nodes[1].node.create_inbound_payment_for_hash_legacy(payment_hash, Some(100_000), 2) {
8224-
assert_eq!(err, "Duplicate payment hash");
8225-
} else { panic!(); }
8226-
8227-
// If we then connect the second block, we should be able to register the same payment hash
8228-
// again (this time getting a new payment secret).
8229-
block.header.prev_blockhash = block.header.block_hash();
8230-
block.header.time += 1;
8231-
connect_block(&nodes[1], &block);
8232-
let our_payment_secret = nodes[1].node.create_inbound_payment_for_hash_legacy(payment_hash, Some(100_000), 2).unwrap();
8233-
assert_ne!(payment_secret_1, our_payment_secret);
8234-
8235-
{
8236-
let (route, _, _, _) = get_route_and_payment_hash!(nodes[0], nodes[1], 100_000);
8237-
nodes[0].node.send_payment_with_route(&route, payment_hash,
8238-
RecipientOnionFields::secret_only(our_payment_secret), PaymentId(payment_hash.0)).unwrap();
8239-
check_added_monitors!(nodes[0], 1);
8240-
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
8241-
let mut payment_event = SendEvent::from_event(events.pop().unwrap());
8242-
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]);
8243-
commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false);
8244-
}
8245-
// Note that after leaving the above scope we have no knowledge of any arguments or return
8246-
// values from previous calls.
8247-
expect_pending_htlcs_forwardable!(nodes[1]);
8248-
let events = nodes[1].node.get_and_clear_pending_events();
8249-
assert_eq!(events.len(), 1);
8250-
match events[0] {
8251-
Event::PaymentClaimable { purpose: PaymentPurpose::InvoicePayment { payment_preimage, payment_secret }, .. } => {
8252-
assert!(payment_preimage.is_none());
8253-
assert_eq!(payment_secret, our_payment_secret);
8254-
// We don't actually have the payment preimage with which to claim this payment!
8255-
},
8256-
_ => panic!("Unexpected event"),
8257-
}
8258-
}
8259-
82608199
#[test]
82618200
fn test_bad_secret_hash() {
82628201
// Simple test of unregistered payment hash/invalid payment secret handling
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
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.

0 commit comments

Comments
 (0)