renepay: add cli option exclude

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 <lagrang3@protonmail.com>
Changelog-EXPERIMENTAL: renepay: add cli option "exclude" to manually disable channels and nodes.
This commit is contained in:
Lagrang3 2024-08-13 13:21:40 +09:30 committed by ShahanaFarooqui
parent 44d53dc473
commit 9afc10bf99
11 changed files with 444 additions and 370 deletions

View file

@ -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,
@ -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

View file

@ -2485,6 +2485,7 @@ message RenepayRequest {
optional string description = 6;
optional string label = 7;
optional bool dev_use_shadow = 8;
repeated string exclude = 9;
}
message RenepayResponse {

View file

@ -4995,6 +4995,8 @@ impl From<requests::RenepayRequest> for pb::RenepayRequest {
amount_msat: c.amount_msat.map(|f| f.into()), // Rule #2 for type msat?
description: c.description, // Rule #2 for type string?
dev_use_shadow: c.dev_use_shadow, // Rule #2 for type boolean?
// Field: RenePay.exclude
exclude: c.exclude.map(|arr| arr.into_iter().map(|i| i.into()).collect()).unwrap_or(vec![]), // Rule #3
invstring: c.invstring, // Rule #2 for type string
label: c.label, // Rule #2 for type string?
maxdelay: c.maxdelay, // Rule #2 for type u32?
@ -6363,6 +6365,7 @@ impl From<pb::RenepayRequest> for requests::RenepayRequest {
amount_msat: c.amount_msat.map(|a| a.into()), // Rule #1 for type msat?
description: c.description, // Rule #1 for type string?
dev_use_shadow: c.dev_use_shadow, // Rule #1 for type boolean?
exclude: Some(c.exclude.into_iter().map(|s| s.into()).collect()), // Rule #4
invstring: c.invstring, // Rule #1 for type string
label: c.label, // Rule #1 for type string?
maxdelay: c.maxdelay, // Rule #1 for type u32?

2
cln-rpc/src/model.rs generated
View file

@ -3046,6 +3046,8 @@ pub mod requests {
pub maxfee: Option<Amount>,
#[serde(skip_serializing_if = "Option::is_none")]
pub retry_for: Option<u32>,
#[serde(skip_serializing_if = "crate::is_none_or_empty")]
pub exclude: Option<Vec<String>>,
pub invstring: String,
}

View file

@ -500,6 +500,7 @@ DatastoreKeyField = ArrayField(itemtype=PrimitiveField("string", None, None, add
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,
@ -539,6 +540,7 @@ overrides = {
'ListDatastore.key': DatastoreKeyField,
'Invoice.exposeprivatechannels': InvoiceExposeprivatechannelsField,
'Pay.exclude': PayExclude,
'RenePay.exclude': RenePayExclude,
'KeySend.routehints': RoutehintListField,
'KeySend.extratlvs': TlvStreamField,
'Decode.routes': DecodeRoutehintListField,

View file

@ -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"

File diff suppressed because one or more lines are too long

View file

@ -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"

View file

@ -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;
@ -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),
@ -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,
@ -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");

View file

@ -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;
@ -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;
@ -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;
@ -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);

View file

@ -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>
@ -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,
@ -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);