Merge pull request #185 from UdjinM6/v0.11.2.x_fix_new_winner_selection

(v0.11.2.x) Fix payee selectoin on CMasternodePayments::ProcessBlock
This commit is contained in:
evan82 2015-02-16 12:47:31 -07:00
commit a3f4946788

View File

@ -731,50 +731,69 @@ void CMasternodePayments::CleanPaymentList()
bool CMasternodePayments::ProcessBlock(int nBlockHeight) bool CMasternodePayments::ProcessBlock(int nBlockHeight)
{ {
if(!enabled) return false; if(!enabled) return false;
CMasternodePaymentWinner winner; CMasternodePaymentWinner newWinner;
std::vector<CTxIn> vecLastPayments; std::vector<CTxIn> vecLastPayments;
int c = 0; BOOST_REVERSE_FOREACH(CMasternodePaymentWinner& winner, vWinning)
BOOST_REVERSE_FOREACH(CMasternodePaymentWinner& winner, vWinning){ {
//if we already have the same vin - we have one full payment cycle, break
if(vecLastPayments.size() > 0
&& std::find(vecLastPayments.begin(), vecLastPayments.end(), winner.vin) != vecLastPayments.end()) break;
vecLastPayments.push_back(winner.vin); vecLastPayments.push_back(winner.vin);
//if we have one full payment cycle, break
if(++c > (int)vecMasternodes.size()) break;
} }
std::random_shuffle ( vecMasternodes.begin(), vecMasternodes.end() ); std::random_shuffle ( vecMasternodes.begin(), vecMasternodes.end() );
BOOST_FOREACH(CMasterNode& mn, vecMasternodes) { BOOST_FOREACH(CMasterNode& mn, vecMasternodes)
{
bool found = false; bool found = false;
BOOST_FOREACH(CTxIn& vin, vecLastPayments) BOOST_FOREACH(CTxIn& vin, vecLastPayments)
if(mn.vin == vin) found = true; if(mn.vin == vin)
{
found = true;
break;
}
if(found) continue; if(found) continue;
mn.Check(); mn.Check();
if(!mn.IsEnabled()) { if(!mn.IsEnabled()) continue;
continue;
}
winner.score = 0; newWinner.score = 0;
winner.nBlockHeight = nBlockHeight; newWinner.nBlockHeight = nBlockHeight;
winner.vin = mn.vin; newWinner.vin = mn.vin;
winner.payee.SetDestination(mn.pubkey.GetID()); newWinner.payee.SetDestination(mn.pubkey.GetID());
break; break;
} }
//if we can't find someone to get paid, pick randomly //if we can't find new MN to get paid, pick first active MN counting back from the end of vecLastPayments list
if(winner.nBlockHeight == 0 && vecMasternodes.size() > 1) { if(newWinner.nBlockHeight == 0 && vecMasternodes.size() > 1)
winner.score = 0; {
winner.nBlockHeight = nBlockHeight; BOOST_REVERSE_FOREACH(CTxIn& vin, vecLastPayments)
winner.vin = vecMasternodes[0].vin; {
winner.payee.SetDestination(vecMasternodes[0].pubkey.GetID()); BOOST_FOREACH(CMasterNode& mn, vecMasternodes)
if(mn.vin == vin)
{
mn.Check();
if(!mn.IsEnabled()) break;
newWinner.score = 0;
newWinner.nBlockHeight = nBlockHeight;
newWinner.vin = vin;
newWinner.payee.SetDestination(mn.pubkey.GetID());
break;
} }
if(Sign(winner)){ if(newWinner.nBlockHeight != 0) break; // we found active MN
if(AddWinningMasternode(winner)){ }
Relay(winner); }
if(Sign(newWinner))
{
if(AddWinningMasternode(newWinner))
{
Relay(newWinner);
return true; return true;
} }
} }