mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 04:22:55 +01:00
refactor: make CActiveMasternodeManager::cs SharedMutex and private
This commit is contained in:
parent
663774c544
commit
069282611c
@ -58,7 +58,7 @@ void CCoinJoinServer::ProcessDSACCEPT(CNode& peer, CDataStream& vRecv)
|
|||||||
LogPrint(BCLog::COINJOIN, "DSACCEPT -- nDenom %d (%s) txCollateral %s", dsa.nDenom, CoinJoin::DenominationToString(dsa.nDenom), dsa.txCollateral.ToString()); /* Continued */
|
LogPrint(BCLog::COINJOIN, "DSACCEPT -- nDenom %d (%s) txCollateral %s", dsa.nDenom, CoinJoin::DenominationToString(dsa.nDenom), dsa.txCollateral.ToString()); /* Continued */
|
||||||
|
|
||||||
auto mnList = m_dmnman.GetListAtChainTip();
|
auto mnList = m_dmnman.GetListAtChainTip();
|
||||||
auto dmn = WITH_LOCK(m_mn_activeman->cs, return mnList.GetValidMNByCollateral(m_mn_activeman->GetOutPoint()));
|
auto dmn = mnList.GetValidMNByCollateral(m_mn_activeman->GetOutPoint());
|
||||||
if (!dmn) {
|
if (!dmn) {
|
||||||
PushStatus(peer, STATUS_REJECTED, ERR_MN_LIST);
|
PushStatus(peer, STATUS_REJECTED, ERR_MN_LIST);
|
||||||
return;
|
return;
|
||||||
@ -69,7 +69,7 @@ void CCoinJoinServer::ProcessDSACCEPT(CNode& peer, CDataStream& vRecv)
|
|||||||
TRY_LOCK(cs_vecqueue, lockRecv);
|
TRY_LOCK(cs_vecqueue, lockRecv);
|
||||||
if (!lockRecv) return;
|
if (!lockRecv) return;
|
||||||
|
|
||||||
auto mnOutpoint = WITH_LOCK(m_mn_activeman->cs, return m_mn_activeman->GetOutPoint());
|
auto mnOutpoint = m_mn_activeman->GetOutPoint();
|
||||||
|
|
||||||
if (ranges::any_of(vecCoinJoinQueue,
|
if (ranges::any_of(vecCoinJoinQueue,
|
||||||
[&mnOutpoint](const auto& q){return q.masternodeOutpoint == mnOutpoint;})) {
|
[&mnOutpoint](const auto& q){return q.masternodeOutpoint == mnOutpoint;})) {
|
||||||
@ -335,8 +335,8 @@ void CCoinJoinServer::CommitFinalTransaction()
|
|||||||
// create and sign masternode dstx transaction
|
// create and sign masternode dstx transaction
|
||||||
if (!m_dstxman.GetDSTX(hashTx)) {
|
if (!m_dstxman.GetDSTX(hashTx)) {
|
||||||
CCoinJoinBroadcastTx dstxNew(finalTransaction,
|
CCoinJoinBroadcastTx dstxNew(finalTransaction,
|
||||||
WITH_LOCK(m_mn_activeman->cs, return m_mn_activeman->GetOutPoint()),
|
m_mn_activeman->GetOutPoint(),
|
||||||
WITH_LOCK(m_mn_activeman->cs, return m_mn_activeman->GetProTxHash()),
|
m_mn_activeman->GetProTxHash(),
|
||||||
GetAdjustedTime());
|
GetAdjustedTime());
|
||||||
dstxNew.Sign(*m_mn_activeman);
|
dstxNew.Sign(*m_mn_activeman);
|
||||||
m_dstxman.AddDSTX(dstxNew);
|
m_dstxman.AddDSTX(dstxNew);
|
||||||
@ -505,8 +505,8 @@ void CCoinJoinServer::CheckForCompleteQueue()
|
|||||||
SetState(POOL_STATE_ACCEPTING_ENTRIES);
|
SetState(POOL_STATE_ACCEPTING_ENTRIES);
|
||||||
|
|
||||||
CCoinJoinQueue dsq(nSessionDenom,
|
CCoinJoinQueue dsq(nSessionDenom,
|
||||||
WITH_LOCK(m_mn_activeman->cs, return m_mn_activeman->GetOutPoint()),
|
m_mn_activeman->GetOutPoint(),
|
||||||
WITH_LOCK(m_mn_activeman->cs, return m_mn_activeman->GetProTxHash()),
|
m_mn_activeman->GetProTxHash(),
|
||||||
GetAdjustedTime(), true);
|
GetAdjustedTime(), true);
|
||||||
LogPrint(BCLog::COINJOIN, "CCoinJoinServer::CheckForCompleteQueue -- queue is ready, signing and relaying (%s) " /* Continued */
|
LogPrint(BCLog::COINJOIN, "CCoinJoinServer::CheckForCompleteQueue -- queue is ready, signing and relaying (%s) " /* Continued */
|
||||||
"with %d participants\n", dsq.ToString(), vecSessionCollaterals.size());
|
"with %d participants\n", dsq.ToString(), vecSessionCollaterals.size());
|
||||||
@ -721,8 +721,8 @@ bool CCoinJoinServer::CreateNewSession(const CCoinJoinAccept& dsa, PoolMessage&
|
|||||||
if (!fUnitTest) {
|
if (!fUnitTest) {
|
||||||
//broadcast that I'm accepting entries, only if it's the first entry through
|
//broadcast that I'm accepting entries, only if it's the first entry through
|
||||||
CCoinJoinQueue dsq(nSessionDenom,
|
CCoinJoinQueue dsq(nSessionDenom,
|
||||||
WITH_LOCK(m_mn_activeman->cs, return m_mn_activeman->GetOutPoint()),
|
m_mn_activeman->GetOutPoint(),
|
||||||
WITH_LOCK(m_mn_activeman->cs, return m_mn_activeman->GetProTxHash()),
|
m_mn_activeman->GetProTxHash(),
|
||||||
GetAdjustedTime(), false);
|
GetAdjustedTime(), false);
|
||||||
LogPrint(BCLog::COINJOIN, "CCoinJoinServer::CreateNewSession -- signing and relaying new queue: %s\n", dsq.ToString());
|
LogPrint(BCLog::COINJOIN, "CCoinJoinServer::CreateNewSession -- signing and relaying new queue: %s\n", dsq.ToString());
|
||||||
dsq.Sign(*m_mn_activeman);
|
dsq.Sign(*m_mn_activeman);
|
||||||
|
@ -24,9 +24,6 @@ void CMNAuth::PushMNAUTH(CNode& peer, CConnman& connman, const CBlockIndex* tip)
|
|||||||
if (!fMasternodeMode) return;
|
if (!fMasternodeMode) return;
|
||||||
|
|
||||||
CMNAuth mnauth;
|
CMNAuth mnauth;
|
||||||
uint256 signHash;
|
|
||||||
{
|
|
||||||
LOCK(::activeMasternodeManager->cs);
|
|
||||||
if (::activeMasternodeManager->GetProTxHash().IsNull()) {
|
if (::activeMasternodeManager->GetProTxHash().IsNull()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -48,14 +45,15 @@ void CMNAuth::PushMNAUTH(CNode& peer, CConnman& connman, const CBlockIndex* tip)
|
|||||||
const bool is_basic_scheme_active{DeploymentActiveAfter(tip, Params().GetConsensus(), Consensus::DEPLOYMENT_V19)};
|
const bool is_basic_scheme_active{DeploymentActiveAfter(tip, Params().GetConsensus(), Consensus::DEPLOYMENT_V19)};
|
||||||
auto pk = ::activeMasternodeManager->GetPubKey();
|
auto pk = ::activeMasternodeManager->GetPubKey();
|
||||||
const CBLSPublicKeyVersionWrapper pubKey(pk, !is_basic_scheme_active);
|
const CBLSPublicKeyVersionWrapper pubKey(pk, !is_basic_scheme_active);
|
||||||
|
uint256 signHash = [&]() {
|
||||||
if (peer.nVersion < MNAUTH_NODE_VER_VERSION || nOurNodeVersion < MNAUTH_NODE_VER_VERSION) {
|
if (peer.nVersion < MNAUTH_NODE_VER_VERSION || nOurNodeVersion < MNAUTH_NODE_VER_VERSION) {
|
||||||
signHash = ::SerializeHash(std::make_tuple(pubKey, receivedMNAuthChallenge, peer.IsInboundConn()));
|
return ::SerializeHash(std::make_tuple(pubKey, receivedMNAuthChallenge, peer.IsInboundConn()));
|
||||||
} else {
|
} else {
|
||||||
signHash = ::SerializeHash(std::make_tuple(pubKey, receivedMNAuthChallenge, peer.IsInboundConn(), nOurNodeVersion));
|
return ::SerializeHash(std::make_tuple(pubKey, receivedMNAuthChallenge, peer.IsInboundConn(), nOurNodeVersion));
|
||||||
}
|
}
|
||||||
|
}();
|
||||||
|
|
||||||
mnauth.proRegTxHash = ::activeMasternodeManager->GetProTxHash();
|
mnauth.proRegTxHash = ::activeMasternodeManager->GetProTxHash();
|
||||||
} // ::activeMasternodeManager->cs
|
|
||||||
|
|
||||||
mnauth.sig = ::activeMasternodeManager->Sign(signHash);
|
mnauth.sig = ::activeMasternodeManager->Sign(signHash);
|
||||||
|
|
||||||
@ -133,7 +131,7 @@ PeerMsgRet CMNAuth::ProcessMessage(CNode& peer, CConnman& connman, const CDeterm
|
|||||||
}
|
}
|
||||||
|
|
||||||
const uint256 myProTxHash = fMasternodeMode ?
|
const uint256 myProTxHash = fMasternodeMode ?
|
||||||
WITH_LOCK(::activeMasternodeManager->cs, return ::activeMasternodeManager->GetProTxHash()) :
|
::activeMasternodeManager->GetProTxHash() :
|
||||||
uint256();
|
uint256();
|
||||||
|
|
||||||
connman.ForEachNode([&](CNode* pnode2) {
|
connman.ForEachNode([&](CNode* pnode2) {
|
||||||
|
@ -691,14 +691,11 @@ std::optional<const CGovernanceObject> CGovernanceManager::CreateGovernanceTrigg
|
|||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
LOCK(::activeMasternodeManager->cs);
|
|
||||||
if (mn_payees.front()->proTxHash != ::activeMasternodeManager->GetProTxHash()) {
|
if (mn_payees.front()->proTxHash != ::activeMasternodeManager->GetProTxHash()) {
|
||||||
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s we are not the payee, skipping\n", __func__);
|
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s we are not the payee, skipping\n", __func__);
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
gov_sb.SetMasternodeOutpoint(::activeMasternodeManager->GetOutPoint());
|
gov_sb.SetMasternodeOutpoint(::activeMasternodeManager->GetOutPoint());
|
||||||
} // ::activeMasternodeManager->cs
|
|
||||||
gov_sb.Sign(*::activeMasternodeManager);
|
gov_sb.Sign(*::activeMasternodeManager);
|
||||||
|
|
||||||
if (std::string strError; !gov_sb.IsValidLocally(m_dmnman->GetListAtChainTip(), strError, true)) {
|
if (std::string strError; !gov_sb.IsValidLocally(m_dmnman->GetListAtChainTip(), strError, true)) {
|
||||||
@ -720,7 +717,7 @@ void CGovernanceManager::VoteGovernanceTriggers(const std::optional<const CGover
|
|||||||
{
|
{
|
||||||
// only active masternodes can vote on triggers
|
// only active masternodes can vote on triggers
|
||||||
if (!fMasternodeMode) return;
|
if (!fMasternodeMode) return;
|
||||||
if (WITH_LOCK(::activeMasternodeManager->cs, return ::activeMasternodeManager->GetProTxHash().IsNull())) return;
|
if (::activeMasternodeManager->GetProTxHash().IsNull()) return;
|
||||||
|
|
||||||
LOCK2(cs_main, cs);
|
LOCK2(cs_main, cs);
|
||||||
|
|
||||||
@ -763,7 +760,7 @@ void CGovernanceManager::VoteGovernanceTriggers(const std::optional<const CGover
|
|||||||
|
|
||||||
bool CGovernanceManager::VoteFundingTrigger(const uint256& nHash, const vote_outcome_enum_t outcome, CConnman& connman)
|
bool CGovernanceManager::VoteFundingTrigger(const uint256& nHash, const vote_outcome_enum_t outcome, CConnman& connman)
|
||||||
{
|
{
|
||||||
CGovernanceVote vote(WITH_LOCK(::activeMasternodeManager->cs, return ::activeMasternodeManager->GetOutPoint()), nHash, VOTE_SIGNAL_FUNDING, outcome);
|
CGovernanceVote vote(::activeMasternodeManager->GetOutPoint(), nHash, VOTE_SIGNAL_FUNDING, outcome);
|
||||||
vote.SetTime(GetAdjustedTime());
|
vote.SetTime(GetAdjustedTime());
|
||||||
vote.Sign(*::activeMasternodeManager);
|
vote.Sign(*::activeMasternodeManager);
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ bool CDKGSessionHandler::InitNewQuorum(const CBlockIndex* pQuorumBaseBlockIndex)
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto mns = utils::GetAllQuorumMembers(params.type, m_dmnman, pQuorumBaseBlockIndex);
|
auto mns = utils::GetAllQuorumMembers(params.type, m_dmnman, pQuorumBaseBlockIndex);
|
||||||
if (!curSession->Init(pQuorumBaseBlockIndex, mns, WITH_LOCK(m_mn_activeman->cs, return m_mn_activeman->GetProTxHash()), quorumIndex)) {
|
if (!curSession->Init(pQuorumBaseBlockIndex, mns, m_mn_activeman->GetProTxHash(), quorumIndex)) {
|
||||||
LogPrintf("CDKGSessionManager::%s -- height[%d] quorum initialization failed for %s qi[%d] mns[%d]\n", __func__, pQuorumBaseBlockIndex->nHeight, curSession->params.name, quorumIndex, mns.size());
|
LogPrintf("CDKGSessionManager::%s -- height[%d] quorum initialization failed for %s qi[%d] mns[%d]\n", __func__, pQuorumBaseBlockIndex->nHeight, curSession->params.name, quorumIndex, mns.size());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ bool CQuorum::SetVerificationVector(const std::vector<CBLSPublicKey>& quorumVecI
|
|||||||
|
|
||||||
bool CQuorum::SetSecretKeyShare(const CBLSSecretKey& secretKeyShare, const CActiveMasternodeManager& mn_activeman)
|
bool CQuorum::SetSecretKeyShare(const CBLSSecretKey& secretKeyShare, const CActiveMasternodeManager& mn_activeman)
|
||||||
{
|
{
|
||||||
if (!secretKeyShare.IsValid() || (secretKeyShare.GetPublicKey() != GetPubKeyShare(WITH_LOCK(mn_activeman.cs, return GetMemberIndex(mn_activeman.GetProTxHash()))))) {
|
if (!secretKeyShare.IsValid() || (secretKeyShare.GetPublicKey() != GetPubKeyShare(GetMemberIndex(mn_activeman.GetProTxHash())))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
@ -256,7 +256,7 @@ void CQuorumManager::TriggerQuorumDataRecoveryThreads(const CBlockIndex* pIndex)
|
|||||||
const uint256 proTxHash = [this]() {
|
const uint256 proTxHash = [this]() {
|
||||||
if (!fMasternodeMode) return uint256();
|
if (!fMasternodeMode) return uint256();
|
||||||
assert(m_mn_activeman);
|
assert(m_mn_activeman);
|
||||||
return WITH_LOCK(m_mn_activeman->cs, return m_mn_activeman->GetProTxHash());
|
return m_mn_activeman->GetProTxHash();
|
||||||
}();
|
}();
|
||||||
|
|
||||||
bool fWeAreQuorumTypeMember = ranges::any_of(vecQuorums, [&proTxHash](const auto& pQuorum) {
|
bool fWeAreQuorumTypeMember = ranges::any_of(vecQuorums, [&proTxHash](const auto& pQuorum) {
|
||||||
@ -352,7 +352,7 @@ void CQuorumManager::CheckQuorumConnections(const Consensus::LLMQParams& llmqPar
|
|||||||
const uint256 myProTxHash = [this]() {
|
const uint256 myProTxHash = [this]() {
|
||||||
if (!fMasternodeMode) return uint256();
|
if (!fMasternodeMode) return uint256();
|
||||||
assert(m_mn_activeman);
|
assert(m_mn_activeman);
|
||||||
return WITH_LOCK(m_mn_activeman->cs, return m_mn_activeman->GetProTxHash());
|
return m_mn_activeman->GetProTxHash();
|
||||||
}();
|
}();
|
||||||
|
|
||||||
bool isISType = llmqParams.type == Params().GetConsensus().llmqTypeDIP0024InstantSend;
|
bool isISType = llmqParams.type == Params().GetConsensus().llmqTypeDIP0024InstantSend;
|
||||||
@ -664,10 +664,10 @@ size_t CQuorumManager::GetQuorumRecoveryStartOffset(const CQuorumCPtr pQuorum, c
|
|||||||
std::sort(vecProTxHashes.begin(), vecProTxHashes.end());
|
std::sort(vecProTxHashes.begin(), vecProTxHashes.end());
|
||||||
size_t nIndex{0};
|
size_t nIndex{0};
|
||||||
{
|
{
|
||||||
LOCK(m_mn_activeman->cs);
|
auto my_protx_hash = m_mn_activeman->GetProTxHash();
|
||||||
for (const auto i : irange::range(vecProTxHashes.size())) {
|
for (const auto i : irange::range(vecProTxHashes.size())) {
|
||||||
// cppcheck-suppress useStlAlgorithm
|
// cppcheck-suppress useStlAlgorithm
|
||||||
if (m_mn_activeman->GetProTxHash() == vecProTxHashes[i]) {
|
if (my_protx_hash == vecProTxHashes[i]) {
|
||||||
nIndex = i;
|
nIndex = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -928,7 +928,7 @@ void CQuorumManager::StartQuorumDataRecoveryThread(const CQuorumCPtr pQuorum, co
|
|||||||
|
|
||||||
vecMemberHashes.reserve(pQuorum->qc->validMembers.size());
|
vecMemberHashes.reserve(pQuorum->qc->validMembers.size());
|
||||||
for (auto& member : pQuorum->members) {
|
for (auto& member : pQuorum->members) {
|
||||||
if (pQuorum->IsValidMember(member->proTxHash) && member->proTxHash != WITH_LOCK(m_mn_activeman->cs, return m_mn_activeman->GetProTxHash())) {
|
if (pQuorum->IsValidMember(member->proTxHash) && member->proTxHash != m_mn_activeman->GetProTxHash()) {
|
||||||
vecMemberHashes.push_back(member->proTxHash);
|
vecMemberHashes.push_back(member->proTxHash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -977,7 +977,7 @@ void CQuorumManager::StartQuorumDataRecoveryThread(const CQuorumCPtr pQuorum, co
|
|||||||
printLog("Connect");
|
printLog("Connect");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto proTxHash = WITH_LOCK(m_mn_activeman->cs, return m_mn_activeman->GetProTxHash());
|
auto proTxHash = m_mn_activeman->GetProTxHash();
|
||||||
connman.ForEachNode([&](CNode* pNode) {
|
connman.ForEachNode([&](CNode* pNode) {
|
||||||
auto verifiedProRegTxHash = pNode->GetVerifiedProRegTxHash();
|
auto verifiedProRegTxHash = pNode->GetVerifiedProRegTxHash();
|
||||||
if (pCurrentMemberHash == nullptr || verifiedProRegTxHash != *pCurrentMemberHash) {
|
if (pCurrentMemberHash == nullptr || verifiedProRegTxHash != *pCurrentMemberHash) {
|
||||||
|
@ -898,7 +898,7 @@ bool CSigningManager::AsyncSignIfMember(Consensus::LLMQType llmqType, CSigShares
|
|||||||
if (!fMasternodeMode) return false;
|
if (!fMasternodeMode) return false;
|
||||||
|
|
||||||
assert(m_mn_activeman);
|
assert(m_mn_activeman);
|
||||||
if (WITH_LOCK(m_mn_activeman->cs, return m_mn_activeman->GetProTxHash().IsNull())) return false;
|
if (m_mn_activeman->GetProTxHash().IsNull()) return false;
|
||||||
|
|
||||||
const CQuorumCPtr quorum = [&]() {
|
const CQuorumCPtr quorum = [&]() {
|
||||||
if (quorumHash.IsNull()) {
|
if (quorumHash.IsNull()) {
|
||||||
@ -920,7 +920,7 @@ bool CSigningManager::AsyncSignIfMember(Consensus::LLMQType llmqType, CSigShares
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!WITH_LOCK(m_mn_activeman->cs, return quorum->IsValidMember(m_mn_activeman->GetProTxHash()))) {
|
if (!quorum->IsValidMember(m_mn_activeman->GetProTxHash())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,7 +221,7 @@ void CSigSharesManager::ProcessMessage(const CNode& pfrom, const CSporkManager&
|
|||||||
if (!fMasternodeMode) return;
|
if (!fMasternodeMode) return;
|
||||||
|
|
||||||
assert(m_mn_activeman);
|
assert(m_mn_activeman);
|
||||||
if (WITH_LOCK(m_mn_activeman->cs, return m_mn_activeman->GetProTxHash().IsNull())) return;
|
if (m_mn_activeman->GetProTxHash().IsNull()) return;
|
||||||
|
|
||||||
if (sporkman.IsSporkActive(SPORK_21_QUORUM_ALL_CONNECTED) && msg_type == NetMsgType::QSIGSHARE) {
|
if (sporkman.IsSporkActive(SPORK_21_QUORUM_ALL_CONNECTED) && msg_type == NetMsgType::QSIGSHARE) {
|
||||||
std::vector<CSigShare> receivedSigShares;
|
std::vector<CSigShare> receivedSigShares;
|
||||||
@ -468,7 +468,7 @@ void CSigSharesManager::ProcessMessageSigShare(NodeId fromId, const CSigShare& s
|
|||||||
// quorum is too old
|
// quorum is too old
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!quorum->IsMember(WITH_LOCK(m_mn_activeman->cs, return m_mn_activeman->GetProTxHash()))) {
|
if (!quorum->IsMember(m_mn_activeman->GetProTxHash())) {
|
||||||
// we're not a member so we can't verify it (we actually shouldn't have received it)
|
// we're not a member so we can't verify it (we actually shouldn't have received it)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -518,7 +518,7 @@ bool CSigSharesManager::PreVerifyBatchedSigShares(const CActiveMasternodeManager
|
|||||||
// quorum is too old
|
// quorum is too old
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!session.quorum->IsMember(WITH_LOCK(mn_activeman.cs, return mn_activeman.GetProTxHash()))) {
|
if (!session.quorum->IsMember(mn_activeman.GetProTxHash())) {
|
||||||
// we're not a member so we can't verify it (we actually shouldn't have received it)
|
// we're not a member so we can't verify it (we actually shouldn't have received it)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -703,7 +703,7 @@ void CSigSharesManager::ProcessSigShare(const CSigShare& sigShare, const CConnma
|
|||||||
|
|
||||||
// prepare node set for direct-push in case this is our sig share
|
// prepare node set for direct-push in case this is our sig share
|
||||||
std::set<NodeId> quorumNodes;
|
std::set<NodeId> quorumNodes;
|
||||||
if (!IsAllMembersConnectedEnabled(llmqType, m_sporkman) && sigShare.getQuorumMember() == quorum->GetMemberIndex(WITH_LOCK(m_mn_activeman->cs, return m_mn_activeman->GetProTxHash()))) {
|
if (!IsAllMembersConnectedEnabled(llmqType, m_sporkman) && sigShare.getQuorumMember() == quorum->GetMemberIndex(m_mn_activeman->GetProTxHash())) {
|
||||||
quorumNodes = connman.GetMasternodeQuorumNodes(sigShare.getLlmqType(), sigShare.getQuorumHash());
|
quorumNodes = connman.GetMasternodeQuorumNodes(sigShare.getLlmqType(), sigShare.getQuorumHash());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1496,7 +1496,7 @@ std::optional<CSigShare> CSigSharesManager::CreateSigShare(const CQuorumCPtr& qu
|
|||||||
assert(m_mn_activeman);
|
assert(m_mn_activeman);
|
||||||
|
|
||||||
cxxtimer::Timer t(true);
|
cxxtimer::Timer t(true);
|
||||||
auto activeMasterNodeProTxHash = WITH_LOCK(m_mn_activeman->cs, return m_mn_activeman->GetProTxHash());
|
auto activeMasterNodeProTxHash = m_mn_activeman->GetProTxHash();
|
||||||
|
|
||||||
if (!quorum->IsValidMember(activeMasterNodeProTxHash)) {
|
if (!quorum->IsValidMember(activeMasterNodeProTxHash)) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
@ -31,7 +31,7 @@ CActiveMasternodeManager::CActiveMasternodeManager(const CBLSSecretKey& sk, CCon
|
|||||||
|
|
||||||
std::string CActiveMasternodeManager::GetStateString() const
|
std::string CActiveMasternodeManager::GetStateString() const
|
||||||
{
|
{
|
||||||
switch (WITH_LOCK(cs, return m_state)) {
|
switch (WITH_READ_LOCK(cs, return m_state)) {
|
||||||
case MASTERNODE_WAITING_FOR_PROTX:
|
case MASTERNODE_WAITING_FOR_PROTX:
|
||||||
return "WAITING_FOR_PROTX";
|
return "WAITING_FOR_PROTX";
|
||||||
case MASTERNODE_POSE_BANNED:
|
case MASTERNODE_POSE_BANNED:
|
||||||
@ -53,7 +53,7 @@ std::string CActiveMasternodeManager::GetStateString() const
|
|||||||
|
|
||||||
std::string CActiveMasternodeManager::GetStatus() const
|
std::string CActiveMasternodeManager::GetStatus() const
|
||||||
{
|
{
|
||||||
LOCK(cs);
|
READ_LOCK(cs);
|
||||||
switch (m_state) {
|
switch (m_state) {
|
||||||
case MASTERNODE_WAITING_FOR_PROTX:
|
case MASTERNODE_WAITING_FOR_PROTX:
|
||||||
return "Waiting for ProTx to appear on-chain";
|
return "Waiting for ProTx to appear on-chain";
|
||||||
@ -74,9 +74,9 @@ std::string CActiveMasternodeManager::GetStatus() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CActiveMasternodeManager::Init(const CBlockIndex* pindex)
|
void CActiveMasternodeManager::InitInternal(const CBlockIndex* pindex)
|
||||||
{
|
{
|
||||||
LOCK(cs);
|
AssertLockHeld(cs);
|
||||||
|
|
||||||
if (!fMasternodeMode) return;
|
if (!fMasternodeMode) return;
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ void CActiveMasternodeManager::UpdatedBlockTip(const CBlockIndex* pindexNew, con
|
|||||||
|
|
||||||
if (!DeploymentDIP0003Enforced(pindexNew->nHeight, Params().GetConsensus())) return;
|
if (!DeploymentDIP0003Enforced(pindexNew->nHeight, Params().GetConsensus())) return;
|
||||||
|
|
||||||
const auto [cur_state, cur_protx_hash] = WITH_LOCK(cs, return std::make_pair(m_state, m_info.proTxHash));
|
const auto [cur_state, cur_protx_hash] = WITH_READ_LOCK(cs, return std::make_pair(m_state, m_info.proTxHash));
|
||||||
if (cur_state == MASTERNODE_READY) {
|
if (cur_state == MASTERNODE_READY) {
|
||||||
auto oldMNList = Assert(m_dmnman)->GetListForBlock(pindexNew->pprev);
|
auto oldMNList = Assert(m_dmnman)->GetListForBlock(pindexNew->pprev);
|
||||||
auto newMNList = m_dmnman->GetListForBlock(pindexNew);
|
auto newMNList = m_dmnman->GetListForBlock(pindexNew);
|
||||||
@ -163,7 +163,7 @@ void CActiveMasternodeManager::UpdatedBlockTip(const CBlockIndex* pindexNew, con
|
|||||||
m_info.proTxHash = uint256();
|
m_info.proTxHash = uint256();
|
||||||
m_info.outpoint.SetNull();
|
m_info.outpoint.SetNull();
|
||||||
// MN might have reappeared in same block with a new ProTx
|
// MN might have reappeared in same block with a new ProTx
|
||||||
Init(pindexNew);
|
InitInternal(pindexNew);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!newMNList.IsMNValid(cur_protx_hash)) {
|
if (!newMNList.IsMNValid(cur_protx_hash)) {
|
||||||
@ -190,6 +190,7 @@ void CActiveMasternodeManager::UpdatedBlockTip(const CBlockIndex* pindexNew, con
|
|||||||
|
|
||||||
bool CActiveMasternodeManager::GetLocalAddress(CService& addrRet)
|
bool CActiveMasternodeManager::GetLocalAddress(CService& addrRet)
|
||||||
{
|
{
|
||||||
|
AssertLockHeld(cs);
|
||||||
// First try to find whatever our own local address is known internally.
|
// First try to find whatever our own local address is known internally.
|
||||||
// Addresses could be specified via externalip or bind option, discovered via UPnP
|
// Addresses could be specified via externalip or bind option, discovered via UPnP
|
||||||
// or added by TorController. Use some random dummy IPv4 peer to prefer the one
|
// or added by TorController. Use some random dummy IPv4 peer to prefer the one
|
||||||
@ -207,7 +208,7 @@ bool CActiveMasternodeManager::GetLocalAddress(CService& addrRet)
|
|||||||
if (!fFoundLocal) {
|
if (!fFoundLocal) {
|
||||||
bool empty = true;
|
bool empty = true;
|
||||||
// If we have some peers, let's try to find our local address from one of them
|
// If we have some peers, let's try to find our local address from one of them
|
||||||
auto service = WITH_LOCK(cs, return m_info.service);
|
auto service = m_info.service;
|
||||||
m_connman.ForEachNodeContinueIf(CConnman::AllNodes, [&](CNode* pnode) {
|
m_connman.ForEachNodeContinueIf(CConnman::AllNodes, [&](CNode* pnode) {
|
||||||
empty = false;
|
empty = false;
|
||||||
if (pnode->addr.IsIPv4())
|
if (pnode->addr.IsIPv4())
|
||||||
@ -216,7 +217,6 @@ bool CActiveMasternodeManager::GetLocalAddress(CService& addrRet)
|
|||||||
});
|
});
|
||||||
// nothing and no live connections, can't do anything for now
|
// nothing and no live connections, can't do anything for now
|
||||||
if (empty) {
|
if (empty) {
|
||||||
LOCK(cs);
|
|
||||||
m_error = "Can't detect valid external address. Please consider using the externalip configuration option if problem persists. Make sure to use IPv4 address only.";
|
m_error = "Can't detect valid external address. Please consider using the externalip configuration option if problem persists. Make sure to use IPv4 address only.";
|
||||||
LogPrintf("CActiveMasternodeManager::GetLocalAddress -- ERROR: %s\n", m_error);
|
LogPrintf("CActiveMasternodeManager::GetLocalAddress -- ERROR: %s\n", m_error);
|
||||||
return false;
|
return false;
|
||||||
@ -238,7 +238,7 @@ template <template <typename> class EncryptedObj, typename Obj>
|
|||||||
int version) const
|
int version) const
|
||||||
{
|
{
|
||||||
AssertLockNotHeld(cs);
|
AssertLockNotHeld(cs);
|
||||||
return WITH_LOCK(cs, return obj.Decrypt(idx, m_info.blsKeyOperator, ret_obj, version));
|
return WITH_READ_LOCK(cs, return obj.Decrypt(idx, m_info.blsKeyOperator, ret_obj, version));
|
||||||
}
|
}
|
||||||
template bool CActiveMasternodeManager::Decrypt(const CBLSIESEncryptedObject<CBLSSecretKey>& obj, size_t idx,
|
template bool CActiveMasternodeManager::Decrypt(const CBLSIESEncryptedObject<CBLSSecretKey>& obj, size_t idx,
|
||||||
CBLSSecretKey& ret_obj, int version) const;
|
CBLSSecretKey& ret_obj, int version) const;
|
||||||
@ -248,18 +248,19 @@ template bool CActiveMasternodeManager::Decrypt(const CBLSIESMultiRecipientObjec
|
|||||||
[[nodiscard]] CBLSSignature CActiveMasternodeManager::Sign(const uint256& hash) const
|
[[nodiscard]] CBLSSignature CActiveMasternodeManager::Sign(const uint256& hash) const
|
||||||
{
|
{
|
||||||
AssertLockNotHeld(cs);
|
AssertLockNotHeld(cs);
|
||||||
return WITH_LOCK(cs, return m_info.blsKeyOperator.Sign(hash));
|
return WITH_READ_LOCK(cs, return m_info.blsKeyOperator.Sign(hash));
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] CBLSSignature CActiveMasternodeManager::Sign(const uint256& hash, const bool is_legacy) const
|
[[nodiscard]] CBLSSignature CActiveMasternodeManager::Sign(const uint256& hash, const bool is_legacy) const
|
||||||
{
|
{
|
||||||
AssertLockNotHeld(cs);
|
AssertLockNotHeld(cs);
|
||||||
return WITH_LOCK(cs, return m_info.blsKeyOperator.Sign(hash, is_legacy));
|
return WITH_READ_LOCK(cs, return m_info.blsKeyOperator.Sign(hash, is_legacy));
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need to pass a copy as opposed to a const ref because CBLSPublicKeyVersionWrapper
|
// We need to pass a copy as opposed to a const ref because CBLSPublicKeyVersionWrapper
|
||||||
// does not accept a const ref in its construction args
|
// does not accept a const ref in its construction args
|
||||||
[[nodiscard]] CBLSPublicKey CActiveMasternodeManager::GetPubKey() const
|
[[nodiscard]] CBLSPublicKey CActiveMasternodeManager::GetPubKey() const
|
||||||
{
|
{
|
||||||
|
READ_LOCK(cs);
|
||||||
return m_info.blsPubKeyOperator;
|
return m_info.blsPubKeyOperator;
|
||||||
}
|
}
|
||||||
|
@ -41,9 +41,8 @@ public:
|
|||||||
MASTERNODE_ERROR,
|
MASTERNODE_ERROR,
|
||||||
};
|
};
|
||||||
|
|
||||||
mutable RecursiveMutex cs;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
mutable SharedMutex cs;
|
||||||
masternode_state_t m_state GUARDED_BY(cs) {MASTERNODE_WAITING_FOR_PROTX};
|
masternode_state_t m_state GUARDED_BY(cs) {MASTERNODE_WAITING_FOR_PROTX};
|
||||||
CActiveMasternodeInfo m_info GUARDED_BY(cs);
|
CActiveMasternodeInfo m_info GUARDED_BY(cs);
|
||||||
std::string m_error GUARDED_BY(cs);
|
std::string m_error GUARDED_BY(cs);
|
||||||
@ -56,7 +55,7 @@ public:
|
|||||||
|
|
||||||
void UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockIndex* pindexFork, bool fInitialDownload) override;
|
void UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockIndex* pindexFork, bool fInitialDownload) override;
|
||||||
|
|
||||||
void Init(const CBlockIndex* pindex);
|
void Init(const CBlockIndex* pindex) LOCKS_EXCLUDED(cs) { LOCK(cs); InitInternal(pindex); };
|
||||||
|
|
||||||
std::string GetStateString() const;
|
std::string GetStateString() const;
|
||||||
std::string GetStatus() const;
|
std::string GetStatus() const;
|
||||||
@ -70,14 +69,15 @@ public:
|
|||||||
[[nodiscard]] CBLSSignature Sign(const uint256& hash, const bool is_legacy) const LOCKS_EXCLUDED(cs);
|
[[nodiscard]] CBLSSignature Sign(const uint256& hash, const bool is_legacy) const LOCKS_EXCLUDED(cs);
|
||||||
|
|
||||||
/* TODO: Reconsider external locking */
|
/* TODO: Reconsider external locking */
|
||||||
[[nodiscard]] const COutPoint& GetOutPoint() const EXCLUSIVE_LOCKS_REQUIRED(cs) { return m_info.outpoint; }
|
[[nodiscard]] COutPoint GetOutPoint() const { READ_LOCK(cs); return m_info.outpoint; }
|
||||||
[[nodiscard]] const uint256& GetProTxHash() const EXCLUSIVE_LOCKS_REQUIRED(cs) { return m_info.proTxHash; }
|
[[nodiscard]] uint256 GetProTxHash() const { READ_LOCK(cs); return m_info.proTxHash; }
|
||||||
[[nodiscard]] const CService& GetService() const EXCLUSIVE_LOCKS_REQUIRED(cs) { return m_info.service; }
|
[[nodiscard]] CService GetService() const { READ_LOCK(cs); return m_info.service; }
|
||||||
[[nodiscard]] CBLSPublicKey GetPubKey() const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
[[nodiscard]] CBLSPublicKey GetPubKey() const;
|
||||||
[[nodiscard]] bool IsLegacy() const EXCLUSIVE_LOCKS_REQUIRED(cs) { return m_info.legacy; }
|
[[nodiscard]] bool IsLegacy() const { READ_LOCK(cs); return m_info.legacy; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool GetLocalAddress(CService& addrRet);
|
void InitInternal(const CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||||
|
bool GetLocalAddress(CService& addrRet) EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern std::unique_ptr<CActiveMasternodeManager> activeMasternodeManager;
|
extern std::unique_ptr<CActiveMasternodeManager> activeMasternodeManager;
|
||||||
|
@ -319,7 +319,6 @@ static UniValue gobject_submit(const JSONRPCRequest& request)
|
|||||||
if (fMasternodeMode) {
|
if (fMasternodeMode) {
|
||||||
CHECK_NONFATAL(node.mn_activeman);
|
CHECK_NONFATAL(node.mn_activeman);
|
||||||
|
|
||||||
LOCK(node.mn_activeman->cs);
|
|
||||||
const bool fMnFound = mnList.HasValidMNByCollateral(node.mn_activeman->GetOutPoint());
|
const bool fMnFound = mnList.HasValidMNByCollateral(node.mn_activeman->GetOutPoint());
|
||||||
|
|
||||||
LogPrint(BCLog::GOBJECT, "gobject_submit -- pubKeyOperator = %s, outpoint = %s, params.size() = %lld, fMnFound = %d\n",
|
LogPrint(BCLog::GOBJECT, "gobject_submit -- pubKeyOperator = %s, outpoint = %s, params.size() = %lld, fMnFound = %d\n",
|
||||||
|
@ -265,15 +265,10 @@ static UniValue masternode_status(const JSONRPCRequest& request)
|
|||||||
CHECK_NONFATAL(node.mn_activeman);
|
CHECK_NONFATAL(node.mn_activeman);
|
||||||
|
|
||||||
UniValue mnObj(UniValue::VOBJ);
|
UniValue mnObj(UniValue::VOBJ);
|
||||||
CDeterministicMNCPtr dmn;
|
|
||||||
{
|
|
||||||
LOCK(node.mn_activeman->cs);
|
|
||||||
|
|
||||||
// keep compatibility with legacy status for now (might get deprecated/removed later)
|
// keep compatibility with legacy status for now (might get deprecated/removed later)
|
||||||
mnObj.pushKV("outpoint", node.mn_activeman->GetOutPoint().ToStringShort());
|
mnObj.pushKV("outpoint", node.mn_activeman->GetOutPoint().ToStringShort());
|
||||||
mnObj.pushKV("service", node.mn_activeman->GetService().ToString());
|
mnObj.pushKV("service", node.mn_activeman->GetService().ToString());
|
||||||
dmn = node.dmnman->GetListAtChainTip().GetMN(node.mn_activeman->GetProTxHash());
|
CDeterministicMNCPtr dmn = node.dmnman->GetListAtChainTip().GetMN(node.mn_activeman->GetProTxHash());
|
||||||
}
|
|
||||||
if (dmn) {
|
if (dmn) {
|
||||||
mnObj.pushKV("proTxHash", dmn->proTxHash.ToString());
|
mnObj.pushKV("proTxHash", dmn->proTxHash.ToString());
|
||||||
mnObj.pushKV("type", std::string(GetMnType(dmn->nType).description));
|
mnObj.pushKV("type", std::string(GetMnType(dmn->nType).description));
|
||||||
|
@ -299,7 +299,7 @@ static UniValue quorum_dkgstatus(const JSONRPCRequest& request, CDeterministicMN
|
|||||||
const uint256 proTxHash = [&mn_activeman]() {
|
const uint256 proTxHash = [&mn_activeman]() {
|
||||||
if (!fMasternodeMode) return uint256();
|
if (!fMasternodeMode) return uint256();
|
||||||
CHECK_NONFATAL(mn_activeman);
|
CHECK_NONFATAL(mn_activeman);
|
||||||
return WITH_LOCK(mn_activeman->cs, return mn_activeman->GetProTxHash());
|
return mn_activeman->GetProTxHash();
|
||||||
}();
|
}();
|
||||||
|
|
||||||
UniValue minableCommitments(UniValue::VARR);
|
UniValue minableCommitments(UniValue::VARR);
|
||||||
|
Loading…
Reference in New Issue
Block a user