Skip to content

Commit b4c076f

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 4bd433a commit b4c076f

4 files changed

Lines changed: 31 additions & 4 deletions

File tree

plugins/offers.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,20 @@ struct find_best_peer_data {
318318
const struct chaninfo *,
319319
void *);
320320
u64 needed_features;
321+
const struct pubkey *fronting_only;
321322
void *arg;
322323
};
323324

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

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

401424
struct command_result *find_best_peer_(struct command *cmd,
402425
u64 needed_features,
426+
const struct pubkey *fronting_only,
403427
struct command_result *(*cb)(struct command *,
404428
const struct chaninfo *,
405429
void *),
@@ -410,6 +434,7 @@ struct command_result *find_best_peer_(struct command *cmd,
410434
data->cb = cb;
411435
data->arg = arg;
412436
data->needed_features = needed_features;
437+
data->fronting_only = fronting_only;
413438
req = jsonrpc_request_start(cmd, "listincoming",
414439
listincoming_done, forward_error, data);
415440
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
u64 needed_features,
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_features, cb, arg) \
95-
find_best_peer_((cmd), (needed_features), \
95+
#define find_best_peer(cmd, needed_features, fronting_only, cb, arg) \
96+
find_best_peer_((cmd), (needed_features), (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
@@ -393,7 +393,7 @@ static struct command_result *add_blindedpaths(struct command *cmd,
393393
* us onion messaging. */
394394
return find_best_peer(cmd,
395395
(1ULL << OPT_ROUTE_BLINDING) | (1ULL << OPT_ONION_MESSAGES),
396-
found_best_peer, ir);
396+
NULL, found_best_peer, ir);
397397
}
398398

399399
static struct command_result *cancel_invoice(struct command *cmd,

plugins/offers_offer.c

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

782783
return call_createinvoicerequest(cmd, invreq, *single_use, label);

0 commit comments

Comments
 (0)