From c239a7161bb6080ad1e7a9b98ec240d256df3ce9 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Tue, 8 Sep 2020 13:26:59 +0200 Subject: [PATCH] wallet: Remove in-memory utxoset filter This removes the in-memory utxoset filter, meaning we now just tracks UTXOs in the DB. --- wallet/db_postgres_sqlgen.c | 16 +-- wallet/db_sqlite3_sqlgen.c | 16 +-- wallet/statements_gettextgen.po | 216 +++++++++++++++----------------- wallet/wallet.c | 54 ++------ wallet/wallet.h | 4 - 5 files changed, 117 insertions(+), 189 deletions(-) diff --git a/wallet/db_postgres_sqlgen.c b/wallet/db_postgres_sqlgen.c index 418f10a8c..d0165b012 100644 --- a/wallet/db_postgres_sqlgen.c +++ b/wallet/db_postgres_sqlgen.c @@ -986,12 +986,6 @@ struct db_query db_postgres_queries[] = { .placeholders = 1, .readonly = true, }, - { - .name = "SELECT txid, outnum FROM utxoset WHERE spendheight is NULL", - .query = "SELECT txid, outnum FROM utxoset WHERE spendheight is NULL", - .placeholders = 0, - .readonly = true, - }, { .name = "SELECT * from outputs WHERE prev_out_tx=? AND prev_out_index=?", .query = "SELECT * from outputs WHERE prev_out_tx=$1 AND prev_out_index=$2", @@ -1418,12 +1412,6 @@ struct db_query db_postgres_queries[] = { .placeholders = 1, .readonly = false, }, - { - .name = "SELECT txid, outnum FROM utxoset WHERE spendheight < ?", - .query = "SELECT txid, outnum FROM utxoset WHERE spendheight < $1", - .placeholders = 1, - .readonly = true, - }, { .name = "DELETE FROM utxoset WHERE spendheight < ?", .query = "DELETE FROM utxoset WHERE spendheight < $1", @@ -1636,10 +1624,10 @@ struct db_query db_postgres_queries[] = { }, }; -#define DB_POSTGRES_QUERY_COUNT 271 +#define DB_POSTGRES_QUERY_COUNT 269 #endif /* HAVE_POSTGRES */ #endif /* LIGHTNINGD_WALLET_GEN_DB_POSTGRES */ -// SHA256STAMP:93c3f12a788012003366f01547f6059bc7894cddd9cf3b046b908f5458452da7 +// SHA256STAMP:933e3d44cffab23c051a63163d4b24bcef044ad617ec3db040e6a92f9c55e0c6 diff --git a/wallet/db_sqlite3_sqlgen.c b/wallet/db_sqlite3_sqlgen.c index 4ea9d086c..14586990c 100644 --- a/wallet/db_sqlite3_sqlgen.c +++ b/wallet/db_sqlite3_sqlgen.c @@ -986,12 +986,6 @@ struct db_query db_sqlite3_queries[] = { .placeholders = 1, .readonly = true, }, - { - .name = "SELECT txid, outnum FROM utxoset WHERE spendheight is NULL", - .query = "SELECT txid, outnum FROM utxoset WHERE spendheight is NULL", - .placeholders = 0, - .readonly = true, - }, { .name = "SELECT * from outputs WHERE prev_out_tx=? AND prev_out_index=?", .query = "SELECT * from outputs WHERE prev_out_tx=? AND prev_out_index=?", @@ -1418,12 +1412,6 @@ struct db_query db_sqlite3_queries[] = { .placeholders = 1, .readonly = false, }, - { - .name = "SELECT txid, outnum FROM utxoset WHERE spendheight < ?", - .query = "SELECT txid, outnum FROM utxoset WHERE spendheight < ?", - .placeholders = 1, - .readonly = true, - }, { .name = "DELETE FROM utxoset WHERE spendheight < ?", .query = "DELETE FROM utxoset WHERE spendheight < ?", @@ -1636,10 +1624,10 @@ struct db_query db_sqlite3_queries[] = { }, }; -#define DB_SQLITE3_QUERY_COUNT 271 +#define DB_SQLITE3_QUERY_COUNT 269 #endif /* HAVE_SQLITE3 */ #endif /* LIGHTNINGD_WALLET_GEN_DB_SQLITE3 */ -// SHA256STAMP:93c3f12a788012003366f01547f6059bc7894cddd9cf3b046b908f5458452da7 +// SHA256STAMP:933e3d44cffab23c051a63163d4b24bcef044ad617ec3db040e6a92f9c55e0c6 diff --git a/wallet/statements_gettextgen.po b/wallet/statements_gettextgen.po index 11eca0a97..5ce12ddbe 100644 --- a/wallet/statements_gettextgen.po +++ b/wallet/statements_gettextgen.po @@ -650,423 +650,415 @@ msgstr "" msgid "SELECT state, payment_key, payment_hash, label, msatoshi, expiry_time, pay_index, msatoshi_received, paid_timestamp, bolt11, description, features FROM invoices WHERE id = ?;" msgstr "" -#: wallet/wallet.c:50 -msgid "SELECT txid, outnum FROM utxoset WHERE spendheight is NULL" -msgstr "" - -#: wallet/wallet.c:91 wallet/wallet.c:569 +#: wallet/wallet.c:75 wallet/wallet.c:553 msgid "SELECT * from outputs WHERE prev_out_tx=? AND prev_out_index=?" msgstr "" -#: wallet/wallet.c:105 wallet/wallet.c:583 +#: wallet/wallet.c:89 wallet/wallet.c:567 msgid "INSERT INTO outputs ( prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:222 +#: wallet/wallet.c:206 msgid "UPDATE outputs SET status=? WHERE status=? AND prev_out_tx=? AND prev_out_index=?" msgstr "" -#: wallet/wallet.c:230 +#: wallet/wallet.c:214 msgid "UPDATE outputs SET status=? WHERE prev_out_tx=? AND prev_out_index=?" msgstr "" -#: wallet/wallet.c:249 +#: wallet/wallet.c:233 msgid "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey , reserved_til FROM outputs" msgstr "" -#: wallet/wallet.c:266 +#: wallet/wallet.c:250 msgid "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey , reserved_til FROM outputs WHERE status= ? " msgstr "" -#: wallet/wallet.c:304 +#: wallet/wallet.c:288 msgid "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey, reserved_til FROM outputs WHERE channel_id IS NOT NULL AND confirmation_height IS NULL" msgstr "" -#: wallet/wallet.c:341 +#: wallet/wallet.c:325 msgid "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey, reserved_til FROM outputs WHERE prev_out_tx = ? AND prev_out_index = ?" msgstr "" -#: wallet/wallet.c:433 +#: wallet/wallet.c:417 msgid "UPDATE outputs SET status=?, reserved_til=?WHERE prev_out_tx=? AND prev_out_index=?" msgstr "" -#: wallet/wallet.c:518 +#: wallet/wallet.c:502 msgid "SELECT prev_out_tx, prev_out_index, value, type, status, keyindex, channel_id, peer_id, commitment_point, option_anchor_outputs, confirmation_height, spend_height, scriptpubkey , reserved_til FROM outputs WHERE status = ? OR (status = ? AND reserved_til <= ?)ORDER BY RANDOM();" msgstr "" -#: wallet/wallet.c:687 +#: wallet/wallet.c:671 msgid "INSERT INTO shachains (min_index, num_valid) VALUES (?, 0);" msgstr "" -#: wallet/wallet.c:731 +#: wallet/wallet.c:715 msgid "UPDATE shachains SET num_valid=?, min_index=? WHERE id=?" msgstr "" -#: wallet/wallet.c:738 +#: wallet/wallet.c:722 msgid "UPDATE shachain_known SET idx=?, hash=? WHERE shachain_id=? AND pos=?" msgstr "" -#: wallet/wallet.c:750 +#: wallet/wallet.c:734 msgid "INSERT INTO shachain_known (shachain_id, pos, idx, hash) VALUES (?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:772 +#: wallet/wallet.c:756 msgid "SELECT min_index, num_valid FROM shachains WHERE id=?" msgstr "" -#: wallet/wallet.c:787 +#: wallet/wallet.c:771 msgid "SELECT idx, hash, pos FROM shachain_known WHERE shachain_id=?" msgstr "" -#: wallet/wallet.c:810 +#: wallet/wallet.c:794 msgid "SELECT id, node_id, address FROM peers WHERE id=?;" msgstr "" -#: wallet/wallet.c:841 +#: wallet/wallet.c:825 msgid "SELECT signature FROM htlc_sigs WHERE channelid = ?" msgstr "" -#: wallet/wallet.c:875 +#: wallet/wallet.c:859 msgid "SELECT remote_ann_node_sig, remote_ann_bitcoin_sig FROM channels WHERE id = ?" msgstr "" -#: wallet/wallet.c:919 +#: wallet/wallet.c:903 msgid "SELECT hstate, feerate_per_kw FROM channel_feerates WHERE channel_id = ?" msgstr "" -#: wallet/wallet.c:1124 +#: wallet/wallet.c:1108 msgid "SELECT id FROM channels ORDER BY id DESC LIMIT 1;" msgstr "" -#: wallet/wallet.c:1141 +#: wallet/wallet.c:1125 msgid "SELECT id, peer_id, short_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 FROM channels WHERE state < ?;" msgstr "" -#: wallet/wallet.c:1229 +#: wallet/wallet.c:1213 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:1234 +#: wallet/wallet.c:1218 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:1239 +#: wallet/wallet.c:1223 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:1244 +#: wallet/wallet.c:1228 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:1286 +#: wallet/wallet.c:1270 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:1315 +#: wallet/wallet.c:1299 msgid "SELECT MIN(height), MAX(height) FROM blocks;" msgstr "" -#: wallet/wallet.c:1337 +#: wallet/wallet.c:1321 msgid "INSERT INTO channel_configs DEFAULT VALUES;" msgstr "" -#: wallet/wallet.c:1349 +#: wallet/wallet.c:1333 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:1373 +#: wallet/wallet.c:1357 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:1407 +#: wallet/wallet.c:1391 msgid "UPDATE channels SET remote_ann_node_sig=?, remote_ann_bitcoin_sig=? WHERE id=?" msgstr "" -#: wallet/wallet.c:1426 +#: wallet/wallet.c:1410 msgid "UPDATE channels SET shachain_remote_id=?, short_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=? WHERE id=?" msgstr "" -#: wallet/wallet.c:1503 +#: wallet/wallet.c:1487 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:1530 +#: wallet/wallet.c:1514 msgid "DELETE FROM channel_feerates WHERE channel_id=?" msgstr "" -#: wallet/wallet.c:1540 +#: wallet/wallet.c:1524 msgid "INSERT INTO channel_feerates VALUES(?, ?, ?)" msgstr "" -#: wallet/wallet.c:1557 +#: wallet/wallet.c:1541 msgid "UPDATE channels SET last_sent_commit=? WHERE id=?" msgstr "" -#: wallet/wallet.c:1571 +#: wallet/wallet.c:1555 msgid "SELECT id FROM peers WHERE node_id = ?" msgstr "" -#: wallet/wallet.c:1583 +#: wallet/wallet.c:1567 msgid "UPDATE peers SET address = ? WHERE id = ?" msgstr "" -#: wallet/wallet.c:1592 +#: wallet/wallet.c:1576 msgid "INSERT INTO peers (node_id, address) VALUES (?, ?);" msgstr "" -#: wallet/wallet.c:1610 +#: wallet/wallet.c:1594 msgid "INSERT INTO channels (peer_id, first_blocknum, id) VALUES (?, ?, ?);" msgstr "" -#: wallet/wallet.c:1636 +#: wallet/wallet.c:1620 msgid "DELETE FROM channel_htlcs WHERE channel_id=?" msgstr "" -#: wallet/wallet.c:1642 +#: wallet/wallet.c:1626 msgid "DELETE FROM htlc_sigs WHERE channelid=?" msgstr "" -#: wallet/wallet.c:1648 +#: wallet/wallet.c:1632 msgid "DELETE FROM channeltxs WHERE channel_id=?" msgstr "" -#: wallet/wallet.c:1654 +#: wallet/wallet.c:1638 msgid "DELETE FROM shachains WHERE id IN ( SELECT shachain_remote_id FROM channels WHERE channels.id=?)" msgstr "" -#: wallet/wallet.c:1664 +#: wallet/wallet.c:1648 msgid "UPDATE channels SET state=?, peer_id=?WHERE channels.id=?" msgstr "" -#: wallet/wallet.c:1678 +#: wallet/wallet.c:1662 msgid "SELECT * FROM channels WHERE peer_id = ?;" msgstr "" -#: wallet/wallet.c:1686 +#: wallet/wallet.c:1670 msgid "DELETE FROM peers WHERE id=?" msgstr "" -#: wallet/wallet.c:1697 +#: wallet/wallet.c:1681 msgid "UPDATE outputs SET confirmation_height = ? WHERE prev_out_tx = ?" msgstr "" -#: wallet/wallet.c:1800 +#: wallet/wallet.c:1784 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:1853 +#: wallet/wallet.c:1837 msgid "INSERT INTO channel_htlcs ( channel_id, channel_htlc_id, direction, origin_htlc, msatoshi, cltv_expiry, payment_hash, payment_key, hstate, routing_onion, partid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:1913 +#: wallet/wallet.c:1897 msgid "UPDATE channel_htlcs SET hstate=?, payment_key=?, malformed_onion=?, failuremsg=?, localfailmsg=?, we_filled=? WHERE id=?" msgstr "" -#: wallet/wallet.c:2129 +#: wallet/wallet.c:2113 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:2176 +#: wallet/wallet.c:2160 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:2306 +#: wallet/wallet.c:2290 msgid "SELECT channel_id, direction, cltv_expiry, channel_htlc_id, payment_hash FROM channel_htlcs WHERE channel_id = ?;" msgstr "" -#: wallet/wallet.c:2340 +#: wallet/wallet.c:2324 msgid "DELETE FROM channel_htlcs WHERE direction = ? AND origin_htlc = ? AND payment_hash = ? AND partid = ?;" msgstr "" -#: wallet/wallet.c:2393 +#: wallet/wallet.c:2377 msgid "SELECT status FROM payments WHERE payment_hash=? AND partid = ?;" msgstr "" -#: wallet/wallet.c:2411 +#: wallet/wallet.c:2395 msgid "INSERT INTO payments ( status, payment_hash, destination, msatoshi, timestamp, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, total_msat, partid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:2494 +#: wallet/wallet.c:2478 msgid "DELETE FROM payments WHERE payment_hash = ? AND partid = ?" msgstr "" -#: wallet/wallet.c:2592 +#: wallet/wallet.c:2576 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 FROM payments WHERE payment_hash = ? AND partid = ?" msgstr "" -#: wallet/wallet.c:2641 +#: wallet/wallet.c:2625 msgid "UPDATE payments SET status=? WHERE payment_hash=? AND partid=?" msgstr "" -#: wallet/wallet.c:2651 +#: wallet/wallet.c:2635 msgid "UPDATE payments SET payment_preimage=? WHERE payment_hash=? AND partid=?" msgstr "" -#: wallet/wallet.c:2661 +#: wallet/wallet.c:2645 msgid "UPDATE payments SET path_secrets = NULL , route_nodes = NULL , route_channels = NULL WHERE payment_hash = ? AND partid = ?;" msgstr "" -#: wallet/wallet.c:2693 +#: wallet/wallet.c:2677 msgid "SELECT failonionreply, faildestperm, failindex, failcode, failnode, failchannel, failupdate, faildetail, faildirection FROM payments WHERE payment_hash=? AND partid=?;" msgstr "" -#: wallet/wallet.c:2760 +#: wallet/wallet.c:2744 msgid "UPDATE payments SET failonionreply=? , faildestperm=? , failindex=? , failcode=? , failnode=? , failchannel=? , failupdate=? , faildetail=? , faildirection=? WHERE payment_hash=? AND partid=?;" msgstr "" -#: wallet/wallet.c:2819 +#: wallet/wallet.c:2803 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 FROM payments WHERE payment_hash = ?;" msgstr "" -#: wallet/wallet.c:2840 +#: wallet/wallet.c:2824 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 FROM payments ORDER BY id;" msgstr "" -#: wallet/wallet.c:2884 +#: wallet/wallet.c:2868 msgid "DELETE FROM htlc_sigs WHERE channelid = ?" msgstr "" -#: wallet/wallet.c:2891 +#: wallet/wallet.c:2875 msgid "INSERT INTO htlc_sigs (channelid, signature) VALUES (?, ?)" msgstr "" -#: wallet/wallet.c:2903 +#: wallet/wallet.c:2887 msgid "SELECT blobval FROM vars WHERE name='genesis_hash'" msgstr "" -#: wallet/wallet.c:2927 +#: wallet/wallet.c:2911 msgid "INSERT INTO vars (name, blobval) VALUES ('genesis_hash', ?);" msgstr "" -#: wallet/wallet.c:2945 -msgid "SELECT txid, outnum FROM utxoset WHERE spendheight < ?" -msgstr "" - -#: wallet/wallet.c:2957 +#: wallet/wallet.c:2927 msgid "DELETE FROM utxoset WHERE spendheight < ?" msgstr "" -#: wallet/wallet.c:2965 wallet/wallet.c:3079 +#: wallet/wallet.c:2935 wallet/wallet.c:3045 msgid "INSERT INTO blocks (height, hash, prev_hash) VALUES (?, ?, ?);" msgstr "" -#: wallet/wallet.c:2984 +#: wallet/wallet.c:2954 msgid "DELETE FROM blocks WHERE hash = ?" msgstr "" -#: wallet/wallet.c:2990 +#: wallet/wallet.c:2960 msgid "SELECT * FROM blocks WHERE height >= ?;" msgstr "" -#: wallet/wallet.c:2999 +#: wallet/wallet.c:2969 msgid "DELETE FROM blocks WHERE height > ?" msgstr "" -#: wallet/wallet.c:3011 +#: wallet/wallet.c:2981 msgid "UPDATE outputs SET spend_height = ?, status = ? WHERE prev_out_tx = ? AND prev_out_index = ?" msgstr "" -#: wallet/wallet.c:3029 +#: wallet/wallet.c:2998 msgid "UPDATE utxoset SET spendheight = ? WHERE txid = ? AND outnum = ?" msgstr "" -#: wallet/wallet.c:3052 wallet/wallet.c:3090 +#: wallet/wallet.c:3020 wallet/wallet.c:3056 msgid "INSERT INTO utxoset ( txid, outnum, blockheight, spendheight, txindex, scriptpubkey, satoshis) VALUES(?, ?, ?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:3116 +#: wallet/wallet.c:3080 msgid "SELECT height FROM blocks WHERE height = ?" msgstr "" -#: wallet/wallet.c:3129 +#: wallet/wallet.c:3093 msgid "SELECT txid, spendheight, scriptpubkey, satoshis FROM utxoset WHERE blockheight = ? AND txindex = ? AND outnum = ? AND spendheight IS NULL" msgstr "" -#: wallet/wallet.c:3171 +#: wallet/wallet.c:3135 msgid "SELECT blockheight, txindex, outnum FROM utxoset WHERE spendheight = ?" msgstr "" -#: wallet/wallet.c:3202 wallet/wallet.c:3362 +#: wallet/wallet.c:3166 wallet/wallet.c:3326 msgid "SELECT blockheight FROM transactions WHERE id=?" msgstr "" -#: wallet/wallet.c:3212 +#: wallet/wallet.c:3176 msgid "INSERT INTO transactions ( id, blockheight, txindex, rawtx) VALUES (?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:3233 +#: wallet/wallet.c:3197 msgid "UPDATE transactions SET blockheight = ?, txindex = ? WHERE id = ?" msgstr "" -#: wallet/wallet.c:3250 +#: wallet/wallet.c:3214 msgid "INSERT INTO transaction_annotations (txid, idx, location, type, channel) VALUES (?, ?, ?, ?, ?) ON CONFLICT(txid,idx) DO NOTHING;" msgstr "" -#: wallet/wallet.c:3282 +#: wallet/wallet.c:3246 msgid "SELECT type, channel_id FROM transactions WHERE id=?" msgstr "" -#: wallet/wallet.c:3298 +#: wallet/wallet.c:3262 msgid "UPDATE transactions SET type = ?, channel_id = ? WHERE id = ?" msgstr "" -#: wallet/wallet.c:3317 +#: wallet/wallet.c:3281 msgid "SELECT type FROM transactions WHERE id=?" msgstr "" -#: wallet/wallet.c:3340 +#: wallet/wallet.c:3304 msgid "SELECT rawtx FROM transactions WHERE id=?" msgstr "" -#: wallet/wallet.c:3386 +#: wallet/wallet.c:3350 msgid "SELECT blockheight, txindex FROM transactions WHERE id=?" msgstr "" -#: wallet/wallet.c:3414 +#: wallet/wallet.c:3378 msgid "SELECT id FROM transactions WHERE blockheight=?" msgstr "" -#: wallet/wallet.c:3433 +#: wallet/wallet.c:3397 msgid "INSERT INTO channeltxs ( channel_id, type, transaction_id, input_num, blockheight) VALUES (?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:3457 +#: wallet/wallet.c:3421 msgid "SELECT DISTINCT(channel_id) FROM channeltxs WHERE type = ?;" msgstr "" -#: wallet/wallet.c:3478 +#: wallet/wallet.c:3442 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:3523 +#: wallet/wallet.c:3487 msgid "UPDATE forwarded_payments SET in_msatoshi=?, out_msatoshi=?, state=?, resolved_time=?, failcode=? WHERE in_htlc_id=?" msgstr "" -#: wallet/wallet.c:3581 +#: wallet/wallet.c:3545 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:3640 +#: wallet/wallet.c:3604 msgid "SELECT CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)FROM forwarded_payments WHERE state = ?;" msgstr "" -#: wallet/wallet.c:3664 +#: wallet/wallet.c:3628 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)" msgstr "" -#: wallet/wallet.c:3752 +#: wallet/wallet.c:3716 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:3846 +#: wallet/wallet.c:3810 msgid "INSERT INTO penalty_bases ( channel_id, commitnum, txid, outnum, amount) VALUES (?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:3871 +#: wallet/wallet.c:3835 msgid "SELECT commitnum, txid, outnum, amount FROM penalty_bases WHERE channel_id = ?" msgstr "" -#: wallet/wallet.c:3895 +#: wallet/wallet.c:3859 msgid "DELETE FROM penalty_bases WHERE channel_id = ? AND commitnum = ?" msgstr "" @@ -1081,4 +1073,4 @@ msgstr "" #: wallet/test/run-wallet.c:1345 msgid "INSERT INTO channels (id) VALUES (1);" msgstr "" -# SHA256STAMP:1276c6c01e98d0dda121978e23a54023515df27ebf4a751e1887e9d5255f6670 +# SHA256STAMP:b4d0dcb353e8a9301b48cfb2565c96a6e9a0e39acb64a3a54cc88f4485d09c0d diff --git a/wallet/wallet.c b/wallet/wallet.c index 0f9af3d3d..b0d72e830 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -33,29 +33,13 @@ static void outpointfilters_init(struct wallet *w) { - struct db_stmt *stmt; struct utxo **utxos = wallet_get_utxos(NULL, w, OUTPUT_STATE_ANY); - struct bitcoin_txid txid; - u32 outnum; w->owned_outpoints = outpointfilter_new(w); for (size_t i = 0; i < tal_count(utxos); i++) outpointfilter_add(w->owned_outpoints, &utxos[i]->txid, utxos[i]->outnum); tal_free(utxos); - - w->utxoset_outpoints = outpointfilter_new(w); - stmt = db_prepare_v2( - w->db, - SQL("SELECT txid, outnum FROM utxoset WHERE spendheight is NULL")); - db_query_prepared(stmt); - - while (db_step(stmt)) { - db_column_sha256d(stmt, 0, &txid.shad); - outnum = db_column_int(stmt, 1); - outpointfilter_add(w->utxoset_outpoints, &txid, outnum); - } - tal_free(stmt); } struct wallet *wallet_new(struct lightningd *ld, struct timers *timers, @@ -2938,20 +2922,6 @@ bool wallet_network_check(struct wallet *w) static void wallet_utxoset_prune(struct wallet *w, const u32 blockheight) { struct db_stmt *stmt; - struct bitcoin_txid txid; - - stmt = db_prepare_v2( - w->db, - SQL("SELECT txid, outnum FROM utxoset WHERE spendheight < ?")); - db_bind_int(stmt, 0, blockheight - UTXO_PRUNE_DEPTH); - db_query_prepared(stmt); - - while (db_step(stmt)) { - db_column_sha256d(stmt, 0, &txid.shad); - outpointfilter_remove(w->utxoset_outpoints, &txid, - db_column_int(stmt, 1)); - } - tal_free(stmt); stmt = db_prepare_v2(w->db, SQL("DELETE FROM utxoset WHERE spendheight < ?")); @@ -3025,18 +2995,16 @@ bool wallet_outpoint_spend(struct wallet *w, const tal_t *ctx, const u32 blockhe } else our_spend = false; - if (outpointfilter_matches(w->utxoset_outpoints, txid, outnum)) { - stmt = db_prepare_v2(w->db, SQL("UPDATE utxoset " - "SET spendheight = ? " - "WHERE txid = ?" - " AND outnum = ?")); + stmt = db_prepare_v2(w->db, SQL("UPDATE utxoset " + "SET spendheight = ? " + "WHERE txid = ?" + " AND outnum = ?")); - db_bind_int(stmt, 0, blockheight); - db_bind_sha256d(stmt, 1, &txid->shad); - db_bind_int(stmt, 2, outnum); - db_exec_prepared_v2(stmt); - tal_free(stmt); - } + db_bind_int(stmt, 0, blockheight); + db_bind_sha256d(stmt, 1, &txid->shad); + db_bind_int(stmt, 2, outnum); + db_exec_prepared_v2(stmt); + tal_free(stmt); return our_spend; } @@ -3066,8 +3034,6 @@ void wallet_utxoset_add(struct wallet *w, const struct bitcoin_tx *tx, db_bind_talarr(stmt, 5, scriptpubkey); db_bind_amount_sat(stmt, 6, &sat); db_exec_prepared_v2(take(stmt)); - - outpointfilter_add(w->utxoset_outpoints, &txid, outnum); } void wallet_filteredblock_add(struct wallet *w, const struct filteredblock *fb) @@ -3104,8 +3070,6 @@ void wallet_filteredblock_add(struct wallet *w, const struct filteredblock *fb) db_bind_talarr(stmt, 5, o->scriptPubKey); db_bind_amount_sat(stmt, 6, &o->amount); db_exec_prepared_v2(take(stmt)); - - outpointfilter_add(w->utxoset_outpoints, &o->txid, o->outnum); } } diff --git a/wallet/wallet.h b/wallet/wallet.h index c97e13203..dc7f58cd1 100644 --- a/wallet/wallet.h +++ b/wallet/wallet.h @@ -44,10 +44,6 @@ struct wallet { * including all spent ones */ struct outpointfilter *owned_outpoints; - /* Filter matching all outpoints that might be a funding transaction on - * the blockchain. This is currently all P2WSH outputs */ - struct outpointfilter *utxoset_outpoints; - /* How many keys should we look ahead at most? */ u64 keyscan_gap; };