2016-11-29 20:51:50 +01:00
|
|
|
#ifndef LIGHTNING_WIRE_WIRE_H
|
|
|
|
#define LIGHTNING_WIRE_WIRE_H
|
|
|
|
#include "config.h"
|
2017-12-18 07:44:10 +01:00
|
|
|
#include <bitcoin/block.h>
|
2019-03-11 20:03:14 +01:00
|
|
|
#include <bitcoin/chainparams.h>
|
2017-02-21 05:45:28 +01:00
|
|
|
#include <bitcoin/privkey.h>
|
2016-11-29 20:51:50 +01:00
|
|
|
#include <bitcoin/pubkey.h>
|
2017-02-21 05:45:28 +01:00
|
|
|
#include <bitcoin/shadouble.h>
|
2017-07-20 20:49:45 +02:00
|
|
|
#include <bitcoin/short_channel_id.h>
|
2016-11-29 20:51:50 +01:00
|
|
|
#include <bitcoin/signature.h>
|
|
|
|
#include <ccan/crypto/sha256/sha256.h>
|
|
|
|
#include <ccan/short_types/short_types.h>
|
2018-07-04 07:30:02 +02:00
|
|
|
#include <ccan/structeq/structeq.h>
|
2019-02-20 12:31:48 +01:00
|
|
|
#include <common/amount.h>
|
2019-07-30 07:25:03 +02:00
|
|
|
#include <common/bigsize.h>
|
2017-10-26 05:01:19 +02:00
|
|
|
#include <secp256k1_recovery.h>
|
2016-11-29 20:51:50 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2017-03-02 13:21:49 +01:00
|
|
|
struct channel_id {
|
|
|
|
u8 id[32];
|
|
|
|
};
|
2018-07-04 07:30:02 +02:00
|
|
|
/* Define channel_id_eq (no padding) */
|
|
|
|
STRUCTEQ_DEF(channel_id, 0, id);
|
2017-05-08 15:15:29 +02:00
|
|
|
|
2017-12-18 07:44:10 +01:00
|
|
|
struct bitcoin_blkid;
|
2018-12-03 00:15:06 +01:00
|
|
|
struct bitcoin_signature;
|
2017-12-18 07:41:52 +01:00
|
|
|
struct bitcoin_txid;
|
common/node_id: new type.
Node ids are pubkeys, but we only use them as pubkeys for routing and checking
gossip messages. So we're packing and unpacking them constantly, and wasting
some space and time.
This introduces a new type, explicitly the SEC1 compressed encoding
(33 bytes). We ensure its validity when we load from the db, or get it
from JSON. We still use 'struct pubkey' for peer messages, which checks
validity.
Results from 5 runs, min-max(mean +/- stddev):
store_load_msec,vsz_kb,store_rewrite_sec,listnodes_sec,listchannels_sec,routing_sec,peer_write_all_sec
39475-39572(39518+/-36),2880732,41.150000-41.390000(41.298+/-0.085),2.260000-2.550000(2.336+/-0.11),44.390000-65.150000(58.648+/-7.5),32.740000-33.020000(32.89+/-0.093),44.130000-45.090000(44.566+/-0.32)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-04-08 08:34:06 +02:00
|
|
|
struct node_id;
|
2017-03-29 12:56:15 +02:00
|
|
|
struct preimage;
|
2017-08-18 06:43:52 +02:00
|
|
|
struct ripemd160;
|
2018-02-26 03:32:58 +01:00
|
|
|
struct siphash_seed;
|
2016-11-29 20:51:50 +01:00
|
|
|
|
2018-02-08 02:25:12 +01:00
|
|
|
/* Makes generate-wire.py work */
|
|
|
|
typedef char wirestring;
|
2019-07-30 07:25:03 +02:00
|
|
|
typedef bigsize_t bigsize;
|
2019-07-27 12:20:25 +02:00
|
|
|
|
|
|
|
/* FIXME: Some versions of spec using 'varint' for bigsize' */
|
|
|
|
typedef bigsize varint;
|
|
|
|
#define fromwire_varint fromwire_bigsize
|
|
|
|
#define towire_varint towire_bigsize
|
2018-02-08 02:25:12 +01:00
|
|
|
|
2017-04-12 08:10:15 +02:00
|
|
|
void derive_channel_id(struct channel_id *channel_id,
|
2019-02-07 15:40:28 +01:00
|
|
|
const struct bitcoin_txid *txid, u16 txout);
|
2017-04-12 08:10:15 +02:00
|
|
|
|
2017-01-04 04:39:21 +01:00
|
|
|
/* Read the type; returns -1 if not long enough. cursor is a tal ptr. */
|
|
|
|
int fromwire_peektype(const u8 *cursor);
|
2017-06-06 05:03:31 +02:00
|
|
|
const void *fromwire_fail(const u8 **cursor, size_t *max);
|
2017-01-04 04:39:21 +01:00
|
|
|
|
2016-11-29 20:51:50 +01:00
|
|
|
void towire(u8 **pptr, const void *data, size_t len);
|
2016-12-02 08:41:06 +01:00
|
|
|
void towire_pubkey(u8 **pptr, const struct pubkey *pubkey);
|
common/node_id: new type.
Node ids are pubkeys, but we only use them as pubkeys for routing and checking
gossip messages. So we're packing and unpacking them constantly, and wasting
some space and time.
This introduces a new type, explicitly the SEC1 compressed encoding
(33 bytes). We ensure its validity when we load from the db, or get it
from JSON. We still use 'struct pubkey' for peer messages, which checks
validity.
Results from 5 runs, min-max(mean +/- stddev):
store_load_msec,vsz_kb,store_rewrite_sec,listnodes_sec,listchannels_sec,routing_sec,peer_write_all_sec
39475-39572(39518+/-36),2880732,41.150000-41.390000(41.298+/-0.085),2.260000-2.550000(2.336+/-0.11),44.390000-65.150000(58.648+/-7.5),32.740000-33.020000(32.89+/-0.093),44.130000-45.090000(44.566+/-0.32)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-04-08 08:34:06 +02:00
|
|
|
void towire_node_id(u8 **pptr, const struct node_id *id);
|
2017-02-21 05:45:28 +01:00
|
|
|
void towire_privkey(u8 **pptr, const struct privkey *privkey);
|
2017-05-06 04:19:44 +02:00
|
|
|
void towire_secret(u8 **pptr, const struct secret *secret);
|
2017-01-25 00:33:42 +01:00
|
|
|
void towire_secp256k1_ecdsa_signature(u8 **pptr,
|
|
|
|
const secp256k1_ecdsa_signature *signature);
|
2017-10-26 05:01:19 +02:00
|
|
|
void towire_secp256k1_ecdsa_recoverable_signature(u8 **pptr,
|
|
|
|
const secp256k1_ecdsa_recoverable_signature *rsig);
|
2016-11-29 20:51:50 +01:00
|
|
|
void towire_channel_id(u8 **pptr, const struct channel_id *channel_id);
|
2017-03-02 13:21:49 +01:00
|
|
|
void towire_short_channel_id(u8 **pptr,
|
|
|
|
const struct short_channel_id *short_channel_id);
|
2019-01-15 05:11:27 +01:00
|
|
|
void towire_short_channel_id_dir(u8 **pptr,
|
|
|
|
const struct short_channel_id_dir *scidd);
|
2016-11-29 20:51:50 +01:00
|
|
|
void towire_sha256(u8 **pptr, const struct sha256 *sha256);
|
2017-02-21 05:45:28 +01:00
|
|
|
void towire_sha256_double(u8 **pptr, const struct sha256_double *sha256d);
|
2017-12-18 07:41:52 +01:00
|
|
|
void towire_bitcoin_txid(u8 **pptr, const struct bitcoin_txid *txid);
|
2018-12-03 00:15:06 +01:00
|
|
|
void towire_bitcoin_signature(u8 **pptr, const struct bitcoin_signature *sig);
|
2017-12-18 07:44:10 +01:00
|
|
|
void towire_bitcoin_blkid(u8 **pptr, const struct bitcoin_blkid *blkid);
|
2017-03-29 12:56:15 +02:00
|
|
|
void towire_preimage(u8 **pptr, const struct preimage *preimage);
|
2017-08-18 06:43:52 +02:00
|
|
|
void towire_ripemd160(u8 **pptr, const struct ripemd160 *ripemd);
|
2019-02-20 12:31:48 +01:00
|
|
|
void towire_amount_msat(u8 **pptr, const struct amount_msat msat);
|
|
|
|
void towire_amount_sat(u8 **pptr, const struct amount_sat sat);
|
2016-11-29 20:51:50 +01:00
|
|
|
void towire_u8(u8 **pptr, u8 v);
|
|
|
|
void towire_u16(u8 **pptr, u16 v);
|
|
|
|
void towire_u32(u8 **pptr, u32 v);
|
|
|
|
void towire_u64(u8 **pptr, u64 v);
|
2019-07-18 07:17:16 +02:00
|
|
|
void towire_tu16(u8 **pptr, u16 v);
|
|
|
|
void towire_tu32(u8 **pptr, u32 v);
|
|
|
|
void towire_tu64(u8 **pptr, u64 v);
|
2018-02-21 12:48:32 +01:00
|
|
|
void towire_double(u8 **pptr, const double *v);
|
2017-01-04 04:39:20 +01:00
|
|
|
void towire_pad(u8 **pptr, size_t num);
|
2017-01-04 04:39:21 +01:00
|
|
|
void towire_bool(u8 **pptr, bool v);
|
2019-07-30 07:25:12 +02:00
|
|
|
void towire_bigsize(u8 **pptr, const bigsize_t val);
|
2016-11-29 20:51:50 +01:00
|
|
|
|
|
|
|
void towire_u8_array(u8 **pptr, const u8 *arr, size_t num);
|
|
|
|
|
2018-01-04 18:19:02 +01:00
|
|
|
void towire_bitcoin_tx(u8 **pptr, const struct bitcoin_tx *tx);
|
2018-02-08 02:25:12 +01:00
|
|
|
void towire_wirestring(u8 **pptr, const char *str);
|
2018-02-26 03:32:58 +01:00
|
|
|
void towire_siphash_seed(u8 **cursor, const struct siphash_seed *seed);
|
2018-01-04 18:19:02 +01:00
|
|
|
|
2019-03-11 20:03:14 +01:00
|
|
|
void towire_bip32_key_version(u8 **cursor, const struct bip32_key_version *version);
|
|
|
|
|
2016-11-29 20:51:50 +01:00
|
|
|
const u8 *fromwire(const u8 **cursor, size_t *max, void *copy, size_t n);
|
|
|
|
u8 fromwire_u8(const u8 **cursor, size_t *max);
|
|
|
|
u16 fromwire_u16(const u8 **cursor, size_t *max);
|
|
|
|
u32 fromwire_u32(const u8 **cursor, size_t *max);
|
|
|
|
u64 fromwire_u64(const u8 **cursor, size_t *max);
|
2019-07-18 07:17:16 +02:00
|
|
|
u16 fromwire_tu16(const u8 **cursor, size_t *max);
|
|
|
|
u32 fromwire_tu32(const u8 **cursor, size_t *max);
|
|
|
|
u64 fromwire_tu64(const u8 **cursor, size_t *max);
|
2018-02-21 12:48:32 +01:00
|
|
|
void fromwire_double(const u8 **cursor, size_t *max, double *v);
|
2017-01-04 04:39:21 +01:00
|
|
|
bool fromwire_bool(const u8 **cursor, size_t *max);
|
2019-07-30 07:25:12 +02:00
|
|
|
bigsize_t fromwire_bigsize(const u8 **cursor, size_t *max);
|
2017-05-06 04:19:44 +02:00
|
|
|
void fromwire_secret(const u8 **cursor, size_t *max, struct secret *secret);
|
2017-02-21 05:45:28 +01:00
|
|
|
void fromwire_privkey(const u8 **cursor, size_t *max, struct privkey *privkey);
|
2016-12-02 08:41:06 +01:00
|
|
|
void fromwire_pubkey(const u8 **cursor, size_t *max, struct pubkey *pubkey);
|
common/node_id: new type.
Node ids are pubkeys, but we only use them as pubkeys for routing and checking
gossip messages. So we're packing and unpacking them constantly, and wasting
some space and time.
This introduces a new type, explicitly the SEC1 compressed encoding
(33 bytes). We ensure its validity when we load from the db, or get it
from JSON. We still use 'struct pubkey' for peer messages, which checks
validity.
Results from 5 runs, min-max(mean +/- stddev):
store_load_msec,vsz_kb,store_rewrite_sec,listnodes_sec,listchannels_sec,routing_sec,peer_write_all_sec
39475-39572(39518+/-36),2880732,41.150000-41.390000(41.298+/-0.085),2.260000-2.550000(2.336+/-0.11),44.390000-65.150000(58.648+/-7.5),32.740000-33.020000(32.89+/-0.093),44.130000-45.090000(44.566+/-0.32)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-04-08 08:34:06 +02:00
|
|
|
void fromwire_node_id(const u8 **cursor, size_t *max, struct node_id *id);
|
2017-01-25 00:33:42 +01:00
|
|
|
void fromwire_secp256k1_ecdsa_signature(const u8 **cursor, size_t *max,
|
|
|
|
secp256k1_ecdsa_signature *signature);
|
2017-10-26 05:01:19 +02:00
|
|
|
void fromwire_secp256k1_ecdsa_recoverable_signature(const u8 **cursor,
|
|
|
|
size_t *max,
|
|
|
|
secp256k1_ecdsa_recoverable_signature *rsig);
|
2016-11-29 20:51:50 +01:00
|
|
|
void fromwire_channel_id(const u8 **cursor, size_t *max,
|
|
|
|
struct channel_id *channel_id);
|
2017-03-02 13:21:49 +01:00
|
|
|
void fromwire_short_channel_id(const u8 **cursor, size_t *max,
|
|
|
|
struct short_channel_id *short_channel_id);
|
2019-01-15 05:11:27 +01:00
|
|
|
void fromwire_short_channel_id_dir(const u8 **cursor, size_t *max,
|
|
|
|
struct short_channel_id_dir *scidd);
|
2016-11-29 20:51:50 +01:00
|
|
|
void fromwire_sha256(const u8 **cursor, size_t *max, struct sha256 *sha256);
|
2017-02-21 05:45:28 +01:00
|
|
|
void fromwire_sha256_double(const u8 **cursor, size_t *max,
|
|
|
|
struct sha256_double *sha256d);
|
2018-12-03 00:15:06 +01:00
|
|
|
void fromwire_bitcoin_signature(const u8 **cursor, size_t *max,
|
|
|
|
struct bitcoin_signature *sig);
|
2017-12-18 07:41:52 +01:00
|
|
|
void fromwire_bitcoin_txid(const u8 **cursor, size_t *max,
|
|
|
|
struct bitcoin_txid *txid);
|
2017-12-18 07:44:10 +01:00
|
|
|
void fromwire_bitcoin_blkid(const u8 **cursor, size_t *max,
|
|
|
|
struct bitcoin_blkid *blkid);
|
2017-03-29 12:56:15 +02:00
|
|
|
void fromwire_preimage(const u8 **cursor, size_t *max, struct preimage *preimage);
|
2017-08-18 06:43:52 +02:00
|
|
|
void fromwire_ripemd160(const u8 **cursor, size_t *max, struct ripemd160 *ripemd);
|
2019-02-20 12:31:48 +01:00
|
|
|
struct amount_msat fromwire_amount_msat(const u8 **cursor, size_t *max);
|
|
|
|
struct amount_sat fromwire_amount_sat(const u8 **cursor, size_t *max);
|
2017-01-04 04:39:20 +01:00
|
|
|
void fromwire_pad(const u8 **cursor, size_t *max, size_t num);
|
2016-11-29 20:51:50 +01:00
|
|
|
|
2017-02-21 05:45:28 +01:00
|
|
|
void fromwire_u8_array(const u8 **cursor, size_t *max, u8 *arr, size_t num);
|
2018-02-08 02:25:12 +01:00
|
|
|
char *fromwire_wirestring(const tal_t *ctx, const u8 **cursor, size_t *max);
|
2018-02-08 02:25:12 +01:00
|
|
|
struct bitcoin_tx *fromwire_bitcoin_tx(const tal_t *ctx,
|
|
|
|
const u8 **cursor, size_t *max);
|
2018-02-26 03:32:58 +01:00
|
|
|
void fromwire_siphash_seed(const u8 **cursor, size_t *max,
|
|
|
|
struct siphash_seed *seed);
|
2019-03-11 20:03:14 +01:00
|
|
|
void fromwire_bip32_key_version(const u8 **cursor, size_t *max,
|
|
|
|
struct bip32_key_version *version);
|
2016-11-29 20:51:50 +01:00
|
|
|
#endif /* LIGHTNING_WIRE_WIRE_H */
|