@@ -35,7 +35,7 @@ use crate::ln::interactivetxs::{
3535 TX_COMMON_FIELDS_WEIGHT,
3636};
3737use crate::ln::msgs;
38- use crate::ln::msgs::{ClosingSigned, ClosingSignedFeeRange, DecodeError};
38+ use crate::ln::msgs::{ClosingSigned, ClosingSignedFeeRange, DecodeError, OnionErrorPacket };
3939use crate::ln::script::{self, ShutdownScript};
4040use crate::ln::channel_state::{ChannelShutdownState, CounterpartyForwardingInfo, InboundHTLCDetails, InboundHTLCStateDetails, OutboundHTLCDetails, OutboundHTLCStateDetails};
4141use crate::ln::channelmanager::{self, OpenChannelMessage, PendingHTLCStatus, HTLCSource, SentHTLCId, HTLCFailureMsg, PendingHTLCInfo, RAACommitmentOrder, PaymentClaimDetails, BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA, MAX_LOCAL_BREAKDOWN_TIMEOUT};
@@ -50,7 +50,7 @@ use crate::ln::chan_utils::{
5050#[cfg(splicing)]
5151use crate::ln::chan_utils::FUNDING_TRANSACTION_WITNESS_WEIGHT;
5252use crate::ln::chan_utils;
53- use crate::ln::onion_utils::HTLCFailReason;
53+ use crate::ln::onion_utils::{ HTLCFailReason} ;
5454use crate::chain::BestBlock;
5555use crate::chain::chaininterface::{FeeEstimator, ConfirmationTarget, LowerBoundedFeeEstimator, fee_for_weight};
5656use crate::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, LATENCY_GRACE_PERIOD_BLOCKS};
@@ -4933,7 +4933,7 @@ trait FailHTLCContents {
49334933impl FailHTLCContents for msgs::OnionErrorPacket {
49344934 type Message = msgs::UpdateFailHTLC;
49354935 fn to_message(self, htlc_id: u64, channel_id: ChannelId) -> Self::Message {
4936- msgs::UpdateFailHTLC { htlc_id, channel_id, reason: self }
4936+ msgs::UpdateFailHTLC { htlc_id, channel_id, reason: self.data }
49374937 }
49384938 fn to_inbound_htlc_state(self) -> InboundHTLCState {
49394939 InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailRelay(self))
@@ -6136,7 +6136,7 @@ impl<SP: Deref> FundedChannel<SP> where
61366136 require_commitment = true;
61376137 match fail_msg {
61386138 HTLCFailureMsg::Relay(msg) => {
6139- htlc.state = InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailRelay(msg.reason. clone()));
6139+ htlc.state = InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailRelay(msg.clone().into ()));
61406140 update_fail_htlcs.push(msg)
61416141 },
61426142 HTLCFailureMsg::Malformed(msg) => {
@@ -6844,7 +6844,7 @@ impl<SP: Deref> FundedChannel<SP> where
68446844 update_fail_htlcs.push(msgs::UpdateFailHTLC {
68456845 channel_id: self.context.channel_id(),
68466846 htlc_id: htlc.htlc_id,
6847- reason: err_packet.clone()
6847+ reason: err_packet.data. clone(),
68486848 });
68496849 },
68506850 &InboundHTLCRemovalReason::FailMalformed((ref sha256_of_onion, ref failure_code)) => {
@@ -10142,11 +10142,6 @@ fn get_initial_channel_type(config: &UserConfig, their_features: &InitFeatures)
1014210142const SERIALIZATION_VERSION: u8 = 4;
1014310143const MIN_SERIALIZATION_VERSION: u8 = 4;
1014410144
10145- impl_writeable_tlv_based_enum_legacy!(InboundHTLCRemovalReason,;
10146- (0, FailRelay),
10147- (1, FailMalformed),
10148- (2, Fulfill),
10149- );
1015010145
1015110146impl Writeable for ChannelUpdateStatus {
1015210147 fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
@@ -10276,7 +10271,20 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1027610271 },
1027710272 &InboundHTLCState::LocalRemoved(ref removal_reason) => {
1027810273 4u8.write(writer)?;
10279- removal_reason.write(writer)?;
10274+ match removal_reason {
10275+ InboundHTLCRemovalReason::FailRelay(msgs::OnionErrorPacket { data }) => {
10276+ 0u8.write(writer)?;
10277+ data.write(writer)?;
10278+ },
10279+ InboundHTLCRemovalReason::FailMalformed((hash, code)) => {
10280+ 1u8.write(writer)?;
10281+ (hash, code).write(writer)?;
10282+ },
10283+ InboundHTLCRemovalReason::Fulfill(preimage) => {
10284+ 2u8.write(writer)?;
10285+ preimage.write(writer)?;
10286+ },
10287+ }
1028010288 },
1028110289 }
1028210290 }
@@ -10355,7 +10363,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1035510363 &HTLCUpdateAwaitingACK::FailHTLC { ref htlc_id, ref err_packet } => {
1035610364 2u8.write(writer)?;
1035710365 htlc_id.write(writer)?;
10358- err_packet.write(writer)?;
10366+ err_packet.data. write(writer)?;
1035910367 }
1036010368 &HTLCUpdateAwaitingACK::FailMalformedHTLC {
1036110369 htlc_id, failure_code, sha256_of_onion
@@ -10364,10 +10372,9 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1036410372 // `::FailHTLC` variant and write the real malformed error as an optional TLV.
1036510373 malformed_htlcs.push((htlc_id, failure_code, sha256_of_onion));
1036610374
10367- let dummy_err_packet = msgs::OnionErrorPacket { data: Vec::new() };
1036810375 2u8.write(writer)?;
1036910376 htlc_id.write(writer)?;
10370- dummy_err_packet .write(writer)?;
10377+ Vec::<u8>::new() .write(writer)?;
1037110378 }
1037210379 }
1037310380 }
@@ -10613,7 +10620,17 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1061310620 InboundHTLCState::AwaitingAnnouncedRemoteRevoke(resolution)
1061410621 },
1061510622 3 => InboundHTLCState::Committed,
10616- 4 => InboundHTLCState::LocalRemoved(Readable::read(reader)?),
10623+ 4 => {
10624+ let reason = match <u8 as Readable>::read(reader)? {
10625+ 0 => InboundHTLCRemovalReason::FailRelay(msgs::OnionErrorPacket {
10626+ data: Readable::read(reader)?,
10627+ }),
10628+ 1 => InboundHTLCRemovalReason::FailMalformed(Readable::read(reader)?),
10629+ 2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?),
10630+ _ => return Err(DecodeError::InvalidValue),
10631+ };
10632+ InboundHTLCState::LocalRemoved(reason)
10633+ },
1061710634 _ => return Err(DecodeError::InvalidValue),
1061810635 },
1061910636 });
@@ -10669,7 +10686,9 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1066910686 },
1067010687 2 => HTLCUpdateAwaitingACK::FailHTLC {
1067110688 htlc_id: Readable::read(reader)?,
10672- err_packet: Readable::read(reader)?,
10689+ err_packet: OnionErrorPacket {
10690+ data: Readable::read(reader)?,
10691+ },
1067310692 },
1067410693 _ => return Err(DecodeError::InvalidValue),
1067510694 });
0 commit comments