Browse Source

onchaind: Store and annotate transactions we broadcast ourselves

Signed-off-by: Christian Decker <decker.christian@gmail.com>
pull/2938/head
Christian Decker 6 years ago
committed by Rusty Russell
parent
commit
ae0bc4aed0
  1. 9
      lightningd/onchain_control.c
  2. 1
      onchaind/onchain_wire.csv
  3. 44
      onchaind/onchaind.c
  4. 2
      onchaind/test/run-grind_feerate.c

9
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) static void handle_onchain_broadcast_tx(struct channel *channel, const u8 *msg)
{ {
struct bitcoin_tx *tx; 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"); channel_internal_error(channel, "Invalid onchain_broadcast_tx");
return; 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. */ /* We don't really care if it fails, we'll respond via watch. */
broadcast_tx(channel->peer->ld->topology, channel, tx, NULL); broadcast_tx(channel->peer->ld->topology, channel, tx, NULL);
} }

1
onchaind/onchain_wire.csv

@ -48,6 +48,7 @@ onchain_init_reply,5101
# onchaind->master: Send out a tx. # onchaind->master: Send out a tx.
onchain_broadcast_tx,5003 onchain_broadcast_tx,5003
onchain_broadcast_tx,,tx,struct bitcoin_tx 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. # master->onchaind: Notifier that an output has been spent by input_num of tx.
onchain_spent,5004 onchain_spent,5004

Can't render this file because it has a wrong number of fields in line 4.

44
onchaind/onchaind.c

@ -15,6 +15,7 @@
#include <common/type_to_string.h> #include <common/type_to_string.h>
#include <common/utils.h> #include <common/utils.h>
#include <common/version.h> #include <common/version.h>
#include <common/wallet.h>
#include <errno.h> #include <errno.h>
#include <hsmd/gen_hsm_wire.h> #include <hsmd/gen_hsm_wire.h>
#include <inttypes.h> #include <inttypes.h>
@ -457,6 +458,41 @@ static void ignore_output(struct tracked_output *out)
out->resolved->tx_type = SELF; 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) static void proposal_meets_depth(struct tracked_output *out)
{ {
/* If we simply wanted to ignore it after some depth */ /* 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), tx_type_name(out->tx_type),
output_type_name(out->output_type)); output_type_name(out->output_type));
wire_sync_write(REQ_FD, wire_sync_write(
take(towire_onchain_broadcast_tx(NULL, REQ_FD,
out->proposal->tx))); 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. */ /* Don't wait for this if we're ignoring the tiny payment. */
if (out->proposal->tx_type == IGNORING_TINY_PAYMENT) { if (out->proposal->tx_type == IGNORING_TINY_PAYMENT) {

2
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) u8 *towire_onchain_all_irrevocably_resolved(const tal_t *ctx UNNEEDED)
{ fprintf(stderr, "towire_onchain_all_irrevocably_resolved called!\n"); abort(); } { fprintf(stderr, "towire_onchain_all_irrevocably_resolved called!\n"); abort(); }
/* Generated stub for towire_onchain_broadcast_tx */ /* 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(); } { fprintf(stderr, "towire_onchain_broadcast_tx called!\n"); abort(); }
/* Generated stub for towire_onchain_dev_memleak_reply */ /* Generated stub for towire_onchain_dev_memleak_reply */
u8 *towire_onchain_dev_memleak_reply(const tal_t *ctx UNNEEDED, bool leak UNNEEDED) u8 *towire_onchain_dev_memleak_reply(const tal_t *ctx UNNEEDED, bool leak UNNEEDED)

Loading…
Cancel
Save