forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
htlc_set.h
56 lines (47 loc) · 1.57 KB
/
htlc_set.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef LIGHTNING_LIGHTNINGD_HTLC_SET_H
#define LIGHTNING_LIGHTNINGD_HTLC_SET_H
#include "config.h"
#include <ccan/crypto/sha256/sha256.h>
#include <ccan/crypto/siphash24/siphash24.h>
#include <ccan/htable/htable_type.h>
#include <common/amount.h>
#include <common/pseudorand.h>
#include <common/utils.h>
#include <wire/gen_onion_wire.h>
struct htlc_in;
struct lightningd;
/* Set of incoming HTLCs for multi-part-payments */
struct htlc_set {
struct amount_msat total_msat, so_far;
struct sha256 payment_hash;
struct htlc_in **htlcs;
struct oneshot *timeout;
};
static inline const struct sha256 *keyof_htlc_set(const struct htlc_set *set)
{
return &set->payment_hash;
}
static inline size_t hash_payment_hash(const struct sha256 *payment_hash)
{
return siphash24(siphash_seed(), payment_hash, sizeof(&payment_hash));
}
static inline bool htlc_set_eq(const struct htlc_set *set,
const struct sha256 *payment_hash)
{
return sha256_eq(payment_hash, &set->payment_hash);
}
HTABLE_DEFINE_TYPE(struct htlc_set,
keyof_htlc_set,
hash_payment_hash,
htlc_set_eq,
htlc_set_map);
/* Handles hin: if it completes a set, hands that to invoice_try_pay */
void htlc_set_add(struct lightningd *ld,
struct htlc_in *hin,
struct amount_msat total_msat,
const struct secret *payment_secret);
/* Fail every htlc in the set: frees set */
void htlc_set_fail(struct htlc_set *set, enum onion_type failcode);
/* Fulfill every htlc in the set: frees set */
void htlc_set_fulfill(struct htlc_set *set, const struct preimage *preimage);
#endif /* LIGHTNING_LIGHTNINGD_HTLC_SET_H */