Merge remote-tracking branch 'upstream/v0.11.2.x' into v0.11.2.x

This commit is contained in:
snogcel 2015-02-26 22:02:04 -07:00
commit 8001c48c71
13 changed files with 124 additions and 93 deletions

View File

@ -51,9 +51,10 @@ int RequestedMasterNodeList = 0;
void ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream& vRecv)
{
if(fLiteMode) return; //disable all darksend/masternode related functionality
if(IsInitialBlockDownload()) return;
if (strCommand == "dsf") { //DarkSend Final tx
if (pfrom->nVersion < darkSendPool.MIN_PEER_PROTO_VERSION) {
if (pfrom->nVersion < MIN_POOL_PEER_PROTO_VERSION) {
return;
}
@ -76,7 +77,7 @@ void ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream&
}
else if (strCommand == "dsc") { //DarkSend Complete
if (pfrom->nVersion < darkSendPool.MIN_PEER_PROTO_VERSION) {
if (pfrom->nVersion < MIN_POOL_PEER_PROTO_VERSION) {
return;
}
@ -100,7 +101,7 @@ void ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream&
else if (strCommand == "dsa") { //DarkSend Acceptable
if (pfrom->nVersion < darkSendPool.MIN_PEER_PROTO_VERSION) {
if (pfrom->nVersion < MIN_POOL_PEER_PROTO_VERSION) {
std::string strError = _("Incompatible version.");
LogPrintf("dsa -- incompatible version! \n");
pfrom->PushMessage("dssu", darkSendPool.sessionID, darkSendPool.GetState(), darkSendPool.GetEntriesCount(), MASTERNODE_REJECTED, strError);
@ -131,7 +132,7 @@ void ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream&
if(darkSendPool.sessionUsers == 0) {
if(pmn->nLastDsq != 0 &&
pmn->nLastDsq + mnodeman.CountMasternodesAboveProtocol(darkSendPool.MIN_PEER_PROTO_VERSION)/5 > darkSendPool.nDsqCount){
pmn->nLastDsq + mnodeman.CountMasternodesAboveProtocol(MIN_POOL_PEER_PROTO_VERSION)/5 > darkSendPool.nDsqCount){
LogPrintf("dsa -- last dsq too recent, must wait. %s \n", pmn->addr.ToString().c_str());
std::string strError = _("Last Darksend was too recent.");
pfrom->PushMessage("dssu", darkSendPool.sessionID, darkSendPool.GetState(), darkSendPool.GetEntriesCount(), MASTERNODE_REJECTED, strError);
@ -151,7 +152,7 @@ void ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream&
}
} else if (strCommand == "dsq") { //DarkSend Queue
if (pfrom->nVersion < darkSendPool.MIN_PEER_PROTO_VERSION) {
if (pfrom->nVersion < MIN_POOL_PEER_PROTO_VERSION) {
return;
}
@ -185,7 +186,7 @@ void ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream&
if(fDebug) LogPrintf("dsq last %d last2 %d count %d\n", pmn->nLastDsq, pmn->nLastDsq + mnodeman.size()/5, darkSendPool.nDsqCount);
//don't allow a few nodes to dominate the queuing process
if(pmn->nLastDsq != 0 &&
pmn->nLastDsq + mnodeman.CountMasternodesAboveProtocol(darkSendPool.MIN_PEER_PROTO_VERSION)/5 > darkSendPool.nDsqCount){
pmn->nLastDsq + mnodeman.CountMasternodesAboveProtocol(MIN_POOL_PEER_PROTO_VERSION)/5 > darkSendPool.nDsqCount){
if(fDebug) LogPrintf("dsq -- masternode sending too many dsq messages. %s \n", pmn->addr.ToString().c_str());
return;
}
@ -201,7 +202,7 @@ void ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream&
} else if (strCommand == "dsi") { //DarkSend vIn
std::string error = "";
if (pfrom->nVersion < darkSendPool.MIN_PEER_PROTO_VERSION) {
if (pfrom->nVersion < MIN_POOL_PEER_PROTO_VERSION) {
LogPrintf("dsi -- incompatible version! \n");
error = _("Incompatible version.");
pfrom->PushMessage("dssu", darkSendPool.sessionID, darkSendPool.GetState(), darkSendPool.GetEntriesCount(), MASTERNODE_REJECTED, error);
@ -323,7 +324,7 @@ void ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream&
}
else if (strCommand == "dssub") { //DarkSend Subscribe To
if (pfrom->nVersion < darkSendPool.MIN_PEER_PROTO_VERSION) {
if (pfrom->nVersion < MIN_POOL_PEER_PROTO_VERSION) {
return;
}
@ -336,7 +337,7 @@ void ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream&
else if (strCommand == "dssu") { //DarkSend status update
if (pfrom->nVersion < darkSendPool.MIN_PEER_PROTO_VERSION) {
if (pfrom->nVersion < MIN_POOL_PEER_PROTO_VERSION) {
return;
}
@ -364,7 +365,7 @@ void ProcessMessageDarksend(CNode* pfrom, std::string& strCommand, CDataStream&
}
else if (strCommand == "dss") { //DarkSend Sign Final Tx
if (pfrom->nVersion < darkSendPool.MIN_PEER_PROTO_VERSION) {
if (pfrom->nVersion < MIN_POOL_PEER_PROTO_VERSION) {
return;
}
@ -1543,7 +1544,7 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready)
int protocolVersion;
if(!dsq.GetProtocolVersion(protocolVersion)) continue;
if(protocolVersion < MIN_PEER_PROTO_VERSION) continue;
if(protocolVersion < MIN_POOL_PEER_PROTO_VERSION) continue;
//non-denom's are incompatible
if((dsq.nDenom & (1 << 4))) continue;
@ -1563,12 +1564,11 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready)
// connect to masternode and submit the queue request
if(ConnectNode((CAddress)addr, NULL, true)){
submittedToMasternode = addr;
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)
{
if((CNetAddr)pnode->addr != (CNetAddr)submittedToMasternode) continue;
if((CNetAddr)pnode->addr != (CNetAddr)addr) continue;
std::string strReason;
if(txCollateral == CTransaction()){
@ -1578,6 +1578,7 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready)
}
}
submittedToMasternode = addr;
vecMasternodesUsed.push_back(dsq.vin);
sessionDenom = dsq.nDenom;
@ -1601,34 +1602,38 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready)
// otherwise, try one randomly
while(i < 10)
{
CMasternode* mn = mnodeman.FindRandom();
CMasternode* pmn = mnodeman.FindRandom();
if(pmn == NULL)
{
LogPrintf("DoAutomaticDenominating --- masternode list is empty!\n");
return false;
}
//don't reuse masternodes
BOOST_FOREACH(CTxIn usedVin, vecMasternodesUsed) {
if(mn->vin == usedVin){
if(pmn->vin == usedVin){
i++;
continue;
}
}
if(mn->protocolVersion < darkSendPool.MIN_PEER_PROTO_VERSION) {
if(pmn->protocolVersion < MIN_POOL_PEER_PROTO_VERSION) {
i++;
continue;
}
if(mn->nLastDsq != 0 &&
mn->nLastDsq + mnodeman.CountMasternodesAboveProtocol(darkSendPool.MIN_PEER_PROTO_VERSION)/5 > darkSendPool.nDsqCount){
if(pmn->nLastDsq != 0 &&
pmn->nLastDsq + mnodeman.CountMasternodesAboveProtocol(MIN_POOL_PEER_PROTO_VERSION)/5 > darkSendPool.nDsqCount){
i++;
continue;
}
lastTimeChanged = GetTimeMillis();
submittedToMasternode = mn->addr;
LogPrintf("DoAutomaticDenominating -- attempt %d connection to masternode %s\n", i, mn->addr.ToString().c_str());
if(ConnectNode((CAddress)mn->addr, NULL, true)){
LogPrintf("DoAutomaticDenominating -- attempt %d connection to masternode %s\n", i, pmn->addr.ToString().c_str());
if(ConnectNode((CAddress)pmn->addr, NULL, true)){
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)
{
if((CNetAddr)pnode->addr != (CNetAddr)mn->addr) continue;
if((CNetAddr)pnode->addr != (CNetAddr)pmn->addr) continue;
std::string strReason;
if(txCollateral == CTransaction()){
@ -1638,7 +1643,8 @@ bool CDarkSendPool::DoAutomaticDenominating(bool fDryRun, bool ready)
}
}
vecMasternodesUsed.push_back(mn->vin);
submittedToMasternode = pmn->addr;
vecMasternodesUsed.push_back(pmn->vin);
std::vector<int64_t> vecAmounts;
pwalletMain->ConvertList(vCoins, vecAmounts);
@ -2193,7 +2199,7 @@ void ThreadCheckDarkSendPool()
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)
{
if (pnode->nVersion >= darkSendPool.MIN_PEER_PROTO_VERSION) {
if (pnode->nVersion >= MIN_POOL_PEER_PROTO_VERSION) {
//keep track of who we've asked for the list
if(pnode->HasFulfilledRequest("mnsync")) continue;

View File

@ -38,6 +38,8 @@ class CActiveMasternode;
#define DARKSEND_QUEUE_TIMEOUT 120
#define DARKSEND_SIGNING_TIMEOUT 30
static const int MIN_POOL_PEER_PROTO_VERSION = 70067; // minimum peer version accepted by DarkSendPool
extern CDarkSendPool darkSendPool;
extern CDarkSendSigner darkSendSigner;
extern std::vector<CDarksendQueue> vecDarksendQueue;
@ -222,7 +224,6 @@ class CDarksendSession
class CDarkSendPool
{
public:
static const int MIN_PEER_PROTO_VERSION = 70066;
// clients entries
std::vector<CDarkSendEntry> myEntries;

View File

@ -37,6 +37,7 @@ void ProcessMessageInstantX(CNode* pfrom, std::string& strCommand, CDataStream&
{
if(fLiteMode) return; //disable all darksend/masternode related functionality
if(!IsSporkActive(SPORK_2_INSTANTX)) return;
if(IsInitialBlockDownload()) return;
if (strCommand == "txlreq")
{

View File

@ -4826,6 +4826,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
//probably one the extensions
ProcessMessageDarksend(pfrom, strCommand, vRecv);
mnodeman.ProcessMessage(pfrom, strCommand, vRecv);
ProcessMessageMasternodePayments(pfrom, strCommand, vRecv);
ProcessMessageInstantX(pfrom, strCommand, vRecv);
ProcessSpork(pfrom, strCommand, vRecv);
}

View File

@ -21,6 +21,8 @@ std::map<int64_t, uint256> mapCacheBlockHashes;
void ProcessMessageMasternodePayments(CNode* pfrom, std::string& strCommand, CDataStream& vRecv)
{
if(IsInitialBlockDownload()) return;
if (strCommand == "mnget") { //Masternode Payments Request Sync
if(fLiteMode) return; //disable all darksend/masternode related functionality

View File

@ -276,47 +276,5 @@ public:
bool GetBlockPayee(int nBlockHeight, CScript& payee);
};
/*//
// Masternode Scanning Error
// Enforces proof-of-service by scanning the masternode network
//
class CMasternodePayments
{
private:
std::vector<CMasternodePaymentWinner> vWinning;
int nSyncedFromPeer;
std::string strMasterPrivKey;
std::string strTestPubKey;
std::string strMainPubKey;
public:
CMasternodePayments() {
strMainPubKey = "04549ac134f694c0243f503e8c8a9a986f5de6610049c40b07816809b0d1d06a21b07be27b9bb555931773f62ba6cf35a25fd52f694d4e1106ccd237a7bb899fdd";
strTestPubKey = "046f78dcf911fbd61910136f7f0f8d90578f68d0b3ac973b5040fb7afb501b5939f39b108b0569dca71488f5bbf498d92e4d1194f6f941307ffd95f75e76869f0e";
}
bool SetPrivKey(std::string strPrivKey);
bool CheckSignature(CMasternodePaymentWinner& winner);
bool Sign(CMasternodePaymentWinner& winner);
// Deterministically calculate a given "score" for a masternode depending on how close it's hash is
// to the blockHeight. The further away they are the better, the furthest will win the election
// and get paid this block
//
uint64_t CalculateScore(uint256 blockHash, CTxIn& vin);
bool GetWinningMasternode(int nBlockHeight, CTxIn& vinOut);
bool AddWinningMasternode(CMasternodePaymentWinner& winner);
bool ProcessBlock(int nBlockHeight);
void Relay(CMasternodePaymentWinner& winner);
void Sync(CNode* node);
void CleanPaymentList();
int LastPayment(CMasterNode& mn);
//slow
bool GetBlockPayee(int nBlockHeight, CScript& payee);
};*/
#endif

View File

@ -175,25 +175,31 @@ void CMasternodeMan::CheckAndRemove()
// check who's asked for the masternode list
map<CNetAddr, int64_t>::iterator it1 = mAskedUsForMasternodeList.begin();
while(it1 != mAskedUsForMasternodeList.end()){
if((*it1).second < GetTime())
it1 = mAskedUsForMasternodeList.erase(it1);
else ++it1;
if((*it1).second < GetTime()) {
mAskedUsForMasternodeList.erase(it1++);
} else {
++it1;
}
}
// check who we asked for the masternode list
it1 = mWeAskedForMasternodeList.begin();
while(it1 != mWeAskedForMasternodeList.end()){
if((*it1).second < GetTime())
it1 = mWeAskedForMasternodeList.erase(it1);
else ++it1;
if((*it1).second < GetTime()){
mWeAskedForMasternodeList.erase(it1++);
} else {
++it1;
}
}
// check which masternodes we've asked for
map<COutPoint, int64_t>::iterator it2 = mWeAskedForMasternodeListEntry.begin();
while(it2 != mWeAskedForMasternodeListEntry.end()){
if((*it2).second < GetTime())
it2 = mWeAskedForMasternodeListEntry.erase(it2);
else ++it2;
if((*it2).second < GetTime()){
mWeAskedForMasternodeListEntry.erase(it2++);
} else {
++it2;
}
}
}
@ -225,6 +231,8 @@ int CMasternodeMan::CountMasternodesAboveProtocol(int protocolVersion)
void CMasternodeMan::DsegUpdate(CNode* pnode)
{
LOCK(cs);
std::map<CNetAddr, int64_t>::iterator it = mWeAskedForMasternodeList.find(pnode->addr);
if (it != mWeAskedForMasternodeList.end())
{

View File

@ -84,7 +84,7 @@ public:
void CheckAndRemove();
// Clear masternode vector
void Clear() { vMasternodes.clear(); }
void Clear() { LOCK(cs); vMasternodes.clear(); }
int CountEnabled();

View File

@ -95,7 +95,28 @@ Value masternode(const Array& params, bool fHelp)
(strCommand != "start" && strCommand != "start-alias" && strCommand != "start-many" && strCommand != "stop" && strCommand != "stop-alias" && strCommand != "stop-many" && strCommand != "list" && strCommand != "list-conf" && strCommand != "count" && strCommand != "enforce"
&& strCommand != "debug" && strCommand != "current" && strCommand != "winners" && strCommand != "genkey" && strCommand != "connect" && strCommand != "outputs"))
throw runtime_error(
"masternode <start|start-alias|start-many|stop|stop-alias|stop-many|list|list-conf|count|debug|current|winners|genkey|enforce|outputs> [passphrase]\n");
"masternode \"command\"... ( \"passphrase\" )\n"
"Set of commands to execute masternode related actions\n"
"\nArguments:\n"
"1. \"command\" (string or set of strings, required) The command to execute\n"
"2. \"passphrase\" (string, optional) The wallet passphrase\n"
"\nAvailable commands:\n"
" count - Print number of all known masternodes (optional: 'enabled', 'both')\n"
" current - Print info on current masternode winner\n"
" debug - Print masternode status\n"
" genkey - Generate new masternodeprivkey\n"
" enforce - Enforce masternode payments\n"
" outputs - Print masternode compatible outputs\n"
" start - Start masternode configured in darkcoin.conf\n"
" start-alias - Start single masternode by assigned alias configured in masternode.conf\n"
" start-many - Start all masternodes configured in masternode.conf\n"
" stop - Stop masternode configured in darkcoin.conf\n"
" stop-alias - Stop single masternode by assigned alias configured in masternode.conf\n"
" stop-many - Stop all masternodes configured in masternode.conf\n"
" list - Print list of all known masternodes (see masternodelist for more info)\n"
" list-conf - Print masternode.conf in JSON format\n"
" winners - Print list of masternode winners\n"
);
if (strCommand == "stop")
{
@ -250,7 +271,11 @@ Value masternode(const Array& params, bool fHelp)
throw runtime_error(
"too many parameters\n");
}
if (params.size() == 2) return mnodeman.CountEnabled();
if (params.size() == 2)
{
if(params[1] == "enabled") return mnodeman.CountEnabled();
if(params[1] == "both") return boost::lexical_cast<std::string>(mnodeman.CountEnabled()) + " / " + boost::lexical_cast<std::string>(mnodeman.size());
}
return mnodeman.size();
}
@ -431,7 +456,20 @@ Value masternode(const Array& params, bool fHelp)
{
CMasternode* winner = mnodeman.GetCurrentMasterNode(1);
if(winner) {
return winner->addr.ToString().c_str();
Object obj;
CScript pubkey;
pubkey.SetDestination(winner->pubkey.GetID());
CTxDestination address1;
ExtractDestination(pubkey, address1);
CBitcoinAddress address2(address1);
obj.push_back(Pair("IP:port", winner->addr.ToString().c_str()));
obj.push_back(Pair("protocol", (int64_t)winner->protocolVersion));
obj.push_back(Pair("vin", winner->vin.prevout.hash.ToString().c_str()));
obj.push_back(Pair("pubkey", address2.ToString().c_str()));
obj.push_back(Pair("lastseen", (int64_t)winner->lastTimeSeen));
obj.push_back(Pair("activeseconds", (int64_t)(winner->lastTimeSeen - winner->now)));
return obj;
}
return "unknown";
@ -543,7 +581,7 @@ Value masternodelist(const Array& params, bool fHelp)
"\nArguments:\n"
"1. \"mode\" (string, optional, defauls = active) The mode to run list in\n"
"2. \"filter\" (string, optional) Filter results, can be applied in few modes only\n"
"Available modes:\n"
"\nAvailable modes:\n"
" active - Print '1' if active and '0' otherwise (can be filtered, exact match)\n"
" activeseconds - Print number of seconds masternode recognized by the network as enabled\n"
" full - Print info in format 'active | protocol | pubkey | vin | lastseen | activeseconds' (can be filtered, partial match)\n"
@ -561,10 +599,12 @@ Value masternodelist(const Array& params, bool fHelp)
std::string strAddr = mn.addr.ToString().c_str();
if(strMode == "active"){
if(strFilter !="" && stoi(strFilter) != mn.IsEnabled()) continue;
if(strFilter !="" && strFilter != boost::lexical_cast<std::string>(mn.IsEnabled()) &&
mn.addr.ToString().find(strFilter) == string::npos) continue;
obj.push_back(Pair(strAddr, (int)mn.IsEnabled()));
} else if (strMode == "vin") {
if(strFilter !="" && mn.vin.prevout.hash.ToString().find(strFilter) == string::npos) continue;
if(strFilter !="" && mn.vin.prevout.hash.ToString().find(strFilter) == string::npos &&
mn.addr.ToString().find(strFilter) == string::npos) continue;
obj.push_back(Pair(strAddr, mn.vin.prevout.hash.ToString().c_str()));
} else if (strMode == "pubkey") {
CScript pubkey;
@ -573,16 +613,23 @@ Value masternodelist(const Array& params, bool fHelp)
ExtractDestination(pubkey, address1);
CBitcoinAddress address2(address1);
if(strFilter !="" && address2.ToString().find(strFilter) == string::npos) continue;
if(strFilter !="" && address2.ToString().find(strFilter) == string::npos &&
mn.addr.ToString().find(strFilter) == string::npos) continue;
obj.push_back(Pair(strAddr, address2.ToString().c_str()));
} else if (strMode == "protocol") {
if(strFilter !="" && stoi(strFilter) != mn.protocolVersion) continue;
if(strFilter !="" && strFilter != boost::lexical_cast<std::string>(mn.protocolVersion) &&
mn.addr.ToString().find(strFilter) == string::npos) continue;
obj.push_back(Pair(strAddr, (int64_t)mn.protocolVersion));
} else if (strMode == "lastseen") {
if(strFilter !="" && mn.addr.ToString().find(strFilter) == string::npos) continue;
obj.push_back(Pair(strAddr, (int64_t)mn.lastTimeSeen));
} else if (strMode == "activeseconds") {
if(strFilter !="" && mn.addr.ToString().find(strFilter) == string::npos) continue;
obj.push_back(Pair(strAddr, (int64_t)(mn.lastTimeSeen - mn.now)));
} else if (strMode == "rank") {
if(strFilter !="" && mn.addr.ToString().find(strFilter) == string::npos) continue;
obj.push_back(Pair(strAddr, (int)(mnodeman.GetMasternodeRank(mn.vin, chainActive.Tip()->nHeight))));
} else if (strMode == "full") {
CScript pubkey;

View File

@ -457,9 +457,14 @@ Value getblocktemplate(const Array& params, bool fHelp)
" \"curtime\" : ttt, (numeric) current timestamp in seconds since epoch (Jan 1 1970 GMT)\n"
" \"bits\" : \"xxx\", (string) compressed target of next block\n"
" \"height\" : n (numeric) The height of the next block\n"
" \"payee\" : required payee\n"
" \"payee_amount\" : required amount to pay\n"
" \"votes\" : show vote candidates for this block\n"
" \"payee\" : \"xxx\", (string) required payee for the next block\n"
" \"payee_amount\" : n, (numeric) required amount to pay\n"
" \"votes\" : [\n (array) show vote candidates\n"
" { ... } (json object) vote candidate\n"
" ,...\n"
" ],\n"
" \"masternode_payments\" : true|false, (boolean) true, if masternode payments are enabled"
" \"enforce_masternode_payments\" : true|false (boolean) true, if masternode payments are enforced"
"}\n"
"\nExamples:\n"

View File

@ -270,12 +270,12 @@ static const CRPCCommand vRPCCommands[] =
{ "verifymessage", &verifymessage, false, false, false },
/* Darkcoin features */
{ "darksend", &darksend, false, false, true },
{ "spork", &spork, true, false, false },
{ "masternode", &masternode, true, false, true },
{ "masternodelist", &masternodelist, true, false, false },
#ifdef ENABLE_WALLET
{ "darksend", &darksend, false, false, true },
/* Wallet */
{ "addmultisigaddress", &addmultisigaddress, false, false, true },
{ "backupwallet", &backupwallet, true, false, true },

View File

@ -19,9 +19,11 @@ using namespace boost;
class CSporkMessage;
class CSporkManager;
CSporkManager sporkManager;
std::map<uint256, CSporkMessage> mapSporks;
std::map<int, CSporkMessage> mapSporksActive;
CSporkManager sporkManager;
void ProcessSpork(CNode* pfrom, std::string& strCommand, CDataStream& vRecv)
{

View File

@ -27,7 +27,7 @@ extern const std::string CLIENT_DATE;
// network protocol versioning
//
static const int PROTOCOL_VERSION = 70066;
static const int PROTOCOL_VERSION = 70067;
// intial proto version, to be increased after version/verack negotiation
static const int INIT_PROTO_VERSION = 209;