diff --git a/lightningd/Makefile b/lightningd/Makefile index b5bef5fe19a0..3ebb582d9750 100644 --- a/lightningd/Makefile +++ b/lightningd/Makefile @@ -51,6 +51,7 @@ LIGHTNINGD_SRC := \ lightningd/build_utxos.c \ lightningd/chaintopology.c \ lightningd/channel.c \ + lightningd/channel_control.c \ lightningd/closing_control.c \ lightningd/connect_control.c \ lightningd/gossip_control.c \ diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c new file mode 100644 index 000000000000..7e88ac7ffec6 --- /dev/null +++ b/lightningd/channel_control.c @@ -0,0 +1,328 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* We were informed by channeld that it announced the channel and sent + * an update, so we can now start sending a node_announcement. The + * first step is to build the provisional announcement and ask the HSM + * to sign it. */ + +static void peer_got_funding_locked(struct channel *channel, const u8 *msg) +{ + struct pubkey next_per_commitment_point; + + if (!fromwire_channel_got_funding_locked(msg, NULL, + &next_per_commitment_point)) { + channel_internal_error(channel, + "bad channel_got_funding_locked %s", + tal_hex(channel, msg)); + return; + } + + if (channel->remote_funding_locked) { + channel_internal_error(channel, + "channel_got_funding_locked twice"); + return; + } + update_per_commit_point(channel, &next_per_commitment_point); + + log_debug(channel->log, "Got funding_locked"); + channel->remote_funding_locked = true; +} + +static void peer_got_shutdown(struct channel *channel, const u8 *msg) +{ + u8 *scriptpubkey; + struct lightningd *ld = channel->peer->ld; + + if (!fromwire_channel_got_shutdown(channel, msg, NULL, &scriptpubkey)) { + channel_internal_error(channel, "bad channel_got_shutdown %s", + tal_hex(msg, msg)); + return; + } + + /* FIXME: Add to spec that we must allow repeated shutdown! */ + tal_free(channel->remote_shutdown_scriptpubkey); + channel->remote_shutdown_scriptpubkey = scriptpubkey; + + /* BOLT #2: + * + * A sending node MUST set `scriptpubkey` to one of the following forms: + * + * 1. `OP_DUP` `OP_HASH160` `20` 20-bytes `OP_EQUALVERIFY` `OP_CHECKSIG` + * (pay to pubkey hash), OR + * 2. `OP_HASH160` `20` 20-bytes `OP_EQUAL` (pay to script hash), OR + * 3. `OP_0` `20` 20-bytes (version 0 pay to witness pubkey), OR + * 4. `OP_0` `32` 32-bytes (version 0 pay to witness script hash) + * + * A receiving node SHOULD fail the connection if the `scriptpubkey` + * is not one of those forms. */ + if (!is_p2pkh(scriptpubkey, NULL) && !is_p2sh(scriptpubkey, NULL) + && !is_p2wpkh(scriptpubkey, NULL) && !is_p2wsh(scriptpubkey, NULL)) { + channel_fail_permanent(channel, "Bad shutdown scriptpubkey %s", + tal_hex(channel, scriptpubkey)); + return; + } + + if (channel->local_shutdown_idx == -1) { + u8 *scriptpubkey; + + channel->local_shutdown_idx = wallet_get_newindex(ld); + if (channel->local_shutdown_idx == -1) { + channel_internal_error(channel, + "Can't get local shutdown index"); + return; + } + + channel_set_state(channel, + CHANNELD_NORMAL, CHANNELD_SHUTTING_DOWN); + + /* BOLT #2: + * + * A sending node MUST set `scriptpubkey` to one of the + * following forms: + * + * ...3. `OP_0` `20` 20-bytes (version 0 pay to witness pubkey), + */ + scriptpubkey = p2wpkh_for_keyidx(msg, ld, + channel->local_shutdown_idx); + if (!scriptpubkey) { + channel_internal_error(channel, + "Can't get shutdown script %"PRIu64, + channel->local_shutdown_idx); + return; + } + + txfilter_add_scriptpubkey(ld->owned_txfilter, scriptpubkey); + + /* BOLT #2: + * + * A receiving node MUST reply to a `shutdown` message with a + * `shutdown` once there are no outstanding updates on the + * peer, unless it has already sent a `shutdown`. + */ + subd_send_msg(channel->owner, + take(towire_channel_send_shutdown(channel, + scriptpubkey))); + } + + /* TODO(cdecker) Selectively save updated fields to DB */ + wallet_channel_save(ld->wallet, channel); +} + +static void peer_start_closingd_after_shutdown(struct channel *channel, + const u8 *msg, + const int *fds) +{ + struct crypto_state cs; + u64 gossip_index; + + /* We expect 2 fds. */ + assert(tal_count(fds) == 2); + + if (!fromwire_channel_shutdown_complete(msg, NULL, &cs, &gossip_index)) { + channel_internal_error(channel, "bad shutdown_complete: %s", + tal_hex(msg, msg)); + return; + } + + /* This sets channel->owner, closes down channeld. */ + peer_start_closingd(channel, &cs, gossip_index, fds[0], fds[1], false); + channel_set_state(channel, CHANNELD_SHUTTING_DOWN, CLOSINGD_SIGEXCHANGE); +} + +static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds) +{ + enum channel_wire_type t = fromwire_peektype(msg); + + switch (t) { + case WIRE_CHANNEL_NORMAL_OPERATION: + channel_set_state(sd->channel, + CHANNELD_AWAITING_LOCKIN, CHANNELD_NORMAL); + break; + case WIRE_CHANNEL_SENDING_COMMITSIG: + peer_sending_commitsig(sd->channel, msg); + break; + case WIRE_CHANNEL_GOT_COMMITSIG: + peer_got_commitsig(sd->channel, msg); + break; + case WIRE_CHANNEL_GOT_REVOKE: + peer_got_revoke(sd->channel, msg); + break; + case WIRE_CHANNEL_GOT_FUNDING_LOCKED: + peer_got_funding_locked(sd->channel, msg); + break; + case WIRE_CHANNEL_GOT_SHUTDOWN: + peer_got_shutdown(sd->channel, msg); + break; + case WIRE_CHANNEL_SHUTDOWN_COMPLETE: + /* We expect 2 fds. */ + if (!fds) + return 2; + peer_start_closingd_after_shutdown(sd->channel, msg, fds); + break; + + /* And we never get these from channeld. */ + case WIRE_CHANNEL_INIT: + case WIRE_CHANNEL_FUNDING_LOCKED: + case WIRE_CHANNEL_FUNDING_ANNOUNCE_DEPTH: + case WIRE_CHANNEL_OFFER_HTLC: + case WIRE_CHANNEL_FULFILL_HTLC: + case WIRE_CHANNEL_FAIL_HTLC: + case WIRE_CHANNEL_PING: + case WIRE_CHANNEL_GOT_COMMITSIG_REPLY: + case WIRE_CHANNEL_GOT_REVOKE_REPLY: + case WIRE_CHANNEL_SENDING_COMMITSIG_REPLY: + case WIRE_CHANNEL_SEND_SHUTDOWN: + case WIRE_CHANNEL_DEV_REENABLE_COMMIT: + case WIRE_CHANNEL_FEERATES: + /* Replies go to requests. */ + case WIRE_CHANNEL_OFFER_HTLC_REPLY: + case WIRE_CHANNEL_PING_REPLY: + case WIRE_CHANNEL_DEV_REENABLE_COMMIT_REPLY: + break; + } + + return 0; +} + +bool peer_start_channeld(struct channel *channel, + const struct crypto_state *cs, + u64 gossip_index, + int peer_fd, int gossip_fd, + const u8 *funding_signed, + bool reconnected) +{ + const tal_t *tmpctx = tal_tmpctx(channel); + u8 *msg, *initmsg; + int hsmfd; + struct added_htlc *htlcs; + enum htlc_state *htlc_states; + struct fulfilled_htlc *fulfilled_htlcs; + enum side *fulfilled_sides; + const struct failed_htlc **failed_htlcs; + enum side *failed_sides; + struct short_channel_id funding_channel_id; + const u8 *shutdown_scriptpubkey; + u64 num_revocations; + struct lightningd *ld = channel->peer->ld; + const struct config *cfg = &ld->config; + + msg = towire_hsm_client_hsmfd(tmpctx, &channel->peer->id, HSM_CAP_SIGN_GOSSIP | HSM_CAP_ECDH); + if (!wire_sync_write(ld->hsm_fd, take(msg))) + fatal("Could not write to HSM: %s", strerror(errno)); + + msg = hsm_sync_read(tmpctx, ld); + if (!fromwire_hsm_client_hsmfd_reply(msg, NULL)) + fatal("Bad reply from HSM: %s", tal_hex(tmpctx, msg)); + + hsmfd = fdpass_recv(ld->hsm_fd); + if (hsmfd < 0) + fatal("Could not read fd from HSM: %s", strerror(errno)); + + channel_set_owner(channel, new_channel_subd(ld, + "lightning_channeld", channel, + channel->log, + channel_wire_type_name, + channel_msg, + channel_errmsg, + take(&peer_fd), + take(&gossip_fd), + take(&hsmfd), NULL)); + + if (!channel->owner) { + log_unusual(channel->log, "Could not subdaemon channel: %s", + strerror(errno)); + channel_fail_transient(channel, "Failed to subdaemon channel"); + tal_free(tmpctx); + return true; + } + + peer_htlcs(tmpctx, channel, &htlcs, &htlc_states, &fulfilled_htlcs, + &fulfilled_sides, &failed_htlcs, &failed_sides); + + if (channel->scid) { + funding_channel_id = *channel->scid; + log_debug(channel->log, "Already have funding locked in"); + } else { + log_debug(channel->log, "Waiting for funding confirmations"); + memset(&funding_channel_id, 0, sizeof(funding_channel_id)); + } + + if (channel->local_shutdown_idx != -1) { + shutdown_scriptpubkey + = p2wpkh_for_keyidx(tmpctx, ld, + channel->local_shutdown_idx); + } else + shutdown_scriptpubkey = NULL; + + num_revocations = revocations_received(&channel->their_shachain.chain); + + /* Warn once. */ + if (ld->config.ignore_fee_limits) + log_debug(channel->log, "Ignoring fee limits!"); + + initmsg = towire_channel_init(tmpctx, + &get_chainparams(ld)->genesis_blockhash, + &channel->funding_txid, + channel->funding_outnum, + channel->funding_satoshi, + &channel->our_config, + &channel->channel_info.their_config, + channel->channel_info.feerate_per_kw, + feerate_min(ld), + feerate_max(ld), + &channel->last_sig, + cs, gossip_index, + &channel->channel_info.remote_fundingkey, + &channel->channel_info.theirbase.revocation, + &channel->channel_info.theirbase.payment, + &channel->channel_info.theirbase.htlc, + &channel->channel_info.theirbase.delayed_payment, + &channel->channel_info.remote_per_commit, + &channel->channel_info.old_remote_per_commit, + channel->funder, + cfg->fee_base, + cfg->fee_per_satoshi, + channel->our_msatoshi, + &channel->seed, + &ld->id, + &channel->peer->id, + time_to_msec(cfg->commit_time), + cfg->cltv_expiry_delta, + channel->last_was_revoke, + channel->last_sent_commit, + channel->next_index[LOCAL], + channel->next_index[REMOTE], + num_revocations, + channel->next_htlc_id, + htlcs, htlc_states, + fulfilled_htlcs, fulfilled_sides, + failed_htlcs, failed_sides, + channel->scid != NULL, + channel->remote_funding_locked, + &funding_channel_id, + reconnected, + shutdown_scriptpubkey, + channel->remote_shutdown_scriptpubkey != NULL, + channel->channel_flags, + funding_signed); + + /* We don't expect a response: we are triggered by funding_depth_cb. */ + subd_send_msg(channel->owner, take(initmsg)); + + tal_free(tmpctx); + return true; +} diff --git a/lightningd/channel_control.h b/lightningd/channel_control.h new file mode 100644 index 000000000000..e2b03eab534c --- /dev/null +++ b/lightningd/channel_control.h @@ -0,0 +1,17 @@ +#ifndef LIGHTNING_LIGHTNINGD_CHANNEL_CONTROL_H +#define LIGHTNING_LIGHTNINGD_CHANNEL_CONTROL_H +#include "config.h" +#include +#include + +struct channel; +struct crypto_state; + +bool peer_start_channeld(struct channel *channel, + const struct crypto_state *cs, + u64 gossip_index, + int peer_fd, int gossip_fd, + const u8 *funding_signed, + bool reconnected); + +#endif /* LIGHTNING_LIGHTNINGD_CHANNEL_CONTROL_H */ diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index e18d8242a8fa..34bf5bf0327b 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include #include #include diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index a7c75658a020..64ef00707c7e 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -22,12 +21,12 @@ #include #include #include -#include #include #include #include #include #include +#include #include #include #include @@ -42,7 +41,6 @@ #include #include #include -#include static void destroy_peer(struct peer *peer) { @@ -579,319 +577,6 @@ void channel_watch_funding(struct lightningd *ld, struct channel *channel) funding_spent, NULL); } -/* We were informed by channeld that it announced the channel and sent - * an update, so we can now start sending a node_announcement. The - * first step is to build the provisional announcement and ask the HSM - * to sign it. */ - -static void peer_got_funding_locked(struct channel *channel, const u8 *msg) -{ - struct pubkey next_per_commitment_point; - - if (!fromwire_channel_got_funding_locked(msg, NULL, - &next_per_commitment_point)) { - channel_internal_error(channel, - "bad channel_got_funding_locked %s", - tal_hex(channel, msg)); - return; - } - - if (channel->remote_funding_locked) { - channel_internal_error(channel, - "channel_got_funding_locked twice"); - return; - } - update_per_commit_point(channel, &next_per_commitment_point); - - log_debug(channel->log, "Got funding_locked"); - channel->remote_funding_locked = true; -} - -static void peer_got_shutdown(struct channel *channel, const u8 *msg) -{ - u8 *scriptpubkey; - struct lightningd *ld = channel->peer->ld; - - if (!fromwire_channel_got_shutdown(channel, msg, NULL, &scriptpubkey)) { - channel_internal_error(channel, "bad channel_got_shutdown %s", - tal_hex(msg, msg)); - return; - } - - /* FIXME: Add to spec that we must allow repeated shutdown! */ - tal_free(channel->remote_shutdown_scriptpubkey); - channel->remote_shutdown_scriptpubkey = scriptpubkey; - - /* BOLT #2: - * - * A sending node MUST set `scriptpubkey` to one of the following forms: - * - * 1. `OP_DUP` `OP_HASH160` `20` 20-bytes `OP_EQUALVERIFY` `OP_CHECKSIG` - * (pay to pubkey hash), OR - * 2. `OP_HASH160` `20` 20-bytes `OP_EQUAL` (pay to script hash), OR - * 3. `OP_0` `20` 20-bytes (version 0 pay to witness pubkey), OR - * 4. `OP_0` `32` 32-bytes (version 0 pay to witness script hash) - * - * A receiving node SHOULD fail the connection if the `scriptpubkey` - * is not one of those forms. */ - if (!is_p2pkh(scriptpubkey, NULL) && !is_p2sh(scriptpubkey, NULL) - && !is_p2wpkh(scriptpubkey, NULL) && !is_p2wsh(scriptpubkey, NULL)) { - channel_fail_permanent(channel, "Bad shutdown scriptpubkey %s", - tal_hex(channel, scriptpubkey)); - return; - } - - if (channel->local_shutdown_idx == -1) { - u8 *scriptpubkey; - - channel->local_shutdown_idx = wallet_get_newindex(ld); - if (channel->local_shutdown_idx == -1) { - channel_internal_error(channel, - "Can't get local shutdown index"); - return; - } - - channel_set_state(channel, - CHANNELD_NORMAL, CHANNELD_SHUTTING_DOWN); - - /* BOLT #2: - * - * A sending node MUST set `scriptpubkey` to one of the - * following forms: - * - * ...3. `OP_0` `20` 20-bytes (version 0 pay to witness pubkey), - */ - scriptpubkey = p2wpkh_for_keyidx(msg, ld, - channel->local_shutdown_idx); - if (!scriptpubkey) { - channel_internal_error(channel, - "Can't get shutdown script %"PRIu64, - channel->local_shutdown_idx); - return; - } - - txfilter_add_scriptpubkey(ld->owned_txfilter, scriptpubkey); - - /* BOLT #2: - * - * A receiving node MUST reply to a `shutdown` message with a - * `shutdown` once there are no outstanding updates on the - * peer, unless it has already sent a `shutdown`. - */ - subd_send_msg(channel->owner, - take(towire_channel_send_shutdown(channel, - scriptpubkey))); - } - - /* TODO(cdecker) Selectively save updated fields to DB */ - wallet_channel_save(ld->wallet, channel); -} - -static void peer_start_closingd_after_shutdown(struct channel *channel, - const u8 *msg, - const int *fds) -{ - struct crypto_state cs; - u64 gossip_index; - - /* We expect 2 fds. */ - assert(tal_count(fds) == 2); - - if (!fromwire_channel_shutdown_complete(msg, NULL, &cs, &gossip_index)) { - channel_internal_error(channel, "bad shutdown_complete: %s", - tal_hex(msg, msg)); - return; - } - - /* This sets channel->owner, closes down channeld. */ - peer_start_closingd(channel, &cs, gossip_index, fds[0], fds[1], false); - channel_set_state(channel, CHANNELD_SHUTTING_DOWN, CLOSINGD_SIGEXCHANGE); -} - -static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds) -{ - enum channel_wire_type t = fromwire_peektype(msg); - - switch (t) { - case WIRE_CHANNEL_NORMAL_OPERATION: - channel_set_state(sd->channel, - CHANNELD_AWAITING_LOCKIN, CHANNELD_NORMAL); - break; - case WIRE_CHANNEL_SENDING_COMMITSIG: - peer_sending_commitsig(sd->channel, msg); - break; - case WIRE_CHANNEL_GOT_COMMITSIG: - peer_got_commitsig(sd->channel, msg); - break; - case WIRE_CHANNEL_GOT_REVOKE: - peer_got_revoke(sd->channel, msg); - break; - case WIRE_CHANNEL_GOT_FUNDING_LOCKED: - peer_got_funding_locked(sd->channel, msg); - break; - case WIRE_CHANNEL_GOT_SHUTDOWN: - peer_got_shutdown(sd->channel, msg); - break; - case WIRE_CHANNEL_SHUTDOWN_COMPLETE: - /* We expect 2 fds. */ - if (!fds) - return 2; - peer_start_closingd_after_shutdown(sd->channel, msg, fds); - break; - - /* And we never get these from channeld. */ - case WIRE_CHANNEL_INIT: - case WIRE_CHANNEL_FUNDING_LOCKED: - case WIRE_CHANNEL_FUNDING_ANNOUNCE_DEPTH: - case WIRE_CHANNEL_OFFER_HTLC: - case WIRE_CHANNEL_FULFILL_HTLC: - case WIRE_CHANNEL_FAIL_HTLC: - case WIRE_CHANNEL_PING: - case WIRE_CHANNEL_GOT_COMMITSIG_REPLY: - case WIRE_CHANNEL_GOT_REVOKE_REPLY: - case WIRE_CHANNEL_SENDING_COMMITSIG_REPLY: - case WIRE_CHANNEL_SEND_SHUTDOWN: - case WIRE_CHANNEL_DEV_REENABLE_COMMIT: - case WIRE_CHANNEL_FEERATES: - /* Replies go to requests. */ - case WIRE_CHANNEL_OFFER_HTLC_REPLY: - case WIRE_CHANNEL_PING_REPLY: - case WIRE_CHANNEL_DEV_REENABLE_COMMIT_REPLY: - break; - } - - return 0; -} - -bool peer_start_channeld(struct channel *channel, - const struct crypto_state *cs, - u64 gossip_index, - int peer_fd, int gossip_fd, - const u8 *funding_signed, - bool reconnected) -{ - const tal_t *tmpctx = tal_tmpctx(channel); - u8 *msg, *initmsg; - int hsmfd; - struct added_htlc *htlcs; - enum htlc_state *htlc_states; - struct fulfilled_htlc *fulfilled_htlcs; - enum side *fulfilled_sides; - const struct failed_htlc **failed_htlcs; - enum side *failed_sides; - struct short_channel_id funding_channel_id; - const u8 *shutdown_scriptpubkey; - u64 num_revocations; - struct lightningd *ld = channel->peer->ld; - const struct config *cfg = &ld->config; - - msg = towire_hsm_client_hsmfd(tmpctx, &channel->peer->id, HSM_CAP_SIGN_GOSSIP | HSM_CAP_ECDH); - if (!wire_sync_write(ld->hsm_fd, take(msg))) - fatal("Could not write to HSM: %s", strerror(errno)); - - msg = hsm_sync_read(tmpctx, ld); - if (!fromwire_hsm_client_hsmfd_reply(msg, NULL)) - fatal("Bad reply from HSM: %s", tal_hex(tmpctx, msg)); - - hsmfd = fdpass_recv(ld->hsm_fd); - if (hsmfd < 0) - fatal("Could not read fd from HSM: %s", strerror(errno)); - - channel_set_owner(channel, new_channel_subd(ld, - "lightning_channeld", channel, - channel->log, - channel_wire_type_name, - channel_msg, - channel_errmsg, - take(&peer_fd), - take(&gossip_fd), - take(&hsmfd), NULL)); - - if (!channel->owner) { - log_unusual(channel->log, "Could not subdaemon channel: %s", - strerror(errno)); - channel_fail_transient(channel, "Failed to subdaemon channel"); - tal_free(tmpctx); - return true; - } - - peer_htlcs(tmpctx, channel, &htlcs, &htlc_states, &fulfilled_htlcs, - &fulfilled_sides, &failed_htlcs, &failed_sides); - - if (channel->scid) { - funding_channel_id = *channel->scid; - log_debug(channel->log, "Already have funding locked in"); - } else { - log_debug(channel->log, "Waiting for funding confirmations"); - memset(&funding_channel_id, 0, sizeof(funding_channel_id)); - } - - if (channel->local_shutdown_idx != -1) { - shutdown_scriptpubkey - = p2wpkh_for_keyidx(tmpctx, ld, - channel->local_shutdown_idx); - } else - shutdown_scriptpubkey = NULL; - - num_revocations = revocations_received(&channel->their_shachain.chain); - - /* Warn once. */ - if (ld->config.ignore_fee_limits) - log_debug(channel->log, "Ignoring fee limits!"); - - initmsg = towire_channel_init(tmpctx, - &get_chainparams(ld)->genesis_blockhash, - &channel->funding_txid, - channel->funding_outnum, - channel->funding_satoshi, - &channel->our_config, - &channel->channel_info.their_config, - channel->channel_info.feerate_per_kw, - feerate_min(ld), - feerate_max(ld), - &channel->last_sig, - cs, gossip_index, - &channel->channel_info.remote_fundingkey, - &channel->channel_info.theirbase.revocation, - &channel->channel_info.theirbase.payment, - &channel->channel_info.theirbase.htlc, - &channel->channel_info.theirbase.delayed_payment, - &channel->channel_info.remote_per_commit, - &channel->channel_info.old_remote_per_commit, - channel->funder, - cfg->fee_base, - cfg->fee_per_satoshi, - channel->our_msatoshi, - &channel->seed, - &ld->id, - &channel->peer->id, - time_to_msec(cfg->commit_time), - cfg->cltv_expiry_delta, - channel->last_was_revoke, - channel->last_sent_commit, - channel->next_index[LOCAL], - channel->next_index[REMOTE], - num_revocations, - channel->next_htlc_id, - htlcs, htlc_states, - fulfilled_htlcs, fulfilled_sides, - failed_htlcs, failed_sides, - channel->scid != NULL, - channel->remote_funding_locked, - &funding_channel_id, - reconnected, - shutdown_scriptpubkey, - channel->remote_shutdown_scriptpubkey != NULL, - channel->channel_flags, - funding_signed); - - /* We don't expect a response: we are triggered by funding_depth_cb. */ - subd_send_msg(channel->owner, take(initmsg)); - - tal_free(tmpctx); - return true; -} - struct getpeers_args { struct command *cmd; /* If non-NULL, they want logs too */ diff --git a/lightningd/peer_control.h b/lightningd/peer_control.h index ab819f196da0..803fbde45f83 100644 --- a/lightningd/peer_control.h +++ b/lightningd/peer_control.h @@ -108,12 +108,5 @@ void drop_to_chain(struct lightningd *ld, struct channel *channel); u32 feerate_min(struct lightningd *ld); u32 feerate_max(struct lightningd *ld); -bool peer_start_channeld(struct channel *channel, - const struct crypto_state *cs, - u64 gossip_index, - int peer_fd, int gossip_fd, - const u8 *funding_signed, - bool reconnected); - void channel_watch_funding(struct lightningd *ld, struct channel *channel); #endif /* LIGHTNING_LIGHTNINGD_PEER_CONTROL_H */ diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index 1aa8762e0851..b64eced7c3f9 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -47,9 +47,6 @@ void broadcast_tx(struct chain_topology *topo UNNEEDED, int exitstatus UNNEEDED, const char *err)) { fprintf(stderr, "broadcast_tx called!\n"); abort(); } -/* Generated stub for channel_wire_type_name */ -const char *channel_wire_type_name(int e UNNEEDED) -{ fprintf(stderr, "channel_wire_type_name called!\n"); abort(); } /* Generated stub for command_fail */ void command_fail(struct command *cmd UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "command_fail called!\n"); abort(); } @@ -76,27 +73,12 @@ bool derive_basepoints(const struct privkey *seed UNNEEDED, /* Generated stub for extract_channel_id */ bool extract_channel_id(const u8 *in_pkt UNNEEDED, struct channel_id *channel_id UNNEEDED) { fprintf(stderr, "extract_channel_id called!\n"); abort(); } -/* Generated stub for fromwire_channel_got_funding_locked */ -bool fromwire_channel_got_funding_locked(const void *p UNNEEDED, size_t *plen UNNEEDED, struct pubkey *next_per_commit_point UNNEEDED) -{ fprintf(stderr, "fromwire_channel_got_funding_locked called!\n"); abort(); } -/* Generated stub for fromwire_channel_got_shutdown */ -bool fromwire_channel_got_shutdown(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, size_t *plen UNNEEDED, u8 **scriptpubkey UNNEEDED) -{ fprintf(stderr, "fromwire_channel_got_shutdown called!\n"); abort(); } -/* Generated stub for fromwire_channel_shutdown_complete */ -bool fromwire_channel_shutdown_complete(const void *p UNNEEDED, size_t *plen UNNEEDED, struct crypto_state *crypto_state UNNEEDED, u64 *gossip_index UNNEEDED) -{ fprintf(stderr, "fromwire_channel_shutdown_complete called!\n"); abort(); } /* Generated stub for fromwire_gossip_getpeers_reply */ bool fromwire_gossip_getpeers_reply(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, size_t *plen UNNEEDED, struct pubkey **id UNNEEDED, struct wireaddr **addr UNNEEDED) { fprintf(stderr, "fromwire_gossip_getpeers_reply called!\n"); abort(); } -/* Generated stub for fromwire_gossip_peer_already_connected */ -bool fromwire_gossip_peer_already_connected(const void *p UNNEEDED, size_t *plen UNNEEDED, struct pubkey *id UNNEEDED) -{ fprintf(stderr, "fromwire_gossip_peer_already_connected called!\n"); abort(); } /* Generated stub for fromwire_gossip_peer_connected */ bool fromwire_gossip_peer_connected(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, size_t *plen UNNEEDED, struct pubkey *id UNNEEDED, struct wireaddr *addr UNNEEDED, struct crypto_state *crypto_state UNNEEDED, u64 *gossip_index UNNEEDED, u8 **gfeatures UNNEEDED, u8 **lfeatures UNNEEDED) { fprintf(stderr, "fromwire_gossip_peer_connected called!\n"); abort(); } -/* Generated stub for fromwire_hsm_client_hsmfd_reply */ -bool fromwire_hsm_client_hsmfd_reply(const void *p UNNEEDED, size_t *plen UNNEEDED) -{ fprintf(stderr, "fromwire_hsm_client_hsmfd_reply called!\n"); abort(); } /* Generated stub for funding_spent */ enum watch_result funding_spent(struct channel *channel UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, @@ -104,9 +86,6 @@ enum watch_result funding_spent(struct channel *channel UNNEEDED, const struct block *block UNNEEDED, void *unused UNNEEDED) { fprintf(stderr, "funding_spent called!\n"); abort(); } -/* Generated stub for get_chainparams */ -struct chainparams *get_chainparams(const struct lightningd *ld UNNEEDED) -{ fprintf(stderr, "get_chainparams called!\n"); abort(); } /* Generated stub for get_feerate */ u32 get_feerate(const struct chain_topology *topo UNNEEDED, enum feerate feerate UNNEEDED) { fprintf(stderr, "get_feerate called!\n"); abort(); } @@ -116,9 +95,6 @@ u8 *get_supported_global_features(const tal_t *ctx UNNEEDED) /* Generated stub for get_supported_local_features */ u8 *get_supported_local_features(const tal_t *ctx UNNEEDED) { fprintf(stderr, "get_supported_local_features called!\n"); abort(); } -/* Generated stub for hsm_sync_read */ -u8 *hsm_sync_read(const tal_t *ctx UNNEEDED, struct lightningd *ld UNNEEDED) -{ fprintf(stderr, "hsm_sync_read called!\n"); abort(); } /* Generated stub for invoices_create */ const struct invoice *invoices_create(struct invoices *invoices UNNEEDED, u64 *msatoshi TAKES UNNEEDED, @@ -258,23 +234,6 @@ void log_io(struct log *log UNNEEDED, enum log_level dir UNNEEDED, const char *c /* Generated stub for logv_add */ void logv_add(struct log *log UNNEEDED, const char *fmt UNNEEDED, va_list ap UNNEEDED) { fprintf(stderr, "logv_add called!\n"); abort(); } -/* Generated stub for new_channel_subd_ */ -struct subd *new_channel_subd_(struct lightningd *ld UNNEEDED, - const char *name UNNEEDED, - void *channel UNNEEDED, - struct log *base_log UNNEEDED, - const char *(*msgname)(int msgtype) UNNEEDED, - unsigned int (*msgcb)(struct subd * UNNEEDED, const u8 * UNNEEDED, - const int *fds) UNNEEDED, - void (*errcb)(void *channel UNNEEDED, - int peer_fd UNNEEDED, int gossip_fd UNNEEDED, - const struct crypto_state *cs UNNEEDED, - u64 gossip_index UNNEEDED, - const struct channel_id *channel_id UNNEEDED, - const char *desc UNNEEDED, - const u8 *err_for_them) UNNEEDED, - ...) -{ fprintf(stderr, "new_channel_subd_ called!\n"); abort(); } /* Generated stub for new_json_result */ struct json_result *new_json_result(const tal_t *ctx UNNEEDED) { fprintf(stderr, "new_json_result called!\n"); abort(); } @@ -292,25 +251,14 @@ u8 *peer_accept_channel(struct lightningd *ld UNNEEDED, const struct channel_id *channel_id UNNEEDED, const u8 *open_msg UNNEEDED) { fprintf(stderr, "peer_accept_channel called!\n"); abort(); } -/* Generated stub for peer_got_commitsig */ -void peer_got_commitsig(struct channel *channel UNNEEDED, const u8 *msg UNNEEDED) -{ fprintf(stderr, "peer_got_commitsig called!\n"); abort(); } -/* Generated stub for peer_got_revoke */ -void peer_got_revoke(struct channel *channel UNNEEDED, const u8 *msg UNNEEDED) -{ fprintf(stderr, "peer_got_revoke called!\n"); abort(); } -/* Generated stub for peer_htlcs */ -void peer_htlcs(const tal_t *ctx UNNEEDED, - const struct channel *channel UNNEEDED, - struct added_htlc **htlcs UNNEEDED, - enum htlc_state **htlc_states UNNEEDED, - struct fulfilled_htlc **fulfilled_htlcs UNNEEDED, - enum side **fulfilled_sides UNNEEDED, - const struct failed_htlc ***failed_htlcs UNNEEDED, - enum side **failed_sides UNNEEDED) -{ fprintf(stderr, "peer_htlcs called!\n"); abort(); } -/* Generated stub for peer_sending_commitsig */ -void peer_sending_commitsig(struct channel *channel UNNEEDED, const u8 *msg UNNEEDED) -{ fprintf(stderr, "peer_sending_commitsig called!\n"); abort(); } +/* Generated stub for peer_start_channeld */ +bool peer_start_channeld(struct channel *channel UNNEEDED, + const struct crypto_state *cs UNNEEDED, + u64 gossip_index UNNEEDED, + int peer_fd UNNEEDED, int gossip_fd UNNEEDED, + const u8 *funding_signed UNNEEDED, + bool reconnected UNNEEDED) +{ fprintf(stderr, "peer_start_channeld called!\n"); abort(); } /* Generated stub for peer_start_closingd */ void peer_start_closingd(struct channel *channel UNNEEDED, struct crypto_state *cs UNNEEDED, @@ -348,9 +296,6 @@ u8 *towire_channel_funding_announce_depth(const tal_t *ctx UNNEEDED) /* Generated stub for towire_channel_funding_locked */ u8 *towire_channel_funding_locked(const tal_t *ctx UNNEEDED, const struct short_channel_id *short_channel_id UNNEEDED) { fprintf(stderr, "towire_channel_funding_locked called!\n"); abort(); } -/* Generated stub for towire_channel_init */ -u8 *towire_channel_init(const tal_t *ctx UNNEEDED, const struct bitcoin_blkid *chain_hash UNNEEDED, const struct bitcoin_txid *funding_txid UNNEEDED, u16 funding_txout UNNEEDED, u64 funding_satoshi UNNEEDED, const struct channel_config *our_config UNNEEDED, const struct channel_config *their_config UNNEEDED, const u32 feerate_per_kw[2] UNNEEDED, u32 feerate_min UNNEEDED, u32 feerate_max UNNEEDED, const secp256k1_ecdsa_signature *first_commit_sig UNNEEDED, const struct crypto_state *crypto_state UNNEEDED, u64 gossip_index UNNEEDED, const struct pubkey *remote_fundingkey UNNEEDED, const struct pubkey *remote_revocation_basepoint UNNEEDED, const struct pubkey *remote_payment_basepoint UNNEEDED, const struct pubkey *remote_htlc_basepoint UNNEEDED, const struct pubkey *remote_delayed_payment_basepoint UNNEEDED, const struct pubkey *remote_per_commit UNNEEDED, const struct pubkey *old_remote_per_commit UNNEEDED, enum side funder UNNEEDED, u32 fee_base UNNEEDED, u32 fee_proportional UNNEEDED, u64 local_msatoshi UNNEEDED, const struct privkey *seed UNNEEDED, const struct pubkey *local_node_id UNNEEDED, const struct pubkey *remote_node_id UNNEEDED, u32 commit_msec UNNEEDED, u16 cltv_delta UNNEEDED, bool last_was_revoke UNNEEDED, const struct changed_htlc *last_sent_commit UNNEEDED, u64 next_index_local UNNEEDED, u64 next_index_remote UNNEEDED, u64 revocations_received UNNEEDED, u64 next_htlc_id UNNEEDED, const struct added_htlc *htlcs UNNEEDED, const enum htlc_state *htlc_states UNNEEDED, const struct fulfilled_htlc *fulfilled UNNEEDED, const enum side *fulfilled_sides UNNEEDED, const struct failed_htlc **failed UNNEEDED, const enum side *failed_sides UNNEEDED, bool local_funding_locked UNNEEDED, bool remote_funding_locked UNNEEDED, const struct short_channel_id *funding_short_id UNNEEDED, bool reestablish UNNEEDED, const u8 *shutdown_scriptpubkey UNNEEDED, bool remote_shutdown_received UNNEEDED, u8 flags UNNEEDED, const u8 *init_peer_pkt UNNEEDED) -{ fprintf(stderr, "towire_channel_init called!\n"); abort(); } /* Generated stub for towire_channel_send_shutdown */ u8 *towire_channel_send_shutdown(const tal_t *ctx UNNEEDED, const u8 *scriptpubkey UNNEEDED) { fprintf(stderr, "towire_channel_send_shutdown called!\n"); abort(); } @@ -377,19 +322,12 @@ u8 *towire_gossip_disable_channel(const tal_t *ctx UNNEEDED, const struct short_ /* Generated stub for towire_gossip_getpeers_request */ u8 *towire_gossip_getpeers_request(const tal_t *ctx UNNEEDED, const struct pubkey *id UNNEEDED) { fprintf(stderr, "towire_gossip_getpeers_request called!\n"); abort(); } -/* Generated stub for towire_hsm_client_hsmfd */ -u8 *towire_hsm_client_hsmfd(const tal_t *ctx UNNEEDED, const struct pubkey *pubkey UNNEEDED, u64 capabilities UNNEEDED) -{ fprintf(stderr, "towire_hsm_client_hsmfd called!\n"); abort(); } /* Generated stub for txfilter_add_scriptpubkey */ void txfilter_add_scriptpubkey(struct txfilter *filter UNNEEDED, u8 *script UNNEEDED) { fprintf(stderr, "txfilter_add_scriptpubkey called!\n"); abort(); } /* Generated stub for unsupported_features */ bool unsupported_features(const u8 *gfeatures UNNEEDED, const u8 *lfeatures UNNEEDED) { fprintf(stderr, "unsupported_features called!\n"); abort(); } -/* Generated stub for update_per_commit_point */ -void update_per_commit_point(struct channel *channel UNNEEDED, - const struct pubkey *per_commitment_point UNNEEDED) -{ fprintf(stderr, "update_per_commit_point called!\n"); abort(); } /* Generated stub for watch_txid_ */ struct txwatch *watch_txid_(const tal_t *ctx UNNEEDED, struct chain_topology *topo UNNEEDED, @@ -414,9 +352,6 @@ struct txowatch *watch_txo_(const tal_t *ctx UNNEEDED, void *) UNNEEDED, void *cbdata UNNEEDED) { fprintf(stderr, "watch_txo_ called!\n"); abort(); } -/* Generated stub for wire_sync_write */ -bool wire_sync_write(int fd UNNEEDED, const void *msg TAKES UNNEEDED) -{ fprintf(stderr, "wire_sync_write called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ #if DEVELOPER