From 060729a0707a91f5dacfafcf5d7705623beacd9d Mon Sep 17 00:00:00 2001 From: random-zebra Date: Mon, 15 Mar 2021 15:30:10 +0100 Subject: [PATCH] [TierTwo] Connect ProUpReg payload management in dmn manager --- src/evo/deterministicmns.cpp | 27 +++++++++++++++++++++++++++ src/evo/deterministicmns.h | 19 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/evo/deterministicmns.cpp b/src/evo/deterministicmns.cpp index 520d3e3bdce4e..1fc349395962d 100644 --- a/src/evo/deterministicmns.cpp +++ b/src/evo/deterministicmns.cpp @@ -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(*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()); + } } } diff --git a/src/evo/deterministicmns.h b/src/evo/deterministicmns.h index 14e3e3e959f2b..86c79e8a63462 100644 --- a/src/evo/deterministicmns.h +++ b/src/evo/deterministicmns.h @@ -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; @@ -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;