Skip to content

Commit

Permalink
Fix blsWorker (#2820)
Browse files Browse the repository at this point in the history
Use a pointer instead of a static variable, start/stop together with other llmq modules.
  • Loading branch information
UdjinM6 committed Apr 1, 2019
1 parent 377dd3b commit 9f04855
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
13 changes: 8 additions & 5 deletions src/bls/bls_worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,21 @@ std::pair<std::function<void(T)>, std::future<T> > BuildFutureDoneCallback2()

CBLSWorker::CBLSWorker()
{
int workerCount = std::thread::hardware_concurrency() / 2;
workerCount = std::max(std::min(1, workerCount), 4);
workerPool.resize(workerCount);

RenameThreadPool(workerPool, "bls-worker");
}

CBLSWorker::~CBLSWorker()
{
Stop();
}

void CBLSWorker::Start()
{
int workerCount = std::thread::hardware_concurrency() / 2;
workerCount = std::max(std::min(1, workerCount), 4);
workerPool.resize(workerCount);
RenameThreadPool(workerPool, "bls-worker");
}

void CBLSWorker::Stop()
{
workerPool.clear_queue();
Expand Down
1 change: 1 addition & 0 deletions src/bls/bls_worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class CBLSWorker
CBLSWorker();
~CBLSWorker();

void Start();
void Stop();

bool GenerateContributions(int threshold, const BLSIdVector& ids, BLSVerificationVectorPtr& vvecRet, BLSSecretKeyVector& skShares);
Expand Down
15 changes: 12 additions & 3 deletions src/llmq/quorums_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@
namespace llmq
{

static CBLSWorker blsWorker;
CBLSWorker* blsWorker;

CDBWrapper* llmqDb;

void InitLLMQSystem(CEvoDB& evoDb, CScheduler* scheduler, bool unitTests)
{
llmqDb = new CDBWrapper(unitTests ? "" : (GetDataDir() / "llmq"), 1 << 20, unitTests);
blsWorker = new CBLSWorker();

quorumDKGDebugManager = new CDKGDebugManager(scheduler);
quorumBlockProcessor = new CQuorumBlockProcessor(evoDb);
quorumDKGSessionManager = new CDKGSessionManager(*llmqDb, blsWorker);
quorumManager = new CQuorumManager(evoDb, blsWorker, *quorumDKGSessionManager);
quorumDKGSessionManager = new CDKGSessionManager(*llmqDb, *blsWorker);
quorumManager = new CQuorumManager(evoDb, *blsWorker, *quorumDKGSessionManager);
quorumSigSharesManager = new CSigSharesManager();
quorumSigningManager = new CSigningManager(*llmqDb, unitTests);
chainLocksHandler = new CChainLocksHandler(scheduler);
Expand All @@ -56,12 +57,17 @@ void DestroyLLMQSystem()
quorumBlockProcessor = nullptr;
delete quorumDKGDebugManager;
quorumDKGDebugManager = nullptr;
delete blsWorker;
blsWorker = nullptr;
delete llmqDb;
llmqDb = nullptr;
}

void StartLLMQSystem()
{
if (blsWorker) {
blsWorker->Start();
}
if (quorumDKGDebugManager) {
quorumDKGDebugManager->StartScheduler();
}
Expand Down Expand Up @@ -95,6 +101,9 @@ void StopLLMQSystem()
if (quorumDKGSessionManager) {
quorumDKGSessionManager->StopMessageHandlerPool();
}
if (blsWorker) {
blsWorker->Stop();
}
}

void InterruptLLMQSystem()
Expand Down

0 comments on commit 9f04855

Please sign in to comment.