-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #607 from skalenetwork/bug/SKALE-5039-oracle-reque…
…st-stuck bug/SKALE-5039
- Loading branch information
Showing
8 changed files
with
272 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
Copyright (C) 2018-2019 SKALE Labs | ||
This file is part of skale-consensus. | ||
skale-consensus is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published | ||
by the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
skale-consensus is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with skale-consensus. If not, see <https://www.gnu.org/licenses/>. | ||
@file SchainMessageThreadPool.cpp | ||
@author Stan Kladko | ||
@date 2018 | ||
*/ | ||
|
||
#include "SkaleCommon.h" | ||
#include "Log.h" | ||
|
||
#include "chains/Schain.h" | ||
#include "blockproposal/pusher/BlockProposalClientAgent.h" | ||
#include "db/BlockProposalDB.h" | ||
#include "pendingqueue/PendingTransactionsAgent.h" | ||
|
||
#include "OracleResultAssemblyAgent.h" | ||
#include "OracleMessageThreadPool.h" | ||
|
||
OracleMessageThreadPool::OracleMessageThreadPool(Agent *_agent) : WorkerThreadPool(NUM_SCHAIN_THREADS, _agent, false) { | ||
|
||
} | ||
|
||
void OracleMessageThreadPool::createThread(uint64_t /*_threadNumber*/) { | ||
LOCK(threadPoolLock) | ||
threadpool.push_back(make_shared<thread>(OracleResultAssemblyAgent::messageThreadProcessingLoop, | ||
reinterpret_cast < OracleResultAssemblyAgent * > ( agent ))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
Copyright (C) 2018-2019 SKALE Labs | ||
This file is part of skale-consensus. | ||
skale-consensus is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published | ||
by the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
skale-consensus is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with skale-consensus. If not, see <https://www.gnu.org/licenses/>. | ||
@file SchainMessageThreadPool.h | ||
@author Stan Kladko | ||
@date 2018 | ||
*/ | ||
|
||
#pragma once | ||
|
||
class Agent; | ||
class Schain; | ||
class WorkerThreadPool; | ||
|
||
|
||
class OracleMessageThreadPool : public WorkerThreadPool { | ||
public: | ||
|
||
OracleMessageThreadPool(Agent *_agent); | ||
|
||
virtual void createThread(uint64_t _numThreads); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// | ||
// Created by skale on 06.04.22. | ||
// | ||
|
||
#include "SkaleCommon.h" | ||
#include "Log.h" | ||
#include "chains/Schain.h" | ||
#include "monitoring/LivelinessMonitor.h" | ||
#include "OracleMessageThreadPool.h" | ||
#include "OracleServerAgent.h" | ||
#include "OracleResultAssemblyAgent.h" | ||
|
||
OracleResultAssemblyAgent::OracleResultAssemblyAgent(Schain &_sChain) : Agent(_sChain, true), | ||
oracleMessageThreadPool(new OracleMessageThreadPool(this)){ | ||
try { | ||
logThreadLocal_ = _sChain.getNode()->getLog(); | ||
oracleMessageThreadPool->startService(); | ||
} catch (...) { | ||
throw_with_nested(FatalError(__FUNCTION__, __CLASS_NAME__)); | ||
} | ||
} | ||
|
||
|
||
void OracleResultAssemblyAgent::messageThreadProcessingLoop(OracleResultAssemblyAgent*_agent) { | ||
CHECK_ARGUMENT(_agent); | ||
|
||
setThreadName("orclAssemblyLoop", _agent->getSchain()->getNode()->getConsensusEngine()); | ||
|
||
_agent->getSchain()->waitOnGlobalStartBarrier(); | ||
|
||
try { | ||
|
||
logThreadLocal_ = _agent->getSchain()->getNode()->getLog(); | ||
|
||
queue<ptr<MessageEnvelope> > newQueue; | ||
|
||
while (!_agent->getSchain()->getNode()->isExitRequested()) { | ||
{ | ||
unique_lock<mutex> mlock(_agent->messageMutex); | ||
while (_agent->messageQueue.empty()) { | ||
_agent->messageCond.wait(mlock); | ||
if (_agent->getNode()->isExitRequested()) | ||
return; | ||
} | ||
|
||
newQueue = _agent->messageQueue; | ||
|
||
while (!_agent->messageQueue.empty()) { | ||
if (_agent->getNode()->isExitRequested()) | ||
return; | ||
|
||
_agent->messageQueue.pop(); | ||
} | ||
} | ||
|
||
while (!newQueue.empty()) { | ||
if (_agent->getNode()->isExitRequested()) | ||
return; | ||
|
||
ptr<MessageEnvelope> m = newQueue.front(); | ||
CHECK_STATE((uint64_t) m->getMessage()->getBlockId() != 0); | ||
|
||
try { | ||
if (m->getMessage()->getMsgType() == MSG_ORACLE_REQ_BROADCAST || | ||
m->getMessage()->getMsgType() == MSG_ORACLE_RSP) { | ||
_agent->getSchain()->getOracleInstance()->routeAndProcessMessage(m); | ||
} else { | ||
CHECK_STATE(false); | ||
} | ||
} catch (exception &e) { | ||
LOG(err, "Exception in Schain::oracleAssemblylLoop"); | ||
SkaleException::logNested(e); | ||
if (_agent->getNode()->isExitRequested()) | ||
return; | ||
} // catch | ||
|
||
newQueue.pop(); | ||
} | ||
} | ||
|
||
|
||
} catch (FatalError &e) { | ||
SkaleException::logNested(e); | ||
_agent->getSchain()->getNode()->exitOnFatalError(e.what()); | ||
} | ||
} | ||
|
||
void OracleResultAssemblyAgent::postMessage(const ptr<MessageEnvelope> &_me) { | ||
CHECK_ARGUMENT(_me); | ||
|
||
MONITOR(__CLASS_NAME__, __FUNCTION__) | ||
|
||
getSchain()->checkForExit(); | ||
|
||
CHECK_STATE((uint64_t) _me->getMessage()->getBlockId() != 0); | ||
{ | ||
lock_guard<mutex> l(messageMutex); | ||
messageQueue.push(_me); | ||
messageCond.notify_all(); | ||
} | ||
} |
Oops, something went wrong.