election improvements

This commit is contained in:
Evan 2014-04-03 11:59:33 -07:00
parent 1407db8382
commit 9a10446317
4 changed files with 82 additions and 66 deletions

View File

@ -2685,7 +2685,7 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl
darkSendPool.CheckTimeout();
if(fMasterNode){
RelayDarkDeclareWinner();
darkSendPool.RelayDarkDeclareWinner();
}
printf("ProcessBlock: ACCEPTED\n");
@ -5692,22 +5692,88 @@ void CDarkSendPool::DisconnectMasterNode(){
void CDarkSendPool::ConnectToBestMasterNode(){
int i = 0;
uint256 score = INT_MAX;
int winner = 0;
uint256 score = 0;
int winner = -1;
BOOST_FOREACH(CMasterNode mn, darkSendMasterNodes) {
uint256 n = mn.CalculateScore();
// GetTimeMillis()-mv.lastSeen <= 60000
if(n < score){
if(n > score){
score = n;
winner = i;
}
i++;
}
ConnectNode((CAddress)darkSendMasterNodes[winner].addr, darkSendMasterNodes[winner].addr.ToString().c_str(), true);
if(winner >= 0)
ConnectNode((CAddress)darkSendMasterNodes[winner].addr, darkSendMasterNodes[winner].addr.ToString().c_str(), true);
}
bool CDarkSendPool::GetMasterNodeVin(CTxIn& vin)
{
int64 nValueIn = 0;
CScript pubScript = CScript();
// try once before we try to denominate
if (!pwalletMain->SelectCoinsExactOutput(1000*COIN, vin, nValueIn, pubScript, false, NULL))
{
printf("I'm not a capable masternode\n");
return false;
}
return true;
}
void CDarkSendPool::RelayDarkDeclareWinner()
{
// Choose coins to use
CService addr;
if(!GetLocal(addr)) return;
CTxIn vin;
if(!GetMasterNodeVin(vin)) return;
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)
{
pnode->PushMessage("dsep", addr, vin);
}
}
void CDarkSendPool::ResetDarkSendMembers()
{
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)
{
pnode->fDarkSendMember = false;
}
}
void CDarkSendPool::RegisterAsMasterNode()
{
printf("RegisterAsMasterNode\n");
if(!fMasterNode) return;
CTxIn vin;
if(!GetMasterNodeVin(vin)) return;
CService addr;
if(GetLocal(addr)){
printf("Adding myself to masternode list\n");
CMasterNode mn(addr, vin);
darkSendMasterNodes.push_back(mn);
}
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)
{
pnode->PushMessage("dsee", addr, vin);
}
}
void ThreadCheckDarkSendPool()
{
// Make this thread recognisable as the wallet flushing thread

View File

@ -2489,6 +2489,12 @@ public:
bool IsConnectedToMasterNode();
void DisconnectMasterNode();
void ConnectToBestMasterNode();
bool GetMasterNodeVin(CTxIn& vin);
void RelayDarkDeclareWinner();
void ResetDarkSendMembers();
void RegisterAsMasterNode();
};
void ConnectToDarkSendMasterNodeWinner();

View File

@ -409,7 +409,7 @@ void ThreadGetMyExternalIP(void* parg)
{
printf("GetMyExternalIP() returned %s\n", addrLocalHost.ToStringIP().c_str());
AddLocal(addrLocalHost, LOCAL_HTTP);
RelayDarkSendMasterNodeContestant();
darkSendPool.RegisterAsMasterNode();
}
}
@ -1110,7 +1110,7 @@ void ThreadMapPort()
printf("UPnP: ExternalIPAddress = %s\n", externalIPAddress);
AddLocal(CNetAddr(externalIPAddress), LOCAL_UPNP);
RelayDarkSendMasterNodeContestant();
darkSendPool.RegisterAsMasterNode();
}
else
printf("UPnP: GetExternalIPAddress failed.\n");
@ -1946,59 +1946,3 @@ void RelayTxPoolStatus(const int newState, const int newEntriesCount, const int
pnode->PushMessage("dssu", newState, newEntriesCount, newAccepted);
}
}
void RelayDarkDeclareWinner()
{
// Choose coins to use
int64 nValueIn = 0;
CScript pubScript = CScript();
CTxIn vin;
CWalletTx wtxDenominate = CWalletTx();
// try once before we try to denominate
if (!SelectCoinsExactOutput(1000*COIN, vin, nValueIn, pubScript, false, coinControl))
{
//I'm not a capable masternode
return;
}
CService addr;
if(!GetLocal(addr)) return;
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)
{
pnode->PushMessage("dsep", addr, vin);
}
}
void RelayDarkSendMasterNodeContestant()
{
printf("RelayDarkSendMasterNodeContestant\n");
if(!fMasterNode) return;
CTxIn vin;
CService addr;
if(GetLocal(addr)){
printf("Adding myself to masternode list\n");
CMasterNode mn(addr, vin);
darkSendMasterNodes.push_back(mn);
}
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)
{
pnode->PushMessage("dsee", addr, vin);
}
}
void ResetDarkSendMembers()
{
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)
{
pnode->fDarkSendMember = false;
}
}

View File

@ -69,9 +69,6 @@ public:
class CWallet : public CCryptoKeyStore
{
private:
bool SelectCoins(int64 nTargetValue, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet, const CCoinControl *coinControl=NULL) const;
bool SelectCoinsWithoutDenomination(int64 nTargetValue, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet, const CCoinControl *coinControl=NULL) const;
bool SelectCoinsExactOutput(int64 nTargetValue, CTxIn& vin, int64& nValueRet, CScript& pubScript, bool confirmed, const CCoinControl* coinControl) const;
CWalletDB *pwalletdbEncryption;
@ -82,6 +79,9 @@ private:
int nWalletMaxVersion;
public:
bool SelectCoins(int64 nTargetValue, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet, const CCoinControl *coinControl=NULL) const;
bool SelectCoinsWithoutDenomination(int64 nTargetValue, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64& nValueRet, const CCoinControl *coinControl=NULL) const;
bool SelectCoinsExactOutput(int64 nTargetValue, CTxIn& vin, int64& nValueRet, CScript& pubScript, bool confirmed, const CCoinControl* coinControl) const;
bool SelectCoinsMoreThanOutput(int64 nTargetValue, CTxIn& vin, int64& nValueRet, CScript& pubScript, bool confirmed, const CCoinControl* coinControl) const;
mutable CCriticalSection cs_wallet;