mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-21 22:31:48 +01:00
wallet: remove edgecase around transaction checks
we don't populate the tx item when we're running a transaction check from deep chain (prior to a chain replay)
This commit is contained in:
parent
b2c4d5e952
commit
700b766ce1
4 changed files with 38 additions and 2 deletions
|
@ -990,7 +990,7 @@ static enum watch_result funding_depth_cb(struct lightningd *ld,
|
|||
struct short_channel_id scid;
|
||||
|
||||
/* Sanity check */
|
||||
if (tx && !check_funding_tx(tx, channel)) {
|
||||
if (!check_funding_tx(tx, channel)) {
|
||||
channel_internal_error(channel, "Bad tx %s: %s",
|
||||
type_to_string(tmpctx,
|
||||
struct bitcoin_txid, txid),
|
||||
|
|
|
@ -300,8 +300,12 @@ void watch_topology_changed(struct chain_topology *topo)
|
|||
u32 depth;
|
||||
|
||||
depth = get_tx_depth(topo, &w->txid);
|
||||
if (depth)
|
||||
if (depth) {
|
||||
if (!w->tx)
|
||||
w->tx = wallet_transaction_get(w, topo->ld->wallet,
|
||||
&w->txid);
|
||||
needs_rerun |= txw_fire(w, &w->txid, depth);
|
||||
}
|
||||
}
|
||||
} while (needs_rerun);
|
||||
}
|
||||
|
|
|
@ -3127,6 +3127,29 @@ bool wallet_transaction_type(struct wallet *w, const struct bitcoin_txid *txid,
|
|||
return true;
|
||||
}
|
||||
|
||||
struct bitcoin_tx *wallet_transaction_get(const tal_t *ctx, struct wallet *w,
|
||||
const struct bitcoin_txid *txid)
|
||||
{
|
||||
struct bitcoin_tx *tx;
|
||||
struct db_stmt *stmt = db_prepare_v2(
|
||||
w->db, SQL("SELECT rawtx FROM transactions WHERE id=?"));
|
||||
db_bind_txid(stmt, 0, txid);
|
||||
db_query_prepared(stmt);
|
||||
|
||||
if (!db_step(stmt)) {
|
||||
tal_free(stmt);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!db_column_is_null(stmt, 0))
|
||||
tx = db_column_tx(ctx, stmt, 0);
|
||||
else
|
||||
tx = NULL;
|
||||
|
||||
tal_free(stmt);
|
||||
return tx;
|
||||
}
|
||||
|
||||
u32 wallet_transaction_height(struct wallet *w, const struct bitcoin_txid *txid)
|
||||
{
|
||||
u32 blockheight;
|
||||
|
|
|
@ -1121,6 +1121,15 @@ void wallet_transaction_annotate(struct wallet *w,
|
|||
bool wallet_transaction_type(struct wallet *w, const struct bitcoin_txid *txid,
|
||||
enum wallet_tx_type *type);
|
||||
|
||||
/**
|
||||
* Get the transaction from the database
|
||||
*
|
||||
* Looks up a transaction we have in the database and returns it, or NULL if
|
||||
* not found.
|
||||
*/
|
||||
struct bitcoin_tx *wallet_transaction_get(const tal_t *ctx, struct wallet *w,
|
||||
const struct bitcoin_txid *txid);
|
||||
|
||||
/**
|
||||
* Get the confirmation height of a transaction we are watching by its
|
||||
* txid. Returns 0 if the transaction was not part of any block.
|
||||
|
|
Loading…
Add table
Reference in a new issue