From 172fefeb7baddcb11160aa9d6ffa22bfbdf62324 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 26 Jun 2021 20:37:57 -0400 Subject: [PATCH] Sometimes you need to say plz --- src/net.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/net.cpp b/src/net.cpp index 218f766d3..d7833b4a0 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -51,6 +51,8 @@ using namespace hush; // This is every 2 blocks, on avg, on HUSH3 #define DUMP_ZINDEX_INTERVAL 150 +#define CHECK_PLZ_STOP_INTERVAL 120 + #if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL) #define MSG_NOSIGNAL 0 #endif @@ -92,6 +94,7 @@ namespace { }; } + // Global state variables extern uint16_t ASSETCHAINS_P2PPORT; extern char SMART_CHAIN_SYMBOL[65]; @@ -111,6 +114,8 @@ bool fAddressesInitialized = false; std::string strSubVersion; TLSManager tlsmanager = TLSManager(); +extern void StartShutdown(); + vector vNodes; CCriticalSection cs_vNodes; map mapRelay; @@ -1413,6 +1418,18 @@ void DumpZindexStats() LogPrintf("Flushed stats at height %li to zindex.dat %dms\n", zstats.Height(), GetTimeMillis() - nStart); } +void CheckIfWeShouldStop() +{ + // If the RPC interface is "stuck", such as filling up with deadlocks + // and cannot process any more requests, the only option was to kill the full node. + // This is a disk-based method where a node can realize it should stop, and which + // can help avoid extremely long rescans + if(boost::filesystem::exists(GetDataDir() / "plz_stop")) { + LogPrintf("%s: Found plz_stop file, shutting down...\n", __func__); + StartShutdown(); + } +} + void static ProcessOneShot() { string strDest; @@ -1925,6 +1942,9 @@ void static Discover(boost::thread_group& threadGroup) //extern CWallet pwalletMain; void StartNode(boost::thread_group& threadGroup, CScheduler& scheduler) { + + CheckIfWeShouldStop(); + if (fZindex) { uiInterface.InitMessage(_("Loading zindex stats...")); int64_t nStart = GetTimeMillis(); @@ -2014,6 +2034,8 @@ void StartNode(boost::thread_group& threadGroup, CScheduler& scheduler) if (fZindex) { scheduler.scheduleEvery(&DumpZindexStats, DUMP_ZINDEX_INTERVAL); } + + scheduler.scheduleEvery(&CheckIfWeShouldStop, CHECK_PLZ_STOP_INTERVAL); } bool StopNode()