mirror of
https://github.com/dashpay/dash.git
synced 2024-12-29 05:49:11 +01:00
7a440d626b
* Implement CompactFull() in CDBWrapper This allows to compact the whole DB in one go. * Implement more compact version of CDeterministicMNListDiff This introduces CDeterministicMNStateDiff which requires to only store fields on-disk which actually changed. * Avoid writing mnUniquePropertyMap to disk when storing snapshots This map can be rebuilt by simply using AddMN for each deserialized MN. * Implement Serialize/Unserialize in CScript This allows us to directly use READWRITE() on scripts and removes the need for the ugly cast to CScriptBase. This commit also changes all Dash specific uses of CScript to not use the cast. * Keep track of registeration counts and introduce internalID for masternodes The "internalId" is simply the number of MNs registered so far when the new MN is added. It is deterministic and stays the same forever. * Use internalId as keys in MN list diffs This reduces the used size on-disk. * Two simple speedups in MN list diff handling 1. Avoid full compare if dmn or state pointers match in BuildDiff 2. Use std::move when adding diff to listDiff in GetListForBlock * Implement upgrade code for old CDeterministicMNListDiff format to new format * Track tipIndex instead of tipHeight/tipBlockHash * Store and pass around CBlockIndex* instead of block hash and height This allows us to switch CDeterministicMNManager::GetListForBlock to work with CBlockIndex. * Refactor CDeterministicMNManager::GetListForBlock to require CBlockIndex* Instead of requiring a block hash. This allows us to remove blockHash and prevBlockHash from CDeterministicMNListDiff without the use of cs_main locks in GetListForBlock. * Remove prevBlockHash, blockHash and nHeight from CDeterministicMNListDiff * Remove access to determinisitcMNManager in CMasternodeMetaMan::ToString() The deterministic MN manager is not fully initialized yet at the time this is called, which results in an empty list being returned everytime. * Better logic to determine if an upgrade is needed Reuse the "best block" logic to figure out if an upgrade is needed. Also use it to ensure that older nodes are unable to start after the upgrade was performed. * Return null block hash if it was requested with getmnlistdiff * bump CGovernanceManager::SERIALIZATION_VERSION_STRING * Check SERIALIZATION_VERSION_STRING before deserializing anything else * Invoke Clear() before deserializing just to be sure
124 lines
3.2 KiB
C++
124 lines
3.2 KiB
C++
// Copyright (c) 2014-2019 The Dash Core developers
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include "masternode-meta.h"
|
|
|
|
CMasternodeMetaMan mmetaman;
|
|
|
|
const std::string CMasternodeMetaMan::SERIALIZATION_VERSION_STRING = "CMasternodeMetaMan-Version-1";
|
|
|
|
void CMasternodeMetaInfo::AddGovernanceVote(const uint256& nGovernanceObjectHash)
|
|
{
|
|
LOCK(cs);
|
|
// Insert a zero value, or not. Then increment the value regardless. This
|
|
// ensures the value is in the map.
|
|
const auto& pair = mapGovernanceObjectsVotedOn.emplace(nGovernanceObjectHash, 0);
|
|
pair.first->second++;
|
|
}
|
|
|
|
void CMasternodeMetaInfo::RemoveGovernanceObject(const uint256& nGovernanceObjectHash)
|
|
{
|
|
LOCK(cs);
|
|
// Whether or not the govobj hash exists in the map first is irrelevant.
|
|
mapGovernanceObjectsVotedOn.erase(nGovernanceObjectHash);
|
|
}
|
|
|
|
/**
|
|
* FLAG GOVERNANCE ITEMS AS DIRTY
|
|
*
|
|
* - When masternode come and go on the network, we must flag the items they voted on to recalc it's cached flags
|
|
*
|
|
*/
|
|
void CMasternodeMetaInfo::FlagGovernanceItemsAsDirty()
|
|
{
|
|
LOCK(cs);
|
|
for (auto& govObjHashPair : mapGovernanceObjectsVotedOn) {
|
|
mmetaman.AddDirtyGovernanceObjectHash(govObjHashPair.first);
|
|
}
|
|
}
|
|
|
|
CMasternodeMetaInfoPtr CMasternodeMetaMan::GetMetaInfo(const uint256& proTxHash, bool fCreate)
|
|
{
|
|
LOCK(cs);
|
|
auto it = metaInfos.find(proTxHash);
|
|
if (it != metaInfos.end()) {
|
|
return it->second;
|
|
}
|
|
if (!fCreate) {
|
|
return nullptr;
|
|
}
|
|
it = metaInfos.emplace(proTxHash, std::make_shared<CMasternodeMetaInfo>(proTxHash)).first;
|
|
return it->second;
|
|
}
|
|
|
|
void CMasternodeMetaMan::AllowMixing(const uint256& proTxHash)
|
|
{
|
|
LOCK(cs);
|
|
auto mm = GetMetaInfo(proTxHash);
|
|
nDsqCount++;
|
|
LOCK(mm->cs);
|
|
mm->nLastDsq = nDsqCount;
|
|
mm->nMixingTxCount = 0;
|
|
}
|
|
|
|
void CMasternodeMetaMan::DisallowMixing(const uint256& proTxHash)
|
|
{
|
|
LOCK(cs);
|
|
auto mm = GetMetaInfo(proTxHash);
|
|
|
|
LOCK(mm->cs);
|
|
mm->nMixingTxCount++;
|
|
}
|
|
|
|
bool CMasternodeMetaMan::AddGovernanceVote(const uint256& proTxHash, const uint256& nGovernanceObjectHash)
|
|
{
|
|
LOCK(cs);
|
|
auto mm = GetMetaInfo(proTxHash);
|
|
mm->AddGovernanceVote(nGovernanceObjectHash);
|
|
return true;
|
|
}
|
|
|
|
void CMasternodeMetaMan::RemoveGovernanceObject(const uint256& nGovernanceObjectHash)
|
|
{
|
|
LOCK(cs);
|
|
for(auto& p : metaInfos) {
|
|
p.second->RemoveGovernanceObject(nGovernanceObjectHash);
|
|
}
|
|
}
|
|
|
|
void CMasternodeMetaMan::AddDirtyGovernanceObjectHash(const uint256& nHash)
|
|
{
|
|
LOCK(cs);
|
|
vecDirtyGovernanceObjectHashes.push_back(nHash);
|
|
}
|
|
|
|
std::vector<uint256> CMasternodeMetaMan::GetAndClearDirtyGovernanceObjectHashes()
|
|
{
|
|
LOCK(cs);
|
|
std::vector<uint256> vecTmp = std::move(vecDirtyGovernanceObjectHashes);
|
|
vecDirtyGovernanceObjectHashes.clear();
|
|
return vecTmp;
|
|
}
|
|
|
|
void CMasternodeMetaMan::Clear()
|
|
{
|
|
LOCK(cs);
|
|
metaInfos.clear();
|
|
vecDirtyGovernanceObjectHashes.clear();
|
|
}
|
|
|
|
void CMasternodeMetaMan::CheckAndRemove()
|
|
{
|
|
|
|
}
|
|
|
|
std::string CMasternodeMetaMan::ToString() const
|
|
{
|
|
std::ostringstream info;
|
|
|
|
info << "Masternodes: meta infos object count: " << (int)metaInfos.size() <<
|
|
", nDsqCount: " << (int)nDsqCount;
|
|
return info.str();
|
|
}
|