@@ -397,10 +397,12 @@ pub(super) enum RAACommitmentOrder {
397
397
// Note this is only exposed in cfg(test):
398
398
pub ( super ) struct ChannelHolder < Signer : Sign > {
399
399
pub ( super ) by_id : HashMap < [ u8 ; 32 ] , Channel < Signer > > ,
400
- /// SCIDs (and outbound SCID aliases) to the real channel id. Outbound SCID aliases are added
401
- /// here once the channel is available for normal use, with SCIDs being added once the funding
402
- /// transaction is confirmed at the channel's required confirmation depth.
403
- pub ( super ) short_to_id : HashMap < u64 , [ u8 ; 32 ] > ,
400
+ /// SCIDs (and outbound SCID aliases) -> `counterparty_node_id`s and `channel_id`s.
401
+ ///
402
+ /// Outbound SCID aliases are added here once the channel is available for normal use, with
403
+ /// SCIDs being added once the funding transaction is confirmed at the channel's required
404
+ /// confirmation depth.
405
+ pub ( super ) short_to_id : HashMap < u64 , ( PublicKey , [ u8 ; 32 ] ) > ,
404
406
/// SCID/SCID Alias -> forward infos. Key of 0 means payments received.
405
407
///
406
408
/// Note that because we may have an SCID Alias as the key we can have two entries per channel,
@@ -1406,12 +1408,12 @@ macro_rules! send_channel_ready {
1406
1408
} ) ;
1407
1409
// Note that we may send a `channel_ready` multiple times for a channel if we reconnect, so
1408
1410
// we allow collisions, but we shouldn't ever be updating the channel ID pointed to.
1409
- let outbound_alias_insert = $short_to_id. insert( $channel. outbound_scid_alias( ) , $channel. channel_id( ) ) ;
1410
- assert!( outbound_alias_insert. is_none( ) || outbound_alias_insert. unwrap( ) == $channel. channel_id( ) ,
1411
+ let outbound_alias_insert = $short_to_id. insert( $channel. outbound_scid_alias( ) , ( $channel. get_counterparty_node_id ( ) , $channel . channel_id( ) ) ) ;
1412
+ assert!( outbound_alias_insert. is_none( ) || outbound_alias_insert. unwrap( ) == ( $channel. get_counterparty_node_id ( ) , $channel . channel_id( ) ) ,
1411
1413
"SCIDs should never collide - ensure you weren't behind the chain tip by a full month when creating channels" ) ;
1412
1414
if let Some ( real_scid) = $channel. get_short_channel_id( ) {
1413
- let scid_insert = $short_to_id. insert( real_scid, $channel. channel_id( ) ) ;
1414
- assert!( scid_insert. is_none( ) || scid_insert. unwrap( ) == $channel. channel_id( ) ,
1415
+ let scid_insert = $short_to_id. insert( real_scid, ( $channel. get_counterparty_node_id ( ) , $channel . channel_id( ) ) ) ;
1416
+ assert!( scid_insert. is_none( ) || scid_insert. unwrap( ) == ( $channel. get_counterparty_node_id ( ) , $channel . channel_id( ) ) ,
1415
1417
"SCIDs should never collide - ensure you weren't behind the chain tip by a full month when creating channels" ) ;
1416
1418
}
1417
1419
}
@@ -2231,7 +2233,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2231
2233
break Some ( ( "Don't have available channel for forwarding as requested." , 0x4000 | 10 , None ) ) ;
2232
2234
}
2233
2235
} ,
2234
- Some ( id ) => Some ( id . clone ( ) ) ,
2236
+ Some ( ( _cp_id , chan_id ) ) => Some ( chan_id . clone ( ) ) ,
2235
2237
} ;
2236
2238
let chan_update_opt = if let Some ( forwarding_id) = forwarding_id_opt {
2237
2239
let chan = channel_state. as_mut ( ) . unwrap ( ) . by_id . get_mut ( & forwarding_id) . unwrap ( ) ;
@@ -2414,7 +2416,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2414
2416
2415
2417
let id = match channel_lock. short_to_id . get ( & path. first ( ) . unwrap ( ) . short_channel_id ) {
2416
2418
None => return Err ( APIError :: ChannelUnavailable { err : "No channel available with first hop!" . to_owned ( ) } ) ,
2417
- Some ( id ) => id . clone ( ) ,
2419
+ Some ( ( _cp_id , chan_id ) ) => chan_id . clone ( ) ,
2418
2420
} ;
2419
2421
2420
2422
macro_rules! insert_outbound_payment {
@@ -3029,7 +3031,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3029
3031
for ( short_chan_id, mut pending_forwards) in channel_state. forward_htlcs . drain ( ) {
3030
3032
if short_chan_id != 0 {
3031
3033
let forward_chan_id = match channel_state. short_to_id . get ( & short_chan_id) {
3032
- Some ( chan_id) => chan_id. clone ( ) ,
3034
+ Some ( ( _cp_id , chan_id) ) => chan_id. clone ( ) ,
3033
3035
None => {
3034
3036
for forward_info in pending_forwards. drain ( ..) {
3035
3037
match forward_info {
@@ -3445,7 +3447,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3445
3447
self . process_background_events ( ) ;
3446
3448
}
3447
3449
3448
- 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 > ) {
3450
+ 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 > ) {
3449
3451
if !chan. is_outbound ( ) { return ( true , NotifyOption :: SkipPersist , Ok ( ( ) ) ) ; }
3450
3452
// If the feerate has decreased by less than half, don't bother
3451
3453
if new_feerate <= chan. get_feerate ( ) && new_feerate * 2 > chan. get_feerate ( ) {
@@ -4065,7 +4067,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4065
4067
//TODO: Delay the claimed_funds relaying just like we do outbound relay!
4066
4068
let channel_state = & mut * * channel_state_lock;
4067
4069
let chan_id = match channel_state. short_to_id . get ( & prev_hop. short_channel_id ) {
4068
- Some ( chan_id) => chan_id. clone ( ) ,
4070
+ Some ( ( _cp_id , chan_id) ) => chan_id. clone ( ) ,
4069
4071
None => {
4070
4072
return ClaimFundsFromHop :: PrevHopForceClosed
4071
4073
}
@@ -4987,7 +4989,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4987
4989
let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
4988
4990
let channel_state = & mut * channel_state_lock;
4989
4991
let chan_id = match channel_state. short_to_id . get ( & msg. contents . short_channel_id ) {
4990
- Some ( chan_id) => chan_id. clone ( ) ,
4992
+ Some ( ( _cp_id , chan_id) ) => chan_id. clone ( ) ,
4991
4993
None => {
4992
4994
// It's not a local channel
4993
4995
return Ok ( NotifyOption :: SkipPersist )
@@ -5769,8 +5771,8 @@ where
5769
5771
// using the real SCID at relay-time (i.e. enforce option_scid_alias
5770
5772
// then), and if the funding tx is ever un-confirmed we force-close the
5771
5773
// channel, ensuring short_to_id is always consistent.
5772
- let scid_insert = short_to_id. insert ( real_scid, channel. channel_id ( ) ) ;
5773
- assert ! ( scid_insert. is_none( ) || scid_insert. unwrap( ) == channel. channel_id( ) ,
5774
+ let scid_insert = short_to_id. insert ( real_scid, ( channel. get_counterparty_node_id ( ) , channel . channel_id ( ) ) ) ;
5775
+ assert ! ( scid_insert. is_none( ) || scid_insert. unwrap( ) == ( channel. get_counterparty_node_id ( ) , channel . channel_id( ) ) ,
5774
5776
"SCIDs should never collide - ensure you weren't behind by a full {} blocks when creating channels" ,
5775
5777
fake_scid:: MAX_SCID_BLOCKS_FROM_NOW ) ;
5776
5778
}
@@ -6814,7 +6816,7 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
6814
6816
} else {
6815
6817
log_info ! ( args. logger, "Successfully loaded channel {}" , log_bytes!( channel. channel_id( ) ) ) ;
6816
6818
if let Some ( short_channel_id) = channel. get_short_channel_id ( ) {
6817
- short_to_id. insert ( short_channel_id, channel. channel_id ( ) ) ;
6819
+ short_to_id. insert ( short_channel_id, ( channel. get_counterparty_node_id ( ) , channel . channel_id ( ) ) ) ;
6818
6820
}
6819
6821
by_id. insert ( channel. channel_id ( ) , channel) ;
6820
6822
}
@@ -7073,7 +7075,7 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
7073
7075
return Err ( DecodeError :: InvalidValue ) ;
7074
7076
}
7075
7077
if chan. is_usable ( ) {
7076
- if short_to_id. insert ( chan. outbound_scid_alias ( ) , * chan_id) . is_some ( ) {
7078
+ if short_to_id. insert ( chan. outbound_scid_alias ( ) , ( chan . get_counterparty_node_id ( ) , * chan_id) ) . is_some ( ) {
7077
7079
// Note that in rare cases its possible to hit this while reading an older
7078
7080
// channel if we just happened to pick a colliding outbound alias above.
7079
7081
log_error ! ( args. logger, "Got duplicate outbound SCID alias; {}" , chan. outbound_scid_alias( ) ) ;
0 commit comments