Skip to content

Commit

Permalink
Dervice counterparty_node_id from more places
Browse files Browse the repository at this point in the history
  • Loading branch information
jurvis committed May 7, 2022
1 parent b611687 commit eac86fa
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions lightning/src/ln/channelmanager.rs
Expand Up @@ -2912,7 +2912,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
phantom_shared_secret: $phantom_ss,
});
failed_forwards.push((htlc_source, payment_hash,
HTLCFailReason::Reason { failure_code: $err_code, data: $err_data }
HTLCFailReason::Reason { failure_code: $err_code, data: $err_data },
None
));
continue;
}
Expand Down Expand Up @@ -2991,7 +2992,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
}
let (failure_code, data) = self.get_htlc_temp_fail_err_and_data(0x1000|7, short_chan_id, chan.get());
failed_forwards.push((htlc_source, payment_hash,
HTLCFailReason::Reason { failure_code, data }
HTLCFailReason::Reason { failure_code, data },
Some(chan.get().get_counterparty_node_id())
));
continue;
},
Expand Down Expand Up @@ -3133,7 +3135,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
incoming_packet_shared_secret: $htlc.prev_hop.incoming_packet_shared_secret,
phantom_shared_secret,
}), payment_hash,
HTLCFailReason::Reason { failure_code: 0x4000 | 15, data: htlc_msat_height_data }
HTLCFailReason::Reason { failure_code: 0x4000 | 15, data: htlc_msat_height_data },
None
));
}
}
Expand Down Expand Up @@ -3261,8 +3264,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
}
}

for (htlc_source, payment_hash, failure_reason) in failed_forwards.drain(..) {
self.fail_htlc_backwards_internal(self.channel_state.lock().unwrap(), htlc_source, &payment_hash, failure_reason, Some(self.get_our_node_id()));
for (htlc_source, payment_hash, failure_reason, node_id) in failed_forwards.drain(..) {
self.fail_htlc_backwards_internal(self.channel_state.lock().unwrap(), htlc_source, &payment_hash, failure_reason, node_id);
}
self.forward_htlcs(&mut phantom_receives);

Expand Down Expand Up @@ -3576,8 +3579,16 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
hash_map::Entry::Vacant(_) => (0x4000|10, Vec::new())
};
let channel_state = self.channel_state.lock().unwrap();
self.fail_htlc_backwards_internal(channel_state,
htlc_src, &payment_hash, HTLCFailReason::Reason { failure_code, data: onion_failure_data}, Some(self.get_our_node_id()));

match channel_state.by_id.get(&channel_id) {
Some(channel) => {
let node_id = channel.get_counterparty_node_id().clone();
self.fail_htlc_backwards_internal(channel_state,
htlc_src, &payment_hash, HTLCFailReason::Reason { failure_code, data: onion_failure_data }, Some(node_id))
},
None => self.fail_htlc_backwards_internal(channel_state,
htlc_src, &payment_hash, HTLCFailReason::Reason { failure_code, data: onion_failure_data }, None)
}
},
HTLCSource::OutboundRoute { session_priv, payment_id, path, payment_params, .. } => {
let mut session_priv_bytes = [0; 32];
Expand Down Expand Up @@ -4086,6 +4097,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
return;
}

let counterparty_node_id = channel.get().get_counterparty_node_id();
let updates = channel.get_mut().monitor_updating_restored(&self.logger, self.get_our_node_id(), self.genesis_hash, self.best_block.read().unwrap().height());
let channel_update = if updates.funding_locked.is_some() && channel.get().is_usable() {
// We only send a channel_update in the case where we are just now sending a
Expand All @@ -4104,12 +4116,14 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
if let Some(upd) = channel_update {
channel_state.pending_msg_events.push(upd);
}
(updates.failed_htlcs, updates.finalized_claimed_htlcs)

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();
(failed_htlcs_with_chan_id, updates.finalized_claimed_htlcs)
};
post_handle_chan_restoration!(self, chan_restoration_res);
self.finalize_claims(finalized_claims);
for failure in pending_failures.drain(..) {
self.fail_htlc_backwards_internal(self.channel_state.lock().unwrap(), failure.0, &failure.1, failure.2, Some(self.get_our_node_id()));
self.fail_htlc_backwards_internal(self.channel_state.lock().unwrap(), failure.0, &failure.1, failure.2, Some(failure.3));
}
}

Expand Down

0 comments on commit eac86fa

Please sign in to comment.