Skip to content

Commit

Permalink
migrations: ignore channels that don't have a peer_id
Browse files Browse the repository at this point in the history
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
  • Loading branch information
niftynei authored and cdecker committed Jun 17, 2020
1 parent 02338a6 commit 2900da6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
Binary file added tests/data/last_tx_closed.sqlite3.xz
Binary file not shown.
14 changes: 14 additions & 0 deletions tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_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")
def test_optimistic_locking(node_factory, bitcoind):
Expand Down
5 changes: 5 additions & 0 deletions wallet/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,11 @@ void migrate_last_tx_to_psbt(struct lightningd *ld, struct db *db)
last_tx = db_column_tx(stmt, stmt, 2);
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_amount_sat(stmt, 3, &funding_sat);
db_column_pubkey(stmt, 4, &remote_funding_pubkey);
Expand Down

0 comments on commit 2900da6

Please sign in to comment.