From 9448358cfd94f3c769e05e634a53175023021927 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 18 Aug 2016 14:23:46 +0930 Subject: [PATCH] chaintopology: wait for full blockchain load before start. Caught because we generated an HTLCs which had already expired, since we didn't know the latest block. Other errors are certainly possible, so it's safest to load the entire thing before going live. Signed-off-by: Rusty Russell --- daemon/chaintopology.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/daemon/chaintopology.c b/daemon/chaintopology.c index 7ba5041d6..cc6352b7e 100644 --- a/daemon/chaintopology.c +++ b/daemon/chaintopology.c @@ -64,12 +64,17 @@ struct topology { struct block *tip; struct block_map block_map; u64 feerate; + bool startup; }; static void start_poll_chaintip(struct lightningd_state *dstate); static void next_topology_timer(struct lightningd_state *dstate) { + if (dstate->topology->startup) { + dstate->topology->startup = false; + io_break(dstate); + } new_reltimer(dstate, dstate, dstate->config.poll_time, start_poll_chaintip, dstate); } @@ -425,7 +430,6 @@ static void init_topo(struct lightningd_state *dstate, /* Now grab chaintip immediately. */ bitcoind_get_chaintip(dstate, check_chaintip, NULL); - io_break(dstate); } static void get_init_block(struct lightningd_state *dstate, @@ -487,9 +491,11 @@ void setup_topology(struct lightningd_state *dstate) dstate->topology = tal(dstate, struct topology); block_map_init(&dstate->topology->block_map); + dstate->topology->startup = true; dstate->topology->feerate = 0; bitcoind_getblockcount(dstate, get_init_blockhash, NULL); - /* Once it gets first block, it calls io_break() and we return. */ + /* Once it gets topology, it calls io_break() and we return. */ io_loop(NULL, NULL); + assert(!dstate->topology->startup); }