Skip to content

Commit

Permalink
Use a new local scheduler instead of the global one
Browse files Browse the repository at this point in the history
  • Loading branch information
panleone committed Sep 13, 2023
1 parent 9eee614 commit 81c46c0
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,7 @@ bool AppInitMain()
// The on-disk coinsdb is now in a good state, create the cache
pcoinsTip.reset(new CCoinsViewCache(pcoinscatcher.get()));

InitTierTwoPostCoinsCacheLoad(&scheduler);
InitTierTwoPostCoinsCacheLoad();

bool is_coinsview_empty = fReset || fReindexChainState || pcoinsTip->GetBestBlock().IsNull();
if (!is_coinsview_empty) {
Expand Down
12 changes: 10 additions & 2 deletions src/llmq/quorums_chainlocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "spork.h"
#include "sporkid.h"
#include "validation.h"
#include <boost/thread/detail/thread.hpp>

namespace llmq
{
Expand All @@ -27,13 +28,19 @@ std::string CChainLockSig::ToString() const
return strprintf("CChainLockSig(nHeight=%d, blockHash=%s)", nHeight, blockHash.ToString());
}

CChainLocksHandler::CChainLocksHandler(CScheduler* _scheduler) :
scheduler(_scheduler)
CChainLocksHandler::CChainLocksHandler()
{
scheduler = new CScheduler();
CScheduler::Function serviceLoop = boost::bind(&CScheduler::serviceQueue, scheduler);
scheduler_thread = new boost::thread(boost::bind(&TraceThread<CScheduler::Function>, "chainlock-scheduler", serviceLoop));
}

CChainLocksHandler::~CChainLocksHandler()
{
scheduler_thread->interrupt();
scheduler_thread->join();
delete scheduler_thread;
delete scheduler;
}

void CChainLocksHandler::Start()
Expand All @@ -47,6 +54,7 @@ void CChainLocksHandler::Start()

void CChainLocksHandler::Stop()
{
scheduler->stop();
quorumSigningManager->UnregisterRecoveredSigsListener(this);
}

Expand Down
3 changes: 2 additions & 1 deletion src/llmq/quorums_chainlocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class CChainLocksHandler : public CRecoveredSigsListener

private:
CScheduler* scheduler;
boost::thread* scheduler_thread;
RecursiveMutex cs;
bool tryLockChainTipScheduled GUARDED_BY(cs) {false};

Expand All @@ -63,7 +64,7 @@ class CChainLocksHandler : public CRecoveredSigsListener
int64_t lastCleanupTime{0};

public:
CChainLocksHandler(CScheduler* _scheduler);
CChainLocksHandler();
~CChainLocksHandler();

void Start();
Expand Down
4 changes: 2 additions & 2 deletions src/llmq/quorums_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace llmq

CBLSWorker* blsWorker;

void InitLLMQSystem(CEvoDB& evoDb, CScheduler* scheduler, bool unitTests)
void InitLLMQSystem(CEvoDB& evoDb, bool unitTests)
{
blsWorker = new CBLSWorker();

Expand All @@ -29,7 +29,7 @@ void InitLLMQSystem(CEvoDB& evoDb, CScheduler* scheduler, bool unitTests)
quorumManager.reset(new CQuorumManager(evoDb, *blsWorker, *quorumDKGSessionManager));
quorumSigSharesManager = new CSigSharesManager();
quorumSigningManager = new CSigningManager(unitTests);
chainLocksHandler = new CChainLocksHandler(scheduler);
chainLocksHandler = new CChainLocksHandler();
}

void DestroyLLMQSystem()
Expand Down
2 changes: 1 addition & 1 deletion src/llmq/quorums_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace llmq
{

// Init/destroy LLMQ globals
void InitLLMQSystem(CEvoDB& evoDb, CScheduler* scheduler, bool unitTests);
void InitLLMQSystem(CEvoDB& evoDb, bool unitTests);
void DestroyLLMQSystem();

// Manage scheduled tasks, threads, listeners etc.
Expand Down
4 changes: 2 additions & 2 deletions src/tiertwo/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ void InitTierTwoPreChainLoad(bool fReindex)
deterministicMNManager.reset(new CDeterministicMNManager(*evoDb));
}

void InitTierTwoPostCoinsCacheLoad(CScheduler* scheduler)
void InitTierTwoPostCoinsCacheLoad()
{
// Initialize LLMQ system
llmq::InitLLMQSystem(*evoDb, scheduler, false);
llmq::InitLLMQSystem(*evoDb, false);
}

void InitTierTwoChainTip()
Expand Down
2 changes: 1 addition & 1 deletion src/tiertwo/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void ResetTierTwoInterfaces();
void InitTierTwoPreChainLoad(bool fReindex);

/** Inits the tier two global objects that require access to the coins tip cache */
void InitTierTwoPostCoinsCacheLoad(CScheduler* scheduler);
void InitTierTwoPostCoinsCacheLoad();

/** Initialize chain tip */
void InitTierTwoChainTip();
Expand Down

0 comments on commit 81c46c0

Please sign in to comment.