From 05dbf1a2a9eadd6c8ee8146e33080164b115c4e3 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Fri, 24 May 2019 12:27:40 +0200 Subject: [PATCH] onchaind: Store and annotate close transaction when we drop to chain Signed-off-by: Christian Decker --- lightningd/onchain_control.c | 3 ++- lightningd/peer_control.c | 5 ++++- lightningd/test/run-invoice-select-inchan.c | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lightningd/onchain_control.c b/lightningd/onchain_control.c index b90952bbb..edc2d369c 100644 --- a/lightningd/onchain_control.c +++ b/lightningd/onchain_control.c @@ -394,7 +394,7 @@ enum watch_result onchaind_funding_spent(struct channel *channel, u32 blockheight) { u8 *msg; - struct bitcoin_txid our_last_txid; + struct bitcoin_txid our_last_txid, txid; struct htlc_stub *stubs; struct lightningd *ld = channel->peer->ld; struct pubkey final_key; @@ -442,6 +442,7 @@ enum watch_result onchaind_funding_spent(struct channel *channel, return KEEP_WATCHING; } /* This could be a mutual close, but it doesn't matter. */ + bitcoin_txid(tx, &txid); bitcoin_txid(channel->last_tx, &our_last_txid); /* We try to use normal feerate for onchaind spends. */ diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index a62c57d3b..5184534d5 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -344,6 +344,7 @@ register_close_command(struct lightningd *ld, void drop_to_chain(struct lightningd *ld, struct channel *channel, bool cooperative) { + struct bitcoin_txid txid; /* BOLT #2: * * - if `next_remote_revocation_number` is greater than expected @@ -357,6 +358,9 @@ void drop_to_chain(struct lightningd *ld, struct channel *channel, " they have a future one"); } else { sign_last_tx(channel); + bitcoin_txid(channel->last_tx, &txid); + wallet_transaction_add(ld->wallet, channel->last_tx, 0, 0); + wallet_transaction_annotate(ld->wallet, &txid, channel->last_tx_type, channel->dbid); /* Keep broadcasting until we say stop (can fail due to dup, * if they beat us to the broadcast). */ @@ -916,7 +920,6 @@ static enum watch_result funding_spent(struct channel *channel, wallet_channeltxs_add(channel->peer->ld->wallet, channel, WIRE_ONCHAIN_INIT, &txid, 0, block->height); - return onchaind_funding_spent(channel, tx, block->height); } diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index 402a7d634..25b294e00 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -557,6 +557,10 @@ void wallet_peer_delete(struct wallet *w UNNEEDED, u64 peer_dbid UNNEEDED) /* Generated stub for wallet_total_forward_fees */ struct amount_msat wallet_total_forward_fees(struct wallet *w UNNEEDED) { fprintf(stderr, "wallet_total_forward_fees called!\n"); abort(); } +/* Generated stub for wallet_transaction_add */ +void wallet_transaction_add(struct wallet *w UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, + const u32 blockheight UNNEEDED, const u32 txindex UNNEEDED) +{ fprintf(stderr, "wallet_transaction_add called!\n"); abort(); } /* Generated stub for wallet_transaction_annotate */ void wallet_transaction_annotate(struct wallet *w UNNEEDED, const struct bitcoin_txid *txid UNNEEDED, txtypes type UNNEEDED,