Skip to content

Commit 0db3f57

Browse files
committed
[Consensus] Compatibility: sign/verify mnw with deterministic nodes
1 parent dbc19ff commit 0db3f57

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

src/masternode-payments.cpp

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -478,15 +478,31 @@ void CMasternodePayments::ProcessMessageMasternodePayments(CNode* pfrom, std::st
478478
return;
479479
}
480480

481-
const CMasternode* pmn = mnodeman.Find(winner.vinMasternode.prevout);
482-
if (!pmn || !winner.CheckSignature(pmn->pubKeyMasternode.GetID())) {
481+
// See if this winner was signed with a dmn or a legacy masternode
482+
bool fDeterministic{false};
483+
Optional<CKeyID> mnKeyID = nullopt;
484+
auto mnList = deterministicMNManager->GetListAtChainTip();
485+
auto dmn = mnList.GetMNByCollateral(winner.vinMasternode.prevout);
486+
if (dmn) {
487+
fDeterministic = true;
488+
mnKeyID = Optional<CKeyID>(dmn->pdmnState->keyIDOperator);
489+
} else {
490+
const CMasternode* pmn = mnodeman.Find(winner.vinMasternode.prevout);
491+
if (pmn) {
492+
mnKeyID = Optional<CKeyID>(pmn->pubKeyMasternode.GetID());
493+
}
494+
}
495+
496+
if (mnKeyID == nullopt || !winner.CheckSignature(*mnKeyID)) {
483497
if (masternodeSync.IsSynced()) {
484498
LogPrintf("CMasternodePayments::ProcessMessageMasternodePayments() : mnw - invalid signature\n");
485499
LOCK(cs_main);
486500
Misbehaving(pfrom->GetId(), 20);
487501
}
488502
// it could just be a non-synced masternode
489-
mnodeman.AskForMN(pfrom, winner.vinMasternode);
503+
if (!fDeterministic) {
504+
mnodeman.AskForMN(pfrom, winner.vinMasternode);
505+
}
490506
return;
491507
}
492508

@@ -693,13 +709,20 @@ void CMasternodePayments::CleanPaymentList(int mnCount, int nHeight)
693709

694710
bool CMasternodePayments::ProcessBlock(int nBlockHeight)
695711
{
712+
// No more mnw messages after transition to DMN
713+
if (deterministicMNManager->LegacyMNObsolete()) {
714+
return false;
715+
}
696716
if (!fMasterNode) return false;
697717

698-
if (activeMasternode.vin == nullopt)
699-
return error("%s: Active Masternode not initialized.", __func__);
718+
// Get the active masternode (operator) key
719+
CKey mnKey; CKeyID mnKeyID; CTxIn mnVin;
720+
if (!GetActiveMasternodeKeys(mnKey, mnKeyID, mnVin)) {
721+
return false;
722+
}
700723

701724
//reference node - hybrid mode
702-
int n = mnodeman.GetMasternodeRank(*(activeMasternode.vin), nBlockHeight - 100);
725+
int n = mnodeman.GetMasternodeRank(mnVin, nBlockHeight - 100);
703726

704727
if (n == -1) {
705728
LogPrint(BCLog::MASTERNODE, "CMasternodePayments::ProcessBlock - Unknown Masternode\n");
@@ -727,12 +750,9 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight)
727750
return false;
728751
}
729752

730-
CMasternodePaymentWinner newWinner(*(activeMasternode.vin), nBlockHeight);
753+
CMasternodePaymentWinner newWinner(mnVin, nBlockHeight);
731754
newWinner.AddPayee(pmn->GetPayeeScript());
732-
733-
CPubKey pubKeyMasternode; CKey keyMasternode;
734-
activeMasternode.GetKeys(keyMasternode, pubKeyMasternode);
735-
if (!newWinner.Sign(keyMasternode, pubKeyMasternode.GetID())) {
755+
if (!newWinner.Sign(mnKey, mnKeyID)) {
736756
LogPrintf("%s: Failed to sign masternode winner\n", __func__);
737757
return false;
738758
}

0 commit comments

Comments
 (0)