Browse Source
This lets us link HTLCs from one peer to another; but for the moment it simply means we can adjust balance when an HTLC is fulfilled. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>ppa-0.6.1
7 changed files with 152 additions and 27 deletions
@ -0,0 +1,39 @@ |
|||
#include <ccan/cast/cast.h> |
|||
#include <ccan/crypto/siphash24/siphash24.h> |
|||
#include <ccan/tal/tal.h> |
|||
#include <daemon/pseudorand.h> |
|||
#include <lightningd/htlc_end.h> |
|||
|
|||
size_t hash_htlc_end(const struct htlc_end *e) |
|||
{ |
|||
struct siphash24_ctx ctx; |
|||
siphash24_init(&ctx, siphash_seed()); |
|||
/* peer doesn't move while in this hash, so we just hash pointer. */ |
|||
siphash24_update(&ctx, &e->peer, sizeof(e->peer)); |
|||
siphash24_u64(&ctx, e->htlc_id); |
|||
siphash24_u8(&ctx, e->which_end); |
|||
|
|||
return siphash24_done(&ctx); |
|||
} |
|||
|
|||
struct htlc_end *find_htlc_end(const struct htlc_end_map *map, |
|||
const struct peer *peer, |
|||
u64 htlc_id, |
|||
enum htlc_end_type which_end) |
|||
{ |
|||
const struct htlc_end key = { which_end, (struct peer *)peer, htlc_id, |
|||
NULL }; |
|||
|
|||
return htlc_end_map_get(map, &key); |
|||
} |
|||
|
|||
static void remove_htlc_end(struct htlc_end *hend, struct htlc_end_map *map) |
|||
{ |
|||
htlc_end_map_del(map, hend); |
|||
} |
|||
|
|||
void connect_htlc_end(struct htlc_end_map *map, struct htlc_end *hend) |
|||
{ |
|||
tal_add_destructor2(hend, remove_htlc_end, map); |
|||
htlc_end_map_add(map, hend); |
|||
} |
@ -0,0 +1,47 @@ |
|||
#ifndef LIGHTNING_LIGHTNINGD_HTLC_END_H |
|||
#define LIGHTNING_LIGHTNINGD_HTLC_END_H |
|||
#include "config.h" |
|||
#include <ccan/htable/htable_type.h> |
|||
#include <ccan/short_types/short_types.h> |
|||
|
|||
/* A HTLC has a source and destination: if other is NULL, it's this node.
|
|||
* |
|||
* The main daemon simply shuffles them back and forth. |
|||
*/ |
|||
enum htlc_end_type { HTLC_SRC, HTLC_DST }; |
|||
|
|||
struct htlc_end { |
|||
enum htlc_end_type which_end; |
|||
struct peer *peer; |
|||
u64 htlc_id; |
|||
u64 msatoshis; |
|||
|
|||
struct htlc_end *other_end; |
|||
/* If this is driven by a command. */ |
|||
struct pay_command *pay_command; |
|||
}; |
|||
|
|||
static inline const struct htlc_end *keyof_htlc_end(const struct htlc_end *e) |
|||
{ |
|||
return e; |
|||
} |
|||
|
|||
size_t hash_htlc_end(const struct htlc_end *e); |
|||
|
|||
static inline bool htlc_end_eq(const struct htlc_end *a, |
|||
const struct htlc_end *b) |
|||
{ |
|||
return a->peer == b->peer |
|||
&& a->htlc_id == b->htlc_id |
|||
&& a->which_end == b->which_end; |
|||
} |
|||
HTABLE_DEFINE_TYPE(struct htlc_end, keyof_htlc_end, hash_htlc_end, htlc_end_eq, |
|||
htlc_end_map); |
|||
|
|||
struct htlc_end *find_htlc_end(const struct htlc_end_map *map, |
|||
const struct peer *peer, |
|||
u64 htlc_id, |
|||
enum htlc_end_type which_end); |
|||
|
|||
void connect_htlc_end(struct htlc_end_map *map, struct htlc_end *hend); |
|||
#endif /* LIGHTNING_LIGHTNINGD_HTLC_END_H */ |
Loading…
Reference in new issue