listtransactions: get rid of per-tx type annotations.

We didn't actually populate them properly, and the real annotations
are on inputs and outputs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-EXPERIMENTAL: JSON-RPC: `listtransactions` `channel` and `type` field removed at top level.
This commit is contained in:
Rusty Russell
2023-01-30 16:36:03 +10:30
committed by Alex Myers
parent 578f075407
commit 611795beee
25 changed files with 23 additions and 235 deletions

View File

@@ -744,7 +744,6 @@ message ListtransactionsTransactions {
bytes rawtx = 2; bytes rawtx = 2;
uint32 blockheight = 3; uint32 blockheight = 3;
uint32 txindex = 4; uint32 txindex = 4;
optional string channel = 6;
uint32 locktime = 7; uint32 locktime = 7;
uint32 version = 8; uint32 version = 8;
repeated ListtransactionsTransactionsInputs inputs = 9; repeated ListtransactionsTransactionsInputs inputs = 9;

View File

@@ -632,7 +632,6 @@ impl From<responses::ListtransactionsTransactions> for pb::ListtransactionsTrans
rawtx: hex::decode(&c.rawtx).unwrap(), // Rule #2 for type hex rawtx: hex::decode(&c.rawtx).unwrap(), // Rule #2 for type hex
blockheight: c.blockheight, // Rule #2 for type u32 blockheight: c.blockheight, // Rule #2 for type u32
txindex: c.txindex, // Rule #2 for type u32 txindex: c.txindex, // Rule #2 for type u32
channel: c.channel.map(|v| v.to_string()), // Rule #2 for type short_channel_id?
locktime: c.locktime, // Rule #2 for type u32 locktime: c.locktime, // Rule #2 for type u32
version: c.version, // Rule #2 for type u32 version: c.version, // Rule #2 for type u32
inputs: c.inputs.into_iter().map(|i| i.into()).collect(), // Rule #3 for type ListtransactionsTransactionsInputs inputs: c.inputs.into_iter().map(|i| i.into()).collect(), // Rule #3 for type ListtransactionsTransactionsInputs

2
cln-rpc/src/model.rs generated
View File

@@ -2632,8 +2632,6 @@ pub mod responses {
pub rawtx: String, pub rawtx: String,
pub blockheight: u32, pub blockheight: u32,
pub txindex: u32, pub txindex: u32,
#[serde(skip_serializing_if = "Option::is_none")]
pub channel: Option<ShortChannelId>,
pub locktime: u32, pub locktime: u32,
pub version: u32, pub version: u32,
pub inputs: Vec<ListtransactionsTransactionsInputs>, pub inputs: Vec<ListtransactionsTransactionsInputs>,

View File

@@ -511,8 +511,6 @@ def listtransactions_transactions2py(m):
"rawtx": hexlify(m.rawtx), # PrimitiveField in generate_composite "rawtx": hexlify(m.rawtx), # PrimitiveField in generate_composite
"blockheight": m.blockheight, # PrimitiveField in generate_composite "blockheight": m.blockheight, # PrimitiveField in generate_composite
"txindex": m.txindex, # PrimitiveField in generate_composite "txindex": m.txindex, # PrimitiveField in generate_composite
"type": [str(i) for i in m.type], # ArrayField[composite] in generate_composite
"channel": m.channel, # PrimitiveField in generate_composite
"locktime": m.locktime, # PrimitiveField in generate_composite "locktime": m.locktime, # PrimitiveField in generate_composite
"version": m.version, # PrimitiveField in generate_composite "version": m.version, # PrimitiveField in generate_composite
"inputs": [listtransactions_transactions_inputs2py(i) for i in m.inputs], # ArrayField[composite] in generate_composite "inputs": [listtransactions_transactions_inputs2py(i) for i in m.inputs], # ArrayField[composite] in generate_composite

View File

@@ -45,9 +45,6 @@ On success, an object containing **transactions** is returned. It is an array o
- **scriptPubKey** (hex): the scriptPubKey - **scriptPubKey** (hex): the scriptPubKey
- **type** (string, optional): the purpose of this output (*EXPERIMENTAL\_FEATURES* only) (one of "theirs", "deposit", "withdraw", "channel\_funding", "channel\_mutual\_close", "channel\_unilateral\_close", "channel\_sweep", "channel\_htlc\_success", "channel\_htlc\_timeout", "channel\_penalty", "channel\_unilateral\_cheat") - **type** (string, optional): the purpose of this output (*EXPERIMENTAL\_FEATURES* only) (one of "theirs", "deposit", "withdraw", "channel\_funding", "channel\_mutual\_close", "channel\_unilateral\_close", "channel\_sweep", "channel\_htlc\_success", "channel\_htlc\_timeout", "channel\_penalty", "channel\_unilateral\_cheat")
- **channel** (short\_channel\_id, optional): the channel this output is associated with (*EXPERIMENTAL\_FEATURES* only) - **channel** (short\_channel\_id, optional): the channel this output is associated with (*EXPERIMENTAL\_FEATURES* only)
- **type** (array of strings, optional):
- Reason we care about this transaction (*EXPERIMENTAL\_FEATURES* only) (one of "theirs", "deposit", "withdraw", "channel\_funding", "channel\_mutual\_close", "channel\_unilateral\_close", "channel\_sweep", "channel\_htlc\_success", "channel\_htlc\_timeout", "channel\_penalty", "channel\_unilateral\_cheat")
- **channel** (short\_channel\_id, optional): the channel this transaction is associated with (*EXPERIMENTAL\_FEATURES* only)
[comment]: # (GENERATE-FROM-SCHEMA-END) [comment]: # (GENERATE-FROM-SCHEMA-END)
@@ -106,4 +103,4 @@ RESOURCES
Main web site: <https://github.com/ElementsProject/lightning> Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:450383460036860bfeb65fac98582b4c075d9b6c8df326f22ee1aabde7980d74) [comment]: # ( SHA256STAMP:4820c0c2f399fd5bec1a960bdc731c131a0fb019f7506df3053ae1bc08705845)

View File

@@ -48,4 +48,4 @@ RESOURCES
Main web site: <https://github.com/ElementsProject/lightning> Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:735dd61146b04745f1e884037ead662a386fec2c41e2de1a8698d6bb03f63540) [comment]: # ( SHA256STAMP:ec98523e094209b75eeeb620d8f2a64409dafe6ba21baf3a89ade514b285d202)

View File

@@ -58,4 +58,4 @@ RESOURCES
Main web site: <https://github.com/ElementsProject/lightning> Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:735dd61146b04745f1e884037ead662a386fec2c41e2de1a8698d6bb03f63540) [comment]: # ( SHA256STAMP:ec98523e094209b75eeeb620d8f2a64409dafe6ba21baf3a89ade514b285d202)

View File

@@ -38,30 +38,6 @@
"type": "u32", "type": "u32",
"description": "the transaction number within the block" "description": "the transaction number within the block"
}, },
"type": {
"type": "array",
"items": {
"type": "string",
"enum": [
"theirs",
"deposit",
"withdraw",
"channel_funding",
"channel_mutual_close",
"channel_unilateral_close",
"channel_sweep",
"channel_htlc_success",
"channel_htlc_timeout",
"channel_penalty",
"channel_unilateral_cheat"
],
"description": "Reason we care about this transaction (*EXPERIMENTAL_FEATURES* only)"
}
},
"channel": {
"type": "short_channel_id",
"description": "the channel this transaction is associated with (*EXPERIMENTAL_FEATURES* only)"
},
"locktime": { "locktime": {
"type": "u32", "type": "u32",
"description": "The nLocktime for this tx" "description": "The nLocktime for this tx"

View File

@@ -239,7 +239,6 @@ struct channel *new_unsaved_channel(struct peer *peer,
channel->shutdown_scriptpubkey[REMOTE] = NULL; channel->shutdown_scriptpubkey[REMOTE] = NULL;
channel->last_was_revoke = false; channel->last_was_revoke = false;
channel->last_sent_commit = NULL; channel->last_sent_commit = NULL;
channel->last_tx_type = TX_UNKNOWN;
channel->feerate_base = feerate_base; channel->feerate_base = feerate_base;
channel->feerate_ppm = feerate_ppm; channel->feerate_ppm = feerate_ppm;
@@ -452,7 +451,6 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
channel->last_tx = tal_steal(channel, last_tx); channel->last_tx = tal_steal(channel, last_tx);
if (channel->last_tx) { if (channel->last_tx) {
channel->last_tx->chainparams = chainparams; channel->last_tx->chainparams = chainparams;
channel->last_tx_type = TX_UNKNOWN;
} }
channel->last_sig = *last_sig; channel->last_sig = *last_sig;
channel->last_htlc_sigs = tal_steal(channel, last_htlc_sigs); channel->last_htlc_sigs = tal_steal(channel, last_htlc_sigs);
@@ -723,14 +721,12 @@ struct channel *find_channel_by_alias(const struct peer *peer,
void channel_set_last_tx(struct channel *channel, void channel_set_last_tx(struct channel *channel,
struct bitcoin_tx *tx, struct bitcoin_tx *tx,
const struct bitcoin_signature *sig, const struct bitcoin_signature *sig)
enum wallet_tx_type txtypes)
{ {
assert(tx->chainparams); assert(tx->chainparams);
channel->last_sig = *sig; channel->last_sig = *sig;
tal_free(channel->last_tx); tal_free(channel->last_tx);
channel->last_tx = tal_steal(channel, tx); channel->last_tx = tal_steal(channel, tx);
channel->last_tx_type = txtypes;
} }
void channel_set_state(struct channel *channel, void channel_set_state(struct channel *channel,

View File

@@ -157,7 +157,6 @@ struct channel {
/* Last tx they gave us. */ /* Last tx they gave us. */
struct bitcoin_tx *last_tx; struct bitcoin_tx *last_tx;
enum wallet_tx_type last_tx_type;
struct bitcoin_signature last_sig; struct bitcoin_signature last_sig;
const struct bitcoin_signature *last_htlc_sigs; const struct bitcoin_signature *last_htlc_sigs;
@@ -435,8 +434,7 @@ struct channel *find_channel_by_alias(const struct peer *peer,
void channel_set_last_tx(struct channel *channel, void channel_set_last_tx(struct channel *channel,
struct bitcoin_tx *tx, struct bitcoin_tx *tx,
const struct bitcoin_signature *sig, const struct bitcoin_signature *sig);
enum wallet_tx_type type);
static inline bool channel_can_add_htlc(const struct channel *channel) static inline bool channel_can_add_htlc(const struct channel *channel)
{ {

View File

@@ -1067,10 +1067,8 @@ struct command_result *cancel_channel_before_broadcast(struct command *cmd,
/* Check if we broadcast the transaction. (We store the transaction /* Check if we broadcast the transaction. (We store the transaction
* type into DB before broadcast). */ * type into DB before broadcast). */
enum wallet_tx_type type; if (wallet_transaction_get(tmpctx, cmd->ld->wallet,
if (wallet_transaction_type(cmd->ld->wallet, &cancel_channel->funding.txid))
&cancel_channel->funding.txid,
&type))
return command_fail(cmd, FUNDING_CANCEL_NOT_SAFE, return command_fail(cmd, FUNDING_CANCEL_NOT_SAFE,
"Has the funding transaction been" "Has the funding transaction been"
" broadcast? Please use `close` or" " broadcast? Please use `close` or"

View File

@@ -266,7 +266,7 @@ static void peer_received_closing_signature(struct channel *channel,
} }
if (closing_fee_is_acceptable(ld, channel, tx)) { if (closing_fee_is_acceptable(ld, channel, tx)) {
channel_set_last_tx(channel, tx, &sig, TX_CHANNEL_CLOSE); channel_set_last_tx(channel, tx, &sig);
wallet_channel_save(ld->wallet, channel); wallet_channel_save(ld->wallet, channel);
} }

View File

@@ -1149,8 +1149,7 @@ wallet_update_channel(struct lightningd *ld,
channel_set_last_tx(channel, channel_set_last_tx(channel,
tal_steal(channel, remote_commit), tal_steal(channel, remote_commit),
remote_commit_sig, remote_commit_sig);
TX_CHANNEL_UNILATERAL);
/* Update in database */ /* Update in database */
wallet_channel_save(ld->wallet, channel); wallet_channel_save(ld->wallet, channel);
@@ -1238,7 +1237,6 @@ wallet_commit_channel(struct lightningd *ld,
channel->last_tx = tal_steal(channel, remote_commit); channel->last_tx = tal_steal(channel, remote_commit);
channel->last_sig = *remote_commit_sig; channel->last_sig = *remote_commit_sig;
channel->last_tx_type = TX_CHANNEL_UNILATERAL;
channel->channel_info = *channel_info; channel->channel_info = *channel_info;
channel->fee_states = new_fee_states(channel, channel->fee_states = new_fee_states(channel,

View File

@@ -329,20 +329,16 @@ static void handle_onchain_broadcast_tx(struct channel *channel,
{ {
struct bitcoin_tx *tx; struct bitcoin_tx *tx;
struct wallet *w = channel->peer->ld->wallet; struct wallet *w = channel->peer->ld->wallet;
struct bitcoin_txid txid;
enum wallet_tx_type type;
bool is_rbf; bool is_rbf;
if (!fromwire_onchaind_broadcast_tx(msg, msg, &tx, &type, &is_rbf)) { if (!fromwire_onchaind_broadcast_tx(msg, msg, &tx, &is_rbf)) {
channel_internal_error(channel, "Invalid onchain_broadcast_tx"); channel_internal_error(channel, "Invalid onchain_broadcast_tx");
return; return;
} }
tx->chainparams = chainparams; tx->chainparams = chainparams;
bitcoin_txid(tx, &txid);
wallet_transaction_add(w, tx->wtx, 0, 0); wallet_transaction_add(w, tx->wtx, 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. */
/* If the onchaind signals this as RBF-able, then we also /* If the onchaind signals this as RBF-able, then we also

View File

@@ -283,9 +283,6 @@ static void sign_and_send_last(struct lightningd *ld,
sign_last_tx(channel, last_tx, last_sig); sign_last_tx(channel, last_tx, last_sig);
bitcoin_txid(last_tx, &txid); bitcoin_txid(last_tx, &txid);
wallet_transaction_add(ld->wallet, last_tx->wtx, 0, 0); wallet_transaction_add(ld->wallet, last_tx->wtx, 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, /* Keep broadcasting until we say stop (can fail due to dup,
* if they beat us to the broadcast). */ * if they beat us to the broadcast). */
@@ -1739,8 +1736,7 @@ static void update_channel_from_inflight(struct lightningd *ld,
psbt_copy = clone_psbt(channel, inflight->last_tx->psbt); psbt_copy = clone_psbt(channel, inflight->last_tx->psbt);
channel_set_last_tx(channel, channel_set_last_tx(channel,
bitcoin_tx_with_psbt(channel, psbt_copy), bitcoin_tx_with_psbt(channel, psbt_copy),
&inflight->last_sig, &inflight->last_sig);
TX_CHANNEL_UNILATERAL);
/* Update the reserve */ /* Update the reserve */
channel_update_reserve(channel, channel_update_reserve(channel,

View File

@@ -1982,7 +1982,7 @@ static bool peer_save_commitsig_received(struct channel *channel, u64 commitnum,
channel->next_index[LOCAL]++; channel->next_index[LOCAL]++;
/* Update channel->last_sig and channel->last_tx before saving to db */ /* Update channel->last_sig and channel->last_tx before saving to db */
channel_set_last_tx(channel, tx, commit_sig, TX_CHANNEL_UNILATERAL); channel_set_last_tx(channel, tx, commit_sig);
return true; return true;
} }

View File

@@ -97,8 +97,7 @@ u32 channel_last_funding_feerate(const struct channel *channel UNNEEDED)
/* Generated stub for channel_set_last_tx */ /* Generated stub for channel_set_last_tx */
void channel_set_last_tx(struct channel *channel UNNEEDED, void channel_set_last_tx(struct channel *channel UNNEEDED,
struct bitcoin_tx *tx UNNEEDED, struct bitcoin_tx *tx UNNEEDED,
const struct bitcoin_signature *sig UNNEEDED, const struct bitcoin_signature *sig UNNEEDED)
enum wallet_tx_type type UNNEEDED)
{ fprintf(stderr, "channel_set_last_tx called!\n"); abort(); } { fprintf(stderr, "channel_set_last_tx called!\n"); abort(); }
/* Generated stub for channel_state_name */ /* Generated stub for channel_state_name */
const char *channel_state_name(const struct channel *channel UNNEEDED) const char *channel_state_name(const struct channel *channel UNNEEDED)
@@ -946,11 +945,6 @@ struct amount_msat wallet_total_forward_fees(struct wallet *w UNNEEDED)
void wallet_transaction_add(struct wallet *w UNNEEDED, const struct wally_tx *tx UNNEEDED, void wallet_transaction_add(struct wallet *w UNNEEDED, const struct wally_tx *tx UNNEEDED,
const u32 blockheight UNNEEDED, const u32 txindex UNNEEDED) const u32 blockheight UNNEEDED, const u32 txindex UNNEEDED)
{ fprintf(stderr, "wallet_transaction_add called!\n"); abort(); } { 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,
enum wallet_tx_type type UNNEEDED, u64 channel_id UNNEEDED)
{ fprintf(stderr, "wallet_transaction_annotate called!\n"); abort(); }
/* Generated stub for wallet_transaction_locate */ /* Generated stub for wallet_transaction_locate */
struct txlocator *wallet_transaction_locate(const tal_t *ctx UNNEEDED, struct wallet *w UNNEEDED, struct txlocator *wallet_transaction_locate(const tal_t *ctx UNNEEDED, struct wallet *w UNNEEDED,
const struct bitcoin_txid *txid UNNEEDED) const struct bitcoin_txid *txid UNNEEDED)

View File

@@ -1018,43 +1018,6 @@ static void ignore_output(struct tracked_output *out)
out->resolved->tx_type = SELF; out->resolved->tx_type = SELF;
} }
static enum wallet_tx_type 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_DELAYED_CHEAT:
return TX_CHANNEL_CHEAT | TX_THEIRS;
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();
}
/** proposal_is_rbfable /** proposal_is_rbfable
* *
* @brief returns true if the given proposal * @brief returns true if the given proposal
@@ -1141,8 +1104,6 @@ static void proposal_should_rbf(struct tracked_output *out)
/* Broadcast the transaction. */ /* Broadcast the transaction. */
if (tx) { if (tx) {
enum wallet_tx_type wtt;
status_debug("Broadcasting RBF %s (%s) to resolve %s/%s " status_debug("Broadcasting RBF %s (%s) to resolve %s/%s "
"depth=%"PRIu32"", "depth=%"PRIu32"",
tx_type_name(out->proposal->tx_type), tx_type_name(out->proposal->tx_type),
@@ -1151,11 +1112,9 @@ static void proposal_should_rbf(struct tracked_output *out)
output_type_name(out->output_type), output_type_name(out->output_type),
depth); depth);
wtt = onchain_txtype_to_wallet_txtype(out->proposal->tx_type);
wire_sync_write(REQ_FD, wire_sync_write(REQ_FD,
take(towire_onchaind_broadcast_tx(NULL, tx, take(towire_onchaind_broadcast_tx(NULL, tx,
wtt, true)));
true)));
} }
} }
@@ -1186,9 +1145,7 @@ static void proposal_meets_depth(struct tracked_output *out)
wire_sync_write( wire_sync_write(
REQ_FD, REQ_FD,
take(towire_onchaind_broadcast_tx( take(towire_onchaind_broadcast_tx(
NULL, out->proposal->tx, NULL, out->proposal->tx, is_rbf)));
onchain_txtype_to_wallet_txtype(out->proposal->tx_type),
is_rbf)));
/* 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) {

View File

@@ -73,7 +73,6 @@ msgdata,onchaind_htlcs,tell_immediately,bool,num_htlcs
# it with a higher fee. # it with a higher fee.
msgtype,onchaind_broadcast_tx,5003 msgtype,onchaind_broadcast_tx,5003
msgdata,onchaind_broadcast_tx,tx,bitcoin_tx, msgdata,onchaind_broadcast_tx,tx,bitcoin_tx,
msgdata,onchaind_broadcast_tx,type,enum wallet_tx_type,
msgdata,onchaind_broadcast_tx,is_rbf,bool, msgdata,onchaind_broadcast_tx,is_rbf,bool,
# 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.
1 #include <bitcoin/tx_parts.h>
73 msgdata,onchaind_broadcast_tx,is_rbf,bool, # master->onchaind: Notifier that an output has been spent by input_num of tx.
74 # master->onchaind: Notifier that an output has been spent by input_num of tx. msgtype,onchaind_spent,5004
75 msgtype,onchaind_spent,5004 msgdata,onchaind_spent,tx,tx_parts,
msgdata,onchaind_spent,tx,tx_parts,
76 msgdata,onchaind_spent,input_num,u32,
77 msgdata,onchaind_spent,blockheight,u32,
78 # master->onchaind: We will receive more than one of these, as depth changes.

View File

@@ -262,7 +262,7 @@ u8 *towire_onchaind_annotate_txin(const tal_t *ctx UNNEEDED, const struct bitcoi
u8 *towire_onchaind_annotate_txout(const tal_t *ctx UNNEEDED, const struct bitcoin_outpoint *outpoint UNNEEDED, enum wallet_tx_type type UNNEEDED) u8 *towire_onchaind_annotate_txout(const tal_t *ctx UNNEEDED, const struct bitcoin_outpoint *outpoint UNNEEDED, enum wallet_tx_type type UNNEEDED)
{ fprintf(stderr, "towire_onchaind_annotate_txout called!\n"); abort(); } { fprintf(stderr, "towire_onchaind_annotate_txout called!\n"); abort(); }
/* Generated stub for towire_onchaind_broadcast_tx */ /* Generated stub for towire_onchaind_broadcast_tx */
u8 *towire_onchaind_broadcast_tx(const tal_t *ctx UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, enum wallet_tx_type type UNNEEDED, bool is_rbf UNNEEDED) u8 *towire_onchaind_broadcast_tx(const tal_t *ctx UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, bool is_rbf UNNEEDED)
{ fprintf(stderr, "towire_onchaind_broadcast_tx called!\n"); abort(); } { fprintf(stderr, "towire_onchaind_broadcast_tx called!\n"); abort(); }
/* Generated stub for towire_onchaind_dev_memleak_reply */ /* Generated stub for towire_onchaind_dev_memleak_reply */
u8 *towire_onchaind_dev_memleak_reply(const tal_t *ctx UNNEEDED, bool leak UNNEEDED) u8 *towire_onchaind_dev_memleak_reply(const tal_t *ctx UNNEEDED, bool leak UNNEEDED)

View File

@@ -288,7 +288,7 @@ u8 *towire_onchaind_annotate_txin(const tal_t *ctx UNNEEDED, const struct bitcoi
u8 *towire_onchaind_annotate_txout(const tal_t *ctx UNNEEDED, const struct bitcoin_outpoint *outpoint UNNEEDED, enum wallet_tx_type type UNNEEDED) u8 *towire_onchaind_annotate_txout(const tal_t *ctx UNNEEDED, const struct bitcoin_outpoint *outpoint UNNEEDED, enum wallet_tx_type type UNNEEDED)
{ fprintf(stderr, "towire_onchaind_annotate_txout called!\n"); abort(); } { fprintf(stderr, "towire_onchaind_annotate_txout called!\n"); abort(); }
/* Generated stub for towire_onchaind_broadcast_tx */ /* Generated stub for towire_onchaind_broadcast_tx */
u8 *towire_onchaind_broadcast_tx(const tal_t *ctx UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, enum wallet_tx_type type UNNEEDED, bool is_rbf UNNEEDED) u8 *towire_onchaind_broadcast_tx(const tal_t *ctx UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, bool is_rbf UNNEEDED)
{ fprintf(stderr, "towire_onchaind_broadcast_tx called!\n"); abort(); } { fprintf(stderr, "towire_onchaind_broadcast_tx called!\n"); abort(); }
/* Generated stub for towire_onchaind_dev_memleak_reply */ /* Generated stub for towire_onchaind_dev_memleak_reply */
u8 *towire_onchaind_dev_memleak_reply(const tal_t *ctx UNNEEDED, bool leak UNNEEDED) u8 *towire_onchaind_dev_memleak_reply(const tal_t *ctx UNNEEDED, bool leak UNNEEDED)

View File

@@ -492,6 +492,8 @@ static struct migration dbmigrations[] = {
/* remote signatures for channel announcement */ /* remote signatures for channel announcement */
{SQL("ALTER TABLE channels ADD remote_ann_node_sig BLOB;"), NULL}, {SQL("ALTER TABLE channels ADD remote_ann_node_sig BLOB;"), NULL},
{SQL("ALTER TABLE channels ADD remote_ann_bitcoin_sig BLOB;"), NULL}, {SQL("ALTER TABLE channels ADD remote_ann_bitcoin_sig BLOB;"), NULL},
/* FIXME: We now use the transaction_annotations table to type each
* input and output instead of type and channel_id! */
/* Additional information for transaction tracking and listing */ /* Additional information for transaction tracking and listing */
{SQL("ALTER TABLE transactions ADD type BIGINT;"), NULL}, {SQL("ALTER TABLE transactions ADD type BIGINT;"), NULL},
/* Not a foreign key on purpose since we still delete channels from /* Not a foreign key on purpose since we still delete channels from

View File

@@ -4133,66 +4133,6 @@ void wallet_annotate_txin(struct wallet *w, const struct bitcoin_txid *txid,
wallet_annotation_add(w, txid, innum, INPUT_ANNOTATION, type, channel); wallet_annotation_add(w, txid, innum, INPUT_ANNOTATION, type, channel);
} }
void wallet_transaction_annotate(struct wallet *w,
const struct bitcoin_txid *txid, enum wallet_tx_type type,
u64 channel_id)
{
struct db_stmt *stmt = db_prepare_v2(
w->db, SQL("SELECT type, channel_id FROM transactions WHERE id=?"));
db_bind_txid(stmt, 0, txid);
db_query_prepared(stmt);
if (!db_step(stmt))
fatal("Attempting to annotate a transaction we don't have: %s",
type_to_string(tmpctx, struct bitcoin_txid, txid));
if (!db_col_is_null(stmt, "type"))
type |= db_col_u64(stmt, "type");
if (channel_id == 0 && !db_col_is_null(stmt, "channel_id"))
channel_id = db_col_u64(stmt, "channel_id");
else
db_col_ignore(stmt, "channel_id");
tal_free(stmt);
stmt = db_prepare_v2(w->db, SQL("UPDATE transactions "
"SET type = ?"
", channel_id = ? "
"WHERE id = ?"));
db_bind_u64(stmt, 0, type);
if (channel_id)
db_bind_int(stmt, 1, channel_id);
else
db_bind_null(stmt, 1);
db_bind_txid(stmt, 2, txid);
db_exec_prepared_v2(take(stmt));
}
bool wallet_transaction_type(struct wallet *w, const struct bitcoin_txid *txid,
enum wallet_tx_type *type)
{
struct db_stmt *stmt = db_prepare_v2(w->db, SQL("SELECT type FROM transactions WHERE id=?"));
db_bind_sha256(stmt, 0, &txid->shad.sha);
db_query_prepared(stmt);
if (!db_step(stmt)) {
tal_free(stmt);
return false;
}
if (!db_col_is_null(stmt, "type"))
*type = db_col_u64(stmt, "type");
else
*type = 0;
tal_free(stmt);
return true;
}
struct bitcoin_tx *wallet_transaction_get(const tal_t *ctx, struct wallet *w, struct bitcoin_tx *wallet_transaction_get(const tal_t *ctx, struct wallet *w,
const struct bitcoin_txid *txid) const struct bitcoin_txid *txid)
{ {
@@ -4794,8 +4734,6 @@ struct wallet_transaction *wallet_transactions_get(struct wallet *w, const tal_t
", t.rawtx" ", t.rawtx"
", t.blockheight" ", t.blockheight"
", t.txindex" ", t.txindex"
", t.type as txtype"
", c2.scid as txchan"
", a.location" ", a.location"
", a.idx as ann_idx" ", a.idx as ann_idx"
", a.type as annotation_type" ", a.type as annotation_type"
@@ -4803,8 +4741,7 @@ struct wallet_transaction *wallet_transactions_get(struct wallet *w, const tal_t
" FROM" " FROM"
" transactions t LEFT JOIN" " transactions t LEFT JOIN"
" transaction_annotations a ON (a.txid = t.id) LEFT JOIN" " transaction_annotations a ON (a.txid = t.id) LEFT JOIN"
" channels c ON (a.channel = c.id) LEFT JOIN" " channels c ON (a.channel = c.id) "
" channels c2 ON (t.channel_id = c2.id) "
"ORDER BY t.blockheight, t.txindex ASC")); "ORDER BY t.blockheight, t.txindex ASC"));
db_query_prepared(stmt); db_query_prepared(stmt);
@@ -4836,16 +4773,6 @@ struct wallet_transaction *wallet_transactions_get(struct wallet *w, const tal_t
cur->blockheight = 0; cur->blockheight = 0;
cur->txindex = 0; cur->txindex = 0;
} }
if (!db_col_is_null(stmt, "txtype"))
cur->annotation.type
= db_col_u64(stmt, "txtype");
else
cur->annotation.type = 0;
if (!db_col_is_null(stmt, "txchan"))
db_col_scid(stmt, "txchan", &cur->annotation.channel);
else
cur->annotation.channel.u64 = 0;
cur->output_annotations = tal_arrz(txs, struct tx_annotation, cur->tx->wtx->num_outputs); cur->output_annotations = tal_arrz(txs, struct tx_annotation, cur->tx->wtx->num_outputs);
cur->input_annotations = tal_arrz(txs, struct tx_annotation, cur->tx->wtx->num_inputs); cur->input_annotations = tal_arrz(txs, struct tx_annotation, cur->tx->wtx->num_inputs);
} }

View File

@@ -408,8 +408,6 @@ struct wallet_transaction {
/* Fully parsed transaction */ /* Fully parsed transaction */
const struct bitcoin_tx *tx; const struct bitcoin_tx *tx;
struct tx_annotation annotation;
/* tal_arr containing the annotation types, if any, for the respective /* tal_arr containing the annotation types, if any, for the respective
* inputs and outputs. 0 if there are no annotations for the * inputs and outputs. 0 if there are no annotations for the
* element. */ * element. */
@@ -1291,28 +1289,6 @@ void wallet_annotate_txout(struct wallet *w,
void wallet_annotate_txin(struct wallet *w, const struct bitcoin_txid *txid, void wallet_annotate_txin(struct wallet *w, const struct bitcoin_txid *txid,
int innum, enum wallet_tx_type type, u64 channel); int innum, enum wallet_tx_type type, u64 channel);
/**
* Annotate a transaction in the DB with its type and channel referemce.
*
* We add transactions when filtering the block, but often know its type only
* when we trigger the txwatches, at which point we've already discarded the
* full transaction. This function can be used to annotate the transactions
* after the fact with a channel number for grouping and a type for filtering.
*/
void wallet_transaction_annotate(struct wallet *w,
const struct bitcoin_txid *txid,
enum wallet_tx_type type, u64 channel_id);
/**
* Get the type of a transaction we are watching by its
* txid.
*
* Returns false if the transaction was not stored in DB.
* Returns true if the transaction exists and sets the `type` parameter.
*/
bool wallet_transaction_type(struct wallet *w, const struct bitcoin_txid *txid,
enum wallet_tx_type *type);
/** /**
* Get the transaction from the database * Get the transaction from the database
* *

View File

@@ -1,6 +1,7 @@
#include "config.h" #include "config.h"
#include <bitcoin/base58.h> #include <bitcoin/base58.h>
#include <bitcoin/script.h> #include <bitcoin/script.h>
#include <ccan/array_size/array_size.h>
#include <ccan/cast/cast.h> #include <ccan/cast/cast.h>
#include <common/addr.h> #include <common/addr.h>
#include <common/bech32.h> #include <common/bech32.h>
@@ -483,28 +484,18 @@ struct {
{TX_CHANNEL_HTLC_TIMEOUT, "channel_htlc_timeout"}, {TX_CHANNEL_HTLC_TIMEOUT, "channel_htlc_timeout"},
{TX_CHANNEL_PENALTY, "channel_penalty"}, {TX_CHANNEL_PENALTY, "channel_penalty"},
{TX_CHANNEL_CHEAT, "channel_unilateral_cheat"}, {TX_CHANNEL_CHEAT, "channel_unilateral_cheat"},
{0, NULL}
}; };
#if EXPERIMENTAL_FEATURES #if EXPERIMENTAL_FEATURES
static const char *txtype_to_string(enum wallet_tx_type t) static const char *txtype_to_string(enum wallet_tx_type t)
{ {
for (size_t i = 0; wallet_tx_type_display_names[i].name != NULL; i++) for (size_t i = 0; i < ARRAY_SIZE(wallet_tx_type_display_names); i++)
if (t == wallet_tx_type_display_names[i].t) if (t == wallet_tx_type_display_names[i].t)
return wallet_tx_type_display_names[i].name; return wallet_tx_type_display_names[i].name;
return NULL; return NULL;
} }
static void json_add_txtypes(struct json_stream *result, const char *fieldname, enum wallet_tx_type value)
{
json_array_start(result, fieldname);
for (size_t i = 0; wallet_tx_type_display_names[i].name != NULL; i++) {
if (value & wallet_tx_type_display_names[i].t)
json_add_string(result, NULL, wallet_tx_type_display_names[i].name);
}
json_array_end(result);
}
#endif #endif
static void json_transaction_details(struct json_stream *response, static void json_transaction_details(struct json_stream *response,
const struct wallet_transaction *tx) const struct wallet_transaction *tx)
{ {
@@ -515,13 +506,6 @@ static void json_transaction_details(struct json_stream *response,
json_add_hex_talarr(response, "rawtx", tx->rawtx); json_add_hex_talarr(response, "rawtx", tx->rawtx);
json_add_num(response, "blockheight", tx->blockheight); json_add_num(response, "blockheight", tx->blockheight);
json_add_num(response, "txindex", tx->txindex); json_add_num(response, "txindex", tx->txindex);
#if EXPERIMENTAL_FEATURES
if (tx->annotation.type != 0)
json_add_txtypes(response, "type", tx->annotation.type);
if (tx->annotation.channel.u64 != 0)
json_add_short_channel_id(response, "channel", &tx->annotation.channel);
#endif
json_add_u32(response, "locktime", wtx->locktime); json_add_u32(response, "locktime", wtx->locktime);
json_add_u32(response, "version", wtx->version); json_add_u32(response, "version", wtx->version);