From 244d4e49e1a1f0dae34a00082faaa8de3733b845 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Tue, 17 Apr 2018 15:20:27 +0200 Subject: [PATCH] onchaind: Store channeltxs so we can restore later Signed-off-by: Christian Decker --- lightningd/chaintopology.c | 4 +++- lightningd/onchain_control.c | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lightningd/chaintopology.c b/lightningd/chaintopology.c index 7f08da950..610f16422 100644 --- a/lightningd/chaintopology.c +++ b/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; 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; diff --git a/lightningd/onchain_control.c b/lightningd/onchain_control.c index 16ca5527b..40b383cec 100644 --- a/lightningd/onchain_control.c +++ b/lightningd/onchain_control.c @@ -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