mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 13:03:17 +01:00
FindRandomNotInVec - should give less failures then FindRandom on doauto
This commit is contained in:
parent
6c7d66f0c1
commit
36bb9d6e27
@ -1544,23 +1544,13 @@ bool CDarksendPool::DoAutomaticDenominating(bool fDryRun, bool ready)
|
||||
// otherwise, try one randomly
|
||||
while(i < 10)
|
||||
{
|
||||
CMasternode* pmn = mnodeman.FindRandom();
|
||||
CMasternode* pmn = mnodeman.FindRandomNotInVec(vecMasternodesUsed, MIN_POOL_PEER_PROTO_VERSION);
|
||||
if(pmn == NULL)
|
||||
{
|
||||
LogPrintf("DoAutomaticDenominating --- Masternode list is empty!\n");
|
||||
LogPrintf("DoAutomaticDenominating --- Can't find random masternode!\n");
|
||||
strAutoDenomResult = _("Can't find random Masternode.");
|
||||
return false;
|
||||
}
|
||||
//don't reuse Masternodes
|
||||
BOOST_FOREACH(CTxIn usedVin, vecMasternodesUsed) {
|
||||
if(pmn->vin == usedVin){
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(pmn->protocolVersion < MIN_POOL_PEER_PROTO_VERSION) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(pmn->nLastDsq != 0 &&
|
||||
pmn->nLastDsq + mnodeman.CountEnabled(MIN_POOL_PEER_PROTO_VERSION)/5 > mnodeman.nDsqCount){
|
||||
|
@ -441,13 +441,36 @@ CMasternode* CMasternodeMan::GetNextMasternodeInQueueForPayment(int nBlockHeight
|
||||
return pBestMasternode;
|
||||
}
|
||||
|
||||
CMasternode *CMasternodeMan::FindRandom()
|
||||
CMasternode *CMasternodeMan::FindRandomNotInVec(std::vector<CTxIn> &vecToExclude, int protocolVersion)
|
||||
{
|
||||
LOCK(cs);
|
||||
|
||||
if(size() == 0) return NULL;
|
||||
protocolVersion = protocolVersion == -1 ? masternodePayments.GetMinMasternodePaymentsProto() : protocolVersion;
|
||||
|
||||
return &vMasternodes[GetRandInt(vMasternodes.size())];
|
||||
int nCountEnabled = CountEnabled(protocolVersion);
|
||||
LogPrintf("CMasternodeMan::FindRandomNotInVec - nCountEnabled - vecToExclude.size() %d\n", nCountEnabled - vecToExclude.size());
|
||||
if(nCountEnabled - vecToExclude.size() < 1) return NULL;
|
||||
|
||||
int rand = GetRandInt(nCountEnabled - vecToExclude.size());
|
||||
LogPrintf("CMasternodeMan::FindRandomNotInVec - rand %d\n", rand);
|
||||
bool found;
|
||||
|
||||
BOOST_FOREACH(CMasternode &mn, vMasternodes) {
|
||||
if(mn.protocolVersion < protocolVersion || !mn.IsEnabled()) continue;
|
||||
found = false;
|
||||
BOOST_FOREACH(CTxIn &usedVin, vecToExclude) {
|
||||
if(mn.vin.prevout == usedVin.prevout) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(found) continue;
|
||||
if(--rand < 1) {
|
||||
return &mn;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CMasternode* CMasternodeMan::GetCurrentMasterNode(int mod, int64_t nBlockHeight, int minProtocol)
|
||||
|
@ -116,7 +116,7 @@ public:
|
||||
CMasternode* GetNextMasternodeInQueueForPayment(int nBlockHeight, bool fFilterSigTime=true);
|
||||
|
||||
/// Find a random entry
|
||||
CMasternode* FindRandom();
|
||||
CMasternode* FindRandomNotInVec(std::vector<CTxIn> &vecToExclude, int protocolVersion = -1);
|
||||
|
||||
/// Get the current winner for this block
|
||||
CMasternode* GetCurrentMasterNode(int mod=1, int64_t nBlockHeight=0, int minProtocol=0);
|
||||
|
Loading…
Reference in New Issue
Block a user