@@ -140,7 +140,7 @@ enum FeeUpdateState {
140
140
enum InboundHTLCRemovalReason {
141
141
FailRelay(msgs::OnionErrorPacket),
142
142
FailMalformed(([u8; 32], u16)),
143
- Fulfill(PaymentPreimage),
143
+ Fulfill(PaymentPreimage, Option<AttributionData> ),
144
144
}
145
145
146
146
/// Represents the resolution status of an inbound HTLC.
@@ -236,7 +236,7 @@ impl From<&InboundHTLCState> for Option<InboundHTLCStateDetails> {
236
236
Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFail),
237
237
InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailMalformed(_)) =>
238
238
Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFail),
239
- InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_)) =>
239
+ InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_, _ )) =>
240
240
Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFulfill),
241
241
}
242
242
}
@@ -268,7 +268,7 @@ impl InboundHTLCState {
268
268
269
269
fn preimage(&self) -> Option<PaymentPreimage> {
270
270
match self {
271
- InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(preimage)) => {
271
+ InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(preimage, _ )) => {
272
272
Some(*preimage)
273
273
},
274
274
_ => None,
@@ -6208,7 +6208,7 @@ where
6208
6208
match htlc.state {
6209
6209
InboundHTLCState::Committed => {},
6210
6210
InboundHTLCState::LocalRemoved(ref reason) => {
6211
- if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
6211
+ if let &InboundHTLCRemovalReason::Fulfill(_, _ ) = reason {
6212
6212
} else {
6213
6213
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());
6214
6214
debug_assert!(
@@ -6319,6 +6319,7 @@ where
6319
6319
);
6320
6320
htlc.state = InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(
6321
6321
payment_preimage_arg.clone(),
6322
+ None,
6322
6323
));
6323
6324
}
6324
6325
@@ -7477,7 +7478,7 @@ where
7477
7478
pending_inbound_htlcs.retain(|htlc| {
7478
7479
if let &InboundHTLCState::LocalRemoved(ref reason) = &htlc.state {
7479
7480
log_trace!(logger, " ...removing inbound LocalRemoved {}", &htlc.payment_hash);
7480
- if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
7481
+ if let &InboundHTLCRemovalReason::Fulfill(_, _ ) = reason {
7481
7482
value_to_self_msat_diff += htlc.amount_msat as i64;
7482
7483
}
7483
7484
*expecting_peer_commitment_signed = true;
@@ -8341,12 +8342,15 @@ where
8341
8342
failure_code: failure_code.clone(),
8342
8343
});
8343
8344
},
8344
- &InboundHTLCRemovalReason::Fulfill(ref payment_preimage) => {
8345
+ &InboundHTLCRemovalReason::Fulfill(
8346
+ ref payment_preimage,
8347
+ ref attribution_data,
8348
+ ) => {
8345
8349
update_fulfill_htlcs.push(msgs::UpdateFulfillHTLC {
8346
8350
channel_id: self.context.channel_id(),
8347
8351
htlc_id: htlc.htlc_id,
8348
8352
payment_preimage: payment_preimage.clone(),
8349
- attribution_data: None ,
8353
+ attribution_data: attribution_data.clone() ,
8350
8354
});
8351
8355
},
8352
8356
}
@@ -12439,7 +12443,7 @@ where
12439
12443
dropped_inbound_htlcs += 1;
12440
12444
}
12441
12445
}
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();
12443
12447
(self.context.pending_inbound_htlcs.len() as u64 - dropped_inbound_htlcs).write(writer)?;
12444
12448
for htlc in self.context.pending_inbound_htlcs.iter() {
12445
12449
if let &InboundHTLCState::RemoteAnnounced(_) = &htlc.state {
@@ -12471,15 +12475,16 @@ where
12471
12475
}) => {
12472
12476
0u8.write(writer)?;
12473
12477
data.write(writer)?;
12474
- removed_htlc_failure_attribution_data .push(&attribution_data);
12478
+ removed_htlc_attribution_data .push(&attribution_data);
12475
12479
},
12476
12480
InboundHTLCRemovalReason::FailMalformed((hash, code)) => {
12477
12481
1u8.write(writer)?;
12478
12482
(hash, code).write(writer)?;
12479
12483
},
12480
- InboundHTLCRemovalReason::Fulfill(preimage) => {
12484
+ InboundHTLCRemovalReason::Fulfill(preimage, attribution_data ) => {
12481
12485
2u8.write(writer)?;
12482
12486
preimage.write(writer)?;
12487
+ removed_htlc_attribution_data.push(&attribution_data);
12483
12488
},
12484
12489
}
12485
12490
},
@@ -12796,7 +12801,7 @@ where
12796
12801
(51, is_manual_broadcast, option), // Added in 0.0.124
12797
12802
(53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
12798
12803
(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
12800
12805
(57, holding_cell_failure_attribution_data, optional_vec), // Added in 0.2
12801
12806
(58, self.interactive_tx_signing_session, option), // Added in 0.2
12802
12807
(59, self.funding.minimum_depth_override, option), // Added in 0.2
@@ -12892,7 +12897,7 @@ where
12892
12897
attribution_data: None,
12893
12898
}),
12894
12899
1 => InboundHTLCRemovalReason::FailMalformed(Readable::read(reader)?),
12895
- 2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?),
12900
+ 2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?, None ),
12896
12901
_ => return Err(DecodeError::InvalidValue),
12897
12902
};
12898
12903
InboundHTLCState::LocalRemoved(reason)
@@ -13142,7 +13147,7 @@ where
13142
13147
let mut pending_outbound_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
13143
13148
let mut holding_cell_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
13144
13149
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;
13146
13151
let mut holding_cell_failure_attribution_data: Option<Vec<Option<AttributionData>>> = None;
13147
13152
13148
13153
let mut malformed_htlcs: Option<Vec<(u64, u16, [u8; 32])>> = None;
@@ -13195,7 +13200,7 @@ where
13195
13200
(51, is_manual_broadcast, option),
13196
13201
(53, funding_tx_broadcast_safe_event_emitted, option),
13197
13202
(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),
13199
13204
(57, holding_cell_failure_attribution_data, optional_vec),
13200
13205
(58, interactive_tx_signing_session, option), // Added in 0.2
13201
13206
(59, minimum_depth_override, option), // Added in 0.2
@@ -13299,24 +13304,27 @@ where
13299
13304
}
13300
13305
}
13301
13306
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,
13312
13318
}
13313
- });
13319
+ } else {
13320
+ None
13321
+ }
13322
+ });
13314
13323
13315
13324
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;
13318
13326
}
13319
- if removed_htlc_relay_failures .next().is_some() {
13327
+ if removed_htlcs .next().is_some() {
13320
13328
return Err(DecodeError::InvalidValue);
13321
13329
}
13322
13330
}
0 commit comments