Implement projection of MN reward winners in "masternode winners"

This commit is contained in:
Alexander Block 2018-04-04 17:20:54 +02:00
parent e6b699bc26
commit 44706dc88a
3 changed files with 56 additions and 26 deletions

View File

@ -254,13 +254,10 @@ void FillBlockPayments(CMutableTransaction& txNew, int nBlockHeight, CAmount blo
nBlockHeight, blockReward, voutMasternodeStr, txNew.ToString()); nBlockHeight, blockReward, voutMasternodeStr, txNew.ToString());
} }
std::string GetRequiredPaymentsString(int nBlockHeight) std::string GetLegacyRequiredPaymentsString(int nBlockHeight)
{ {
// IF WE HAVE A ACTIVATED TRIGGER FOR THIS HEIGHT - IT IS A SUPERBLOCK, GET THE REQUIRED PAYEES // IF WE HAVE A ACTIVATED TRIGGER FOR THIS HEIGHT - IT IS A SUPERBLOCK, GET THE REQUIRED PAYEES
if(CSuperblockManager::IsSuperblockTriggered(nBlockHeight)) { if(CSuperblockManager::IsSuperblockTriggered(nBlockHeight)) {
if (deterministicMNManager->IsDeterministicMNsSporkActive(nBlockHeight)) {
return mnpayments.GetRequiredPaymentsString(nBlockHeight) + ", " + CSuperblockManager::GetRequiredPaymentsString(nBlockHeight);
}
return CSuperblockManager::GetRequiredPaymentsString(nBlockHeight); return CSuperblockManager::GetRequiredPaymentsString(nBlockHeight);
} }
@ -268,6 +265,54 @@ std::string GetRequiredPaymentsString(int nBlockHeight)
return mnpayments.GetRequiredPaymentsString(nBlockHeight); return mnpayments.GetRequiredPaymentsString(nBlockHeight);
} }
std::string GetRequiredPaymentsString(int nBlockHeight, const CDeterministicMNCPtr &payee)
{
std::string strPayee = "Unknown";
if (payee) {
CTxDestination dest;
if (!ExtractDestination(payee->pdmnState->scriptPayout, dest))
assert(false);
strPayee = CBitcoinAddress(dest).ToString();
}
if (CSuperblockManager::IsSuperblockTriggered(nBlockHeight)) {
strPayee += ", " + CSuperblockManager::GetRequiredPaymentsString(nBlockHeight);
}
return strPayee;
}
std::map<int, std::string> GetRequiredPaymentsStrings(int nStartHeight, int nEndHeight)
{
std::map<int, std::string> mapPayments;
LOCK(cs_main);
int nChainTipHeight = chainActive.Height();
bool doProjection = false;
for(int h = nStartHeight; h < nEndHeight; h++) {
if (deterministicMNManager->IsDeterministicMNsSporkActive(h)) {
if (h <= nChainTipHeight) {
auto payee = deterministicMNManager->GetListForBlock(chainActive[h - 1]->GetBlockHash()).GetMNPayee();
mapPayments.emplace(h, GetRequiredPaymentsString(h, payee));
} else {
doProjection = true;
break;
}
} else {
mapPayments.emplace(h, GetLegacyRequiredPaymentsString(h));
}
}
if (doProjection) {
auto projection = deterministicMNManager->GetListAtChainTip().GetProjectedMNPayees(nEndHeight - nChainTipHeight);
for (size_t i = 0; i < projection.size(); i++) {
auto payee = projection[i];
int h = nChainTipHeight + 1 + i;
mapPayments.emplace(h, GetRequiredPaymentsString(h, payee));
}
}
return mapPayments;
}
void CMasternodePayments::Clear() void CMasternodePayments::Clear()
{ {
LOCK2(cs_mapMasternodeBlocks, cs_mapMasternodePaymentVotes); LOCK2(cs_mapMasternodeBlocks, cs_mapMasternodePaymentVotes);
@ -731,22 +776,9 @@ std::string CMasternodeBlockPayees::GetRequiredPaymentsString() const
std::string CMasternodePayments::GetRequiredPaymentsString(int nBlockHeight) const std::string CMasternodePayments::GetRequiredPaymentsString(int nBlockHeight) const
{ {
if (deterministicMNManager->IsDeterministicMNsSporkActive(nBlockHeight)) { LOCK(cs_mapMasternodeBlocks);
LOCK(cs_main); const auto it = mapMasternodeBlocks.find(nBlockHeight);
auto pindex = chainActive[nBlockHeight - 1]; return it == mapMasternodeBlocks.end() ? "Unknown" : it->second.GetRequiredPaymentsString();
auto payee = deterministicMNManager->GetListForBlock(pindex->GetBlockHash()).GetMNPayee();
if (!payee) {
return "Unknown";
}
CTxDestination dest;
if (!ExtractDestination(payee->pdmnState->scriptPayout, dest))
assert(false);
return CBitcoinAddress(dest).ToString();
} else {
LOCK(cs_mapMasternodeBlocks);
const auto it = mapMasternodeBlocks.find(nBlockHeight);
return it == mapMasternodeBlocks.end() ? "Unknown" : it->second.GetRequiredPaymentsString();
}
} }
bool CMasternodePayments::IsTransactionValid(const CTransaction& txNew, int nBlockHeight, CAmount blockReward) const bool CMasternodePayments::IsTransactionValid(const CTransaction& txNew, int nBlockHeight, CAmount blockReward) const

View File

@ -36,7 +36,7 @@ extern CMasternodePayments mnpayments;
bool IsBlockValueValid(const CBlock& block, int nBlockHeight, CAmount blockReward, std::string& strErrorRet); bool IsBlockValueValid(const CBlock& block, int nBlockHeight, CAmount blockReward, std::string& strErrorRet);
bool IsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight, CAmount blockReward); bool IsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight, CAmount blockReward);
void FillBlockPayments(CMutableTransaction& txNew, int nBlockHeight, CAmount blockReward, std::vector<CTxOut>& voutMasternodePaymentsRet, std::vector<CTxOut>& voutSuperblockPaymentsRet); void FillBlockPayments(CMutableTransaction& txNew, int nBlockHeight, CAmount blockReward, std::vector<CTxOut>& voutMasternodePaymentsRet, std::vector<CTxOut>& voutSuperblockPaymentsRet);
std::string GetRequiredPaymentsString(int nBlockHeight); std::map<int, std::string> GetRequiredPaymentsStrings(int nStartHeight, int nEndHeight);
class CMasternodePayee class CMasternodePayee
{ {

View File

@ -801,11 +801,9 @@ UniValue masternode_winners(const JSONRPCRequest& request)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'masternode winners ( \"count\" \"filter\" )'"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'masternode winners ( \"count\" \"filter\" )'");
UniValue obj(UniValue::VOBJ); UniValue obj(UniValue::VOBJ);
auto mapPayments = GetRequiredPaymentsStrings(nHeight - nLast, nHeight + 20);
for (int i = nHeight - nLast; i < nHeight + 20; i++) { for (const auto &p : mapPayments) {
std::string strPayment = GetRequiredPaymentsString(i); obj.push_back(Pair(strprintf("%d", p.first), p.second));
if (strFilter !="" && strPayment.find(strFilter) == std::string::npos) continue;
obj.push_back(Pair(strprintf("%d", i), strPayment));
} }
return obj; return obj;