@@ -397,10 +397,12 @@ pub(super) enum RAACommitmentOrder {
397397// Note this is only exposed in cfg(test):
398398pub ( super ) struct ChannelHolder < Signer : Sign > {
399399 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 ] ) > ,
404406 /// SCID/SCID Alias -> forward infos. Key of 0 means payments received.
405407 ///
406408 /// 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 {
14061408 } ) ;
14071409 // Note that we may send a `channel_ready` multiple times for a channel if we reconnect, so
14081410 // 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( ) ) ,
14111413 "SCIDs should never collide - ensure you weren't behind the chain tip by a full month when creating channels" ) ;
14121414 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( ) ) ,
14151417 "SCIDs should never collide - ensure you weren't behind the chain tip by a full month when creating channels" ) ;
14161418 }
14171419 }
@@ -2231,7 +2233,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
22312233 break Some ( ( "Don't have available channel for forwarding as requested." , 0x4000 | 10 , None ) ) ;
22322234 }
22332235 } ,
2234- Some ( id ) => Some ( id . clone ( ) ) ,
2236+ Some ( ( _cp_id , chan_id ) ) => Some ( chan_id . clone ( ) ) ,
22352237 } ;
22362238 let chan_update_opt = if let Some ( forwarding_id) = forwarding_id_opt {
22372239 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
24142416
24152417 let id = match channel_lock. short_to_id . get ( & path. first ( ) . unwrap ( ) . short_channel_id ) {
24162418 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 ( ) ,
24182420 } ;
24192421
24202422 macro_rules! insert_outbound_payment {
@@ -3029,7 +3031,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
30293031 for ( short_chan_id, mut pending_forwards) in channel_state. forward_htlcs . drain ( ) {
30303032 if short_chan_id != 0 {
30313033 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 ( ) ,
30333035 None => {
30343036 for forward_info in pending_forwards. drain ( ..) {
30353037 match forward_info {
@@ -3445,7 +3447,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
34453447 self . process_background_events ( ) ;
34463448 }
34473449
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 > ) {
34493451 if !chan. is_outbound ( ) { return ( true , NotifyOption :: SkipPersist , Ok ( ( ) ) ) ; }
34503452 // If the feerate has decreased by less than half, don't bother
34513453 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
40654067 //TODO: Delay the claimed_funds relaying just like we do outbound relay!
40664068 let channel_state = & mut * * channel_state_lock;
40674069 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 ( ) ,
40694071 None => {
40704072 return ClaimFundsFromHop :: PrevHopForceClosed
40714073 }
@@ -4987,7 +4989,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
49874989 let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
49884990 let channel_state = & mut * channel_state_lock;
49894991 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 ( ) ,
49914993 None => {
49924994 // It's not a local channel
49934995 return Ok ( NotifyOption :: SkipPersist )
@@ -5769,8 +5771,8 @@ where
57695771 // using the real SCID at relay-time (i.e. enforce option_scid_alias
57705772 // then), and if the funding tx is ever un-confirmed we force-close the
57715773 // 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( ) ) ,
57745776 "SCIDs should never collide - ensure you weren't behind by a full {} blocks when creating channels" ,
57755777 fake_scid:: MAX_SCID_BLOCKS_FROM_NOW ) ;
57765778 }
@@ -6814,7 +6816,7 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
68146816 } else {
68156817 log_info ! ( args. logger, "Successfully loaded channel {}" , log_bytes!( channel. channel_id( ) ) ) ;
68166818 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 ( ) ) ) ;
68186820 }
68196821 by_id. insert ( channel. channel_id ( ) , channel) ;
68206822 }
@@ -7073,7 +7075,7 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
70737075 return Err ( DecodeError :: InvalidValue ) ;
70747076 }
70757077 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 ( ) {
70777079 // Note that in rare cases its possible to hit this while reading an older
70787080 // channel if we just happened to pick a colliding outbound alias above.
70797081 log_error ! ( args. logger, "Got duplicate outbound SCID alias; {}" , chan. outbound_scid_alias( ) ) ;
0 commit comments