mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
onchaind: Store channeltxs so we can restore later
Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
parent
8e7ac53f5a
commit
244d4e49e1
@ -59,8 +59,10 @@ static void filter_block_txs(struct chain_topology *topo, struct block *b)
|
||||
out.index = tx->input[j].index;
|
||||
|
||||
txo = txowatch_hash_get(&topo->txowatches, &out);
|
||||
if (txo)
|
||||
if (txo) {
|
||||
wallet_transaction_add(topo->wallet, tx, b->height, i);
|
||||
txowatch_fire(txo, tx, j, b);
|
||||
}
|
||||
}
|
||||
|
||||
satoshi_owned = 0;
|
||||
|
@ -71,6 +71,7 @@ static enum watch_result onchain_tx_watched(struct channel *channel,
|
||||
const struct bitcoin_txid *txid,
|
||||
unsigned int depth)
|
||||
{
|
||||
u32 blockheight = channel->peer->ld->topology->tip->height;
|
||||
if (depth == 0) {
|
||||
log_unusual(channel->log, "Chain reorganization!");
|
||||
channel_set_owner(channel, NULL);
|
||||
@ -83,6 +84,10 @@ static enum watch_result onchain_tx_watched(struct channel *channel,
|
||||
return KEEP_WATCHING;
|
||||
}
|
||||
|
||||
/* Store the channeltx so we can replay later */
|
||||
wallet_channeltxs_add(channel->peer->ld->wallet, channel,
|
||||
WIRE_ONCHAIN_DEPTH, txid, 0, blockheight);
|
||||
|
||||
onchain_tx_depth(channel, txid, depth);
|
||||
return KEEP_WATCHING;
|
||||
}
|
||||
@ -112,6 +117,14 @@ static enum watch_result onchain_txo_watched(struct channel *channel,
|
||||
size_t input_num,
|
||||
const struct block *block)
|
||||
{
|
||||
struct bitcoin_txid txid;
|
||||
bitcoin_txid(tx, &txid);
|
||||
|
||||
/* Store the channeltx so we can replay later */
|
||||
wallet_channeltxs_add(channel->peer->ld->wallet, channel,
|
||||
WIRE_ONCHAIN_SPENT, &txid, input_num,
|
||||
block->height);
|
||||
|
||||
onchain_txo_spent(channel, tx, input_num, block->height);
|
||||
|
||||
/* We don't need to keep watching: If this output is double-spent
|
||||
|
Loading…
Reference in New Issue
Block a user