Browse Source

txwatch: remove unused callback arg, hide struct definitions.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
719290a4c4
  1. 13
      lightningd/onchain_control.c
  2. 3
      lightningd/onchain_control.h
  3. 14
      lightningd/peer_control.c
  4. 89
      lightningd/watch.c
  5. 121
      lightningd/watch.h
  6. 45
      wallet/test/run-wallet.c

13
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, static enum watch_result onchain_tx_watched(struct channel *channel,
const struct bitcoin_tx *tx, const struct bitcoin_tx *tx,
unsigned int depth, unsigned int depth)
void *unused)
{ {
u8 *msg; u8 *msg;
struct bitcoin_txid txid; 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, static enum watch_result onchain_txo_watched(struct channel *channel,
const struct bitcoin_tx *tx, const struct bitcoin_tx *tx,
size_t input_num, size_t input_num,
const struct block *block, const struct block *block)
void *unused)
{ {
u8 *msg; 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. */ /* Make txwatch a parent of txo watches, so we can unwatch together. */
txw = watch_tx(channel->owner, ld->topology, channel, tx, 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++) for (size_t i = 0; i < tal_count(tx->output); i++)
watch_txo(txw, ld->topology, channel, &txid, 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) 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, enum watch_result funding_spent(struct channel *channel,
const struct bitcoin_tx *tx, const struct bitcoin_tx *tx,
size_t input_num, size_t input_num,
const struct block *block, const struct block *block)
void *unused)
{ {
u8 *msg, *scriptpubkey; u8 *msg, *scriptpubkey;
struct bitcoin_txid our_last_txid; struct bitcoin_txid our_last_txid;

3
lightningd/onchain_control.h

@ -10,7 +10,6 @@ struct block;
enum watch_result funding_spent(struct channel *channel, enum watch_result funding_spent(struct channel *channel,
const struct bitcoin_tx *tx, const struct bitcoin_tx *tx,
size_t input_num, size_t input_num,
const struct block *block, const struct block *block);
void *unused);
#endif /* LIGHTNING_LIGHTNINGD_ONCHAIN_CONTROL_H */ #endif /* LIGHTNING_LIGHTNINGD_ONCHAIN_CONTROL_H */

14
lightningd/peer_control.c

@ -479,8 +479,7 @@ send_error:
static enum watch_result funding_announce_cb(struct channel *channel, static enum watch_result funding_announce_cb(struct channel *channel,
const struct bitcoin_tx *tx, const struct bitcoin_tx *tx,
unsigned int depth, unsigned int depth)
void *unused)
{ {
if (depth < ANNOUNCE_MIN_DEPTH) { if (depth < ANNOUNCE_MIN_DEPTH) {
return KEEP_WATCHING; 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, static enum watch_result funding_lockin_cb(struct channel *channel,
const struct bitcoin_tx *tx, const struct bitcoin_tx *tx,
unsigned int depth, unsigned int depth)
void *unused)
{ {
struct bitcoin_txid txid; struct bitcoin_txid txid;
const char *txidstr; 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 * before. If we are at the right depth, call the callback
* directly, otherwise schedule a callback */ * directly, otherwise schedule a callback */
if (depth >= ANNOUNCE_MIN_DEPTH) if (depth >= ANNOUNCE_MIN_DEPTH)
funding_announce_cb(channel, tx, depth, NULL); funding_announce_cb(channel, tx, depth);
else else
watch_txid(channel, ld->topology, channel, &txid, watch_txid(channel, ld->topology, channel, &txid,
funding_announce_cb, NULL); funding_announce_cb);
return DELETE_WATCH; return DELETE_WATCH;
} }
@ -571,10 +569,10 @@ void channel_watch_funding(struct lightningd *ld, struct channel *channel)
{ {
/* FIXME: Remove arg from cb? */ /* FIXME: Remove arg from cb? */
watch_txid(channel, ld->topology, channel, 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, watch_txo(channel, ld->topology, channel,
&channel->funding_txid, channel->funding_outnum, &channel->funding_txid, channel->funding_outnum,
funding_spent, NULL); funding_spent);
} }
struct getpeers_args { struct getpeers_args {

89
lightningd/watch.c

@ -40,6 +40,39 @@
#include <lightningd/peer_control.h> #include <lightningd/peer_control.h>
#include <lightningd/watch.h> #include <lightningd/watch.h>
/* 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) const struct txwatch_output *txowatch_keyof(const struct txowatch *w)
{ {
return &w->out; return &w->out;
@ -86,15 +119,13 @@ static void destroy_txwatch(struct txwatch *w)
txwatch_hash_del(&w->topo->txwatches, w); txwatch_hash_del(&w->topo->txwatches, w);
} }
struct txwatch *watch_txid_(const tal_t *ctx, struct txwatch *watch_txid(const tal_t *ctx,
struct chain_topology *topo, struct chain_topology *topo,
struct channel *channel, struct channel *channel,
const struct bitcoin_txid *txid, const struct bitcoin_txid *txid,
enum watch_result (*cb)(struct channel *channel, enum watch_result (*cb)(struct channel *channel,
const struct bitcoin_tx *, const struct bitcoin_tx *,
unsigned int depth, unsigned int depth))
void *arg),
void *cb_arg)
{ {
struct txwatch *w; struct txwatch *w;
@ -104,7 +135,6 @@ struct txwatch *watch_txid_(const tal_t *ctx,
w->txid = *txid; w->txid = *txid;
w->channel = channel; w->channel = channel;
w->cb = cb; w->cb = cb;
w->cbdata = cb_arg;
txwatch_hash_add(&w->topo->txwatches, w); txwatch_hash_add(&w->topo->txwatches, w);
tal_add_destructor(w, destroy_txwatch); 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; return txwatch_hash_get(&topo->txwatches, txid) != NULL;
} }
struct txwatch *watch_tx_(const tal_t *ctx, struct txwatch *watch_tx(const tal_t *ctx,
struct chain_topology *topo, struct chain_topology *topo,
struct channel *channel, struct channel *channel,
const struct bitcoin_tx *tx, const struct bitcoin_tx *tx,
enum watch_result (*cb)(struct channel *channel, enum watch_result (*cb)(struct channel *channel,
const struct bitcoin_tx *, const struct bitcoin_tx *,
unsigned int depth, unsigned int depth))
void *arg),
void *cb_arg)
{ {
struct bitcoin_txid txid; struct bitcoin_txid txid;
bitcoin_txid(tx, &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 txowatch *watch_txo(const tal_t *ctx,
struct chain_topology *topo, struct chain_topology *topo,
struct channel *channel, struct channel *channel,
const struct bitcoin_txid *txid, const struct bitcoin_txid *txid,
unsigned int output, unsigned int output,
enum watch_result (*cb)(struct channel *channel, enum watch_result (*cb)(struct channel *channel,
const struct bitcoin_tx *tx, const struct bitcoin_tx *tx,
size_t input_num, size_t input_num,
const struct block *block, const struct block *block))
void *),
void *cbdata)
{ {
struct txowatch *w = tal(ctx, struct txowatch); struct txowatch *w = tal(ctx, struct txowatch);
@ -171,7 +197,6 @@ struct txowatch *watch_txo_(const tal_t *ctx,
w->out.index = output; w->out.index = output;
w->channel = channel; w->channel = channel;
w->cb = cb; w->cb = cb;
w->cbdata = cbdata;
txowatch_hash_add(&w->topo->txowatches, w); txowatch_hash_add(&w->topo->txowatches, w);
tal_add_destructor(w, destroy_txowatch); tal_add_destructor(w, destroy_txowatch);
@ -194,7 +219,7 @@ static bool txw_fire(struct chain_topology *topo,
txw->depth, depth, txw->depth, depth,
type_to_string(ltmp, struct bitcoin_txid, &txw->txid)); type_to_string(ltmp, struct bitcoin_txid, &txw->txid));
txw->depth = depth; txw->depth = depth;
r = txw->cb(txw->channel, tx, txw->depth, txw->cbdata); r = txw->cb(txw->channel, tx, txw->depth);
switch (r) { switch (r) {
case DELETE_WATCH: case DELETE_WATCH:
tal_free(txw); tal_free(txw);
@ -235,7 +260,7 @@ void txowatch_fire(struct chain_topology *topo,
txow->out.index, txow->out.index,
type_to_string(ltmp, struct bitcoin_txid, &txid)); 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) { switch (r) {
case DELETE_WATCH: case DELETE_WATCH:
tal_free(txow); tal_free(txow);

121
lightningd/watch.h

@ -10,6 +10,10 @@
struct bitcoin_tx; struct bitcoin_tx;
struct block; struct block;
struct channel;
struct chain_topology;
struct txowatch;
struct txwatch;
enum watch_result { enum watch_result {
DELETE_WATCH = -1, DELETE_WATCH = -1,
@ -21,26 +25,6 @@ struct txwatch_output {
unsigned int index; 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); const struct txwatch_output *txowatch_keyof(const struct txowatch *w);
size_t txo_hash(const struct txwatch_output *out); size_t txo_hash(const struct txwatch_output *out);
bool txowatch_eq(const struct txowatch *w, 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, HTABLE_DEFINE_TYPE(struct txowatch, txowatch_keyof, txo_hash, txowatch_eq,
txowatch_hash); 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); const struct bitcoin_txid *txwatch_keyof(const struct txwatch *w);
size_t txid_hash(const struct bitcoin_txid *txid); size_t txid_hash(const struct bitcoin_txid *txid);
bool txwatch_eq(const struct txwatch *w, 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); txwatch_hash);
struct txwatch *watch_txid_(const tal_t *ctx, struct txwatch *watch_txid(const tal_t *ctx,
struct chain_topology *topo, struct chain_topology *topo,
struct channel *channel, struct channel *channel,
const struct bitcoin_txid *txid, const struct bitcoin_txid *txid,
enum watch_result (*cb)(struct channel *channel, enum watch_result (*cb)(struct channel *channel,
const struct bitcoin_tx *, const struct bitcoin_tx *,
unsigned int depth, unsigned int depth));
void *),
void *cbdata);
#define watch_txid(ctx, topo, channel_, txid, cb, cbdata) \ struct txwatch *watch_tx(const tal_t *ctx,
watch_txid_((ctx), (topo), (channel_), (txid), \ struct chain_topology *topo,
typesafe_cb_preargs(enum watch_result, void *, \ struct channel *channel,
(cb), (cbdata), \ const struct bitcoin_tx *tx,
struct channel *, \ enum watch_result (*cb)(struct channel *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,
const struct bitcoin_tx *, const struct bitcoin_tx *,
unsigned int depth, unsigned int depth));
void *),
void *cbdata); struct txowatch *watch_txo(const tal_t *ctx,
struct chain_topology *topo,
#define watch_tx(ctx, topo, channel_, tx, cb, cbdata) \ struct channel *channel,
watch_tx_((ctx), (topo), (channel_), (tx), \ const struct bitcoin_txid *txid,
typesafe_cb_preargs(enum watch_result, void *, \ unsigned int output,
(cb), (cbdata), \ enum watch_result (*cb)(struct channel *channel,
struct channel *, \ const struct bitcoin_tx *tx,
const struct bitcoin_tx *, \ size_t input_num,
unsigned int depth), \ const struct block *block));
(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))
struct txwatch *find_txwatch(struct chain_topology *topo, struct txwatch *find_txwatch(struct chain_topology *topo,
const struct bitcoin_txid *txid, const struct bitcoin_txid *txid,

45
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, enum watch_result funding_spent(struct channel *channel UNNEEDED,
const struct bitcoin_tx *tx UNNEEDED, const struct bitcoin_tx *tx UNNEEDED,
size_t input_num UNNEEDED, size_t input_num UNNEEDED,
const struct block *block UNNEEDED, const struct block *block UNNEEDED)
void *unused UNNEEDED)
{ fprintf(stderr, "funding_spent called!\n"); abort(); } { fprintf(stderr, "funding_spent called!\n"); abort(); }
/* Generated stub for get_feerate */ /* Generated stub for get_feerate */
u32 get_feerate(const struct chain_topology *topo UNNEEDED, enum feerate feerate UNNEEDED) 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 */ /* Generated stub for unsupported_features */
bool unsupported_features(const u8 *gfeatures UNNEEDED, const u8 *lfeatures UNNEEDED) bool unsupported_features(const u8 *gfeatures UNNEEDED, const u8 *lfeatures UNNEEDED)
{ fprintf(stderr, "unsupported_features called!\n"); abort(); } { fprintf(stderr, "unsupported_features called!\n"); abort(); }
/* Generated stub for watch_txid_ */ /* Generated stub for watch_txid */
struct txwatch *watch_txid_(const tal_t *ctx UNNEEDED, struct txwatch *watch_txid(const tal_t *ctx UNNEEDED,
struct chain_topology *topo UNNEEDED, struct chain_topology *topo UNNEEDED,
struct channel *channel UNNEEDED, struct channel *channel UNNEEDED,
const struct bitcoin_txid *txid UNNEEDED, const struct bitcoin_txid *txid UNNEEDED,
enum watch_result (*cb)(struct channel *channel UNNEEDED, enum watch_result (*cb)(struct channel *channel UNNEEDED,
const struct bitcoin_tx * UNNEEDED, const struct bitcoin_tx * UNNEEDED,
unsigned int depth UNNEEDED, unsigned int depth))
void *) UNNEEDED, { fprintf(stderr, "watch_txid called!\n"); abort(); }
void *cbdata UNNEEDED) /* Generated stub for watch_txo */
{ fprintf(stderr, "watch_txid_ called!\n"); abort(); } struct txowatch *watch_txo(const tal_t *ctx UNNEEDED,
/* Generated stub for watch_txo_ */ struct chain_topology *topo UNNEEDED,
struct txowatch *watch_txo_(const tal_t *ctx UNNEEDED, struct channel *channel UNNEEDED,
struct chain_topology *topo UNNEEDED, const struct bitcoin_txid *txid UNNEEDED,
struct channel *channel UNNEEDED, unsigned int output UNNEEDED,
const struct bitcoin_txid *txid UNNEEDED, enum watch_result (*cb)(struct channel *channel UNNEEDED,
unsigned int output UNNEEDED, const struct bitcoin_tx *tx UNNEEDED,
enum watch_result (*cb)(struct channel *channel UNNEEDED, size_t input_num UNNEEDED,
const struct bitcoin_tx *tx UNNEEDED, const struct block *block))
size_t input_num UNNEEDED, { fprintf(stderr, "watch_txo called!\n"); abort(); }
const struct block *block UNNEEDED,
void *) UNNEEDED,
void *cbdata UNNEEDED)
{ fprintf(stderr, "watch_txo_ called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */ /* AUTOGENERATED MOCKS END */
#if DEVELOPER #if DEVELOPER

Loading…
Cancel
Save