Browse Source

migrations: ignore channels that don't have a peer_id

We erase peer data after the last channel close transaction for that
peer is 100 blocks deep. We were failing to finish the migration because
the peer_id lookup on these was failing.

Now we ignore any channel with a null peer_id.

Fixes #3768
nifty/pset-pre
niftynei 5 years ago
committed by Christian Decker
parent
commit
2900da6112
  1. BIN
      tests/data/last_tx_closed.sqlite3.xz
  2. 14
      tests/test_db.py
  3. 5
      wallet/db.c

BIN
tests/data/last_tx_closed.sqlite3.xz

Binary file not shown.

14
tests/test_db.py

@ -165,6 +165,20 @@ def test_last_tx_psbt_upgrade(node_factory, bitcoind):
assert funding_input['witness_utxo']['scriptPubKey']['type'] == 'witness_v0_scripthash' assert funding_input['witness_utxo']['scriptPubKey']['type'] == 'witness_v0_scripthash'
assert funding_input['witness_script']['type'] == 'multisig' assert funding_input['witness_script']['type'] == 'multisig'
l1.stop()
# Test again, but this time with a database with a closed channel + forgotten peer
# We need to get to block #232 from block #113
bitcoind.generate_block(232 - 113)
# We need to give it a chance to update
time.sleep(2)
l2 = node_factory.get_node(dbfile='last_tx_closed.sqlite3.xz')
last_txs = [x['last_tx'] for x in l2.db_query('SELECT last_tx FROM channels ORDER BY id;')]
# The first tx should be psbt, the second should still be hex
bitcoind.rpc.decodepsbt(base64.b64encode(last_txs[0]).decode('utf-8'))
bitcoind.rpc.decoderawtransaction(last_txs[1].hex())
@unittest.skipIf(VALGRIND and not DEVELOPER, "Without developer valgrind will complain about debug symbols missing") @unittest.skipIf(VALGRIND and not DEVELOPER, "Without developer valgrind will complain about debug symbols missing")
def test_optimistic_locking(node_factory, bitcoind): def test_optimistic_locking(node_factory, bitcoind):

5
wallet/db.c

@ -1150,6 +1150,11 @@ void migrate_last_tx_to_psbt(struct lightningd *ld, struct db *db)
last_tx = db_column_tx(stmt, stmt, 2); last_tx = db_column_tx(stmt, stmt, 2);
assert(last_tx != NULL); assert(last_tx != NULL);
/* If we've forgotten about the peer_id
* because we closed / forgot the channel,
* we can skip this. */
if (db_column_is_null(stmt, 1))
continue;
db_column_node_id(stmt, 1, &peer_id); db_column_node_id(stmt, 1, &peer_id);
db_column_amount_sat(stmt, 3, &funding_sat); db_column_amount_sat(stmt, 3, &funding_sat);
db_column_pubkey(stmt, 4, &remote_funding_pubkey); db_column_pubkey(stmt, 4, &remote_funding_pubkey);

Loading…
Cancel
Save