From 7bab1fd3ef32a4f1efa8d611a420b476c30fc9f7 Mon Sep 17 00:00:00 2001 From: Andrew Toth Date: Sun, 6 Oct 2024 13:47:32 -0400 Subject: [PATCH] Don't sync mempool when not yet loaded --- src/daemon.rs | 6 ++++++ src/mempool.rs | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/daemon.rs b/src/daemon.rs index c0207b4..6270801 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -219,6 +219,12 @@ impl Daemon { .tx) } + pub(crate) fn get_mempool_info(&self) -> Result { + self.rpc + .get_mempool_info() + .context("failed to get mempool info") + } + pub(crate) fn get_mempool_txids(&self) -> Result> { self.rpc .get_raw_mempool() diff --git a/src/mempool.rs b/src/mempool.rs index 2612f23..8522ce6 100644 --- a/src/mempool.rs +++ b/src/mempool.rs @@ -211,6 +211,18 @@ impl Mempool { } pub fn sync(&mut self, daemon: &Daemon, exit_flag: &ExitFlag) { + let loaded = match daemon.get_mempool_info() { + Ok(info) => info.loaded.unwrap_or(true), + Err(e) => { + warn!("mempool sync failed: {}", e); + return; + } + }; + if !loaded { + warn!("mempool not loaded"); + return; + } + let old_txids = HashSet::::from_iter(self.entries.keys().copied()); let poll_result = MempoolSyncUpdate::poll(daemon, old_txids, exit_flag);