@@ -10036,11 +10036,11 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
10036
10036
10037
10037
let mut holding_cell_skimmed_fees: Vec<Option<u64>> = Vec::new();
10038
10038
let mut holding_cell_blinding_points: Vec<Option<PublicKey>> = Vec::new();
10039
- let mut holding_cell_failure_attribution_data: Vec<&Option< [u8; ATTRIBUTION_DATA_LEN]> > = Vec::new();
10039
+ let mut holding_cell_failure_attribution_data: Vec<(u32, [u8; ATTRIBUTION_DATA_LEN]) > = Vec::new();
10040
10040
// Vec of (htlc_id, failure_code, sha256_of_onion)
10041
10041
let mut malformed_htlcs: Vec<(u64, u16, [u8; 32])> = Vec::new();
10042
10042
(self.context.holding_cell_htlc_updates.len() as u64).write(writer)?;
10043
- for update in self.context.holding_cell_htlc_updates.iter() {
10043
+ for (i, update) in self.context.holding_cell_htlc_updates.iter().enumerate () {
10044
10044
match update {
10045
10045
&HTLCUpdateAwaitingACK::AddHTLC {
10046
10046
ref amount_msat, ref cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet,
@@ -10065,7 +10065,13 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
10065
10065
2u8.write(writer)?;
10066
10066
htlc_id.write(writer)?;
10067
10067
err_packet.data.write(writer)?;
10068
- holding_cell_failure_attribution_data.push(&err_packet.attribution_data);
10068
+
10069
+ // Store the attribution data for later writing. Include the holding cell htlc update index because
10070
+ // FailMalformedHTLC is stored with the same type 2 and we wouldn't be able to distinguish the two
10071
+ // when reading back in.
10072
+ if let Some(attribution_data ) = err_packet.attribution_data {
10073
+ holding_cell_failure_attribution_data.push((i as u32, attribution_data));
10074
+ }
10069
10075
}
10070
10076
&HTLCUpdateAwaitingACK::FailMalformedHTLC {
10071
10077
htlc_id, failure_code, sha256_of_onion
@@ -10563,7 +10569,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10563
10569
let mut holding_cell_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
10564
10570
10565
10571
let mut removed_htlc_failure_attribution_data: Option<Vec<Option<[u8; ATTRIBUTION_DATA_LEN]>>> = None;
10566
- let mut holding_cell_failure_attribution_data: Option<Vec<Option< [u8; ATTRIBUTION_DATA_LEN]> >> = None;
10572
+ let mut holding_cell_failure_attribution_data: Option<Vec<(u32, [u8; ATTRIBUTION_DATA_LEN]) >> = None;
10567
10573
10568
10574
let mut malformed_htlcs: Option<Vec<(u64, u16, [u8; 32])>> = None;
10569
10575
let mut monitor_pending_update_adds: Option<Vec<msgs::UpdateAddHTLC>> = None;
@@ -10722,20 +10728,17 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10722
10728
}
10723
10729
if removed_htlc_relay_failures.next().is_some() { return Err(DecodeError::InvalidValue); }
10724
10730
}
10731
+
10725
10732
if let Some(attribution_datas) = holding_cell_failure_attribution_data {
10726
- let mut holding_cell_failures =
10727
- holding_cell_htlc_updates.iter_mut().filter_map(|upd|
10728
- if let HTLCUpdateAwaitingACK::FailHTLC { err_packet: OnionErrorPacket { ref mut attribution_data, .. }, .. } = upd {
10729
- Some(attribution_data)
10730
- } else {
10731
- None
10732
- }
10733
- );
10733
+ for (i, attribution_data) in attribution_datas {
10734
+ let update = holding_cell_htlc_updates.get_mut(i as usize).ok_or(DecodeError::InvalidValue)?;
10734
10735
10735
- for attribution_data in attribution_datas {
10736
- *holding_cell_failures.next().ok_or(DecodeError::InvalidValue)? = attribution_data;
10736
+ if let HTLCUpdateAwaitingACK::FailHTLC { htlc_id: _, ref mut err_packet } = update {
10737
+ err_packet.attribution_data = Some(attribution_data);
10738
+ } else {
10739
+ return Err(DecodeError::InvalidValue);
10740
+ }
10737
10741
}
10738
- if holding_cell_failures.next().is_some() { return Err(DecodeError::InvalidValue); }
10739
10742
}
10740
10743
10741
10744
if let Some(malformed_htlcs) = malformed_htlcs {
@@ -11568,7 +11571,7 @@ mod tests {
11568
11571
htlc_id: 0,
11569
11572
};
11570
11573
let dummy_holding_cell_failed_htlc = |htlc_id| HTLCUpdateAwaitingACK::FailHTLC {
11571
- htlc_id, err_packet: msgs::OnionErrorPacket { data: vec![42], attribution_data: Some([0 ; ATTRIBUTION_DATA_LEN]) }
11574
+ htlc_id, err_packet: msgs::OnionErrorPacket { data: vec![42], attribution_data: Some([1 ; ATTRIBUTION_DATA_LEN]) }
11572
11575
};
11573
11576
let dummy_holding_cell_malformed_htlc = |htlc_id| HTLCUpdateAwaitingACK::FailMalformedHTLC {
11574
11577
htlc_id, failure_code: INVALID_ONION_BLINDING, sha256_of_onion: [0; 32],
0 commit comments