mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-21 14:24:09 +01:00
wallet: Add migration to cache local basepoints from the HSMd
This commit is contained in:
parent
bfa5db79b3
commit
2f6e33a7cd
7 changed files with 154 additions and 1060 deletions
BIN
tests/data/no-local-basepoints.sqlite3.xz
Normal file
BIN
tests/data/no-local-basepoints.sqlite3.xz
Normal file
Binary file not shown.
|
@ -298,3 +298,51 @@ def test_psql_key_value_dsn(node_factory, db_provider, monkeypatch):
|
|||
l1 = node_factory.get_node()
|
||||
opt = [o for o in l1.daemon.cmd_line if '--wallet' in o][0]
|
||||
assert('host=127.0.0.1' in opt)
|
||||
|
||||
|
||||
@unittest.skipIf(
|
||||
TEST_NETWORK != 'regtest',
|
||||
"The DB migration is network specific due to the chain var."
|
||||
)
|
||||
@unittest.skipIf(
|
||||
os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3',
|
||||
"This test is based on a sqlite3 snapshot"
|
||||
)
|
||||
def test_local_basepoints_cache(bitcoind, node_factory):
|
||||
"""XXX started caching the local basepoints as well as the remote ones.
|
||||
|
||||
This tests that we can successfully migrate a DB from the
|
||||
pre-caching state to the caching state, by simply starting the
|
||||
node up once, issue the HSMd requests, and then store them in the
|
||||
DB.
|
||||
|
||||
"""
|
||||
# Reestablish the blockheight we had when generating the DB
|
||||
bitcoind.generate_block(6)
|
||||
l1 = node_factory.get_node(
|
||||
dbfile='no-local-basepoints.sqlite3.xz',
|
||||
start=False
|
||||
)
|
||||
|
||||
fields = [
|
||||
"revocation_basepoint_local",
|
||||
"payment_basepoint_local",
|
||||
"htlc_basepoint_local",
|
||||
"delayed_payment_basepoint_local",
|
||||
]
|
||||
q = "SELECT {fields} FROM channels".format(fields=", ".join(fields))
|
||||
|
||||
# Make sure the DB doesn't have the fields yet.
|
||||
missing = l1.db.query("SELECT * FROM channels")[0]
|
||||
for f in fields:
|
||||
assert(f not in missing)
|
||||
|
||||
# Starting this should cause us to migrate the DB, but none of
|
||||
# these fields will be set.
|
||||
l1.start()
|
||||
|
||||
present = l1.db.query(q)[0]
|
||||
for f in fields:
|
||||
assert(f in present)
|
||||
assert(present[f] is None)
|
||||
|
||||
|
|
|
@ -690,6 +690,11 @@ static struct migration dbmigrations[] = {
|
|||
", PRIMARY KEY (channel_id, funding_tx_id)"
|
||||
");"),
|
||||
NULL},
|
||||
{SQL("ALTER TABLE channels ADD revocation_basepoint_local BLOB"), NULL},
|
||||
{SQL("ALTER TABLE channels ADD payment_basepoint_local BLOB"), NULL},
|
||||
{SQL("ALTER TABLE channels ADD htlc_basepoint_local BLOB"), NULL},
|
||||
{SQL("ALTER TABLE channels ADD delayed_payment_basepoint_local BLOB"), NULL},
|
||||
{SQL("ALTER TABLE channels ADD funding_pubkey_local BLOB"), NULL},
|
||||
};
|
||||
|
||||
/* Leak tracking. */
|
||||
|
|
34
wallet/db_postgres_sqlgen.c
generated
34
wallet/db_postgres_sqlgen.c
generated
|
@ -896,6 +896,36 @@ struct db_query db_postgres_queries[] = {
|
|||
.placeholders = 0,
|
||||
.readonly = false,
|
||||
},
|
||||
{
|
||||
.name = "ALTER TABLE channels ADD revocation_basepoint_local BLOB",
|
||||
.query = "ALTER TABLE channels ADD revocation_basepoint_local BYTEA",
|
||||
.placeholders = 0,
|
||||
.readonly = false,
|
||||
},
|
||||
{
|
||||
.name = "ALTER TABLE channels ADD payment_basepoint_local BLOB",
|
||||
.query = "ALTER TABLE channels ADD payment_basepoint_local BYTEA",
|
||||
.placeholders = 0,
|
||||
.readonly = false,
|
||||
},
|
||||
{
|
||||
.name = "ALTER TABLE channels ADD htlc_basepoint_local BLOB",
|
||||
.query = "ALTER TABLE channels ADD htlc_basepoint_local BYTEA",
|
||||
.placeholders = 0,
|
||||
.readonly = false,
|
||||
},
|
||||
{
|
||||
.name = "ALTER TABLE channels ADD delayed_payment_basepoint_local BLOB",
|
||||
.query = "ALTER TABLE channels ADD delayed_payment_basepoint_local BYTEA",
|
||||
.placeholders = 0,
|
||||
.readonly = false,
|
||||
},
|
||||
{
|
||||
.name = "ALTER TABLE channels ADD funding_pubkey_local BLOB",
|
||||
.query = "ALTER TABLE channels ADD funding_pubkey_local BYTEA",
|
||||
.placeholders = 0,
|
||||
.readonly = false,
|
||||
},
|
||||
{
|
||||
.name = "UPDATE vars SET intval = intval + 1 WHERE name = 'data_version' AND intval = ?",
|
||||
.query = "UPDATE vars SET intval = intval + 1 WHERE name = 'data_version' AND intval = $1",
|
||||
|
@ -1828,10 +1858,10 @@ struct db_query db_postgres_queries[] = {
|
|||
},
|
||||
};
|
||||
|
||||
#define DB_POSTGRES_QUERY_COUNT 303
|
||||
#define DB_POSTGRES_QUERY_COUNT 308
|
||||
|
||||
#endif /* HAVE_POSTGRES */
|
||||
|
||||
#endif /* LIGHTNINGD_WALLET_GEN_DB_POSTGRES */
|
||||
|
||||
// SHA256STAMP:984787ceecca007210a6b465695a1fc910b7f9899ac98cdf2eae35e417bc6cf2
|
||||
// SHA256STAMP:f821e078a09daf59ba061f0a2098510f136efa4b70fa046aa9b2f5de2f0160ed
|
||||
|
|
34
wallet/db_sqlite3_sqlgen.c
generated
34
wallet/db_sqlite3_sqlgen.c
generated
|
@ -896,6 +896,36 @@ struct db_query db_sqlite3_queries[] = {
|
|||
.placeholders = 0,
|
||||
.readonly = false,
|
||||
},
|
||||
{
|
||||
.name = "ALTER TABLE channels ADD revocation_basepoint_local BLOB",
|
||||
.query = "ALTER TABLE channels ADD revocation_basepoint_local BLOB",
|
||||
.placeholders = 0,
|
||||
.readonly = false,
|
||||
},
|
||||
{
|
||||
.name = "ALTER TABLE channels ADD payment_basepoint_local BLOB",
|
||||
.query = "ALTER TABLE channels ADD payment_basepoint_local BLOB",
|
||||
.placeholders = 0,
|
||||
.readonly = false,
|
||||
},
|
||||
{
|
||||
.name = "ALTER TABLE channels ADD htlc_basepoint_local BLOB",
|
||||
.query = "ALTER TABLE channels ADD htlc_basepoint_local BLOB",
|
||||
.placeholders = 0,
|
||||
.readonly = false,
|
||||
},
|
||||
{
|
||||
.name = "ALTER TABLE channels ADD delayed_payment_basepoint_local BLOB",
|
||||
.query = "ALTER TABLE channels ADD delayed_payment_basepoint_local BLOB",
|
||||
.placeholders = 0,
|
||||
.readonly = false,
|
||||
},
|
||||
{
|
||||
.name = "ALTER TABLE channels ADD funding_pubkey_local BLOB",
|
||||
.query = "ALTER TABLE channels ADD funding_pubkey_local BLOB",
|
||||
.placeholders = 0,
|
||||
.readonly = false,
|
||||
},
|
||||
{
|
||||
.name = "UPDATE vars SET intval = intval + 1 WHERE name = 'data_version' AND intval = ?",
|
||||
.query = "UPDATE vars SET intval = intval + 1 WHERE name = 'data_version' AND intval = ?",
|
||||
|
@ -1828,10 +1858,10 @@ struct db_query db_sqlite3_queries[] = {
|
|||
},
|
||||
};
|
||||
|
||||
#define DB_SQLITE3_QUERY_COUNT 303
|
||||
#define DB_SQLITE3_QUERY_COUNT 308
|
||||
|
||||
#endif /* HAVE_SQLITE3 */
|
||||
|
||||
#endif /* LIGHTNINGD_WALLET_GEN_DB_SQLITE3 */
|
||||
|
||||
// SHA256STAMP:984787ceecca007210a6b465695a1fc910b7f9899ac98cdf2eae35e417bc6cf2
|
||||
// SHA256STAMP:f821e078a09daf59ba061f0a2098510f136efa4b70fa046aa9b2f5de2f0160ed
|
||||
|
|
1039
wallet/statements.po
1039
wallet/statements.po
File diff suppressed because it is too large
Load diff
54
wallet/statements_gettextgen.po
generated
54
wallet/statements_gettextgen.po
generated
|
@ -590,67 +590,87 @@ msgstr ""
|
|||
msgid "CREATE TABLE channel_funding_inflights ( channel_id BIGSERIAL REFERENCES channels(id) ON DELETE CASCADE, funding_tx_id BLOB, funding_tx_outnum INTEGER, funding_feerate INTEGER, funding_satoshi BIGINT, our_funding_satoshi BIGINT, funding_psbt BLOB, last_tx BLOB, last_sig BLOB, funding_tx_remote_sigs_received INTEGER, PRIMARY KEY (channel_id, funding_tx_id));"
|
||||
msgstr ""
|
||||
|
||||
#: wallet/db.c:919
|
||||
#: wallet/db.c:693
|
||||
msgid "ALTER TABLE channels ADD revocation_basepoint_local BLOB"
|
||||
msgstr ""
|
||||
|
||||
#: wallet/db.c:694
|
||||
msgid "ALTER TABLE channels ADD payment_basepoint_local BLOB"
|
||||
msgstr ""
|
||||
|
||||
#: wallet/db.c:695
|
||||
msgid "ALTER TABLE channels ADD htlc_basepoint_local BLOB"
|
||||
msgstr ""
|
||||
|
||||
#: wallet/db.c:696
|
||||
msgid "ALTER TABLE channels ADD delayed_payment_basepoint_local BLOB"
|
||||
msgstr ""
|
||||
|
||||
#: wallet/db.c:697
|
||||
msgid "ALTER TABLE channels ADD funding_pubkey_local BLOB"
|
||||
msgstr ""
|
||||
|
||||
#: wallet/db.c:924
|
||||
msgid "UPDATE vars SET intval = intval + 1 WHERE name = 'data_version' AND intval = ?"
|
||||
msgstr ""
|
||||
|
||||
#: wallet/db.c:1019
|
||||
#: wallet/db.c:1024
|
||||
msgid "SELECT version FROM version LIMIT 1"
|
||||
msgstr ""
|
||||
|
||||
#: wallet/db.c:1077
|
||||
#: wallet/db.c:1082
|
||||
msgid "UPDATE version SET version=?;"
|
||||
msgstr ""
|
||||
|
||||
#: wallet/db.c:1085
|
||||
#: wallet/db.c:1090
|
||||
msgid "INSERT INTO db_upgrades VALUES (?, ?);"
|
||||
msgstr ""
|
||||
|
||||
#: wallet/db.c:1097
|
||||
#: wallet/db.c:1102
|
||||
msgid "SELECT intval FROM vars WHERE name = 'data_version'"
|
||||
msgstr ""
|
||||
|
||||
#: wallet/db.c:1124
|
||||
#: wallet/db.c:1129
|
||||
msgid "SELECT intval FROM vars WHERE name= ? LIMIT 1"
|
||||
msgstr ""
|
||||
|
||||
#: wallet/db.c:1140
|
||||
#: wallet/db.c:1145
|
||||
msgid "UPDATE vars SET intval=? WHERE name=?;"
|
||||
msgstr ""
|
||||
|
||||
#: wallet/db.c:1149
|
||||
#: wallet/db.c:1154
|
||||
msgid "INSERT INTO vars (name, intval) VALUES (?, ?);"
|
||||
msgstr ""
|
||||
|
||||
#: wallet/db.c:1163
|
||||
#: wallet/db.c:1168
|
||||
msgid "UPDATE channels SET feerate_base = ?, feerate_ppm = ?;"
|
||||
msgstr ""
|
||||
|
||||
#: wallet/db.c:1184
|
||||
#: wallet/db.c:1189
|
||||
msgid "UPDATE channels SET our_funding_satoshi = funding_satoshi WHERE funder = 0;"
|
||||
msgstr ""
|
||||
|
||||
#: wallet/db.c:1200
|
||||
#: wallet/db.c:1205
|
||||
msgid "SELECT type, keyindex, prev_out_tx, prev_out_index, channel_id, peer_id, commitment_point FROM outputs WHERE scriptpubkey IS NULL;"
|
||||
msgstr ""
|
||||
|
||||
#: wallet/db.c:1262
|
||||
#: wallet/db.c:1267
|
||||
msgid "UPDATE outputs SET scriptpubkey = ? WHERE prev_out_tx = ? AND prev_out_index = ?"
|
||||
msgstr ""
|
||||
|
||||
#: wallet/db.c:1287
|
||||
#: wallet/db.c:1292
|
||||
msgid "SELECT id, funding_tx_id, funding_tx_outnum FROM channels;"
|
||||
msgstr ""
|
||||
|
||||
#: wallet/db.c:1306
|
||||
#: wallet/db.c:1311
|
||||
msgid "UPDATE channels SET full_channel_id = ? WHERE id = ?;"
|
||||
msgstr ""
|
||||
|
||||
#: wallet/db.c:1329
|
||||
#: wallet/db.c:1334
|
||||
msgid "SELECT c.id, p.node_id, c.last_tx, c.funding_satoshi, c.fundingkey_remote, c.last_sig FROM channels c LEFT OUTER JOIN peers p ON p.id = c.peer_id;"
|
||||
msgstr ""
|
||||
|
||||
#: wallet/db.c:1396
|
||||
#: wallet/db.c:1401
|
||||
msgid "UPDATE channels SET last_tx = ? WHERE id = ?;"
|
||||
msgstr ""
|
||||
|
||||
|
@ -1209,4 +1229,4 @@ msgstr ""
|
|||
#: wallet/test/run-wallet.c:1616
|
||||
msgid "INSERT INTO channels (id) VALUES (1);"
|
||||
msgstr ""
|
||||
# SHA256STAMP:4fb460b69d30a052f367c585ebefaefb8e032d2a6bf591ec48ae3117ccbb2966
|
||||
# SHA256STAMP:1e757793031663e303889a7aa483262adf1078d9fc48ce6f0a7fef08cd4a12f7
|
||||
|
|
Loading…
Add table
Reference in a new issue