From 77936ceddaf0a5c95920cadb76effbfff29397b7 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 20 Mar 2024 11:17:55 +1030 Subject: [PATCH] wallet: fix parameter order to hand `const tal_t *ctx` first. This is the convention everywhere else: allocation ctx comes first, any other context comes second. Signed-off-by: Rusty Russell --- lightningd/chaintopology.c | 2 +- lightningd/forwards.c | 2 +- lightningd/gossip_control.c | 23 +++++++++++---------- lightningd/onchain_control.c | 5 ++--- lightningd/peer_control.c | 2 +- lightningd/test/run-invoice-select-inchan.c | 4 ++-- wallet/wallet.c | 19 ++++++++--------- wallet/wallet.h | 19 ++++++++--------- wallet/walletrpc.c | 2 +- 9 files changed, 38 insertions(+), 40 deletions(-) diff --git a/lightningd/chaintopology.c b/lightningd/chaintopology.c index 1ac6f2fcf..081d8bd1e 100644 --- a/lightningd/chaintopology.c +++ b/lightningd/chaintopology.c @@ -930,7 +930,7 @@ static void topo_update_spends(struct chain_topology *topo, struct block *b) bitcoin_tx_input_get_outpoint(tx, j, &outpoint); - if (wallet_outpoint_spend(topo->ld->wallet, tmpctx, + if (wallet_outpoint_spend(tmpctx, topo->ld->wallet, b->height, &outpoint)) record_wallet_spend(topo->ld, &outpoint, &b->txids[i], b->height); diff --git a/lightningd/forwards.c b/lightningd/forwards.c index 2cf48018d..c06877928 100644 --- a/lightningd/forwards.c +++ b/lightningd/forwards.c @@ -160,7 +160,7 @@ static void listforwardings_add_forwardings(struct json_stream *response, { const struct forwarding *forwardings; - forwardings = wallet_forwarded_payments_get(wallet, tmpctx, status, chan_in, chan_out, listindex, liststart, listlimit); + forwardings = wallet_forwarded_payments_get(tmpctx, wallet, status, chan_in, chan_out, listindex, liststart, listlimit); json_array_start(response, "forwards"); for (size_t i=0; ild->topology; - if (!fromwire_gossipd_get_txout(msg, scid)) + if (!fromwire_gossipd_get_txout(msg, &scid)) fatal("Gossip gave bad GOSSIP_GET_TXOUT message %s", tal_hex(msg, msg)); /* FIXME: Block less than 6 deep? */ - blockheight = short_channel_id_blocknum(scid); - - op = wallet_outpoint_for_scid(gossip->ld->wallet, scid, scid); + blockheight = short_channel_id_blocknum(&scid); + op = wallet_outpoint_for_scid(tmpctx, gossip->ld->wallet, &scid); if (op) { subd_send_msg(gossip, - towire_gossipd_get_txout_reply( - scid, scid, op->sat, op->scriptpubkey)); - tal_free(scid); + take(towire_gossipd_get_txout_reply( + NULL, &scid, op->sat, op->scriptpubkey))); } else if (wallet_have_block(gossip->ld->wallet, blockheight)) { /* We should have known about this outpoint since its header * is in the DB. The fact that we don't means that this is * either a spent outpoint or an invalid one. Return a * failure. */ subd_send_msg(gossip, take(towire_gossipd_get_txout_reply( - NULL, scid, AMOUNT_SAT(0), NULL))); - tal_free(scid); + NULL, &scid, AMOUNT_SAT(0), NULL))); } else { - bitcoind_getfilteredblock(topo->bitcoind, short_channel_id_blocknum(scid), got_filteredblock, scid); + /* Make a pointer of a copy of scid here, for got_filteredblock */ + bitcoind_getfilteredblock(topo->bitcoind, + short_channel_id_blocknum(&scid), + got_filteredblock, + tal_dup(gossip, struct short_channel_id, &scid)); } } diff --git a/lightningd/onchain_control.c b/lightningd/onchain_control.c index 681ba2334..21313b622 100644 --- a/lightningd/onchain_control.c +++ b/lightningd/onchain_control.c @@ -1642,13 +1642,13 @@ void onchaind_replay_channels(struct lightningd *ld) struct channel *chan; db_begin_transaction(ld->wallet->db); - onchaind_ids = wallet_onchaind_channels(ld->wallet, ld); + onchaind_ids = wallet_onchaind_channels(tmpctx, ld->wallet); for (size_t i = 0; i < tal_count(onchaind_ids); i++) { log_info(ld->log, "Restarting onchaind for channel %d", onchaind_ids[i]); - txs = wallet_channeltxs_get(ld->wallet, onchaind_ids, + txs = wallet_channeltxs_get(onchaind_ids, ld->wallet, onchaind_ids[i]); chan = channel_by_dbid(ld, onchaind_ids[i]); @@ -1674,7 +1674,6 @@ void onchaind_replay_channels(struct lightningd *ld) } tal_free(txs); } - tal_free(onchaind_ids); db_commit_transaction(ld->wallet->db); } diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 6128a9848..99d98990e 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -1156,7 +1156,7 @@ static void json_add_channel(struct lightningd *ld, json_add_num(response, "max_accepted_htlcs", channel->our_config.max_accepted_htlcs); - state_changes = wallet_state_change_get(ld->wallet, tmpctx, channel->dbid); + state_changes = wallet_state_change_get(tmpctx, ld->wallet, channel->dbid); json_array_start(response, "state_changes"); for (size_t i = 0; i < tal_count(state_changes); i++) { json_object_start(response, NULL); diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index a3bdc51b1..fc5a115e8 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -1043,8 +1043,8 @@ char *wallet_offer_find(const tal_t *ctx UNNEEDED, { fprintf(stderr, "wallet_offer_find called!\n"); abort(); } /* Generated stub for wallet_state_change_get */ -struct state_change_entry *wallet_state_change_get(struct wallet *w UNNEEDED, - const tal_t *ctx UNNEEDED, +struct state_change_entry *wallet_state_change_get(const tal_t *ctx UNNEEDED, + struct wallet *w UNNEEDED, u64 channel_id UNNEEDED) { fprintf(stderr, "wallet_state_change_get called!\n"); abort(); } /* Generated stub for wallet_total_forward_fees */ diff --git a/wallet/wallet.c b/wallet/wallet.c index 241a8d2e2..95b49d86e 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -2506,8 +2506,8 @@ void wallet_state_change_add(struct wallet *w, db_exec_prepared_v2(take(stmt)); } -struct state_change_entry *wallet_state_change_get(struct wallet *w, - const tal_t *ctx, +struct state_change_entry *wallet_state_change_get(const tal_t *ctx, + struct wallet *w, u64 channel_id) { struct db_stmt *stmt; @@ -4298,7 +4298,7 @@ void wallet_blocks_rollback(struct wallet *w, u32 height) db_exec_prepared_v2(take(stmt)); } -bool wallet_outpoint_spend(struct wallet *w, const tal_t *ctx, const u32 blockheight, +bool wallet_outpoint_spend(const tal_t *ctx, struct wallet *w, const u32 blockheight, const struct bitcoin_outpoint *outpoint) { struct db_stmt *stmt; @@ -4418,7 +4418,7 @@ bool wallet_have_block(struct wallet *w, u32 blockheight) return result; } -struct outpoint *wallet_outpoint_for_scid(struct wallet *w, tal_t *ctx, +struct outpoint *wallet_outpoint_for_scid(const tal_t *ctx, struct wallet *w, const struct short_channel_id *scid) { struct db_stmt *stmt; @@ -4713,8 +4713,7 @@ void wallet_channeltxs_add(struct wallet *w, struct channel *chan, db_exec_prepared_v2(take(stmt)); } -u32 *wallet_onchaind_channels(struct wallet *w, - const tal_t *ctx) +u32 *wallet_onchaind_channels(const tal_t *ctx, struct wallet *w) { struct db_stmt *stmt; size_t count = 0; @@ -4735,7 +4734,7 @@ u32 *wallet_onchaind_channels(struct wallet *w, return channel_ids; } -struct channeltx *wallet_channeltxs_get(struct wallet *w, const tal_t *ctx, +struct channeltx *wallet_channeltxs_get(const tal_t *ctx, struct wallet *w, u32 channel_id) { struct db_stmt *stmt; @@ -4976,8 +4975,8 @@ struct amount_msat wallet_total_forward_fees(struct wallet *w) return total; } -const struct forwarding *wallet_forwarded_payments_get(struct wallet *w, - const tal_t *ctx, +const struct forwarding *wallet_forwarded_payments_get(const tal_t *ctx, + struct wallet *w, enum forward_status status, const struct short_channel_id *chan_in, const struct short_channel_id *chan_out, @@ -5280,7 +5279,7 @@ bool wallet_forward_delete(struct wallet *w, return changed; } -struct wallet_transaction *wallet_transactions_get(struct wallet *w, const tal_t *ctx) +struct wallet_transaction *wallet_transactions_get(const tal_t *ctx, struct wallet *w) { struct db_stmt *stmt; struct wallet_transaction *txs = tal_arr(ctx, struct wallet_transaction, 0); diff --git a/wallet/wallet.h b/wallet/wallet.h index 7b3cd34ca..0d64c9cd4 100644 --- a/wallet/wallet.h +++ b/wallet/wallet.h @@ -663,8 +663,8 @@ void wallet_state_change_add(struct wallet *w, /** * Gets all state change history entries for a channel from the database */ -struct state_change_entry *wallet_state_change_get(struct wallet *w, - const tal_t *ctx, +struct state_change_entry *wallet_state_change_get(const tal_t *ctx, + struct wallet *w, u64 channel_id); /** @@ -1137,11 +1137,11 @@ bool wallet_have_block(struct wallet *w, u32 blockheight); * * @return true if found in our wallet's output set, false otherwise */ -bool wallet_outpoint_spend(struct wallet *w, const tal_t *ctx, +bool wallet_outpoint_spend(const tal_t *ctx, struct wallet *w, const u32 blockheight, const struct bitcoin_outpoint *outpoint); -struct outpoint *wallet_outpoint_for_scid(struct wallet *w, tal_t *ctx, +struct outpoint *wallet_outpoint_for_scid(const tal_t *ctx, struct wallet *w, const struct short_channel_id *scid); void wallet_utxoset_add(struct wallet *w, @@ -1220,13 +1220,12 @@ void wallet_channeltxs_add(struct wallet *w, struct channel *chan, /** * List channels for which we had an onchaind running */ -u32 *wallet_onchaind_channels(struct wallet *w, - const tal_t *ctx); +u32 *wallet_onchaind_channels(const tal_t *ctx, struct wallet *w); /** * Get transactions that we'd like to replay for a channel. */ -struct channeltx *wallet_channeltxs_get(struct wallet *w, const tal_t *ctx, +struct channeltx *wallet_channeltxs_get(const tal_t *ctx, struct wallet *w, u32 channel_id); /** @@ -1247,8 +1246,8 @@ struct amount_msat wallet_total_forward_fees(struct wallet *w); /** * Retrieve a list of all forwarded_payments */ -const struct forwarding *wallet_forwarded_payments_get(struct wallet *w, - const tal_t *ctx, +const struct forwarding *wallet_forwarded_payments_get(const tal_t *ctx, + struct wallet *w, enum forward_status state, const struct short_channel_id *chan_in, const struct short_channel_id *chan_out, @@ -1295,7 +1294,7 @@ void wallet_remote_ann_sigs_clear(struct wallet *w, const struct channel *chan); * @param wallet: Wallet to load from. * @return A tal_arr of wallet annotated transactions */ -struct wallet_transaction *wallet_transactions_get(struct wallet *w, const tal_t *ctx); +struct wallet_transaction *wallet_transactions_get(const tal_t *ctx, struct wallet *w); /** * Add a filteredblock to the blocks and utxoset tables. diff --git a/wallet/walletrpc.c b/wallet/walletrpc.c index 32d085230..561be6dab 100644 --- a/wallet/walletrpc.c +++ b/wallet/walletrpc.c @@ -560,7 +560,7 @@ static struct command_result *json_listtransactions(struct command *cmd, if (!param(cmd, buffer, params, NULL)) return command_param_failed(); - txs = wallet_transactions_get(cmd->ld->wallet, cmd); + txs = wallet_transactions_get(cmd, cmd->ld->wallet); response = json_stream_success(cmd); json_array_start(response, "transactions");