diff --git a/Makefile b/Makefile index e36863bb0..d18ba821e 100644 --- a/Makefile +++ b/Makefile @@ -279,7 +279,7 @@ libsecp256k1.% libwallycore.%: libwally-core/src/secp256k1/libsecp256k1.la libwa libwally-core/src/libwallycore.% libwally-core/src/secp256k1/libsecp256k1.%: $(LIBWALLY_HEADERS) $(LIBSECP_HEADERS) cd libwally-core && ./tools/autogen.sh && ./configure CC="$(CC)" --enable-static=yes --enable-shared=no --libdir=`pwd`/.. && $(MAKE) -$(TEST_PROGRAMS): % : %.o $(BITCOIN_OBJS) $(LIBBASE58_OBJS) $(WIRE_OBJS) $(CCAN_OBJS) lightningd/sphinx.o common/utils.o libwallycore.a libsecp256k1.a libsodium.a +$(TEST_PROGRAMS): % : %.o $(BITCOIN_OBJS) $(LIBBASE58_OBJS) $(WIRE_OBJS) $(CCAN_OBJS) common/sphinx.o common/utils.o libwallycore.a libsecp256k1.a libsodium.a ccan/config.h: ccan/tools/configurator/configurator if $< > $@.new; then mv $@.new $@; else rm $@.new; exit 1; fi diff --git a/bitcoin/test/run-tx-encode.c b/bitcoin/test/run-tx-encode.c index f79e7ceec..1223bd46c 100644 --- a/bitcoin/test/run-tx-encode.c +++ b/bitcoin/test/run-tx-encode.c @@ -1,10 +1,10 @@ -#include "bitcoin/pullpush.c" -#include "bitcoin/tx.c" -#include "bitcoin/shadouble.c" -#include "bitcoin/varint.c" -#include "utils.c" #include +#include +#include +#include +#include #include +#include const char extended_tx[] = "02000000000101b5bef485c41d0d1f58d1e8a561924ece5c476d86cff063ea10c8df06136eb31d00000000171600144aa38e396e1394fb45cbf83f48d1464fbc9f498fffffffff0140330f000000000017a9140580ba016669d3efaf09a0b2ec3954469ea2bf038702483045022100f2abf9e9cf238c66533af93f23937eae8ac01fb6f105a00ab71dbefb9637dc9502205c1ac745829b3f6889607961f5d817dfa0c8f52bdda12e837c4f7b162f6db8a701210204096eb817f7efb414ef4d3d8be39dd04374256d3b054a322d4a6ee22736d03b00000000"; diff --git a/cli/Makefile b/cli/Makefile index 00fb72a08..fcba66c59 100644 --- a/cli/Makefile +++ b/cli/Makefile @@ -30,6 +30,8 @@ $(LIGHTNING_CLI_OBJS) $(JSMN_OBJS): $(JSMN_HEADERS) $(COMMON_HEADERS) $(CCAN_HEA cli/lightning-cli: $(LIGHTNING_CLI_OBJS) $(LIGHTNING_CLI_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS) +check-source: $(LIGHTNING_CLI_SRC:%=check-src-include-order/%) + clean: lightning-cli-clean lightning-cli-clean: diff --git a/common/Makefile b/common/Makefile index c40cb91fb..eacbd3843 100644 --- a/common/Makefile +++ b/common/Makefile @@ -1,18 +1,34 @@ COMMON_SRC := \ + common/bip32.c \ + common/channel_config.c \ common/close_tx.c \ common/configdir.c \ + common/crypto_sync.c \ + common/cryptomsg.c \ + common/daemon_conn.c \ + common/debug.c \ common/derive_basepoints.c \ + common/dev_disconnect.c \ common/funding_tx.c \ - common/htlc_tx.c \ common/htlc_state.c \ + common/htlc_tx.c \ + common/htlc_wire.c \ common/initial_channel.c \ common/initial_commit_tx.c \ common/json.c \ + common/key_derive.c \ + common/keyset.c \ + common/msg_queue.c \ + common/peer_failed.c \ common/permute_tx.c \ + common/ping.c \ common/pseudorand.c \ + common/sphinx.c \ + common/status.c \ common/timeout.c \ common/type_to_string.c \ common/utils.c \ + common/utxo.c \ common/version.c \ common/withdraw_tx.c diff --git a/lightningd/bip32.c b/common/bip32.c similarity index 95% rename from lightningd/bip32.c rename to common/bip32.c index 5839adcb8..f2c22870e 100644 --- a/lightningd/bip32.c +++ b/common/bip32.c @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/lightningd/bip32.h b/common/bip32.h similarity index 100% rename from lightningd/bip32.h rename to common/bip32.h diff --git a/lightningd/channel_config.c b/common/channel_config.c similarity index 95% rename from lightningd/channel_config.c rename to common/channel_config.c index 41b26d856..f4de14357 100644 --- a/lightningd/channel_config.c +++ b/common/channel_config.c @@ -1,4 +1,4 @@ -#include +#include #include void towire_channel_config(u8 **pptr, const struct channel_config *config) diff --git a/lightningd/channel_config.h b/common/channel_config.h similarity index 100% rename from lightningd/channel_config.h rename to common/channel_config.h diff --git a/lightningd/crypto_sync.c b/common/crypto_sync.c similarity index 91% rename from lightningd/crypto_sync.c rename to common/crypto_sync.c index b3abcfd09..878ff0628 100644 --- a/lightningd/crypto_sync.c +++ b/common/crypto_sync.c @@ -1,11 +1,11 @@ #include +#include +#include +#include +#include #include #include #include -#include -#include -#include -#include #include #include diff --git a/lightningd/crypto_sync.h b/common/crypto_sync.h similarity index 100% rename from lightningd/crypto_sync.h rename to common/crypto_sync.h diff --git a/lightningd/cryptomsg.c b/common/cryptomsg.c similarity index 98% rename from lightningd/cryptomsg.c rename to common/cryptomsg.c index d9b386d79..aeed15c35 100644 --- a/lightningd/cryptomsg.c +++ b/common/cryptomsg.c @@ -6,10 +6,10 @@ #include #include #include +#include +#include +#include #include -#include -#include -#include #include #include #include @@ -61,11 +61,13 @@ static void maybe_rotate_key(u64 *n, struct secret *k, struct secret *ck) * * `ck = ck'` */ hkdf_two_keys(&new_ck, &new_k, ck, k); +#ifdef SUPERVERBOSE status_trace("# 0x%s, 0x%s = HKDF(0x%s, 0x%s)", tal_hexstr(trc, &new_ck, sizeof(new_ck)), tal_hexstr(trc, &new_k, sizeof(new_k)), tal_hexstr(trc, ck, sizeof(*ck)), tal_hexstr(trc, k, sizeof(*k))); +#endif *ck = new_ck; *k = new_k; *n = 0; diff --git a/lightningd/cryptomsg.h b/common/cryptomsg.h similarity index 100% rename from lightningd/cryptomsg.h rename to common/cryptomsg.h diff --git a/lightningd/daemon_conn.c b/common/daemon_conn.c similarity index 98% rename from lightningd/daemon_conn.c rename to common/daemon_conn.c index 7353bf7b4..899a497e8 100644 --- a/lightningd/daemon_conn.c +++ b/common/daemon_conn.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include diff --git a/lightningd/daemon_conn.h b/common/daemon_conn.h similarity index 98% rename from lightningd/daemon_conn.h rename to common/daemon_conn.h index ebf46f800..eae98503f 100644 --- a/lightningd/daemon_conn.h +++ b/common/daemon_conn.h @@ -4,7 +4,7 @@ #include "config.h" #include #include -#include +#include struct daemon_conn { /* Context to tallocate all things from, possibly the diff --git a/lightningd/debug.c b/common/debug.c similarity index 89% rename from lightningd/debug.c rename to common/debug.c index c10d1f243..febedfe84 100644 --- a/lightningd/debug.c +++ b/common/debug.c @@ -1,6 +1,6 @@ #include -#include -#include +#include +#include #include #include #include diff --git a/lightningd/debug.h b/common/debug.h similarity index 100% rename from lightningd/debug.h rename to common/debug.h diff --git a/lightningd/dev_disconnect.c b/common/dev_disconnect.c similarity index 96% rename from lightningd/dev_disconnect.c rename to common/dev_disconnect.c index 4eb0c7343..b1fd99369 100644 --- a/lightningd/dev_disconnect.c +++ b/common/dev_disconnect.c @@ -1,8 +1,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include diff --git a/lightningd/dev_disconnect.h b/common/dev_disconnect.h similarity index 100% rename from lightningd/dev_disconnect.h rename to common/dev_disconnect.h diff --git a/common/funding_tx.c b/common/funding_tx.c index 77bdd1cae..6f3b8699b 100644 --- a/common/funding_tx.c +++ b/common/funding_tx.c @@ -4,9 +4,9 @@ #include #include #include +#include #include -#include -#include +#include #ifndef SUPERVERBOSE #define SUPERVERBOSE(...) diff --git a/common/htlc_tx.c b/common/htlc_tx.c index 64d712350..295ee647e 100644 --- a/common/htlc_tx.c +++ b/common/htlc_tx.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include static struct bitcoin_tx *htlc_tx(const tal_t *ctx, const struct sha256_double *commit_txid, diff --git a/lightningd/htlc_wire.c b/common/htlc_wire.c similarity index 99% rename from lightningd/htlc_wire.c rename to common/htlc_wire.c index 822576bf9..c6c5083a9 100644 --- a/lightningd/htlc_wire.c +++ b/common/htlc_wire.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include /* FIXME: We could adapt tools/generate-wire.py to generate structures diff --git a/lightningd/htlc_wire.h b/common/htlc_wire.h similarity index 98% rename from lightningd/htlc_wire.h rename to common/htlc_wire.h index c68901afc..70a0413b2 100644 --- a/lightningd/htlc_wire.h +++ b/common/htlc_wire.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include struct bitcoin_tx; diff --git a/common/initial_channel.c b/common/initial_channel.c index 03e7308c3..c4c47b696 100644 --- a/common/initial_channel.c +++ b/common/initial_channel.c @@ -3,9 +3,9 @@ #include #include #include +#include #include #include -#include struct channel *new_initial_channel(const tal_t *ctx, const struct sha256_double *funding_txid, diff --git a/common/initial_channel.h b/common/initial_channel.h index 13526e11e..a19f96d39 100644 --- a/common/initial_channel.h +++ b/common/initial_channel.h @@ -7,9 +7,9 @@ #include #include #include +#include #include #include -#include #include struct signature; diff --git a/common/initial_commit_tx.c b/common/initial_commit_tx.c index 5c923fcac..d4d6ed69b 100644 --- a/common/initial_commit_tx.c +++ b/common/initial_commit_tx.c @@ -2,9 +2,9 @@ #include #include #include +#include #include #include -#include /* BOLT #3: * diff --git a/lightningd/key_derive.c b/common/key_derive.c similarity index 99% rename from lightningd/key_derive.c rename to common/key_derive.c index 7668c6e2c..46a9bbf94 100644 --- a/lightningd/key_derive.c +++ b/common/key_derive.c @@ -1,8 +1,8 @@ #include #include #include +#include #include -#include #include /* BOLT #3: diff --git a/lightningd/key_derive.h b/common/key_derive.h similarity index 100% rename from lightningd/key_derive.h rename to common/key_derive.h diff --git a/lightningd/keyset.c b/common/keyset.c similarity index 96% rename from lightningd/keyset.c rename to common/keyset.c index 735686590..2e4d2b862 100644 --- a/lightningd/keyset.c +++ b/common/keyset.c @@ -1,5 +1,5 @@ -#include -#include +#include +#include bool derive_keyset(const struct pubkey *per_commitment_point, const struct pubkey *self_payment_basepoint, diff --git a/lightningd/keyset.h b/common/keyset.h similarity index 100% rename from lightningd/keyset.h rename to common/keyset.h diff --git a/lightningd/msg_queue.c b/common/msg_queue.c similarity index 97% rename from lightningd/msg_queue.c rename to common/msg_queue.c index 7a341b87b..37f1751f6 100644 --- a/lightningd/msg_queue.c +++ b/common/msg_queue.c @@ -1,6 +1,6 @@ #include #include -#include +#include #include void msg_queue_init(struct msg_queue *q, const tal_t *ctx) diff --git a/lightningd/msg_queue.h b/common/msg_queue.h similarity index 100% rename from lightningd/msg_queue.h rename to common/msg_queue.h diff --git a/lightningd/peer_failed.c b/common/peer_failed.c similarity index 91% rename from lightningd/peer_failed.c rename to common/peer_failed.c index c5b2709c2..686ae565b 100644 --- a/lightningd/peer_failed.c +++ b/common/peer_failed.c @@ -1,9 +1,9 @@ #include #include +#include +#include +#include #include -#include -#include -#include #include #include #include diff --git a/lightningd/peer_failed.h b/common/peer_failed.h similarity index 100% rename from lightningd/peer_failed.h rename to common/peer_failed.h diff --git a/lightningd/ping.c b/common/ping.c similarity index 97% rename from lightningd/ping.c rename to common/ping.c index ffdf766ad..519f9974d 100644 --- a/lightningd/ping.c +++ b/common/ping.c @@ -1,4 +1,4 @@ -#include +#include #include bool check_ping_make_pong(const tal_t *ctx, const u8 *ping, u8 **pong) diff --git a/lightningd/ping.h b/common/ping.h similarity index 100% rename from lightningd/ping.h rename to common/ping.h diff --git a/lightningd/sphinx.c b/common/sphinx.c similarity index 99% rename from lightningd/sphinx.c rename to common/sphinx.c index 66dbdabb4..66e361a51 100644 --- a/lightningd/sphinx.c +++ b/common/sphinx.c @@ -1,9 +1,9 @@ -#include "lightningd/sphinx.h" #include #include #include #include +#include #include #include diff --git a/lightningd/sphinx.h b/common/sphinx.h similarity index 100% rename from lightningd/sphinx.h rename to common/sphinx.h diff --git a/lightningd/status.c b/common/status.c similarity index 97% rename from lightningd/status.c rename to common/status.c index 81017dade..728df6bd8 100644 --- a/lightningd/status.c +++ b/common/status.c @@ -6,9 +6,9 @@ #include #include #include +#include +#include #include -#include -#include #include #include #include diff --git a/lightningd/status.h b/common/status.h similarity index 100% rename from lightningd/status.h rename to common/status.h diff --git a/lightningd/utxo.c b/common/utxo.c similarity index 97% rename from lightningd/utxo.c rename to common/utxo.c index e66d80f19..8da8a77bc 100644 --- a/lightningd/utxo.c +++ b/common/utxo.c @@ -1,4 +1,4 @@ -#include +#include #include void towire_utxo(u8 **pptr, const struct utxo *utxo) diff --git a/lightningd/utxo.h b/common/utxo.h similarity index 100% rename from lightningd/utxo.h rename to common/utxo.h diff --git a/common/withdraw_tx.c b/common/withdraw_tx.c index 6411d05db..4804d91ef 100644 --- a/common/withdraw_tx.c +++ b/common/withdraw_tx.c @@ -2,9 +2,9 @@ #include #include #include +#include #include -#include -#include +#include #include struct bitcoin_tx *withdraw_tx(const tal_t *ctx, diff --git a/lightningd/Makefile b/lightningd/Makefile index f43ef9584..64229cf24 100644 --- a/lightningd/Makefile +++ b/lightningd/Makefile @@ -12,48 +12,34 @@ default: lightningd-all # Common source we use. LIGHTNINGD_COMMON_OBJS := \ + common/bip32.o \ + common/channel_config.o \ common/configdir.o \ + common/cryptomsg.o \ common/derive_basepoints.o \ common/funding_tx.o \ common/htlc_state.o \ + common/htlc_wire.o \ + common/key_derive.o \ common/json.o \ + common/msg_queue.o \ common/permute_tx.o \ common/pseudorand.o \ + common/sphinx.o \ common/timeout.o \ common/type_to_string.o \ common/utils.o \ + common/utxo.o \ common/version.o \ common/withdraw_tx.o -# FIXME: put in a library so we don't link all of them. -LIGHTNINGD_LIB_SRC := \ - lightningd/bip32.c \ - lightningd/channel_config.c \ - lightningd/cryptomsg.c \ - lightningd/crypto_sync.c \ - lightningd/debug.c \ - lightningd/daemon_conn.c \ - lightningd/dev_disconnect.c \ - lightningd/gossip_msg.c \ - lightningd/htlc_wire.c \ - lightningd/key_derive.c \ - lightningd/keyset.c \ - lightningd/msg_queue.c \ - lightningd/peer_failed.c \ - lightningd/ping.c \ - lightningd/sphinx.c \ - lightningd/status.c \ - lightningd/utxo.c - -LIGHTNINGD_LIB_OBJS := $(LIGHTNINGD_LIB_SRC:.c=.o) -LIGHTNINGD_LIB_HEADERS := $(LIGHTNINGD_LIB_SRC:.c=.h) - LIGHTNINGD_SRC := \ lightningd/bitcoind.c \ lightningd/build_utxos.c \ lightningd/chaintopology.c \ lightningd/dns.c \ lightningd/gossip_control.c \ + lightningd/gossip_msg.c \ lightningd/hsm_control.c \ lightningd/htlc_end.c \ lightningd/invoice.c \ @@ -83,7 +69,6 @@ LIGHTNINGD_JSMN_HEADERS := daemon/jsmn/jsmn.h LIGHTNINGD_HEADERS_NOGEN = \ $(LIGHTNINGD_SRC:.c=.h) \ lightningd/peer_state.h \ - $(LIGHTNINGD_LIB_HEADERS) \ $(WIRE_HEADERS) \ $(BITCOIN_HEADERS) \ $(COMMON_HEADERS_NOGEN) \ @@ -117,28 +102,26 @@ include lightningd/channel/Makefile include lightningd/closing/Makefile include lightningd/onchain/Makefile -$(LIGHTNINGD_OBJS) $(LIGHTNINGD_LIB_OBJS): $(LIGHTNINGD_HEADERS) +$(LIGHTNINGD_OBJS): $(LIGHTNINGD_HEADERS) lightningd/gen_peer_state_names.h: lightningd/peer_state.h ccan/ccan/cdump/tools/cdump-enumstr ccan/ccan/cdump/tools/cdump-enumstr lightningd/peer_state.h > $@ check-source: $(LIGHTNINGD_SRC:%=check-src-include-order/%) $(LIGHTNINGD_SRC_NOHDR:%=check-src-include-order/%) -check-source: $(LIGHTNINGD_LIB_SRC:%=check-src-include-order/%) -check-source: $(LIGHTNINGD_CLI_SRC:%=check-src-include-order/%) check-source: $(LIGHTNINGD_HEADERS_NOGEN:%=check-hdr-include-order/%) -check-source-bolt: $(LIGHTNINGD_SRC:%=bolt-check/%) $(LIGHTNINGD_LIB_SRC:%=bolt-check/%) $(LIGHTNINGD_HEADERS_NOGEN:%=bolt-check/%) +check-source-bolt: $(LIGHTNINGD_SRC:%=bolt-check/%) $(LIGHTNINGD_HEADERS_NOGEN:%=bolt-check/%) -check-whitespace: $(LIGHTNINGD_SRC:%=check-whitespace/%) $(LIGHTNINGD_HEADERS_NOGEN:%=check-whitespace/%) $(LIGHTNINGD_LIB_SRC:%=check-whitespace/%) $(LIGHTNINGD_LIB_HEADERS:%=check-whitespace/%) +check-whitespace: $(LIGHTNINGD_SRC:%=check-whitespace/%) $(LIGHTNINGD_HEADERS_NOGEN:%=check-whitespace/%) check-makefile: check-lightningd-makefile check-lightningd-makefile: @for f in lightningd/*.h lightningd/*/*.h; do if ! echo $(LIGHTNINGD_HEADERS_NOGEN) $(LIGHTNINGD_HEADERS_GEN) "" | grep -q "$$f "; then echo $$f not mentioned in LIGHTNINGD_HEADERS_NOGEN or LIGHTNINGD_HEADERS_GEN >&2; exit 1; fi; done -lightningd/lightningd: $(LIGHTNINGD_OBJS) $(LIGHTNINGD_LIB_OBJS) $(LIGHTNINGD_COMMON_OBJS) $(LIGHTNINGD_JSMN_OBJS) $(BITCOIN_OBJS) $(WIRE_OBJS) $(WIRE_ONION_OBJS) $(CCAN_OBJS) $(CCAN_SHACHAIN48_OBJ) $(LIGHTNINGD_HSM_CONTROL_OBJS) $(LIGHTNINGD_HANDSHAKE_CONTROL_OBJS) $(LIGHTNINGD_GOSSIP_CONTROL_OBJS) $(LIBBASE58_OBJS) $(LIGHTNINGD_OPENING_CONTROL_OBJS) $(LIGHTNINGD_CHANNEL_CONTROL_OBJS) $(LIGHTNINGD_CLOSING_CONTROL_OBJS) $(LIGHTNINGD_ONCHAIN_CONTROL_OBJS) $(WALLET_LIB_OBJS) libsecp256k1.a libsodium.a libwallycore.a +lightningd/lightningd: $(LIGHTNINGD_OBJS) $(LIGHTNINGD_COMMON_OBJS) $(LIGHTNINGD_JSMN_OBJS) $(BITCOIN_OBJS) $(WIRE_OBJS) $(WIRE_ONION_OBJS) $(CCAN_OBJS) $(CCAN_SHACHAIN48_OBJ) $(LIGHTNINGD_HSM_CONTROL_OBJS) $(LIGHTNINGD_HANDSHAKE_CONTROL_OBJS) $(LIGHTNINGD_GOSSIP_CONTROL_OBJS) $(LIBBASE58_OBJS) $(LIGHTNINGD_OPENING_CONTROL_OBJS) $(LIGHTNINGD_CHANNEL_CONTROL_OBJS) $(LIGHTNINGD_CLOSING_CONTROL_OBJS) $(LIGHTNINGD_ONCHAIN_CONTROL_OBJS) $(WALLET_LIB_OBJS) libsecp256k1.a libsodium.a libwallycore.a clean: lightningd-clean lightningd-clean: - $(RM) $(LIGHTNINGD_OBJS) $(LIGHTNINGD_LIB_OBJS) $(LIGHTNINGD_JSMN_OBJS) $(LIGHTNINGD_BINS) + $(RM) $(LIGHTNINGD_OBJS) $(LIGHTNINGD_JSMN_OBJS) $(LIGHTNINGD_BINS) include lightningd/test/Makefile diff --git a/lightningd/build_utxos.h b/lightningd/build_utxos.h index 706fcaf8b..f97726335 100644 --- a/lightningd/build_utxos.h +++ b/lightningd/build_utxos.h @@ -1,8 +1,8 @@ #ifndef LIGHTNING_LIGHTNINGD_BUILD_UTXOS_H #define LIGHTNING_LIGHTNINGD_BUILD_UTXOS_H #include "config.h" +#include #include -#include /* Reserves UTXOs to build tx which pays this amount; returns NULL if * impossible. *change_satoshis 0 if no change needed. */ diff --git a/lightningd/channel/Makefile b/lightningd/channel/Makefile index dd64d2c72..0c78deb0d 100644 --- a/lightningd/channel/Makefile +++ b/lightningd/channel/Makefile @@ -27,13 +27,27 @@ LIGHTNINGD_CHANNEL_OBJS := $(LIGHTNINGD_CHANNEL_SRC:.c=.o) # Common source we use. CHANNELD_COMMON_OBJS := \ + common/channel_config.o \ + common/crypto_sync.o \ + common/cryptomsg.o \ + common/daemon_conn.o \ + common/debug.o \ common/derive_basepoints.o \ + common/dev_disconnect.o \ common/htlc_state.o \ common/htlc_tx.o \ + common/htlc_wire.o \ common/initial_channel.o \ common/initial_commit_tx.o \ + common/keyset.o \ + common/key_derive.o \ + common/msg_queue.o \ + common/ping.o \ + common/peer_failed.o \ common/permute_tx.o \ common/pseudorand.o \ + common/sphinx.o \ + common/status.o \ common/timeout.o \ common/type_to_string.o \ common/utils.o \ @@ -62,7 +76,7 @@ lightningd/channel/gen_channel_wire.c: $(WIRE_GEN) lightningd/channel/channel_wi LIGHTNINGD_CHANNEL_OBJS := $(LIGHTNINGD_CHANNEL_SRC:.c=.o) $(LIGHTNINGD_CHANNEL_GEN_SRC:.c=.o) -lightningd/lightningd_channel: $(LIGHTNINGD_OLD_LIB_OBJS) $(LIGHTNINGD_LIB_OBJS) $(LIGHTNINGD_CHANNEL_OBJS) $(WIRE_ONION_OBJS) $(CHANNELD_COMMON_OBJS) $(WIRE_OBJS) $(BITCOIN_OBJS) $(CCAN_OBJS) $(CCAN_SHACHAIN48_OBJ) $(LIGHTNINGD_HSM_CLIENT_OBJS) $(LIBBASE58_OBJS) libsecp256k1.a libsodium.a libwallycore.a +lightningd/lightningd_channel: $(LIGHTNINGD_CHANNEL_OBJS) $(WIRE_ONION_OBJS) $(CHANNELD_COMMON_OBJS) $(WIRE_OBJS) $(BITCOIN_OBJS) $(CCAN_OBJS) $(CCAN_SHACHAIN48_OBJ) $(LIGHTNINGD_HSM_CLIENT_OBJS) $(LIBBASE58_OBJS) libsecp256k1.a libsodium.a libwallycore.a $(CC) $(CFLAGS) -o $@ $^ $(LDLIBS) check-source: $(LIGHTNINGD_CHANNEL_SRC_NOGEN:%=check-src-include-order/%) diff --git a/lightningd/channel/channel.c b/lightningd/channel/channel.c index a2023ccc1..405ec0f2a 100644 --- a/lightningd/channel/channel.c +++ b/lightningd/channel/channel.c @@ -11,8 +11,18 @@ #include #include #include +#include +#include +#include +#include #include #include +#include +#include +#include +#include +#include +#include #include #include #include @@ -21,18 +31,8 @@ #include #include #include -#include -#include -#include -#include #include #include -#include -#include -#include -#include -#include -#include #include #include #include diff --git a/lightningd/channel/channel_wire.csv b/lightningd/channel/channel_wire.csv index 980302660..b4ba95362 100644 --- a/lightningd/channel/channel_wire.csv +++ b/lightningd/channel/channel_wire.csv @@ -17,8 +17,8 @@ channel_peer_bad_message,,msg,len*u8 # Received and sent funding_locked channel_normal_operation,1001 -#include -#include +#include +#include # Begin! (passes gossipd-client fd) channel_init,1 @@ -161,7 +161,7 @@ channel_got_commitsig,,tx,struct bitcoin_tx # Wait for reply, to make sure it's on disk before we send revocation. channel_got_commitsig_reply,121 -#include +#include channel_got_revoke,22 channel_got_revoke,,revokenum,u64 diff --git a/lightningd/channel/commit_tx.c b/lightningd/channel/commit_tx.c index d70b23ac2..d83ca8540 100644 --- a/lightningd/channel/commit_tx.c +++ b/lightningd/channel/commit_tx.c @@ -2,10 +2,10 @@ #include #include #include +#include #include #include #include -#include #ifndef SUPERVERBOSE #define SUPERVERBOSE(...) diff --git a/lightningd/channel/full_channel.c b/lightningd/channel/full_channel.c index c1e48d6bb..c750e7969 100644 --- a/lightningd/channel/full_channel.c +++ b/lightningd/channel/full_channel.c @@ -6,17 +6,17 @@ #include #include #include +#include #include #include +#include +#include +#include +#include #include #include #include #include -#include -#include -#include -#include -#include #include struct channel *new_channel(const tal_t *ctx, diff --git a/lightningd/channel/full_channel.h b/lightningd/channel/full_channel.h index 518a8c8b1..1132a8239 100644 --- a/lightningd/channel/full_channel.h +++ b/lightningd/channel/full_channel.h @@ -3,8 +3,8 @@ #define LIGHTNING_LIGHTNINGD_CHANNEL_H #include "config.h" #include +#include #include -#include /** * new_channel: Given initial fees and funding, what is initial state? diff --git a/lightningd/closing/Makefile b/lightningd/closing/Makefile index f41816c57..86929365f 100644 --- a/lightningd/closing/Makefile +++ b/lightningd/closing/Makefile @@ -38,8 +38,16 @@ $(LIGHTNINGD_CLOSING_OBJS): $(LIGHTNINGD_HEADERS) # Common source we use. CLOSINGD_COMMON_OBJS := \ common/close_tx.o \ + common/crypto_sync.o \ + common/cryptomsg.o \ + common/daemon_conn.o \ + common/debug.o \ + common/dev_disconnect.o \ common/derive_basepoints.o \ + common/htlc_wire.o \ + common/msg_queue.o \ common/permute_tx.o \ + common/status.o \ common/type_to_string.o \ common/utils.o \ common/version.o @@ -52,7 +60,7 @@ lightningd/closing/gen_closing_wire.c: $(WIRE_GEN) lightningd/closing/closing_wi LIGHTNINGD_CLOSING_OBJS := $(LIGHTNINGD_CLOSING_SRC:.c=.o) $(LIGHTNINGD_CLOSING_GEN_SRC:.c=.o) -lightningd/lightningd_closing: $(LIGHTNINGD_OLD_LIB_OBJS) $(LIGHTNINGD_LIB_OBJS) $(LIGHTNINGD_CLOSING_OBJS) $(WIRE_ONION_OBJS) $(CLOSINGD_COMMON_OBJS) $(WIRE_OBJS) $(BITCOIN_OBJS) $(CCAN_OBJS) $(CCAN_SHACHAIN48_OBJ) $(LIGHTNINGD_HSM_CLIENT_OBJS) $(LIBBASE58_OBJS) libsecp256k1.a libsodium.a libwallycore.a +lightningd/lightningd_closing: $(LIGHTNINGD_CLOSING_OBJS) $(WIRE_ONION_OBJS) $(CLOSINGD_COMMON_OBJS) $(WIRE_OBJS) $(BITCOIN_OBJS) $(CCAN_OBJS) $(CCAN_SHACHAIN48_OBJ) $(LIGHTNINGD_HSM_CLIENT_OBJS) $(LIBBASE58_OBJS) libsecp256k1.a libsodium.a libwallycore.a $(CC) $(CFLAGS) -o $@ $^ $(LDLIBS) check-source: $(LIGHTNINGD_CLOSING_SRC_NOGEN:%=check-src-include-order/%) diff --git a/lightningd/closing/closing.c b/lightningd/closing/closing.c index 26d29e2aa..1b9e736d1 100644 --- a/lightningd/closing/closing.c +++ b/lightningd/closing/closing.c @@ -1,19 +1,19 @@ #include #include +#include +#include #include #include +#include #include #include #include #include #include #include -#include -#include -#include -#include #include #include +#include #include #include diff --git a/lightningd/closing/closing_wire.csv b/lightningd/closing/closing_wire.csv index 91ba9494a..dae40f911 100644 --- a/lightningd/closing/closing_wire.csv +++ b/lightningd/closing/closing_wire.csv @@ -14,8 +14,8 @@ closing_negotiation_error,0x8013 closing_negotiation_error,,len,u16 closing_negotiation_error,,msg,len*u8 -#include -#include +#include +#include # Begin! (passes peer fd, gossipd-client fd) closing_init,1 closing_init,,crypto_state,struct crypto_state diff --git a/lightningd/dev_ping.c b/lightningd/dev_ping.c index 7feb7ef7a..4491df4ad 100644 --- a/lightningd/dev_ping.c +++ b/lightningd/dev_ping.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -6,7 +7,6 @@ #include #include #include -#include #include static bool ping_reply(struct subd *subd, const u8 *msg, const int *fds, diff --git a/lightningd/gossip/Makefile b/lightningd/gossip/Makefile index 6f8f6a424..04525b9ec 100644 --- a/lightningd/gossip/Makefile +++ b/lightningd/gossip/Makefile @@ -28,11 +28,20 @@ LIGHTNINGD_HEADERS_GEN += $(LIGHTNINGD_GOSSIP_HEADERS) # Common source we use. GOSSIPD_COMMON_OBJS := \ + common/crypto_sync.o \ + common/cryptomsg.o \ + common/daemon_conn.o \ + common/debug.o \ + common/dev_disconnect.o \ + common/msg_queue.o \ + common/ping.o \ common/pseudorand.o \ + common/status.o \ common/timeout.o \ common/type_to_string.o \ common/utils.o \ - common/version.o + common/version.o \ + lightningd/gossip_msg.o $(LIGHTNINGD_GOSSIP_OBJS) $(LIGHTNINGD_GOSSIP_CLIENT_OBJS): $(LIGHTNINGD_HEADERS) @@ -40,7 +49,7 @@ $(LIGHTNINGD_GOSSIP_CONTROL_OBJS) : $(LIGHTNINGD_GOSSIP_CONTROL_HEADERS) lightningd/gossip-all: lightningd/lightningd_gossip $(LIGHTNINGD_GOSSIP_CLIENT_OBJS) -lightningd/lightningd_gossip: $(LIGHTNINGD_GOSSIP_OBJS) $(GOSSIPD_COMMON_OBJS) $(BITCOIN_OBJS) $(WIRE_OBJS) $(CCAN_OBJS) $(CCAN_SHACHAIN48_OBJ) $(LIGHTNINGD_OLD_LIB_OBJS) $(LIGHTNINGD_LIB_OBJS) $(LIBBASE58_OBJS) libsecp256k1.a libsodium.a libwallycore.a +lightningd/lightningd_gossip: $(LIGHTNINGD_GOSSIP_OBJS) $(GOSSIPD_COMMON_OBJS) $(BITCOIN_OBJS) $(WIRE_OBJS) $(CCAN_OBJS) $(CCAN_SHACHAIN48_OBJ) $(LIBBASE58_OBJS) libsecp256k1.a libsodium.a libwallycore.a $(CC) $(CFLAGS) -o $@ $^ $(LDLIBS) lightningd/gossip/gen_gossip_wire.h: $(WIRE_GEN) lightningd/gossip/gossip_wire.csv diff --git a/lightningd/gossip/gossip.c b/lightningd/gossip/gossip.c index c31b7fdf2..c84a4ac7c 100644 --- a/lightningd/gossip/gossip.c +++ b/lightningd/gossip/gossip.c @@ -10,6 +10,11 @@ #include #include #include +#include +#include +#include +#include +#include #include #include #include @@ -17,15 +22,10 @@ #include #include #include -#include -#include -#include #include #include #include #include -#include -#include #include #include #include diff --git a/lightningd/gossip/gossip_wire.csv b/lightningd/gossip/gossip_wire.csv index f12602cf9..27e1788d6 100644 --- a/lightningd/gossip/gossip_wire.csv +++ b/lightningd/gossip/gossip_wire.csv @@ -18,7 +18,7 @@ gossipstatus_peer_failed,,unique_id,8 gossipstatus_peer_failed,,len,2 gossipstatus_peer_failed,,err,len*u8 -#include +#include # Initialize the gossip daemon gossipctl_init,0 diff --git a/lightningd/gossip/routing.c b/lightningd/gossip/routing.c index fddad4860..c978aa357 100644 --- a/lightningd/gossip/routing.c +++ b/lightningd/gossip/routing.c @@ -8,10 +8,9 @@ #include #include #include +#include #include #include -#include -#include #include /* 365.25 * 24 * 60 / 10 */ @@ -463,48 +462,6 @@ find_route(const tal_t *ctx, struct routing_state *rstate, return first_conn; } -static bool get_slash_u32(const char **arg, u32 *v) -{ - size_t len; - char *endp; - - if (**arg != '/') - return false; - (*arg)++; - len = strcspn(*arg, "/"); - *v = strtoul(*arg, &endp, 10); - (*arg) += len; - return (endp == *arg); -} - -/* srcid/dstid/base/var/delay/minblocks */ -char *opt_add_route(const char *arg, struct lightningd_state *dstate) -{ - size_t len; - struct pubkey src, dst; - u32 base, var, delay, minblocks; - - len = strcspn(arg, "/"); - if (!pubkey_from_hexstr(arg, len, &src)) - return "Bad src pubkey"; - arg += len + 1; - len = strcspn(arg, "/"); - if (!pubkey_from_hexstr(arg, len, &dst)) - return "Bad dst pubkey"; - arg += len; - - if (!get_slash_u32(&arg, &base) - || !get_slash_u32(&arg, &var) - || !get_slash_u32(&arg, &delay) - || !get_slash_u32(&arg, &minblocks)) - return "Bad base/var/delay/minblocks"; - if (*arg) - return "Data after minblocks"; - - add_connection(dstate->rstate, &src, &dst, base, var, delay, minblocks); - return NULL; -} - bool add_channel_direction(struct routing_state *rstate, const struct pubkey *from, const struct pubkey *to, diff --git a/lightningd/gossip/routing.h b/lightningd/gossip/routing.h index a7fffdb7c..610449cd1 100644 --- a/lightningd/gossip/routing.h +++ b/lightningd/gossip/routing.h @@ -151,8 +151,6 @@ find_route(const tal_t *ctx, struct routing_state *rstate, struct node_map *empty_node_map(const tal_t *ctx); -char *opt_add_route(const char *arg, struct lightningd_state *dstate); - bool add_channel_direction(struct routing_state *rstate, const struct pubkey *from, const struct pubkey *to, diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index a1d955ddb..3458b7f9f 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include diff --git a/lightningd/handshake/Makefile b/lightningd/handshake/Makefile index 6e4c9f67b..dcde84670 100644 --- a/lightningd/handshake/Makefile +++ b/lightningd/handshake/Makefile @@ -31,6 +31,13 @@ $(LIGHTNINGD_HANDSHAKE_OBJS): $(LIGHTNINGD_HEADERS) # Common source we use. HANDSHAKED_COMMON_OBJS := \ + common/crypto_sync.o \ + common/cryptomsg.o \ + common/daemon_conn.o \ + common/debug.o \ + common/dev_disconnect.o \ + common/msg_queue.o \ + common/status.o \ common/type_to_string.o \ common/utils.o \ common/version.o diff --git a/lightningd/handshake/handshake.c b/lightningd/handshake/handshake.c index 830f7e97f..6d8f20491 100644 --- a/lightningd/handshake/handshake.c +++ b/lightningd/handshake/handshake.c @@ -7,14 +7,14 @@ #include #include #include +#include +#include +#include #include #include #include -#include -#include #include #include -#include #include #include #include diff --git a/lightningd/handshake/handshake_wire.csv b/lightningd/handshake/handshake_wire.csv index 00aa3fc15..7c0e19a24 100644 --- a/lightningd/handshake/handshake_wire.csv +++ b/lightningd/handshake/handshake_wire.csv @@ -1,4 +1,4 @@ -#include +#include handshake_bad_command,0x8000 initr_act1_bad_ecdh_for_ss,0x8011 initr_act1_write_failed,0x8012 diff --git a/lightningd/handshake/test/Makefile b/lightningd/handshake/test/Makefile index 1ae9ffeed..8fbb034e3 100644 --- a/lightningd/handshake/test/Makefile +++ b/lightningd/handshake/test/Makefile @@ -6,11 +6,22 @@ LIGHTNINGD_HANDSHAKE_TEST_SRC := $(wildcard lightningd/handshake/test/run-*.c) LIGHTNINGD_HANDSHAKE_TEST_OBJS := $(LIGHTNINGD_HANDSHAKE_TEST_SRC:.c=.o) LIGHTNINGD_HANDSHAKE_TEST_PROGRAMS := $(LIGHTNINGD_HANDSHAKE_TEST_OBJS:.o=) +LIGHTNINGD_HANDSHAKE_TEST_COMMON_OBJS := \ + common/cryptomsg.o \ + common/daemon_conn.o \ + common/dev_disconnect.o \ + common/htlc_state.o \ + common/msg_queue.o \ + common/pseudorand.o \ + common/status.o \ + common/type_to_string.o \ + common/utils.o + update-mocks: $(LIGHTNINGD_HANDSHAKE_TEST_SRC:%=update-mocks/%) -$(LIGHTNINGD_HANDSHAKE_TEST_PROGRAMS): $(CCAN_OBJS) $(CCAN_SHACHAIN48_OBJ) $(BITCOIN_OBJS) $(CORE_TX_OBJS) $(CORE_OBJS) $(WIRE_OBJS) $(LIBBASE58_OBJS) $(LIGHTNINGD_LIB_OBJS) $(LIGHTNINGD_OLD_LIB_OBJS) libsecp256k1.a libsodium.a utils.o $(LIGHTNINGD_HANDSHAKE_GEN_SRC:.c=.o) libwallycore.a +$(LIGHTNINGD_HANDSHAKE_TEST_PROGRAMS): $(CCAN_OBJS) $(CCAN_SHACHAIN48_OBJ) $(BITCOIN_OBJS) $(WIRE_OBJS) $(LIBBASE58_OBJS) libsecp256k1.a libsodium.a $(LIGHTNINGD_HANDSHAKE_TEST_COMMON_OBJS) $(LIGHTNINGD_HANDSHAKE_GEN_SRC:.c=.o) libwallycore.a -$(LIGHTNINGD_HANDSHAKE_TEST_OBJS): $(LIGHTNINGD_HANDSHAKE_HEADERS) $(LIGHTNINGD_LIB_HEADERS) $(BITCOIN_HEADERS) $(CORE_HEADERS) $(GEN_HEADERS) $(WIRE_HEADERS) $(CCAN_HEADERS) $(LIBBASE58_HEADERS) $(LIBSODIUM_HEADERS) +$(LIGHTNINGD_HANDSHAKE_TEST_OBJS): $(LIGHTNINGD_HANDSHAKE_HEADERS) $(BITCOIN_HEADERS) $(GEN_HEADERS) $(WIRE_HEADERS) $(CCAN_HEADERS) $(LIBBASE58_HEADERS) $(LIBSODIUM_HEADERS) lightningd/handshake-tests: $(LIGHTNINGD_HANDSHAKE_TEST_PROGRAMS:%=unittest/%) diff --git a/lightningd/handshake/test/run-handshake.c b/lightningd/handshake/test/run-handshake.c index 8d0eba46e..23cf665ea 100644 --- a/lightningd/handshake/test/run-handshake.c +++ b/lightningd/handshake/test/run-handshake.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include /* Since we use pipes, we need different fds for read and write. */ static int read_fd, write_fd; @@ -50,7 +50,7 @@ static unsigned char e_priv[32]; #define TESTING #include "../handshake.c" -#include "utils.h" +#include #include secp256k1_context *secp256k1_ctx; diff --git a/lightningd/hsm/Makefile b/lightningd/hsm/Makefile index aa1a5f1a9..a1722653e 100644 --- a/lightningd/hsm/Makefile +++ b/lightningd/hsm/Makefile @@ -25,9 +25,15 @@ LIGHTNINGD_HSM_OBJS := $(LIGHTNINGD_HSM_SRC:.c=.o) # Common source we use. HSMD_COMMON_OBJS := \ + common/bip32.o \ + common/daemon_conn.o \ common/funding_tx.o \ + common/key_derive.o \ + common/msg_queue.o \ common/permute_tx.o \ + common/status.o \ common/utils.o \ + common/utxo.o \ common/version.o \ common/withdraw_tx.o @@ -46,7 +52,7 @@ $(LIGHTNINGD_HSM_OBJS): $(COMMON_HEADERS) lightningd/hsm-all: lightningd/lightningd_hsm $(LIGHTNINGD_HSM_CLIENT_OBJS) -lightningd/lightningd_hsm: $(LIGHTNINGD_HSM_OBJS) $(LIGHTNINGD_OLD_LIB_OBJS) $(LIGHTNINGD_LIB_OBJS) $(HSMD_COMMON_OBJS) $(BITCOIN_OBJS) $(WIRE_OBJS) $(CCAN_OBJS) $(CCAN_SHACHAIN48_OBJ) $(LIBBASE58_OBJS) lightningd/utxo.o libsecp256k1.a libsodium.a libwallycore.a +lightningd/lightningd_hsm: $(LIGHTNINGD_HSM_OBJS) $(LIGHTNINGD_OLD_LIB_OBJS) $(LIGHTNINGD_LIB_OBJS) $(HSMD_COMMON_OBJS) $(BITCOIN_OBJS) $(WIRE_OBJS) $(CCAN_OBJS) $(CCAN_SHACHAIN48_OBJ) $(LIBBASE58_OBJS) libsecp256k1.a libsodium.a libwallycore.a $(CC) $(CFLAGS) -o $@ $^ $(LDLIBS) lightningd/hsm/gen_hsm_client_wire.h: $(WIRE_GEN) lightningd/hsm/hsm_client_wire_csv diff --git a/lightningd/hsm/hsm.c b/lightningd/hsm/hsm.c index bc8235aed..35a8aa304 100644 --- a/lightningd/hsm/hsm.c +++ b/lightningd/hsm/hsm.c @@ -14,19 +14,18 @@ #include #include #include +#include #include +#include #include #include #include #include #include #include -#include -#include #include #include #include -#include #include #include #include diff --git a/lightningd/hsm/hsm_wire.csv b/lightningd/hsm/hsm_wire.csv index 135c8077b..228e90521 100644 --- a/lightningd/hsm/hsm_wire.csv +++ b/lightningd/hsm/hsm_wire.csv @@ -15,7 +15,7 @@ hsmstatus_client_bad_request,,msg,len*u8 hsmctl_init,1 hsmctl_init,,new,bool -#include +#include hsmctl_init_reply,101 hsmctl_init_reply,,node_id,33 hsmctl_init_reply,,peer_seed,struct secret @@ -29,7 +29,7 @@ hsmctl_hsmfd_ecdh,,unique_id,8 hsmctl_hsmfd_ecdh_fd_reply,103 # Return signature for a funding tx. -#include +#include # FIXME: This should also take their commit sig & details, to verify. hsmctl_sign_funding,4 hsmctl_sign_funding,,satoshi_out,8 diff --git a/lightningd/hsm_control.c b/lightningd/hsm_control.c index bc42e8933..057d58ff7 100644 --- a/lightningd/hsm_control.c +++ b/lightningd/hsm_control.c @@ -1,16 +1,15 @@ #include "hsm_control.h" #include "lightningd.h" -#include "peer_control.h" #include "subd.h" #include #include #include +#include #include #include #include #include #include -#include #include #include #include diff --git a/lightningd/htlc_end.h b/lightningd/htlc_end.h index a0dfa88b0..6a7d8f108 100644 --- a/lightningd/htlc_end.h +++ b/lightningd/htlc_end.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include /* We look up HTLCs by peer & id */ diff --git a/lightningd/new_connection.c b/lightningd/new_connection.c index 18824ea19..e887eac5a 100644 --- a/lightningd/new_connection.c +++ b/lightningd/new_connection.c @@ -1,9 +1,9 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include diff --git a/lightningd/onchain/Makefile b/lightningd/onchain/Makefile index 20747d21b..e31859833 100644 --- a/lightningd/onchain/Makefile +++ b/lightningd/onchain/Makefile @@ -47,10 +47,18 @@ $(LIGHTNINGD_ONCHAIN_OBJS): $(LIGHTNINGD_HEADERS) # Common source we use. ONCHAIND_COMMON_OBJS := \ + common/daemon_conn.o \ + common/debug.o \ common/derive_basepoints.o \ - common/initial_commit_tx.o \ + common/dev_disconnect.o \ common/htlc_tx.o \ + common/htlc_wire.o \ + common/initial_commit_tx.o \ + common/keyset.o \ + common/key_derive.o \ + common/msg_queue.o \ common/permute_tx.o \ + common/status.o \ common/type_to_string.o \ common/utils.o \ common/version.o @@ -63,7 +71,7 @@ lightningd/onchain/gen_onchain_wire.c: $(WIRE_GEN) lightningd/onchain/onchain_wi LIGHTNINGD_ONCHAIN_OBJS := $(LIGHTNINGD_ONCHAIN_SRC:.c=.o) $(LIGHTNINGD_ONCHAIN_GEN_SRC:.c=.o) -lightningd/lightningd_onchain: $(LIGHTNINGD_OLD_LIB_OBJS) $(LIGHTNINGD_LIB_OBJS) $(LIGHTNINGD_ONCHAIN_OBJS) $(WIRE_ONION_OBJS) $(ONCHAIND_COMMON_OBJS) $(WIRE_OBJS) $(BITCOIN_OBJS) $(CCAN_OBJS) $(CCAN_SHACHAIN48_OBJ) $(LIGHTNINGD_HSM_CLIENT_OBJS) $(LIBBASE58_OBJS) libsecp256k1.a libsodium.a libwallycore.a +lightningd/lightningd_onchain: $(LIGHTNINGD_ONCHAIN_OBJS) $(WIRE_ONION_OBJS) $(ONCHAIND_COMMON_OBJS) $(WIRE_OBJS) $(BITCOIN_OBJS) $(CCAN_OBJS) $(CCAN_SHACHAIN48_OBJ) $(LIGHTNINGD_HSM_CLIENT_OBJS) $(LIBBASE58_OBJS) libsecp256k1.a libsodium.a libwallycore.a $(CC) $(CFLAGS) -o $@ $^ $(LDLIBS) check-source: $(LIGHTNINGD_ONCHAIN_SRC_NOGEN:%=check-src-include-order/%) diff --git a/lightningd/onchain/onchain.c b/lightningd/onchain/onchain.c index e469d9388..5c031ce80 100644 --- a/lightningd/onchain/onchain.c +++ b/lightningd/onchain/onchain.c @@ -3,24 +3,24 @@ #include #include #include +#include #include #include #include +#include +#include +#include #include #include #include #include #include -#include -#include -#include #include #include #include -#include -#include #include #include +#include #include #include "gen_onchain_types_names.h" diff --git a/lightningd/onchain/onchain_wire.c b/lightningd/onchain/onchain_wire.c index 3a895bd0e..02ec01e09 100644 --- a/lightningd/onchain/onchain_wire.c +++ b/lightningd/onchain/onchain_wire.c @@ -1,5 +1,5 @@ #include -#include +#include #include #include diff --git a/lightningd/onchain/onchain_wire.csv b/lightningd/onchain/onchain_wire.csv index d812c6047..6a9a438a7 100644 --- a/lightningd/onchain/onchain_wire.csv +++ b/lightningd/onchain/onchain_wire.csv @@ -3,7 +3,7 @@ onchain_bad_command,0x8000 onchain_internal_error,0x8003 onchain_crypto_failed,0x8004 -#include +#include # Begin! Here's the onchain tx which spends funding tx, followed by all HTLCs. onchain_init,1 onchain_init,,seed,struct privkey diff --git a/lightningd/opening/Makefile b/lightningd/opening/Makefile index 843ec1abe..4b1894de9 100644 --- a/lightningd/opening/Makefile +++ b/lightningd/opening/Makefile @@ -35,14 +35,29 @@ LIGHTNINGD_HEADERS_NOGEN += $(LIGHTNINGD_OPENING_HEADERS_NOGEN) # Common source we use. OPENINGD_COMMON_OBJS := \ + common/bip32.o \ + common/channel_config.o \ + common/crypto_sync.o \ + common/cryptomsg.o \ + common/daemon_conn.o \ + common/debug.o \ common/derive_basepoints.o \ + common/dev_disconnect.o \ common/funding_tx.o \ + common/htlc_wire.o \ common/initial_channel.o \ common/initial_commit_tx.o \ + common/key_derive.o \ + common/keyset.o \ + common/msg_queue.o \ + common/ping.o \ + common/peer_failed.o \ common/permute_tx.o \ common/pseudorand.o \ + common/status.o \ common/type_to_string.o \ common/utils.o \ + common/utxo.o \ common/version.o $(LIGHTNINGD_OPENING_OBJS): $(LIGHTNINGD_HEADERS) @@ -55,7 +70,7 @@ lightningd/opening/gen_opening_wire.c: $(WIRE_GEN) lightningd/opening/opening_wi LIGHTNINGD_OPENING_OBJS := $(LIGHTNINGD_OPENING_SRC:.c=.o) $(LIGHTNINGD_OPENING_GEN_SRC:.c=.o) -lightningd/lightningd_opening: $(LIGHTNINGD_OLD_LIB_OBJS) $(LIGHTNINGD_LIB_OBJS) $(LIGHTNINGD_OPENING_OBJS) $(OPENINGD_COMMON_OBJS) $(WIRE_OBJS) $(BITCOIN_OBJS) $(CCAN_OBJS) $(CCAN_SHACHAIN48_OBJ) $(LIGHTNINGD_HSM_CLIENT_OBJS) $(LIBBASE58_OBJS) libsecp256k1.a libsodium.a libwallycore.a +lightningd/lightningd_opening: $(LIGHTNINGD_OPENING_OBJS) $(OPENINGD_COMMON_OBJS) $(WIRE_OBJS) $(BITCOIN_OBJS) $(CCAN_OBJS) $(CCAN_SHACHAIN48_OBJ) $(LIGHTNINGD_HSM_CLIENT_OBJS) $(LIBBASE58_OBJS) libsecp256k1.a libsodium.a libwallycore.a $(CC) $(CFLAGS) -o $@ $^ $(LDLIBS) check-source: $(LIGHTNINGD_OPENING_SRC_NOGEN:%=check-src-include-order/%) diff --git a/lightningd/opening/opening.c b/lightningd/opening/opening.c index 08518ab66..98aa237e1 100644 --- a/lightningd/opening/opening.c +++ b/lightningd/opening/opening.c @@ -5,21 +5,21 @@ #include #include #include +#include +#include #include #include #include +#include +#include +#include #include +#include #include #include #include #include -#include -#include -#include #include -#include -#include -#include #include #include #include diff --git a/lightningd/opening/opening_wire.csv b/lightningd/opening/opening_wire.csv index e907cd063..4fa291eee 100644 --- a/lightningd/opening/opening_wire.csv +++ b/lightningd/opening/opening_wire.csv @@ -11,8 +11,8 @@ opening_peer_bad_funding,0x8012 opening_peer_bad_config,0x8013 opening_peer_bad_initial_message,0x8014 -#include -#include +#include +#include opening_init,0 # Which network are we configured for (as index into the chainparams)? opening_init,,network_index,4 @@ -25,8 +25,8 @@ opening_init,,crypto_state,struct crypto_state # Seed to generate all the keys from opening_init,,seed,struct privkey -#include -#include +#include +#include # This means we offer the open. opening_funder,1 opening_funder,,funding_satoshis,8 @@ -36,7 +36,7 @@ opening_funder,,max_minimum_depth,4 opening_funder,,change_satoshis,u64 opening_funder,,change_keyindex,u32 opening_funder,,channel_flags,u8 -#include +#include opening_funder,,num_inputs,u16 opening_funder,,inputs,num_inputs*struct utxo opening_funder,,bip32,struct ext_key diff --git a/lightningd/pay.c b/lightningd/pay.c index 85626ddf6..7ff36d9f1 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index c53976017..86e3f0c82 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -9,8 +9,11 @@ #include #include #include +#include #include #include +#include +#include #include #include #include @@ -19,21 +22,18 @@ #include #include #include -#include #include #include #include #include #include #include -#include #include #include #include #include #include #include -#include #include #include #include @@ -252,11 +252,26 @@ static void peer_start_closingd(struct peer *peer, int peer_fd, int gossip_fd, bool reconnected); +/* FIXME: Fake NOP dev_disconnect/dev_sabotage_fd for below. */ +char dev_disconnect(int pkt_type) +{ + return DEV_DISCONNECT_NORMAL; +} + +void dev_sabotage_fd(int fd) +{ + abort(); +} + /* Send (encrypted) error message, then close. */ static struct io_plan *send_error(struct io_conn *conn, struct peer_crypto_state *pcs) { log_debug(pcs->peer->log, "Sending canned error"); + /* FIXME: This is the only place where master talks directly to peer; + * and pulls in quite a lot of code to do so. If we got a subdaemon + * to do this work, we'd avoid pulling in cryptomsg.o and the fake + * dev_disconnect. */ return peer_write_message(conn, pcs, pcs->peer->error, (void *)io_close_cb); } diff --git a/lightningd/peer_control.h b/lightningd/peer_control.h index 83719cd11..c787abc90 100644 --- a/lightningd/peer_control.h +++ b/lightningd/peer_control.h @@ -4,9 +4,9 @@ #include #include #include +#include #include #include -#include #include #include #include diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index 6fa0243a7..672f8e3c6 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -4,12 +4,13 @@ #include #include #include +#include #include +#include #include #include #include #include -#include #include #include #include @@ -17,7 +18,6 @@ #include #include #include -#include #include #include diff --git a/lightningd/peer_htlcs.h b/lightningd/peer_htlcs.h index 83d527234..389a4d9be 100644 --- a/lightningd/peer_htlcs.h +++ b/lightningd/peer_htlcs.h @@ -4,7 +4,7 @@ #include "config.h" #include #include -#include +#include /* FIXME: Define serialization primitive for this? */ struct channel_info { diff --git a/lightningd/subd.c b/lightningd/subd.c index deb52830f..ec33194fb 100644 --- a/lightningd/subd.c +++ b/lightningd/subd.c @@ -5,11 +5,11 @@ #include #include #include +#include #include #include #include #include -#include #include #include #include diff --git a/lightningd/subd.h b/lightningd/subd.h index 3f6705c43..e1b4fcf69 100644 --- a/lightningd/subd.h +++ b/lightningd/subd.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include struct io_conn; diff --git a/lightningd/test/Makefile b/lightningd/test/Makefile index 50a4386b6..3cce7e813 100644 --- a/lightningd/test/Makefile +++ b/lightningd/test/Makefile @@ -6,11 +6,20 @@ LIGHTNINGD_TEST_SRC := $(wildcard lightningd/test/run-*.c) LIGHTNINGD_TEST_OBJS := $(LIGHTNINGD_TEST_SRC:.c=.o) LIGHTNINGD_TEST_PROGRAMS := $(LIGHTNINGD_TEST_OBJS:.o=) +LIGHTNINGD_TEST_COMMON_OBJS := \ + common/daemon_conn.o \ + common/htlc_state.o \ + common/pseudorand.o \ + common/msg_queue.o \ + common/utils.o \ + common/type_to_string.o \ + common/permute_tx.o + update-mocks: $(LIGHTNINGD_TEST_SRC:%=update-mocks/%) -$(LIGHTNINGD_TEST_PROGRAMS): $(CCAN_OBJS) $(CCAN_SHACHAIN48_OBJ) $(CORE_OBJS) $(CORE_TX_OBJS) $(BITCOIN_OBJS) $(WIRE_OBJS) $(LIBBASE58_OBJS) $(LIGHTNINGD_OLD_LIB_OBJS) utils.o libsecp256k1.a libsodium.a libwallycore.a +$(LIGHTNINGD_TEST_PROGRAMS): $(CCAN_OBJS) $(CCAN_SHACHAIN48_OBJ) $(BITCOIN_OBJS) $(WIRE_OBJS) $(LIBBASE58_OBJS) $(LIGHTNINGD_OLD_LIB_OBJS) $(LIGHTNINGD_TEST_COMMON_OBJS) libsecp256k1.a libsodium.a libwallycore.a -$(LIGHTNINGD_TEST_OBJS): $(LIGHTNINGD_HEADERS) $(LIGHTNINGD_SRC) $(LIGHTNINGD_LIB_SRC) +$(LIGHTNINGD_TEST_OBJS): $(LIGHTNINGD_HEADERS) $(LIGHTNINGD_SRC) lightningd/tests: $(LIGHTNINGD_TEST_PROGRAMS:%=unittest/%) diff --git a/lightningd/test/run-channel.c b/lightningd/test/run-channel.c index 35d4a4475..1f27308da 100644 --- a/lightningd/test/run-channel.c +++ b/lightningd/test/run-channel.c @@ -1,20 +1,22 @@ - #include + #include #include #define status_trace(fmt , ...) \ printf(fmt "\n" , ## __VA_ARGS__) -#include "../key_derive.c" -#include "../keyset.c" -#include "../channel.c" -#include "../commit_tx.c" -#include "../htlc_tx.c" +#include "../../common/key_derive.c" +#include "../../common/keyset.c" +#include "../../common/initial_channel.c" +#include "../channel/full_channel.c" +#include "../../common/initial_commit_tx.c" +#include "../channel/commit_tx.c" +#include "../../common/htlc_tx.c" #include #include #include #include #include -#include -#include +#include +#include const void *trc; diff --git a/lightningd/test/run-commit_tx.c b/lightningd/test/run-commit_tx.c index 1c14215d7..01dc28839 100644 --- a/lightningd/test/run-commit_tx.c +++ b/lightningd/test/run-commit_tx.c @@ -1,20 +1,21 @@ -#include "../key_derive.c" +#include "../../common/key_derive.c" #include #include -#include +#include static bool print_superverbose; #define SUPERVERBOSE(...) \ do { if (print_superverbose) printf(__VA_ARGS__); } while(0) #define PRINT_ACTUAL_FEE -#include "../commit_tx.c" -#include "../htlc_tx.c" +#include "../channel/commit_tx.c" +#include "../../common/initial_commit_tx.c" +#include "../../common/htlc_tx.c" #include #include #include #include #include #include -#include +#include /* Turn this on to brute-force fee values */ /*#define DEBUG */ diff --git a/lightningd/test/run-cryptomsg.c b/lightningd/test/run-cryptomsg.c index 83014f05f..76466552c 100644 --- a/lightningd/test/run-cryptomsg.c +++ b/lightningd/test/run-cryptomsg.c @@ -1,8 +1,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -52,7 +52,7 @@ char dev_disconnect(int pkt_type) /* We test what look like unknown messages. */ #define is_unknown_msg_discardable(x) 0 -#include "../cryptomsg.c" +#include "../../common/cryptomsg.c" const void *trc; diff --git a/lightningd/test/run-funding_tx.c b/lightningd/test/run-funding_tx.c index 8a761b6fc..83c3df1b9 100644 --- a/lightningd/test/run-funding_tx.c +++ b/lightningd/test/run-funding_tx.c @@ -3,14 +3,14 @@ #include #include #include +#include +#include #include #include -#include -#include #define SUPERVERBOSE printf - #include "../funding_tx.c" + #include "../../common/funding_tx.c" #undef SUPERVERBOSE - #include "../key_derive.c" + #include "../../common/key_derive.c" #if 0 static struct sha256 sha256_from_hex(const char *hex) diff --git a/lightningd/test/run-key_derive.c b/lightningd/test/run-key_derive.c index b4ab327a5..c4fac6d53 100644 --- a/lightningd/test/run-key_derive.c +++ b/lightningd/test/run-key_derive.c @@ -1,14 +1,12 @@ #define SUPERVERBOSE static void *tmpctx; -#include -#include -#include -#include "../key_derive.c" #include #include +#include +#include #include -#include +#include "../../common/key_derive.c" static struct secret secret_from_hex(const char *hex) { diff --git a/test/test_sphinx.c b/test/test_sphinx.c index a07ef8b46..816dad051 100644 --- a/test/test_sphinx.c +++ b/test/test_sphinx.c @@ -4,13 +4,13 @@ #include #include #include +#include #include #include #include #include #include -#include "lightningd/sphinx.h" secp256k1_context *secp256k1_ctx; diff --git a/wallet/Makefile b/wallet/Makefile index 857bf540f..9c7d8dd87 100644 --- a/wallet/Makefile +++ b/wallet/Makefile @@ -22,7 +22,7 @@ WALLET_TEST_PROGRAMS := $(WALLET_TEST_OBJS:.o=) $(WALLET_TEST_OBJS): $(WALLET_LIB_OBJS) -$(WALLET_TEST_PROGRAMS): $(BITCOIN_OBJS) $(CCAN_OBJS) $(LIBBASE58_OBJS) daemon/log.o type_to_string.o daemon/pseudorand.o ccan-crypto-shachain-48.o utils.o libwallycore.a libsecp256k1.a libsodium.a +$(WALLET_TEST_PROGRAMS): $(BITCOIN_OBJS) $(CCAN_OBJS) $(LIBBASE58_OBJS) lightningd/log.o common/type_to_string.o common/pseudorand.o ccan-crypto-shachain-48.o common/utils.o libwallycore.a libsecp256k1.a libsodium.a $(WALLET_TEST_OBJS): $(CCAN_HEADERS) wallet/tests: $(WALLET_TEST_PROGRAMS:%=unittest/%) diff --git a/wallet/wallet.h b/wallet/wallet.h index 71b10e554..160474e20 100644 --- a/wallet/wallet.h +++ b/wallet/wallet.h @@ -6,8 +6,8 @@ #include #include #include -#include -#include +#include +#include #include struct lightningd; diff --git a/wallet/walletrpc.c b/wallet/walletrpc.c index a2025d299..40bea6a46 100644 --- a/wallet/walletrpc.c +++ b/wallet/walletrpc.c @@ -2,6 +2,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -9,12 +12,9 @@ #include #include #include -#include #include #include -#include #include -#include #include #include diff --git a/wire/test/Makefile b/wire/test/Makefile index 67f6632f2..c9658192d 100644 --- a/wire/test/Makefile +++ b/wire/test/Makefile @@ -8,7 +8,7 @@ WIRE_TEST_PROGRAMS := $(WIRE_TEST_OBJS:.o=) update-mocks: $(WIRE_TEST_SRC:%=update-mocks/%) -$(WIRE_TEST_PROGRAMS): $(CCAN_OBJS) $(CCAN_SHACHAIN48_OBJ) $(BITCOIN_OBJS) $(LIBBASE58_OBJS) libsecp256k1.a utils.o libsodium.a +$(WIRE_TEST_PROGRAMS): $(CCAN_OBJS) $(CCAN_SHACHAIN48_OBJ) $(BITCOIN_OBJS) $(LIBBASE58_OBJS) libsecp256k1.a common/utils.o libsodium.a $(WIRE_TEST_OBJS): $(WIRE_HEADERS) $(BITCOIN_HEADERS) $(CORE_HEADERS) $(GEN_HEADERS) $(WIRE_GEN_HEADERS) $(WIRE_GEN_SRC) $(CCAN_HEADERS) $(LIBSODIUM_HEADERS) diff --git a/wire/test/run-peer-wire.c b/wire/test/run-peer-wire.c index ad9d3d0c3..f28d924a1 100644 --- a/wire/test/run-peer-wire.c +++ b/wire/test/run-peer-wire.c @@ -14,7 +14,7 @@ void fromwire_pad_orig(const u8 **cursor, size_t *max, size_t num); #include #include #include -#include +#include secp256k1_context *secp256k1_ctx;