mirror of
https://github.com/dashpay/dash.git
synced 2024-12-29 13:59:06 +01:00
working election system
This commit is contained in:
parent
93131d106e
commit
42bd3b436f
@ -1094,6 +1094,10 @@ bool AppInit2(boost::thread_group& threadGroup)
|
||||
|
||||
// ********************************************************* Step 10: setup DarkSend
|
||||
|
||||
//string strNode = "23.23.186.131";
|
||||
//CAddress addr;
|
||||
//ConnectNode(addr, strNode.c_str(), true);
|
||||
|
||||
fMasterNode = GetBoolArg("-masternode");
|
||||
if(fMasterNode) {printf("IS DARKSEND MASTER NODE\n");}
|
||||
|
||||
|
78
src/main.cpp
78
src/main.cpp
@ -54,6 +54,8 @@ unsigned int nCoinCacheSize = 5000;
|
||||
|
||||
// create DarkSend pools
|
||||
CDarkSendPool darkSendPool;
|
||||
std::vector<CMasterNode> darkSendMasterNodes;
|
||||
|
||||
|
||||
/** Fees smaller than this (in satoshi) are considered zero fee (for transaction creation) */
|
||||
int64 CTransaction::nMinTxFee = 100000;
|
||||
@ -2682,6 +2684,10 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl
|
||||
//might need to reset pool
|
||||
darkSendPool.CheckTimeout();
|
||||
|
||||
if(fMasterNode){
|
||||
RelayDarkDeclareWinner();
|
||||
}
|
||||
|
||||
printf("ProcessBlock: ACCEPTED\n");
|
||||
return true;
|
||||
}
|
||||
@ -3620,6 +3626,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
||||
pfrom->PushMessage("verack");
|
||||
pfrom->ssSend.SetVersion(min(pfrom->nVersion, PROTOCOL_VERSION));
|
||||
|
||||
pfrom->PushMessage("dseg");
|
||||
|
||||
if (!pfrom->fInbound)
|
||||
{
|
||||
// Advertise our address
|
||||
@ -3751,6 +3759,49 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
||||
}
|
||||
}
|
||||
|
||||
else if (strCommand == "dseg") { //DarkSend Election Get
|
||||
int count = darkSendMasterNodes.size()-1;
|
||||
int i = 0;
|
||||
|
||||
BOOST_FOREACH(const CMasterNode mn, darkSendMasterNodes) {
|
||||
printf("Sending master node entry\n");
|
||||
pfrom->PushMessage("dsee", mn.vin, mn.addr, count, i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
else if (strCommand == "dsee") { //DarkSend Election Entry
|
||||
CTxIn vin;
|
||||
CService addr;
|
||||
int count;
|
||||
int current;
|
||||
vRecv >> vin >> addr >> count >> current;
|
||||
|
||||
bool found = false;
|
||||
BOOST_FOREACH(const CMasterNode mn, darkSendMasterNodes) {
|
||||
if(mn.vin == vin) found = true;
|
||||
}
|
||||
if(found) return false;
|
||||
|
||||
printf("Got masternode entry %i %i\n", count, current);
|
||||
|
||||
CMasterNode mn(addr, vin);
|
||||
darkSendMasterNodes.push_back(mn);
|
||||
|
||||
if(count == current) ConnectToDarkSendMasterNodeWinner();
|
||||
}
|
||||
|
||||
else if (strCommand == "dsew") { //DarkSend Election Winner
|
||||
CTxIn vin;
|
||||
CService addr;
|
||||
vRecv >> vin >> addr;
|
||||
|
||||
printf("DarkSend Election Winner\n");
|
||||
ConnectToDarkSendMasterNodeWinner();
|
||||
|
||||
//ConnectNode((CAddress)addr, addr.ToString().c_str(), true);
|
||||
}
|
||||
|
||||
else if (strCommand == "addr")
|
||||
{
|
||||
vector<CAddress> vAddr;
|
||||
@ -5604,6 +5655,33 @@ bool CDarkSendPool::SignFinalTransaction(CTransaction& finalTransactionNew, CNod
|
||||
return true;
|
||||
}
|
||||
|
||||
void ConnectToDarkSendMasterNodeWinner(){
|
||||
int i = 0;
|
||||
uint256 score = INT_MAX;
|
||||
int winner = 0;
|
||||
|
||||
BOOST_FOREACH(CMasterNode mn, darkSendMasterNodes) {
|
||||
uint256 n = mn.CalculateScore();
|
||||
if(n < score){
|
||||
score = n;
|
||||
winner = i;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
LOCK(cs_vNodes);
|
||||
BOOST_FOREACH(CNode* pnode, vNodes)
|
||||
{
|
||||
if(!pnode->fDarkSendMaster)
|
||||
continue;
|
||||
|
||||
pnode->fDarkSendMaster = false;
|
||||
pnode->fDisconnect = true;
|
||||
}
|
||||
|
||||
ConnectNode((CAddress)darkSendMasterNodes[winner].addr, darkSendMasterNodes[winner].addr.ToString().c_str(), true);
|
||||
}
|
||||
|
||||
void ThreadCheckDarkSendPool()
|
||||
{
|
||||
// Make this thread recognisable as the wallet flushing thread
|
||||
|
28
src/main.h
28
src/main.h
@ -24,6 +24,7 @@ class CAddress;
|
||||
class CInv;
|
||||
class CNode;
|
||||
class CDarkSendPool;
|
||||
class CMasterNode;
|
||||
class CBitcoinAddress;
|
||||
|
||||
struct CBlockIndexWorkComparator;
|
||||
@ -106,6 +107,7 @@ extern int nScriptCheckThreads;
|
||||
extern bool fTxIndex;
|
||||
extern unsigned int nCoinCacheSize;
|
||||
extern CDarkSendPool darkSendPool;
|
||||
extern std::vector<CMasterNode> darkSendMasterNodes;
|
||||
extern CWallet pmainWallet;
|
||||
|
||||
// Settings
|
||||
@ -2294,6 +2296,30 @@ public:
|
||||
)
|
||||
};
|
||||
|
||||
|
||||
|
||||
class CMasterNode
|
||||
{
|
||||
public:
|
||||
CService addr;
|
||||
CTxIn vin;
|
||||
|
||||
CMasterNode(CService newAddr, CTxIn newVin)
|
||||
{
|
||||
addr = newAddr;
|
||||
newVin = newVin;
|
||||
}
|
||||
|
||||
uint256 CalculateScore()
|
||||
{
|
||||
if(pindexBest == NULL) return 0;
|
||||
|
||||
uint256 n = vin.prevout.hash > pindexBest->GetBlockHash() ? (vin.prevout.hash - pindexBest->GetBlockHash()) : (pindexBest->GetBlockHash() - vin.prevout.hash);
|
||||
printf(" -- MasterNode CalculateScore() = %s \n", n.ToString().c_str());
|
||||
return n;
|
||||
}
|
||||
};
|
||||
|
||||
class CDarkSendEntry
|
||||
{
|
||||
public:
|
||||
@ -2456,6 +2482,8 @@ public:
|
||||
|
||||
};
|
||||
|
||||
void ConnectToDarkSendMasterNodeWinner();
|
||||
|
||||
void ThreadCheckDarkSendPool();
|
||||
|
||||
|
||||
|
39
src/net.cpp
39
src/net.cpp
@ -409,6 +409,7 @@ void ThreadGetMyExternalIP(void* parg)
|
||||
{
|
||||
printf("GetMyExternalIP() returned %s\n", addrLocalHost.ToStringIP().c_str());
|
||||
AddLocal(addrLocalHost, LOCAL_HTTP);
|
||||
RelayDarkSendMasterNodeContestant();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1108,6 +1109,8 @@ void ThreadMapPort()
|
||||
{
|
||||
printf("UPnP: ExternalIPAddress = %s\n", externalIPAddress);
|
||||
AddLocal(CNetAddr(externalIPAddress), LOCAL_UPNP);
|
||||
|
||||
RelayDarkSendMasterNodeContestant();
|
||||
}
|
||||
else
|
||||
printf("UPnP: GetExternalIPAddress failed.\n");
|
||||
@ -1944,6 +1947,42 @@ void RelayTxPoolStatus(const int newState, const int newEntriesCount, const int
|
||||
}
|
||||
}
|
||||
|
||||
void RelayDarkDeclareWinner()
|
||||
{
|
||||
|
||||
CTxIn vin;
|
||||
CService addr;
|
||||
if(!GetLocal(addr)) return;
|
||||
|
||||
LOCK(cs_vNodes);
|
||||
BOOST_FOREACH(CNode* pnode, vNodes)
|
||||
{
|
||||
pnode->PushMessage("dsew", 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);
|
||||
|
@ -650,5 +650,7 @@ void RelayTxPoolFinalTransaction(const CTransaction& txNew);
|
||||
void RelayTxPoolIn(const CTxIn& in, const int64& nAmount, const CTransaction& txCollateral, const CTransaction& txSupporting, const CTxOut& out, const CTxOut& out2);
|
||||
void RelayTxPoolStatus(const int newState, const int newEntriesCount, const int newAccepted);
|
||||
void ResetDarkSendMembers();
|
||||
void RelayDarkDeclareWinner();
|
||||
void RelayDarkSendMasterNodeContestant();
|
||||
|
||||
#endif
|
||||
|
@ -127,7 +127,6 @@ Value darksendnode(const Array& params, bool fHelp)
|
||||
|
||||
string strNode = params[0].get_str();
|
||||
|
||||
printf("darksendnode\n");
|
||||
CAddress addr;
|
||||
ConnectNode(addr, strNode.c_str(), true);
|
||||
return Value::null;
|
||||
|
Loading…
Reference in New Issue
Block a user