From dff50c3a5f2224592d135ad9cc6c11be89e26def Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 13 Sep 2016 15:23:37 +0930 Subject: [PATCH] peer: do not send anchor depth input twice. We *should* be in a state which accepts it (could happen with reorg), and there's no reason to test for greater than depth since we must process blocks in order. Signed-off-by: Rusty Russell --- daemon/peer.c | 4 ++-- state.h | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/daemon/peer.c b/daemon/peer.c index 8bc63e619..0c21fc05c 100644 --- a/daemon/peer.c +++ b/daemon/peer.c @@ -2960,8 +2960,8 @@ static enum watch_result anchor_depthchange(struct peer *peer, void *unused) { /* Still waiting for it to reach depth? */ - if (state_is_opening(peer->state)) { - if ((int)depth >= peer->anchor.ok_depth) { + if (state_is_waiting_for_anchor(peer->state)) { + if ((int)depth == peer->anchor.ok_depth) { state_event(peer, BITCOIN_ANCHOR_DEPTHOK, NULL); peer->anchor.ok_depth = -1; } diff --git a/state.h b/state.h index f7aff9d0b..80ebbdad5 100644 --- a/state.h +++ b/state.h @@ -40,6 +40,14 @@ static inline bool state_is_opening(enum state s) return s < STATE_NORMAL; } +static inline bool state_is_waiting_for_anchor(enum state s) +{ + return s == STATE_OPEN_WAITING_OURANCHOR + || s == STATE_OPEN_WAITING_OURANCHOR_THEYCOMPLETED + || s == STATE_OPEN_WAITING_THEIRANCHOR + || s == STATE_OPEN_WAITING_THEIRANCHOR_THEYCOMPLETED; +} + static inline bool state_can_io(enum state s) { if (state_is_error(s))