@@ -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,
@@ -6203,7 +6203,7 @@ where
62036203 match htlc.state {
62046204 InboundHTLCState::Committed => {},
62056205 InboundHTLCState::LocalRemoved(ref reason) => {
6206- if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
6206+ if let &InboundHTLCRemovalReason::Fulfill(_, _ ) = reason {
62076207 } else {
62086208 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());
62096209 debug_assert!(
@@ -6314,6 +6314,7 @@ where
63146314 );
63156315 htlc.state = InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(
63166316 payment_preimage_arg.clone(),
6317+ None,
63176318 ));
63186319 }
63196320
@@ -7474,7 +7475,7 @@ where
74747475 pending_inbound_htlcs.retain(|htlc| {
74757476 if let &InboundHTLCState::LocalRemoved(ref reason) = &htlc.state {
74767477 log_trace!(logger, " ...removing inbound LocalRemoved {}", &htlc.payment_hash);
7477- if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
7478+ if let &InboundHTLCRemovalReason::Fulfill(_, _ ) = reason {
74787479 value_to_self_msat_diff += htlc.amount_msat as i64;
74797480 }
74807481 *expecting_peer_commitment_signed = true;
@@ -8344,12 +8345,15 @@ where
83448345 failure_code: failure_code.clone(),
83458346 });
83468347 },
8347- &InboundHTLCRemovalReason::Fulfill(ref payment_preimage) => {
8348+ &InboundHTLCRemovalReason::Fulfill(
8349+ ref payment_preimage,
8350+ ref attribution_data,
8351+ ) => {
83488352 update_fulfill_htlcs.push(msgs::UpdateFulfillHTLC {
83498353 channel_id: self.context.channel_id(),
83508354 htlc_id: htlc.htlc_id,
83518355 payment_preimage: payment_preimage.clone(),
8352- attribution_data: None ,
8356+ attribution_data: attribution_data.clone() ,
83538357 });
83548358 },
83558359 }
@@ -12444,7 +12448,7 @@ where
1244412448 dropped_inbound_htlcs += 1;
1244512449 }
1244612450 }
12447- let mut removed_htlc_failure_attribution_data : Vec<&Option<AttributionData>> = Vec::new();
12451+ let mut removed_htlc_attribution_data : Vec<&Option<AttributionData>> = Vec::new();
1244812452 (self.context.pending_inbound_htlcs.len() as u64 - dropped_inbound_htlcs).write(writer)?;
1244912453 for htlc in self.context.pending_inbound_htlcs.iter() {
1245012454 if let &InboundHTLCState::RemoteAnnounced(_) = &htlc.state {
@@ -12476,15 +12480,16 @@ where
1247612480 }) => {
1247712481 0u8.write(writer)?;
1247812482 data.write(writer)?;
12479- removed_htlc_failure_attribution_data .push(&attribution_data);
12483+ removed_htlc_attribution_data .push(&attribution_data);
1248012484 },
1248112485 InboundHTLCRemovalReason::FailMalformed((hash, code)) => {
1248212486 1u8.write(writer)?;
1248312487 (hash, code).write(writer)?;
1248412488 },
12485- InboundHTLCRemovalReason::Fulfill(preimage) => {
12489+ InboundHTLCRemovalReason::Fulfill(preimage, attribution_data ) => {
1248612490 2u8.write(writer)?;
1248712491 preimage.write(writer)?;
12492+ removed_htlc_attribution_data.push(&attribution_data);
1248812493 },
1248912494 }
1249012495 },
@@ -12801,7 +12806,7 @@ where
1280112806 (51, is_manual_broadcast, option), // Added in 0.0.124
1280212807 (53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
1280312808 (54, self.pending_funding, optional_vec), // Added in 0.2
12804- (55, removed_htlc_failure_attribution_data , optional_vec), // Added in 0.2
12809+ (55, removed_htlc_attribution_data , optional_vec), // Added in 0.2
1280512810 (57, holding_cell_failure_attribution_data, optional_vec), // Added in 0.2
1280612811 (58, self.interactive_tx_signing_session, option), // Added in 0.2
1280712812 (59, self.funding.minimum_depth_override, option), // Added in 0.2
@@ -12897,7 +12902,7 @@ where
1289712902 attribution_data: None,
1289812903 }),
1289912904 1 => InboundHTLCRemovalReason::FailMalformed(Readable::read(reader)?),
12900- 2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?),
12905+ 2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?, None ),
1290112906 _ => return Err(DecodeError::InvalidValue),
1290212907 };
1290312908 InboundHTLCState::LocalRemoved(reason)
@@ -13147,7 +13152,7 @@ where
1314713152 let mut pending_outbound_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
1314813153 let mut holding_cell_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
1314913154
13150- let mut removed_htlc_failure_attribution_data : Option<Vec<Option<AttributionData>>> = None;
13155+ let mut removed_htlc_attribution_data : Option<Vec<Option<AttributionData>>> = None;
1315113156 let mut holding_cell_failure_attribution_data: Option<Vec<Option<AttributionData>>> = None;
1315213157
1315313158 let mut malformed_htlcs: Option<Vec<(u64, u16, [u8; 32])>> = None;
@@ -13200,7 +13205,7 @@ where
1320013205 (51, is_manual_broadcast, option),
1320113206 (53, funding_tx_broadcast_safe_event_emitted, option),
1320213207 (54, pending_funding, optional_vec), // Added in 0.2
13203- (55, removed_htlc_failure_attribution_data , optional_vec),
13208+ (55, removed_htlc_attribution_data , optional_vec),
1320413209 (57, holding_cell_failure_attribution_data, optional_vec),
1320513210 (58, interactive_tx_signing_session, option), // Added in 0.2
1320613211 (59, minimum_depth_override, option), // Added in 0.2
@@ -13304,24 +13309,27 @@ where
1330413309 }
1330513310 }
1330613311
13307- if let Some(attribution_data_list) = removed_htlc_failure_attribution_data {
13308- let mut removed_htlc_relay_failures =
13309- pending_inbound_htlcs.iter_mut().filter_map(|status| {
13310- if let InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailRelay(
13311- ref mut packet,
13312- )) = &mut status.state
13313- {
13314- Some(&mut packet.attribution_data)
13315- } else {
13316- None
13312+ if let Some(attribution_data_list) = removed_htlc_attribution_data {
13313+ let mut removed_htlcs = pending_inbound_htlcs.iter_mut().filter_map(|status| {
13314+ if let InboundHTLCState::LocalRemoved(reason) = &mut status.state {
13315+ match reason {
13316+ InboundHTLCRemovalReason::FailRelay(ref mut packet) => {
13317+ Some(&mut packet.attribution_data)
13318+ },
13319+ InboundHTLCRemovalReason::Fulfill(_, ref mut attribution_data) => {
13320+ Some(attribution_data)
13321+ },
13322+ _ => None,
1331713323 }
13318- });
13324+ } else {
13325+ None
13326+ }
13327+ });
1331913328
1332013329 for attribution_data in attribution_data_list {
13321- *removed_htlc_relay_failures.next().ok_or(DecodeError::InvalidValue)? =
13322- attribution_data;
13330+ *removed_htlcs.next().ok_or(DecodeError::InvalidValue)? = attribution_data;
1332313331 }
13324- if removed_htlc_relay_failures .next().is_some() {
13332+ if removed_htlcs .next().is_some() {
1332513333 return Err(DecodeError::InvalidValue);
1332613334 }
1332713335 }
0 commit comments