From 719290a4c493f6a9b60eaa31313d975c0eacffbd Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 21 Feb 2018 07:29:09 +1030 Subject: [PATCH] txwatch: remove unused callback arg, hide struct definitions. Signed-off-by: Rusty Russell --- lightningd/onchain_control.c | 13 ++-- lightningd/onchain_control.h | 3 +- lightningd/peer_control.c | 14 ++-- lightningd/watch.c | 89 +++++++++++++++++--------- lightningd/watch.h | 121 ++++++++--------------------------- wallet/test/run-wallet.c | 45 ++++++------- 6 files changed, 115 insertions(+), 170 deletions(-) diff --git a/lightningd/onchain_control.c b/lightningd/onchain_control.c index eec615203..61e308380 100644 --- a/lightningd/onchain_control.c +++ b/lightningd/onchain_control.c @@ -70,8 +70,7 @@ static void handle_onchain_init_reply(struct channel *channel, const u8 *msg) static enum watch_result onchain_tx_watched(struct channel *channel, const struct bitcoin_tx *tx, - unsigned int depth, - void *unused) + unsigned int depth) { u8 *msg; struct bitcoin_txid txid; @@ -100,8 +99,7 @@ static void watch_tx_and_outputs(struct channel *channel, static enum watch_result onchain_txo_watched(struct channel *channel, const struct bitcoin_tx *tx, size_t input_num, - const struct block *block, - void *unused) + const struct block *block) { u8 *msg; @@ -128,11 +126,11 @@ static void watch_tx_and_outputs(struct channel *channel, /* Make txwatch a parent of txo watches, so we can unwatch together. */ txw = watch_tx(channel->owner, ld->topology, channel, tx, - onchain_tx_watched, NULL); + onchain_tx_watched); for (size_t i = 0; i < tal_count(tx->output); i++) watch_txo(txw, ld->topology, channel, &txid, i, - onchain_txo_watched, NULL); + onchain_txo_watched); } static void handle_onchain_broadcast_tx(struct channel *channel, const u8 *msg) @@ -352,8 +350,7 @@ static void onchain_error(struct channel *channel, enum watch_result funding_spent(struct channel *channel, const struct bitcoin_tx *tx, size_t input_num, - const struct block *block, - void *unused) + const struct block *block) { u8 *msg, *scriptpubkey; struct bitcoin_txid our_last_txid; diff --git a/lightningd/onchain_control.h b/lightningd/onchain_control.h index f1611c3a5..8b1b20bca 100644 --- a/lightningd/onchain_control.h +++ b/lightningd/onchain_control.h @@ -10,7 +10,6 @@ struct block; enum watch_result funding_spent(struct channel *channel, const struct bitcoin_tx *tx, size_t input_num, - const struct block *block, - void *unused); + const struct block *block); #endif /* LIGHTNING_LIGHTNINGD_ONCHAIN_CONTROL_H */ diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 64ef00707..c969489ad 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -479,8 +479,7 @@ send_error: static enum watch_result funding_announce_cb(struct channel *channel, const struct bitcoin_tx *tx, - unsigned int depth, - void *unused) + unsigned int depth) { if (depth < ANNOUNCE_MIN_DEPTH) { return KEEP_WATCHING; @@ -502,8 +501,7 @@ static enum watch_result funding_announce_cb(struct channel *channel, static enum watch_result funding_lockin_cb(struct channel *channel, const struct bitcoin_tx *tx, - unsigned int depth, - void *unused) + unsigned int depth) { struct bitcoin_txid txid; const char *txidstr; @@ -560,10 +558,10 @@ static enum watch_result funding_lockin_cb(struct channel *channel, * before. If we are at the right depth, call the callback * directly, otherwise schedule a callback */ if (depth >= ANNOUNCE_MIN_DEPTH) - funding_announce_cb(channel, tx, depth, NULL); + funding_announce_cb(channel, tx, depth); else watch_txid(channel, ld->topology, channel, &txid, - funding_announce_cb, NULL); + funding_announce_cb); return DELETE_WATCH; } @@ -571,10 +569,10 @@ void channel_watch_funding(struct lightningd *ld, struct channel *channel) { /* FIXME: Remove arg from cb? */ watch_txid(channel, ld->topology, channel, - &channel->funding_txid, funding_lockin_cb, NULL); + &channel->funding_txid, funding_lockin_cb); watch_txo(channel, ld->topology, channel, &channel->funding_txid, channel->funding_outnum, - funding_spent, NULL); + funding_spent); } struct getpeers_args { diff --git a/lightningd/watch.c b/lightningd/watch.c index 4d5303e19..ed7dff774 100644 --- a/lightningd/watch.c +++ b/lightningd/watch.c @@ -40,6 +40,39 @@ #include #include +/* Watching an output */ +struct txowatch { + struct chain_topology *topo; + + /* Channel who owns us. */ + struct channel *channel; + + /* Output to watch. */ + struct txwatch_output out; + + /* A new tx. */ + enum watch_result (*cb)(struct channel *channel, + const struct bitcoin_tx *tx, + size_t input_num, + const struct block *block); +}; + +struct txwatch { + struct chain_topology *topo; + + /* Channel who owns us. */ + struct channel *channel; + + /* Transaction to watch. */ + struct bitcoin_txid txid; + unsigned int depth; + + /* A new depth (0 if kicked out, otherwise 1 = tip, etc.) */ + enum watch_result (*cb)(struct channel *channel, + const struct bitcoin_tx *tx, + unsigned int depth); +}; + const struct txwatch_output *txowatch_keyof(const struct txowatch *w) { return &w->out; @@ -86,15 +119,13 @@ static void destroy_txwatch(struct txwatch *w) txwatch_hash_del(&w->topo->txwatches, w); } -struct txwatch *watch_txid_(const tal_t *ctx, - struct chain_topology *topo, - struct channel *channel, - const struct bitcoin_txid *txid, - enum watch_result (*cb)(struct channel *channel, +struct txwatch *watch_txid(const tal_t *ctx, + struct chain_topology *topo, + struct channel *channel, + const struct bitcoin_txid *txid, + enum watch_result (*cb)(struct channel *channel, const struct bitcoin_tx *, - unsigned int depth, - void *arg), - void *cb_arg) + unsigned int depth)) { struct txwatch *w; @@ -104,7 +135,6 @@ struct txwatch *watch_txid_(const tal_t *ctx, w->txid = *txid; w->channel = channel; w->cb = cb; - w->cbdata = cb_arg; txwatch_hash_add(&w->topo->txwatches, w); tal_add_destructor(w, destroy_txwatch); @@ -136,33 +166,29 @@ bool watching_txid(const struct chain_topology *topo, return txwatch_hash_get(&topo->txwatches, txid) != NULL; } -struct txwatch *watch_tx_(const tal_t *ctx, - struct chain_topology *topo, - struct channel *channel, - const struct bitcoin_tx *tx, - enum watch_result (*cb)(struct channel *channel, +struct txwatch *watch_tx(const tal_t *ctx, + struct chain_topology *topo, + struct channel *channel, + const struct bitcoin_tx *tx, + enum watch_result (*cb)(struct channel *channel, const struct bitcoin_tx *, - unsigned int depth, - void *arg), - void *cb_arg) + unsigned int depth)) { struct bitcoin_txid txid; bitcoin_txid(tx, &txid); - return watch_txid(ctx, topo, channel, &txid, cb, cb_arg); + return watch_txid(ctx, topo, channel, &txid, cb); } -struct txowatch *watch_txo_(const tal_t *ctx, - struct chain_topology *topo, - struct channel *channel, - const struct bitcoin_txid *txid, - unsigned int output, - enum watch_result (*cb)(struct channel *channel, - const struct bitcoin_tx *tx, - size_t input_num, - const struct block *block, - void *), - void *cbdata) +struct txowatch *watch_txo(const tal_t *ctx, + struct chain_topology *topo, + struct channel *channel, + const struct bitcoin_txid *txid, + unsigned int output, + enum watch_result (*cb)(struct channel *channel, + const struct bitcoin_tx *tx, + size_t input_num, + const struct block *block)) { struct txowatch *w = tal(ctx, struct txowatch); @@ -171,7 +197,6 @@ struct txowatch *watch_txo_(const tal_t *ctx, w->out.index = output; w->channel = channel; w->cb = cb; - w->cbdata = cbdata; txowatch_hash_add(&w->topo->txowatches, w); tal_add_destructor(w, destroy_txowatch); @@ -194,7 +219,7 @@ static bool txw_fire(struct chain_topology *topo, txw->depth, depth, type_to_string(ltmp, struct bitcoin_txid, &txw->txid)); txw->depth = depth; - r = txw->cb(txw->channel, tx, txw->depth, txw->cbdata); + r = txw->cb(txw->channel, tx, txw->depth); switch (r) { case DELETE_WATCH: tal_free(txw); @@ -235,7 +260,7 @@ void txowatch_fire(struct chain_topology *topo, txow->out.index, type_to_string(ltmp, struct bitcoin_txid, &txid)); - r = txow->cb(txow->channel, tx, input_num, block, txow->cbdata); + r = txow->cb(txow->channel, tx, input_num, block); switch (r) { case DELETE_WATCH: tal_free(txow); diff --git a/lightningd/watch.h b/lightningd/watch.h index 80a1c790b..90238eecf 100644 --- a/lightningd/watch.h +++ b/lightningd/watch.h @@ -10,6 +10,10 @@ struct bitcoin_tx; struct block; +struct channel; +struct chain_topology; +struct txowatch; +struct txwatch; enum watch_result { DELETE_WATCH = -1, @@ -21,26 +25,6 @@ struct txwatch_output { unsigned int index; }; -/* Watching an output */ -struct txowatch { - struct chain_topology *topo; - - /* Channel who owns us. */ - struct channel *channel; - - /* Output to watch. */ - struct txwatch_output out; - - /* A new tx. */ - enum watch_result (*cb)(struct channel *channel, - const struct bitcoin_tx *tx, - size_t input_num, - const struct block *block, - void *cbdata); - - void *cbdata; -}; - const struct txwatch_output *txowatch_keyof(const struct txowatch *w); size_t txo_hash(const struct txwatch_output *out); bool txowatch_eq(const struct txowatch *w, const struct txwatch_output *out); @@ -48,25 +32,6 @@ bool txowatch_eq(const struct txowatch *w, const struct txwatch_output *out); HTABLE_DEFINE_TYPE(struct txowatch, txowatch_keyof, txo_hash, txowatch_eq, txowatch_hash); -struct txwatch { - struct chain_topology *topo; - - /* Channel who owns us. */ - struct channel *channel; - - /* Transaction to watch. */ - struct bitcoin_txid txid; - unsigned int depth; - - /* A new depth (0 if kicked out, otherwise 1 = tip, etc.) */ - enum watch_result (*cb)(struct channel *channel, - const struct bitcoin_tx *tx, - unsigned int depth, - void *cbdata); - - void *cbdata; -}; - const struct bitcoin_txid *txwatch_keyof(const struct txwatch *w); size_t txid_hash(const struct bitcoin_txid *txid); bool txwatch_eq(const struct txwatch *w, const struct bitcoin_txid *txid); @@ -74,65 +39,31 @@ HTABLE_DEFINE_TYPE(struct txwatch, txwatch_keyof, txid_hash, txwatch_eq, txwatch_hash); -struct txwatch *watch_txid_(const tal_t *ctx, - struct chain_topology *topo, - struct channel *channel, - const struct bitcoin_txid *txid, - enum watch_result (*cb)(struct channel *channel, +struct txwatch *watch_txid(const tal_t *ctx, + struct chain_topology *topo, + struct channel *channel, + const struct bitcoin_txid *txid, + enum watch_result (*cb)(struct channel *channel, const struct bitcoin_tx *, - unsigned int depth, - void *), - void *cbdata); + unsigned int depth)); -#define watch_txid(ctx, topo, channel_, txid, cb, cbdata) \ - watch_txid_((ctx), (topo), (channel_), (txid), \ - typesafe_cb_preargs(enum watch_result, void *, \ - (cb), (cbdata), \ - struct channel *, \ - const struct bitcoin_tx *, \ - unsigned int depth), \ - (cbdata)) - -struct txwatch *watch_tx_(const tal_t *ctx, - struct chain_topology *topo, - struct channel *channel, - const struct bitcoin_tx *tx, - enum watch_result (*cb)(struct channel *channel, +struct txwatch *watch_tx(const tal_t *ctx, + struct chain_topology *topo, + struct channel *channel, + const struct bitcoin_tx *tx, + enum watch_result (*cb)(struct channel *channel, const struct bitcoin_tx *, - unsigned int depth, - void *), - void *cbdata); - -#define watch_tx(ctx, topo, channel_, tx, cb, cbdata) \ - watch_tx_((ctx), (topo), (channel_), (tx), \ - typesafe_cb_preargs(enum watch_result, void *, \ - (cb), (cbdata), \ - struct channel *, \ - const struct bitcoin_tx *, \ - unsigned int depth), \ - (cbdata)) - -struct txowatch *watch_txo_(const tal_t *ctx, - struct chain_topology *topo, - struct channel *channel, - const struct bitcoin_txid *txid, - unsigned int output, - enum watch_result (*cb)(struct channel *channel, - const struct bitcoin_tx *tx, - size_t input_num, - const struct block *block, - void *), - void *cbdata); - -#define watch_txo(ctx, topo, channel_, txid, outnum, cb, cbdata) \ - watch_txo_((ctx), (topo), (channel_), (txid), (outnum), \ - typesafe_cb_preargs(enum watch_result, void *, \ - (cb), (cbdata), \ - struct channel *, \ - const struct bitcoin_tx *, \ - size_t, \ - const struct block *block), \ - (cbdata)) + unsigned int depth)); + +struct txowatch *watch_txo(const tal_t *ctx, + struct chain_topology *topo, + struct channel *channel, + const struct bitcoin_txid *txid, + unsigned int output, + enum watch_result (*cb)(struct channel *channel, + const struct bitcoin_tx *tx, + size_t input_num, + const struct block *block)); struct txwatch *find_txwatch(struct chain_topology *topo, const struct bitcoin_txid *txid, diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index b64eced7c..856a62633 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -83,8 +83,7 @@ bool fromwire_gossip_peer_connected(const tal_t *ctx UNNEEDED, const void *p UNN enum watch_result funding_spent(struct channel *channel UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, size_t input_num UNNEEDED, - const struct block *block UNNEEDED, - void *unused UNNEEDED) + const struct block *block UNNEEDED) { fprintf(stderr, "funding_spent called!\n"); abort(); } /* Generated stub for get_feerate */ u32 get_feerate(const struct chain_topology *topo UNNEEDED, enum feerate feerate UNNEEDED) @@ -328,30 +327,26 @@ void txfilter_add_scriptpubkey(struct txfilter *filter UNNEEDED, u8 *script UNNE /* Generated stub for unsupported_features */ bool unsupported_features(const u8 *gfeatures UNNEEDED, const u8 *lfeatures UNNEEDED) { fprintf(stderr, "unsupported_features called!\n"); abort(); } -/* Generated stub for watch_txid_ */ -struct txwatch *watch_txid_(const tal_t *ctx UNNEEDED, - struct chain_topology *topo UNNEEDED, - struct channel *channel UNNEEDED, - const struct bitcoin_txid *txid UNNEEDED, - enum watch_result (*cb)(struct channel *channel UNNEEDED, +/* Generated stub for watch_txid */ +struct txwatch *watch_txid(const tal_t *ctx UNNEEDED, + struct chain_topology *topo UNNEEDED, + struct channel *channel UNNEEDED, + const struct bitcoin_txid *txid UNNEEDED, + enum watch_result (*cb)(struct channel *channel UNNEEDED, const struct bitcoin_tx * UNNEEDED, - unsigned int depth UNNEEDED, - void *) UNNEEDED, - void *cbdata UNNEEDED) -{ fprintf(stderr, "watch_txid_ called!\n"); abort(); } -/* Generated stub for watch_txo_ */ -struct txowatch *watch_txo_(const tal_t *ctx UNNEEDED, - struct chain_topology *topo UNNEEDED, - struct channel *channel UNNEEDED, - const struct bitcoin_txid *txid UNNEEDED, - unsigned int output UNNEEDED, - enum watch_result (*cb)(struct channel *channel UNNEEDED, - const struct bitcoin_tx *tx UNNEEDED, - size_t input_num UNNEEDED, - const struct block *block UNNEEDED, - void *) UNNEEDED, - void *cbdata UNNEEDED) -{ fprintf(stderr, "watch_txo_ called!\n"); abort(); } + unsigned int depth)) +{ fprintf(stderr, "watch_txid called!\n"); abort(); } +/* Generated stub for watch_txo */ +struct txowatch *watch_txo(const tal_t *ctx UNNEEDED, + struct chain_topology *topo UNNEEDED, + struct channel *channel UNNEEDED, + const struct bitcoin_txid *txid UNNEEDED, + unsigned int output UNNEEDED, + enum watch_result (*cb)(struct channel *channel UNNEEDED, + const struct bitcoin_tx *tx UNNEEDED, + size_t input_num UNNEEDED, + const struct block *block)) +{ fprintf(stderr, "watch_txo called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ #if DEVELOPER