Skip to content

Commit c027a24

Browse files
move prev_htlc_amount into PendingHTLCInfo
1 parent ab59642 commit c027a24

File tree

2 files changed

+25
-26
lines changed

2 files changed

+25
-26
lines changed

lightning/src/ln/channel.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ pub enum UpdateFulfillCommitFetch {
413413
/// state.
414414
pub(super) struct RAAUpdates {
415415
pub commitment_update: Option<msgs::CommitmentUpdate>,
416-
pub accepted_htlcs: Vec<(PendingHTLCInfo, u64, Option<u64>)>,
416+
pub accepted_htlcs: Vec<(PendingHTLCInfo, u64)>,
417417
pub failed_htlcs: Vec<(HTLCSource, PaymentHash, HTLCFailReason)>,
418418
pub finalized_claimed_htlcs: Vec<HTLCSource>,
419419
pub monitor_update: ChannelMonitorUpdate,
@@ -425,7 +425,7 @@ pub(super) struct MonitorRestoreUpdates {
425425
pub raa: Option<msgs::RevokeAndACK>,
426426
pub commitment_update: Option<msgs::CommitmentUpdate>,
427427
pub order: RAACommitmentOrder,
428-
pub accepted_htlcs: Vec<(PendingHTLCInfo, u64, Option<u64>)>,
428+
pub accepted_htlcs: Vec<(PendingHTLCInfo, u64)>,
429429
pub failed_htlcs: Vec<(HTLCSource, PaymentHash, HTLCFailReason)>,
430430
pub finalized_claimed_htlcs: Vec<HTLCSource>,
431431
pub funding_broadcastable: Option<Transaction>,
@@ -558,7 +558,7 @@ pub(super) struct Channel<Signer: Sign> {
558558
monitor_pending_channel_ready: bool,
559559
monitor_pending_revoke_and_ack: bool,
560560
monitor_pending_commitment_signed: bool,
561-
monitor_pending_forwards: Vec<(PendingHTLCInfo, u64, Option<u64>)>,
561+
monitor_pending_forwards: Vec<(PendingHTLCInfo, u64)>,
562562
monitor_pending_failures: Vec<(HTLCSource, PaymentHash, HTLCFailReason)>,
563563
monitor_pending_finalized_fulfills: Vec<HTLCSource>,
564564

@@ -3326,7 +3326,7 @@ impl<Signer: Sign> Channel<Signer> {
33263326
},
33273327
PendingHTLCStatus::Forward(forward_info) => {
33283328
log_trace!(logger, " ...promoting inbound AwaitingAnnouncedRemoteRevoke {} to Committed", log_bytes!(htlc.payment_hash.0));
3329-
to_forward_infos.push((forward_info, htlc.htlc_id, Some(htlc.amount_msat)));
3329+
to_forward_infos.push((forward_info, htlc.htlc_id));
33303330
htlc.state = InboundHTLCState::Committed;
33313331
}
33323332
}
@@ -3599,7 +3599,7 @@ impl<Signer: Sign> Channel<Signer> {
35993599
/// monitor update failure must *not* have been sent to the remote end, and must instead
36003600
/// have been dropped. They will be regenerated when monitor_updating_restored is called.
36013601
pub fn monitor_update_failed(&mut self, resend_raa: bool, resend_commitment: bool,
3602-
resend_channel_ready: bool, mut pending_forwards: Vec<(PendingHTLCInfo, u64, Option<u64>)>,
3602+
resend_channel_ready: bool, mut pending_forwards: Vec<(PendingHTLCInfo, u64)>,
36033603
mut pending_fails: Vec<(HTLCSource, PaymentHash, HTLCFailReason)>,
36043604
mut pending_finalized_claimed_htlcs: Vec<HTLCSource>
36053605
) {
@@ -6007,10 +6007,9 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
60076007
self.monitor_pending_commitment_signed.write(writer)?;
60086008

60096009
(self.monitor_pending_forwards.len() as u64).write(writer)?;
6010-
for &(ref pending_forward, ref htlc_id, ref htlc_amount) in self.monitor_pending_forwards.iter() {
6010+
for &(ref pending_forward, ref htlc_id) in self.monitor_pending_forwards.iter() {
60116011
pending_forward.write(writer)?;
60126012
htlc_id.write(writer)?;
6013-
htlc_amount.write(writer)?;
60146013
}
60156014

60166015
(self.monitor_pending_failures.len() as u64).write(writer)?;
@@ -6271,7 +6270,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
62716270
let monitor_pending_forwards_count: u64 = Readable::read(reader)?;
62726271
let mut monitor_pending_forwards = Vec::with_capacity(cmp::min(monitor_pending_forwards_count as usize, OUR_MAX_HTLCS as usize));
62736272
for _ in 0..monitor_pending_forwards_count {
6274-
monitor_pending_forwards.push((Readable::read(reader)?, Readable::read(reader)?, Readable::read(reader)?));
6273+
monitor_pending_forwards.push((Readable::read(reader)?, Readable::read(reader)?));
62756274
}
62766275

62776276
let monitor_pending_failures_count: u64 = Readable::read(reader)?;

lightning/src/ln/channelmanager.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ pub(super) struct PendingHTLCInfo {
116116
payment_hash: PaymentHash,
117117
pub(super) amt_to_forward: u64,
118118
pub(super) outgoing_cltv_value: u32,
119+
pub(super) amt_incoming: Option<u64>
119120
}
120121

121122
#[derive(Clone)] // See Channel::revoke_and_ack for why, tl;dr: Rust bug
@@ -136,7 +137,6 @@ pub(super) struct PendingInterceptedHTLC {
136137
prev_short_channel_id: u64,
137138
prev_htlc_id: u64,
138139
prev_funding_outpoint: OutPoint,
139-
prev_htlc_amount: u64
140140
}
141141

142142
pub(super) enum HTLCForwardInfo {
@@ -152,7 +152,6 @@ pub(super) enum HTLCForwardInfo {
152152
prev_short_channel_id: u64,
153153
prev_htlc_id: u64,
154154
prev_funding_outpoint: OutPoint,
155-
prev_htlc_amount: Option<u64>
156155
},
157156
FailHTLC {
158157
htlc_id: u64,
@@ -1374,7 +1373,7 @@ macro_rules! handle_monitor_err {
13741373
} else if $resend_commitment { "commitment" }
13751374
else if $resend_raa { "RAA" }
13761375
else { "nothing" },
1377-
(&$failed_forwards as &Vec<(PendingHTLCInfo, u64, Option<u64>)>).len(),
1376+
(&$failed_forwards as &Vec<(PendingHTLCInfo, u64)>).len(),
13781377
(&$failed_fails as &Vec<(HTLCSource, PaymentHash, HTLCFailReason)>).len(),
13791378
(&$failed_finalized_fulfills as &Vec<HTLCSource>).len());
13801379
if !$resend_commitment {
@@ -1463,7 +1462,7 @@ macro_rules! handle_chan_restoration_locked {
14631462
let chanmon_update_is_none = chanmon_update.is_none();
14641463
let counterparty_node_id = $channel_entry.get().get_counterparty_node_id();
14651464
let res = loop {
1466-
let forwards: Vec<(PendingHTLCInfo, u64, Option<u64>)> = $pending_forwards; // Force type-checking to resolve
1465+
let forwards: Vec<(PendingHTLCInfo, u64)> = $pending_forwards; // Force type-checking to resolve
14671466
if !forwards.is_empty() {
14681467
htlc_forwards = Some(($channel_entry.get().get_short_channel_id().unwrap_or($channel_entry.get().outbound_scid_alias()),
14691468
$channel_entry.get().get_funding_txo().unwrap(), forwards));
@@ -2146,6 +2145,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
21462145
payment_hash,
21472146
incoming_shared_secret: shared_secret,
21482147
amt_to_forward: amt_msat,
2148+
amt_incoming: Some(amt_msat),
21492149
outgoing_cltv_value: hop_data.outgoing_cltv_value,
21502150
})
21512151
}
@@ -2248,6 +2248,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
22482248
incoming_shared_secret: shared_secret,
22492249
amt_to_forward: next_hop_data.amt_to_forward,
22502250
outgoing_cltv_value: next_hop_data.outgoing_cltv_value,
2251+
amt_incoming: Some(msg.amount_msat)
22512252
})
22522253
}
22532254
};
@@ -3137,7 +3138,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
31373138
..payment.forward_info
31383139
};
31393140

3140-
let mut per_source_pending_forward = vec![(payment.prev_short_channel_id, payment.prev_funding_outpoint, vec![(pending_htlc_info, payment.prev_htlc_id, Some(payment.prev_htlc_amount))])];
3141+
let mut per_source_pending_forward = vec![(payment.prev_short_channel_id, payment.prev_funding_outpoint, vec![(pending_htlc_info, payment.prev_htlc_id)])];
31413142
self.forward_htlcs(&mut per_source_pending_forward);
31423143
Ok(())
31433144
}
@@ -3153,7 +3154,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
31533154

31543155
let mut new_events = Vec::new();
31553156
let mut failed_forwards = Vec::new();
3156-
let mut phantom_receives: Vec<(u64, OutPoint, Vec<(PendingHTLCInfo, u64, Option<u64>)>)> = Vec::new();
3157+
let mut phantom_receives: Vec<(u64, OutPoint, Vec<(PendingHTLCInfo, u64)>)> = Vec::new();
31573158
let mut handle_errors = Vec::new();
31583159
{
31593160
let mut channel_state_lock = self.channel_state.lock().unwrap();
@@ -3166,7 +3167,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
31663167
None => {
31673168
for forward_info in pending_forwards.drain(..) {
31683169
match forward_info {
3169-
HTLCForwardInfo::AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info, prev_funding_outpoint, prev_htlc_amount } => {
3170+
HTLCForwardInfo::AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info, prev_funding_outpoint } => {
31703171
macro_rules! fail_forward {
31713172
($msg: expr, $err_code: expr, $err_data: expr, $phantom_ss: expr) => {
31723173
{
@@ -3206,13 +3207,13 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
32063207
match next_hop {
32073208
onion_utils::Hop::Receive(hop_data) => {
32083209
match self.construct_recv_pending_htlc_info(hop_data, forward_info.incoming_shared_secret, forward_info.payment_hash, forward_info.amt_to_forward, forward_info.outgoing_cltv_value, Some(phantom_shared_secret)) {
3209-
Ok(info) => phantom_receives.push((prev_short_channel_id, prev_funding_outpoint, vec![(info, prev_htlc_id, prev_htlc_amount)])),
3210+
Ok(info) => phantom_receives.push((prev_short_channel_id, prev_funding_outpoint, vec![(info, prev_htlc_id)])),
32103211
Err(ReceiveError { err_code, err_data, msg }) => fail_forward!(msg, err_code, err_data, Some(phantom_shared_secret))
32113212
}
32123213
},
32133214
_ => panic!(),
32143215
}
3215-
} else if prev_htlc_amount.is_some() && fake_scid::is_valid_intercept(&self.fake_scid_rand_bytes, short_chan_id) {
3216+
} else if forward_info.amt_incoming.is_some() && fake_scid::is_valid_intercept(&self.fake_scid_rand_bytes, short_chan_id) {
32163217
let intercept_id = InterceptId(Sha256::hash(&forward_info.incoming_shared_secret).into_inner());
32173218
let mut pending_intercepts = self.pending_intercepted_payments.lock().unwrap();
32183219
match pending_intercepts.entry(intercept_id) {
@@ -3222,13 +3223,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
32223223
prev_short_channel_id,
32233224
prev_htlc_id,
32243225
prev_funding_outpoint,
3225-
prev_htlc_amount: prev_htlc_amount.unwrap()
32263226
};
32273227
entry.insert(pending_intercepted_payment);
32283228
new_events.push(events::Event::PaymentIntercepted {
32293229
short_channel_id: short_chan_id,
32303230
payment_hash: forward_info.payment_hash,
3231-
inbound_amount_msats: prev_htlc_amount.unwrap(),
3231+
inbound_amount_msats: forward_info.amt_incoming.unwrap(),
32323232
expected_outbound_amount_msats: forward_info.amt_to_forward,
32333233
intercept_id
32343234
});
@@ -3263,7 +3263,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
32633263
HTLCForwardInfo::AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info: PendingHTLCInfo {
32643264
routing: PendingHTLCRouting::Forward {
32653265
onion_packet, ..
3266-
}, incoming_shared_secret, payment_hash, amt_to_forward, outgoing_cltv_value },
3266+
}, incoming_shared_secret, payment_hash, amt_to_forward, outgoing_cltv_value, .. },
32673267
prev_funding_outpoint, .. } => {
32683268
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);
32693269
let htlc_source = HTLCSource::PreviousHopData(HTLCPreviousHopData {
@@ -5016,27 +5016,27 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
50165016
}
50175017

50185018
#[inline]
5019-
fn forward_htlcs(&self, per_source_pending_forwards: &mut [(u64, OutPoint, Vec<(PendingHTLCInfo, u64, Option<u64>)>)]) {
5019+
fn forward_htlcs(&self, per_source_pending_forwards: &mut [(u64, OutPoint, Vec<(PendingHTLCInfo, u64)>)]) {
50205020
for &mut (prev_short_channel_id, prev_funding_outpoint, ref mut pending_forwards) in per_source_pending_forwards {
50215021
let mut forward_event = None;
50225022
if !pending_forwards.is_empty() {
50235023
let mut channel_state = self.channel_state.lock().unwrap();
50245024
if channel_state.forward_htlcs.is_empty() {
50255025
forward_event = Some(Duration::from_millis(MIN_HTLC_RELAY_HOLDING_CELL_MILLIS))
50265026
}
5027-
for (forward_info, prev_htlc_id, prev_htlc_amount) in pending_forwards.drain(..) {
5027+
for (forward_info, prev_htlc_id) in pending_forwards.drain(..) {
50285028
match channel_state.forward_htlcs.entry(match forward_info.routing {
50295029
PendingHTLCRouting::Forward { short_channel_id, .. } => short_channel_id,
50305030
PendingHTLCRouting::Receive { .. } => 0,
50315031
PendingHTLCRouting::ReceiveKeysend { .. } => 0,
50325032
}) {
50335033
hash_map::Entry::Occupied(mut entry) => {
50345034
entry.get_mut().push(HTLCForwardInfo::AddHTLC { prev_short_channel_id, prev_funding_outpoint,
5035-
prev_htlc_id, prev_htlc_amount, forward_info });
5035+
prev_htlc_id, forward_info });
50365036
},
50375037
hash_map::Entry::Vacant(entry) => {
50385038
entry.insert(vec!(HTLCForwardInfo::AddHTLC { prev_short_channel_id, prev_funding_outpoint,
5039-
prev_htlc_id, prev_htlc_amount, forward_info }));
5039+
prev_htlc_id, forward_info }));
50405040
}
50415041
}
50425042
}
@@ -6426,7 +6426,8 @@ impl_writeable_tlv_based!(PendingHTLCInfo, {
64266426
(2, incoming_shared_secret, required),
64276427
(4, payment_hash, required),
64286428
(6, amt_to_forward, required),
6429-
(8, outgoing_cltv_value, required)
6429+
(8, outgoing_cltv_value, required),
6430+
(9, amt_incoming, option),
64306431
});
64316432

64326433

@@ -6654,7 +6655,6 @@ impl_writeable_tlv_based_enum!(HTLCForwardInfo,
66546655
(2, prev_short_channel_id, required),
66556656
(4, prev_htlc_id, required),
66566657
(6, prev_funding_outpoint, required),
6657-
(8, prev_htlc_amount, option)
66586658
},
66596659
(1, FailHTLC) => {
66606660
(0, htlc_id, required),

0 commit comments

Comments
 (0)