Skip to content

Commit dc4b841

Browse files
committed
fix holding cell persistence for attribution_data
1 parent 087aaf4 commit dc4b841

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

lightning/src/ln/channel.rs

+19-16
Original file line numberDiff line numberDiff line change
@@ -10036,11 +10036,11 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1003610036

1003710037
let mut holding_cell_skimmed_fees: Vec<Option<u64>> = Vec::new();
1003810038
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();
1004010040
// Vec of (htlc_id, failure_code, sha256_of_onion)
1004110041
let mut malformed_htlcs: Vec<(u64, u16, [u8; 32])> = Vec::new();
1004210042
(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() {
1004410044
match update {
1004510045
&HTLCUpdateAwaitingACK::AddHTLC {
1004610046
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
1006510065
2u8.write(writer)?;
1006610066
htlc_id.write(writer)?;
1006710067
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+
}
1006910075
}
1007010076
&HTLCUpdateAwaitingACK::FailMalformedHTLC {
1007110077
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
1056310569
let mut holding_cell_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
1056410570

1056510571
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;
1056710573

1056810574
let mut malformed_htlcs: Option<Vec<(u64, u16, [u8; 32])>> = None;
1056910575
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
1072210728
}
1072310729
if removed_htlc_relay_failures.next().is_some() { return Err(DecodeError::InvalidValue); }
1072410730
}
10731+
1072510732
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)?;
1073410735

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+
}
1073710741
}
10738-
if holding_cell_failures.next().is_some() { return Err(DecodeError::InvalidValue); }
1073910742
}
1074010743

1074110744
if let Some(malformed_htlcs) = malformed_htlcs {
@@ -11568,7 +11571,7 @@ mod tests {
1156811571
htlc_id: 0,
1156911572
};
1157011573
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]) }
1157211575
};
1157311576
let dummy_holding_cell_malformed_htlc = |htlc_id| HTLCUpdateAwaitingACK::FailMalformedHTLC {
1157411577
htlc_id, failure_code: INVALID_ONION_BLINDING, sha256_of_onion: [0; 32],

0 commit comments

Comments
 (0)