Browse Source

onchaind: Annotate inputs and outputs not the transactions

travis-debug
Christian Decker 5 years ago
committed by neil saitug
parent
commit
ff4a2bf38f
  1. 2
      bitcoin/tx.c
  2. 30
      lightningd/onchain_control.c
  3. 13
      onchaind/onchain_wire.csv
  4. 38
      onchaind/onchaind.c
  5. 9
      onchaind/test/run-grind_feerate-bug.c
  6. 9
      onchaind/test/run-grind_feerate.c

2
bitcoin/tx.c

@ -428,7 +428,7 @@ struct bitcoin_tx *pull_bitcoin_tx(const tal_t *ctx, const u8 **cursor,
/* We don't know the input amounts yet, so set them all to NULL */ /* We don't know the input amounts yet, so set them all to NULL */
tx->input_amounts = tx->input_amounts =
tal_arrz(tx, struct amount_sat *, tx->wtx->inputs_allocation_len); tal_arrz(tx, struct amount_sat *, tx->wtx->inputs_allocation_len);
tx->chainparams = NULL; tx->chainparams = chainparams;
*cursor += wsize; *cursor += wsize;
*max -= wsize; *max -= wsize;

30
lightningd/onchain_control.c

@ -306,15 +306,29 @@ static void onchain_add_utxo(struct channel *channel, const u8 *msg)
wallet_add_utxo(channel->peer->ld->wallet, u, p2wpkh); wallet_add_utxo(channel->peer->ld->wallet, u, p2wpkh);
} }
static void onchain_transaction_annotate(struct channel *channel, const u8 *msg) static void onchain_annotate_txout(struct channel *channel, const u8 *msg)
{ {
struct bitcoin_txid txid; struct bitcoin_txid txid;
enum wallet_tx_type type; enum wallet_tx_type type;
if (!fromwire_onchain_transaction_annotate(msg, &txid, &type)) u32 outnum;
fatal("onchaind gave invalid onchain_transaction_annotate " if (!fromwire_onchain_annotate_txout(msg, &txid, &outnum, &type))
fatal("onchaind gave invalid onchain_annotate_txout "
"message: %s", "message: %s",
tal_hex(msg, msg)); tal_hex(msg, msg));
wallet_transaction_annotate(channel->peer->ld->wallet, &txid, type, wallet_annotate_txout(channel->peer->ld->wallet, &txid, outnum, type,
channel->dbid);
}
static void onchain_annotate_txin(struct channel *channel, const u8 *msg)
{
struct bitcoin_txid txid;
enum wallet_tx_type type;
u32 innum;
if (!fromwire_onchain_annotate_txin(msg, &txid, &innum, &type))
fatal("onchaind gave invalid onchain_annotate_txin "
"message: %s",
tal_hex(msg, msg));
wallet_annotate_txin(channel->peer->ld->wallet, &txid, innum, type,
channel->dbid); channel->dbid);
} }
@ -355,8 +369,12 @@ static unsigned int onchain_msg(struct subd *sd, const u8 *msg, const int *fds U
onchain_add_utxo(sd->channel, msg); onchain_add_utxo(sd->channel, msg);
break; break;
case WIRE_ONCHAIN_TRANSACTION_ANNOTATE: case WIRE_ONCHAIN_ANNOTATE_TXIN:
onchain_transaction_annotate(sd->channel, msg); onchain_annotate_txin(sd->channel, msg);
break;
case WIRE_ONCHAIN_ANNOTATE_TXOUT:
onchain_annotate_txout(sd->channel, msg);
break; break;
/* We send these, not receive them */ /* We send these, not receive them */

13
onchaind/onchain_wire.csv

@ -108,6 +108,13 @@ msgdata,onchain_dev_memleak_reply,leak,bool,
# Tell the main daemon what we've been watching, mainly used for transactions # Tell the main daemon what we've been watching, mainly used for transactions
# that we tracked automatically but only onchaind knows how to classify their # that we tracked automatically but only onchaind knows how to classify their
# transactions. # transactions.
msgtype,onchain_transaction_annotate,5034 msgtype,onchain_annotate_txout,5035
msgdata,onchain_transaction_annotate,txid,bitcoin_txid, msgdata,onchain_annotate_txout,txid,bitcoin_txid,
msgdata,onchain_transaction_annotate,type,enum wallet_tx_type, msgdata,onchain_annotate_txout,outnum,u32,
msgdata,onchain_annotate_txout,type,enum wallet_tx_type,
msgtype,onchain_annotate_txin,5036
msgdata,onchain_annotate_txin,txid,bitcoin_txid,
msgdata,onchain_annotate_txin,innum,u32,
msgdata,onchain_annotate_txin,type,enum wallet_tx_type,

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

38
onchaind/onchaind.c

@ -1010,12 +1010,20 @@ static void steal_htlc_tx(struct tracked_output *out)
propose_resolution(out, tx, 0, tx_type); propose_resolution(out, tx, 0, tx_type);
} }
static void onchain_transaction_annotate(const struct bitcoin_txid *txid, static void onchain_annotate_txout(const struct bitcoin_txid *txid, u32 outnum,
enum wallet_tx_type type) enum wallet_tx_type type)
{ {
u8 *msg = towire_onchain_transaction_annotate(tmpctx, txid, type); wire_sync_write(REQ_FD, take(towire_onchain_annotate_txout(
wire_sync_write(REQ_FD, take(msg)); tmpctx, txid, outnum, type)));
} }
static void onchain_annotate_txin(const struct bitcoin_txid *txid, u32 innum,
enum wallet_tx_type type)
{
wire_sync_write(REQ_FD, take(towire_onchain_annotate_txin(
tmpctx, txid, innum, type)));
}
/* An output has been spent: see if it resolves something we care about. */ /* An output has been spent: see if it resolves something we care about. */
static void output_spent(const struct chainparams *chainparams, static void output_spent(const struct chainparams *chainparams,
struct tracked_output ***outs, struct tracked_output ***outs,
@ -1062,8 +1070,8 @@ static void output_spent(const struct chainparams *chainparams,
} else { } else {
/* We ignore this timeout tx, since we should /* We ignore this timeout tx, since we should
* resolve by ignoring once we reach depth. */ * resolve by ignoring once we reach depth. */
onchain_transaction_annotate( onchain_annotate_txout(
&spendertxid, &spendertxid, out->outnum,
TX_CHANNEL_HTLC_TIMEOUT | TX_THEIRS); TX_CHANNEL_HTLC_TIMEOUT | TX_THEIRS);
} }
break; break;
@ -1097,8 +1105,8 @@ static void output_spent(const struct chainparams *chainparams,
* output is considered *irrevocably resolved* * output is considered *irrevocably resolved*
*/ */
ignore_output(out); ignore_output(out);
onchain_transaction_annotate( onchain_annotate_txout(
&spendertxid, &spendertxid, out->outnum,
TX_CHANNEL_HTLC_SUCCESS | TX_THEIRS); TX_CHANNEL_HTLC_SUCCESS | TX_THEIRS);
} }
break; break;
@ -1434,7 +1442,10 @@ static void handle_mutual_close(const struct chainparams *chainparams,
struct tracked_output **outs) struct tracked_output **outs)
{ {
init_reply("Tracking mutual close transaction"); init_reply("Tracking mutual close transaction");
onchain_transaction_annotate(txid, TX_CHANNEL_CLOSE);
/* Annotate the first input as close. We can currently only have a
* single input for these. */
onchain_annotate_txin(txid, 0, TX_CHANNEL_CLOSE);
/* BOLT #5: /* BOLT #5:
* *
@ -1732,7 +1743,7 @@ static void handle_our_unilateral(const struct bitcoin_tx *tx,
size_t i; size_t i;
init_reply("Tracking our own unilateral close"); init_reply("Tracking our own unilateral close");
onchain_transaction_annotate(txid, TX_CHANNEL_UNILATERAL); onchain_annotate_txin(txid, 0, TX_CHANNEL_UNILATERAL);
/* BOLT #5: /* BOLT #5:
* *
@ -1898,7 +1909,7 @@ static void handle_our_unilateral(const struct bitcoin_tx *tx,
matches = match_htlc_output(tmpctx, tx, i, htlc_scripts); matches = match_htlc_output(tmpctx, tx, i, htlc_scripts);
/* FIXME: limp along when this happens! */ /* FIXME: limp along when this happens! */
if (tal_count(matches) == 0) { if (tal_count(matches) == 0) {
onchain_transaction_annotate(txid, TX_CHANNEL_PENALTY | TX_THEIRS); onchain_annotate_txout(txid, i, TX_CHANNEL_PENALTY | TX_THEIRS);
status_failed(STATUS_FAIL_INTERNAL_ERROR, status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Could not find resolution for output %zu", "Could not find resolution for output %zu",
i); i);
@ -2065,7 +2076,8 @@ static void handle_their_cheat(const struct bitcoin_tx *tx,
size_t i; size_t i;
init_reply("Tracking their illegal close: taking all funds"); init_reply("Tracking their illegal close: taking all funds");
onchain_transaction_annotate(txid, TX_CHANNEL_UNILATERAL | TX_CHANNEL_CHEAT | TX_THEIRS); onchain_annotate_txin(
txid, 0, TX_CHANNEL_UNILATERAL | TX_CHANNEL_CHEAT | TX_THEIRS);
/* BOLT #5: /* BOLT #5:
* *
@ -2308,7 +2320,7 @@ static void handle_their_unilateral(const struct bitcoin_tx *tx,
size_t i; size_t i;
init_reply("Tracking their unilateral close"); init_reply("Tracking their unilateral close");
onchain_transaction_annotate(txid, TX_CHANNEL_UNILATERAL | TX_THEIRS); onchain_annotate_txin(txid, 0, TX_CHANNEL_UNILATERAL | TX_THEIRS);
/* HSM can't derive this. */ /* HSM can't derive this. */
remote_per_commitment_point = this_remote_per_commitment_point; remote_per_commitment_point = this_remote_per_commitment_point;
@ -2540,7 +2552,7 @@ static void handle_unknown_commitment(const struct bitcoin_tx *tx,
int to_us_output = -1; int to_us_output = -1;
u8 *local_script; u8 *local_script;
onchain_transaction_annotate(txid, TX_CHANNEL_UNILATERAL | TX_THEIRS); onchain_annotate_txin(txid, 0, TX_CHANNEL_UNILATERAL | TX_THEIRS);
resolved_by_other(outs[0], txid, UNKNOWN_UNILATERAL); resolved_by_other(outs[0], txid, UNKNOWN_UNILATERAL);

9
onchaind/test/run-grind_feerate-bug.c

@ -137,6 +137,12 @@ u8 *towire_onchain_add_utxo(const tal_t *ctx UNNEEDED, const struct bitcoin_txid
/* Generated stub for towire_onchain_all_irrevocably_resolved */ /* Generated stub for towire_onchain_all_irrevocably_resolved */
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_annotate_txin */
u8 *towire_onchain_annotate_txin(const tal_t *ctx UNNEEDED, const struct bitcoin_txid *txid UNNEEDED, u32 innum UNNEEDED, enum wallet_tx_type type UNNEEDED)
{ fprintf(stderr, "towire_onchain_annotate_txin called!\n"); abort(); }
/* Generated stub for towire_onchain_annotate_txout */
u8 *towire_onchain_annotate_txout(const tal_t *ctx UNNEEDED, const struct bitcoin_txid *txid UNNEEDED, u32 outnum UNNEEDED, enum wallet_tx_type type UNNEEDED)
{ fprintf(stderr, "towire_onchain_annotate_txout 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, enum wallet_tx_type type UNNEEDED) u8 *towire_onchain_broadcast_tx(const tal_t *ctx UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, enum wallet_tx_type type UNNEEDED)
{ fprintf(stderr, "towire_onchain_broadcast_tx called!\n"); abort(); } { fprintf(stderr, "towire_onchain_broadcast_tx called!\n"); abort(); }
@ -155,9 +161,6 @@ u8 *towire_onchain_init_reply(const tal_t *ctx UNNEEDED)
/* Generated stub for towire_onchain_missing_htlc_output */ /* Generated stub for towire_onchain_missing_htlc_output */
u8 *towire_onchain_missing_htlc_output(const tal_t *ctx UNNEEDED, const struct htlc_stub *htlc UNNEEDED) u8 *towire_onchain_missing_htlc_output(const tal_t *ctx UNNEEDED, const struct htlc_stub *htlc UNNEEDED)
{ fprintf(stderr, "towire_onchain_missing_htlc_output called!\n"); abort(); } { fprintf(stderr, "towire_onchain_missing_htlc_output called!\n"); abort(); }
/* Generated stub for towire_onchain_transaction_annotate */
u8 *towire_onchain_transaction_annotate(const tal_t *ctx UNNEEDED, const struct bitcoin_txid *txid UNNEEDED, enum wallet_tx_type type UNNEEDED)
{ fprintf(stderr, "towire_onchain_transaction_annotate called!\n"); abort(); }
/* Generated stub for towire_onchain_unwatch_tx */ /* Generated stub for towire_onchain_unwatch_tx */
u8 *towire_onchain_unwatch_tx(const tal_t *ctx UNNEEDED, const struct bitcoin_txid *txid UNNEEDED) u8 *towire_onchain_unwatch_tx(const tal_t *ctx UNNEEDED, const struct bitcoin_txid *txid UNNEEDED)
{ fprintf(stderr, "towire_onchain_unwatch_tx called!\n"); abort(); } { fprintf(stderr, "towire_onchain_unwatch_tx called!\n"); abort(); }

9
onchaind/test/run-grind_feerate.c

@ -153,6 +153,12 @@ u8 *towire_onchain_add_utxo(const tal_t *ctx UNNEEDED, const struct bitcoin_txid
/* Generated stub for towire_onchain_all_irrevocably_resolved */ /* Generated stub for towire_onchain_all_irrevocably_resolved */
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_annotate_txin */
u8 *towire_onchain_annotate_txin(const tal_t *ctx UNNEEDED, const struct bitcoin_txid *txid UNNEEDED, u32 innum UNNEEDED, enum wallet_tx_type type UNNEEDED)
{ fprintf(stderr, "towire_onchain_annotate_txin called!\n"); abort(); }
/* Generated stub for towire_onchain_annotate_txout */
u8 *towire_onchain_annotate_txout(const tal_t *ctx UNNEEDED, const struct bitcoin_txid *txid UNNEEDED, u32 outnum UNNEEDED, enum wallet_tx_type type UNNEEDED)
{ fprintf(stderr, "towire_onchain_annotate_txout 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, enum wallet_tx_type type UNNEEDED) u8 *towire_onchain_broadcast_tx(const tal_t *ctx UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, enum wallet_tx_type type UNNEEDED)
{ fprintf(stderr, "towire_onchain_broadcast_tx called!\n"); abort(); } { fprintf(stderr, "towire_onchain_broadcast_tx called!\n"); abort(); }
@ -171,9 +177,6 @@ u8 *towire_onchain_init_reply(const tal_t *ctx UNNEEDED)
/* Generated stub for towire_onchain_missing_htlc_output */ /* Generated stub for towire_onchain_missing_htlc_output */
u8 *towire_onchain_missing_htlc_output(const tal_t *ctx UNNEEDED, const struct htlc_stub *htlc UNNEEDED) u8 *towire_onchain_missing_htlc_output(const tal_t *ctx UNNEEDED, const struct htlc_stub *htlc UNNEEDED)
{ fprintf(stderr, "towire_onchain_missing_htlc_output called!\n"); abort(); } { fprintf(stderr, "towire_onchain_missing_htlc_output called!\n"); abort(); }
/* Generated stub for towire_onchain_transaction_annotate */
u8 *towire_onchain_transaction_annotate(const tal_t *ctx UNNEEDED, const struct bitcoin_txid *txid UNNEEDED, enum wallet_tx_type type UNNEEDED)
{ fprintf(stderr, "towire_onchain_transaction_annotate called!\n"); abort(); }
/* Generated stub for towire_onchain_unwatch_tx */ /* Generated stub for towire_onchain_unwatch_tx */
u8 *towire_onchain_unwatch_tx(const tal_t *ctx UNNEEDED, const struct bitcoin_txid *txid UNNEEDED) u8 *towire_onchain_unwatch_tx(const tal_t *ctx UNNEEDED, const struct bitcoin_txid *txid UNNEEDED)
{ fprintf(stderr, "towire_onchain_unwatch_tx called!\n"); abort(); } { fprintf(stderr, "towire_onchain_unwatch_tx called!\n"); abort(); }

Loading…
Cancel
Save