Skip to content

Commit 8dcb077

Browse files
committed
offers: modify find_best_peer() to only select from fronting nodes if set.
Signed-off-by: Rusty Russell <[email protected]>
1 parent 7160541 commit 8dcb077

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

plugins/offers.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,20 @@ struct find_best_peer_data {
320320
const struct chaninfo *,
321321
void *);
322322
int needed_feature;
323+
const struct pubkey *fronting_only;
323324
void *arg;
324325
};
325326

327+
static bool is_in_pubkeys(const struct pubkey *pubkeys,
328+
const struct pubkey *k)
329+
{
330+
for (size_t i = 0; i < tal_count(pubkeys); i++) {
331+
if (pubkey_eq(&pubkeys[i], k))
332+
return true;
333+
}
334+
return false;
335+
}
336+
326337
static struct command_result *listincoming_done(struct command *cmd,
327338
const char *method,
328339
const char *buf,
@@ -367,6 +378,18 @@ static struct command_result *listincoming_done(struct command *cmd,
367378
}
368379
ci.feebase = feebase.millisatoshis; /* Raw: feebase */
369380

381+
if (data->fronting_only) {
382+
if (!is_in_pubkeys(data->fronting_only, &ci.id))
383+
continue;
384+
385+
/* If disconnected, don't eliminate, simply
386+
* consider it last. */
387+
if (!enabled) {
388+
ci.capacity = AMOUNT_MSAT(0);
389+
enabled = true;
390+
}
391+
}
392+
370393
/* Don't pick a peer which is disconnected */
371394
if (!enabled)
372395
continue;
@@ -392,6 +415,7 @@ static struct command_result *listincoming_done(struct command *cmd,
392415

393416
struct command_result *find_best_peer_(struct command *cmd,
394417
int needed_feature,
418+
const struct pubkey *fronting_only,
395419
struct command_result *(*cb)(struct command *,
396420
const struct chaninfo *,
397421
void *),
@@ -402,6 +426,7 @@ struct command_result *find_best_peer_(struct command *cmd,
402426
data->cb = cb;
403427
data->arg = arg;
404428
data->needed_feature = needed_feature;
429+
data->fronting_only = fronting_only;
405430
req = jsonrpc_request_start(cmd, "listincoming",
406431
listincoming_done, forward_error, data);
407432
return send_outreq(req);

plugins/offers.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,14 @@ struct chaninfo {
8686
/* Calls listpeerchannels, then cb with best peer (if any!) which has needed_feature */
8787
struct command_result *find_best_peer_(struct command *cmd,
8888
int needed_feature,
89+
const struct pubkey *fronting_only,
8990
struct command_result *(*cb)(struct command *,
9091
const struct chaninfo *,
9192
void *),
9293
void *arg);
9394

94-
#define find_best_peer(cmd, needed_feature, cb, arg) \
95-
find_best_peer_((cmd), (needed_feature), \
95+
#define find_best_peer(cmd, needed_feature, fronting_only, cb, arg) \
96+
find_best_peer_((cmd), (needed_feature), (fronting_only), \
9697
typesafe_cb_preargs(struct command_result *, void *, \
9798
(cb), (arg), \
9899
struct command *, \

plugins/offers_invreq_hook.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ static struct command_result *add_blindedpaths(struct command *cmd,
361361
if (!we_want_blinded_path(cmd->plugin, true))
362362
return create_invoicereq(cmd, ir);
363363

364-
return find_best_peer(cmd, OPT_ROUTE_BLINDING,
364+
return find_best_peer(cmd, OPT_ROUTE_BLINDING, NULL,
365365
found_best_peer, ir);
366366
}
367367

plugins/offers_offer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ static struct command_result *maybe_add_path(struct command *cmd,
369369
tal_count(od->fronting_nodes));
370370
} else {
371371
return find_best_peer(cmd, OPT_ONION_MESSAGES,
372+
NULL,
372373
found_best_peer, offinfo);
373374
}
374375
}
@@ -779,7 +780,7 @@ struct command_result *json_invoicerequest(struct command *cmd,
779780
idata->invreq = invreq;
780781
idata->single_use = *single_use;
781782
idata->label = label;
782-
return find_best_peer(cmd, OPT_ONION_MESSAGES,
783+
return find_best_peer(cmd, OPT_ONION_MESSAGES, NULL,
783784
found_best_peer_invrequest, idata);
784785
}
785786

0 commit comments

Comments
 (0)