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
This commit is contained in:
niftynei 2020-06-16 18:25:32 -05:00 committed by Christian Decker
parent 02338a6b25
commit 2900da6112
3 changed files with 19 additions and 0 deletions

Binary file not shown.

View File

@ -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):

View File

@ -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);