Skip to content

Commit 15b79f8

Browse files
Merge pull request #1844 from valentinewallace/2022-11-htlc-interception-refactor-followup
Rename `PendingHTLCInfo` fields to include msat suffix
2 parents 384c4dc + 246d33d commit 15b79f8

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

lightning/src/ln/channelmanager.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ pub(super) struct PendingHTLCInfo {
112112
pub(super) routing: PendingHTLCRouting,
113113
pub(super) incoming_shared_secret: [u8; 32],
114114
payment_hash: PaymentHash,
115-
pub(super) amt_to_forward: u64,
116-
pub(super) amt_incoming: Option<u64>, // Added in 0.0.113
115+
pub(super) incoming_amt_msat: Option<u64>, // Added in 0.0.113
116+
pub(super) outgoing_amt_msat: u64,
117117
pub(super) outgoing_cltv_value: u32,
118118
}
119119

@@ -2197,8 +2197,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
21972197
routing,
21982198
payment_hash,
21992199
incoming_shared_secret: shared_secret,
2200-
amt_incoming: Some(amt_msat),
2201-
amt_to_forward: amt_msat,
2200+
incoming_amt_msat: Some(amt_msat),
2201+
outgoing_amt_msat: amt_msat,
22022202
outgoing_cltv_value: hop_data.outgoing_cltv_value,
22032203
})
22042204
}
@@ -2294,14 +2294,14 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
22942294
},
22952295
payment_hash: msg.payment_hash.clone(),
22962296
incoming_shared_secret: shared_secret,
2297-
amt_incoming: Some(msg.amount_msat),
2298-
amt_to_forward: next_hop_data.amt_to_forward,
2297+
incoming_amt_msat: Some(msg.amount_msat),
2298+
outgoing_amt_msat: next_hop_data.amt_to_forward,
22992299
outgoing_cltv_value: next_hop_data.outgoing_cltv_value,
23002300
})
23012301
}
23022302
};
23032303

