X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fchannelmanager.rs;h=44ad0a16037adda6b2775e0434b0539e6d0de760;hb=555cb4024fde76ed2bea0466289ae45c8904b395;hp=f27ca53bcf07a3c42334ee0b8cec05e681cdfc34;hpb=7809c5515c0bd7e3ae7a79c7634dd578b75d4386;p=rust-lightning diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index f27ca53b..44ad0a16 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -287,6 +287,16 @@ pub(super) enum HTLCFailReason { } } +impl HTLCFailReason { + pub(super) fn reason(failure_code: u16, data: Vec) -> Self { + Self::Reason { failure_code, data } + } + + pub(super) fn from_failure_code(failure_code: u16) -> Self { + Self::Reason { failure_code, data: Vec::new() } + } +} + struct ReceiveError { err_code: u16, err_data: Vec, @@ -1877,7 +1887,7 @@ impl ChannelManager ChannelManager ChannelManager chan.get_short_channel_id().unwrap_or(chan.outbound_scid_alias()), + Some(chan) => { + if !chan.is_usable() { + return Err(APIError::APIMisuseError { + err: format!("Channel with id {:?} not fully established", next_hop_channel_id) + }) + } + chan.get_short_channel_id().unwrap_or(chan.outbound_scid_alias()) + }, None => return Err(APIError::APIMisuseError { err: format!("Channel with id {:?} not found", next_hop_channel_id) }) @@ -3133,7 +3150,7 @@ impl ChannelManager ChannelManager ChannelManager ChannelManager ChannelManager ChannelManager ChannelManager ChannelManager ChannelManager ChannelManager return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id)) @@ -5233,7 +5250,7 @@ impl ChannelManager ChannelManager= htlc.cltv_expiry - HTLC_FAIL_BACK_BUFFER { let mut htlc_msat_height_data = byte_utils::be64_to_array(htlc.value).to_vec(); htlc_msat_height_data.extend_from_slice(&byte_utils::be32_to_array(height)); - timed_out_htlcs.push((HTLCSource::PreviousHopData(htlc.prev_hop.clone()), payment_hash.clone(), HTLCFailReason::Reason { - failure_code: 0x4000 | 15, - data: htlc_msat_height_data - }, HTLCDestination::FailedPayment { payment_hash: payment_hash.clone() })); + + timed_out_htlcs.push((HTLCSource::PreviousHopData(htlc.prev_hop.clone()), payment_hash.clone(), + HTLCFailReason::reason(0x4000 | 15, htlc_msat_height_data), + HTLCDestination::FailedPayment { payment_hash: payment_hash.clone() })); false } else { true } }); @@ -6288,7 +6304,7 @@ where _ => unreachable!(), }; timed_out_htlcs.push((prev_hop_data, htlc.forward_info.payment_hash, - HTLCFailReason::Reason { failure_code: 0x2000 | 2, data: Vec::new() }, + HTLCFailReason::from_failure_code(0x2000 | 2), HTLCDestination::InvalidForward { requested_forward_scid })); log_trace!(self.logger, "Timing out intercepted HTLC with requested forward scid {}", requested_forward_scid); false @@ -7786,7 +7802,7 @@ impl<'a, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> for htlc_source in failed_htlcs.drain(..) { let (source, payment_hash, counterparty_node_id, channel_id) = htlc_source; let receiver = HTLCDestination::NextHopChannel { node_id: Some(counterparty_node_id), channel_id }; - channel_manager.fail_htlc_backwards_internal(source, &payment_hash, HTLCFailReason::Reason { failure_code: 0x4000 | 8, data: Vec::new() }, receiver); + channel_manager.fail_htlc_backwards_internal(source, &payment_hash, HTLCFailReason::from_failure_code(0x4000 | 8), receiver); } //TODO: Broadcast channel update for closed channels, but only after we've made a