Skip to content

Commit

Permalink
add payment hash table
Browse files Browse the repository at this point in the history
  • Loading branch information
Lagrang3 committed Feb 10, 2024
1 parent 45b3a8b commit 9e9a74a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
8 changes: 7 additions & 1 deletion plugins/renepay/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions plugins/renepay/pay.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions plugins/renepay/payment.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 9e9a74a

Please sign in to comment.