@@ -36,7 +36,7 @@ use crate::ln::interactivetxs::{
3636 TX_COMMON_FIELDS_WEIGHT,
3737};
3838use crate::ln::msgs;
39- use crate::ln::msgs::{ClosingSigned, ClosingSignedFeeRange, DecodeError};
39+ use crate::ln::msgs::{ClosingSigned, ClosingSignedFeeRange, DecodeError, OnionErrorPacket };
4040use crate::ln::script::{self, ShutdownScript};
4141use crate::ln::channel_state::{ChannelShutdownState, CounterpartyForwardingInfo, InboundHTLCDetails, InboundHTLCStateDetails, OutboundHTLCDetails, OutboundHTLCStateDetails};
4242use crate::ln::channelmanager::{self, OpenChannelMessage, PendingHTLCStatus, HTLCSource, SentHTLCId, HTLCFailureMsg, PendingHTLCInfo, RAACommitmentOrder, PaymentClaimDetails, BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA, MAX_LOCAL_BREAKDOWN_TIMEOUT};
@@ -9840,11 +9840,6 @@ fn get_initial_channel_type(config: &UserConfig, their_features: &InitFeatures)
98409840const SERIALIZATION_VERSION: u8 = 4;
98419841const MIN_SERIALIZATION_VERSION: u8 = 4;
98429842
9843- impl_writeable_tlv_based_enum_legacy!(InboundHTLCRemovalReason,;
9844- (0, FailRelay),
9845- (1, FailMalformed),
9846- (2, Fulfill),
9847- );
98489843
98499844impl Writeable for ChannelUpdateStatus {
98509845 fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
@@ -9950,6 +9945,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
99509945 dropped_inbound_htlcs += 1;
99519946 }
99529947 }
9948+ let mut removed_htlc_failure_attribution_data: Vec<&Option<[u8; ATTRIBUTION_DATA_LEN]>> = Vec::new();
99539949 (self.context.pending_inbound_htlcs.len() as u64 - dropped_inbound_htlcs).write(writer)?;
99549950 for htlc in self.context.pending_inbound_htlcs.iter() {
99559951 if let &InboundHTLCState::RemoteAnnounced(_) = &htlc.state {
@@ -9974,7 +9970,21 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
99749970 },
99759971 &InboundHTLCState::LocalRemoved(ref removal_reason) => {
99769972 4u8.write(writer)?;
9977- removal_reason.write(writer)?;
9973+ match removal_reason {
9974+ InboundHTLCRemovalReason::FailRelay(msgs::OnionErrorPacket { data, attribution_data }) => {
9975+ 0u8.write(writer)?;
9976+ data.write(writer)?;
9977+ removed_htlc_failure_attribution_data.push(&attribution_data);
9978+ },
9979+ InboundHTLCRemovalReason::FailMalformed((hash, code)) => {
9980+ 1u8.write(writer)?;
9981+ (hash, code).write(writer)?;
9982+ },
9983+ InboundHTLCRemovalReason::Fulfill(preimage) => {
9984+ 2u8.write(writer)?;
9985+ preimage.write(writer)?;
9986+ },
9987+ }
99789988 },
99799989 }
99809990 }
@@ -10026,6 +10036,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1002610036
1002710037 let mut holding_cell_skimmed_fees: Vec<Option<u64>> = Vec::new();
1002810038 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();
1002910040 // Vec of (htlc_id, failure_code, sha256_of_onion)
1003010041 let mut malformed_htlcs: Vec<(u64, u16, [u8; 32])> = Vec::new();
1003110042 (self.context.holding_cell_htlc_updates.len() as u64).write(writer)?;
@@ -10053,7 +10064,8 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1005310064 &HTLCUpdateAwaitingACK::FailHTLC { ref htlc_id, ref err_packet } => {
1005410065 2u8.write(writer)?;
1005510066 htlc_id.write(writer)?;
10056- err_packet.write(writer)?;
10067+ err_packet.data.write(writer)?;
10068+ holding_cell_failure_attribution_data.push(&err_packet.attribution_data);
1005710069 }
1005810070 &HTLCUpdateAwaitingACK::FailMalformedHTLC {
1005910071 htlc_id, failure_code, sha256_of_onion
@@ -10062,10 +10074,9 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1006210074 // `::FailHTLC` variant and write the real malformed error as an optional TLV.
1006310075 malformed_htlcs.push((htlc_id, failure_code, sha256_of_onion));
1006410076
10065- let dummy_err_packet = msgs::OnionErrorPacket { data: Vec::new(), attribution_data: [0; ATTRIBUTION_DATA_LEN] };
1006610077 2u8.write(writer)?;
1006710078 htlc_id.write(writer)?;
10068- dummy_err_packet .write(writer)?;
10079+ Vec::<u8>::new() .write(writer)?;
1006910080 }
1007010081 }
1007110082 }
@@ -10238,6 +10249,8 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1023810249 (49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
1023910250 (51, is_manual_broadcast, option), // Added in 0.0.124
1024010251 (53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
10252+ (55, removed_htlc_failure_attribution_data, optional_vec), // Added in 0.2
10253+ (57, holding_cell_failure_attribution_data, optional_vec), // Added in 0.2
1024110254 });
1024210255
1024310256 Ok(())
@@ -10330,7 +10343,18 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1033010343 InboundHTLCState::AwaitingAnnouncedRemoteRevoke(resolution)
1033110344 },
1033210345 3 => InboundHTLCState::Committed,
10333- 4 => InboundHTLCState::LocalRemoved(Readable::read(reader)?),
10346+ 4 => {
10347+ let reason = match <u8 as Readable>::read(reader)? {
10348+ 0 => InboundHTLCRemovalReason::FailRelay(msgs::OnionErrorPacket {
10349+ data: Readable::read(reader)?,
10350+ attribution_data: None,
10351+ }),
10352+ 1 => InboundHTLCRemovalReason::FailMalformed(Readable::read(reader)?),
10353+ 2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?),
10354+ _ => return Err(DecodeError::InvalidValue),
10355+ };
10356+ InboundHTLCState::LocalRemoved(reason)
10357+ },
1033410358 _ => return Err(DecodeError::InvalidValue),
1033510359 },
1033610360 });
@@ -10386,7 +10410,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1038610410 },
1038710411 2 => HTLCUpdateAwaitingACK::FailHTLC {
1038810412 htlc_id: Readable::read(reader)?,
10389- err_packet: Readable::read(reader)?,
10413+ err_packet: OnionErrorPacket {
10414+ data: Readable::read(reader)?,
10415+ attribution_data: None,
10416+ },
1039010417 },
1039110418 _ => return Err(DecodeError::InvalidValue),
1039210419 });
@@ -10535,6 +10562,9 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1053510562 let mut pending_outbound_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
1053610563 let mut holding_cell_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
1053710564
10565+ 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;
10567+
1053810568 let mut malformed_htlcs: Option<Vec<(u64, u16, [u8; 32])>> = None;
1053910569 let mut monitor_pending_update_adds: Option<Vec<msgs::UpdateAddHTLC>> = None;
1054010570
@@ -10577,6 +10607,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1057710607 (49, local_initiated_shutdown, option),
1057810608 (51, is_manual_broadcast, option),
1057910609 (53, funding_tx_broadcast_safe_event_emitted, option),
10610+ (55, removed_htlc_failure_attribution_data, option),
10611+ (57, holding_cell_failure_attribution_data, option),
1058010612 });
1058110613
1058210614 let (channel_keys_id, holder_signer) = if let Some(channel_keys_id) = channel_keys_id {
@@ -10671,6 +10703,41 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1067110703 if iter.next().is_some() { return Err(DecodeError::InvalidValue) }
1067210704 }
1067310705
10706+ if let Some(attribution_datas) = removed_htlc_failure_attribution_data {
10707+ let mut removed_htlc_relay_failures =
10708+ pending_inbound_htlcs.iter_mut().filter_map(|status|
10709+ if let InboundHTLCState::LocalRemoved(ref mut reason) = &mut status.state {
10710+ if let InboundHTLCRemovalReason::FailRelay(ref mut packet) = reason {
10711+ Some(&mut packet.attribution_data)
10712+ } else {
10713+ None
10714+ }
10715+ } else {
10716+ None
10717+ }
10718+ );
10719+
10720+ for attribution_data in attribution_datas {
10721+ *removed_htlc_relay_failures.next().ok_or(DecodeError::InvalidValue)? = attribution_data;
10722+ }
10723+ if removed_htlc_relay_failures.next().is_some() { return Err(DecodeError::InvalidValue); }
10724+ }
10725+ 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+ );
10734+
10735+ for attribution_data in attribution_datas {
10736+ *holding_cell_failures.next().ok_or(DecodeError::InvalidValue)? = attribution_data;
10737+ }
10738+ if holding_cell_failures.next().is_some() { return Err(DecodeError::InvalidValue); }
10739+ }
10740+
1067410741 if let Some(malformed_htlcs) = malformed_htlcs {
1067510742 for (malformed_htlc_id, failure_code, sha256_of_onion) in malformed_htlcs {
1067610743 let htlc_idx = holding_cell_htlc_updates.iter().position(|htlc| {
0 commit comments