From 8a1c81021a1cf579193d9ebe3fdcfc1bcb56c0ff Mon Sep 17 00:00:00 2001 From: Janito Vaqueiro Ferreira Filho Date: Thu, 26 Aug 2021 00:29:24 +0000 Subject: [PATCH] Pause crawler if mempool is disabled Implement waiting until the mempool becomes enabled, so that the crawler does not run while the mempool is disabled. If the `MempoolStatus` helper is unable to determine if the mempool is enabled, stop the crawler task entirely. --- zebrad/src/components/mempool/crawler.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/zebrad/src/components/mempool/crawler.rs b/zebrad/src/components/mempool/crawler.rs index e924d6382df..bb53da4c667 100644 --- a/zebrad/src/components/mempool/crawler.rs +++ b/zebrad/src/components/mempool/crawler.rs @@ -52,17 +52,16 @@ where } /// Periodically crawl peers for transactions to include in the mempool. - pub async fn run(self) -> Result<(), BoxError> { - loop { - self.wait_until_enabled().await; + /// + /// Runs until the [`SyncStatus`] loses its connection to the chain syncer, which happens when + /// Zebra is shutting down. + pub async fn run(mut self) -> Result<(), BoxError> { + while self.status.wait_until_close_to_tip().await.is_ok() { self.crawl_transactions().await?; sleep(RATE_LIMIT_DELAY).await; } - } - /// Wait until the mempool is enabled. - async fn wait_until_enabled(&self) { - // TODO: Check if synchronizing up to chain tip has finished (#2603). + Ok(()) } /// Crawl peers for transactions.