From 80c2f283736999b2cb333245b192ab41fd897b38 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 16 Mar 2021 06:55:41 +1030 Subject: [PATCH] channeld: accept the 'wrong_funding' shutdown TLV. If it passes checks, lightningd puts it in the database. Signed-off-by: Rusty Russell --- channeld/channeld.c | 32 +++++- channeld/channeld_wire.csv | 1 + channeld/channeld_wiregen.c | 18 ++- channeld/channeld_wiregen.h | 6 +- lightningd/channel.c | 7 +- lightningd/channel.h | 7 +- lightningd/channel_control.c | 9 +- lightningd/opening_control.c | 3 +- wallet/db_postgres_sqlgen.c | 8 +- wallet/db_sqlite3_sqlgen.c | 8 +- wallet/statements_gettextgen.po | 196 ++++++++++++++++---------------- wallet/test/run-wallet.c | 2 +- wallet/wallet.c | 26 ++++- 13 files changed, 201 insertions(+), 122 deletions(-) diff --git a/channeld/channeld.c b/channeld/channeld.c index 28f957c89..ca3eae79d 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -1636,6 +1636,7 @@ static void handle_peer_shutdown(struct peer *peer, const u8 *shutdown) struct channel_id channel_id; u8 *scriptpubkey; struct tlv_shutdown_tlvs *tlvs = tlv_shutdown_tlvs_new(tmpctx); + struct bitcoin_outpoint *wrong_funding; /* Disable the channel. */ send_channel_update(peer, ROUTING_FLAGS_DISABLED); @@ -1663,6 +1664,12 @@ static void handle_peer_shutdown(struct peer *peer, const u8 *shutdown) tal_hex(peer, scriptpubkey), tal_hex(peer, peer->remote_upfront_shutdown_script)); + /* We only accept an wrong_funding if: + * 1. It was negotiated. + * 2. It's not dual-funding. + * 3. They opened it. + * 4. The channel was never used. + */ if (tlvs->wrong_funding) { if (!feature_negotiated(peer->our_features, peer->their_features, @@ -1671,12 +1678,35 @@ static void handle_peer_shutdown(struct peer *peer, const u8 *shutdown) "wrong_funding shutdown needs" " feature %u", OPT_SHUTDOWN_WRONG_FUNDING); + if (feature_negotiated(peer->our_features, + peer->their_features, + OPT_DUAL_FUND)) + peer_failed_warn(peer->pps, &peer->channel_id, + "wrong_funding shutdown invalid" + " with dual-funding"); + if (peer->channel->opener != REMOTE) + peer_failed_warn(peer->pps, &peer->channel_id, + "No shutdown wrong_funding" + " for channels we opened!"); + if (peer->next_index[REMOTE] != 1 + || peer->next_index[LOCAL] != 1) + peer_failed_warn(peer->pps, &peer->channel_id, + "No shutdown wrong_funding" + " for used channels!"); + + /* Turn into our outpoint type. */ + wrong_funding = tal(tmpctx, struct bitcoin_outpoint); + wrong_funding->txid = tlvs->wrong_funding->txid; + wrong_funding->n = tlvs->wrong_funding->outnum; + } else { + wrong_funding = NULL; } /* Tell master: we don't have to wait because on reconnect other end * will re-send anyway. */ wire_sync_write(MASTER_FD, - take(towire_channeld_got_shutdown(NULL, scriptpubkey))); + take(towire_channeld_got_shutdown(NULL, scriptpubkey, + wrong_funding))); peer->shutdown_sent[REMOTE] = true; /* BOLT #2: diff --git a/channeld/channeld_wire.csv b/channeld/channeld_wire.csv index a06861abd..cd94c22a6 100644 --- a/channeld/channeld_wire.csv +++ b/channeld/channeld_wire.csv @@ -173,6 +173,7 @@ msgdata,channeld_send_shutdown,shutdown_scriptpubkey,u8,shutdown_len msgtype,channeld_got_shutdown,1024 msgdata,channeld_got_shutdown,scriptpubkey_len,u16, msgdata,channeld_got_shutdown,scriptpubkey,u8,scriptpubkey_len +msgdata,channeld_got_shutdown,wrong_funding,?bitcoin_outpoint, # Shutdown is complete, ready for closing negotiation. + peer_fd & gossip_fd. msgtype,channeld_shutdown_complete,1025 diff --git a/channeld/channeld_wiregen.c b/channeld/channeld_wiregen.c index ef8aa1aed..3c91557cc 100644 --- a/channeld/channeld_wiregen.c +++ b/channeld/channeld_wiregen.c @@ -767,7 +767,7 @@ bool fromwire_channeld_send_shutdown(const tal_t *ctx, const void *p, u8 **shutd /* WIRE: CHANNELD_GOT_SHUTDOWN */ /* Peer told us that channel is shutting down */ -u8 *towire_channeld_got_shutdown(const tal_t *ctx, const u8 *scriptpubkey) +u8 *towire_channeld_got_shutdown(const tal_t *ctx, const u8 *scriptpubkey, const struct bitcoin_outpoint *wrong_funding) { u16 scriptpubkey_len = tal_count(scriptpubkey); u8 *p = tal_arr(ctx, u8, 0); @@ -775,10 +775,16 @@ u8 *towire_channeld_got_shutdown(const tal_t *ctx, const u8 *scriptpubkey) towire_u16(&p, WIRE_CHANNELD_GOT_SHUTDOWN); towire_u16(&p, scriptpubkey_len); towire_u8_array(&p, scriptpubkey, scriptpubkey_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)); } -bool fromwire_channeld_got_shutdown(const tal_t *ctx, const void *p, u8 **scriptpubkey) +bool fromwire_channeld_got_shutdown(const tal_t *ctx, const void *p, u8 **scriptpubkey, struct bitcoin_outpoint **wrong_funding) { u16 scriptpubkey_len; @@ -791,6 +797,12 @@ bool fromwire_channeld_got_shutdown(const tal_t *ctx, const void *p, u8 **script // 2nd case scriptpubkey *scriptpubkey = scriptpubkey_len ? tal_arr(ctx, u8, scriptpubkey_len) : NULL; fromwire_u8_array(&cursor, &plen, *scriptpubkey, scriptpubkey_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; } @@ -1046,4 +1058,4 @@ bool fromwire_channeld_send_error_reply(const void *p) return false; return cursor != NULL; } -// SHA256STAMP:8b6491f5aa25f4c067f4aedff32620ddb8b39cc78f95c70cb2d0b5366026871a +// SHA256STAMP:09bf2ecffadb3ef3959ba8f1154d9b160780e2dd9515b12478bf3155fa34e9ad diff --git a/channeld/channeld_wiregen.h b/channeld/channeld_wiregen.h index 6346058c6..13904a5ec 100644 --- a/channeld/channeld_wiregen.h +++ b/channeld/channeld_wiregen.h @@ -156,8 +156,8 @@ bool fromwire_channeld_send_shutdown(const tal_t *ctx, const void *p, u8 **shutd /* WIRE: CHANNELD_GOT_SHUTDOWN */ /* Peer told us that channel is shutting down */ -u8 *towire_channeld_got_shutdown(const tal_t *ctx, const u8 *scriptpubkey); -bool fromwire_channeld_got_shutdown(const tal_t *ctx, const void *p, u8 **scriptpubkey); +u8 *towire_channeld_got_shutdown(const tal_t *ctx, const u8 *scriptpubkey, const struct bitcoin_outpoint *wrong_funding); +bool fromwire_channeld_got_shutdown(const tal_t *ctx, const void *p, u8 **scriptpubkey, struct bitcoin_outpoint **wrong_funding); /* WIRE: CHANNELD_SHUTDOWN_COMPLETE */ /* Shutdown is complete */ @@ -213,4 +213,4 @@ bool fromwire_channeld_send_error_reply(const void *p); #endif /* LIGHTNING_CHANNELD_CHANNELD_WIREGEN_H */ -// SHA256STAMP:8b6491f5aa25f4c067f4aedff32620ddb8b39cc78f95c70cb2d0b5366026871a +// SHA256STAMP:09bf2ecffadb3ef3959ba8f1154d9b160780e2dd9515b12478bf3155fa34e9ad diff --git a/lightningd/channel.c b/lightningd/channel.c index fd46d71aa..246d5614a 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -240,6 +240,7 @@ struct channel *new_unsaved_channel(struct peer *peer, channel->closing_fee_negotiation_step = 50; channel->closing_fee_negotiation_step_unit = CLOSING_FEE_NEGOTIATION_STEP_UNIT_PERCENTAGE; + channel->shutdown_wrong_funding = NULL; /* Channel is connected! */ channel->connected = true; @@ -332,7 +333,9 @@ struct channel *new_channel(struct peer *peer, u64 dbid, bool option_static_remotekey, bool option_anchor_outputs, enum side closer, - enum state_change reason) + enum state_change reason, + /* NULL or stolen */ + const struct bitcoin_outpoint *shutdown_wrong_funding) { struct channel *channel = tal(peer->ld, struct channel); @@ -394,6 +397,8 @@ struct channel *new_channel(struct peer *peer, u64 dbid, channel->closing_fee_negotiation_step = 50; channel->closing_fee_negotiation_step_unit = CLOSING_FEE_NEGOTIATION_STEP_UNIT_PERCENTAGE; + channel->shutdown_wrong_funding + = tal_steal(channel, shutdown_wrong_funding); if (local_shutdown_scriptpubkey) channel->shutdown_scriptpubkey[LOCAL] = tal_steal(channel, local_shutdown_scriptpubkey); diff --git a/lightningd/channel.h b/lightningd/channel.h index e764c5564..a7e00fcaf 100644 --- a/lightningd/channel.h +++ b/lightningd/channel.h @@ -163,6 +163,9 @@ struct channel { /* Whether closing_fee_negotiation_step is in satoshi or %. */ u8 closing_fee_negotiation_step_unit; + /* optional wrong_funding for mutual close */ + const struct bitcoin_outpoint *shutdown_wrong_funding; + /* Reestablishment stuff: last sent commit and revocation details. */ bool last_was_revoke; struct changed_htlc *last_sent_commit; @@ -269,7 +272,9 @@ struct channel *new_channel(struct peer *peer, u64 dbid, bool option_static_remotekey, bool option_anchor_outputs, enum side closer, - enum state_change reason); + enum state_change reason, + /* NULL or stolen */ + const struct bitcoin_outpoint *shutdown_wrong_funding STEALS); /* new_inflight - Create a new channel_inflight for a channel */ struct channel_inflight * diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index a4e2fc59d..e6ba176b8 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -227,11 +227,13 @@ static void peer_got_shutdown(struct channel *channel, const u8 *msg) { u8 *scriptpubkey; struct lightningd *ld = channel->peer->ld; + struct bitcoin_outpoint *wrong_funding; bool anysegwit = feature_negotiated(ld->our_features, channel->peer->their_features, OPT_SHUTDOWN_ANYSEGWIT); - if (!fromwire_channeld_got_shutdown(channel, msg, &scriptpubkey)) { + if (!fromwire_channeld_got_shutdown(channel, msg, &scriptpubkey, + &wrong_funding)) { channel_internal_error(channel, "bad channel_got_shutdown %s", tal_hex(msg, msg)); return; @@ -257,6 +259,11 @@ static void peer_got_shutdown(struct channel *channel, const u8 *msg) REASON_REMOTE, "Peer closes channel"); + /* If we set it, that's what we want. Otherwise use their preference. + * We can't have both, since only opener can set this! */ + if (!channel->shutdown_wrong_funding) + channel->shutdown_wrong_funding = wrong_funding; + /* TODO(cdecker) Selectively save updated fields to DB */ wallet_channel_save(ld->wallet, channel); } diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 163971bf7..6f9bfe738 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -210,7 +210,8 @@ wallet_commit_channel(struct lightningd *ld, option_static_remotekey, option_anchor_outputs, NUM_SIDES, /* closer not yet known */ - uc->fc ? REASON_USER : REASON_REMOTE); + uc->fc ? REASON_USER : REASON_REMOTE, + NULL); /* Now we finally put it in the database. */ wallet_channel_insert(ld->wallet, channel); diff --git a/wallet/db_postgres_sqlgen.c b/wallet/db_postgres_sqlgen.c index 07660baab..16155376d 100644 --- a/wallet/db_postgres_sqlgen.c +++ b/wallet/db_postgres_sqlgen.c @@ -1353,9 +1353,9 @@ struct db_query db_postgres_queries[] = { .readonly = false, }, { - .name = "UPDATE channels SET shachain_remote_id=?, short_channel_id=?, full_channel_id=?, state=?, funder=?, channel_flags=?, minimum_depth=?, next_index_local=?, next_index_remote=?, next_htlc_id=?, funding_tx_id=?, funding_tx_outnum=?, funding_satoshi=?, our_funding_satoshi=?, funding_locked_remote=?, push_msatoshi=?, msatoshi_local=?, shutdown_scriptpubkey_remote=?, shutdown_keyidx_local=?, channel_config_local=?, last_tx=?, last_sig=?, last_was_revoke=?, min_possible_feerate=?, max_possible_feerate=?, msatoshi_to_us_min=?, msatoshi_to_us_max=?, feerate_base=?, feerate_ppm=?, remote_upfront_shutdown_script=?, option_static_remotekey=?, option_anchor_outputs=?, shutdown_scriptpubkey_local=?, closer=?, state_change_reason=? WHERE id=?", - .query = "UPDATE channels SET shachain_remote_id=$1, short_channel_id=$2, full_channel_id=$3, state=$4, funder=$5, channel_flags=$6, minimum_depth=$7, next_index_local=$8, next_index_remote=$9, next_htlc_id=$10, funding_tx_id=$11, funding_tx_outnum=$12, funding_satoshi=$13, our_funding_satoshi=$14, funding_locked_remote=$15, push_msatoshi=$16, msatoshi_local=$17, shutdown_scriptpubkey_remote=$18, shutdown_keyidx_local=$19, channel_config_local=$20, last_tx=$21, last_sig=$22, last_was_revoke=$23, min_possible_feerate=$24, max_possible_feerate=$25, msatoshi_to_us_min=$26, msatoshi_to_us_max=$27, feerate_base=$28, feerate_ppm=$29, remote_upfront_shutdown_script=$30, option_static_remotekey=$31, option_anchor_outputs=$32, shutdown_scriptpubkey_local=$33, closer=$34, state_change_reason=$35 WHERE id=$36", - .placeholders = 36, + .name = "UPDATE channels SET shachain_remote_id=?, short_channel_id=?, full_channel_id=?, state=?, funder=?, channel_flags=?, minimum_depth=?, next_index_local=?, next_index_remote=?, next_htlc_id=?, funding_tx_id=?, funding_tx_outnum=?, funding_satoshi=?, our_funding_satoshi=?, funding_locked_remote=?, push_msatoshi=?, msatoshi_local=?, shutdown_scriptpubkey_remote=?, shutdown_keyidx_local=?, channel_config_local=?, last_tx=?, last_sig=?, last_was_revoke=?, min_possible_feerate=?, max_possible_feerate=?, msatoshi_to_us_min=?, msatoshi_to_us_max=?, feerate_base=?, feerate_ppm=?, remote_upfront_shutdown_script=?, option_static_remotekey=?, option_anchor_outputs=?, shutdown_scriptpubkey_local=?, closer=?, state_change_reason=?, shutdown_wrong_txid=?, shutdown_wrong_outnum=? WHERE id=?", + .query = "UPDATE channels SET shachain_remote_id=$1, short_channel_id=$2, full_channel_id=$3, state=$4, funder=$5, channel_flags=$6, minimum_depth=$7, next_index_local=$8, next_index_remote=$9, next_htlc_id=$10, funding_tx_id=$11, funding_tx_outnum=$12, funding_satoshi=$13, our_funding_satoshi=$14, funding_locked_remote=$15, push_msatoshi=$16, msatoshi_local=$17, shutdown_scriptpubkey_remote=$18, shutdown_keyidx_local=$19, channel_config_local=$20, last_tx=$21, last_sig=$22, last_was_revoke=$23, min_possible_feerate=$24, max_possible_feerate=$25, msatoshi_to_us_min=$26, msatoshi_to_us_max=$27, feerate_base=$28, feerate_ppm=$29, remote_upfront_shutdown_script=$30, option_static_remotekey=$31, option_anchor_outputs=$32, shutdown_scriptpubkey_local=$33, closer=$34, state_change_reason=$35, shutdown_wrong_txid=$36, shutdown_wrong_outnum=$37 WHERE id=$38", + .placeholders = 38, .readonly = false, }, { @@ -1888,4 +1888,4 @@ struct db_query db_postgres_queries[] = { #endif /* LIGHTNINGD_WALLET_GEN_DB_POSTGRES */ -// SHA256STAMP:2f7fe69dc5a4d2904d678ad97eea588b6df44bb565b5391ff104c8237e6ff0b9 +// SHA256STAMP:7eea03944a711e7f4660ef2d02e6ad1af12938d123e4585d179c0c31be1d4278 diff --git a/wallet/db_sqlite3_sqlgen.c b/wallet/db_sqlite3_sqlgen.c index 5f7aae692..3f386d5fe 100644 --- a/wallet/db_sqlite3_sqlgen.c +++ b/wallet/db_sqlite3_sqlgen.c @@ -1353,9 +1353,9 @@ struct db_query db_sqlite3_queries[] = { .readonly = false, }, { - .name = "UPDATE channels SET shachain_remote_id=?, short_channel_id=?, full_channel_id=?, state=?, funder=?, channel_flags=?, minimum_depth=?, next_index_local=?, next_index_remote=?, next_htlc_id=?, funding_tx_id=?, funding_tx_outnum=?, funding_satoshi=?, our_funding_satoshi=?, funding_locked_remote=?, push_msatoshi=?, msatoshi_local=?, shutdown_scriptpubkey_remote=?, shutdown_keyidx_local=?, channel_config_local=?, last_tx=?, last_sig=?, last_was_revoke=?, min_possible_feerate=?, max_possible_feerate=?, msatoshi_to_us_min=?, msatoshi_to_us_max=?, feerate_base=?, feerate_ppm=?, remote_upfront_shutdown_script=?, option_static_remotekey=?, option_anchor_outputs=?, shutdown_scriptpubkey_local=?, closer=?, state_change_reason=? WHERE id=?", - .query = "UPDATE channels SET shachain_remote_id=?, short_channel_id=?, full_channel_id=?, state=?, funder=?, channel_flags=?, minimum_depth=?, next_index_local=?, next_index_remote=?, next_htlc_id=?, funding_tx_id=?, funding_tx_outnum=?, funding_satoshi=?, our_funding_satoshi=?, funding_locked_remote=?, push_msatoshi=?, msatoshi_local=?, shutdown_scriptpubkey_remote=?, shutdown_keyidx_local=?, channel_config_local=?, last_tx=?, last_sig=?, last_was_revoke=?, min_possible_feerate=?, max_possible_feerate=?, msatoshi_to_us_min=?, msatoshi_to_us_max=?, feerate_base=?, feerate_ppm=?, remote_upfront_shutdown_script=?, option_static_remotekey=?, option_anchor_outputs=?, shutdown_scriptpubkey_local=?, closer=?, state_change_reason=? WHERE id=?", - .placeholders = 36, + .name = "UPDATE channels SET shachain_remote_id=?, short_channel_id=?, full_channel_id=?, state=?, funder=?, channel_flags=?, minimum_depth=?, next_index_local=?, next_index_remote=?, next_htlc_id=?, funding_tx_id=?, funding_tx_outnum=?, funding_satoshi=?, our_funding_satoshi=?, funding_locked_remote=?, push_msatoshi=?, msatoshi_local=?, shutdown_scriptpubkey_remote=?, shutdown_keyidx_local=?, channel_config_local=?, last_tx=?, last_sig=?, last_was_revoke=?, min_possible_feerate=?, max_possible_feerate=?, msatoshi_to_us_min=?, msatoshi_to_us_max=?, feerate_base=?, feerate_ppm=?, remote_upfront_shutdown_script=?, option_static_remotekey=?, option_anchor_outputs=?, shutdown_scriptpubkey_local=?, closer=?, state_change_reason=?, shutdown_wrong_txid=?, shutdown_wrong_outnum=? WHERE id=?", + .query = "UPDATE channels SET shachain_remote_id=?, short_channel_id=?, full_channel_id=?, state=?, funder=?, channel_flags=?, minimum_depth=?, next_index_local=?, next_index_remote=?, next_htlc_id=?, funding_tx_id=?, funding_tx_outnum=?, funding_satoshi=?, our_funding_satoshi=?, funding_locked_remote=?, push_msatoshi=?, msatoshi_local=?, shutdown_scriptpubkey_remote=?, shutdown_keyidx_local=?, channel_config_local=?, last_tx=?, last_sig=?, last_was_revoke=?, min_possible_feerate=?, max_possible_feerate=?, msatoshi_to_us_min=?, msatoshi_to_us_max=?, feerate_base=?, feerate_ppm=?, remote_upfront_shutdown_script=?, option_static_remotekey=?, option_anchor_outputs=?, shutdown_scriptpubkey_local=?, closer=?, state_change_reason=?, shutdown_wrong_txid=?, shutdown_wrong_outnum=? WHERE id=?", + .placeholders = 38, .readonly = false, }, { @@ -1888,4 +1888,4 @@ struct db_query db_sqlite3_queries[] = { #endif /* LIGHTNINGD_WALLET_GEN_DB_SQLITE3 */ -// SHA256STAMP:2f7fe69dc5a4d2904d678ad97eea588b6df44bb565b5391ff104c8237e6ff0b9 +// SHA256STAMP:7eea03944a711e7f4660ef2d02e6ad1af12938d123e4585d179c0c31be1d4278 diff --git a/wallet/statements_gettextgen.po b/wallet/statements_gettextgen.po index 083e0e352..6fb759f44 100644 --- a/wallet/statements_gettextgen.po +++ b/wallet/statements_gettextgen.po @@ -846,387 +846,387 @@ msgstr "" msgid "SELECT funding_tx_id, funding_tx_outnum, funding_feerate, funding_satoshi, our_funding_satoshi, funding_psbt, last_tx, last_sig FROM channel_funding_inflights WHERE channel_id = ?" msgstr "" -#: wallet/wallet.c:1251 +#: wallet/wallet.c:1260 msgid "SELECT id FROM channels ORDER BY id DESC LIMIT 1;" msgstr "" -#: wallet/wallet.c:1268 +#: wallet/wallet.c:1277 msgid "SELECT id, peer_id, short_channel_id, full_channel_id, channel_config_local, channel_config_remote, state, funder, channel_flags, minimum_depth, next_index_local, next_index_remote, next_htlc_id, funding_tx_id, funding_tx_outnum, funding_satoshi, our_funding_satoshi, funding_locked_remote, push_msatoshi, msatoshi_local, fundingkey_remote, revocation_basepoint_remote, payment_basepoint_remote, htlc_basepoint_remote, delayed_payment_basepoint_remote, per_commit_remote, old_per_commit_remote, local_feerate_per_kw, remote_feerate_per_kw, shachain_remote_id, shutdown_scriptpubkey_remote, shutdown_keyidx_local, last_sent_commit_state, last_sent_commit_id, last_tx, last_sig, last_was_revoke, first_blocknum, min_possible_feerate, max_possible_feerate, msatoshi_to_us_min, msatoshi_to_us_max, future_per_commitment_point, last_sent_commit, feerate_base, feerate_ppm, remote_upfront_shutdown_script, option_static_remotekey, option_anchor_outputs, shutdown_scriptpubkey_local, closer, state_change_reason, revocation_basepoint_local, payment_basepoint_local, htlc_basepoint_local, delayed_payment_basepoint_local, funding_pubkey_local, shutdown_wrong_txid, shutdown_wrong_outnum FROM channels WHERE state != ?;" msgstr "" -#: wallet/wallet.c:1366 +#: wallet/wallet.c:1375 msgid "UPDATE channels SET in_payments_offered = COALESCE(in_payments_offered, 0) + 1 , in_msatoshi_offered = COALESCE(in_msatoshi_offered, 0) + ? WHERE id = ?;" msgstr "" -#: wallet/wallet.c:1371 +#: wallet/wallet.c:1380 msgid "UPDATE channels SET in_payments_fulfilled = COALESCE(in_payments_fulfilled, 0) + 1 , in_msatoshi_fulfilled = COALESCE(in_msatoshi_fulfilled, 0) + ? WHERE id = ?;" msgstr "" -#: wallet/wallet.c:1376 +#: wallet/wallet.c:1385 msgid "UPDATE channels SET out_payments_offered = COALESCE(out_payments_offered, 0) + 1 , out_msatoshi_offered = COALESCE(out_msatoshi_offered, 0) + ? WHERE id = ?;" msgstr "" -#: wallet/wallet.c:1381 +#: wallet/wallet.c:1390 msgid "UPDATE channels SET out_payments_fulfilled = COALESCE(out_payments_fulfilled, 0) + 1 , out_msatoshi_fulfilled = COALESCE(out_msatoshi_fulfilled, 0) + ? WHERE id = ?;" msgstr "" -#: wallet/wallet.c:1423 +#: wallet/wallet.c:1432 msgid "SELECT in_payments_offered, in_payments_fulfilled, in_msatoshi_offered, in_msatoshi_fulfilled, out_payments_offered, out_payments_fulfilled, out_msatoshi_offered, out_msatoshi_fulfilled FROM channels WHERE id = ?" msgstr "" -#: wallet/wallet.c:1452 +#: wallet/wallet.c:1461 msgid "SELECT MIN(height), MAX(height) FROM blocks;" msgstr "" -#: wallet/wallet.c:1474 +#: wallet/wallet.c:1483 msgid "INSERT INTO channel_configs DEFAULT VALUES;" msgstr "" -#: wallet/wallet.c:1486 +#: wallet/wallet.c:1495 msgid "UPDATE channel_configs SET dust_limit_satoshis=?, max_htlc_value_in_flight_msat=?, channel_reserve_satoshis=?, htlc_minimum_msat=?, to_self_delay=?, max_accepted_htlcs=? WHERE id=?;" msgstr "" -#: wallet/wallet.c:1510 +#: wallet/wallet.c:1519 msgid "SELECT id, dust_limit_satoshis, max_htlc_value_in_flight_msat, channel_reserve_satoshis, htlc_minimum_msat, to_self_delay, max_accepted_htlcs FROM channel_configs WHERE id= ? ;" msgstr "" -#: wallet/wallet.c:1544 +#: wallet/wallet.c:1553 msgid "UPDATE channels SET remote_ann_node_sig=?, remote_ann_bitcoin_sig=? WHERE id=?" msgstr "" -#: wallet/wallet.c:1563 -msgid "UPDATE channels SET shachain_remote_id=?, short_channel_id=?, full_channel_id=?, state=?, funder=?, channel_flags=?, minimum_depth=?, next_index_local=?, next_index_remote=?, next_htlc_id=?, funding_tx_id=?, funding_tx_outnum=?, funding_satoshi=?, our_funding_satoshi=?, funding_locked_remote=?, push_msatoshi=?, msatoshi_local=?, shutdown_scriptpubkey_remote=?, shutdown_keyidx_local=?, channel_config_local=?, last_tx=?, last_sig=?, last_was_revoke=?, min_possible_feerate=?, max_possible_feerate=?, msatoshi_to_us_min=?, msatoshi_to_us_max=?, feerate_base=?, feerate_ppm=?, remote_upfront_shutdown_script=?, option_static_remotekey=?, option_anchor_outputs=?, shutdown_scriptpubkey_local=?, closer=?, state_change_reason=? WHERE id=?" +#: wallet/wallet.c:1572 +msgid "UPDATE channels SET shachain_remote_id=?, short_channel_id=?, full_channel_id=?, state=?, funder=?, channel_flags=?, minimum_depth=?, next_index_local=?, next_index_remote=?, next_htlc_id=?, funding_tx_id=?, funding_tx_outnum=?, funding_satoshi=?, our_funding_satoshi=?, funding_locked_remote=?, push_msatoshi=?, msatoshi_local=?, shutdown_scriptpubkey_remote=?, shutdown_keyidx_local=?, channel_config_local=?, last_tx=?, last_sig=?, last_was_revoke=?, min_possible_feerate=?, max_possible_feerate=?, msatoshi_to_us_min=?, msatoshi_to_us_max=?, feerate_base=?, feerate_ppm=?, remote_upfront_shutdown_script=?, option_static_remotekey=?, option_anchor_outputs=?, shutdown_scriptpubkey_local=?, closer=?, state_change_reason=?, shutdown_wrong_txid=?, shutdown_wrong_outnum=? WHERE id=?" msgstr "" -#: wallet/wallet.c:1646 +#: wallet/wallet.c:1664 msgid "UPDATE channels SET fundingkey_remote=?, revocation_basepoint_remote=?, payment_basepoint_remote=?, htlc_basepoint_remote=?, delayed_payment_basepoint_remote=?, per_commit_remote=?, old_per_commit_remote=?, channel_config_remote=?, future_per_commitment_point=? WHERE id=?" msgstr "" -#: wallet/wallet.c:1673 +#: wallet/wallet.c:1691 msgid "DELETE FROM channel_feerates WHERE channel_id=?" msgstr "" -#: wallet/wallet.c:1683 +#: wallet/wallet.c:1701 msgid "INSERT INTO channel_feerates VALUES(?, ?, ?)" msgstr "" -#: wallet/wallet.c:1700 +#: wallet/wallet.c:1718 msgid "UPDATE channels SET last_sent_commit=? WHERE id=?" msgstr "" -#: wallet/wallet.c:1723 +#: wallet/wallet.c:1741 msgid "INSERT INTO channel_state_changes ( channel_id, timestamp, old_state, new_state, cause, message) VALUES (?, ?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:1751 +#: wallet/wallet.c:1769 msgid "SELECT timestamp, old_state, new_state, cause, message FROM channel_state_changes WHERE channel_id = ? ORDER BY timestamp ASC;" msgstr "" -#: wallet/wallet.c:1780 +#: wallet/wallet.c:1798 msgid "SELECT id FROM peers WHERE node_id = ?" msgstr "" -#: wallet/wallet.c:1792 +#: wallet/wallet.c:1810 msgid "UPDATE peers SET address = ? WHERE id = ?" msgstr "" -#: wallet/wallet.c:1801 +#: wallet/wallet.c:1819 msgid "INSERT INTO peers (node_id, address) VALUES (?, ?);" msgstr "" -#: wallet/wallet.c:1822 +#: wallet/wallet.c:1840 msgid "INSERT INTO channels ( peer_id, first_blocknum, id, revocation_basepoint_local, payment_basepoint_local, htlc_basepoint_local, delayed_payment_basepoint_local, funding_pubkey_local) VALUES (?, ?, ?, ?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:1863 +#: wallet/wallet.c:1881 msgid "DELETE FROM channel_htlcs WHERE channel_id=?" msgstr "" -#: wallet/wallet.c:1869 +#: wallet/wallet.c:1887 msgid "DELETE FROM htlc_sigs WHERE channelid=?" msgstr "" -#: wallet/wallet.c:1875 +#: wallet/wallet.c:1893 msgid "DELETE FROM channeltxs WHERE channel_id=?" msgstr "" -#: wallet/wallet.c:1882 +#: wallet/wallet.c:1900 msgid "DELETE FROM channel_funding_inflights WHERE channel_id=?" msgstr "" -#: wallet/wallet.c:1888 +#: wallet/wallet.c:1906 msgid "DELETE FROM shachains WHERE id IN ( SELECT shachain_remote_id FROM channels WHERE channels.id=?)" msgstr "" -#: wallet/wallet.c:1898 +#: wallet/wallet.c:1916 msgid "UPDATE channels SET state=?, peer_id=? WHERE channels.id=?" msgstr "" -#: wallet/wallet.c:1912 +#: wallet/wallet.c:1930 msgid "SELECT * FROM channels WHERE peer_id = ?;" msgstr "" -#: wallet/wallet.c:1920 +#: wallet/wallet.c:1938 msgid "DELETE FROM peers WHERE id=?" msgstr "" -#: wallet/wallet.c:1931 +#: wallet/wallet.c:1949 msgid "UPDATE outputs SET confirmation_height = ? WHERE prev_out_tx = ?" msgstr "" -#: wallet/wallet.c:2034 +#: wallet/wallet.c:2052 msgid "INSERT INTO channel_htlcs ( channel_id, channel_htlc_id, direction, msatoshi, cltv_expiry, payment_hash, payment_key, hstate, shared_secret, routing_onion, received_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:2087 +#: wallet/wallet.c:2105 msgid "INSERT INTO channel_htlcs ( channel_id, channel_htlc_id, direction, origin_htlc, msatoshi, cltv_expiry, payment_hash, payment_key, hstate, routing_onion, malformed_onion, partid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, ?);" msgstr "" -#: wallet/wallet.c:2148 +#: wallet/wallet.c:2166 msgid "UPDATE channel_htlcs SET hstate=?, payment_key=?, malformed_onion=?, failuremsg=?, localfailmsg=?, we_filled=? WHERE id=?" msgstr "" -#: wallet/wallet.c:2364 +#: wallet/wallet.c:2382 msgid "SELECT id, channel_htlc_id, msatoshi, cltv_expiry, hstate, payment_hash, payment_key, routing_onion, failuremsg, malformed_onion, origin_htlc, shared_secret, received_time, we_filled FROM channel_htlcs WHERE direction= ? AND channel_id= ? AND hstate != ?" msgstr "" -#: wallet/wallet.c:2411 +#: wallet/wallet.c:2429 msgid "SELECT id, channel_htlc_id, msatoshi, cltv_expiry, hstate, payment_hash, payment_key, routing_onion, failuremsg, malformed_onion, origin_htlc, shared_secret, received_time, partid, localfailmsg FROM channel_htlcs WHERE direction = ? AND channel_id = ? AND hstate != ?" msgstr "" -#: wallet/wallet.c:2542 +#: wallet/wallet.c:2560 msgid "SELECT channel_id, direction, cltv_expiry, channel_htlc_id, payment_hash FROM channel_htlcs WHERE channel_id = ?;" msgstr "" -#: wallet/wallet.c:2576 +#: wallet/wallet.c:2594 msgid "DELETE FROM channel_htlcs WHERE direction = ? AND origin_htlc = ? AND payment_hash = ? AND partid = ?;" msgstr "" -#: wallet/wallet.c:2629 +#: wallet/wallet.c:2647 msgid "SELECT status FROM payments WHERE payment_hash=? AND partid = ?;" msgstr "" -#: wallet/wallet.c:2647 +#: wallet/wallet.c:2665 msgid "INSERT INTO payments ( status, payment_hash, destination, msatoshi, timestamp, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, total_msat, partid, local_offer_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:2736 +#: wallet/wallet.c:2754 msgid "DELETE FROM payments WHERE payment_hash = ? AND partid = ?" msgstr "" -#: wallet/wallet.c:2750 +#: wallet/wallet.c:2768 msgid "DELETE FROM payments WHERE payment_hash = ?" msgstr "" -#: wallet/wallet.c:2851 +#: wallet/wallet.c:2869 msgid "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid, local_offer_id FROM payments WHERE payment_hash = ? AND partid = ?" msgstr "" -#: wallet/wallet.c:2901 +#: wallet/wallet.c:2919 msgid "UPDATE payments SET status=? WHERE payment_hash=? AND partid=?" msgstr "" -#: wallet/wallet.c:2911 +#: wallet/wallet.c:2929 msgid "UPDATE payments SET payment_preimage=? WHERE payment_hash=? AND partid=?" msgstr "" -#: wallet/wallet.c:2921 +#: wallet/wallet.c:2939 msgid "UPDATE payments SET path_secrets = NULL , route_nodes = NULL , route_channels = NULL WHERE payment_hash = ? AND partid = ?;" msgstr "" -#: wallet/wallet.c:2953 +#: wallet/wallet.c:2971 msgid "SELECT failonionreply, faildestperm, failindex, failcode, failnode, failchannel, failupdate, faildetail, faildirection FROM payments WHERE payment_hash=? AND partid=?;" msgstr "" -#: wallet/wallet.c:3020 +#: wallet/wallet.c:3038 msgid "UPDATE payments SET failonionreply=? , faildestperm=? , failindex=? , failcode=? , failnode=? , failchannel=? , failupdate=? , faildetail=? , faildirection=? WHERE payment_hash=? AND partid=?;" msgstr "" -#: wallet/wallet.c:3079 +#: wallet/wallet.c:3097 msgid "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid, local_offer_id FROM payments WHERE payment_hash = ?;" msgstr "" -#: wallet/wallet.c:3101 +#: wallet/wallet.c:3119 msgid "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid, local_offer_id FROM payments ORDER BY id;" msgstr "" -#: wallet/wallet.c:3152 +#: wallet/wallet.c:3170 msgid "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid, local_offer_id FROM payments WHERE local_offer_id = ?;" msgstr "" -#: wallet/wallet.c:3197 +#: wallet/wallet.c:3215 msgid "DELETE FROM htlc_sigs WHERE channelid = ?" msgstr "" -#: wallet/wallet.c:3204 +#: wallet/wallet.c:3222 msgid "INSERT INTO htlc_sigs (channelid, signature) VALUES (?, ?)" msgstr "" -#: wallet/wallet.c:3216 +#: wallet/wallet.c:3234 msgid "SELECT blobval FROM vars WHERE name='genesis_hash'" msgstr "" -#: wallet/wallet.c:3240 +#: wallet/wallet.c:3258 msgid "INSERT INTO vars (name, blobval) VALUES ('genesis_hash', ?);" msgstr "" -#: wallet/wallet.c:3258 +#: wallet/wallet.c:3276 msgid "SELECT txid, outnum FROM utxoset WHERE spendheight < ?" msgstr "" -#: wallet/wallet.c:3270 +#: wallet/wallet.c:3288 msgid "DELETE FROM utxoset WHERE spendheight < ?" msgstr "" -#: wallet/wallet.c:3278 wallet/wallet.c:3392 +#: wallet/wallet.c:3296 wallet/wallet.c:3410 msgid "INSERT INTO blocks (height, hash, prev_hash) VALUES (?, ?, ?);" msgstr "" -#: wallet/wallet.c:3297 +#: wallet/wallet.c:3315 msgid "DELETE FROM blocks WHERE hash = ?" msgstr "" -#: wallet/wallet.c:3303 +#: wallet/wallet.c:3321 msgid "SELECT * FROM blocks WHERE height >= ?;" msgstr "" -#: wallet/wallet.c:3312 +#: wallet/wallet.c:3330 msgid "DELETE FROM blocks WHERE height > ?" msgstr "" -#: wallet/wallet.c:3324 +#: wallet/wallet.c:3342 msgid "UPDATE outputs SET spend_height = ?, status = ? WHERE prev_out_tx = ? AND prev_out_index = ?" msgstr "" -#: wallet/wallet.c:3342 +#: wallet/wallet.c:3360 msgid "UPDATE utxoset SET spendheight = ? WHERE txid = ? AND outnum = ?" msgstr "" -#: wallet/wallet.c:3365 wallet/wallet.c:3403 +#: wallet/wallet.c:3383 wallet/wallet.c:3421 msgid "INSERT INTO utxoset ( txid, outnum, blockheight, spendheight, txindex, scriptpubkey, satoshis) VALUES(?, ?, ?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:3429 +#: wallet/wallet.c:3447 msgid "SELECT height FROM blocks WHERE height = ?" msgstr "" -#: wallet/wallet.c:3442 +#: wallet/wallet.c:3460 msgid "SELECT txid, spendheight, scriptpubkey, satoshis FROM utxoset WHERE blockheight = ? AND txindex = ? AND outnum = ? AND spendheight IS NULL" msgstr "" -#: wallet/wallet.c:3484 +#: wallet/wallet.c:3502 msgid "SELECT blockheight, txindex, outnum FROM utxoset WHERE spendheight = ?" msgstr "" -#: wallet/wallet.c:3515 wallet/wallet.c:3675 +#: wallet/wallet.c:3533 wallet/wallet.c:3693 msgid "SELECT blockheight FROM transactions WHERE id=?" msgstr "" -#: wallet/wallet.c:3525 +#: wallet/wallet.c:3543 msgid "INSERT INTO transactions ( id, blockheight, txindex, rawtx) VALUES (?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:3546 +#: wallet/wallet.c:3564 msgid "UPDATE transactions SET blockheight = ?, txindex = ? WHERE id = ?" msgstr "" -#: wallet/wallet.c:3563 +#: wallet/wallet.c:3581 msgid "INSERT INTO transaction_annotations (txid, idx, location, type, channel) VALUES (?, ?, ?, ?, ?) ON CONFLICT(txid,idx) DO NOTHING;" msgstr "" -#: wallet/wallet.c:3595 +#: wallet/wallet.c:3613 msgid "SELECT type, channel_id FROM transactions WHERE id=?" msgstr "" -#: wallet/wallet.c:3611 +#: wallet/wallet.c:3629 msgid "UPDATE transactions SET type = ?, channel_id = ? WHERE id = ?" msgstr "" -#: wallet/wallet.c:3630 +#: wallet/wallet.c:3648 msgid "SELECT type FROM transactions WHERE id=?" msgstr "" -#: wallet/wallet.c:3653 +#: wallet/wallet.c:3671 msgid "SELECT rawtx FROM transactions WHERE id=?" msgstr "" -#: wallet/wallet.c:3699 +#: wallet/wallet.c:3717 msgid "SELECT blockheight, txindex FROM transactions WHERE id=?" msgstr "" -#: wallet/wallet.c:3727 +#: wallet/wallet.c:3745 msgid "SELECT id FROM transactions WHERE blockheight=?" msgstr "" -#: wallet/wallet.c:3746 +#: wallet/wallet.c:3764 msgid "INSERT INTO channeltxs ( channel_id, type, transaction_id, input_num, blockheight) VALUES (?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:3770 +#: wallet/wallet.c:3788 msgid "SELECT DISTINCT(channel_id) FROM channeltxs WHERE type = ?;" msgstr "" -#: wallet/wallet.c:3791 +#: wallet/wallet.c:3809 msgid "SELECT c.type, c.blockheight, t.rawtx, c.input_num, c.blockheight - t.blockheight + 1 AS depth, t.id as txid FROM channeltxs c JOIN transactions t ON t.id = c.transaction_id WHERE c.channel_id = ? ORDER BY c.id ASC;" msgstr "" -#: wallet/wallet.c:3836 +#: wallet/wallet.c:3854 msgid "UPDATE forwarded_payments SET in_msatoshi=?, out_msatoshi=?, state=?, resolved_time=?, failcode=? WHERE in_htlc_id=?" msgstr "" -#: wallet/wallet.c:3894 +#: wallet/wallet.c:3912 msgid "INSERT INTO forwarded_payments ( in_htlc_id, out_htlc_id, in_channel_scid, out_channel_scid, in_msatoshi, out_msatoshi, state, received_time, resolved_time, failcode) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:3953 +#: wallet/wallet.c:3971 msgid "SELECT CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)FROM forwarded_payments WHERE state = ?;" msgstr "" -#: wallet/wallet.c:4002 +#: wallet/wallet.c:4020 msgid "SELECT f.state, in_msatoshi, out_msatoshi, hin.payment_hash as payment_hash, in_channel_scid, out_channel_scid, f.received_time, f.resolved_time, f.failcode FROM forwarded_payments f LEFT JOIN channel_htlcs hin ON (f.in_htlc_id = hin.id) WHERE (1 = ? OR f.state = ?) AND (1 = ? OR f.in_channel_scid = ?) AND (1 = ? OR f.out_channel_scid = ?)" msgstr "" -#: wallet/wallet.c:4124 +#: wallet/wallet.c:4142 msgid "SELECT t.id, t.rawtx, t.blockheight, t.txindex, t.type as txtype, c2.short_channel_id as txchan, a.location, a.idx as ann_idx, a.type as annotation_type, c.short_channel_id FROM transactions t LEFT JOIN transaction_annotations a ON (a.txid = t.id) LEFT JOIN channels c ON (a.channel = c.id) LEFT JOIN channels c2 ON (t.channel_id = c2.id) ORDER BY t.blockheight, t.txindex ASC" msgstr "" -#: wallet/wallet.c:4218 +#: wallet/wallet.c:4236 msgid "INSERT INTO penalty_bases ( channel_id, commitnum, txid, outnum, amount) VALUES (?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:4243 +#: wallet/wallet.c:4261 msgid "SELECT commitnum, txid, outnum, amount FROM penalty_bases WHERE channel_id = ?" msgstr "" -#: wallet/wallet.c:4267 +#: wallet/wallet.c:4285 msgid "DELETE FROM penalty_bases WHERE channel_id = ? AND commitnum = ?" msgstr "" -#: wallet/wallet.c:4285 +#: wallet/wallet.c:4303 msgid "SELECT 1 FROM offers WHERE offer_id = ?;" msgstr "" -#: wallet/wallet.c:4298 +#: wallet/wallet.c:4316 msgid "INSERT INTO offers ( offer_id, bolt12, label, status) VALUES (?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:4325 +#: wallet/wallet.c:4343 msgid "SELECT bolt12, label, status FROM offers WHERE offer_id = ?;" msgstr "" -#: wallet/wallet.c:4353 +#: wallet/wallet.c:4371 msgid "SELECT offer_id FROM offers;" msgstr "" -#: wallet/wallet.c:4379 +#: wallet/wallet.c:4397 msgid "UPDATE offers SET status=? WHERE offer_id = ?;" msgstr "" -#: wallet/wallet.c:4390 +#: wallet/wallet.c:4408 msgid "UPDATE invoices SET state=? WHERE state=? AND local_offer_id = ?;" msgstr "" -#: wallet/wallet.c:4418 +#: wallet/wallet.c:4436 msgid "SELECT status FROM offers WHERE offer_id = ?;" msgstr "" @@ -1245,4 +1245,4 @@ msgstr "" #: wallet/test/run-wallet.c:1632 msgid "INSERT INTO channels (id) VALUES (1);" msgstr "" -# SHA256STAMP:8c8e651c259b33910c13fff8fa52d1ada04a025436dfa5bd40557652600d586e +# SHA256STAMP:8da50eaa6605e1f68e9cfa47733d265cc60040f859941eb9358af99720138142 diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index 00cf006c4..3a475a740 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -1524,7 +1524,7 @@ static bool test_channel_inflight_crud(struct lightningd *ld, const tal_t *ctx) &pk, NULL, 1000, 100, NULL, true, true, - LOCAL, REASON_UNKNOWN); + LOCAL, REASON_UNKNOWN, NULL); db_begin_transaction(w->db); CHECK(!wallet_err); wallet_channel_insert(w, chan); diff --git a/wallet/wallet.c b/wallet/wallet.c index 1c3ac408a..be907ee7c 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -1074,6 +1074,7 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm struct wallet_shachain wshachain; struct channel_config our_config; struct bitcoin_txid funding_txid; + struct bitcoin_outpoint *shutdown_wrong_funding; struct bitcoin_signature last_sig; u8 *remote_shutdown_scriptpubkey; u8 *local_shutdown_scriptpubkey; @@ -1178,6 +1179,13 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm db_column_pubkey(stmt, 54, &local_basepoints.htlc); db_column_pubkey(stmt, 55, &local_basepoints.delayed_payment); db_column_pubkey(stmt, 56, &local_funding_pubkey); + if (db_column_is_null(stmt, 57)) + shutdown_wrong_funding = NULL; + else { + shutdown_wrong_funding = tal(tmpctx, struct bitcoin_outpoint); + db_column_txid(stmt, 57, &shutdown_wrong_funding->txid); + shutdown_wrong_funding->n = db_column_int(stmt, 58); + } db_column_amount_sat(stmt, 15, &funding_sat); db_column_amount_sat(stmt, 16, &our_funding_sat); @@ -1234,7 +1242,8 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm db_column_int(stmt, 47), db_column_int(stmt, 48), db_column_int(stmt, 50), - db_column_int(stmt, 51)); + db_column_int(stmt, 51), + shutdown_wrong_funding); if (!wallet_channel_load_inflights(w, chan)) { tal_free(chan); @@ -1594,8 +1603,10 @@ void wallet_channel_save(struct wallet *w, struct channel *chan) " option_anchor_outputs=?," // 31 " shutdown_scriptpubkey_local=?," // 32 " closer=?," // 33 - " state_change_reason=?" // 34 - " WHERE id=?")); // 35 + " state_change_reason=?," // 34 + " shutdown_wrong_txid=?," // 35 + " shutdown_wrong_outnum=?" // 36 + " WHERE id=?")); // 37 db_bind_u64(stmt, 0, chan->their_shachain.id); if (chan->scid) db_bind_short_channel_id(stmt, 1, chan->scid); @@ -1639,7 +1650,14 @@ void wallet_channel_save(struct wallet *w, struct channel *chan) db_bind_talarr(stmt, 32, chan->shutdown_scriptpubkey[LOCAL]); db_bind_int(stmt, 33, chan->closer); db_bind_int(stmt, 34, chan->state_change_cause); - db_bind_u64(stmt, 35, chan->dbid); + if (chan->shutdown_wrong_funding) { + db_bind_txid(stmt, 35, &chan->shutdown_wrong_funding->txid); + db_bind_int(stmt, 36, chan->shutdown_wrong_funding->n); + } else { + db_bind_null(stmt, 35); + db_bind_null(stmt, 36); + } + db_bind_u64(stmt, 37, chan->dbid); db_exec_prepared_v2(take(stmt)); wallet_channel_config_save(w, &chan->channel_info.their_config);