Skip to content

Commit 428b23c

Browse files
Lagrang3endothermicdev
authored andcommitted
renepay: relax knowledge mod
Add a payment mod that relaxes the knowledge of the uncertainty network as a function of time. Signed-off-by: Lagrang3 <[email protected]>
1 parent 2664fae commit 428b23c

File tree

3 files changed

+65
-14
lines changed

3 files changed

+65
-14
lines changed

plugins/renepay/mods.c

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,27 @@ static struct command_result *checktimeout_cb(struct payment *payment)
10201020

10211021
REGISTER_PAYMENT_MODIFIER(checktimeout, checktimeout_cb);
10221022

1023+
/*****************************************************************************
1024+
* knowledgerelax
1025+
*
1026+
* Reduce the knowledge of the network as time goes by.
1027+
*/
1028+
1029+
static struct command_result *knowledgerelax_cb(struct payment *payment)
1030+
{
1031+
const u64 now_sec = time_now().ts.tv_sec;
1032+
enum renepay_errorcode err = uncertainty_relax(
1033+
pay_plugin->uncertainty, now_sec - pay_plugin->last_time);
1034+
if (err)
1035+
plugin_err(pay_plugin->plugin,
1036+
"uncertainty_relax failed with error %s",
1037+
renepay_errorcode_name(err));
1038+
pay_plugin->last_time = now_sec;
1039+
return payment_continue(payment);
1040+
}
1041+
1042+
REGISTER_PAYMENT_MODIFIER(knowledgerelax, knowledgerelax_cb);
1043+
10231044
/*****************************************************************************
10241045
* alwaystrue
10251046
*
@@ -1068,29 +1089,29 @@ REGISTER_PAYMENT_CONDITION(retry, retry_cb);
10681089
*/
10691090
// TODO
10701091
// add shadow route
1071-
// add knowledge decay
10721092
// add check pre-approved invoice
10731093
void *payment_virtual_program[] = {
10741094
/*0*/ OP_CALL, &previous_sendpays_pay_mod,
10751095
/*2*/ OP_CALL, &selfpay_pay_mod,
1076-
/*4*/ OP_CALL, &getmychannels_pay_mod,
1077-
/*6*/ OP_CALL, &routehints_pay_mod,
1096+
/*4*/ OP_CALL, &knowledgerelax_pay_mod,
1097+
/*6*/ OP_CALL, &getmychannels_pay_mod,
1098+
/*8*/ OP_CALL, &routehints_pay_mod,
10781099
// TODO: add a channel filter, for example disable channels that have
10791100
// htlcmax < 0.1% of payment amount, or base fee > 100msat, or
10801101
// proportional_fee > 10%, or capacity < 10% payment amount
10811102
// TODO shadow_additions
10821103
/* do */
1083-
/*8*/ OP_CALL, &refreshgossmap_pay_mod,
1084-
/*10*/ OP_CALL, &checktimeout_pay_mod,
1085-
/*12*/ OP_CALL, &compute_routes_pay_mod,
1086-
/*14*/ OP_CALL, &send_routes_pay_mod,
1104+
/*10*/ OP_CALL, &refreshgossmap_pay_mod,
1105+
/*12*/ OP_CALL, &checktimeout_pay_mod,
1106+
/*14*/ OP_CALL, &compute_routes_pay_mod,
1107+
/*16*/ OP_CALL, &send_routes_pay_mod,
10871108
/*do*/
1088-
/*16*/ OP_CALL, &checktimeout_pay_mod,
1089-
/*18*/ OP_CALL, &sleep_pay_mod,
1090-
/*20*/ OP_CALL, &collect_results_pay_mod,
1109+
/*18*/ OP_CALL, &checktimeout_pay_mod,
1110+
/*20*/ OP_CALL, &sleep_pay_mod,
1111+
/*22*/ OP_CALL, &collect_results_pay_mod,
10911112
/*while*/
1092-
/*22*/ OP_IF, &nothaveresults_pay_cond, (void *)16,
1113+
/*24*/ OP_IF, &nothaveresults_pay_cond, (void *)18,
10931114
/* while */
1094-
/*25*/ OP_IF, &retry_pay_cond, (void *)8,
1095-
/*28*/ OP_CALL, &end_pay_mod, /* safety net, default failure if reached */
1096-
/*20*/ NULL};
1115+
/*27*/ OP_IF, &retry_pay_cond, (void *)10,
1116+
/*30*/ OP_CALL, &end_pay_mod, /* safety net, default failure if reached */
1117+
/*32*/ NULL};

plugins/renepay/uncertainty.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "config.h"
2+
#include <plugins/renepay/renepayconfig.h>
23
#include <plugins/renepay/uncertainty.h>
34

45
void uncertainty_route_success(struct uncertainty *uncertainty,
@@ -177,3 +178,22 @@ struct chan_extra *uncertainty_find_channel(struct uncertainty *uncertainty,
177178
{
178179
return chan_extra_map_get(uncertainty->chan_extra_map, scid);
179180
}
181+
182+
enum renepay_errorcode uncertainty_relax(struct uncertainty *uncertainty,
183+
double seconds)
184+
{
185+
assert(seconds >= 0);
186+
const double fraction = MIN(seconds / TIMER_FORGET_SEC, 1.0);
187+
struct chan_extra_map *chan_extra_map =
188+
uncertainty_get_chan_extra_map(uncertainty);
189+
struct chan_extra_map_iter it;
190+
for (struct chan_extra *ce = chan_extra_map_first(chan_extra_map, &it);
191+
ce; ce = chan_extra_map_next(chan_extra_map, &it)) {
192+
enum renepay_errorcode err =
193+
chan_extra_relax_fraction(ce, fraction);
194+
195+
if (err)
196+
return err;
197+
}
198+
return RENEPAY_NOERROR;
199+
}

plugins/renepay/uncertainty.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,14 @@ bool uncertainty_set_liquidity(struct uncertainty *uncertainty,
5555
struct chan_extra *uncertainty_find_channel(struct uncertainty *uncertainty,
5656
const struct short_channel_id scid);
5757

58+
/* Adds randomness to the current state simulating the natural evolution of the
59+
* liquidity in the network. It should be a markovian process with the minimum
60+
* requirement that the transition operator T satisfies:
61+
* T(t1) T(t2) = T(t1+t2)
62+
* i.e. the transition operator is a one parameter semigroup.
63+
* For the moment we omit the continuous and linear aspects of the problem for a
64+
* lack for formulation. */
65+
enum renepay_errorcode uncertainty_relax(struct uncertainty *uncertainty,
66+
double seconds);
67+
5868
#endif /* LIGHTNING_PLUGINS_RENEPAY_UNCERTAINTY_H */

0 commit comments

Comments
 (0)