@@ -695,6 +695,13 @@ pub(super) struct Channel<Signer: Sign> {
695
695
696
696
/// This channel's type, as negotiated during channel open
697
697
channel_type : ChannelTypeFeatures ,
698
+
699
+ // Our counerparty can offer us SCID aliases which they will map to this channel when routing
700
+ // outbound payments. These can be used in invoice route hints to provide privacy of which
701
+ // on-chain transaction is ours.
702
+ // We only bother storing the most recent SCID alias at any time, though our counterparty has
703
+ // to store all of them.
704
+ latest_inbound_scid_alias : Option < u64 > ,
698
705
}
699
706
700
707
#[ cfg( any( test, feature = "fuzztarget" ) ) ]
@@ -947,6 +954,8 @@ impl<Signer: Sign> Channel<Signer> {
947
954
948
955
workaround_lnd_bug_4006 : None ,
949
956
957
+ latest_inbound_scid_alias : None ,
958
+
950
959
#[ cfg( any( test, feature = "fuzztarget" ) ) ]
951
960
historical_inbound_htlc_fulfills : HashSet :: new ( ) ,
952
961
@@ -1252,6 +1261,8 @@ impl<Signer: Sign> Channel<Signer> {
1252
1261
1253
1262
workaround_lnd_bug_4006 : None ,
1254
1263
1264
+ latest_inbound_scid_alias : None ,
1265
+
1255
1266
#[ cfg( any( test, feature = "fuzztarget" ) ) ]
1256
1267
historical_inbound_htlc_fulfills : HashSet :: new ( ) ,
1257
1268
@@ -2141,6 +2152,15 @@ impl<Signer: Sign> Channel<Signer> {
2141
2152
return Err ( ChannelError :: Ignore ( "Peer sent funding_locked when we needed a channel_reestablish. The peer is likely lnd, see https://github.com/lightningnetwork/lnd/issues/4006" . to_owned ( ) ) ) ;
2142
2153
}
2143
2154
2155
+ if let Some ( scid_alias) = msg. short_channel_id_alias {
2156
+ if Some ( scid_alias) != self . short_channel_id {
2157
+ // The scid alias provided can be used to route payments *from* our counterparty,
2158
+ // i.e. can be used for inbound payments and provided in invoices, but is not used
2159
+ // whrn routing outbound payments.
2160
+ self . latest_inbound_scid_alias = Some ( scid_alias) ;
2161
+ }
2162
+ }
2163
+
2144
2164
let non_shutdown_state = self . channel_state & ( !MULTI_STATE_FLAGS ) ;
2145
2165
2146
2166
if non_shutdown_state == ChannelState :: FundingSent as u32 {
@@ -4188,6 +4208,11 @@ impl<Signer: Sign> Channel<Signer> {
4188
4208
self . short_channel_id
4189
4209
}
4190
4210
4211
+ /// Allowed in any state (including after shutdown)
4212
+ pub fn get_latest_inbound_scid_alias ( & self ) -> Option < u64 > {
4213
+ self . latest_inbound_scid_alias
4214
+ }
4215
+
4191
4216
/// Returns the funding_txo we either got from our peer, or were given by
4192
4217
/// get_outbound_funding_created.
4193
4218
pub fn get_funding_txo ( & self ) -> Option < OutPoint > {
@@ -5758,6 +5783,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
5758
5783
( 13 , self . channel_creation_height, required) ,
5759
5784
( 15 , preimages, vec_type) ,
5760
5785
( 17 , self . announcement_sigs_state, required) ,
5786
+ ( 19 , self . latest_inbound_scid_alias, option) ,
5761
5787
} ) ;
5762
5788
5763
5789
Ok ( ( ) )
@@ -6013,6 +6039,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
6013
6039
// If we read an old Channel, for simplicity we just treat it as "we never sent an
6014
6040
// AnnouncementSignatures" which implies we'll re-send it on reconnect, but that's fine.
6015
6041
let mut announcement_sigs_state = Some ( AnnouncementSigsState :: NotSent ) ;
6042
+ let mut latest_inbound_scid_alias = None ;
6016
6043
6017
6044
read_tlv_fields ! ( reader, {
6018
6045
( 0 , announcement_sigs, option) ,
@@ -6028,6 +6055,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
6028
6055
( 13 , channel_creation_height, option) ,
6029
6056
( 15 , preimages_opt, vec_type) ,
6030
6057
( 17 , announcement_sigs_state, option) ,
6058
+ ( 19 , latest_inbound_scid_alias, option) ,
6031
6059
} ) ;
6032
6060
6033
6061
if let Some ( preimages) = preimages_opt {
@@ -6162,6 +6190,8 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
6162
6190
6163
6191
workaround_lnd_bug_4006 : None ,
6164
6192
6193
+ latest_inbound_scid_alias,
6194
+
6165
6195
#[ cfg( any( test, feature = "fuzztarget" ) ) ]
6166
6196
historical_inbound_htlc_fulfills,
6167
6197
0 commit comments