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