@@ -36,7 +36,7 @@ use crate::ln::interactivetxs::{
36
36
TX_COMMON_FIELDS_WEIGHT,
37
37
};
38
38
use crate::ln::msgs;
39
- use crate::ln::msgs::{ClosingSigned, ClosingSignedFeeRange, DecodeError};
39
+ use crate::ln::msgs::{ClosingSigned, ClosingSignedFeeRange, DecodeError, OnionErrorPacket };
40
40
use crate::ln::script::{self, ShutdownScript};
41
41
use crate::ln::channel_state::{ChannelShutdownState, CounterpartyForwardingInfo, InboundHTLCDetails, InboundHTLCStateDetails, OutboundHTLCDetails, OutboundHTLCStateDetails};
42
42
use 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)
9840
9840
const SERIALIZATION_VERSION: u8 = 4;
9841
9841
const MIN_SERIALIZATION_VERSION: u8 = 4;
9842
9842
9843
- impl_writeable_tlv_based_enum_legacy!(InboundHTLCRemovalReason,;
9844
- (0, FailRelay),
9845
- (1, FailMalformed),
9846
- (2, Fulfill),
9847
- );
9848
9843
9849
9844
impl Writeable for ChannelUpdateStatus {
9850
9845
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
9950
9945
dropped_inbound_htlcs += 1;
9951
9946
}
9952
9947
}
9948
+ let mut removed_htlc_failure_attribution_data: Vec<&Option<[u8; ATTRIBUTION_DATA_LEN]>> = Vec::new();
9953
9949
(self.context.pending_inbound_htlcs.len() as u64 - dropped_inbound_htlcs).write(writer)?;
9954
9950
for htlc in self.context.pending_inbound_htlcs.iter() {
9955
9951
if let &InboundHTLCState::RemoteAnnounced(_) = &htlc.state {
@@ -9974,7 +9970,21 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
9974
9970
},
9975
9971
&InboundHTLCState::LocalRemoved(ref removal_reason) => {
9976
9972
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
+ }
9978
9988
},
9979
9989
}
9980
9990
}
@@ -10026,6 +10036,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
10026
10036
10027
10037
let mut holding_cell_skimmed_fees: Vec<Option<u64>> = Vec::new();
10028
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();
10029
10040
// Vec of (htlc_id, failure_code, sha256_of_onion)
10030
10041
let mut malformed_htlcs: Vec<(u64, u16, [u8; 32])> = Vec::new();
10031
10042
(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
10053
10064
&HTLCUpdateAwaitingACK::FailHTLC { ref htlc_id, ref err_packet } => {
10054
10065
2u8.write(writer)?;
10055
10066
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);
10057
10069
}
10058
10070
&HTLCUpdateAwaitingACK::FailMalformedHTLC {
10059
10071
htlc_id, failure_code, sha256_of_onion
@@ -10062,10 +10074,9 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
10062
10074
// `::FailHTLC` variant and write the real malformed error as an optional TLV.
10063
10075
malformed_htlcs.push((htlc_id, failure_code, sha256_of_onion));
10064
10076
10065
- let dummy_err_packet = msgs::OnionErrorPacket { data: Vec::new(), attribution_data: [0; ATTRIBUTION_DATA_LEN] };
10066
10077
2u8.write(writer)?;
10067
10078
htlc_id.write(writer)?;
10068
- dummy_err_packet .write(writer)?;
10079
+ Vec::<u8>::new() .write(writer)?;
10069
10080
}
10070
10081
}
10071
10082
}
@@ -10238,6 +10249,8 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
10238
10249
(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
10239
10250
(51, is_manual_broadcast, option), // Added in 0.0.124
10240
10251
(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
10241
10254
});
10242
10255
10243
10256
Ok(())
@@ -10330,7 +10343,18 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10330
10343
InboundHTLCState::AwaitingAnnouncedRemoteRevoke(resolution)
10331
10344
},
10332
10345
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
+ },
10334
10358
_ => return Err(DecodeError::InvalidValue),
10335
10359
},
10336
10360
});
@@ -10386,7 +10410,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10386
10410
},
10387
10411
2 => HTLCUpdateAwaitingACK::FailHTLC {
10388
10412
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
+ },
10390
10417
},
10391
10418
_ => return Err(DecodeError::InvalidValue),
10392
10419
});
@@ -10535,6 +10562,9 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10535
10562
let mut pending_outbound_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
10536
10563
let mut holding_cell_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
10537
10564
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
+
10538
10568
let mut malformed_htlcs: Option<Vec<(u64, u16, [u8; 32])>> = None;
10539
10569
let mut monitor_pending_update_adds: Option<Vec<msgs::UpdateAddHTLC>> = None;
10540
10570
@@ -10577,6 +10607,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10577
10607
(49, local_initiated_shutdown, option),
10578
10608
(51, is_manual_broadcast, option),
10579
10609
(53, funding_tx_broadcast_safe_event_emitted, option),
10610
+ (55, removed_htlc_failure_attribution_data, option),
10611
+ (57, holding_cell_failure_attribution_data, option),
10580
10612
});
10581
10613
10582
10614
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
10671
10703
if iter.next().is_some() { return Err(DecodeError::InvalidValue) }
10672
10704
}
10673
10705
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
+
10674
10741
if let Some(malformed_htlcs) = malformed_htlcs {
10675
10742
for (malformed_htlc_id, failure_code, sha256_of_onion) in malformed_htlcs {
10676
10743
let htlc_idx = holding_cell_htlc_updates.iter().position(|htlc| {
0 commit comments