Browse Source

onchaind: Store channeltxs so we can restore later

Signed-off-by: Christian Decker <decker.christian@gmail.com>
ppa-0.6.1
Christian Decker 7 years ago
parent
commit
244d4e49e1
  1. 4
      lightningd/chaintopology.c
  2. 13
      lightningd/onchain_control.c

4
lightningd/chaintopology.c

@ -59,8 +59,10 @@ static void filter_block_txs(struct chain_topology *topo, struct block *b)
out.index = tx->input[j].index; out.index = tx->input[j].index;
txo = txowatch_hash_get(&topo->txowatches, &out); 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); txowatch_fire(txo, tx, j, b);
}
} }
satoshi_owned = 0; satoshi_owned = 0;

13
lightningd/onchain_control.c

@ -71,6 +71,7 @@ static enum watch_result onchain_tx_watched(struct channel *channel,
const struct bitcoin_txid *txid, const struct bitcoin_txid *txid,
unsigned int depth) unsigned int depth)
{ {
u32 blockheight = channel->peer->ld->topology->tip->height;
if (depth == 0) { if (depth == 0) {
log_unusual(channel->log, "Chain reorganization!"); log_unusual(channel->log, "Chain reorganization!");
channel_set_owner(channel, NULL); channel_set_owner(channel, NULL);
@ -83,6 +84,10 @@ static enum watch_result onchain_tx_watched(struct channel *channel,
return KEEP_WATCHING; 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); onchain_tx_depth(channel, txid, depth);
return KEEP_WATCHING; return KEEP_WATCHING;
} }
@ -112,6 +117,14 @@ static enum watch_result onchain_txo_watched(struct channel *channel,
size_t input_num, size_t input_num,
const struct block *block) 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); onchain_txo_spent(channel, tx, input_num, block->height);
/* We don't need to keep watching: If this output is double-spent /* We don't need to keep watching: If this output is double-spent

Loading…
Cancel
Save