Skip to content

Commit

Permalink
Revert "Rework handling of CSigSharesManager worker thread (dashpay#2703
Browse files Browse the repository at this point in the history
)"

This reverts commit bedfc26.
  • Loading branch information
UdjinM6 committed Feb 16, 2019
1 parent bedfc26 commit 130c5b6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 35 deletions.
1 change: 0 additions & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ void Interrupt(boost::thread_group& threadGroup)
InterruptRPC();
InterruptREST();
InterruptTorControl();
llmq::InterruptLLMQSystem();
if (g_connman)
g_connman->Interrupt();
threadGroup.interrupt_all();
Expand Down
9 changes: 4 additions & 5 deletions src/llmq/quorums_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@ void InitLLMQSystem(CEvoDB& evoDb, CScheduler* scheduler, bool unitTests)
quorumSigSharesManager = new CSigSharesManager();
quorumSigningManager = new CSigningManager(unitTests);
chainLocksHandler = new CChainLocksHandler(scheduler);

quorumSigSharesManager->StartWorkerThread();
}

void InterruptLLMQSystem()
void DestroyLLMQSystem()
{
if (quorumSigSharesManager) {
quorumSigSharesManager->InterruptWorkerThread();
quorumSigSharesManager->StopWorkerThread();
}
}

void DestroyLLMQSystem()
{
delete chainLocksHandler;
chainLocksHandler = nullptr;
delete quorumSigningManager;
Expand Down
1 change: 0 additions & 1 deletion src/llmq/quorums_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace llmq
static const bool DEFAULT_WATCH_QUORUMS = false;

void InitLLMQSystem(CEvoDB& evoDb, CScheduler* scheduler, bool unitTests);
void InterruptLLMQSystem();
void DestroyLLMQSystem();

}
Expand Down
34 changes: 12 additions & 22 deletions src/llmq/quorums_signing_shares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ CSigSharesInv CBatchedSigShares::ToInv() const

CSigSharesManager::CSigSharesManager()
{
StartWorkerThread();
}

CSigSharesManager::~CSigSharesManager()
Expand All @@ -186,23 +185,24 @@ CSigSharesManager::~CSigSharesManager()

void CSigSharesManager::StartWorkerThread()
{
workThread = std::thread(&TraceThread<std::function<void()> >,
"sigshares",
std::function<void()>(std::bind(&CSigSharesManager::WorkThreadMain, this)));
workThread = std::thread([this]() {
RenameThread("quorum-sigshares");
WorkThreadMain();
});
}

void CSigSharesManager::StopWorkerThread()
{
if (stopWorkThread) {
return;
}

stopWorkThread = true;
if (workThread.joinable()) {
workThread.join();
}
}

void CSigSharesManager::InterruptWorkerThread()
{
workInterrupt();
}

void CSigSharesManager::ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman)
{
// non-masternodes are not interested in sigshares
Expand Down Expand Up @@ -1096,16 +1096,8 @@ void CSigSharesManager::BanNode(NodeId nodeId)

void CSigSharesManager::WorkThreadMain()
{
workInterrupt.reset();

while (!workInterrupt) {
if (!quorumSigningManager || !g_connman || !quorumSigningManager) {
if (!workInterrupt.sleep_for(std::chrono::milliseconds(100))) {
return;
}
continue;
}

int64_t lastProcessTime = GetTimeMillis();
while (!stopWorkThread && !ShutdownRequested()) {
RemoveBannedNodeStates();
quorumSigningManager->ProcessPendingRecoveredSigs(*g_connman);
ProcessPendingSigShares(*g_connman);
Expand All @@ -1115,9 +1107,7 @@ void CSigSharesManager::WorkThreadMain()
quorumSigningManager->Cleanup();

// TODO Wakeup when pending signing is needed?
if (!workInterrupt.sleep_for(std::chrono::milliseconds(100))) {
return;
}
MilliSleep(100);
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/llmq/quorums_signing_shares.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class CSigSharesManager
CCriticalSection cs;

std::thread workThread;
CThreadInterrupt workInterrupt;
std::atomic<bool> stopWorkThread{false};

std::map<SigShareKey, CSigShare> sigShares;
std::map<uint256, int64_t> firstSeenForSessions;
Expand All @@ -214,7 +214,8 @@ class CSigSharesManager
CSigSharesManager();
~CSigSharesManager();

void InterruptWorkerThread();
void StartWorkerThread();
void StopWorkerThread();

public:
void ProcessMessage(CNode* pnode, const std::string& strCommand, CDataStream& vRecv, CConnman& connman);
Expand All @@ -223,9 +224,6 @@ class CSigSharesManager
void Sign(const CQuorumCPtr& quorum, const uint256& id, const uint256& msgHash);

private:
void StartWorkerThread();
void StopWorkerThread();

void ProcessMessageSigSharesInv(CNode* pfrom, const CSigSharesInv& inv, CConnman& connman);
void ProcessMessageGetSigShares(CNode* pfrom, const CSigSharesInv& inv, CConnman& connman);
void ProcessMessageBatchedSigShares(CNode* pfrom, const CBatchedSigShares& batchedSigShares, CConnman& connman);
Expand Down
1 change: 0 additions & 1 deletion src/test/test_dash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(cha
TestingSetup::~TestingSetup()
{
UnregisterNodeSignals(GetNodeSignals());
llmq::InterruptLLMQSystem();
threadGroup.interrupt_all();
threadGroup.join_all();
UnloadBlockIndex();
Expand Down

0 comments on commit 130c5b6

Please sign in to comment.