@@ -613,11 +613,12 @@ payment_get_excluded_channels(const tal_t *ctx, struct payment *p)
613613{
614614 struct payment * root = payment_root (p );
615615 struct channel_hint * hint ;
616+ struct channel_hint_map_iter iter ;
616617 struct short_channel_id_dir * res =
617618 tal_arr (ctx , struct short_channel_id_dir , 0 );
618- for (size_t i = 0 ; i < tal_count (root -> hints -> hints ); i ++ ) {
619- hint = & root -> hints -> hints [ i ] ;
620-
619+ for (hint = channel_hint_map_first (root -> hints -> hints , & iter );
620+ hint ;
621+ hint = channel_hint_map_next ( root -> hints -> hints , & iter )) {
621622 if (!hint -> enabled )
622623 tal_arr_expand (& res , hint -> scid );
623624
@@ -640,19 +641,6 @@ static const struct node_id *payment_get_excluded_nodes(const tal_t *ctx,
640641 return root -> excluded_nodes ;
641642}
642643
643- /* FIXME: This is slow! */
644- static const struct channel_hint * find_hint (const struct channel_hint * hints ,
645- struct short_channel_id scid ,
646- int dir )
647- {
648- for (size_t i = 0 ; i < tal_count (hints ); i ++ ) {
649- if (short_channel_id_eq (scid , hints [i ].scid .scid )
650- && dir == hints [i ].scid .dir )
651- return & hints [i ];
652- }
653- return NULL ;
654- }
655-
656644/* FIXME: This is slow! */
657645static bool dst_is_excluded (const struct gossmap * gossmap ,
658646 const struct gossmap_chan * c ,
@@ -680,7 +668,7 @@ static bool payment_route_check(const struct gossmap *gossmap,
680668 struct amount_msat amount ,
681669 struct payment * p )
682670{
683- struct short_channel_id scid ;
671+ struct short_channel_id_dir scidd ;
684672 const struct channel_hint * hint ;
685673
686674 if (dst_is_excluded (gossmap , c , dir , payment_root (p )-> excluded_nodes ))
@@ -689,8 +677,9 @@ static bool payment_route_check(const struct gossmap *gossmap,
689677 if (dst_is_excluded (gossmap , c , dir , p -> temp_exclusion ))
690678 return false;
691679
692- scid = gossmap_chan_scid (gossmap , c );
693- hint = find_hint (payment_root (p )-> hints -> hints , scid , dir );
680+ scidd .scid = gossmap_chan_scid (gossmap , c );
681+ scidd .dir = dir ;
682+ hint = channel_hint_set_find (payment_root (p )-> hints , & scidd );
694683 if (!hint )
695684 return true;
696685
@@ -2613,10 +2602,7 @@ local_channel_hints_listpeerchannels(struct command *cmd, const char *buffer,
26132602 * observations, and should re-enable some channels that would
26142603 * otherwise start out as excluded and remain so until
26152604 * forever. */
2616-
2617- struct channel_hint * hints = payment_root (p )-> hints -> hints ;
2618- for (size_t i = 0 ; i < tal_count (hints ); i ++ )
2619- channel_hint_update (time_now (), & hints [i ]);
2605+ channel_hint_set_update (payment_root (p )-> hints , time_now ());
26202606
26212607 payment_continue (p );
26222608 return command_still_pending (cmd );
@@ -2758,6 +2744,8 @@ static bool routehint_excluded(struct payment *p,
27582744 const struct short_channel_id_dir * chans =
27592745 payment_get_excluded_channels (tmpctx , p );
27602746 const struct channel_hint_set * hints = payment_root (p )-> hints ;
2747+ struct short_channel_id_dir scidd ;
2748+ struct channel_hint * hint ;
27612749
27622750 /* Note that we ignore direction here: in theory, we could have
27632751 * found that one direction of a channel is unavailable, but they
@@ -2797,15 +2785,12 @@ static bool routehint_excluded(struct payment *p,
27972785 * know the exact capacity we need to send via this
27982786 * channel, which is greater than the destination.
27992787 */
2800- for (size_t j = 0 ; j < tal_count (hints ); j ++ ) {
2801- if (!short_channel_id_eq (hints -> hints [j ].scid .scid , r -> short_channel_id ))
2802- continue ;
2803- /* We exclude on equality because we set the estimate
2804- * to the smallest failed attempt. */
2805- if (amount_msat_greater_eq (needed_capacity ,
2806- hints -> hints [j ].estimated_capacity ))
2807- return true;
2808- }
2788+ scidd .scid = r -> short_channel_id ;
2789+ scidd .dir = node_id_idx (& r -> pubkey , p -> pay_destination );
2790+ hint = channel_hint_set_find (hints , & scidd );
2791+ if (hint && amount_msat_greater_eq (needed_capacity ,
2792+ hint -> estimated_capacity ))
2793+ return true;
28092794 }
28102795 return false;
28112796}
0 commit comments