@@ -140,7 +140,7 @@ enum FeeUpdateState {
140140enum InboundHTLCRemovalReason {
141141 FailRelay(msgs::OnionErrorPacket),
142142 FailMalformed(([u8; 32], u16)),
143- Fulfill(PaymentPreimage),
143+ Fulfill(PaymentPreimage, Option<AttributionData> ),
144144}
145145
146146/// Represents the resolution status of an inbound HTLC.
@@ -236,7 +236,7 @@ impl From<&InboundHTLCState> for Option<InboundHTLCStateDetails> {
236236 Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFail),
237237 InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailMalformed(_)) =>
238238 Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFail),
239- InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_)) =>
239+ InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_, _ )) =>
240240 Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFulfill),
241241 }
242242 }
@@ -268,7 +268,7 @@ impl InboundHTLCState {
268268
269269 fn preimage(&self) -> Option<PaymentPreimage> {
270270 match self {
271- InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(preimage)) => {
271+ InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(preimage, _ )) => {
272272 Some(*preimage)
273273 },
274274 _ => None,
@@ -6208,7 +6208,7 @@ where
62086208 match htlc.state {
62096209 InboundHTLCState::Committed => {},
62106210 InboundHTLCState::LocalRemoved(ref reason) => {
6211- if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
6211+ if let &InboundHTLCRemovalReason::Fulfill(_, _ ) = reason {
62126212 } else {
62136213 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());
62146214 debug_assert!(
@@ -6319,6 +6319,7 @@ where
63196319 );
63206320 htlc.state = InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(
63216321 payment_preimage_arg.clone(),
6322+ None,
63226323 ));
63236324 }
63246325
@@ -7477,7 +7478,7 @@ where
74777478 pending_inbound_htlcs.retain(|htlc| {
74787479 if let &InboundHTLCState::LocalRemoved(ref reason) = &htlc.state {
74797480 log_trace!(logger, " ...removing inbound LocalRemoved {}", &htlc.payment_hash);
7480- if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
7481+ if let &InboundHTLCRemovalReason::Fulfill(_, _ ) = reason {
74817482 value_to_self_msat_diff += htlc.amount_msat as i64;
74827483 }
74837484 *expecting_peer_commitment_signed = true;
@@ -8341,12 +8342,15 @@ where
83418342 failure_code: failure_code.clone(),
83428343 });
83438344 },
8344- &InboundHTLCRemovalReason::Fulfill(ref payment_preimage) => {
8345+ &InboundHTLCRemovalReason::Fulfill(
8346+ ref payment_preimage,
8347+ ref attribution_data,
8348+ ) => {
83458349 update_fulfill_htlcs.push(msgs::UpdateFulfillHTLC {
83468350 channel_id: self.context.channel_id(),
83478351 htlc_id: htlc.htlc_id,
83488352 payment_preimage: payment_preimage.clone(),
8349- attribution_data: None ,
8353+ attribution_data: attribution_data.clone() ,
83508354 });
83518355 },
83528356 }
@@ -12439,7 +12443,7 @@ where
1243912443 dropped_inbound_htlcs += 1;
1244012444 }
1244112445 }
12442- let mut removed_htlc_failure_attribution_data : Vec<&Option<AttributionData>> = Vec::new();
12446+ let mut removed_htlc_attribution_data : Vec<&Option<AttributionData>> = Vec::new();
1244312447 (self.context.pending_inbound_htlcs.len() as u64 - dropped_inbound_htlcs).write(writer)?;
1244412448 for htlc in self.context.pending_inbound_htlcs.iter() {
1244512449 if let &InboundHTLCState::RemoteAnnounced(_) = &htlc.state {
@@ -12471,15 +12475,16 @@ where
1247112475 }) => {
1247212476 0u8.write(writer)?;
1247312477 data.write(writer)?;
12474- removed_htlc_failure_attribution_data .push(&attribution_data);
12478+ removed_htlc_attribution_data .push(&attribution_data);
1247512479 },
1247612480 InboundHTLCRemovalReason::FailMalformed((hash, code)) => {
1247712481 1u8.write(writer)?;
1247812482 (hash, code).write(writer)?;
1247912483 },
12480- InboundHTLCRemovalReason::Fulfill(preimage) => {
12484+ InboundHTLCRemovalReason::Fulfill(preimage, attribution_data ) => {
1248112485 2u8.write(writer)?;
1248212486 preimage.write(writer)?;
12487+ removed_htlc_attribution_data.push(&attribution_data);
1248312488 },
1248412489 }
1248512490 },
@@ -12796,7 +12801,7 @@ where
1279612801 (51, is_manual_broadcast, option), // Added in 0.0.124
1279712802 (53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
1279812803 (54, self.pending_funding, optional_vec), // Added in 0.2
12799- (55, removed_htlc_failure_attribution_data , optional_vec), // Added in 0.2
12804+ (55, removed_htlc_attribution_data , optional_vec), // Added in 0.2
1280012805 (57, holding_cell_failure_attribution_data, optional_vec), // Added in 0.2
1280112806 (58, self.interactive_tx_signing_session, option), // Added in 0.2
1280212807 (59, self.funding.minimum_depth_override, option), // Added in 0.2
@@ -12892,7 +12897,7 @@ where
1289212897 attribution_data: None,
1289312898 }),
1289412899 1 => InboundHTLCRemovalReason::FailMalformed(Readable::read(reader)?),
12895- 2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?),
12900+ 2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?, None ),
1289612901 _ => return Err(DecodeError::InvalidValue),
1289712902 };
1289812903 InboundHTLCState::LocalRemoved(reason)
@@ -13142,7 +13147,7 @@ where
1314213147 let mut pending_outbound_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
1314313148 let mut holding_cell_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
1314413149
13145- let mut removed_htlc_failure_attribution_data : Option<Vec<Option<AttributionData>>> = None;
13150+ let mut removed_htlc_attribution_data : Option<Vec<Option<AttributionData>>> = None;
1314613151 let mut holding_cell_failure_attribution_data: Option<Vec<Option<AttributionData>>> = None;
1314713152
1314813153 let mut malformed_htlcs: Option<Vec<(u64, u16, [u8; 32])>> = None;
@@ -13195,7 +13200,7 @@ where
1319513200 (51, is_manual_broadcast, option),
1319613201 (53, funding_tx_broadcast_safe_event_emitted, option),
1319713202 (54, pending_funding, optional_vec), // Added in 0.2
13198- (55, removed_htlc_failure_attribution_data , optional_vec),
13203+ (55, removed_htlc_attribution_data , optional_vec),
1319913204 (57, holding_cell_failure_attribution_data, optional_vec),
1320013205 (58, interactive_tx_signing_session, option), // Added in 0.2
1320113206 (59, minimum_depth_override, option), // Added in 0.2
@@ -13299,24 +13304,27 @@ where
1329913304 }
1330013305 }
1330113306
13302- if let Some(attribution_data_list) = removed_htlc_failure_attribution_data {
13303- let mut removed_htlc_relay_failures =
13304- pending_inbound_htlcs.iter_mut().filter_map(|status| {
13305- if let InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailRelay(
13306- ref mut packet,
13307- )) = &mut status.state
13308- {
13309- Some(&mut packet.attribution_data)
13310- } else {
13311- None
13307+ if let Some(attribution_data_list) = removed_htlc_attribution_data {
13308+ let mut removed_htlcs = pending_inbound_htlcs.iter_mut().filter_map(|status| {
13309+ if let InboundHTLCState::LocalRemoved(reason) = &mut status.state {
13310+ match reason {
13311+ InboundHTLCRemovalReason::FailRelay(ref mut packet) => {
13312+ Some(&mut packet.attribution_data)
13313+ },
13314+ InboundHTLCRemovalReason::Fulfill(_, ref mut attribution_data) => {
13315+ Some(attribution_data)
13316+ },
13317+ _ => None,
1331213318 }
13313- });
13319+ } else {
13320+ None
13321+ }
13322+ });
1331413323
1331513324 for attribution_data in attribution_data_list {
13316- *removed_htlc_relay_failures.next().ok_or(DecodeError::InvalidValue)? =
13317- attribution_data;
13325+ *removed_htlcs.next().ok_or(DecodeError::InvalidValue)? = attribution_data;
1331813326 }
13319- if removed_htlc_relay_failures .next().is_some() {
13327+ if removed_htlcs .next().is_some() {
1332013328 return Err(DecodeError::InvalidValue);
1332113329 }
1332213330 }
0 commit comments