@@ -139,7 +139,7 @@ enum FeeUpdateState {
139139enum InboundHTLCRemovalReason {
140140 FailRelay(msgs::OnionErrorPacket),
141141 FailMalformed(([u8; 32], u16)),
142- Fulfill(PaymentPreimage),
142+ Fulfill(PaymentPreimage, Option<AttributionData> ),
143143}
144144
145145/// Represents the resolution status of an inbound HTLC.
@@ -235,7 +235,7 @@ impl From<&InboundHTLCState> for Option<InboundHTLCStateDetails> {
235235 Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFail),
236236 InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailMalformed(_)) =>
237237 Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFail),
238- InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_)) =>
238+ InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_, _ )) =>
239239 Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFulfill),
240240 }
241241 }
@@ -267,7 +267,7 @@ impl InboundHTLCState {
267267
268268 fn preimage(&self) -> Option<PaymentPreimage> {
269269 match self {
270- InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(preimage)) => {
270+ InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(preimage, _ )) => {
271271 Some(*preimage)
272272 },
273273 _ => None,
@@ -6233,7 +6233,7 @@ where
62336233 match htlc.state {
62346234 InboundHTLCState::Committed => {},
62356235 InboundHTLCState::LocalRemoved(ref reason) => {
6236- if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
6236+ if let &InboundHTLCRemovalReason::Fulfill(_, _ ) = reason {
62376237 } else {
62386238 log_warn!(logger, "Have preimage and want to fulfill HTLC with payment hash {} we already failed against channel {}", &htlc.payment_hash, &self.context.channel_id());
62396239 debug_assert!(
@@ -6344,6 +6344,7 @@ where
63446344 );
63456345 htlc.state = InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(
63466346 payment_preimage_arg.clone(),
6347+ None,
63476348 ));
63486349 }
63496350
@@ -7504,7 +7505,7 @@ where
75047505 pending_inbound_htlcs.retain(|htlc| {
75057506 if let &InboundHTLCState::LocalRemoved(ref reason) = &htlc.state {
75067507 log_trace!(logger, " ...removing inbound LocalRemoved {}", &htlc.payment_hash);
7507- if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
7508+ if let &InboundHTLCRemovalReason::Fulfill(_, _ ) = reason {
75087509 value_to_self_msat_diff += htlc.amount_msat as i64;
75097510 }
75107511 *expecting_peer_commitment_signed = true;
@@ -8374,12 +8375,15 @@ where
83748375 failure_code: failure_code.clone(),
83758376 });
83768377 },
8377- &InboundHTLCRemovalReason::Fulfill(ref payment_preimage) => {
8378+ &InboundHTLCRemovalReason::Fulfill(
8379+ ref payment_preimage,
8380+ ref attribution_data,
8381+ ) => {
83788382 update_fulfill_htlcs.push(msgs::UpdateFulfillHTLC {
83798383 channel_id: self.context.channel_id(),
83808384 htlc_id: htlc.htlc_id,
83818385 payment_preimage: payment_preimage.clone(),
8382- attribution_data: None ,
8386+ attribution_data: attribution_data.clone() ,
83838387 });
83848388 },
83858389 }
@@ -12475,7 +12479,7 @@ where
1247512479 dropped_inbound_htlcs += 1;
1247612480 }
1247712481 }
12478- let mut removed_htlc_failure_attribution_data : Vec<&Option<AttributionData>> = Vec::new();
12482+ let mut removed_htlc_attribution_data : Vec<&Option<AttributionData>> = Vec::new();
1247912483 (self.context.pending_inbound_htlcs.len() as u64 - dropped_inbound_htlcs).write(writer)?;
1248012484 for htlc in self.context.pending_inbound_htlcs.iter() {
1248112485 if let &InboundHTLCState::RemoteAnnounced(_) = &htlc.state {
@@ -12507,15 +12511,16 @@ where
1250712511 }) => {
1250812512 0u8.write(writer)?;
1250912513 data.write(writer)?;
12510- removed_htlc_failure_attribution_data .push(&attribution_data);
12514+ removed_htlc_attribution_data .push(&attribution_data);
1251112515 },
1251212516 InboundHTLCRemovalReason::FailMalformed((hash, code)) => {
1251312517 1u8.write(writer)?;
1251412518 (hash, code).write(writer)?;
1251512519 },
12516- InboundHTLCRemovalReason::Fulfill(preimage) => {
12520+ InboundHTLCRemovalReason::Fulfill(preimage, attribution_data ) => {
1251712521 2u8.write(writer)?;
1251812522 preimage.write(writer)?;
12523+ removed_htlc_attribution_data.push(&attribution_data);
1251912524 },
1252012525 }
1252112526 },
@@ -12832,7 +12837,7 @@ where
1283212837 (51, is_manual_broadcast, option), // Added in 0.0.124
1283312838 (53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
1283412839 (54, self.pending_funding, optional_vec), // Added in 0.2
12835- (55, removed_htlc_failure_attribution_data , optional_vec), // Added in 0.2
12840+ (55, removed_htlc_attribution_data , optional_vec), // Added in 0.2
1283612841 (57, holding_cell_failure_attribution_data, optional_vec), // Added in 0.2
1283712842 (58, self.interactive_tx_signing_session, option), // Added in 0.2
1283812843 (59, self.funding.minimum_depth_override, option), // Added in 0.2
@@ -12928,7 +12933,7 @@ where
1292812933 attribution_data: None,
1292912934 }),
1293012935 1 => InboundHTLCRemovalReason::FailMalformed(Readable::read(reader)?),
12931- 2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?),
12936+ 2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?, None ),
1293212937 _ => return Err(DecodeError::InvalidValue),
1293312938 };
1293412939 InboundHTLCState::LocalRemoved(reason)
@@ -13178,7 +13183,7 @@ where
1317813183 let mut pending_outbound_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
1317913184 let mut holding_cell_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
1318013185
13181- let mut removed_htlc_failure_attribution_data : Option<Vec<Option<AttributionData>>> = None;
13186+ let mut removed_htlc_attribution_data : Option<Vec<Option<AttributionData>>> = None;
1318213187 let mut holding_cell_failure_attribution_data: Option<Vec<Option<AttributionData>>> = None;
1318313188
1318413189 let mut malformed_htlcs: Option<Vec<(u64, u16, [u8; 32])>> = None;
@@ -13231,7 +13236,7 @@ where
1323113236 (51, is_manual_broadcast, option),
1323213237 (53, funding_tx_broadcast_safe_event_emitted, option),
1323313238 (54, pending_funding, optional_vec), // Added in 0.2
13234- (55, removed_htlc_failure_attribution_data , optional_vec),
13239+ (55, removed_htlc_attribution_data , optional_vec),
1323513240 (57, holding_cell_failure_attribution_data, optional_vec),
1323613241 (58, interactive_tx_signing_session, option), // Added in 0.2
1323713242 (59, minimum_depth_override, option), // Added in 0.2
@@ -13335,24 +13340,27 @@ where
1333513340 }
1333613341 }
1333713342
13338- if let Some(attribution_data_list) = removed_htlc_failure_attribution_data {
13339- let mut removed_htlc_relay_failures =
13340- pending_inbound_htlcs.iter_mut().filter_map(|status| {
13341- if let InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailRelay(
13342- ref mut packet,
13343- )) = &mut status.state
13344- {
13345- Some(&mut packet.attribution_data)
13346- } else {
13347- None
13343+ if let Some(attribution_data_list) = removed_htlc_attribution_data {
13344+ let mut removed_htlcs = pending_inbound_htlcs.iter_mut().filter_map(|status| {
13345+ if let InboundHTLCState::LocalRemoved(reason) = &mut status.state {
13346+ match reason {
13347+ InboundHTLCRemovalReason::FailRelay(ref mut packet) => {
13348+ Some(&mut packet.attribution_data)
13349+ },
13350+ InboundHTLCRemovalReason::Fulfill(_, ref mut attribution_data) => {
13351+ Some(attribution_data)
13352+ },
13353+ _ => None,
1334813354 }
13349- });
13355+ } else {
13356+ None
13357+ }
13358+ });
1335013359
1335113360 for attribution_data in attribution_data_list {
13352- *removed_htlc_relay_failures.next().ok_or(DecodeError::InvalidValue)? =
13353- attribution_data;
13361+ *removed_htlcs.next().ok_or(DecodeError::InvalidValue)? = attribution_data;
1335413362 }
13355- if removed_htlc_relay_failures .next().is_some() {
13363+ if removed_htlcs .next().is_some() {
1335613364 return Err(DecodeError::InvalidValue);
1335713365 }
1335813366 }
0 commit comments