@@ -814,43 +814,28 @@ struct channel *any_channel_by_scid(struct lightningd *ld,
814814 struct short_channel_id scid ,
815815 bool privacy_leak_ok )
816816{
817- struct peer * p ;
818- struct channel * chan ;
819- struct peer_node_id_map_iter it ;
820-
821- /* FIXME: Support lookup by scid directly! */
822- for (p = peer_node_id_map_first (ld -> peers , & it );
823- p ;
824- p = peer_node_id_map_next (ld -> peers , & it )) {
825- list_for_each (& p -> channels , chan , list ) {
826- /* BOLT #2:
827- * - MUST always recognize the `alias` as a
828- * `short_channel_id` for incoming HTLCs to this
829- * channel.
830- */
831- if (chan -> alias [LOCAL ] &&
832- short_channel_id_eq (scid , * chan -> alias [LOCAL ]))
833- return chan ;
834- /* BOLT #2:
835- * - if `channel_type` has `option_scid_alias` set:
836- * - MUST NOT allow incoming HTLCs to this channel
837- * using the real `short_channel_id`
838- */
839- if (!privacy_leak_ok
840- && channel_type_has (chan -> type , OPT_SCID_ALIAS ))
841- continue ;
842- if (chan -> scid
843- && short_channel_id_eq (scid , * chan -> scid ))
844- return chan ;
845-
846- /* Look through any old pre-splice channel ids */
847- for (size_t i = 0 ; i < tal_count (chan -> old_scids ); i ++ ) {
848- if (short_channel_id_eq (scid , chan -> old_scids [i ]))
849- return chan ;
850- }
851- }
852- }
853- return NULL ;
817+ const struct scid_to_channel * scc = channel_scid_map_get (ld -> channels_by_scid , scid );
818+ if (!scc )
819+ return NULL ;
820+
821+ /* BOLT #2:
822+ * - MUST always recognize the `alias` as a `short_channel_id` for
823+ * incoming HTLCs to this channel.
824+ */
825+ if (scc -> channel -> alias [LOCAL ]
826+ && short_channel_id_eq (scid , * scc -> channel -> alias [LOCAL ]))
827+ return scc -> channel ;
828+
829+ /* BOLT #2:
830+ * - if `channel_type` has `option_scid_alias` set:
831+ * - MUST NOT allow incoming HTLCs to this channel using the real
832+ * `short_channel_id`
833+ */
834+ /* This means any scids other than the alias (handled above) cannot be exposed */
835+ if (!privacy_leak_ok && channel_type_has (scc -> channel -> type , OPT_SCID_ALIAS ))
836+ return NULL ;
837+
838+ return scc -> channel ;
854839}
855840
856841struct channel * channel_by_dbid (struct lightningd * ld , const u64 dbid )
0 commit comments