mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
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 <rusty@rustcorp.com.au>
This commit is contained in:
parent
4e102ccfcf
commit
7d4d2977b6
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user