Implement BuildSimplifiedDiff in CDeterministicMNList
And use it instead of BuildDiff in DIP4
This commit is contained in:
parent
6edad37457
commit
b5947f2997
@ -283,6 +283,34 @@ CDeterministicMNListDiff CDeterministicMNList::BuildDiff(const CDeterministicMNL
|
||||
return diffRet;
|
||||
}
|
||||
|
||||
CSimplifiedMNListDiff CDeterministicMNList::BuildSimplifiedDiff(const CDeterministicMNList& to) const
|
||||
{
|
||||
CSimplifiedMNListDiff diffRet;
|
||||
diffRet.baseBlockHash = blockHash;
|
||||
diffRet.blockHash = to.blockHash;
|
||||
|
||||
to.ForEachMN(false, [&](const CDeterministicMNCPtr& toPtr) {
|
||||
const auto fromPtr = mnMap.find(toPtr->proTxHash);
|
||||
if (fromPtr == nullptr) {
|
||||
diffRet.mnList.emplace_back(*toPtr);
|
||||
} else {
|
||||
CSimplifiedMNListEntry sme1(*toPtr);
|
||||
CSimplifiedMNListEntry sme2(**fromPtr);
|
||||
if (sme1 != sme2) {
|
||||
diffRet.mnList.emplace_back(*toPtr);
|
||||
}
|
||||
}
|
||||
});
|
||||
ForEachMN(false, [&](const CDeterministicMNCPtr& fromPtr) {
|
||||
const auto toPtr = to.mnMap.find(fromPtr->proTxHash);
|
||||
if (toPtr == nullptr) {
|
||||
diffRet.deletedMNs.emplace_back(fromPtr->proTxHash);
|
||||
}
|
||||
});
|
||||
|
||||
return diffRet;
|
||||
}
|
||||
|
||||
CDeterministicMNList CDeterministicMNList::ApplyDiff(const CDeterministicMNListDiff& diff) const
|
||||
{
|
||||
assert(diff.prevBlockHash == blockHash && diff.nHeight == nHeight + 1);
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "dbwrapper.h"
|
||||
#include "evodb.h"
|
||||
#include "providertx.h"
|
||||
#include "simplifiedmns.h"
|
||||
#include "sync.h"
|
||||
|
||||
#include "immer/map.hpp"
|
||||
@ -307,6 +308,7 @@ public:
|
||||
std::vector<std::pair<arith_uint256, CDeterministicMNCPtr>> CalculateScores(const uint256& modifier) const;
|
||||
|
||||
CDeterministicMNListDiff BuildDiff(const CDeterministicMNList& to) const;
|
||||
CSimplifiedMNListDiff BuildSimplifiedDiff(const CDeterministicMNList& to) const;
|
||||
CDeterministicMNList ApplyDiff(const CDeterministicMNListDiff& diff) const;
|
||||
|
||||
void AddMN(const CDeterministicMNCPtr& dmn);
|
||||
|
@ -144,7 +144,7 @@ bool BuildSimplifiedMNListDiff(const uint256& baseBlockHash, const uint256& bloc
|
||||
|
||||
auto baseDmnList = deterministicMNManager->GetListForBlock(baseBlockHash);
|
||||
auto dmnList = deterministicMNManager->GetListForBlock(blockHash);
|
||||
auto dmnDiff = baseDmnList.BuildDiff(dmnList);
|
||||
mnListDiffRet = baseDmnList.BuildSimplifiedDiff(dmnList);
|
||||
|
||||
// TODO store coinbase TX in CBlockIndex
|
||||
CBlock block;
|
||||
@ -153,8 +153,6 @@ bool BuildSimplifiedMNListDiff(const uint256& baseBlockHash, const uint256& bloc
|
||||
return false;
|
||||
}
|
||||
|
||||
mnListDiffRet.baseBlockHash = baseBlockHash;
|
||||
mnListDiffRet.blockHash = blockHash;
|
||||
mnListDiffRet.cbTx = block.vtx[0];
|
||||
|
||||
std::vector<uint256> vHashes;
|
||||
@ -164,17 +162,6 @@ bool BuildSimplifiedMNListDiff(const uint256& baseBlockHash, const uint256& bloc
|
||||
}
|
||||
vMatch[0] = true; // only coinbase matches
|
||||
mnListDiffRet.cbTxMerkleTree = CPartialMerkleTree(vHashes, vMatch);
|
||||
mnListDiffRet.deletedMNs.assign(dmnDiff.removedMns.begin(), dmnDiff.removedMns.end());
|
||||
|
||||
for (const auto& p : dmnDiff.addedMNs) {
|
||||
mnListDiffRet.mnList.emplace_back(*p.second);
|
||||
}
|
||||
for (const auto& p : dmnDiff.updatedMNs) {
|
||||
const auto& dmn = dmnList.GetMN(p.first);
|
||||
CDeterministicMN newDmn(*dmn);
|
||||
newDmn.pdmnState = p.second;
|
||||
mnListDiffRet.mnList.emplace_back(newDmn);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -29,6 +29,21 @@ public:
|
||||
CSimplifiedMNListEntry() {}
|
||||
CSimplifiedMNListEntry(const CDeterministicMN& dmn);
|
||||
|
||||
bool operator==(const CSimplifiedMNListEntry& rhs) const
|
||||
{
|
||||
return proRegTxHash == rhs.proRegTxHash &&
|
||||
confirmedHash == rhs.confirmedHash &&
|
||||
service == rhs.service &&
|
||||
pubKeyOperator == rhs.pubKeyOperator &&
|
||||
keyIDVoting == rhs.keyIDVoting &&
|
||||
isValid == rhs.isValid;
|
||||
}
|
||||
|
||||
bool operator!=(const CSimplifiedMNListEntry& rhs) const
|
||||
{
|
||||
return !(rhs == *this);
|
||||
}
|
||||
|
||||
public:
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user