Skip to content

Commit

Permalink
Merge #2308: [Consensus] Compatibility code for MN payments + budget …
Browse files Browse the repository at this point in the history
…voting

04cd17e [QA][BUG] Fix test and rework setupDMN to return only proTx hash (random-zebra)
9aeeb76 [Test] Add test coverage for MN and DMN votes expiration removal. (furszy)
3f16936 [Test] Update tiertwo_mn_compatibility and check winners (random-zebra)
ad2cc30 [Consensus] Check against current hash when no payee is found (random-zebra)
ede4519 [Cleanup] Remove unused parameter in GetCurrentMasternode (random-zebra)
dd3bce9 [Tests] Raise regtest ping timeouts to 1/10th of mainnet value (random-zebra)
d616239 [Cleanup] Remove redundant checks in CMasternodePaymentWinner::IsValid (random-zebra)
0db3f57 [Consensus] Compatibility: sign/verify mnw with deterministic nodes (random-zebra)
dbc19ff [Refactor] Decouple getting active mn keys from VoteOnFinalizedBudgets (random-zebra)
971f1da [Consensus] DMN payment compatibility code (random-zebra)
acfa24b [Tests] Introduce tiertwo_dmn_compatibility functional test (random-zebra)
6ad7ea6 [BUG] Fix locking order between CDeterministicMNManager/CMasternodeman (random-zebra)
aa867d5 [RPC] Add DMN support to listmasternodes (random-zebra)
064f774 [RPC] getmasternodestatus for DMN (random-zebra)
8b10fc2 [P2P] Stop processing mnw messages when Legacy MN system is obsolete (random-zebra)
baf60c7 [Tests] governance_sync_basic sign final budget with DMN too (random-zebra)
474e0b2 [RPC][Refactoring] Use ProcessProposal(FinalBudget)Vote directly (random-zebra)
72c2a70 [RPC] Get all required keys before signing budgets (random-zebra)
0591957 [RPC][Refactoring] Mn final budget / proposal voting code de-duplication (random-zebra)
a7557f7 [Validation] Sign/Verify final budgets with DMNs (random-zebra)
6fcd53d [MN] Active MN manager: return key and dmn after validation (random-zebra)
5df5067 [Tests] tiertwo_governance_basic: add deterministic masternodes (random-zebra)
972d236 [RPC] Init Deterministic masternode on-demand (random-zebra)
f93bc0f [Budget] Validate proposal votes from deterministic masternodes (random-zebra)
c5b9e6f [RPC][Budget] Deterministic MNs: vote for proposals (random-zebra)
366bfd0 [RPC] Remove redundant checks for wallet existing/unlocked (random-zebra)

Pull request description:

  Extrated from #2267.
  This enables proposals and budget voting for DMNs.
  It also implements the compatibility code for masternode payments, to be used between v6 enforcement and SPORK_21 activation (when both systems coexist).

  Based on top of:
  - [x] #2275
  - [x] #2296

ACKs for top commit:
  furszy:
    ACK 04cd17e ☕.
  Fuzzbawls:
    ACK 04cd17e

Tree-SHA512: d9504fdd87a7cd05c385e08d51cde0566738bd8992b493ca77592f9b1d1254374d0c5d49d9278edb4525c5559f7e26496fc6b0dd846bbb3acb2164e330ccc92e
  • Loading branch information
random-zebra committed May 25, 2021
2 parents d95f524 + 04cd17e commit 6abc9b6
Show file tree
Hide file tree
Showing 26 changed files with 1,421 additions and 441 deletions.
65 changes: 62 additions & 3 deletions src/activemasternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "addrman.h"
#include "evo/providertx.h"
#include "evo/deterministicmns.h"
#include "masternode-sync.h"
#include "masternode.h"
#include "masternodeconfig.h"
Expand Down Expand Up @@ -67,10 +66,38 @@ OperationResult CActiveDeterministicMasternodeManager::SetOperatorKey(const std:
return OperationResult(true);
}

OperationResult CActiveDeterministicMasternodeManager::GetOperatorKey(CKey& key, CKeyID& keyID, CDeterministicMNCPtr& dmn) const
{
if (!IsReady()) {
return errorOut("Active masternode not ready");
}
dmn = deterministicMNManager->GetListAtChainTip().GetValidMN(info.proTxHash);
if (!dmn) {
return errorOut(strprintf("Active masternode %s not registered or PoSe banned", info.proTxHash.ToString()));
}
if (info.keyIDOperator != dmn->pdmnState->keyIDOperator) {
return errorOut("Active masternode operator key changed or revoked");
}
// return keys
key = info.keyOperator;
keyID = info.keyIDOperator;
return OperationResult(true);
}

