mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-17 19:03:42 +01:00
onchaind: Annotate inputs and outputs not the transactions
This commit is contained in:
parent
af53e3494b
commit
ff4a2bf38f
@ -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 */
|
||||
tx->input_amounts =
|
||||
tal_arrz(tx, struct amount_sat *, tx->wtx->inputs_allocation_len);
|
||||
tx->chainparams = NULL;
|
||||
tx->chainparams = chainparams;
|
||||
|
||||
*cursor += wsize;
|
||||
*max -= wsize;
|
||||
|
@ -306,15 +306,29 @@ static void onchain_add_utxo(struct channel *channel, const u8 *msg)
|
||||
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;
|
||||
enum wallet_tx_type type;
|
||||
if (!fromwire_onchain_transaction_annotate(msg, &txid, &type))
|
||||
fatal("onchaind gave invalid onchain_transaction_annotate "
|
||||
u32 outnum;
|
||||
if (!fromwire_onchain_annotate_txout(msg, &txid, &outnum, &type))
|
||||
fatal("onchaind gave invalid onchain_annotate_txout "
|
||||
"message: %s",
|
||||
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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
break;
|
||||
|
||||
case WIRE_ONCHAIN_TRANSACTION_ANNOTATE:
|
||||
onchain_transaction_annotate(sd->channel, msg);
|
||||
case WIRE_ONCHAIN_ANNOTATE_TXIN:
|
||||
onchain_annotate_txin(sd->channel, msg);
|
||||
break;
|
||||
|
||||
case WIRE_ONCHAIN_ANNOTATE_TXOUT:
|
||||
onchain_annotate_txout(sd->channel, msg);
|
||||
break;
|
||||
|
||||
/* We send these, not receive them */
|
||||
|
@ -108,6 +108,13 @@ msgdata,onchain_dev_memleak_reply,leak,bool,
|
||||
# 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
|
||||
# transactions.
|
||||
msgtype,onchain_transaction_annotate,5034
|
||||
msgdata,onchain_transaction_annotate,txid,bitcoin_txid,
|
||||
msgdata,onchain_transaction_annotate,type,enum wallet_tx_type,
|
||||
msgtype,onchain_annotate_txout,5035
|
||||
msgdata,onchain_annotate_txout,txid,bitcoin_txid,
|
||||
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,
|
||||
|
||||
|
|
@ -1010,12 +1010,20 @@ static void steal_htlc_tx(struct tracked_output *out)
|
||||
propose_resolution(out, tx, 0, tx_type);
|
||||
}
|
||||
|
||||
static void onchain_transaction_annotate(const struct bitcoin_txid *txid,
|
||||
enum wallet_tx_type type)
|
||||
static void onchain_annotate_txout(const struct bitcoin_txid *txid, u32 outnum,
|
||||
enum wallet_tx_type type)
|
||||
{
|
||||
u8 *msg = towire_onchain_transaction_annotate(tmpctx, txid, type);
|
||||
wire_sync_write(REQ_FD, take(msg));
|
||||
wire_sync_write(REQ_FD, take(towire_onchain_annotate_txout(
|
||||
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. */
|
||||
static void output_spent(const struct chainparams *chainparams,
|
||||
struct tracked_output ***outs,
|
||||
@ -1062,8 +1070,8 @@ static void output_spent(const struct chainparams *chainparams,
|
||||
} else {
|
||||
/* We ignore this timeout tx, since we should
|
||||
* resolve by ignoring once we reach depth. */
|
||||
onchain_transaction_annotate(
|
||||
&spendertxid,
|
||||
onchain_annotate_txout(
|
||||
&spendertxid, out->outnum,
|
||||
TX_CHANNEL_HTLC_TIMEOUT | TX_THEIRS);
|
||||
}
|
||||
break;
|
||||
@ -1097,8 +1105,8 @@ static void output_spent(const struct chainparams *chainparams,
|
||||
* output is considered *irrevocably resolved*
|
||||
*/
|
||||
ignore_output(out);
|
||||
onchain_transaction_annotate(
|
||||
&spendertxid,
|
||||
onchain_annotate_txout(
|
||||
&spendertxid, out->outnum,
|
||||
TX_CHANNEL_HTLC_SUCCESS | TX_THEIRS);
|
||||
}
|
||||
break;
|
||||
@ -1434,7 +1442,10 @@ static void handle_mutual_close(const struct chainparams *chainparams,
|
||||
struct tracked_output **outs)
|
||||
{
|
||||
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:
|
||||
*
|
||||
@ -1732,7 +1743,7 @@ static void handle_our_unilateral(const struct bitcoin_tx *tx,
|
||||
size_t i;
|
||||
|
||||
init_reply("Tracking our own unilateral close");
|
||||
onchain_transaction_annotate(txid, TX_CHANNEL_UNILATERAL);
|
||||
onchain_annotate_txin(txid, 0, TX_CHANNEL_UNILATERAL);
|
||||
|
||||
/* 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);
|
||||
/* FIXME: limp along when this happens! */
|
||||
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,
|
||||
"Could not find resolution for output %zu",
|
||||
i);
|
||||
@ -2065,7 +2076,8 @@ static void handle_their_cheat(const struct bitcoin_tx *tx,
|
||||
size_t i;
|
||||
|
||||
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:
|
||||
*
|
||||
@ -2308,7 +2320,7 @@ static void handle_their_unilateral(const struct bitcoin_tx *tx,
|
||||
size_t i;
|
||||
|
||||
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. */
|
||||
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;
|
||||
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);
|
||||
|
||||
|
@ -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 */
|
||||
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_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 */
|
||||
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(); }
|
||||
@ -155,9 +161,6 @@ u8 *towire_onchain_init_reply(const tal_t *ctx UNNEEDED)
|
||||
/* 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)
|
||||
{ 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 */
|
||||
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(); }
|
||||
|
@ -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 */
|
||||
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_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 */
|
||||
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(); }
|
||||
@ -171,9 +177,6 @@ u8 *towire_onchain_init_reply(const tal_t *ctx UNNEEDED)
|
||||
/* 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)
|
||||
{ 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 */
|
||||
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(); }
|
||||
|
Loading…
Reference in New Issue
Block a user