2304-
if let &PendingHTLCStatus::Forward(PendingHTLCInfo { ref routing, ref amt_to_forward, ref outgoing_cltv_value, .. }) = &pending_forward_info {
2304+
if let &PendingHTLCStatus::Forward(PendingHTLCInfo { ref routing, ref outgoing_amt_msat, ref outgoing_cltv_value, .. }) = &pending_forward_info {
23052305
// If short_channel_id is 0 here, we'll reject the HTLC as there cannot be a channel
23062306
// with a short_channel_id of 0. This is important as various things later assume
23072307
// short_channel_id is non-0 in any ::Forward.
@@ -2352,10 +2352,10 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
23522352
if !chan.is_live() { // channel_disabled
23532353
break Some(("Forwarding channel is not in a ready state.", 0x1000 | 20, chan_update_opt));
23542354
}
2355-
if *amt_to_forward < chan.get_counterparty_htlc_minimum_msat() { // amount_below_minimum
2355+
if *outgoing_amt_msat < chan.get_counterparty_htlc_minimum_msat() { // amount_below_minimum
23562356
break Some(("HTLC amount was below the htlc_minimum_msat", 0x1000 | 11, chan_update_opt));
23572357
}
2358-
if let Err((err, code)) = chan.htlc_satisfies_config(&msg, *amt_to_forward, *outgoing_cltv_value) {
2358+
if let Err((err, code)) = chan.htlc_satisfies_config(&msg, *outgoing_amt_msat, *outgoing_cltv_value) {
23592359
break Some((err, code, chan_update_opt));
23602360
}
23612361
chan_update_opt
@@ -3157,8 +3157,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
31573157
HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
31583158
prev_short_channel_id, prev_htlc_id, prev_funding_outpoint,
31593159
forward_info: PendingHTLCInfo {
3160-
routing, incoming_shared_secret, payment_hash, amt_to_forward,
3161-
outgoing_cltv_value, amt_incoming: _
3160+
routing, incoming_shared_secret, payment_hash, outgoing_amt_msat,
3161+
outgoing_cltv_value, incoming_amt_msat: _
31623162
}
31633163
}) => {
31643164
macro_rules! failure_handler {
@@ -3220,7 +3220,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
32203220
};
32213221
match next_hop {
32223222
onion_utils::Hop::Receive(hop_data) => {
3223-
match self.construct_recv_pending_htlc_info(hop_data, incoming_shared_secret, payment_hash, amt_to_forward, outgoing_cltv_value, Some(phantom_shared_secret)) {
3223+
match self.construct_recv_pending_htlc_info(hop_data, incoming_shared_secret, payment_hash, outgoing_amt_msat, outgoing_cltv_value, Some(phantom_shared_secret)) {
32243224
Ok(info) => phantom_receives.push((prev_short_channel_id, prev_funding_outpoint, vec![(info, prev_htlc_id)])),
32253225
Err(ReceiveError { err_code, err_data, msg }) => failed_payment!(msg, err_code, err_data, Some(phantom_shared_secret))
32263226
}
@@ -3264,8 +3264,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
32643264
HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
32653265
prev_short_channel_id, prev_htlc_id, prev_funding_outpoint ,
32663266
forward_info: PendingHTLCInfo {
3267-
incoming_shared_secret, payment_hash, amt_to_forward, outgoing_cltv_value,
3268-
routing: PendingHTLCRouting::Forward { onion_packet, .. }, amt_incoming: _,
3267+
incoming_shared_secret, payment_hash, outgoing_amt_msat, outgoing_cltv_value,
3268+
routing: PendingHTLCRouting::Forward { onion_packet, .. }, incoming_amt_msat: _,
32693269
},
32703270
}) => {
32713271
log_trace!(self.logger, "Adding HTLC from short id {} with payment_hash {} to channel with short id {} after delay", prev_short_channel_id, log_bytes!(payment_hash.0), short_chan_id);
@@ -3277,7 +3277,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
32773277
// Phantom payments are only PendingHTLCRouting::Receive.
32783278
phantom_shared_secret: None,
32793279
});
3280-
match chan.get_mut().send_htlc(amt_to_forward, payment_hash, outgoing_cltv_value, htlc_source.clone(), onion_packet, &self.logger) {
3280+
match chan.get_mut().send_htlc(outgoing_amt_msat, payment_hash, outgoing_cltv_value, htlc_source.clone(), onion_packet, &self.logger) {
32813281
Err(e) => {
32823282
if let ChannelError::Ignore(msg) = e {
32833283
log_trace!(self.logger, "Failed to forward HTLC with payment_hash {}: {}", log_bytes!(payment_hash.0), msg);
@@ -3391,7 +3391,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
33913391
HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
33923392
prev_short_channel_id, prev_htlc_id, prev_funding_outpoint,
33933393
forward_info: PendingHTLCInfo {
3394-
routing, incoming_shared_secret, payment_hash, amt_to_forward, ..
3394+
routing, incoming_shared_secret, payment_hash, outgoing_amt_msat, ..
33953395
}
33963396
}) => {
33973397
let (cltv_expiry, onion_payload, payment_data, phantom_shared_secret) = match routing {
@@ -3413,9 +3413,9 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
34133413
incoming_packet_shared_secret: incoming_shared_secret,
34143414
phantom_shared_secret,
34153415
},
3416-
value: amt_to_forward,
3416+
value: outgoing_amt_msat,
34173417
timer_ticks: 0,
3418-
total_msat: if let Some(data) = &payment_data { data.total_msat } else { amt_to_forward },
3418+
total_msat: if let Some(data) = &payment_data { data.total_msat } else { outgoing_amt_msat },
34193419
cltv_expiry,
34203420
onion_payload,
34213421
};
@@ -3522,7 +3522,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
35223522
e.insert((purpose.clone(), vec![claimable_htlc]));
35233523
new_events.push(events::Event::PaymentReceived {
35243524
payment_hash,
3525-
amount_msat: amt_to_forward,
3525+
amount_msat: outgoing_amt_msat,
35263526
purpose,
35273527
});
35283528
},
@@ -6472,9 +6472,9 @@ impl_writeable_tlv_based!(PendingHTLCInfo, {
64726472
(0, routing, required),
64736473
(2, incoming_shared_secret, required),
64746474
(4, payment_hash, required),
6475-
(6, amt_to_forward, required),
6475+
(6, outgoing_amt_msat, required),
64766476
(8, outgoing_cltv_value, required),
6477-
(9, amt_incoming, option),
6477+
(9, incoming_amt_msat, option),
64786478
});
64796479

64806480

lightning/src/ln/onion_route_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ fn test_onion_failure() {
568568
for f in pending_forwards.iter_mut() {
569569
match f {
570570
&mut HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo { ref mut forward_info, .. }) =>
571-
forward_info.amt_to_forward -= 1,
571+
forward_info.outgoing_amt_msat -= 1,
572572
_ => {},
573573
}
574574
}

0 commit comments

Comments
 (0)