void CActiveDeterministicMasternodeManager::Init()
{
if (!fMasterNode || !deterministicMNManager->IsDIP3Enforced())
// set masternode arg if called from RPC
if (!fMasterNode) {
gArgs.ForceSetArg("-masternode", "1");
fMasterNode = true;
}

if (!deterministicMNManager->IsDIP3Enforced()) {
state = MASTERNODE_ERROR;
strError = "Evo upgrade is not active yet.";
LogPrintf("%s -- ERROR: %s\n", __func__, strError);
return;
}

LOCK(cs_main);

Expand Down Expand Up @@ -109,6 +136,8 @@ void CActiveDeterministicMasternodeManager::Init()

LogPrintf("%s: proTxHash=%s, proTx=%s\n", __func__, dmn->proTxHash.ToString(), dmn->ToString());

info.proTxHash = dmn->proTxHash;

if (info.service != dmn->pdmnState->addr) {
state = MASTERNODE_ERROR;
strError = strprintf("Local address %s does not match the address from ProTx (%s)",
Expand All @@ -132,7 +161,6 @@ void CActiveDeterministicMasternodeManager::Init()
}
}

info.proTxHash = dmn->proTxHash;
state = MASTERNODE_READY;
}

Expand Down Expand Up @@ -260,6 +288,7 @@ void CActiveMasternode::ManageStatus()
return;
}

// !TODO: Legacy masternodes - remove after enforcement
LogPrint(BCLog::MASTERNODE, "CActiveMasternode::ManageStatus() - Begin\n");

// If a DMN has been registered with same collateral, disable me.
Expand Down Expand Up @@ -427,3 +456,33 @@ void CActiveMasternode::GetKeys(CKey& _privKeyMasternode, CPubKey& _pubKeyMaster
_privKeyMasternode = privKeyMasternode;
_pubKeyMasternode = pubKeyMasternode;
}

bool GetActiveMasternodeKeys(CKey& key, CKeyID& keyID, CTxIn& vin)
{
if (activeMasternodeManager != nullptr) {
// deterministic mn
CDeterministicMNCPtr dmn;
auto res = activeMasternodeManager->GetOperatorKey(key, keyID, dmn);
if (!res) {
LogPrint(BCLog::MNBUDGET,"%s: %s\n", __func__, res.getError());
return false;
}
vin = CTxIn(dmn->collateralOutpoint);
return true;
}

// legacy mn
if (activeMasternode.vin == nullopt) {
LogPrint(BCLog::MNBUDGET,"%s: Active Masternode not initialized\n", __func__);
return false;
}
if (activeMasternode.GetStatus() != ACTIVE_MASTERNODE_STARTED) {
LogPrint(BCLog::MNBUDGET,"%s: MN not started (%s)\n", __func__, activeMasternode.GetStatusMessage());
return false;
}
CPubKey mnPubKey;
activeMasternode.GetKeys(key, mnPubKey);
keyID = mnPubKey.GetID();
vin = *activeMasternode.vin;
return true;
}
7 changes: 7 additions & 0 deletions src/activemasternode.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "init.h"
#include "key.h"
#include "evo/deterministicmns.h"
#include "masternode.h"
#include "net.h"
#include "operationresult.h"
Expand Down Expand Up @@ -60,6 +61,9 @@ class CActiveDeterministicMasternodeManager : public CValidationInterface
void Reset(masternode_state_t _state);
// Sets the Deterministic Masternode Operator's private/public key
OperationResult SetOperatorKey(const std::string& strMNOperatorPrivKey);
// If the active masternode is ready, and the keyID matches with the registered one,
// return private key, keyID, and pointer to dmn.
OperationResult GetOperatorKey(CKey& key, CKeyID& keyID, CDeterministicMNCPtr& dmn) const;
void SetNullProTx() { info.proTxHash = UINT256_ZERO; }

const CActiveMasternodeInfo* GetInfo() const { return &info; }
Expand Down Expand Up @@ -112,4 +116,7 @@ class CActiveMasternode
void GetKeys(CKey& privKeyMasternode, CPubKey& pubKeyMasternode);
};

// Compatibility code: get keys for either legacy or deterministic masternode
bool GetActiveMasternodeKeys(CKey& key, CKeyID& keyID, CTxIn& vin);

#endif
Loading

0 comments on commit 6abc9b6

Please sign in to comment.