From 1273b842d21d00e3eb53ef6895df0b3715dd0b85 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 29 Jan 2020 15:20:11 +1030 Subject: [PATCH] lightningd: fix reorg bug where we don't fire watches. If the same memory gets reallocated, our "has the tip changed?" test gets a false negative. This happened for me about one time in 10, causing tests/test_misc.py::test_funding_reorg_remote_lags to fail. Signed-off-by: Rusty Russell --- lightningd/chaintopology.c | 7 ++++--- lightningd/chaintopology.h | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lightningd/chaintopology.c b/lightningd/chaintopology.c index 91c3cd1a1..9b5c9ff7a 100644 --- a/lightningd/chaintopology.c +++ b/lightningd/chaintopology.c @@ -585,7 +585,7 @@ void topology_add_sync_waiter_(const tal_t *ctx, /* Once we're run out of new blocks to add, call this. */ static void updates_complete(struct chain_topology *topo) { - if (topo->tip != topo->prev_tip) { + if (!bitcoin_blkid_eq(&topo->tip->blkid, &topo->prev_tip)) { /* Tell lightningd about new block. */ notify_new_block(topo->bitcoind->ld, topo->tip->height); @@ -599,7 +599,7 @@ static void updates_complete(struct chain_topology *topo) db_set_intvar(topo->bitcoind->ld->wallet->db, "last_processed_block", topo->tip->height); - topo->prev_tip = topo->tip; + topo->prev_tip = topo->tip->blkid; } /* If bitcoind is synced, we're now synced. */ @@ -785,7 +785,8 @@ static void init_topo(struct bitcoind *bitcoind UNUSED, { topo->root = new_block(topo, blk, topo->max_blockheight); block_map_add(&topo->block_map, topo->root); - topo->tip = topo->prev_tip = topo->root; + topo->tip = topo->root; + topo->prev_tip = topo->tip->blkid; /* In case we don't get all the way to updates_complete */ db_set_intvar(topo->bitcoind->ld->wallet->db, diff --git a/lightningd/chaintopology.h b/lightningd/chaintopology.h index c36286719..816c537f9 100644 --- a/lightningd/chaintopology.h +++ b/lightningd/chaintopology.h @@ -85,7 +85,8 @@ HTABLE_DEFINE_TYPE(struct block, keyof_block_map, hash_sha, block_eq, block_map) struct chain_topology { struct lightningd *ld; struct block *root; - struct block *prev_tip, *tip; + struct block *tip; + struct bitcoin_blkid prev_tip; struct block_map block_map; u32 feerate[NUM_FEERATES]; bool feerate_uninitialized;