From 8c8aa7dba237f2d7e7ae36d6ec83a597c990a02a Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Thu, 16 Jul 2015 16:41:11 -0400 Subject: [PATCH] Wait to be able to query transactions from the mempool. --- src/bitcoindjs.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index fcf700a9..cf0bd614 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -193,13 +193,25 @@ async_blocks_ready(uv_work_t *req) { CBlockIndex* tip = chainActive.Tip(); uint256 tipHash = tip->GetBlockHash(); + // Wait to be able to query for blocks by hash while(mapBlockIndex.count(tipHash) == 0) { usleep(1E6); } + // Wait for chainActive to be able to get the hash + // for the genesis block for querying blocks by height while(chainActive[0] == NULL) { usleep(1E6); } + + // Wait until we can get a lock on cs_main + // And therefore ready to be able to quickly + // query for transactions from the mempool. + LOCK(cs_main); + { + return; + } + } static void