Skip to content

Commit 28eea12

Browse files
Rename MppId to PaymentId
Leftover from previous PR Jeff feedback. Useful in upcoming commits as we'll expose this to users for payment retries
1 parent 5811f5b commit 28eea12

File tree

3 files changed

+39
-39
lines changed

3 files changed

+39
-39
lines changed

lightning/src/ln/channel.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5509,7 +5509,7 @@ mod tests {
55095509
use bitcoin::hashes::hex::FromHex;
55105510
use hex;
55115511
use ln::{PaymentPreimage, PaymentHash};
5512-
use ln::channelmanager::{HTLCSource, MppId};
5512+
use ln::channelmanager::{HTLCSource, PaymentId};
55135513
use ln::channel::{Channel,InboundHTLCOutput,OutboundHTLCOutput,InboundHTLCState,OutboundHTLCState,HTLCOutputInCommitment,HTLCCandidate,HTLCInitiator,TxCreationKeys};
55145514
use ln::channel::MAX_FUNDING_SATOSHIS;
55155515
use ln::features::InitFeatures;
@@ -5683,7 +5683,7 @@ mod tests {
56835683
path: Vec::new(),
56845684
session_priv: SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap(),
56855685
first_hop_htlc_msat: 548,
5686-
mpp_id: MppId([42; 32]),
5686+
payment_id: PaymentId([42; 32]),
56875687
}
56885688
});
56895689

lightning/src/ln/channelmanager.rs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -172,20 +172,20 @@ struct ClaimableHTLC {
172172
onion_payload: OnionPayload,
173173
}
174174

175-
/// A payment identifier used to correlate an MPP payment's per-path HTLC sources internally.
175+
/// A payment identifier used to uniquely identify a payment to LDK.
176176
#[derive(Hash, Copy, Clone, PartialEq, Eq, Debug)]
177-
pub(crate) struct MppId(pub [u8; 32]);
177+
pub(crate) struct PaymentId(pub [u8; 32]);
178178

179-
impl Writeable for MppId {
179+
impl Writeable for PaymentId {
180180
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
181181
self.0.write(w)
182182
}
183183
}
184184

185-
impl Readable for MppId {
185+
impl Readable for PaymentId {
186186
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
187187
let buf: [u8; 32] = Readable::read(r)?;
188-
Ok(MppId(buf))
188+
Ok(PaymentId(buf))
189189
}
190190
}
191191
/// Tracks the inbound corresponding to an outbound HTLC
@@ -198,7 +198,7 @@ pub(crate) enum HTLCSource {
198198
/// Technically we can recalculate this from the route, but we cache it here to avoid
199199
/// doing a double-pass on route when we get a failure back
200200
first_hop_htlc_msat: u64,
201-
mpp_id: MppId,
201+
payment_id: PaymentId,
202202
},
203203
}
204204
#[cfg(test)]
@@ -208,7 +208,7 @@ impl HTLCSource {
208208
path: Vec::new(),
209209
session_priv: SecretKey::from_slice(&[1; 32]).unwrap(),
210210
first_hop_htlc_msat: 0,
211-
mpp_id: MppId([2; 32]),
211+
payment_id: PaymentId([2; 32]),
212212
}
213213
}
214214
}
@@ -499,7 +499,7 @@ pub struct ChannelManager<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref,
499499
/// payments over a single path).
500500
///
501501
/// Locked *after* channel_state.
502-
pending_outbound_payments: Mutex<HashMap<MppId, HashSet<[u8; 32]>>>,
502+
pending_outbound_payments: Mutex<HashMap<PaymentId, HashSet<[u8; 32]>>>,
503503

504504
our_network_key: SecretKey,
505505
our_network_pubkey: PublicKey,
@@ -1878,7 +1878,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
18781878
}
18791879

