@@ -614,11 +614,12 @@ payment_get_excluded_channels(const tal_t *ctx, struct payment *p)
614614{
615615 struct payment * root = payment_root (p );
616616 struct channel_hint * hint ;
617+ struct channel_hint_map_iter iter ;
617618 struct short_channel_id_dir * res =
618619 tal_arr (ctx , struct short_channel_id_dir , 0 );
619- for (size_t i = 0 ; i < tal_count (root -> hints -> hints ); i ++ ) {
620- hint = & root -> hints -> hints [ i ] ;
621-
620+ for (hint = channel_hint_map_first (root -> hints -> hints , & iter );
621+ hint ;
622+ hint = channel_hint_map_next ( root -> hints -> hints , & iter )) {
622623 if (!hint -> enabled )
623624 tal_arr_expand (& res , hint -> scid );
624625
@@ -641,19 +642,6 @@ static const struct node_id *payment_get_excluded_nodes(const tal_t *ctx,
641642 return root -> excluded_nodes ;
642643}
643644
644- /* FIXME: This is slow! */
645- static const struct channel_hint * find_hint (const struct channel_hint * hints ,
646- struct short_channel_id scid ,
647- int dir )
648- {
649- for (size_t i = 0 ; i < tal_count (hints ); i ++ ) {
650- if (short_channel_id_eq (scid , hints [i ].scid .scid )
651- && dir == hints [i ].scid .dir )
652- return & hints [i ];
653- }
654- return NULL ;
655- }
656-
657645/* FIXME: This is slow! */
658646static bool dst_is_excluded (const struct gossmap * gossmap ,
659647 const struct gossmap_chan * c ,
@@ -681,7 +669,7 @@ static bool payment_route_check(const struct gossmap *gossmap,
681669 struct amount_msat amount ,
682670 struct payment * p )
683671{
684- struct short_channel_id scid ;
672+ struct short_channel_id_dir scidd ;
685673 const struct channel_hint * hint ;
686674
687675 if (dst_is_excluded (gossmap , c , dir , payment_root (p )-> excluded_nodes ))
@@ -690,8 +678,9 @@ static bool payment_route_check(const struct gossmap *gossmap,
690678 if (dst_is_excluded (gossmap , c , dir , p -> temp_exclusion ))
691679 return false;
692680
693- scid = gossmap_chan_scid (gossmap , c );
694- hint = find_hint (payment_root (p )-> hints -> hints , scid , dir );
681+ scidd .scid = gossmap_chan_scid (gossmap , c );
682+ scidd .dir = dir ;
683+ hint = channel_hint_set_find (payment_root (p )-> hints , & scidd );
695684 if (!hint )
696685 return true;
697686
@@ -2617,10 +2606,7 @@ local_channel_hints_listpeerchannels(struct command *cmd, const char *buffer,
26172606 * observations, and should re-enable some channels that would
26182607 * otherwise start out as excluded and remain so until
26192608 * forever. */
2620-
2621- struct channel_hint * hints = payment_root (p )-> hints -> hints ;
2622- for (size_t i = 0 ; i < tal_count (hints ); i ++ )
2623- channel_hint_update (time_now (), & hints [i ]);
2609+ channel_hint_set_update (payment_root (p )-> hints , time_now ());
26242610
26252611 payment_continue (p );
26262612 return command_still_pending (cmd );
@@ -2762,6 +2748,8 @@ static bool routehint_excluded(struct payment *p,
27622748 const struct short_channel_id_dir * chans =
27632749 payment_get_excluded_channels (tmpctx , p );
27642750 const struct channel_hint_set * hints = payment_root (p )-> hints ;
2751+ struct short_channel_id_dir scidd ;
2752+ struct channel_hint * hint ;
27652753
27662754 /* Note that we ignore direction here: in theory, we could have
27672755 * found that one direction of a channel is unavailable, but they
@@ -2801,15 +2789,12 @@ static bool routehint_excluded(struct payment *p,
28012789 * know the exact capacity we need to send via this
28022790 * channel, which is greater than the destination.
28032791 */
2804- for (size_t j = 0 ; j < tal_count (hints ); j ++ ) {
2805- if (!short_channel_id_eq (hints -> hints [j ].scid .scid , r -> short_channel_id ))
2806- continue ;
2807- /* We exclude on equality because we set the estimate
2808- * to the smallest failed attempt. */
2809- if (amount_msat_greater_eq (needed_capacity ,
2810- hints -> hints [j ].estimated_capacity ))
2811- return true;
2812- }
2792+ scidd .scid = r -> short_channel_id ;
2793+ scidd .dir = node_id_idx (& r -> pubkey , p -> pay_destination );
2794+ hint = channel_hint_set_find (hints , & scidd );
2795+ if (hint && amount_msat_greater_eq (needed_capacity ,
2796+ hint -> estimated_capacity ))
2797+ return true;
28132798 }
28142799 return false;
28152800}
0 commit comments