evo: Avoid some unnecessary copying in BuildNewListFromBlock (#3594)

This commit is contained in:
dustinface 2020-07-10 03:25:41 +02:00 committed by GitHub
parent af2fbbccfb
commit a7f4f95f10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -670,9 +670,9 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C
// has been reached, but the block hash will then point to the block at nMasternodeMinimumConfirmations // has been reached, but the block hash will then point to the block at nMasternodeMinimumConfirmations
int nConfirmations = pindexPrev->nHeight - dmn->pdmnState->nRegisteredHeight; int nConfirmations = pindexPrev->nHeight - dmn->pdmnState->nRegisteredHeight;
if (nConfirmations >= Params().GetConsensus().nMasternodeMinimumConfirmations) { if (nConfirmations >= Params().GetConsensus().nMasternodeMinimumConfirmations) {
CDeterministicMNState newState = *dmn->pdmnState; auto newState = std::make_shared<CDeterministicMNState>(*dmn->pdmnState);
newState.UpdateConfirmedHash(dmn->proTxHash, pindexPrev->GetBlockHash()); newState->UpdateConfirmedHash(dmn->proTxHash, pindexPrev->GetBlockHash());
newList.UpdateMN(dmn->proTxHash, std::make_shared<CDeterministicMNState>(newState)); newList.UpdateMN(dmn->proTxHash, newState);
} }
}); });
@ -730,17 +730,14 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C
} }
dmn->nOperatorReward = proTx.nOperatorReward; dmn->nOperatorReward = proTx.nOperatorReward;
dmn->pdmnState = std::make_shared<CDeterministicMNState>(proTx);
CDeterministicMNState dmnState = *dmn->pdmnState;
dmnState.nRegisteredHeight = nHeight;
auto dmnState = std::make_shared<CDeterministicMNState>(proTx);
dmnState->nRegisteredHeight = nHeight;
if (proTx.addr == CService()) { if (proTx.addr == CService()) {
// start in banned pdmnState as we need to wait for a ProUpServTx // start in banned pdmnState as we need to wait for a ProUpServTx
dmnState.nPoSeBanHeight = nHeight; dmnState->nPoSeBanHeight = nHeight;
} }
dmn->pdmnState = dmnState;
dmn->pdmnState = std::make_shared<CDeterministicMNState>(dmnState);
newList.AddMN(dmn); newList.AddMN(dmn);