Skip to content

Commit

Permalink
renepay: add cli option exclude
Browse files Browse the repository at this point in the history
msggen cannot handle the complex type in renepay-exclude,
therefore I added a rule override for it, just like pay-exclude.

```
msggen cln-grpc/proto/node.proto
Traceback (most recent call last):
  File "/home/rusty/devel/cvs/lightning/contrib/msggen/msggen/__main__.py", line 131, in <module>
    main()
  File "/home/rusty/devel/cvs/lightning/contrib/msggen/msggen/__main__.py", line 115, in main
    run()
  File "/home/rusty/devel/cvs/lightning/contrib/msggen/msggen/__main__.py", line 72, in run
    service = load_jsonrpc_service(
              ^^^^^^^^^^^^^^^^^^^^^
  File "/home/rusty/devel/cvs/lightning/contrib/msggen/msggen/utils/utils.py", line 241, in load_jsonrpc_service
    methods = [load_jsonrpc_method(name) for name in grpc_method_names]
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rusty/devel/cvs/lightning/contrib/msggen/msggen/utils/utils.py", line 209, in load_jsonrpc_method
    request = CompositeField.from_js(schema["methods"][rpc_name]['request'], path=name)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rusty/devel/cvs/lightning/contrib/msggen/msggen/model.py", line 297, in from_js
    field = ArrayField.from_js(fpath, ftype)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rusty/devel/cvs/lightning/contrib/msggen/msggen/model.py", line 464, in from_js
    itemtype = UnionField.from_js(child_js, path)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rusty/devel/cvs/lightning/contrib/msggen/msggen/model.py", line 393, in from_js
    itemtype = PrimitiveField(
               ^^^^^^^^^^^^^^^
TypeError: PrimitiveField.__init__() missing 2 required positional arguments: 'added' and 'deprecated'
```

Signed-off-by: Lagrang3 <[email protected]>
Changelog-EXPERIMENTAL: renepay: add cli option "exclude" to manually disable channels and nodes.
  • Loading branch information
