@@ -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,
@@ -6190,7 +6190,7 @@ where
6190
6190
match htlc.state {
6191
6191
InboundHTLCState::Committed => {},
6192
6192
InboundHTLCState::LocalRemoved(ref reason) => {
6193
- if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
6193
+ if let &InboundHTLCRemovalReason::Fulfill(_, _ ) = reason {
6194
6194
} else {
6195
6195
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());
6196
6196
debug_assert!(
@@ -6301,6 +6301,7 @@ where
6301
6301
);
6302
6302
htlc.state = InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(
6303
6303
payment_preimage_arg.clone(),
6304
+ None,
6304
6305
));
6305
6306
}
6306
6307
@@ -7459,7 +7460,7 @@ where
7459
7460
pending_inbound_htlcs.retain(|htlc| {
7460
7461
if let &InboundHTLCState::LocalRemoved(ref reason) = &htlc.state {
7461
7462
log_trace!(logger, " ...removing inbound LocalRemoved {}", &htlc.payment_hash);
7462
- if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
7463
+ if let &InboundHTLCRemovalReason::Fulfill(_, _ ) = reason {
7463
7464
value_to_self_msat_diff += htlc.amount_msat as i64;
7464
7465
}
7465
7466
*expecting_peer_commitment_signed = true;
@@ -8323,12 +8324,15 @@ where
8323
8324
failure_code: failure_code.clone(),
8324
8325
});
8325
8326
},
8326
- &InboundHTLCRemovalReason::Fulfill(ref payment_preimage) => {
8327
+ &InboundHTLCRemovalReason::Fulfill(
8328
+ ref payment_preimage,
8329
+ ref attribution_data,
8330
+ ) => {
8327
8331
update_fulfill_htlcs.push(msgs::UpdateFulfillHTLC {
8328
8332
channel_id: self.context.channel_id(),
8329
8333
htlc_id: htlc.htlc_id,
8330
8334
payment_preimage: payment_preimage.clone(),
8331
- attribution_data: None ,
8335
+ attribution_data: attribution_data.clone() ,
8332
8336
});
8333
8337
},
8334
8338
}
@@ -12414,7 +12418,7 @@ where
12414
12418
dropped_inbound_htlcs += 1;
12415
12419
}
12416
12420
}
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();
12418
12422
(self.context.pending_inbound_htlcs.len() as u64 - dropped_inbound_htlcs).write(writer)?;
12419
12423
for htlc in self.context.pending_inbound_htlcs.iter() {
12420
12424
if let &InboundHTLCState::RemoteAnnounced(_) = &htlc.state {
@@ -12446,15 +12450,16 @@ where
12446
12450
}) => {
12447
12451
0u8.write(writer)?;
12448
12452
data.write(writer)?;
12449
- removed_htlc_failure_attribution_data .push(&attribution_data);
12453
+ removed_htlc_attribution_data .push(&attribution_data);
12450
12454
},
12451
12455
InboundHTLCRemovalReason::FailMalformed((hash, code)) => {
12452
12456
1u8.write(writer)?;
12453
12457
(hash, code).write(writer)?;
12454
12458
},
12455
- InboundHTLCRemovalReason::Fulfill(preimage) => {
12459
+ InboundHTLCRemovalReason::Fulfill(preimage, attribution_data ) => {
12456
12460
2u8.write(writer)?;
12457
12461
preimage.write(writer)?;
12462
+ removed_htlc_attribution_data.push(&attribution_data);
12458
12463
},
12459
12464
}
12460
12465
},
@@ -12771,7 +12776,7 @@ where
12771
12776
(51, is_manual_broadcast, option), // Added in 0.0.124
12772
12777
(53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
12773
12778
(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
12775
12780
(57, holding_cell_failure_attribution_data, optional_vec), // Added in 0.2
12776
12781
(58, self.interactive_tx_signing_session, option), // Added in 0.2
12777
12782
(59, self.funding.minimum_depth_override, option), // Added in 0.2
@@ -12867,7 +12872,7 @@ where
12867
12872
attribution_data: None,
12868
12873
}),
12869
12874
1 => InboundHTLCRemovalReason::FailMalformed(Readable::read(reader)?),
12870
- 2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?),
12875
+ 2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?, None ),
12871
12876
_ => return Err(DecodeError::InvalidValue),
12872
12877
};
12873
12878
InboundHTLCState::LocalRemoved(reason)
@@ -13117,7 +13122,7 @@ where
13117
13122
let mut pending_outbound_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
13118
13123
let mut holding_cell_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
13119
13124
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;
13121
13126
let mut holding_cell_failure_attribution_data: Option<Vec<Option<AttributionData>>> = None;
13122
13127
13123
13128
let mut malformed_htlcs: Option<Vec<(u64, u16, [u8; 32])>> = None;
@@ -13170,7 +13175,7 @@ where
13170
13175
(51, is_manual_broadcast, option),
13171
13176
(53, funding_tx_broadcast_safe_event_emitted, option),
13172
13177
(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),
13174
13179
(57, holding_cell_failure_attribution_data, optional_vec),
13175
13180
(58, interactive_tx_signing_session, option), // Added in 0.2
13176
13181
(59, minimum_depth_override, option), // Added in 0.2
@@ -13274,24 +13279,27 @@ where
13274
13279
}
13275
13280
}
13276
13281
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,
13287
13293
}
13288
- });
13294
+ } else {
13295
+ None
13296
+ }
13297
+ });
13289
13298
13290
13299
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;
13293
13301
}
13294
- if removed_htlc_relay_failures .next().is_some() {
13302
+ if removed_htlcs .next().is_some() {
13295
13303
return Err(DecodeError::InvalidValue);
13296
13304
}
13297
13305
}
0 commit comments