2017-08-28 18:06:01 +02:00
|
|
|
#ifndef LIGHTNING_COMMON_HTLC_WIRE_H
|
|
|
|
#define LIGHTNING_COMMON_HTLC_WIRE_H
|
2017-06-20 07:46:03 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include <bitcoin/preimage.h>
|
2017-08-28 18:04:01 +02:00
|
|
|
#include <common/htlc.h>
|
2017-08-28 18:05:01 +02:00
|
|
|
#include <common/sphinx.h>
|
2017-06-20 07:46:03 +02:00
|
|
|
|
2017-08-18 06:43:52 +02:00
|
|
|
struct bitcoin_tx;
|
2017-08-18 06:43:52 +02:00
|
|
|
struct shachain;
|
|
|
|
|
2017-06-20 07:46:03 +02:00
|
|
|
/* These are how we communicate about HTLC state to the master daemon */
|
|
|
|
struct added_htlc {
|
|
|
|
u64 id;
|
2019-02-21 04:45:55 +01:00
|
|
|
struct amount_msat amount;
|
2017-06-20 07:46:03 +02:00
|
|
|
struct sha256 payment_hash;
|
|
|
|
u32 cltv_expiry;
|
2020-12-08 07:48:53 +01:00
|
|
|
u8 onion_routing_packet[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)];
|
2021-09-28 21:08:11 +02:00
|
|
|
bool fail_immediate;
|
2020-04-11 05:22:40 +02:00
|
|
|
|
|
|
|
/* If this is non-NULL, secret is the resulting shared secret */
|
|
|
|
struct pubkey *blinding;
|
|
|
|
struct secret blinding_ss;
|
2017-06-20 07:46:03 +02:00
|
|
|
};
|
|
|
|
|
2020-04-03 05:14:07 +02:00
|
|
|
/* This is how lightningd tells us about HTLCs which already exist at startup */
|
|
|
|
struct existing_htlc {
|
|
|
|
u64 id;
|
|
|
|
enum htlc_state state;
|
|
|
|
struct amount_msat amount;
|
|
|
|
struct sha256 payment_hash;
|
|
|
|
u32 cltv_expiry;
|
2020-12-08 07:48:53 +01:00
|
|
|
u8 onion_routing_packet[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)];
|
2020-04-11 05:22:40 +02:00
|
|
|
/* If this is non-NULL, this is blinding to send with (outgoing) HTLC */
|
|
|
|
struct pubkey *blinding;
|
2020-04-03 05:14:07 +02:00
|
|
|
/* If fulfilled, this is non-NULL */
|
|
|
|
struct preimage *payment_preimage;
|
|
|
|
/* If failed, this is set */
|
|
|
|
const struct failed_htlc *failed;
|
|
|
|
};
|
|
|
|
|
2017-06-20 07:46:03 +02:00
|
|
|
struct fulfilled_htlc {
|
|
|
|
u64 id;
|
|
|
|
struct preimage payment_preimage;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct failed_htlc {
|
|
|
|
u64 id;
|
2020-02-18 00:58:58 +01:00
|
|
|
|
|
|
|
/* If this is non-NULL, then the onion was malformed and this is the
|
|
|
|
* SHA256 of what we got: send update_fail_malformed_htlc, using
|
|
|
|
* failcode. */
|
|
|
|
struct sha256 *sha256_of_onion;
|
|
|
|
/* WIRE_INVALID_ONION_VERSION, WIRE_INVALID_ONION_KEY or
|
|
|
|
* WIRE_INVALID_ONION_HMAC (ie. must have BADONION) */
|
2020-08-31 03:13:25 +02:00
|
|
|
enum onion_wire badonion;
|
2020-02-18 00:58:58 +01:00
|
|
|
|
|
|
|
/* Otherwise, this is the onion ready to send to them. */
|
|
|
|
const struct onionreply *onion;
|
2017-06-20 07:46:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct changed_htlc {
|
|
|
|
enum htlc_state newstate;
|
|
|
|
u64 id;
|
|
|
|
};
|
|
|
|
|
2020-04-03 05:14:07 +02:00
|
|
|
struct existing_htlc *new_existing_htlc(const tal_t *ctx,
|
|
|
|
u64 id,
|
|
|
|
enum htlc_state state,
|
|
|
|
struct amount_msat amount,
|
|
|
|
const struct sha256 *payment_hash,
|
|
|
|
u32 cltv_expiry,
|
2020-12-08 07:48:53 +01:00
|
|
|
const u8 onion_routing_packet[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)],
|
2020-04-11 05:22:40 +02:00
|
|
|
const struct pubkey *blinding TAKES,
|
|
|
|
const struct preimage *preimage TAKES,
|
2020-04-03 05:14:07 +02:00
|
|
|
const struct failed_htlc *failed TAKES);
|
|
|
|
|
2017-06-20 07:46:03 +02:00
|
|
|
void towire_added_htlc(u8 **pptr, const struct added_htlc *added);
|
2020-04-03 05:14:07 +02:00
|
|
|
void towire_existing_htlc(u8 **pptr, const struct existing_htlc *existing);
|
2017-06-20 07:46:03 +02:00
|
|
|
void towire_fulfilled_htlc(u8 **pptr, const struct fulfilled_htlc *fulfilled);
|
|
|
|
void towire_failed_htlc(u8 **pptr, const struct failed_htlc *failed);
|
|
|
|
void towire_changed_htlc(u8 **pptr, const struct changed_htlc *changed);
|
2017-07-04 02:44:57 +02:00
|
|
|
void towire_side(u8 **pptr, const enum side side);
|
2017-08-18 06:43:52 +02:00
|
|
|
void towire_shachain(u8 **pptr, const struct shachain *shachain);
|
2017-06-20 07:58:03 +02:00
|
|
|
|
2017-06-20 07:46:03 +02:00
|
|
|
void fromwire_added_htlc(const u8 **cursor, size_t *max,
|
|
|
|
struct added_htlc *added);
|
2020-04-03 05:14:07 +02:00
|
|
|
struct existing_htlc *fromwire_existing_htlc(const tal_t *ctx,
|
|
|
|
const u8 **cursor, size_t *max);
|
2017-06-20 07:46:03 +02:00
|
|
|
void fromwire_fulfilled_htlc(const u8 **cursor, size_t *max,
|
|
|
|
struct fulfilled_htlc *fulfilled);
|
2018-02-08 02:23:46 +01:00
|
|
|
struct failed_htlc *fromwire_failed_htlc(const tal_t *ctx, const u8 **cursor,
|
|
|
|
size_t *max);
|
2017-06-20 07:46:03 +02:00
|
|
|
void fromwire_changed_htlc(const u8 **cursor, size_t *max,
|
|
|
|
struct changed_htlc *changed);
|
2017-07-04 02:44:57 +02:00
|
|
|
enum side fromwire_side(const u8 **cursor, size_t *max);
|
2017-08-18 06:43:52 +02:00
|
|
|
void fromwire_shachain(const u8 **cursor, size_t *max,
|
|
|
|
struct shachain *shachain);
|
2017-08-28 18:06:01 +02:00
|
|
|
#endif /* LIGHTNING_COMMON_HTLC_WIRE_H */
|