Skip to content

Commit eac86fa

Browse files
committed
Dervice counterparty_node_id from more places
1 parent b611687 commit eac86fa

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2912,7 +2912,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
29122912
phantom_shared_secret: $phantom_ss,
29132913
});
29142914
failed_forwards.push((htlc_source, payment_hash,
2915-
HTLCFailReason::Reason { failure_code: $err_code, data: $err_data }
2915+
HTLCFailReason::Reason { failure_code: $err_code, data: $err_data },
2916+
None
29162917
));
29172918
continue;
29182919
}
@@ -2991,7 +2992,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
29912992
}
29922993
let (failure_code, data) = self.get_htlc_temp_fail_err_and_data(0x1000|7, short_chan_id, chan.get());
29932994
failed_forwards.push((htlc_source, payment_hash,
2994-
HTLCFailReason::Reason { failure_code, data }
2995+
HTLCFailReason::Reason { failure_code, data },
2996+
Some(chan.get().get_counterparty_node_id())
29952997
));
29962998
continue;
29972999
},
@@ -3133,7 +3135,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
31333135
incoming_packet_shared_secret: $htlc.prev_hop.incoming_packet_shared_secret,
31343136
phantom_shared_secret,
31353137
}), payment_hash,
3136-
HTLCFailReason::Reason { failure_code: 0x4000 | 15, data: htlc_msat_height_data }
3138+
HTLCFailReason::Reason { failure_code: 0x4000 | 15, data: htlc_msat_height_data },
3139+
None
31373140
));
31383141
}
31393142
}
@@ -3261,8 +3264,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
32613264
}
32623265
}
32633266

3264-
for (htlc_source, payment_hash, failure_reason) in failed_forwards.drain(..) {
3265-
self.fail_htlc_backwards_internal(self.channel_state.lock().unwrap(), htlc_source, &payment_hash, failure_reason, Some(self.get_our_node_id()));
3267+
for (htlc_source, payment_hash, failure_reason, node_id) in failed_forwards.drain(..) {
3268+
self.fail_htlc_backwards_internal(self.channel_state.lock().unwrap(), htlc_source, &payment_hash, failure_reason, node_id);
32663269
}
32673270
self.forward_htlcs(&mut phantom_receives);
32683271

@@ -3576,8 +3579,16 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
35763579
hash_map::Entry::Vacant(_) => (0x4000|10, Vec::new())
35773580
};
35783581
let channel_state = self.channel_state.lock().unwrap();
3579-
self.fail_htlc_backwards_internal(channel_state,
3580-
htlc_src, &payment_hash, HTLCFailReason::Reason { failure_code, data: onion_failure_data}, Some(self.get_our_node_id()));
3582+
3583+
match channel_state.by_id.get(&channel_id) {
3584+
Some(channel) => {
3585+
let node_id = channel.get_counterparty_node_id().clone();
3586+
self.fail_htlc_backwards_internal(channel_state,
3587+
htlc_src, &payment_hash, HTLCFailReason::Reason { failure_code, data: onion_failure_data }, Some(node_id))
3588+
},
3589+
None => self.fail_htlc_backwards_internal(channel_state,
3590+
htlc_src, &payment_hash, HTLCFailReason::Reason { failure_code, data: onion_failure_data }, None)
3591+
}
35813592
},
35823593
HTLCSource::OutboundRoute { session_priv, payment_id, path, payment_params, .. } => {
35833594
let mut session_priv_bytes = [0; 32];
@@ -4086,6 +4097,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
40864097
return;
40874098
}
40884099

4100+
let counterparty_node_id = channel.get().get_counterparty_node_id();
40894101
let updates = channel.get_mut().monitor_updating_restored(&self.logger, self.get_our_node_id(), self.genesis_hash, self.best_block.read().unwrap().height());
40904102
let channel_update = if updates.funding_locked.is_some() && channel.get().is_usable() {
40914103
// We only send a channel_update in the case where we are just now sending a
@@ -4104,12 +4116,14 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
41044116
if let Some(upd) = channel_update {
41054117
channel_state.pending_msg_events.push(upd);
41064118
}
4107-
(updates.failed_htlcs, updates.finalized_claimed_htlcs)
4119+
4120+
let failed_htlcs_with_chan_id: Vec<(HTLCSource, PaymentHash, HTLCFailReason, PublicKey)> = updates.failed_htlcs.into_iter().map(|h| (h.0, h.1, h.2, counterparty_node_id)).collect();
4121+
(failed_htlcs_with_chan_id, updates.finalized_claimed_htlcs)
41084122
};
41094123
post_handle_chan_restoration!(self, chan_restoration_res);
41104124
self.finalize_claims(finalized_claims);
41114125
for failure in pending_failures.drain(..) {
4112-
self.fail_htlc_backwards_internal(self.channel_state.lock().unwrap(), failure.0, &failure.1, failure.2, Some(self.get_our_node_id()));
4126+
self.fail_htlc_backwards_internal(self.channel_state.lock().unwrap(), failure.0, &failure.1, failure.2, Some(failure.3));
41134127
}
41144128
}
41154129

0 commit comments

Comments
 (0)