Skip to content

Commit 312b7cb

Browse files
pass through prev_htlc_amount
1 parent 2557243 commit 312b7cb

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

lightning/src/ln/channel.rs

Lines changed: 8 additions & 7 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)>,
416+
pub accepted_htlcs: Vec<(PendingHTLCInfo, u64, Option<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)>,
428+
pub accepted_htlcs: Vec<(PendingHTLCInfo, u64, Option<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)>,
561+
monitor_pending_forwards: Vec<(PendingHTLCInfo, u64, Option<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));
3329+
to_forward_infos.push((forward_info, htlc.htlc_id, Some(htlc.amount_msat)));
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)>,
3602+
resend_channel_ready: bool, mut pending_forwards: Vec<(PendingHTLCInfo, u64, Option<u64>)>,
36033603
mut pending_fails: Vec<(HTLCSource, PaymentHash, HTLCFailReason)>,
36043604
mut pending_finalized_claimed_htlcs: Vec<HTLCSource>
36053605
) {
@@ -6007,9 +6007,10 @@ 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) in self.monitor_pending_forwards.iter() {
6010+
for &(ref pending_forward, ref htlc_id, ref htlc_amount) in self.monitor_pending_forwards.iter() {
60116011
pending_forward.write(writer)?;
60126012
htlc_id.write(writer)?;
6013+
htlc_amount.write(writer)?;
60136014
}
60146015

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

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

lightning/src/ln/channelmanager.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ pub(super) enum HTLCForwardInfo {
144144
prev_short_channel_id: u64,
145145
prev_htlc_id: u64,
146146
prev_funding_outpoint: OutPoint,
147+
prev_htlc_amount: Option<u64>
147148
},
148149
FailHTLC {
149150
htlc_id: u64,
@@ -1365,7 +1366,7 @@ macro_rules! handle_monitor_err {
13651366
} else if $resend_commitment { "commitment" }
13661367
else if $resend_raa { "RAA" }
13671368
else { "nothing" },
1368-
(&$failed_forwards as &Vec<(PendingHTLCInfo, u64)>).len(),
1369+
(&$failed_forwards as &Vec<(PendingHTLCInfo, u64, Option<u64>)>).len(),
13691370
(&$failed_fails as &Vec<(HTLCSource, PaymentHash, HTLCFailReason)>).len(),
13701371
(&$failed_finalized_fulfills as &Vec<HTLCSource>).len());
13711372
if !$resend_commitment {
@@ -1454,7 +1455,7 @@ macro_rules! handle_chan_restoration_locked {
14541455
let chanmon_update_is_none = chanmon_update.is_none();
14551456
let counterparty_node_id = $channel_entry.get().get_counterparty_node_id();
14561457
let res = loop {
1457-
let forwards: Vec<(PendingHTLCInfo, u64)> = $pending_forwards; // Force type-checking to resolve
1458+
let forwards: Vec<(PendingHTLCInfo, u64, Option<u64>)> = $pending_forwards; // Force type-checking to resolve
14581459
if !forwards.is_empty() {
14591460
htlc_forwards = Some(($channel_entry.get().get_short_channel_id().unwrap_or($channel_entry.get().outbound_scid_alias()),
14601461
$channel_entry.get().get_funding_txo().unwrap(), forwards));
@@ -3108,7 +3109,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
31083109
None => Err(APIError::APIMisuseError { err: "Payment with that InterceptId not found".to_string() }),
31093110
Some(payment) => {
31103111
match payment {
3111-
HTLCForwardInfo::AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info, prev_funding_outpoint } => {
3112+
HTLCForwardInfo::AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info, prev_funding_outpoint, prev_htlc_amount } => {
31123113

31133114
let routing = match forward_info.routing {
31143115
PendingHTLCRouting::Forward { onion_packet, .. } => {
@@ -3123,7 +3124,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
31233124
..forward_info
31243125
};
31253126

3126-
let mut per_source_pending_forward = vec![(prev_short_channel_id, prev_funding_outpoint, vec![(pending_htlc_info, prev_htlc_id)])];
3127+
let mut per_source_pending_forward = vec![(prev_short_channel_id, prev_funding_outpoint, vec![(pending_htlc_info, prev_htlc_id, prev_htlc_amount)])];
31273128

31283129
self.forward_htlcs(&mut per_source_pending_forward);
31293130

@@ -3144,7 +3145,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
31443145

31453146
let mut new_events = Vec::new();
31463147
let mut failed_forwards = Vec::new();
3147-
let mut phantom_receives: Vec<(u64, OutPoint, Vec<(PendingHTLCInfo, u64)>)> = Vec::new();
3148+
let mut phantom_receives: Vec<(u64, OutPoint, Vec<(PendingHTLCInfo, u64, Option<u64>)>)> = Vec::new();
31483149
let mut handle_errors = Vec::new();
31493150
{
31503151
let mut channel_state_lock = self.channel_state.lock().unwrap();
@@ -3159,7 +3160,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
31593160
match forward_info {
31603161
HTLCForwardInfo::AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info: PendingHTLCInfo {
31613162
ref routing, incoming_shared_secret, payment_hash, amt_to_forward, outgoing_cltv_value },
3162-
prev_funding_outpoint } => {
3163+
prev_funding_outpoint, prev_htlc_amount } => {
31633164
macro_rules! fail_forward {
31643165
($msg: expr, $err_code: expr, $err_data: expr, $phantom_ss: expr) => {
31653166
{
@@ -3199,13 +3200,13 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
31993200
match next_hop {
32003201
onion_utils::Hop::Receive(hop_data) => {
32013202
match self.construct_recv_pending_htlc_info(hop_data, incoming_shared_secret, payment_hash, amt_to_forward, outgoing_cltv_value, Some(phantom_shared_secret)) {
3202-
Ok(info) => phantom_receives.push((prev_short_channel_id, prev_funding_outpoint, vec![(info, prev_htlc_id)])),
3203+
Ok(info) => phantom_receives.push((prev_short_channel_id, prev_funding_outpoint, vec![(info, prev_htlc_id, prev_htlc_amount)])),
32033204
Err(ReceiveError { err_code, err_data, msg }) => fail_forward!(msg, err_code, err_data, Some(phantom_shared_secret))
32043205
}
32053206
},
32063207
_ => panic!(),
32073208
}
3208-
} else if fake_scid::is_valid_intercept(&self.fake_scid_rand_bytes, short_chan_id) {
3209+
} else if prev_htlc_amount.is_some() && fake_scid::is_valid_intercept(&self.fake_scid_rand_bytes, short_chan_id) {
32093210
let intercept_id = InterceptId(Sha256::hash(&incoming_shared_secret).into_inner());
32103211
let mut pending_intercepts = self.pending_intercepted_payments.lock().unwrap();
32113212
match pending_intercepts.entry(intercept_id) {
@@ -3214,7 +3215,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
32143215
new_events.push(events::Event::PaymentIntercepted {
32153216
short_channel_id: short_chan_id,
32163217
payment_hash,
3217-
inbound_amount_msats: 0,
3218+
inbound_amount_msats: prev_htlc_amount.unwrap(),
32183219
expected_outbound_amount_msats: amt_to_forward,
32193220
intercept_id
32203221
});
@@ -3250,7 +3251,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
32503251
routing: PendingHTLCRouting::Forward {
32513252
onion_packet, ..
32523253
}, incoming_shared_secret, payment_hash, amt_to_forward, outgoing_cltv_value },
3253-
prev_funding_outpoint } => {
3254+
prev_funding_outpoint, .. } => {
32543255
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);
32553256
let htlc_source = HTLCSource::PreviousHopData(HTLCPreviousHopData {
32563257
short_channel_id: prev_short_channel_id,
@@ -3370,7 +3371,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
33703371
match forward_info {
33713372
HTLCForwardInfo::AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info: PendingHTLCInfo {
33723373
routing, incoming_shared_secret, payment_hash, amt_to_forward, .. },
3373-
prev_funding_outpoint } => {
3374+
prev_funding_outpoint, .. } => {
33743375
let (cltv_expiry, onion_payload, payment_data, phantom_shared_secret) = match routing {
33753376
PendingHTLCRouting::Receive { payment_data, incoming_cltv_expiry, phantom_shared_secret } => {
33763377
let _legacy_hop_data = Some(payment_data.clone());
@@ -5002,27 +5003,27 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
50025003
}
50035004

50045005
#[inline]
5005-
fn forward_htlcs(&self, per_source_pending_forwards: &mut [(u64, OutPoint, Vec<(PendingHTLCInfo, u64)>)]) {
5006+
fn forward_htlcs(&self, per_source_pending_forwards: &mut [(u64, OutPoint, Vec<(PendingHTLCInfo, u64, Option<u64>)>)]) {
50065007
for &mut (prev_short_channel_id, prev_funding_outpoint, ref mut pending_forwards) in per_source_pending_forwards {
50075008
let mut forward_event = None;
50085009
if !pending_forwards.is_empty() {
50095010
let mut channel_state = self.channel_state.lock().unwrap();
50105011
if channel_state.forward_htlcs.is_empty() {
50115012
forward_event = Some(Duration::from_millis(MIN_HTLC_RELAY_HOLDING_CELL_MILLIS))
50125013
}
5013-
for (forward_info, prev_htlc_id) in pending_forwards.drain(..) {
5014+
for (forward_info, prev_htlc_id, prev_htlc_amount) in pending_forwards.drain(..) {
50145015
match channel_state.forward_htlcs.entry(match forward_info.routing {
50155016
PendingHTLCRouting::Forward { short_channel_id, .. } => short_channel_id,
50165017
PendingHTLCRouting::Receive { .. } => 0,
50175018
PendingHTLCRouting::ReceiveKeysend { .. } => 0,
50185019
}) {
50195020
hash_map::Entry::Occupied(mut entry) => {
50205021
entry.get_mut().push(HTLCForwardInfo::AddHTLC { prev_short_channel_id, prev_funding_outpoint,
5021-
prev_htlc_id, forward_info });
5022+
prev_htlc_id, prev_htlc_amount, forward_info });
50225023
},
50235024
hash_map::Entry::Vacant(entry) => {
50245025
entry.insert(vec!(HTLCForwardInfo::AddHTLC { prev_short_channel_id, prev_funding_outpoint,
5025-
prev_htlc_id, forward_info }));
5026+
prev_htlc_id, prev_htlc_amount, forward_info }));
50265027
}
50275028
}
50285029
}
@@ -6640,6 +6641,7 @@ impl_writeable_tlv_based_enum!(HTLCForwardInfo,
66406641
(2, prev_short_channel_id, required),
66416642
(4, prev_htlc_id, required),
66426643
(6, prev_funding_outpoint, required),
6644+
(8, prev_htlc_amount, option)
66436645
},
66446646
(1, FailHTLC) => {
66456647
(0, htlc_id, required),

0 commit comments

Comments
 (0)