diff --git a/lightningd/onchain_control.c b/lightningd/onchain_control.c index edc2d369c..67fa22f6c 100644 --- a/lightningd/onchain_control.c +++ b/lightningd/onchain_control.c @@ -165,12 +165,19 @@ static void watch_tx_and_outputs(struct channel *channel, static void handle_onchain_broadcast_tx(struct channel *channel, const u8 *msg) { struct bitcoin_tx *tx; + struct wallet *w = channel->peer->ld->wallet; + struct bitcoin_txid txid; + txtypes type; - if (!fromwire_onchain_broadcast_tx(msg, msg, &tx)) { + if (!fromwire_onchain_broadcast_tx(msg, msg, &tx, &type)) { channel_internal_error(channel, "Invalid onchain_broadcast_tx"); return; } + bitcoin_txid(tx, &txid); + wallet_transaction_add(w, tx, 0, 0); + wallet_transaction_annotate(w, &txid, type, channel->dbid); + /* We don't really care if it fails, we'll respond via watch. */ broadcast_tx(channel->peer->ld->topology, channel, tx, NULL); } diff --git a/onchaind/onchain_wire.csv b/onchaind/onchain_wire.csv index cec4f03eb..88de07d8c 100644 --- a/onchaind/onchain_wire.csv +++ b/onchaind/onchain_wire.csv @@ -48,6 +48,7 @@ onchain_init_reply,5101 # onchaind->master: Send out a tx. onchain_broadcast_tx,5003 onchain_broadcast_tx,,tx,struct bitcoin_tx +onchain_broadcast_tx,,type,u16 # master->onchaind: Notifier that an output has been spent by input_num of tx. onchain_spent,5004 diff --git a/onchaind/onchaind.c b/onchaind/onchaind.c index 868e645fe..7cf61bbc9 100644 --- a/onchaind/onchaind.c +++ b/onchaind/onchaind.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -457,6 +458,41 @@ static void ignore_output(struct tracked_output *out) out->resolved->tx_type = SELF; } +static txtypes onchain_txtype_to_wallet_txtype(enum tx_type t) +{ + switch (t) { + case FUNDING_TRANSACTION: + return TX_CHANNEL_FUNDING; + case MUTUAL_CLOSE: + return TX_CHANNEL_CLOSE; + case OUR_UNILATERAL: + return TX_CHANNEL_UNILATERAL; + case THEIR_HTLC_FULFILL_TO_US: + case OUR_HTLC_SUCCESS_TX: + return TX_CHANNEL_HTLC_SUCCESS; + case OUR_HTLC_TIMEOUT_TO_US: + case OUR_HTLC_TIMEOUT_TX: + return TX_CHANNEL_HTLC_TIMEOUT; + case OUR_DELAYED_RETURN_TO_WALLET: + case SELF: + return TX_CHANNEL_SWEEP; + case OUR_PENALTY_TX: + return TX_CHANNEL_PENALTY; + case THEIR_UNILATERAL: + case UNKNOWN_UNILATERAL: + case THEIR_REVOKED_UNILATERAL: + return TX_CHANNEL_UNILATERAL | TX_THEIRS; + case THEIR_HTLC_TIMEOUT_TO_THEM: + return TX_CHANNEL_HTLC_TIMEOUT | TX_THEIRS; + case OUR_HTLC_FULFILL_TO_THEM: + return TX_CHANNEL_HTLC_SUCCESS | TX_THEIRS; + case IGNORING_TINY_PAYMENT: + case UNKNOWN_TXTYPE: + return TX_UNKNOWN; + } + abort(); +} + static void proposal_meets_depth(struct tracked_output *out) { /* If we simply wanted to ignore it after some depth */ @@ -471,9 +507,11 @@ static void proposal_meets_depth(struct tracked_output *out) tx_type_name(out->tx_type), output_type_name(out->output_type)); - wire_sync_write(REQ_FD, - take(towire_onchain_broadcast_tx(NULL, - out->proposal->tx))); + wire_sync_write( + REQ_FD, + take(towire_onchain_broadcast_tx( + NULL, out->proposal->tx, + onchain_txtype_to_wallet_txtype(out->proposal->tx_type)))); /* Don't wait for this if we're ignoring the tiny payment. */ if (out->proposal->tx_type == IGNORING_TINY_PAYMENT) { diff --git a/onchaind/test/run-grind_feerate.c b/onchaind/test/run-grind_feerate.c index dd6d0b922..416d5ad12 100644 --- a/onchaind/test/run-grind_feerate.c +++ b/onchaind/test/run-grind_feerate.c @@ -130,7 +130,7 @@ u8 *towire_onchain_add_utxo(const tal_t *ctx UNNEEDED, const struct bitcoin_txid u8 *towire_onchain_all_irrevocably_resolved(const tal_t *ctx UNNEEDED) { fprintf(stderr, "towire_onchain_all_irrevocably_resolved called!\n"); abort(); } /* Generated stub for towire_onchain_broadcast_tx */ -u8 *towire_onchain_broadcast_tx(const tal_t *ctx UNNEEDED, const struct bitcoin_tx *tx UNNEEDED) +u8 *towire_onchain_broadcast_tx(const tal_t *ctx UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, u16 type UNNEEDED) { fprintf(stderr, "towire_onchain_broadcast_tx called!\n"); abort(); } /* Generated stub for towire_onchain_dev_memleak_reply */ u8 *towire_onchain_dev_memleak_reply(const tal_t *ctx UNNEEDED, bool leak UNNEEDED)