Skip to content

Commit b9189ea

Browse files
committed
Pass OutPoint, rather than channel id to claim_funds_internal
This is a trivial refactor which will be used in the next commit.
1 parent 9b13862 commit b9189ea

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

lightning/src/ln/channelmanager.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -5083,7 +5083,7 @@ where
50835083
self.pending_outbound_payments.finalize_claims(sources, &self.pending_events);
50845084
}
50855085

5086-
fn claim_funds_internal(&self, source: HTLCSource, payment_preimage: PaymentPreimage, forwarded_htlc_value_msat: Option<u64>, from_onchain: bool, next_channel_id: [u8; 32]) {
5086+
fn claim_funds_internal(&self, source: HTLCSource, payment_preimage: PaymentPreimage, forwarded_htlc_value_msat: Option<u64>, from_onchain: bool, next_channel_outpoint: OutPoint) {
50875087
match source {
50885088
HTLCSource::OutboundRoute { session_priv, payment_id, path, .. } => {
50895089
debug_assert!(self.background_events_processed_since_startup.load(Ordering::Acquire),
@@ -5104,7 +5104,7 @@ where
51045104
fee_earned_msat,
51055105
claim_from_onchain_tx: from_onchain,
51065106
prev_channel_id: Some(prev_outpoint.to_channel_id()),
5107-
next_channel_id: Some(next_channel_id),
5107+
next_channel_id: Some(next_channel_outpoint.to_channel_id()),
51085108
outbound_amount_forwarded_msat: forwarded_htlc_value_msat,
51095109
},
51105110
downstream_counterparty_and_funding_outpoint: None,
@@ -5879,6 +5879,7 @@ where
58795879
}
58805880

58815881
fn internal_update_fulfill_htlc(&self, counterparty_node_id: &PublicKey, msg: &msgs::UpdateFulfillHTLC) -> Result<(), MsgHandleErrInternal> {
5882+
let funding_txo;
58825883
let (htlc_source, forwarded_htlc_value) = {
58835884
let per_peer_state = self.per_peer_state.read().unwrap();
58845885
let peer_state_mutex = per_peer_state.get(counterparty_node_id)
@@ -5890,12 +5891,14 @@ where
58905891
let peer_state = &mut *peer_state_lock;
58915892
match peer_state.channel_by_id.entry(msg.channel_id) {
58925893
hash_map::Entry::Occupied(mut chan) => {
5893-
try_chan_entry!(self, chan.get_mut().update_fulfill_htlc(&msg), chan)
5894+
let res = try_chan_entry!(self, chan.get_mut().update_fulfill_htlc(&msg), chan);
5895+
funding_txo = chan.get().context.get_funding_txo().expect("We won't accept a fulfill until funded");
5896+
res
58945897
},
58955898
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))
58965899
}
58975900
};
5898-
self.claim_funds_internal(htlc_source, msg.payment_preimage.clone(), Some(forwarded_htlc_value), false, msg.channel_id);
5901+
self.claim_funds_internal(htlc_source, msg.payment_preimage.clone(), Some(forwarded_htlc_value), false, funding_txo);
58995902
Ok(())
59005903
}
59015904

@@ -6270,7 +6273,7 @@ where
62706273
MonitorEvent::HTLCEvent(htlc_update) => {
62716274
if let Some(preimage) = htlc_update.payment_preimage {
62726275
log_trace!(self.logger, "Claiming HTLC with preimage {} from our monitor", log_bytes!(preimage.0));
6273-
self.claim_funds_internal(htlc_update.source, preimage, htlc_update.htlc_value_satoshis.map(|v| v * 1000), true, funding_outpoint.to_channel_id());
6276+
self.claim_funds_internal(htlc_update.source, preimage, htlc_update.htlc_value_satoshis.map(|v| v * 1000), true, funding_outpoint);
62746277
} else {
62756278
log_trace!(self.logger, "Failing HTLC with hash {} from our monitor", log_bytes!(htlc_update.payment_hash.0));
62766279
let receiver = HTLCDestination::NextHopChannel { node_id: counterparty_node_id, channel_id: funding_outpoint.to_channel_id() };
@@ -8994,7 +8997,7 @@ where
89948997
// downstream chan is closed (because we don't have a
89958998
// channel_id -> peer map entry).
89968999
counterparty_opt.is_none(),
8997-
monitor.get_funding_txo().0.to_channel_id()))
9000+
monitor.get_funding_txo().0))
89989001
} else { None }
89999002
} else {
90009003
// If it was an outbound payment, we've handled it above - if a preimage
@@ -9263,12 +9266,12 @@ where
92639266
channel_manager.fail_htlc_backwards_internal(&source, &payment_hash, &reason, receiver);
92649267
}
92659268

9266-
for (source, preimage, downstream_value, downstream_closed, downstream_chan_id) in pending_claims_to_replay {
9269+
for (source, preimage, downstream_value, downstream_closed, downstream_funding) in pending_claims_to_replay {
92679270
// We use `downstream_closed` in place of `from_onchain` here just as a guess - we
92689271
// don't remember in the `ChannelMonitor` where we got a preimage from, but if the
92699272
// channel is closed we just assume that it probably came from an on-chain claim.
92709273
channel_manager.claim_funds_internal(source, preimage, Some(downstream_value),
9271-
downstream_closed, downstream_chan_id);
9274+
downstream_closed, downstream_funding);
92729275
}
92739276

92749277
//TODO: Broadcast channel update for closed channels, but only after we've made a

0 commit comments

Comments
 (0)