MCPcopy Create free account
hub / github.com/ElementsProject/lightning / wallet_begin_old_close_rescan

Function wallet_begin_old_close_rescan

wallet/wallet.c:7579–7686  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7577}
7578
7579void wallet_begin_old_close_rescan(struct lightningd *ld)
7580{
7581 struct db_stmt *stmt;
7582 u32 earliest_block = UINT32_MAX;
7583 struct missing *missing;
7584 int v = db_get_intvar(ld->wallet->db, "needs_p2wpkh_close_rescan", -1);
7585 if (v == 0)
7586 return;
7587 assert(v == 1);
7588
7589 /* Channels where we might have already seen a mutual close,
7590 * which said their key was only taproot, but we didn't see an
7591 * output, may actually have closed to the p2wpkh address.
7592 * Some debugging help with ChatGPT here!
7593 */
7594 stmt = db_prepare_v2(ld->wallet->db,
7595 SQL("SELECT "
7596 " full_channel_id"
7597 ", state"
7598 ", scid"
7599 ", shutdown_keyidx_local"
7600 " FROM channels"
7601 " JOIN addresses"
7602 " ON channels.shutdown_keyidx_local = addresses.keyidx"
7603 " WHERE addresses.addrtype = ?"
7604 " AND NOT EXISTS ("
7605 " SELECT 1"
7606 " FROM outputs"
7607 " WHERE outputs.keyindex = addresses.keyidx"
7608 ");"));
7609 db_bind_int(stmt, wallet_addrtype_in_db(ADDR_P2TR));
7610 db_query_prepared(stmt);
7611
7612 missing = tal(tmpctx, struct missing);
7613 missing->num_found = 0;
7614 missing->addrs = tal_arr(missing, struct missing_addr, 0);
7615 while (db_step(stmt)) {
7616 enum channel_state state;
7617 struct short_channel_id scid;
7618 struct channel_id cid;
7619 struct missing_addr maddr;
7620 struct ext_key ext;
7621
7622 state = channel_state_in_db(db_col_int(stmt, "state"));
7623 switch (state) {
7624 case DUALOPEND_OPEN_INIT:
7625 case CHANNELD_AWAITING_LOCKIN:
7626 case CHANNELD_NORMAL:
7627 case CHANNELD_SHUTTING_DOWN:
7628 case CLOSINGD_SIGEXCHANGE:
7629 case DUALOPEND_OPEN_COMMITTED:
7630 case DUALOPEND_AWAITING_LOCKIN:
7631 case CHANNELD_AWAITING_SPLICE:
7632 case DUALOPEND_OPEN_COMMIT_READY:
7633 db_col_ignore(stmt, "full_channel_id");
7634 db_col_ignore(stmt, "scid");
7635 db_col_ignore(stmt, "shutdown_keyidx_local");
7636 continue;

Callers

nothing calls this directly

Calls 15

db_bind_intFunction · 0.85
wallet_addrtype_in_dbFunction · 0.85
db_query_preparedFunction · 0.85
db_stepFunction · 0.85
channel_state_in_dbFunction · 0.85
db_col_intFunction · 0.85
db_col_ignoreFunction · 0.85
db_col_channel_idFunction · 0.85
db_col_u64Function · 0.85
db_col_is_nullFunction · 0.85
db_col_short_channel_idFunction · 0.85

Tested by

no test coverage detected