Skip to content

Commit

Permalink
[TierTwo] Connect ProUpReg payload management in dmn manager
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed Jul 6, 2021
1 parent ceeaf31 commit 060729a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,33 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C
LogPrintf("CDeterministicMNManager::%s -- MN %s updated at height %d: %s\n",
__func__, pl.proTxHash.ToString(), nHeight, pl.ToString());
}

} else if (tx.nType == CTransaction::TxType::PROUPREG) {
ProUpRegPL pl;
if (!GetTxPayload(tx, pl)) {
return _state.DoS(100, false, REJECT_INVALID, "bad-protx-payload");
}

CDeterministicMNCPtr dmn = newList.GetMN(pl.proTxHash);
if (!dmn) {
return _state.DoS(100, false, REJECT_INVALID, "bad-protx-hash");
}
auto newState = std::make_shared<CDeterministicMNState>(*dmn->pdmnState);
if (newState->keyIDOperator != pl.keyIDOperator) {
// reset all operator related fields and put MN into PoSe-banned state in case the operator key changes
newState->ResetOperatorFields();
newState->BanIfNotBanned(nHeight);
}
newState->keyIDOperator = pl.keyIDOperator;
newState->keyIDVoting = pl.keyIDVoting;
newState->scriptPayout = pl.scriptPayout;

newList.UpdateMN(pl.proTxHash, newState);

if (debugLogs) {
LogPrintf("CDeterministicMNManager::%s -- MN %s updated at height %d: %s\n",
__func__, pl.proTxHash.ToString(), nHeight, pl.ToString());
}
}

}
Expand Down
19 changes: 19 additions & 0 deletions src/evo/deterministicmns.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class CDeterministicMNState
int nPoSeRevivedHeight{-1};
int nPoSeBanHeight{-1};
uint16_t nRevocationReason{0};
/* !TODO: after introducing ProUpRev enum:
uint16_t nRevocationReason{ProUpRevPL::REASON_NOT_SPECIFIED};
*/

// the block hash X blocks after registration, used in quorum calculations
uint256 confirmedHash;
Expand Down Expand Up @@ -77,6 +80,22 @@ class CDeterministicMNState
READWRITE(obj.scriptOperatorPayout);
}

void ResetOperatorFields()
{
keyIDOperator = CKeyID();
addr = CService();
scriptOperatorPayout = CScript();
nRevocationReason = 0;
/* !TODO: after introducing ProUpRev enum:
nRevocationReason = ProUpRevPL::REASON_NOT_SPECIFIED;
*/
}
void BanIfNotBanned(int height)
{
if (nPoSeBanHeight == -1) {
nPoSeBanHeight = height;
}
}
void UpdateConfirmedHash(const uint256& _proTxHash, const uint256& _confirmedHash)
{
confirmedHash = _confirmedHash;
Expand Down

0 comments on commit 060729a

Please sign in to comment.