Skip to content

Commit db8f46f

Browse files
committed
offers: modify find_best_peer() to only select from fronting nodes if set.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 5a350a5 commit db8f46f

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
@@ -316,9 +316,20 @@ struct find_best_peer_data {
316316
const struct chaninfo *,
317317
void *);
318318
int needed_feature;
319+
const struct pubkey *fronting_only;
319320
void *arg;
320321
};
321322

323+
static bool is_in_pubkeys(const struct pubkey *pubkeys,
324+
const struct pubkey *k)
325+
{
326+
for (size_t i = 0; i < tal_count(pubkeys); i++) {
327+
if (pubkey_eq(&pubkeys[i], k))
328+
return true;
329+
}
330+
return false;
331+
}
332+
322333
static struct command_result *listincoming_done(struct command *cmd,
323334
const char *method,
324335
const char *buf,
@@ -363,6 +374,18 @@ static struct command_result *listincoming_done(struct command *cmd,
363374
}
364375
ci.feebase = feebase.millisatoshis; /* Raw: feebase */
365376

377+
if (data->fronting_only) {
378+
if (!is_in_pubkeys(data->fronting_only, &ci.id))
379+
continue;
380+
381+
/* If disconnected, don't eliminate, simply
382+
* consider it last. */
383+
if (!enabled) {
384+
ci.capacity = AMOUNT_MSAT(0);
385+
enabled = true;
386+
}
387+
}
388+
366389
/* Don't pick a peer which is disconnected */
367390
if (!enabled)
368391
continue;
@@ -388,6 +411,7 @@ static struct command_result *listincoming_done(struct command *cmd,
388411

389412
struct command_result *find_best_peer_(struct command *cmd,
390413
int needed_feature,
414+
const struct pubkey *fronting_only,
391415
struct command_result *(*cb)(struct command *,
392416
const struct chaninfo *,
393417
void *),
@@ -398,6 +422,7 @@ struct command_result *find_best_peer_(struct command *cmd,
398422
data->cb = cb;
399423
data->arg = arg;
400424
data->needed_feature = needed_feature;
425+
data->fronting_only = fronting_only;
401426
req = jsonrpc_request_start(cmd, "listincoming",
402427
listincoming_done, forward_error, data);
403428
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
@@ -390,7 +390,7 @@ static struct command_result *add_blindedpaths(struct command *cmd,
390390
if (!we_want_blinded_path(cmd->plugin, true))
391391
return create_invoicereq(cmd, ir);
392392

393-
return find_best_peer(cmd, OPT_ROUTE_BLINDING,
393+
return find_best_peer(cmd, OPT_ROUTE_BLINDING, NULL,
394394
found_best_peer, ir);
395395
}
396396

plugins/offers_offer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ static struct command_result *maybe_add_path(struct command *cmd,
343343
tal_count(od->fronting_nodes));
344344
} else {
345345
return find_best_peer(cmd, OPT_ONION_MESSAGES,
346+
NULL,
346347
found_best_peer, offinfo);
347348
}
348349
}
@@ -776,7 +777,7 @@ struct command_result *json_invoicerequest(struct command *cmd,
776777
idata->invreq = invreq;
777778
idata->single_use = *single_use;
778779
idata->label = label;
779-
return find_best_peer(cmd, OPT_ONION_MESSAGES,
780+
return find_best_peer(cmd, OPT_ONION_MESSAGES, NULL,
780781
found_best_peer_invrequest, idata);
781782
}
782783

0 commit comments

Comments
 (0)