From e51988c43bad185a527dbf02bab4cbee36bd290d Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 26 May 2021 14:58:45 +0930 Subject: [PATCH] lightningd: always pass closing connections through channeld. It handles all the cases of retransmission, and in the normal case retransmits shutdown and immediately returns for us to run closingd. This is actually far simpler and reduces code duplication. Signed-off-by: Rusty Russell Changelog-Fixed: Protocol: We could get stuck on signature exchange if we needed to retransmit the final revoke_and_ack. --- closingd/closingd.c | 154 -------------------- closingd/closingd_wire.csv | 7 - closingd/closingd_wiregen.c | 24 +-- closingd/closingd_wiregen.h | 6 +- gossipd/test/run-bench-find_route.c | 3 - gossipd/test/run-find_route-specific.c | 3 - gossipd/test/run-find_route.c | 3 - gossipd/test/run-overlong.c | 3 - lightningd/channel_control.c | 18 ++- lightningd/closing_control.c | 34 +---- lightningd/closing_control.h | 7 +- lightningd/dual_open_control.c | 2 +- lightningd/peer_control.c | 2 +- lightningd/test/run-invoice-select-inchan.c | 6 - tests/test_closing.py | 1 - tests/test_connection.py | 2 +- wallet/db_postgres_sqlgen.c | 2 +- wallet/db_sqlite3_sqlgen.c | 2 +- wallet/statements_gettextgen.po | 6 +- wallet/test/run-wallet.c | 6 - 20 files changed, 28 insertions(+), 263 deletions(-) diff --git a/closingd/closingd.c b/closingd/closingd.c index 80c10adcaa87..6c95ab92679d 100644 --- a/closingd/closingd.c +++ b/closingd/closingd.c @@ -130,143 +130,6 @@ static u8 *closing_read_peer_msg(const tal_t *ctx, } } -static struct pubkey get_per_commitment_point(u64 commitment_number) -{ - u8 *msg; - struct pubkey commitment_point; - struct secret *s; - - /* Our current per-commitment point is the commitment point in the last - * received signed commitment; HSM gives us that and the previous - * secret (which we don't need). */ - msg = towire_hsmd_get_per_commitment_point(NULL, - commitment_number); - if (!wire_sync_write(HSM_FD, take(msg))) - status_failed(STATUS_FAIL_HSM_IO, - "Writing get_per_commitment_point to HSM: %s", - strerror(errno)); - - msg = wire_sync_read(tmpctx, HSM_FD); - if (!msg) - status_failed(STATUS_FAIL_HSM_IO, - "Reading resp get_per_commitment_point reply: %s", - strerror(errno)); - if (!fromwire_hsmd_get_per_commitment_point_reply(tmpctx, msg, - &commitment_point, - &s)) - status_failed(STATUS_FAIL_HSM_IO, - "Bad per_commitment_point reply %s", - tal_hex(tmpctx, msg)); - - return commitment_point; -} - -static void do_reconnect(struct per_peer_state *pps, - const struct channel_id *channel_id, - const u64 next_index[NUM_SIDES], - u64 revocations_received, - const u8 *channel_reestablish, - const u8 *final_scriptpubkey, - const struct secret *last_remote_per_commit_secret, - const struct bitcoin_outpoint *wrong_funding) -{ - u8 *msg; - struct channel_id their_channel_id; - u64 next_local_commitment_number, next_remote_revocation_number; - struct pubkey my_current_per_commitment_point, next_commitment_point; - struct secret their_secret; - struct tlv_shutdown_tlvs *tlvs; - - my_current_per_commitment_point = get_per_commitment_point(next_index[LOCAL]-1); - - /* BOLT #2: - * - * - upon reconnection: - * - if a channel is in an error state: - * - SHOULD retransmit the error packet and ignore any other packets for - * that channel. - * - otherwise: - * - MUST transmit `channel_reestablish` for each channel. - * - MUST wait to receive the other node's `channel_reestablish` - * message before sending any other messages for that channel. - * - * The sending node: - * - MUST set `next_commitment_number` to the commitment number - * of the next `commitment_signed` it expects to receive. - * - MUST set `next_revocation_number` to the commitment number - * of the next `revoke_and_ack` message it expects to receive. - */ - - msg = towire_channel_reestablish(NULL, channel_id, - next_index[LOCAL], - revocations_received, - last_remote_per_commit_secret, - &my_current_per_commitment_point); - sync_crypto_write(pps, take(msg)); - - /* They might have already sent reestablish, which triggered us */ - if (!channel_reestablish) { - do { - tal_free(channel_reestablish); - channel_reestablish = closing_read_peer_msg(tmpctx, pps, - channel_id); - /* They *should* send reestablish first, but lnd - * sends other messages, which we can ignore since - * we're closing anyway... */ - } while (fromwire_peektype(channel_reestablish) - != WIRE_CHANNEL_REESTABLISH); - } - - if (!fromwire_channel_reestablish(channel_reestablish, &their_channel_id, - &next_local_commitment_number, - &next_remote_revocation_number, - &their_secret, - &next_commitment_point)) { - peer_failed_warn(pps, channel_id, - "bad reestablish msg: %s %s", - peer_wire_name(fromwire_peektype(channel_reestablish)), - tal_hex(tmpctx, channel_reestablish)); - } - status_debug("Got reestablish commit=%"PRIu64" revoke=%"PRIu64, - next_local_commitment_number, - next_remote_revocation_number); - - /* BOLT #2: - * - * A node: - *... - * - upon reconnection: - * - if it has sent a previous `shutdown`: - * - MUST retransmit `shutdown`. - */ - if (wrong_funding) { - tlvs = tlv_shutdown_tlvs_new(tmpctx); - tlvs->wrong_funding - = tal(tlvs, struct tlv_shutdown_tlvs_wrong_funding); - tlvs->wrong_funding->txid = wrong_funding->txid; - tlvs->wrong_funding->outnum = wrong_funding->n; - } else - tlvs = NULL; - - msg = towire_shutdown(NULL, channel_id, final_scriptpubkey, tlvs); - sync_crypto_write(pps, take(msg)); - - /* BOLT #2: - * - * A node: - *... - * - if `next_commitment_number` is 1 in both the `channel_reestablish` it sent and received: - * - MUST retransmit `funding_locked`. - */ - if (next_index[REMOTE] == 1 && next_index[LOCAL] == 1) { - status_debug("Retransmitting funding_locked for channel %s", - type_to_string(tmpctx, struct channel_id, channel_id)); - next_commitment_point = get_per_commitment_point(next_index[LOCAL]); - msg = towire_funding_locked(NULL, channel_id, &next_commitment_point); - sync_crypto_write(pps, take(msg)); - } -} - static void send_offer(struct per_peer_state *pps, const struct chainparams *chainparams, const struct channel_id *channel_id, @@ -648,11 +511,7 @@ int main(int argc, char *argv[]) u8 fee_negotiation_step_unit; char fee_negotiation_step_str[32]; /* fee_negotiation_step + "sat" */ struct channel_id channel_id; - bool reconnected; - u64 next_index[NUM_SIDES], revocations_received; enum side whose_turn; - u8 *channel_reestablish; - struct secret last_remote_per_commit_secret; struct bitcoin_outpoint *wrong_funding; subdaemon_setup(argc, argv); @@ -678,12 +537,6 @@ int main(int argc, char *argv[]) &scriptpubkey[REMOTE], &fee_negotiation_step, &fee_negotiation_step_unit, - &reconnected, - &next_index[LOCAL], - &next_index[REMOTE], - &revocations_received, - &channel_reestablish, - &last_remote_per_commit_secret, &dev_fast_gossip, &wrong_funding)) master_badmsg(WIRE_CLOSINGD_INIT, msg); @@ -716,13 +569,6 @@ int main(int argc, char *argv[]) &funding_pubkey[LOCAL], &funding_pubkey[REMOTE]); - if (reconnected) - do_reconnect(pps, &channel_id, - next_index, revocations_received, - channel_reestablish, scriptpubkey[LOCAL], - &last_remote_per_commit_secret, - wrong_funding); - peer_billboard( true, "Negotiating closing fee between %s and %s satoshi (ideal %s) " diff --git a/closingd/closingd_wire.csv b/closingd/closingd_wire.csv index c6f7ea07f5f3..4558c9a982d2 100644 --- a/closingd/closingd_wire.csv +++ b/closingd/closingd_wire.csv @@ -26,13 +26,6 @@ msgdata,closingd_init,remote_scriptpubkey_len,u16, msgdata,closingd_init,remote_scriptpubkey,u8,remote_scriptpubkey_len msgdata,closingd_init,fee_negotiation_step,u64, msgdata,closingd_init,fee_negotiation_step_unit,u8, -msgdata,closingd_init,reconnected,bool, -msgdata,closingd_init,next_index_local,u64, -msgdata,closingd_init,next_index_remote,u64, -msgdata,closingd_init,revocations_received,u64, -msgdata,closingd_init,channel_reestablish_len,u16, -msgdata,closingd_init,channel_reestablish,u8,channel_reestablish_len -msgdata,closingd_init,last_remote_secret,secret, msgdata,closingd_init,dev_fast_gossip,bool, msgdata,closingd_init,shutdown_wrong_funding,?bitcoin_outpoint, diff --git a/closingd/closingd_wiregen.c b/closingd/closingd_wiregen.c index 91f2693f80ca..94914f2ed452 100644 --- a/closingd/closingd_wiregen.c +++ b/closingd/closingd_wiregen.c @@ -48,11 +48,10 @@ bool closingd_wire_is_defined(u16 type) /* WIRE: CLOSINGD_INIT */ /* Begin! (passes peer fd */ -u8 *towire_closingd_init(const tal_t *ctx, const struct chainparams *chainparams, const struct per_peer_state *pps, const struct channel_id *channel_id, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshi, const struct pubkey *local_fundingkey, const struct pubkey *remote_fundingkey, enum side opener, struct amount_sat local_sat, struct amount_sat remote_sat, struct amount_sat our_dust_limit, struct amount_sat min_fee_satoshi, struct amount_sat fee_limit_satoshi, struct amount_sat initial_fee_satoshi, const u8 *local_scriptpubkey, const u8 *remote_scriptpubkey, u64 fee_negotiation_step, u8 fee_negotiation_step_unit, bool reconnected, u64 next_index_local, u64 next_index_remote, u64 revocations_received, const u8 *channel_reestablish, const struct secret *last_remote_secret, bool dev_fast_gossip, const struct bitcoin_outpoint *shutdown_wrong_funding) +u8 *towire_closingd_init(const tal_t *ctx, const struct chainparams *chainparams, const struct per_peer_state *pps, const struct channel_id *channel_id, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshi, const struct pubkey *local_fundingkey, const struct pubkey *remote_fundingkey, enum side opener, struct amount_sat local_sat, struct amount_sat remote_sat, struct amount_sat our_dust_limit, struct amount_sat min_fee_satoshi, struct amount_sat fee_limit_satoshi, struct amount_sat initial_fee_satoshi, const u8 *local_scriptpubkey, const u8 *remote_scriptpubkey, u64 fee_negotiation_step, u8 fee_negotiation_step_unit, bool dev_fast_gossip, const struct bitcoin_outpoint *shutdown_wrong_funding) { u16 local_scriptpubkey_len = tal_count(local_scriptpubkey); u16 remote_scriptpubkey_len = tal_count(remote_scriptpubkey); - u16 channel_reestablish_len = tal_count(channel_reestablish); u8 *p = tal_arr(ctx, u8, 0); towire_u16(&p, WIRE_CLOSINGD_INIT); @@ -77,13 +76,6 @@ u8 *towire_closingd_init(const tal_t *ctx, const struct chainparams *chainparams towire_u8_array(&p, remote_scriptpubkey, remote_scriptpubkey_len); towire_u64(&p, fee_negotiation_step); towire_u8(&p, fee_negotiation_step_unit); - towire_bool(&p, reconnected); - towire_u64(&p, next_index_local); - towire_u64(&p, next_index_remote); - towire_u64(&p, revocations_received); - towire_u16(&p, channel_reestablish_len); - towire_u8_array(&p, channel_reestablish, channel_reestablish_len); - towire_secret(&p, last_remote_secret); towire_bool(&p, dev_fast_gossip); if (!shutdown_wrong_funding) towire_bool(&p, false); @@ -94,11 +86,10 @@ u8 *towire_closingd_init(const tal_t *ctx, const struct chainparams *chainparams return memcheck(p, tal_count(p)); } -bool fromwire_closingd_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct per_peer_state **pps, struct channel_id *channel_id, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshi, struct pubkey *local_fundingkey, struct pubkey *remote_fundingkey, enum side *opener, struct amount_sat *local_sat, struct amount_sat *remote_sat, struct amount_sat *our_dust_limit, struct amount_sat *min_fee_satoshi, struct amount_sat *fee_limit_satoshi, struct amount_sat *initial_fee_satoshi, u8 **local_scriptpubkey, u8 **remote_scriptpubkey, u64 *fee_negotiation_step, u8 *fee_negotiation_step_unit, bool *reconnected, u64 *next_index_local, u64 *next_index_remote, u64 *revocations_received, u8 **channel_reestablish, struct secret *last_remote_secret, bool *dev_fast_gossip, struct bitcoin_outpoint **shutdown_wrong_funding) +bool fromwire_closingd_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct per_peer_state **pps, struct channel_id *channel_id, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshi, struct pubkey *local_fundingkey, struct pubkey *remote_fundingkey, enum side *opener, struct amount_sat *local_sat, struct amount_sat *remote_sat, struct amount_sat *our_dust_limit, struct amount_sat *min_fee_satoshi, struct amount_sat *fee_limit_satoshi, struct amount_sat *initial_fee_satoshi, u8 **local_scriptpubkey, u8 **remote_scriptpubkey, u64 *fee_negotiation_step, u8 *fee_negotiation_step_unit, bool *dev_fast_gossip, struct bitcoin_outpoint **shutdown_wrong_funding) { u16 local_scriptpubkey_len; u16 remote_scriptpubkey_len; - u16 channel_reestablish_len; const u8 *cursor = p; size_t plen = tal_count(p); @@ -130,15 +121,6 @@ bool fromwire_closingd_init(const tal_t *ctx, const void *p, const struct chainp fromwire_u8_array(&cursor, &plen, *remote_scriptpubkey, remote_scriptpubkey_len); *fee_negotiation_step = fromwire_u64(&cursor, &plen); *fee_negotiation_step_unit = fromwire_u8(&cursor, &plen); - *reconnected = fromwire_bool(&cursor, &plen); - *next_index_local = fromwire_u64(&cursor, &plen); - *next_index_remote = fromwire_u64(&cursor, &plen); - *revocations_received = fromwire_u64(&cursor, &plen); - channel_reestablish_len = fromwire_u16(&cursor, &plen); - // 2nd case channel_reestablish - *channel_reestablish = channel_reestablish_len ? tal_arr(ctx, u8, channel_reestablish_len) : NULL; - fromwire_u8_array(&cursor, &plen, *channel_reestablish, channel_reestablish_len); - fromwire_secret(&cursor, &plen, last_remote_secret); *dev_fast_gossip = fromwire_bool(&cursor, &plen); if (!fromwire_bool(&cursor, &plen)) *shutdown_wrong_funding = NULL; @@ -213,4 +195,4 @@ bool fromwire_closingd_complete(const void *p) return false; return cursor != NULL; } -// SHA256STAMP:95043321951ace6f7a5ee9f1dc0ae57c8a6427644b8b79d3e08e521dc9b3b49f +// SHA256STAMP:1dcbd7b74aeab22bc03fc0af061676d79772b025f85f58e8cc747e6f4d1df917 diff --git a/closingd/closingd_wiregen.h b/closingd/closingd_wiregen.h index ea2aa4f2e144..9b9895a23fcd 100644 --- a/closingd/closingd_wiregen.h +++ b/closingd/closingd_wiregen.h @@ -37,8 +37,8 @@ bool closingd_wire_is_defined(u16 type); /* WIRE: CLOSINGD_INIT */ /* Begin! (passes peer fd */ -u8 *towire_closingd_init(const tal_t *ctx, const struct chainparams *chainparams, const struct per_peer_state *pps, const struct channel_id *channel_id, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshi, const struct pubkey *local_fundingkey, const struct pubkey *remote_fundingkey, enum side opener, struct amount_sat local_sat, struct amount_sat remote_sat, struct amount_sat our_dust_limit, struct amount_sat min_fee_satoshi, struct amount_sat fee_limit_satoshi, struct amount_sat initial_fee_satoshi, const u8 *local_scriptpubkey, const u8 *remote_scriptpubkey, u64 fee_negotiation_step, u8 fee_negotiation_step_unit, bool reconnected, u64 next_index_local, u64 next_index_remote, u64 revocations_received, const u8 *channel_reestablish, const struct secret *last_remote_secret, bool dev_fast_gossip, const struct bitcoin_outpoint *shutdown_wrong_funding); -bool fromwire_closingd_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct per_peer_state **pps, struct channel_id *channel_id, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshi, struct pubkey *local_fundingkey, struct pubkey *remote_fundingkey, enum side *opener, struct amount_sat *local_sat, struct amount_sat *remote_sat, struct amount_sat *our_dust_limit, struct amount_sat *min_fee_satoshi, struct amount_sat *fee_limit_satoshi, struct amount_sat *initial_fee_satoshi, u8 **local_scriptpubkey, u8 **remote_scriptpubkey, u64 *fee_negotiation_step, u8 *fee_negotiation_step_unit, bool *reconnected, u64 *next_index_local, u64 *next_index_remote, u64 *revocations_received, u8 **channel_reestablish, struct secret *last_remote_secret, bool *dev_fast_gossip, struct bitcoin_outpoint **shutdown_wrong_funding); +u8 *towire_closingd_init(const tal_t *ctx, const struct chainparams *chainparams, const struct per_peer_state *pps, const struct channel_id *channel_id, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshi, const struct pubkey *local_fundingkey, const struct pubkey *remote_fundingkey, enum side opener, struct amount_sat local_sat, struct amount_sat remote_sat, struct amount_sat our_dust_limit, struct amount_sat min_fee_satoshi, struct amount_sat fee_limit_satoshi, struct amount_sat initial_fee_satoshi, const u8 *local_scriptpubkey, const u8 *remote_scriptpubkey, u64 fee_negotiation_step, u8 fee_negotiation_step_unit, bool dev_fast_gossip, const struct bitcoin_outpoint *shutdown_wrong_funding); +bool fromwire_closingd_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct per_peer_state **pps, struct channel_id *channel_id, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshi, struct pubkey *local_fundingkey, struct pubkey *remote_fundingkey, enum side *opener, struct amount_sat *local_sat, struct amount_sat *remote_sat, struct amount_sat *our_dust_limit, struct amount_sat *min_fee_satoshi, struct amount_sat *fee_limit_satoshi, struct amount_sat *initial_fee_satoshi, u8 **local_scriptpubkey, u8 **remote_scriptpubkey, u64 *fee_negotiation_step, u8 *fee_negotiation_step_unit, bool *dev_fast_gossip, struct bitcoin_outpoint **shutdown_wrong_funding); /* WIRE: CLOSINGD_RECEIVED_SIGNATURE */ /* We received an offer */ @@ -56,4 +56,4 @@ bool fromwire_closingd_complete(const void *p); #endif /* LIGHTNING_CLOSINGD_CLOSINGD_WIREGEN_H */ -// SHA256STAMP:95043321951ace6f7a5ee9f1dc0ae57c8a6427644b8b79d3e08e521dc9b3b49f +// SHA256STAMP:1dcbd7b74aeab22bc03fc0af061676d79772b025f85f58e8cc747e6f4d1df917 diff --git a/gossipd/test/run-bench-find_route.c b/gossipd/test/run-bench-find_route.c index 476053582169..0772b7d2348f 100644 --- a/gossipd/test/run-bench-find_route.c +++ b/gossipd/test/run-bench-find_route.c @@ -92,9 +92,6 @@ u8 *towire_warningfmt(const tal_t *ctx UNNEEDED, const struct channel_id *channel UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "towire_warningfmt called!\n"); abort(); } -/* Generated stub for update_peers_broadcast_index */ -void update_peers_broadcast_index(struct list_head *peers UNNEEDED, u32 offset UNNEEDED) -{ fprintf(stderr, "update_peers_broadcast_index called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ #if DEVELOPER diff --git a/gossipd/test/run-find_route-specific.c b/gossipd/test/run-find_route-specific.c index 52256dacb368..64060092c2cb 100644 --- a/gossipd/test/run-find_route-specific.c +++ b/gossipd/test/run-find_route-specific.c @@ -78,9 +78,6 @@ u8 *towire_warningfmt(const tal_t *ctx UNNEEDED, const struct channel_id *channel UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "towire_warningfmt called!\n"); abort(); } -/* Generated stub for update_peers_broadcast_index */ -void update_peers_broadcast_index(struct list_head *peers UNNEEDED, u32 offset UNNEEDED) -{ fprintf(stderr, "update_peers_broadcast_index called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ #if DEVELOPER diff --git a/gossipd/test/run-find_route.c b/gossipd/test/run-find_route.c index 609282974484..41400bf2cd05 100644 --- a/gossipd/test/run-find_route.c +++ b/gossipd/test/run-find_route.c @@ -78,9 +78,6 @@ u8 *towire_warningfmt(const tal_t *ctx UNNEEDED, const struct channel_id *channel UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "towire_warningfmt called!\n"); abort(); } -/* Generated stub for update_peers_broadcast_index */ -void update_peers_broadcast_index(struct list_head *peers UNNEEDED, u32 offset UNNEEDED) -{ fprintf(stderr, "update_peers_broadcast_index called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ #if DEVELOPER diff --git a/gossipd/test/run-overlong.c b/gossipd/test/run-overlong.c index d400aa792626..2a16642f7026 100644 --- a/gossipd/test/run-overlong.c +++ b/gossipd/test/run-overlong.c @@ -78,9 +78,6 @@ u8 *towire_warningfmt(const tal_t *ctx UNNEEDED, const struct channel_id *channel UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "towire_warningfmt called!\n"); abort(); } -/* Generated stub for update_peers_broadcast_index */ -void update_peers_broadcast_index(struct list_head *peers UNNEEDED, u32 offset UNNEEDED) -{ fprintf(stderr, "update_peers_broadcast_index called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ #if DEVELOPER diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index 3958e9dfa1b7..7bee48ecbb5d 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -321,12 +321,15 @@ static void peer_start_closingd_after_shutdown(struct channel *channel, per_peer_state_set_fds_arr(pps, fds); /* This sets channel->owner, closes down channeld. */ - peer_start_closingd(channel, pps, false, NULL); - channel_set_state(channel, - CHANNELD_SHUTTING_DOWN, - CLOSINGD_SIGEXCHANGE, - REASON_UNKNOWN, - "Start closingd"); + peer_start_closingd(channel, pps); + + /* We might have reconnected, so already be here. */ + if (channel->state != CLOSINGD_SIGEXCHANGE) + channel_set_state(channel, + CHANNELD_SHUTTING_DOWN, + CLOSINGD_SIGEXCHANGE, + REASON_UNKNOWN, + "Start closingd"); } static void forget(struct channel *channel) @@ -593,7 +596,8 @@ void peer_start_channeld(struct channel *channel, channel->remote_funding_locked, &scid, reconnected, - channel->state == CHANNELD_SHUTTING_DOWN, + channel->state == CHANNELD_SHUTTING_DOWN + || channel->state == CLOSINGD_SIGEXCHANGE, channel->shutdown_scriptpubkey[REMOTE] != NULL, channel->shutdown_scriptpubkey[LOCAL], channel->channel_flags, diff --git a/lightningd/closing_control.c b/lightningd/closing_control.c index 2df07d6f5de8..83865209abd0 100644 --- a/lightningd/closing_control.c +++ b/lightningd/closing_control.c @@ -181,17 +181,13 @@ static unsigned closing_msg(struct subd *sd, const u8 *msg, const int *fds UNUSE } void peer_start_closingd(struct channel *channel, - struct per_peer_state *pps, - bool reconnected, - const u8 *channel_reestablish) + struct per_peer_state *pps) { u8 *initmsg; u32 feerate; struct amount_sat minfee, startfee, feelimit; - u64 num_revocations; struct amount_msat their_msat; int hsmfd; - struct secret last_remote_per_commit_secret; struct lightningd *ld = channel->peer->ld; u32 final_commit_feerate; @@ -258,9 +254,6 @@ void peer_start_closingd(struct channel *channel, if (amount_sat_greater(minfee, feelimit)) minfee = feelimit; - num_revocations - = revocations_received(&channel->their_shachain.chain); - /* BOLT #3: * * Each node offering a signature: @@ -280,25 +273,6 @@ void peer_start_closingd(struct channel *channel, return; } - /* BOLT #2: - * - if `next_revocation_number` equals 0: - * - MUST set `your_last_per_commitment_secret` to all zeroes - * - otherwise: - * - MUST set `your_last_per_commitment_secret` to the last - * `per_commitment_secret` it received - */ - if (num_revocations == 0) - memset(&last_remote_per_commit_secret, 0, - sizeof(last_remote_per_commit_secret)); - else if (!shachain_get_secret(&channel->their_shachain.chain, - num_revocations-1, - &last_remote_per_commit_secret)) { - channel_fail_permanent(channel, - REASON_LOCAL, - "Could not get revocation secret %"PRIu64, - num_revocations-1); - return; - } initmsg = towire_closingd_init(tmpctx, chainparams, pps, @@ -317,12 +291,6 @@ void peer_start_closingd(struct channel *channel, channel->shutdown_scriptpubkey[REMOTE], channel->closing_fee_negotiation_step, channel->closing_fee_negotiation_step_unit, - reconnected, - channel->next_index[LOCAL], - channel->next_index[REMOTE], - num_revocations, - channel_reestablish, - &last_remote_per_commit_secret, IFDEV(ld->dev_fast_gossip, false), channel->shutdown_wrong_funding); diff --git a/lightningd/closing_control.h b/lightningd/closing_control.h index cbaa76ab9941..0ee6afb29a56 100644 --- a/lightningd/closing_control.h +++ b/lightningd/closing_control.h @@ -3,13 +3,10 @@ #include "config.h" #include -struct channel_id; -struct crypto_state; +struct channel; struct per_peer_state; void peer_start_closingd(struct channel *channel, - struct per_peer_state *pps, - bool reconnected, - const u8 *channel_reestablish); + struct per_peer_state *pps); #endif /* LIGHTNING_LIGHTNINGD_CLOSING_CONTROL_H */ diff --git a/lightningd/dual_open_control.c b/lightningd/dual_open_control.c index 292531e1173f..2f4fb2c8ccaa 100644 --- a/lightningd/dual_open_control.c +++ b/lightningd/dual_open_control.c @@ -1294,7 +1294,7 @@ static void handle_channel_closed(struct subd *dualopend, per_peer_state_set_fds_arr(pps, fds); - peer_start_closingd(channel, pps, false, NULL); + peer_start_closingd(channel, pps); channel_set_state(channel, CHANNELD_SHUTTING_DOWN, CLOSINGD_SIGEXCHANGE, diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 93b31c17f045..bd64636733c6 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -1128,7 +1128,7 @@ static void peer_connected_hook_final(struct peer_connected_hook_payload *payloa assert(!channel->owner); channel->peer->addr = addr; channel->peer->connected_incoming = payload->incoming; - peer_start_closingd(channel, payload->pps, true, NULL); + peer_start_channeld(channel, payload->pps, NULL, true); return; } abort(); diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index 5634b25b9549..510906b3e734 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -578,12 +578,6 @@ void peer_start_channeld(struct channel *channel UNNEEDED, const u8 *fwd_msg 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 per_peer_state *pps UNNEEDED, - bool reconnected UNNEEDED, - const u8 *channel_reestablish UNNEEDED) -{ fprintf(stderr, "peer_start_closingd called!\n"); abort(); } /* Generated stub for peer_start_dualopend */ void peer_start_dualopend(struct peer *peer UNNEEDED, struct per_peer_state *pps UNNEEDED, diff --git a/tests/test_closing.py b/tests/test_closing.py index 7f8d75aff863..bd58319236b5 100644 --- a/tests/test_closing.py +++ b/tests/test_closing.py @@ -2749,7 +2749,6 @@ def test_shutdown_alternate_txid(node_factory, bitcoind): wait_for(lambda: l1.rpc.listpeers()['peers'] == []) -@pytest.mark.xfail(strict=True) @pytest.mark.developer("needs dev_disconnect") def test_htlc_rexmit_while_closing(node_factory, executor): """Retranmitting an HTLC revocation while shutting down should work""" diff --git a/tests/test_connection.py b/tests/test_connection.py index 80fea2994309..1ddb6bb21279 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -554,7 +554,7 @@ def test_reconnect_no_update(node_factory, executor, bitcoind): # Close will trigger the @WIRE_SHUTDOWN and we then wait for the # automatic reconnection to trigger the retransmission. l1.rpc.close(l2.info['id'], 0) - l2.daemon.wait_for_log(r"closingd.* Retransmitting funding_locked for channel") + l2.daemon.wait_for_log(r"channeld.* Retransmitting funding_locked for channel") l1.daemon.wait_for_log(r"CLOSINGD_COMPLETE") diff --git a/wallet/db_postgres_sqlgen.c b/wallet/db_postgres_sqlgen.c index 6e4dd0b44015..42a21966720c 100644 --- a/wallet/db_postgres_sqlgen.c +++ b/wallet/db_postgres_sqlgen.c @@ -1906,4 +1906,4 @@ struct db_query db_postgres_queries[] = { #endif /* LIGHTNINGD_WALLET_GEN_DB_POSTGRES */ -// SHA256STAMP:0e328ae08429373c5aa43797ae12be23e5b6c3d7e2f06123c2640a1a42ac79ee +// SHA256STAMP:554fa318878413e112eb4db1f7c49b668972d98eac22032dd9c37b7408e99e8b diff --git a/wallet/db_sqlite3_sqlgen.c b/wallet/db_sqlite3_sqlgen.c index 994b296e7ac0..caaa5378a446 100644 --- a/wallet/db_sqlite3_sqlgen.c +++ b/wallet/db_sqlite3_sqlgen.c @@ -1906,4 +1906,4 @@ struct db_query db_sqlite3_queries[] = { #endif /* LIGHTNINGD_WALLET_GEN_DB_SQLITE3 */ -// SHA256STAMP:0e328ae08429373c5aa43797ae12be23e5b6c3d7e2f06123c2640a1a42ac79ee +// SHA256STAMP:554fa318878413e112eb4db1f7c49b668972d98eac22032dd9c37b7408e99e8b diff --git a/wallet/statements_gettextgen.po b/wallet/statements_gettextgen.po index d4f00c142b7f..3e72bf87e43d 100644 --- a/wallet/statements_gettextgen.po +++ b/wallet/statements_gettextgen.po @@ -1250,11 +1250,11 @@ msgstr "" msgid "not a valid SQL statement" msgstr "" -#: wallet/test/run-wallet.c:1449 +#: wallet/test/run-wallet.c:1443 msgid "SELECT COUNT(1) FROM channel_funding_inflights WHERE channel_id = ?;" msgstr "" -#: wallet/test/run-wallet.c:1647 +#: wallet/test/run-wallet.c:1641 msgid "INSERT INTO channels (id) VALUES (1);" msgstr "" -# SHA256STAMP:2fdded09bd28387ed024108cbe04c6ba1e158605c4c84eb1cf4caa83e26599fe +# SHA256STAMP:7ad9dc6b09cb25c62a002e8ac32b14a453fcf1d22f980076af6489c974c5112e diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index 4401f4468fe1..42e949bf08a8 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -650,12 +650,6 @@ void peer_start_channeld(struct channel *channel UNNEEDED, const u8 *fwd_msg 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 per_peer_state *pps UNNEEDED, - bool reconnected UNNEEDED, - const u8 *channel_reestablish UNNEEDED) -{ fprintf(stderr, "peer_start_closingd called!\n"); abort(); } /* Generated stub for peer_start_dualopend */ void peer_start_dualopend(struct peer *peer UNNEEDED, struct per_peer_state *pps UNNEEDED,