Skip to content

Commit aeca180

Browse files
Add counterparty_node_id to short_to_id map
1 parent 0b77008 commit aeca180

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ pub(super) struct ChannelHolder<Signer: Sign> {
408408
/// SCIDs (and outbound SCID aliases) to the real channel id. Outbound SCID aliases are added
409409
/// here once the channel is available for normal use, with SCIDs being added once the funding
410410
/// transaction is confirmed at the channel's required confirmation depth.
411-
pub(super) short_to_id: HashMap<u64, [u8; 32]>,
411+
pub(super) short_to_id: HashMap<u64, (PublicKey, [u8; 32])>,
412412
/// SCID/SCID Alias -> forward infos. Key of 0 means payments received.
413413
///
414414
/// Note that because we may have an SCID Alias as the key we can have two entries per channel,
@@ -1411,12 +1411,12 @@ macro_rules! send_channel_ready {
14111411
});
14121412
// Note that we may send a `channel_ready` multiple times for a channel if we reconnect, so
14131413
// we allow collisions, but we shouldn't ever be updating the channel ID pointed to.
1414-
let outbound_alias_insert = $short_to_id.insert($channel.outbound_scid_alias(), $channel.channel_id());
1415-
assert!(outbound_alias_insert.is_none() || outbound_alias_insert.unwrap() == $channel.channel_id(),
1414+
let outbound_alias_insert = $short_to_id.insert($channel.outbound_scid_alias(), ($channel.get_counterparty_node_id(), $channel.channel_id()));
1415+
assert!(outbound_alias_insert.is_none() || outbound_alias_insert.unwrap() == ($channel.get_counterparty_node_id(), $channel.channel_id()),
14161416
"SCIDs should never collide - ensure you weren't behind the chain tip by a full month when creating channels");
14171417
if let Some(real_scid) = $channel.get_short_channel_id() {
1418-
let scid_insert = $short_to_id.insert(real_scid, $channel.channel_id());
1419-
assert!(scid_insert.is_none() || scid_insert.unwrap() == $channel.channel_id(),
1418+
let scid_insert = $short_to_id.insert(real_scid, ($channel.get_counterparty_node_id(), $channel.channel_id()));
1419+
assert!(scid_insert.is_none() || scid_insert.unwrap() == ($channel.get_counterparty_node_id(), $channel.channel_id()),
14201420
"SCIDs should never collide - ensure you weren't behind the chain tip by a full month when creating channels");
14211421
}
14221422
}
@@ -2220,7 +2220,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
22202220
break Some(("Don't have available channel for forwarding as requested.", 0x4000 | 10, None));
22212221
}
22222222
},
2223-
Some(id) => Some(id.clone()),
2223+
Some((_cp_id, id)) => Some(id.clone()),
22242224
};
22252225
let (chan_update_opt, forwardee_cltv_expiry_delta) = if let Some(forwarding_id) = forwarding_id_opt {
22262226
let chan = channel_state.as_mut().unwrap().by_id.get_mut(&forwarding_id).unwrap();
@@ -2401,7 +2401,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
24012401

24022402
let id = match channel_lock.short_to_id.get(&path.first().unwrap().short_channel_id) {
24032403
None => return Err(APIError::ChannelUnavailable{err: "No channel available with first hop!".to_owned()}),
2404-
Some(id) => id.clone(),
2404+
Some((_cp_id, id)) => id.clone(),
24052405
};
24062406

24072407
macro_rules! insert_outbound_payment {
@@ -2935,7 +2935,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
29352935
for (short_chan_id, mut pending_forwards) in channel_state.forward_htlcs.drain() {
29362936
if short_chan_id != 0 {
29372937
let forward_chan_id = match channel_state.short_to_id.get(&short_chan_id) {
2938-
Some(chan_id) => chan_id.clone(),
2938+
Some((_cp_id, chan_id)) => chan_id.clone(),
29392939
None => {
29402940
for forward_info in pending_forwards.drain(..) {
29412941
match forward_info {
@@ -3352,7 +3352,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
33523352
self.process_background_events();
33533353
}
33543354

3355-
fn update_channel_fee(&self, short_to_id: &mut HashMap<u64, [u8; 32]>, pending_msg_events: &mut Vec<events::MessageSendEvent>, chan_id: &[u8; 32], chan: &mut Channel<Signer>, new_feerate: u32) -> (bool, NotifyOption, Result<(), MsgHandleErrInternal>) {
3355+
fn update_channel_fee(&self, short_to_id: &mut HashMap<u64, (PublicKey, [u8; 32])>, pending_msg_events: &mut Vec<events::MessageSendEvent>, chan_id: &[u8; 32], chan: &mut Channel<Signer>, new_feerate: u32) -> (bool, NotifyOption, Result<(), MsgHandleErrInternal>) {
33563356
if !chan.is_outbound() { return (true, NotifyOption::SkipPersist, Ok(())); }
33573357
// If the feerate has decreased by less than half, don't bother
33583358
if new_feerate <= chan.get_feerate() && new_feerate * 2 > chan.get_feerate() {
@@ -3965,7 +3965,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
39653965
//TODO: Delay the claimed_funds relaying just like we do outbound relay!
39663966
let channel_state = &mut **channel_state_lock;
39673967
let chan_id = match channel_state.short_to_id.get(&prev_hop.short_channel_id) {
3968-
Some(chan_id) => chan_id.clone(),
3968+
Some((_cp_id, chan_id)) => chan_id.clone(),
39693969
None => {
39703970
return ClaimFundsFromHop::PrevHopForceClosed
39713971
}
@@ -4867,7 +4867,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
48674867
let mut channel_state_lock = self.channel_state.lock().unwrap();
48684868
let channel_state = &mut *channel_state_lock;
48694869
let chan_id = match channel_state.short_to_id.get(&msg.contents.short_channel_id) {
4870-
Some(chan_id) => chan_id.clone(),
4870+
Some((_cp_id, chan_id)) => chan_id.clone(),
48714871
None => {
48724872
// It's not a local channel
48734873
return Ok(NotifyOption::SkipPersist)
@@ -6689,7 +6689,7 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
66896689
} else {
66906690
log_info!(args.logger, "Successfully loaded channel {}", log_bytes!(channel.channel_id()));
66916691
if let Some(short_channel_id) = channel.get_short_channel_id() {
6692-
short_to_id.insert(short_channel_id, channel.channel_id());
6692+
short_to_id.insert(short_channel_id, (channel.get_counterparty_node_id(), channel.channel_id()));
66936693
}
66946694
by_id.insert(channel.channel_id(), channel);
66956695
}
@@ -6948,7 +6948,7 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
69486948
return Err(DecodeError::InvalidValue);
69496949
}
69506950
if chan.is_usable() {
6951-
if short_to_id.insert(chan.outbound_scid_alias(), *chan_id).is_some() {
6951+
if short_to_id.insert(chan.outbound_scid_alias(), (chan.get_counterparty_node_id(), *chan_id)).is_some() {
69526952
// Note that in rare cases its possible to hit this while reading an older
69536953
// channel if we just happened to pick a colliding outbound alias above.
69546954
log_error!(args.logger, "Got duplicate outbound SCID alias; {}", chan.outbound_scid_alias());

0 commit comments

Comments
 (0)