2018-03-22 11:36:25 +01:00
|
|
|
#ifndef LIGHTNING_CHANNELD_CHANNELD_HTLC_H
|
|
|
|
#define LIGHTNING_CHANNELD_CHANNELD_HTLC_H
|
2017-08-28 17:57:01 +02:00
|
|
|
#include "config.h"
|
2021-09-16 07:00:42 +02:00
|
|
|
#include <ccan/crypto/siphash24/siphash24.h>
|
2017-08-29 06:12:04 +02:00
|
|
|
#include <common/htlc.h>
|
2017-08-28 18:04:01 +02:00
|
|
|
#include <common/pseudorand.h>
|
2020-09-07 23:06:50 +02:00
|
|
|
#include <wire/onion_wire.h>
|
2017-08-28 17:57:01 +02:00
|
|
|
|
|
|
|
struct htlc {
|
|
|
|
/* What's the status. */
|
|
|
|
enum htlc_state state;
|
|
|
|
/* The unique ID for this peer and this direction (LOCAL or REMOTE) */
|
|
|
|
u64 id;
|
|
|
|
/* The amount in millisatoshi. */
|
2019-02-21 04:45:55 +01:00
|
|
|
struct amount_msat amount;
|
2017-08-28 17:57:01 +02:00
|
|
|
/* When the HTLC can no longer be redeemed. */
|
|
|
|
struct abs_locktime expiry;
|
|
|
|
/* The hash of the preimage which can redeem this HTLC */
|
|
|
|
struct sha256 rhash;
|
|
|
|
/* The preimage which hashes to rhash (if known) */
|
|
|
|
struct preimage *r;
|
|
|
|
|
2020-02-18 00:58:58 +01:00
|
|
|
/* If they fail the HTLC, we store why here. */
|
|
|
|
const struct failed_htlc *failed;
|
2017-11-28 06:03:13 +01:00
|
|
|
|
2020-02-18 00:58:58 +01:00
|
|
|
/* Routing information sent with this HTLC (outgoing only). */
|
2017-08-28 17:57:01 +02:00
|
|
|
const u8 *routing;
|
2020-04-11 05:22:40 +02:00
|
|
|
|
|
|
|
/* Blinding (optional). */
|
|
|
|
struct pubkey *blinding;
|
2017-08-28 17:57:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline bool htlc_has(const struct htlc *h, int flag)
|
|
|
|
{
|
|
|
|
return htlc_state_flags(h->state) & flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline enum side htlc_owner(const struct htlc *h)
|
|
|
|
{
|
|
|
|
return htlc_state_owner(h->state);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* htlc_map: ID -> htlc mapping. */
|
|
|
|
static inline u64 htlc_key(const struct htlc *h)
|
|
|
|
{
|
|
|
|
return h->id;
|
|
|
|
}
|
|
|
|
static inline bool htlc_cmp(const struct htlc *h, u64 id)
|
|
|
|
{
|
|
|
|
return h->id == id;
|
|
|
|
}
|
|
|
|
static inline size_t htlc_hash(u64 id)
|
|
|
|
{
|
|
|
|
return siphash24(siphash_seed(), &id, sizeof(id));
|
|
|
|
}
|
|
|
|
HTABLE_DEFINE_TYPE(struct htlc, htlc_key, htlc_hash, htlc_cmp, htlc_map);
|
|
|
|
|
|
|
|
static inline struct htlc *htlc_get(struct htlc_map *htlcs, u64 id, enum side owner)
|
|
|
|
{
|
|
|
|
struct htlc *h;
|
|
|
|
struct htlc_map_iter it;
|
|
|
|
|
|
|
|
for (h = htlc_map_getfirst(htlcs, id, &it);
|
|
|
|
h;
|
|
|
|
h = htlc_map_getnext(htlcs, id, &it)) {
|
|
|
|
if (h->id == id && htlc_has(h, HTLC_FLAG(owner,HTLC_F_OWNER)))
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: Move these out of the hash! */
|
|
|
|
static inline bool htlc_is_dead(const struct htlc *htlc)
|
|
|
|
{
|
|
|
|
return htlc->state == RCVD_REMOVE_ACK_REVOCATION
|
|
|
|
|| htlc->state == SENT_REMOVE_ACK_REVOCATION;
|
|
|
|
}
|
2018-03-22 11:36:25 +01:00
|
|
|
#endif /* LIGHTNING_CHANNELD_CHANNELD_HTLC_H */
|