From 2248739dd55f6fdb4d98463cd7e7d2ca6e081863 Mon Sep 17 00:00:00 2001
From: SChernykh <sergey.v.chernykh@gmail.com>
Date: Wed, 13 Sep 2023 21:12:01 +0200
Subject: [PATCH] Don't update api when shutting down

---
 src/miner.cpp          |  2 +-
 src/p2p_server.cpp     |  2 +-
 src/p2pool.cpp         | 10 +++++-----
 src/stratum_server.cpp |  2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/miner.cpp b/src/miner.cpp
index 5487351..50fcc32 100644
--- a/src/miner.cpp
+++ b/src/miner.cpp
@@ -119,7 +119,7 @@ void Miner::on_block(const BlockTemplate& block)
 	m_nonceTimestamp = cur_ts;
 	m_totalHashes += hash_count;
 
-	if (m_pool->api() && m_pool->params().m_localStats) {
+	if (m_pool->api() && m_pool->params().m_localStats && !m_pool->stopped()) {
 		const double block_reward_share_percent = m_pool->side_chain().get_reward_share(m_pool->params().m_wallet) * 100.0;
 
 		m_pool->api()->set(p2pool_api::Category::LOCAL, "miner",
diff --git a/src/p2p_server.cpp b/src/p2p_server.cpp
index bd6079a..60706c9 100644
--- a/src/p2p_server.cpp
+++ b/src/p2p_server.cpp
@@ -1305,7 +1305,7 @@ void P2PServer::on_shutdown()
 
 void P2PServer::api_update_local_stats()
 {
-	if (!m_pool->api() || !m_pool->params().m_localStats || ((m_timerCounter % 30) != 5)) {
+	if (!m_pool->api() || !m_pool->params().m_localStats || m_pool->stopped() || ((m_timerCounter % 30) != 5)) {
 		return;
 	}
 
diff --git a/src/p2pool.cpp b/src/p2pool.cpp
index 84a591f..0a02279 100644
--- a/src/p2pool.cpp
+++ b/src/p2pool.cpp
@@ -925,7 +925,7 @@ void p2pool::get_info()
 
 void p2pool::load_found_blocks()
 {
-	if (!m_api) {
+	if (!m_api || m_stopped) {
 		return;
 	}
 
@@ -1277,7 +1277,7 @@ uint32_t p2pool::parse_block_headers_range(const char* data, size_t size)
 
 void p2pool::api_update_network_stats()
 {
-	if (!m_api) {
+	if (!m_api || m_stopped) {
 		return;
 	}
 
@@ -1308,7 +1308,7 @@ void p2pool::api_update_network_stats()
 
 void p2pool::api_update_pool_stats()
 {
-	if (!m_api) {
+	if (!m_api || m_stopped) {
 		return;
 	}
 
@@ -1360,7 +1360,7 @@ void p2pool::api_update_pool_stats()
 
 void p2pool::api_update_stats_mod()
 {
-	if (!m_api) {
+	if (!m_api || m_stopped) {
 		return;
 	}
 
@@ -1453,7 +1453,7 @@ void p2pool::cleanup_mainchain_data(uint64_t height)
 
 void p2pool::api_update_block_found(const ChainMain* data, const PoolBlock* block)
 {
-	if (!m_api) {
+	if (!m_api || m_stopped) {
 		return;
 	}
 
diff --git a/src/stratum_server.cpp b/src/stratum_server.cpp
index 86911e0..97c51c5 100644
--- a/src/stratum_server.cpp
+++ b/src/stratum_server.cpp
@@ -1274,7 +1274,7 @@ bool StratumServer::StratumClient::process_submit(rapidjson::Document& doc, uint
 
 void StratumServer::api_update_local_stats(uint64_t timestamp)
 {
-	if (!m_pool->api() || !m_pool->params().m_localStats) {
+	if (!m_pool->api() || !m_pool->params().m_localStats || m_pool->stopped()) {
 		return;
 	}