Skip to content

Commit

Permalink
lightningd: fix reorg bug where we don't fire watches.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
rustyrussell committed Jan 29, 2020
1 parent 8eda489 commit 1273b84
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lightningd/chaintopology.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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. */
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion lightningd/chaintopology.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1273b84

Please sign in to comment.