mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 18:11:28 +01:00
90a5ba043c
We set hout->key.id when channeld tells us what it is, but if channeld dies before that we free the hout, and our destructor logs it: Valgrind error file: valgrind-errors.20312 ==20312== Use of uninitialised value of size 8 ==20312== at 0x53ABC9B: _itoa_word (_itoa.c:179) ==20312== by 0x53B041F: vfprintf (vfprintf.c:1642) ==20312== by 0x53B17D5: buffered_vfprintf (vfprintf.c:2330) ==20312== by 0x53AEAA5: vfprintf (vfprintf.c:1301) ==20312== by 0x53B7D63: fprintf (fprintf.c:32) ==20312== by 0x128BAC: hout_subd_died (peer_htlcs.c:316) ==20312== by 0x16D8E0: notify (tal.c:240) ==20312== by 0x16DD95: del_tree (tal.c:400) ==20312== by 0x16DDE7: del_tree (tal.c:410) ==20312== by 0x16DDE7: del_tree (tal.c:410) ==20312== by 0x16E1B4: tal_free (tal.c:509) ==20312== by 0x162B5C: io_close (io.c:443) ==20312== by 0x12D563: sd_msg_read (subd.c:508) ==20312== by 0x161EA5: next_plan (io.c:59) ==20312== by 0x1629A2: do_plan (io.c:387) ==20312== by 0x1629E0: io_ready (io.c:397) ==20312== by 0x164319: io_loop (poll.c:305) ==20312== by 0x118E21: main (lightningd.c:334) Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
157 lines
4.2 KiB
C
157 lines
4.2 KiB
C
#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>
|
|
#include <common/htlc_state.h>
|
|
#include <common/sphinx.h>
|
|
#include <wire/gen_onion_wire.h>
|
|
|
|
/* We look up HTLCs by peer & id */
|
|
struct htlc_key {
|
|
struct peer *peer;
|
|
u64 id;
|
|
};
|
|
|
|
#define HTLC_INVALID_ID (-1ULL)
|
|
|
|
/* Incoming HTLC */
|
|
struct htlc_in {
|
|
/* The database primary key for this htlc. Must be 0 until it
|
|
* is saved to the database, must be >0 after saving to the
|
|
* database. */
|
|
u64 dbid;
|
|
struct htlc_key key;
|
|
u64 msatoshi;
|
|
u32 cltv_expiry;
|
|
struct sha256 payment_hash;
|
|
|
|
enum htlc_state hstate;
|
|
|
|
/* Onion information */
|
|
u8 onion_routing_packet[TOTAL_PACKET_SIZE];
|
|
|
|
/* Shared secret for us to send any failure message. */
|
|
struct secret shared_secret;
|
|
|
|
/* If a local error, this is non-zero. */
|
|
enum onion_type failcode;
|
|
|
|
/* For a remote error. */
|
|
const u8 *failuremsg;
|
|
|
|
/* If failcode & UPDATE, this is the channel which failed. */
|
|
struct short_channel_id failoutchannel;
|
|
|
|
/* If they fulfilled, here's the preimage. */
|
|
struct preimage *preimage;
|
|
|
|
};
|
|
|
|
struct htlc_out {
|
|
/* The database primary key for this htlc. Must be 0 until it
|
|
* is saved to the database, must be >0 after saving to the
|
|
* database. */
|
|
u64 dbid;
|
|
u64 origin_htlc_id;
|
|
struct htlc_key key;
|
|
u64 msatoshi;
|
|
u32 cltv_expiry;
|
|
struct sha256 payment_hash;
|
|
|
|
enum htlc_state hstate;
|
|
|
|
/* Onion information */
|
|
u8 onion_routing_packet[TOTAL_PACKET_SIZE];
|
|
|
|
/* If a local error, this is non-zero. */
|
|
enum onion_type failcode;
|
|
|
|
/* For a remote error. */
|
|
const u8 *failuremsg;
|
|
|
|
/* If we fulfilled, here's the preimage. */
|
|
struct preimage *preimage;
|
|
|
|
/* Where it's from, if not going to us. */
|
|
struct htlc_in *in;
|
|
|
|
/* Otherwise, payment command which created it. */
|
|
struct pay_command *pay_command;
|
|
|
|
/* Temporary payment store, so we can save everything in one go */
|
|
struct wallet_payment *payment;
|
|
};
|
|
|
|
static inline const struct htlc_key *keyof_htlc_in(const struct htlc_in *in)
|
|
{
|
|
return &in->key;
|
|
}
|
|
|
|
static inline const struct htlc_key *keyof_htlc_out(const struct htlc_out *out)
|
|
{
|
|
return &out->key;
|
|
}
|
|
|
|
size_t hash_htlc_key(const struct htlc_key *htlc_key);
|
|
|
|
static inline bool htlc_in_eq(const struct htlc_in *in, const struct htlc_key *k)
|
|
{
|
|
return in->key.peer == k->peer && in->key.id == k->id;
|
|
}
|
|
|
|
static inline bool htlc_out_eq(const struct htlc_out *out,
|
|
const struct htlc_key *k)
|
|
{
|
|
return out->key.peer == k->peer && out->key.id == k->id;
|
|
}
|
|
|
|
|
|
HTABLE_DEFINE_TYPE(struct htlc_in, keyof_htlc_in, hash_htlc_key, htlc_in_eq,
|
|
htlc_in_map);
|
|
|
|
HTABLE_DEFINE_TYPE(struct htlc_out, keyof_htlc_out, hash_htlc_key, htlc_out_eq,
|
|
htlc_out_map);
|
|
|
|
struct htlc_in *find_htlc_in(const struct htlc_in_map *map,
|
|
const struct peer *peer,
|
|
u64 htlc_id);
|
|
|
|
struct htlc_out *find_htlc_out(const struct htlc_out_map *map,
|
|
const struct peer *peer,
|
|
u64 htlc_id);
|
|
|
|
/* You still need to connect_htlc_in this! */
|
|
struct htlc_in *new_htlc_in(const tal_t *ctx,
|
|
struct peer *peer, u64 id,
|
|
u64 msatoshi, u32 cltv_expiry,
|
|
const struct sha256 *payment_hash,
|
|
const struct secret *shared_secret,
|
|
const u8 *onion_routing_packet);
|
|
|
|
/* You need to set the ID, then connect_htlc_out this! Steals @payment. */
|
|
struct htlc_out *new_htlc_out(const tal_t *ctx,
|
|
struct peer *peer,
|
|
u64 msatoshi, u32 cltv_expiry,
|
|
const struct sha256 *payment_hash,
|
|
const u8 *onion_routing_packet,
|
|
struct htlc_in *in,
|
|
struct pay_command *pc,
|
|
struct wallet_payment *payment);
|
|
|
|
void connect_htlc_in(struct htlc_in_map *map, struct htlc_in *hin);
|
|
void connect_htlc_out(struct htlc_out_map *map, struct htlc_out *hout);
|
|
|
|
struct htlc_out *htlc_out_check(const struct htlc_out *hout,
|
|
const char *abortstr);
|
|
struct htlc_in *htlc_in_check(const struct htlc_in *hin, const char *abortstr);
|
|
|
|
#if DEVELOPER
|
|
struct htable;
|
|
void htlc_inmap_mark_pointers_used(struct htable *memtable,
|
|
const struct htlc_in_map *map);
|
|
void htlc_outmap_mark_pointers_used(struct htable *memtable,
|
|
const struct htlc_out_map *map);
|
|
#endif /* DEVELOPER */
|
|
#endif /* LIGHTNING_LIGHTNINGD_HTLC_END_H */
|