18801880
// Only public for testing, this should otherwise never be called direcly
1881-
pub(crate) fn send_payment_along_path(&self, path: &Vec<RouteHop>, payment_hash: &PaymentHash, payment_secret: &Option<PaymentSecret>, total_value: u64, cur_height: u32, mpp_id: MppId, keysend_preimage: &Option<PaymentPreimage>) -> Result<(), APIError> {
1881+
pub(crate) fn send_payment_along_path(&self, path: &Vec<RouteHop>, payment_hash: &PaymentHash, payment_secret: &Option<PaymentSecret>, total_value: u64, cur_height: u32, payment_id: PaymentId, keysend_preimage: &Option<PaymentPreimage>) -> Result<(), APIError> {
18821882
log_trace!(self.logger, "Attempting to send payment for path with next hop {}", path.first().unwrap().short_channel_id);
18831883
let prng_seed = self.keys_manager.get_secure_random_bytes();
18841884
let session_priv_bytes = self.keys_manager.get_secure_random_bytes();
@@ -1894,7 +1894,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
18941894

18951895
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier);
18961896
let mut pending_outbounds = self.pending_outbound_payments.lock().unwrap();
1897-
let sessions = pending_outbounds.entry(mpp_id).or_insert(HashSet::new());
1897+
let sessions = pending_outbounds.entry(payment_id).or_insert(HashSet::new());
18981898
assert!(sessions.insert(session_priv_bytes));
18991899

19001900
let err: Result<(), _> = loop {
@@ -1917,7 +1917,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
19171917
path: path.clone(),
19181918
session_priv: session_priv.clone(),
19191919
first_hop_htlc_msat: htlc_msat,
1920-
mpp_id,
1920+
payment_id,
19211921
}, onion_packet, &self.logger), channel_state, chan)
19221922
} {
19231923
Some((update_add, commitment_signed, monitor_update)) => {
@@ -2017,7 +2017,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
20172017
let mut total_value = 0;
20182018
let our_node_id = self.get_our_node_id();
20192019
let mut path_errs = Vec::with_capacity(route.paths.len());
2020-
let mpp_id = MppId(self.keys_manager.get_secure_random_bytes());
2020+
let payment_id = PaymentId(self.keys_manager.get_secure_random_bytes());
20212021
'path_check: for path in route.paths.iter() {
20222022
if path.len() < 1 || path.len() > 20 {
20232023
path_errs.push(Err(APIError::RouteError{err: "Path didn't go anywhere/had bogus size"}));
@@ -2039,7 +2039,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
20392039
let cur_height = self.best_block.read().unwrap().height() + 1;
20402040
let mut results = Vec::new();
20412041
for path in route.paths.iter() {
2042-
results.push(self.send_payment_along_path(&path, &payment_hash, payment_secret, total_value, cur_height, mpp_id, &keysend_preimage));
2042+
results.push(self.send_payment_along_path(&path, &payment_hash, payment_secret, total_value, cur_height, payment_id, &keysend_preimage));
20432043
}
20442044
let mut has_ok = false;
20452045
let mut has_err = false;
@@ -2875,11 +2875,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
28752875
self.fail_htlc_backwards_internal(channel_state,
28762876
htlc_src, &payment_hash, HTLCFailReason::Reason { failure_code, data: onion_failure_data});
28772877
},
2878-
HTLCSource::OutboundRoute { session_priv, mpp_id, path, .. } => {
2878+
HTLCSource::OutboundRoute { session_priv, payment_id, path, .. } => {
28792879
let mut session_priv_bytes = [0; 32];
28802880
session_priv_bytes.copy_from_slice(&session_priv[..]);
28812881
let mut outbounds = self.pending_outbound_payments.lock().unwrap();
2882-
if let hash_map::Entry::Occupied(mut sessions) = outbounds.entry(mpp_id) {
2882+
if let hash_map::Entry::Occupied(mut sessions) = outbounds.entry(payment_id) {
28832883
if sessions.get_mut().remove(&session_priv_bytes) {
28842884
self.pending_events.lock().unwrap().push(
28852885
events::Event::PaymentPathFailed {
@@ -2922,12 +2922,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
29222922
// from block_connected which may run during initialization prior to the chain_monitor
29232923
// being fully configured. See the docs for `ChannelManagerReadArgs` for more.
29242924
match source {
2925-
HTLCSource::OutboundRoute { ref path, session_priv, mpp_id, .. } => {
2925+
HTLCSource::OutboundRoute { ref path, session_priv, payment_id, .. } => {
29262926
let mut session_priv_bytes = [0; 32];
29272927
session_priv_bytes.copy_from_slice(&session_priv[..]);
29282928
let mut outbounds = self.pending_outbound_payments.lock().unwrap();
29292929
let mut all_paths_failed = false;
2930-
if let hash_map::Entry::Occupied(mut sessions) = outbounds.entry(mpp_id) {
2930+
if let hash_map::Entry::Occupied(mut sessions) = outbounds.entry(payment_id) {
29312931
if !sessions.get_mut().remove(&session_priv_bytes) {
29322932
log_trace!(self.logger, "Received duplicative fail for HTLC with payment_hash {}", log_bytes!(payment_hash.0));
29332933
return;
@@ -3181,12 +3181,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
31813181

31823182
fn claim_funds_internal(&self, mut channel_state_lock: MutexGuard<ChannelHolder<Signer>>, source: HTLCSource, payment_preimage: PaymentPreimage, forwarded_htlc_value_msat: Option<u64>, from_onchain: bool) {
31833183
match source {
3184-
HTLCSource::OutboundRoute { session_priv, mpp_id, .. } => {
3184+
HTLCSource::OutboundRoute { session_priv, payment_id, .. } => {
31853185
mem::drop(channel_state_lock);
31863186
let mut session_priv_bytes = [0; 32];
31873187
session_priv_bytes.copy_from_slice(&session_priv[..]);
31883188
let mut outbounds = self.pending_outbound_payments.lock().unwrap();
3189-
let found_payment = if let Some(mut sessions) = outbounds.remove(&mpp_id) {
3189+
let found_payment = if let Some(mut sessions) = outbounds.remove(&payment_id) {
31903190
sessions.remove(&session_priv_bytes)
31913191
} else { false };
31923192
if found_payment {
@@ -5079,23 +5079,23 @@ impl Readable for HTLCSource {
50795079
let mut session_priv: ::util::ser::OptionDeserWrapper<SecretKey> = ::util::ser::OptionDeserWrapper(None);
50805080
let mut first_hop_htlc_msat: u64 = 0;
50815081
let mut path = Some(Vec::new());
5082-
let mut mpp_id = None;
5082+
let mut payment_id = None;
50835083
read_tlv_fields!(reader, {
50845084
(0, session_priv, required),
5085-
(1, mpp_id, option),
5085+
(1, payment_id, option),
50865086
(2, first_hop_htlc_msat, required),
50875087
(4, path, vec_type),
50885088
});
5089-
if mpp_id.is_none() {
5090-
// For backwards compat, if there was no mpp_id written, use the session_priv bytes
5089+
if payment_id.is_none() {
5090+
// For backwards compat, if there was no payment_id written, use the session_priv bytes
50915091
// instead.
5092-
mpp_id = Some(MppId(*session_priv.0.unwrap().as_ref()));
5092+
payment_id = Some(PaymentId(*session_priv.0.unwrap().as_ref()));
50935093
}
50945094
Ok(HTLCSource::OutboundRoute {
50955095
session_priv: session_priv.0.unwrap(),
50965096
first_hop_htlc_msat: first_hop_htlc_msat,
50975097
path: path.unwrap(),
5098-
mpp_id: mpp_id.unwrap(),
5098+
payment_id: payment_id.unwrap(),
50995099
})
51005100
}
51015101
1 => Ok(HTLCSource::PreviousHopData(Readable::read(reader)?)),
@@ -5107,12 +5107,12 @@ impl Readable for HTLCSource {
51075107
impl Writeable for HTLCSource {
51085108
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::io::Error> {
51095109
match self {
5110-
HTLCSource::OutboundRoute { ref session_priv, ref first_hop_htlc_msat, ref path, mpp_id } => {
5110+
HTLCSource::OutboundRoute { ref session_priv, ref first_hop_htlc_msat, ref path, payment_id } => {
51115111
0u8.write(writer)?;
5112-
let mpp_id_opt = Some(mpp_id);
5112+
let payment_id_opt = Some(payment_id);
51135113
write_tlv_fields!(writer, {
51145114
(0, session_priv, required),
5115-
(1, mpp_id_opt, option),
5115+
(1, payment_id_opt, option),
51165116
(2, first_hop_htlc_msat, required),
51175117
(4, path, vec_type),
51185118
});
@@ -5518,11 +5518,11 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
55185518
}
55195519

55205520
let pending_outbound_payments_count_compat: u64 = Readable::read(reader)?;
5521-
let mut pending_outbound_payments_compat: HashMap<MppId, HashSet<[u8; 32]>> =
5521+
let mut pending_outbound_payments_compat: HashMap<PaymentId, HashSet<[u8; 32]>> =
55225522
HashMap::with_capacity(cmp::min(pending_outbound_payments_count_compat as usize, MAX_ALLOC_SIZE/32));
55235523
for _ in 0..pending_outbound_payments_count_compat {
55245524
let session_priv = Readable::read(reader)?;
5525-
if pending_outbound_payments_compat.insert(MppId(session_priv), [session_priv].iter().cloned().collect()).is_some() {
5525+
if pending_outbound_payments_compat.insert(PaymentId(session_priv), [session_priv].iter().cloned().collect()).is_some() {
55265526
return Err(DecodeError::InvalidValue)
55275527
};
55285528
}
@@ -5596,7 +5596,7 @@ mod tests {
55965596
use bitcoin::hashes::sha256::Hash as Sha256;
55975597
use core::time::Duration;
55985598
use ln::{PaymentPreimage, PaymentHash, PaymentSecret};
5599-
use ln::channelmanager::{MppId, PaymentSendFailure};
5599+
use ln::channelmanager::{PaymentId, PaymentSendFailure};
56005600
use ln::features::{InitFeatures, InvoiceFeatures};
56015601
use ln::functional_test_utils::*;
56025602
use ln::msgs;
@@ -5747,11 +5747,11 @@ mod tests {
57475747
let net_graph_msg_handler = &nodes[0].net_graph_msg_handler;
57485748
let route = get_route(&nodes[0].node.get_our_node_id(), &net_graph_msg_handler.network_graph, &nodes[1].node.get_our_node_id(), Some(InvoiceFeatures::known()), None, &Vec::new(), 100_000, TEST_FINAL_CLTV, &logger).unwrap();
57495749
let (payment_preimage, our_payment_hash, payment_secret) = get_payment_preimage_hash!(&nodes[1]);
5750-
let mpp_id = MppId([42; 32]);
5750+
let payment_id = PaymentId([42; 32]);
57515751
// Use the utility function send_payment_along_path to send the payment with MPP data which
57525752
// indicates there are more HTLCs coming.
57535753
let cur_height = CHAN_CONFIRM_DEPTH + 1; // route_payment calls send_payment, which adds 1 to the current height. So we do the same here to match.
5754-
nodes[0].node.send_payment_along_path(&route.paths[0], &our_payment_hash, &Some(payment_secret), 200_000, cur_height, mpp_id, &None).unwrap();
5754+
nodes[0].node.send_payment_along_path(&route.paths[0], &our_payment_hash, &Some(payment_secret), 200_000, cur_height, payment_id, &None).unwrap();
57555755
check_added_monitors!(nodes[0], 1);
57565756
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
57575757
assert_eq!(events.len(), 1);
@@ -5781,7 +5781,7 @@ mod tests {
57815781
expect_payment_failed!(nodes[0], our_payment_hash, true);
57825782

57835783
// Send the second half of the original MPP payment.
5784-
nodes[0].node.send_payment_along_path(&route.paths[0], &our_payment_hash, &Some(payment_secret), 200_000, cur_height, mpp_id, &None).unwrap();
5784+
nodes[0].node.send_payment_along_path(&route.paths[0], &our_payment_hash, &Some(payment_secret), 200_000, cur_height, payment_id, &None).unwrap();
57855785
check_added_monitors!(nodes[0], 1);
57865786
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
57875787
assert_eq!(events.len(), 1);

lightning/src/ln/functional_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use chain::transaction::OutPoint;
1919
use chain::keysinterface::BaseSign;
2020
use ln::{PaymentPreimage, PaymentSecret, PaymentHash};
2121
use ln::channel::{COMMITMENT_TX_BASE_WEIGHT, COMMITMENT_TX_WEIGHT_PER_HTLC};
22-
use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, MppId, RAACommitmentOrder, PaymentSendFailure, BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA};
22+
use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, PaymentId, RAACommitmentOrder, PaymentSendFailure, BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA};
2323
use ln::channel::{Channel, ChannelError};
2424
use ln::{chan_utils, onion_utils};
2525
use ln::chan_utils::HTLC_SUCCESS_TX_WEIGHT;
@@ -3957,8 +3957,8 @@ fn do_test_htlc_timeout(send_partial_mpp: bool) {
39573957
// Use the utility function send_payment_along_path to send the payment with MPP data which
39583958
// indicates there are more HTLCs coming.
39593959
let cur_height = CHAN_CONFIRM_DEPTH + 1; // route_payment calls send_payment, which adds 1 to the current height. So we do the same here to match.
3960-
let mpp_id = MppId([42; 32]);
3961-
nodes[0].node.send_payment_along_path(&route.paths[0], &our_payment_hash, &Some(payment_secret), 200000, cur_height, mpp_id, &None).unwrap();
3960+
let payment_id = PaymentId([42; 32]);
3961+
nodes[0].node.send_payment_along_path(&route.paths[0], &our_payment_hash, &Some(payment_secret), 200000, cur_height, payment_id, &None).unwrap();
39623962
check_added_monitors!(nodes[0], 1);
39633963
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
39643964
assert_eq!(events.len(), 1);

0 commit comments

Comments
 (0)