@@ -4936,7 +4936,7 @@ where
49364936 self.pending_outbound_payments.finalize_claims(sources, &self.pending_events);
49374937 }
49384938
4939- fn claim_funds_internal(&self, source: HTLCSource, payment_preimage: PaymentPreimage, forwarded_htlc_value_msat: Option<u64>, from_onchain: bool, next_channel_id: [u8; 32] ) {
4939+ fn claim_funds_internal(&self, source: HTLCSource, payment_preimage: PaymentPreimage, forwarded_htlc_value_msat: Option<u64>, from_onchain: bool, next_channel_outpoint: OutPoint ) {
49404940 match source {
49414941 HTLCSource::OutboundRoute { session_priv, payment_id, path, .. } => {
49424942 debug_assert!(self.background_events_processed_since_startup.load(Ordering::Acquire),
@@ -4957,7 +4957,7 @@ where
49574957 fee_earned_msat,
49584958 claim_from_onchain_tx: from_onchain,
49594959 prev_channel_id: Some(prev_outpoint.to_channel_id()),
4960- next_channel_id: Some(next_channel_id ),
4960+ next_channel_id: Some(next_channel_outpoint.to_channel_id() ),
49614961 outbound_amount_forwarded_msat: forwarded_htlc_value_msat,
49624962 },
49634963 downstream_counterparty_and_funding_outpoint: None,
@@ -5712,6 +5712,7 @@ where
57125712 }
57135713
57145714 fn internal_update_fulfill_htlc(&self, counterparty_node_id: &PublicKey, msg: &msgs::UpdateFulfillHTLC) -> Result<(), MsgHandleErrInternal> {
5715+ let funding_txo;
57155716 let (htlc_source, forwarded_htlc_value) = {
57165717 let per_peer_state = self.per_peer_state.read().unwrap();
57175718 let peer_state_mutex = per_peer_state.get(counterparty_node_id)
@@ -5723,12 +5724,14 @@ where
57235724 let peer_state = &mut *peer_state_lock;
57245725 match peer_state.channel_by_id.entry(msg.channel_id) {
57255726 hash_map::Entry::Occupied(mut chan) => {
5726- try_chan_entry!(self, chan.get_mut().update_fulfill_htlc(&msg), chan)
5727+ let res = try_chan_entry!(self, chan.get_mut().update_fulfill_htlc(&msg), chan);
5728+ funding_txo = chan.get().context.get_funding_txo().expect("We won't accept a fulfill until funded");
5729+ res
57275730 },
57285731 hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close(format!("Got a message for a channel from the wrong node! No such channel for the passed counterparty_node_id {}", counterparty_node_id), msg.channel_id))
57295732 }
57305733 };
5731- self.claim_funds_internal(htlc_source, msg.payment_preimage.clone(), Some(forwarded_htlc_value), false, msg.channel_id );
5734+ self.claim_funds_internal(htlc_source, msg.payment_preimage.clone(), Some(forwarded_htlc_value), false, funding_txo );
57325735 Ok(())
57335736 }
57345737
@@ -6103,7 +6106,7 @@ where
61036106 MonitorEvent::HTLCEvent(htlc_update) => {
61046107 if let Some(preimage) = htlc_update.payment_preimage {
61056108 log_trace!(self.logger, "Claiming HTLC with preimage {} from our monitor", log_bytes!(preimage.0));
6106- self.claim_funds_internal(htlc_update.source, preimage, htlc_update.htlc_value_satoshis.map(|v| v * 1000), true, funding_outpoint.to_channel_id() );
6109+ self.claim_funds_internal(htlc_update.source, preimage, htlc_update.htlc_value_satoshis.map(|v| v * 1000), true, funding_outpoint);
61076110 } else {
61086111 log_trace!(self.logger, "Failing HTLC with hash {} from our monitor", log_bytes!(htlc_update.payment_hash.0));
61096112 let receiver = HTLCDestination::NextHopChannel { node_id: counterparty_node_id, channel_id: funding_outpoint.to_channel_id() };
@@ -8815,7 +8818,7 @@ where
88158818 // downstream chan is closed (because we don't have a
88168819 // channel_id -> peer map entry).
88178820 counterparty_opt.is_none(),
8818- monitor.get_funding_txo().0.to_channel_id() ))
8821+ monitor.get_funding_txo().0))
88198822 } else { None }
88208823 } else {
88218824 // If it was an outbound payment, we've handled it above - if a preimage
@@ -9084,12 +9087,12 @@ where
90849087 channel_manager.fail_htlc_backwards_internal(&source, &payment_hash, &reason, receiver);
90859088 }
90869089
9087- for (source, preimage, downstream_value, downstream_closed, downstream_chan_id ) in pending_claims_to_replay {
9090+ for (source, preimage, downstream_value, downstream_closed, downstream_funding ) in pending_claims_to_replay {
90889091 // We use `downstream_closed` in place of `from_onchain` here just as a guess - we
90899092 // don't remember in the `ChannelMonitor` where we got a preimage from, but if the
90909093 // channel is closed we just assume that it probably came from an on-chain claim.
90919094 channel_manager.claim_funds_internal(source, preimage, Some(downstream_value),
9092- downstream_closed, downstream_chan_id );
9095+ downstream_closed, downstream_funding );
90939096 }
90949097
90959098 //TODO: Broadcast channel update for closed channels, but only after we've made a
0 commit comments