Skip to content

Commit 3fdddde

Browse files
committed
Remove prevBlockHash, blockHash and nHeight from CDeterministicMNListDiff
1 parent 21c34c1 commit 3fdddde

File tree

2 files changed

+8
-25
lines changed

2 files changed

+8
-25
lines changed

src/evo/deterministicmns.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,6 @@ void CDeterministicMNList::PoSeDecrease(const uint256& proTxHash)
359359
CDeterministicMNListDiff CDeterministicMNList::BuildDiff(const CDeterministicMNList& to) const
360360
{
361361
CDeterministicMNListDiff diffRet;
362-
diffRet.prevBlockHash = blockHash;
363-
diffRet.blockHash = to.blockHash;
364-
diffRet.nHeight = to.nHeight;
365362

366363
to.ForEachMN(false, [&](const CDeterministicMNCPtr& toPtr) {
367364
auto fromPtr = GetMN(toPtr->proTxHash);
@@ -418,13 +415,11 @@ CSimplifiedMNListDiff CDeterministicMNList::BuildSimplifiedDiff(const CDetermini
418415
return diffRet;
419416
}
420417

421-
CDeterministicMNList CDeterministicMNList::ApplyDiff(const CDeterministicMNListDiff& diff) const
418+
CDeterministicMNList CDeterministicMNList::ApplyDiff(const CBlockIndex* pindex, const CDeterministicMNListDiff& diff) const
422419
{
423-
assert(diff.prevBlockHash == blockHash && diff.nHeight == nHeight + 1);
424-
425420
CDeterministicMNList result = *this;
426-
result.blockHash = diff.blockHash;
427-
result.nHeight = diff.nHeight;
421+
result.blockHash = pindex->GetBlockHash();
422+
result.nHeight = pindex->nHeight;
428423

429424
for (const auto& id : diff.removedMns) {
430425
auto dmn = result.GetMNByInternalId(id);
@@ -544,9 +539,9 @@ bool CDeterministicMNManager::ProcessBlock(const CBlock& block, const CBlockInde
544539
oldList = GetListForBlock(pindex->pprev);
545540
diff = oldList.BuildDiff(newList);
546541

547-
evoDb.Write(std::make_pair(DB_LIST_DIFF, diff.blockHash), diff);
542+
evoDb.Write(std::make_pair(DB_LIST_DIFF, newList.GetBlockHash()), diff);
548543
if ((nHeight % SNAPSHOT_LIST_PERIOD) == 0 || oldList.GetHeight() == -1) {
549-
evoDb.Write(std::make_pair(DB_LIST_SNAPSHOT, diff.blockHash), newList);
544+
evoDb.Write(std::make_pair(DB_LIST_SNAPSHOT, newList.GetBlockHash()), newList);
550545
LogPrintf("CDeterministicMNManager::%s -- Wrote snapshot. nHeight=%d, mapCurMNs.allMNsCount=%d\n",
551546
__func__, nHeight, newList.GetAllMNsCount());
552547
}
@@ -929,7 +924,7 @@ CDeterministicMNList CDeterministicMNManager::GetListForBlock(const CBlockIndex*
929924
auto diffIndex = p.first;
930925
auto& diff = p.second;
931926
if (diff.HasChanges()) {
932-
snapshot = snapshot.ApplyDiff(diff);
927+
snapshot = snapshot.ApplyDiff(diffIndex, diff);
933928
} else {
934929
snapshot.SetBlockHash(diffIndex->GetBlockHash());
935930
snapshot.SetHeight(diffIndex->nHeight);
@@ -1013,9 +1008,6 @@ bool CDeterministicMNManager::UpgradeDiff(CDBBatch& batch, const CBlockIndex* pi
10131008
oldDiffData >> oldDiff;
10141009

10151010
CDeterministicMNListDiff newDiff;
1016-
newDiff.prevBlockHash = oldDiff.prevBlockHash;
1017-
newDiff.blockHash = oldDiff.blockHash;
1018-
newDiff.nHeight = oldDiff.nHeight;
10191011
size_t addedCount = 0;
10201012
for (auto& p : oldDiff.addedMNs) {
10211013
auto dmn = std::make_shared<CDeterministicMN>(*p.second);
@@ -1030,7 +1022,7 @@ bool CDeterministicMNManager::UpgradeDiff(CDBBatch& batch, const CBlockIndex* pi
10301022
}
10311023

10321024
// applies added/removed MNs
1033-
newMNList = curMNList.ApplyDiff(newDiff);
1025+
newMNList = curMNList.ApplyDiff(pindexNext, newDiff);
10341026

10351027
// manually apply updated MNs and calc new state diffs
10361028
for (auto& p : oldDiff.updatedMNs) {

src/evo/deterministicmns.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ class CDeterministicMNList
466466

467467
CDeterministicMNListDiff BuildDiff(const CDeterministicMNList& to) const;
468468
CSimplifiedMNListDiff BuildSimplifiedDiff(const CDeterministicMNList& to) const;
469-
CDeterministicMNList ApplyDiff(const CDeterministicMNListDiff& diff) const;
469+
CDeterministicMNList ApplyDiff(const CBlockIndex* pindex, const CDeterministicMNListDiff& diff) const;
470470

471471
void AddMN(const CDeterministicMNCPtr& dmn);
472472
void UpdateMN(const CDeterministicMNCPtr& oldDmn, const CDeterministicMNStateCPtr& pdmnState);
@@ -541,9 +541,6 @@ class CDeterministicMNList
541541
class CDeterministicMNListDiff
542542
{
543543
public:
544-
uint256 prevBlockHash;
545-
uint256 blockHash;
546-
int nHeight{-1};
547544
std::vector<CDeterministicMNCPtr> addedMNs;
548545
// keys are all relating to the internalId of MNs
549546
std::map<uint64_t, CDeterministicMNStateDiff> updatedMNs;
@@ -553,9 +550,6 @@ class CDeterministicMNListDiff
553550
template<typename Stream>
554551
void Serialize(Stream& s) const
555552
{
556-
s << prevBlockHash;
557-
s << blockHash;
558-
s << nHeight;
559553
s << addedMNs;
560554
WriteCompactSize(s, updatedMNs.size());
561555
for (const auto& p : updatedMNs) {
@@ -576,9 +570,6 @@ class CDeterministicMNListDiff
576570

577571
size_t tmp;
578572
uint64_t tmp2;
579-
s >> prevBlockHash;
580-
s >> blockHash;
581-
s >> nHeight;
582573
s >> addedMNs;
583574
tmp = ReadCompactSize(s);
584575
for (size_t i = 0; i < tmp; i++) {

0 commit comments

Comments
 (0)