@@ -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};
@@ -49,7 +49,7 @@ use crate::ln::chan_utils::{
4949 ClosingTransaction, commit_tx_fee_sat,
5050};
5151use crate::ln::chan_utils;
52- use crate::ln::onion_utils::HTLCFailReason;
52+ use crate::ln::onion_utils::{ HTLCFailReason} ;
5353use crate::chain::BestBlock;
5454use crate::chain::chaininterface::{FeeEstimator, ConfirmationTarget, LowerBoundedFeeEstimator, fee_for_weight};
5555use crate::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, LATENCY_GRACE_PERIOD_BLOCKS};
@@ -4856,7 +4856,7 @@ trait FailHTLCContents {
48564856impl FailHTLCContents for msgs::OnionErrorPacket {
48574857 type Message = msgs::UpdateFailHTLC;
48584858 fn to_message(self, htlc_id: u64, channel_id: ChannelId) -> Self::Message {
4859- msgs::UpdateFailHTLC { htlc_id, channel_id, reason: self }
4859+ msgs::UpdateFailHTLC { htlc_id, channel_id, reason: self.data }
48604860 }
48614861 fn to_inbound_htlc_state(self) -> InboundHTLCState {
48624862 InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailRelay(self))
@@ -6070,7 +6070,7 @@ impl<SP: Deref> FundedChannel<SP> where
60706070 require_commitment = true;
60716071 match fail_msg {
60726072 HTLCFailureMsg::Relay(msg) => {
6073- htlc.state = InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailRelay(msg.reason.clone ()));
6073+ htlc.state = InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailRelay((& msg).into ()));
60746074 update_fail_htlcs.push(msg)
60756075 },
60766076 HTLCFailureMsg::Malformed(msg) => {
@@ -6778,7 +6778,7 @@ impl<SP: Deref> FundedChannel<SP> where
67786778 update_fail_htlcs.push(msgs::UpdateFailHTLC {
67796779 channel_id: self.context.channel_id(),
67806780 htlc_id: htlc.htlc_id,
6781- reason: err_packet.clone()
6781+ reason: err_packet.data. clone(),
67826782 });
67836783 },
67846784 &InboundHTLCRemovalReason::FailMalformed((ref sha256_of_onion, ref failure_code)) => {
@@ -9932,11 +9932,6 @@ fn get_initial_channel_type(config: &UserConfig, their_features: &InitFeatures)
99329932const SERIALIZATION_VERSION: u8 = 4;
99339933const MIN_SERIALIZATION_VERSION: u8 = 4;
99349934
9935- impl_writeable_tlv_based_enum_legacy!(InboundHTLCRemovalReason,;
9936- (0, FailRelay),
9937- (1, FailMalformed),
9938- (2, Fulfill),
9939- );
99409935
99419936impl Writeable for ChannelUpdateStatus {
99429937 fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
@@ -10066,7 +10061,20 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1006610061 },
1006710062 &InboundHTLCState::LocalRemoved(ref removal_reason) => {
1006810063 4u8.write(writer)?;
10069- removal_reason.write(writer)?;
10064+ match removal_reason {
10065+ InboundHTLCRemovalReason::FailRelay(msgs::OnionErrorPacket { data }) => {
10066+ 0u8.write(writer)?;
10067+ data.write(writer)?;
10068+ },
10069+ InboundHTLCRemovalReason::FailMalformed((hash, code)) => {
10070+ 1u8.write(writer)?;
10071+ (hash, code).write(writer)?;
10072+ },
10073+ InboundHTLCRemovalReason::Fulfill(preimage) => {
10074+ 2u8.write(writer)?;
10075+ preimage.write(writer)?;
10076+ },
10077+ }
1007010078 },
1007110079 }
1007210080 }
@@ -10145,7 +10153,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1014510153 &HTLCUpdateAwaitingACK::FailHTLC { ref htlc_id, ref err_packet } => {
1014610154 2u8.write(writer)?;
1014710155 htlc_id.write(writer)?;
10148- err_packet.write(writer)?;
10156+ err_packet.data. write(writer)?;
1014910157 }
1015010158 &HTLCUpdateAwaitingACK::FailMalformedHTLC {
1015110159 htlc_id, failure_code, sha256_of_onion
@@ -10154,10 +10162,9 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1015410162 // `::FailHTLC` variant and write the real malformed error as an optional TLV.
1015510163 malformed_htlcs.push((htlc_id, failure_code, sha256_of_onion));
1015610164
10157- let dummy_err_packet = msgs::OnionErrorPacket { data: Vec::new() };
1015810165 2u8.write(writer)?;
1015910166 htlc_id.write(writer)?;
10160- dummy_err_packet .write(writer)?;
10167+ Vec::<u8>::new() .write(writer)?;
1016110168 }
1016210169 }
1016310170 }
@@ -10403,7 +10410,17 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1040310410 InboundHTLCState::AwaitingAnnouncedRemoteRevoke(resolution)
1040410411 },
1040510412 3 => InboundHTLCState::Committed,
10406- 4 => InboundHTLCState::LocalRemoved(Readable::read(reader)?),
10413+ 4 => {
10414+ let reason = match <u8 as Readable>::read(reader)? {
10415+ 0 => InboundHTLCRemovalReason::FailRelay(msgs::OnionErrorPacket {
10416+ data: Readable::read(reader)?,
10417+ }),
10418+ 1 => InboundHTLCRemovalReason::FailMalformed(Readable::read(reader)?),
10419+ 2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?),
10420+ _ => return Err(DecodeError::InvalidValue),
10421+ };
10422+ InboundHTLCState::LocalRemoved(reason)
10423+ },
1040710424 _ => return Err(DecodeError::InvalidValue),
1040810425 },
1040910426 });
@@ -10459,7 +10476,9 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1045910476 },
1046010477 2 => HTLCUpdateAwaitingACK::FailHTLC {
1046110478 htlc_id: Readable::read(reader)?,
10462- err_packet: Readable::read(reader)?,
10479+ err_packet: OnionErrorPacket {
10480+ data: Readable::read(reader)?,
10481+ },
1046310482 },
1046410483 _ => return Err(DecodeError::InvalidValue),
1046510484 });
0 commit comments