@@ -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,
@@ -6190,7 +6190,7 @@ where
61906190 match htlc.state {
61916191 InboundHTLCState::Committed => {},
61926192 InboundHTLCState::LocalRemoved(ref reason) => {
6193- if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
6193+ if let &InboundHTLCRemovalReason::Fulfill(_, _ ) = reason {
61946194 } else {
61956195 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());
61966196 debug_assert!(
@@ -6301,6 +6301,7 @@ where
63016301 );
63026302 htlc.state = InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(
63036303 payment_preimage_arg.clone(),
6304+ None,
63046305 ));
63056306 }
63066307
@@ -7459,7 +7460,7 @@ where
74597460 pending_inbound_htlcs.retain(|htlc| {
74607461 if let &InboundHTLCState::LocalRemoved(ref reason) = &htlc.state {
74617462 log_trace!(logger, " ...removing inbound LocalRemoved {}", &htlc.payment_hash);
7462- if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
7463+ if let &InboundHTLCRemovalReason::Fulfill(_, _ ) = reason {
74637464 value_to_self_msat_diff += htlc.amount_msat as i64;
74647465 }
74657466 *expecting_peer_commitment_signed = true;
@@ -8323,12 +8324,15 @@ where
83238324 failure_code: failure_code.clone(),
83248325 });
83258326 },
8326- &InboundHTLCRemovalReason::Fulfill(ref payment_preimage) => {
8327+ &InboundHTLCRemovalReason::Fulfill(
8328+ ref payment_preimage,
8329+ ref attribution_data,
8330+ ) => {
83278331 update_fulfill_htlcs.push(msgs::UpdateFulfillHTLC {
83288332 channel_id: self.context.channel_id(),
83298333 htlc_id: htlc.htlc_id,
83308334 payment_preimage: payment_preimage.clone(),
8331- attribution_data: None ,
8335+ attribution_data: attribution_data.clone() ,
83328336 });
83338337 },
83348338 }
@@ -12414,7 +12418,7 @@ where
1241412418 dropped_inbound_htlcs += 1;
1241512419 }
1241612420 }
12417- let mut removed_htlc_failure_attribution_data : Vec<&Option<AttributionData>> = Vec::new();
12421+ let mut removed_htlc_attribution_data : Vec<&Option<AttributionData>> = Vec::new();
1241812422 (self.context.pending_inbound_htlcs.len() as u64 - dropped_inbound_htlcs).write(writer)?;
1241912423 for htlc in self.context.pending_inbound_htlcs.iter() {
1242012424 if let &InboundHTLCState::RemoteAnnounced(_) = &htlc.state {
@@ -12446,15 +12450,16 @@ where
1244612450 }) => {
1244712451 0u8.write(writer)?;
1244812452 data.write(writer)?;
12449- removed_htlc_failure_attribution_data .push(&attribution_data);
12453+ removed_htlc_attribution_data .push(&attribution_data);
1245012454 },
1245112455 InboundHTLCRemovalReason::FailMalformed((hash, code)) => {
1245212456 1u8.write(writer)?;
1245312457 (hash, code).write(writer)?;
1245412458 },
12455- InboundHTLCRemovalReason::Fulfill(preimage) => {
12459+ InboundHTLCRemovalReason::Fulfill(preimage, attribution_data ) => {
1245612460 2u8.write(writer)?;
1245712461 preimage.write(writer)?;
12462+ removed_htlc_attribution_data.push(&attribution_data);
1245812463 },
1245912464 }
1246012465 },
@@ -12771,7 +12776,7 @@ where
1277112776 (51, is_manual_broadcast, option), // Added in 0.0.124
1277212777 (53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
1277312778 (54, self.pending_funding, optional_vec), // Added in 0.2
12774- (55, removed_htlc_failure_attribution_data , optional_vec), // Added in 0.2
12779+ (55, removed_htlc_attribution_data , optional_vec), // Added in 0.2
1277512780 (57, holding_cell_failure_attribution_data, optional_vec), // Added in 0.2
1277612781 (58, self.interactive_tx_signing_session, option), // Added in 0.2
1277712782 (59, self.funding.minimum_depth_override, option), // Added in 0.2
@@ -12867,7 +12872,7 @@ where
1286712872 attribution_data: None,
1286812873 }),
1286912874 1 => InboundHTLCRemovalReason::FailMalformed(Readable::read(reader)?),
12870- 2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?),
12875+ 2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?, None ),
1287112876 _ => return Err(DecodeError::InvalidValue),
1287212877 };
1287312878 InboundHTLCState::LocalRemoved(reason)
@@ -13117,7 +13122,7 @@ where
1311713122 let mut pending_outbound_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
1311813123 let mut holding_cell_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
1311913124
13120- let mut removed_htlc_failure_attribution_data : Option<Vec<Option<AttributionData>>> = None;
13125+ let mut removed_htlc_attribution_data : Option<Vec<Option<AttributionData>>> = None;
1312113126 let mut holding_cell_failure_attribution_data: Option<Vec<Option<AttributionData>>> = None;
1312213127
1312313128 let mut malformed_htlcs: Option<Vec<(u64, u16, [u8; 32])>> = None;
@@ -13170,7 +13175,7 @@ where
1317013175 (51, is_manual_broadcast, option),
1317113176 (53, funding_tx_broadcast_safe_event_emitted, option),
1317213177 (54, pending_funding, optional_vec), // Added in 0.2
13173- (55, removed_htlc_failure_attribution_data , optional_vec),
13178+ (55, removed_htlc_attribution_data , optional_vec),
1317413179 (57, holding_cell_failure_attribution_data, optional_vec),
1317513180 (58, interactive_tx_signing_session, option), // Added in 0.2
1317613181 (59, minimum_depth_override, option), // Added in 0.2
@@ -13274,24 +13279,27 @@ where
1327413279 }
1327513280 }
1327613281
13277- if let Some(attribution_data_list) = removed_htlc_failure_attribution_data {
13278- let mut removed_htlc_relay_failures =
13279- pending_inbound_htlcs.iter_mut().filter_map(|status| {
13280- if let InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailRelay(
13281- ref mut packet,
13282- )) = &mut status.state
13283- {
13284- Some(&mut packet.attribution_data)
13285- } else {
13286- None
13282+ if let Some(attribution_data_list) = removed_htlc_attribution_data {
13283+ let mut removed_htlcs = pending_inbound_htlcs.iter_mut().filter_map(|status| {
13284+ if let InboundHTLCState::LocalRemoved(reason) = &mut status.state {
13285+ match reason {
13286+ InboundHTLCRemovalReason::FailRelay(ref mut packet) => {
13287+ Some(&mut packet.attribution_data)
13288+ },
13289+ InboundHTLCRemovalReason::Fulfill(_, ref mut attribution_data) => {
13290+ Some(attribution_data)
13291+ },
13292+ _ => None,
1328713293 }
13288- });
13294+ } else {
13295+ None
13296+ }
13297+ });
1328913298
1329013299 for attribution_data in attribution_data_list {
13291- *removed_htlc_relay_failures.next().ok_or(DecodeError::InvalidValue)? =
13292- attribution_data;
13300+ *removed_htlcs.next().ok_or(DecodeError::InvalidValue)? = attribution_data;
1329313301 }
13294- if removed_htlc_relay_failures .next().is_some() {
13302+ if removed_htlcs .next().is_some() {
1329513303 return Err(DecodeError::InvalidValue);
1329613304 }
1329713305 }
0 commit comments