Lagrang3 authored and ShahanaFarooqui committed Aug 13, 2024
1 parent 44d53dc commit 9afc10b
Show file tree
Hide file tree
Showing 11 changed files with 444 additions and 370 deletions.
5 changes: 5 additions & 0 deletions .msggen.json
Original file line number Diff line number Diff line change
Expand Up @@ -2842,6 +2842,7 @@
"RenePay.amount_msat": 2,
"RenePay.description": 6,
"RenePay.dev_use_shadow": 8,
"RenePay.exclude": 9,
"RenePay.invstring": 1,
"RenePay.label": 7,
"RenePay.maxdelay": 4,
Expand Down Expand Up @@ -10097,6 +10098,10 @@
"added": "pre-v0.10.1",
"deprecated": null
},
"RenePay.exclude": {
"added": "v24.08",
"deprecated": null
},
"RenePay.invstring": {
"added": "pre-v0.10.1",
"deprecated": null
Expand Down
1 change: 1 addition & 0 deletions cln-grpc/proto/node.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions cln-grpc/src/convert.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cln-rpc/src/model.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions contrib/msggen/msggen/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ def __str__(self):
DatastoreUsageKeyField = ArrayField(itemtype=PrimitiveField("string", None, None, added="v23.11", deprecated=None), dims=1, path=None, description=None, added="v23.11", deprecated=None)
InvoiceExposeprivatechannelsField = ArrayField(itemtype=PrimitiveField("short_channel_id", None, None, added=None, deprecated=None), dims=1, path=None, description=None, added=None, deprecated=None)
PayExclude = ArrayField(itemtype=PrimitiveField("string", None, None, added=None, deprecated=None), dims=1, path=None, description=None, added=None, deprecated=None)
RenePayExclude = ArrayField(itemtype=PrimitiveField("string", None, None, added=None, deprecated=None), dims=1, path=None, description=None, added="v24.08", deprecated=None)
RoutehintListField = PrimitiveField(
"RoutehintList",
None,
Expand Down Expand Up @@ -539,6 +540,7 @@ def __str__(self):
'ListDatastore.key': DatastoreKeyField,
'Invoice.exposeprivatechannels': InvoiceExposeprivatechannelsField,
'Pay.exclude': PayExclude,
'RenePay.exclude': RenePayExclude,
'KeySend.routehints': RoutehintListField,
'KeySend.extratlvs': TlvStreamField,
'Decode.routes': DecodeRoutehintListField,
Expand Down
18 changes: 18 additions & 0 deletions contrib/msggen/msggen/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -28620,6 +28620,24 @@
"Used to attach a label to payments, and is returned in lightning-listpays(7) and lightning-listsendpays(7)."
]
},
"exclude": {
"added": "v24.08",
"type": "array",
"description": [
"*exclude* is a JSON array of short-channel-id/direction (e.g. [ '564334x877x1/0', '564195x1292x0/1' ]) or pubkey which should be excluded from consideration for routing."
],
"default": "not to exclude any channels or nodes",
"items": {
"oneOf": [
{
"type": "short_channel_id_dir"
},
{
"type": "pubkey"
}
]
}
},
"dev_use_shadow": {
"hidden": true,
"type": "boolean"
Expand Down
728 changes: 364 additions & 364 deletions contrib/pyln-grpc-proto/pyln/grpc/node_pb2.py

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions doc/schemas/lightning-renepay.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@
"Used to attach a label to payments, and is returned in lightning-listpays(7) and lightning-listsendpays(7)."
]
},
"exclude": {
"added": "v24.08",
"type": "array",
"description": [
"*exclude* is a JSON array of short-channel-id/direction (e.g. [ '564334x877x1/0', '564195x1292x0/1' ]) or pubkey which should be excluded from consideration for routing."
],
"default": "not to exclude any channels or nodes",
"items": {
"oneOf": [
{
"type": "short_channel_id_dir"
},
{
"type": "pubkey"
}
]
}
},
"dev_use_shadow": {
"hidden": true,
"type": "boolean"
Expand Down
8 changes: 6 additions & 2 deletions plugins/renepay/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ static struct command_result *json_pay(struct command *cmd, const char *buf,
u32 *retryfor;
const char *description;
const char *label;
struct route_exclusion **exclusions;

// dev options
bool *use_shadow;
Expand All @@ -198,6 +199,7 @@ static struct command_result *json_pay(struct command *cmd, const char *buf,
60), // 60 seconds
p_opt("description", param_string, &description),
p_opt("label", param_string, &label),
p_opt("exclude", param_route_exclusion_array, &exclusions),

// FIXME add support for offers
// p_opt("localofferid", param_sha256, &local_offer_id),
Expand Down Expand Up @@ -313,7 +315,8 @@ static struct command_result *json_pay(struct command *cmd, const char *buf,
*prob_cost_factor_millionths,
*riskfactor_millionths,
*min_prob_success_millionths,
use_shadow);
use_shadow,
cast_const2(const struct route_exclusion**, exclusions));

if (!payment)
return command_fail(cmd, PLUGIN_ERROR,
Expand Down Expand Up @@ -349,7 +352,8 @@ static struct command_result *json_pay(struct command *cmd, const char *buf,
*prob_cost_factor_millionths,
*riskfactor_millionths,
*min_prob_success_millionths,
use_shadow))
use_shadow,
cast_const2(const struct route_exclusion**, exclusions)))
return command_fail(
cmd, PLUGIN_ERROR,
"failed to update the payment parameters");
Expand Down
22 changes: 20 additions & 2 deletions plugins/renepay/payment.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ struct payment *payment_new(
u64 prob_cost_factor_millionths,
u64 riskfactor_millionths,
u64 min_prob_success_millionths,
bool use_shadow)
bool use_shadow,
const struct route_exclusion **exclusions)
{
struct payment *p = tal(ctx, struct payment);
struct payment_info *pinfo = &p->payment_info;
Expand Down Expand Up @@ -101,6 +102,14 @@ struct payment *payment_new(
p->local_gossmods = NULL;
p->disabledmap = disabledmap_new(p);

for (size_t i = 0; i < tal_count(exclusions); i++) {
const struct route_exclusion *ex = exclusions[i];
if (ex->type == EXCLUDE_CHANNEL)
disabledmap_add_channel(p->disabledmap, ex->u.chan_id);
else
disabledmap_add_node(p->disabledmap, ex->u.node_id);
}

p->have_results = false;
p->retry = false;
p->waitresult_timer = NULL;
Expand Down Expand Up @@ -137,7 +146,8 @@ bool payment_update(
u64 prob_cost_factor_millionths,
u64 riskfactor_millionths,
u64 min_prob_success_millionths,
bool use_shadow)
bool use_shadow,
const struct route_exclusion **exclusions)
{
assert(p);
struct payment_info *pinfo = &p->payment_info;
Expand Down Expand Up @@ -192,6 +202,14 @@ bool payment_update(
assert(p->disabledmap);
disabledmap_reset(p->disabledmap);

for (size_t i = 0; i < tal_count(exclusions); i++) {
const struct route_exclusion *ex = exclusions[i];
if (ex->type == EXCLUDE_CHANNEL)
disabledmap_add_channel(p->disabledmap, ex->u.chan_id);
else
disabledmap_add_node(p->disabledmap, ex->u.node_id);
}

p->have_results = false;
p->retry = false;
p->waitresult_timer = tal_free(p->waitresult_timer);
Expand Down
7 changes: 5 additions & 2 deletions plugins/renepay/payment.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define LIGHTNING_PLUGINS_RENEPAY_PAYMENT_H
#include "config.h"
#include <common/gossmap.h>
#include <common/route.h>
#include <plugins/libplugin.h>
#include <plugins/renepay/disabledmap.h>
#include <plugins/renepay/payment_info.h>
Expand Down Expand Up @@ -116,7 +117,8 @@ struct payment *payment_new(
u64 prob_cost_factor_millionths,
u64 riskfactor_millionths,
u64 min_prob_success_millionths,
bool use_shadow);
bool use_shadow,
const struct route_exclusion **exclusions);

bool payment_update(
struct payment *p,
Expand All @@ -129,7 +131,8 @@ bool payment_update(
u64 prob_cost_factor_millionths,
u64 riskfactor_millionths,
u64 min_prob_success_millionths,
bool use_shadow);
bool use_shadow,
const struct route_exclusion **exclusions);

struct amount_msat payment_sent(const struct payment *p);
struct amount_msat payment_delivered(const struct payment *p);
Expand Down

0 comments on commit 9afc10b

Please sign in to comment.