diff --git a/plugins/renepay/pay.c b/plugins/renepay/pay.c index 2d05c6f0acf2..3c95bb322852 100644 --- a/plugins/renepay/pay.c +++ b/plugins/renepay/pay.c @@ -37,6 +37,7 @@ static void memleak_mark(struct plugin *p, struct htable *memtable) { memleak_scan_obj(memtable, pay_plugin); memleak_scan_htable(memtable, &pay_plugin->chan_extra_map->raw); + memleak_scan_htable(memtable, &pay_plugin->payment_map->raw); } static const char *init(struct plugin *p, @@ -62,6 +63,9 @@ static const char *init(struct plugin *p, list_head_init(&pay_plugin->payments); + pay_plugin->payment_map = tal(pay_plugin, struct payment_map); + payment_map_init(pay_plugin->payment_map); + pay_plugin->chan_extra_map = tal(pay_plugin,struct chan_extra_map); chan_extra_map_init(pay_plugin->chan_extra_map); @@ -511,6 +515,7 @@ static struct command_result *listpeerchannels_done( static void destroy_payment(struct payment *p) { list_del_from(&pay_plugin->payments, &p->list); + payment_map_del(pay_plugin->payment_map, p); } static struct command_result *json_paystatus(struct command *cmd, @@ -956,7 +961,7 @@ static struct command_result *json_pay(struct command *cmd, const char *buf, take(description), b11->payment_secret, b11->metadata, - b11->routes, + cast_const2(const struct route_info**, b11->routes), &b11->receiver_id, &b11->payment_hash, *msat, @@ -972,6 +977,7 @@ static struct command_result *json_pay(struct command *cmd, const char *buf, // FIXME do we really need a list here? list_add_tail(&pay_plugin->payments, &payment->list); + payment_map_add(pay_plugin->payment_map, payment); // FIXME shall we add a payment destructor? tal_add_destructor(payment, destroy_payment); diff --git a/plugins/renepay/pay.h b/plugins/renepay/pay.h index 014c08880542..4cc8e83f8db1 100644 --- a/plugins/renepay/pay.h +++ b/plugins/renepay/pay.h @@ -65,6 +65,7 @@ struct pay_plugin { /* All the struct payment */ struct list_head payments; + struct payment_map *payment_map; /* Per-channel metadata: some persists between payments */ struct chan_extra_map *chan_extra_map; diff --git a/plugins/renepay/payment.h b/plugins/renepay/payment.h index b348dfc8983f..b2f5bbbf4ed2 100644 --- a/plugins/renepay/payment.h +++ b/plugins/renepay/payment.h @@ -115,6 +115,31 @@ struct payment { u64 groupid; }; +static inline const struct sha256 payment_hash(const struct payment *p) +{ + return p->payment_hash; +} + +static inline size_t payment_hash64(const struct sha256 h) +{ + return ((u64) h.u.u32[1] << 32) ^ h.u.u32[0]; +} + +static inline bool payment_hash_eq(const struct payment *p, + const struct sha256 h) +{ + return p->payment_hash.u.u32[0] == h.u.u32[0] && + p->payment_hash.u.u32[1] == h.u.u32[1] && + p->payment_hash.u.u32[2] == h.u.u32[2] && + p->payment_hash.u.u32[3] == h.u.u32[3] && + p->payment_hash.u.u32[4] == h.u.u32[4] && + p->payment_hash.u.u32[5] == h.u.u32[5] && + p->payment_hash.u.u32[6] == h.u.u32[6] && + p->payment_hash.u.u32[7] == h.u.u32[7]; +} + +HTABLE_DEFINE_TYPE(struct payment, payment_hash, payment_hash64, + payment_hash_eq, payment_map); struct payment *payment_new(const tal_t *ctx, struct command *cmd,