diff --git a/daemon/htlc.h b/daemon/htlc.h index 1f6731fd3..2e7c409d0 100644 --- a/daemon/htlc.h +++ b/daemon/htlc.h @@ -47,47 +47,9 @@ enum side { #define HTLC_LOCAL_F_OWNER HTLC_FLAG(LOCAL,HTLC_F_OWNER) #define HTLC_LOCAL_F_WAS_COMMITTED HTLC_FLAG(LOCAL,HTLC_F_WAS_COMMITTED) -struct htlc { - /* Useful for debugging, and decoding via ->src. */ - struct peer *peer; - /* Block number where we abort if it's still live (LOCAL only) */ - u32 deadline; - /* 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. */ - u64 msatoshi; - /* 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; - - /* FIXME: We could union these together: */ - /* Routing information sent with this HTLC. */ - const u8 *routing; - /* Previous HTLC (if any) which made us offer this (LOCAL only) */ - struct htlc *src; - const u8 *fail; - /* FIXME: actually an enum onion_type */ - u8 malformed; -}; - const char *htlc_state_name(enum htlc_state s); -enum htlc_state htlc_state_from_name(const char *name); -void htlc_changestate(struct htlc *h, - enum htlc_state oldstate, - enum htlc_state newstate, - bool db_commit); int htlc_state_flags(enum htlc_state state); -static inline bool htlc_has(const struct htlc *h, int flag) -{ - return htlc_state_flags(h->state) & flag; -} - static inline enum side htlc_state_owner(enum htlc_state state) { if (state < RCVD_ADD_HTLC) { @@ -103,56 +65,6 @@ static inline enum side htlc_state_owner(enum htlc_state state) } } -static inline enum side htlc_owner(const struct htlc *h) -{ - return htlc_state_owner(h->state); -} - -void htlc_undostate(struct htlc *h, - enum htlc_state oldstate, enum htlc_state newstate); - -/* 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; -} - -static inline size_t htlc_map_count(const struct htlc_map *htlcs) -{ - return htlcs->raw.elems; -} - -/* 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; -} - - static inline const char *side_to_str(enum side side) { switch (side) { diff --git a/lightningd/channel.h b/lightningd/channel.h index 4f4dd4fa3..7d5347186 100644 --- a/lightningd/channel.h +++ b/lightningd/channel.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include diff --git a/lightningd/channel/Makefile b/lightningd/channel/Makefile index 0c6709c33..b859b470d 100644 --- a/lightningd/channel/Makefile +++ b/lightningd/channel/Makefile @@ -12,17 +12,18 @@ lightningd/channel-all: lightningd/lightningd_channel LIGHTNINGD_CHANNEL_HEADERS_GEN := \ lightningd/channel/gen_channel_wire.h -LIGHTNINGD_CHANNEL_HEADERS_NOGEN := +LIGHTNINGD_CHANNEL_HEADERS_NOGEN := \ + lightningd/channel/channeld_htlc.h LIGHTNINGD_CHANNEL_HEADERS := $(LIGHTNINGD_CHANNEL_HEADERS_GEN) $(LIGHTNINGD_CHANNEL_HEADERS_NOGEN) LIGHTNINGD_CHANNEL_SRC := lightningd/channel/channel.c \ - $(LIGHTNINGD_CHANNEL_HEADERS:.h=.c) + $(LIGHTNINGD_CHANNEL_HEADERS_GEN:.h=.c) LIGHTNINGD_CHANNEL_OBJS := $(LIGHTNINGD_CHANNEL_SRC:.c=.o) # Control daemon uses this: -LIGHTNINGD_CHANNEL_CONTROL_HEADERS := $(LIGHTNINGD_CHANNEL_HEADERS) -LIGHTNINGD_CHANNEL_CONTROL_SRC := $(LIGHTNINGD_CHANNEL_HEADERS:.h=.c) +LIGHTNINGD_CHANNEL_CONTROL_HEADERS := $(LIGHTNINGD_CHANNEL_HEADERS_GEN) +LIGHTNINGD_CHANNEL_CONTROL_SRC := $(LIGHTNINGD_CHANNEL_HEADERS_GEN:.h=.c) LIGHTNINGD_CHANNEL_CONTROL_OBJS := $(LIGHTNINGD_CHANNEL_CONTROL_SRC:.c=.o) LIGHTNINGD_CHANNEL_GEN_SRC := $(filter lightningd/channel/gen_%, $(LIGHTNINGD_CHANNEL_SRC) $(LIGHTNINGD_CHANNEL_CONTROL_SRC)) diff --git a/lightningd/channel/channeld_htlc.h b/lightningd/channel/channeld_htlc.h new file mode 100644 index 000000000..e88fa952d --- /dev/null +++ b/lightningd/channel/channeld_htlc.h @@ -0,0 +1,78 @@ +#ifndef LIGHTNINGD_CHANNELD_HTLC_H +#define LIGHTNINGD_CHANNELD_HTLC_H +#include "config.h" +#include +#include + +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. */ + u64 msatoshi; + /* 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; + + /* FIXME: We could union these together: */ + /* Routing information sent with this HTLC. */ + const u8 *routing; + const u8 *fail; + enum onion_type malformed; +}; + +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; +} + +static inline size_t htlc_map_count(const struct htlc_map *htlcs) +{ + return htlcs->raw.elems; +} + +/* 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; +} +#endif /* LIGHTNINGD_CHANNELD_HTLC_H */ diff --git a/lightningd/commit_tx.h b/lightningd/commit_tx.h index 92f24e234..16c3c5510 100644 --- a/lightningd/commit_tx.h +++ b/lightningd/commit_tx.h @@ -3,6 +3,7 @@ #include "config.h" #include #include +#include struct keyset; struct sha256_double;