From 7d4d2977b60d49b08c111265a61508e471aec5e9 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 4 May 2016 16:10:39 +0930 Subject: [PATCH] watch: depth callback is always >= 0 We don't report conflicts, just depths. So we report 0 if it's in a main chain which loses to another, otherwise it's always positive. Signed-off-by: Rusty Russell --- daemon/peer.c | 19 +++++++++---------- daemon/watch.c | 12 ++++++------ daemon/watch.h | 14 +++++++------- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/daemon/peer.c b/daemon/peer.c index 33c718152..ade0df1b6 100644 --- a/daemon/peer.c +++ b/daemon/peer.c @@ -659,15 +659,14 @@ struct anchor_watch { struct oneshot *timer; }; -static void anchor_depthchange(struct peer *peer, int depth, +static void anchor_depthchange(struct peer *peer, unsigned int depth, const struct sha256_double *txid, void *unused) { struct anchor_watch *w = peer->anchor.watches; /* Still waiting for it to reach depth? */ if (w->depthok != INPUT_NONE) { - /* Beware sign! */ - if (depth >= (int)peer->us.mindepth) { + if (depth >= peer->us.mindepth) { enum state_input in = w->depthok; w->depthok = INPUT_NONE; /* We don't need the timeout timer any more. */ @@ -675,7 +674,7 @@ static void anchor_depthchange(struct peer *peer, int depth, state_event(peer, in, NULL); } } else { - if (depth < 0 && w->unspent != INPUT_NONE) { + if (depth == 0 && w->unspent != INPUT_NONE) { enum state_input in = w->unspent; w->unspent = INPUT_NONE; state_event(peer, in, NULL); @@ -735,7 +734,7 @@ static bool is_mutual_close(const struct peer *peer, return false; } -static void close_depth_cb(struct peer *peer, int depth, +static void close_depth_cb(struct peer *peer, unsigned int depth, const struct sha256_double *txid, void *unused) { @@ -846,7 +845,7 @@ void peer_unwatch_anchor_depth(struct peer *peer, peer->anchor.watches = tal_free(peer->anchor.watches); } -static void commit_tx_depth(struct peer *peer, int depth, +static void commit_tx_depth(struct peer *peer, unsigned int depth, const struct sha256_double *txid, ptrint_t *canspend) { @@ -856,7 +855,7 @@ static void commit_tx_depth(struct peer *peer, int depth, /* FIXME: Handle locktime in blocks, as well as seconds! */ /* Fell out of a block? */ - if (depth <= 0) + if (depth == 0) return; mediantime = get_tx_mediantime(peer->dstate, txid); @@ -909,12 +908,12 @@ void peer_watch_delayed(struct peer *peer, watch_commit_outputs(peer, tx); } -static void spend_tx_done(struct peer *peer, int depth, +static void spend_tx_done(struct peer *peer, unsigned int depth, const struct sha256_double *txid, ptrint_t *done) { - log_debug(peer->log, "tx reached depth %i", depth); - if (depth >= (int)peer->dstate->config.forever_confirms) + log_debug(peer->log, "tx reached depth %u", depth); + if (depth >= peer->dstate->config.forever_confirms) state_event(peer, ptr2int(done), NULL); } diff --git a/daemon/watch.c b/daemon/watch.c index 7e0d3dce2..9abff89a9 100644 --- a/daemon/watch.c +++ b/daemon/watch.c @@ -83,7 +83,7 @@ static void destroy_txwatch(struct txwatch *w) struct txwatch *watch_txid_(const tal_t *ctx, struct peer *peer, const struct sha256_double *txid, - void (*cb)(struct peer *peer, int depth, + void (*cb)(struct peer *peer, unsigned int depth, const struct sha256_double *txid, void *arg), void *cb_arg) @@ -111,11 +111,11 @@ bool watching_txid(struct lightningd_state *dstate, } struct txwatch *watch_tx_(const tal_t *ctx, - struct peer *peer, - const struct bitcoin_tx *tx, - void (*cb)(struct peer *peer, int depth, - const struct sha256_double *txid, - void *arg), + struct peer *peer, + const struct bitcoin_tx *tx, + void (*cb)(struct peer *peer, unsigned int depth, + const struct sha256_double *txid, + void *arg), void *cb_arg) { struct sha256_double txid; diff --git a/daemon/watch.h b/daemon/watch.h index 51617f91d..74e9d6b72 100644 --- a/daemon/watch.h +++ b/daemon/watch.h @@ -48,10 +48,10 @@ struct txwatch { /* Transaction to watch. */ struct sha256_double txid; - int depth; + unsigned int depth; - /* A new depth (-1 if conflicted), blkhash valid if > 0 */ - void (*cb)(struct peer *peer, int depth, + /* A new depth (0 if kicked out, otherwise 1 = tip, etc.) */ + void (*cb)(struct peer *peer, unsigned int depth, const struct sha256_double *txid, void *cbdata); void *cbdata; @@ -67,7 +67,7 @@ HTABLE_DEFINE_TYPE(struct txwatch, txwatch_keyof, txid_hash, txwatch_eq, struct txwatch *watch_txid_(const tal_t *ctx, struct peer *peer, const struct sha256_double *txid, - void (*cb)(struct peer *peer, int depth, + void (*cb)(struct peer *peer, unsigned int depth, const struct sha256_double *txid, void *), void *cbdata); @@ -77,14 +77,14 @@ struct txwatch *watch_txid_(const tal_t *ctx, typesafe_cb_preargs(void, void *, \ (cb), (cbdata), \ struct peer *, \ - int depth, \ + unsigned int depth, \ const struct sha256_double *), \ (cbdata)) struct txwatch *watch_tx_(const tal_t *ctx, struct peer *peer, const struct bitcoin_tx *tx, - void (*cb)(struct peer *peer, int depth, + void (*cb)(struct peer *peer, unsigned int depth, const struct sha256_double *txid, void *), void *cbdata); @@ -94,7 +94,7 @@ struct txwatch *watch_tx_(const tal_t *ctx, typesafe_cb_preargs(void, void *, \ (cb), (cbdata), \ struct peer *, \ - int depth, \ + unsigned int depth, \ const struct sha256_double *), \ (cbdata))