channeld: code to send wrong_funding if lightningd says to.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2021-03-16 06:55:52 +10:30
parent 80c2f28373
commit 820fbcd65a
10 changed files with 42 additions and 15 deletions

View file

@ -156,6 +156,8 @@ struct peer {
bool send_shutdown; bool send_shutdown;
/* Has shutdown been sent by each side? */ /* Has shutdown been sent by each side? */
bool shutdown_sent[NUM_SIDES]; bool shutdown_sent[NUM_SIDES];
/* If master told us to send wrong_funding */
struct bitcoin_outpoint *shutdown_wrong_funding;
/* Information used for reestablishment. */ /* Information used for reestablishment. */
bool last_was_revoke; bool last_was_revoke;
@ -740,6 +742,7 @@ static bool shutdown_complete(const struct peer *peer)
static void maybe_send_shutdown(struct peer *peer) static void maybe_send_shutdown(struct peer *peer)
{ {
u8 *msg; u8 *msg;
struct tlv_shutdown_tlvs *tlvs;
if (!peer->send_shutdown) if (!peer->send_shutdown)
return; return;
@ -748,9 +751,17 @@ static void maybe_send_shutdown(struct peer *peer)
* over us */ * over us */
send_channel_update(peer, ROUTING_FLAGS_DISABLED); send_channel_update(peer, ROUTING_FLAGS_DISABLED);
/* FIXME: send wrong_funding */ if (peer->shutdown_wrong_funding) {
tlvs = tlv_shutdown_tlvs_new(tmpctx);
tlvs->wrong_funding
= tal(tlvs, struct tlv_shutdown_tlvs_wrong_funding);
tlvs->wrong_funding->txid = peer->shutdown_wrong_funding->txid;
tlvs->wrong_funding->outnum = peer->shutdown_wrong_funding->n;
} else
tlvs = NULL;
msg = towire_shutdown(NULL, &peer->channel_id, peer->final_scriptpubkey, msg = towire_shutdown(NULL, &peer->channel_id, peer->final_scriptpubkey,
NULL); tlvs);
sync_crypto_write(peer->pps, take(msg)); sync_crypto_write(peer->pps, take(msg));
peer->send_shutdown = false; peer->send_shutdown = false;
peer->shutdown_sent[LOCAL] = true; peer->shutdown_sent[LOCAL] = true;
@ -2867,7 +2878,8 @@ static void handle_shutdown_cmd(struct peer *peer, const u8 *inmsg)
{ {
u8 *local_shutdown_script; u8 *local_shutdown_script;
if (!fromwire_channeld_send_shutdown(peer, inmsg, &local_shutdown_script)) if (!fromwire_channeld_send_shutdown(peer, inmsg, &local_shutdown_script,
&peer->shutdown_wrong_funding))
master_badmsg(WIRE_CHANNELD_SEND_SHUTDOWN, inmsg); master_badmsg(WIRE_CHANNELD_SEND_SHUTDOWN, inmsg);
tal_free(peer->final_scriptpubkey); tal_free(peer->final_scriptpubkey);
@ -3228,6 +3240,7 @@ int main(int argc, char *argv[])
peer->channel_local_active = false; peer->channel_local_active = false;
peer->from_master = msg_queue_new(peer); peer->from_master = msg_queue_new(peer);
peer->shutdown_sent[LOCAL] = false; peer->shutdown_sent[LOCAL] = false;
peer->shutdown_wrong_funding = NULL;
peer->last_update_timestamp = 0; peer->last_update_timestamp = 0;
/* We actually received it in the previous daemon, but near enough */ /* We actually received it in the previous daemon, but near enough */
peer->last_recv = time_now(); peer->last_recv = time_now();

View file

@ -168,6 +168,7 @@ msgtype,channeld_got_revoke_reply,1122
msgtype,channeld_send_shutdown,1023 msgtype,channeld_send_shutdown,1023
msgdata,channeld_send_shutdown,shutdown_len,u16, msgdata,channeld_send_shutdown,shutdown_len,u16,
msgdata,channeld_send_shutdown,shutdown_scriptpubkey,u8,shutdown_len msgdata,channeld_send_shutdown,shutdown_scriptpubkey,u8,shutdown_len
msgdata,channeld_send_shutdown,wrong_funding,?bitcoin_outpoint,
# Peer told us that channel is shutting down # Peer told us that channel is shutting down
msgtype,channeld_got_shutdown,1024 msgtype,channeld_got_shutdown,1024

Can't render this file because it has a wrong number of fields in line 12.

View file

@ -738,7 +738,7 @@ bool fromwire_channeld_got_revoke_reply(const void *p)
/* WIRE: CHANNELD_SEND_SHUTDOWN */ /* WIRE: CHANNELD_SEND_SHUTDOWN */
/* Tell peer to shut down channel. */ /* Tell peer to shut down channel. */
u8 *towire_channeld_send_shutdown(const tal_t *ctx, const u8 *shutdown_scriptpubkey) u8 *towire_channeld_send_shutdown(const tal_t *ctx, const u8 *shutdown_scriptpubkey, const struct bitcoin_outpoint *wrong_funding)
{ {
u16 shutdown_len = tal_count(shutdown_scriptpubkey); u16 shutdown_len = tal_count(shutdown_scriptpubkey);
u8 *p = tal_arr(ctx, u8, 0); u8 *p = tal_arr(ctx, u8, 0);
@ -746,10 +746,16 @@ u8 *towire_channeld_send_shutdown(const tal_t *ctx, const u8 *shutdown_scriptpub
towire_u16(&p, WIRE_CHANNELD_SEND_SHUTDOWN); towire_u16(&p, WIRE_CHANNELD_SEND_SHUTDOWN);
towire_u16(&p, shutdown_len); towire_u16(&p, shutdown_len);
towire_u8_array(&p, shutdown_scriptpubkey, shutdown_len); towire_u8_array(&p, shutdown_scriptpubkey, shutdown_len);
if (!wrong_funding)
towire_bool(&p, false);
else {
towire_bool(&p, true);
towire_bitcoin_outpoint(&p, wrong_funding);
}
return memcheck(p, tal_count(p)); return memcheck(p, tal_count(p));
} }
bool fromwire_channeld_send_shutdown(const tal_t *ctx, const void *p, u8 **shutdown_scriptpubkey) bool fromwire_channeld_send_shutdown(const tal_t *ctx, const void *p, u8 **shutdown_scriptpubkey, struct bitcoin_outpoint **wrong_funding)
{ {
u16 shutdown_len; u16 shutdown_len;
@ -762,6 +768,12 @@ bool fromwire_channeld_send_shutdown(const tal_t *ctx, const void *p, u8 **shutd
// 2nd case shutdown_scriptpubkey // 2nd case shutdown_scriptpubkey
*shutdown_scriptpubkey = shutdown_len ? tal_arr(ctx, u8, shutdown_len) : NULL; *shutdown_scriptpubkey = shutdown_len ? tal_arr(ctx, u8, shutdown_len) : NULL;
fromwire_u8_array(&cursor, &plen, *shutdown_scriptpubkey, shutdown_len); fromwire_u8_array(&cursor, &plen, *shutdown_scriptpubkey, shutdown_len);
if (!fromwire_bool(&cursor, &plen))
*wrong_funding = NULL;
else {
*wrong_funding = tal(ctx, struct bitcoin_outpoint);
fromwire_bitcoin_outpoint(&cursor, &plen, *wrong_funding);
}
return cursor != NULL; return cursor != NULL;
} }
@ -1058,4 +1070,4 @@ bool fromwire_channeld_send_error_reply(const void *p)
return false; return false;
return cursor != NULL; return cursor != NULL;
} }
// SHA256STAMP:09bf2ecffadb3ef3959ba8f1154d9b160780e2dd9515b12478bf3155fa34e9ad // SHA256STAMP:60143693b0c3611c8ecdf7f3549ef9f4c280e359cac0cd1f4df38cdca2dad3cb

View file

@ -151,8 +151,8 @@ bool fromwire_channeld_got_revoke_reply(const void *p);
/* WIRE: CHANNELD_SEND_SHUTDOWN */ /* WIRE: CHANNELD_SEND_SHUTDOWN */
/* Tell peer to shut down channel. */ /* Tell peer to shut down channel. */
u8 *towire_channeld_send_shutdown(const tal_t *ctx, const u8 *shutdown_scriptpubkey); u8 *towire_channeld_send_shutdown(const tal_t *ctx, const u8 *shutdown_scriptpubkey, const struct bitcoin_outpoint *wrong_funding);
bool fromwire_channeld_send_shutdown(const tal_t *ctx, const void *p, u8 **shutdown_scriptpubkey); bool fromwire_channeld_send_shutdown(const tal_t *ctx, const void *p, u8 **shutdown_scriptpubkey, struct bitcoin_outpoint **wrong_funding);
/* WIRE: CHANNELD_GOT_SHUTDOWN */ /* WIRE: CHANNELD_GOT_SHUTDOWN */
/* Peer told us that channel is shutting down */ /* Peer told us that channel is shutting down */
@ -213,4 +213,4 @@ bool fromwire_channeld_send_error_reply(const void *p);
#endif /* LIGHTNING_CHANNELD_CHANNELD_WIREGEN_H */ #endif /* LIGHTNING_CHANNELD_CHANNELD_WIREGEN_H */
// SHA256STAMP:09bf2ecffadb3ef3959ba8f1154d9b160780e2dd9515b12478bf3155fa34e9ad // SHA256STAMP:60143693b0c3611c8ecdf7f3549ef9f4c280e359cac0cd1f4df38cdca2dad3cb

View file

@ -1647,7 +1647,8 @@ static struct command_result *json_close(struct command *cmd,
} else } else
msg = towire_channeld_send_shutdown( msg = towire_channeld_send_shutdown(
NULL, NULL,
channel->shutdown_scriptpubkey[LOCAL]); channel->shutdown_scriptpubkey[LOCAL],
channel->shutdown_wrong_funding);
subd_send_msg(channel->owner, take(msg)); subd_send_msg(channel->owner, take(msg));
} }

View file

@ -604,7 +604,7 @@ u8 *towire_channeld_dev_memleak(const tal_t *ctx UNNEEDED)
u8 *towire_channeld_dev_reenable_commit(const tal_t *ctx UNNEEDED) u8 *towire_channeld_dev_reenable_commit(const tal_t *ctx UNNEEDED)
{ fprintf(stderr, "towire_channeld_dev_reenable_commit called!\n"); abort(); } { fprintf(stderr, "towire_channeld_dev_reenable_commit called!\n"); abort(); }
/* Generated stub for towire_channeld_send_shutdown */ /* Generated stub for towire_channeld_send_shutdown */
u8 *towire_channeld_send_shutdown(const tal_t *ctx UNNEEDED, const u8 *shutdown_scriptpubkey UNNEEDED) u8 *towire_channeld_send_shutdown(const tal_t *ctx UNNEEDED, const u8 *shutdown_scriptpubkey UNNEEDED, const struct bitcoin_outpoint *wrong_funding UNNEEDED)
{ fprintf(stderr, "towire_channeld_send_shutdown called!\n"); abort(); } { fprintf(stderr, "towire_channeld_send_shutdown called!\n"); abort(); }
/* Generated stub for towire_channeld_specific_feerates */ /* Generated stub for towire_channeld_specific_feerates */
u8 *towire_channeld_specific_feerates(const tal_t *ctx UNNEEDED, u32 feerate_base UNNEEDED, u32 feerate_ppm UNNEEDED) u8 *towire_channeld_specific_feerates(const tal_t *ctx UNNEEDED, u32 feerate_base UNNEEDED, u32 feerate_ppm UNNEEDED)

View file

@ -1888,4 +1888,4 @@ struct db_query db_postgres_queries[] = {
#endif /* LIGHTNINGD_WALLET_GEN_DB_POSTGRES */ #endif /* LIGHTNINGD_WALLET_GEN_DB_POSTGRES */
// SHA256STAMP:7eea03944a711e7f4660ef2d02e6ad1af12938d123e4585d179c0c31be1d4278 // SHA256STAMP:2456747feb02494cb6237921d03c41c45fc86cf20289f4b5c379db7e548761f7

View file

@ -1888,4 +1888,4 @@ struct db_query db_sqlite3_queries[] = {
#endif /* LIGHTNINGD_WALLET_GEN_DB_SQLITE3 */ #endif /* LIGHTNINGD_WALLET_GEN_DB_SQLITE3 */
// SHA256STAMP:7eea03944a711e7f4660ef2d02e6ad1af12938d123e4585d179c0c31be1d4278 // SHA256STAMP:2456747feb02494cb6237921d03c41c45fc86cf20289f4b5c379db7e548761f7

View file

@ -1245,4 +1245,4 @@ msgstr ""
#: wallet/test/run-wallet.c:1632 #: wallet/test/run-wallet.c:1632
msgid "INSERT INTO channels (id) VALUES (1);" msgid "INSERT INTO channels (id) VALUES (1);"
msgstr "" msgstr ""
# SHA256STAMP:8da50eaa6605e1f68e9cfa47733d265cc60040f859941eb9358af99720138142 # SHA256STAMP:6a7cda25fc90182775e1fd2a4055e2c1e74ddca42f8a0160fea20e7aa3d045cb

View file

@ -731,7 +731,7 @@ u8 *towire_channeld_got_revoke_reply(const tal_t *ctx UNNEEDED)
u8 *towire_channeld_offer_htlc(const tal_t *ctx UNNEEDED, struct amount_msat amount_msat UNNEEDED, u32 cltv_expiry UNNEEDED, const struct sha256 *payment_hash UNNEEDED, const u8 onion_routing_packet[1366] UNNEEDED, const struct pubkey *blinding UNNEEDED) u8 *towire_channeld_offer_htlc(const tal_t *ctx UNNEEDED, struct amount_msat amount_msat UNNEEDED, u32 cltv_expiry UNNEEDED, const struct sha256 *payment_hash UNNEEDED, const u8 onion_routing_packet[1366] UNNEEDED, const struct pubkey *blinding UNNEEDED)
{ fprintf(stderr, "towire_channeld_offer_htlc called!\n"); abort(); } { fprintf(stderr, "towire_channeld_offer_htlc called!\n"); abort(); }
/* Generated stub for towire_channeld_send_shutdown */ /* Generated stub for towire_channeld_send_shutdown */
u8 *towire_channeld_send_shutdown(const tal_t *ctx UNNEEDED, const u8 *shutdown_scriptpubkey UNNEEDED) u8 *towire_channeld_send_shutdown(const tal_t *ctx UNNEEDED, const u8 *shutdown_scriptpubkey UNNEEDED, const struct bitcoin_outpoint *wrong_funding UNNEEDED)
{ fprintf(stderr, "towire_channeld_send_shutdown called!\n"); abort(); } { fprintf(stderr, "towire_channeld_send_shutdown called!\n"); abort(); }
/* Generated stub for towire_channeld_sending_commitsig_reply */ /* Generated stub for towire_channeld_sending_commitsig_reply */
u8 *towire_channeld_sending_commitsig_reply(const tal_t *ctx UNNEEDED) u8 *towire_channeld_sending_commitsig_reply(const tal_t *ctx UNNEEDED)