From b65d718cf56ecadfe0a4b4c47cab5a07842a1f7a Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Fri, 6 Feb 2015 08:54:39 -0700 Subject: [PATCH 1/6] debugging --- src/instantx.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/instantx.cpp b/src/instantx.cpp index 1202303cfe..7056c545da 100644 --- a/src/instantx.cpp +++ b/src/instantx.cpp @@ -295,6 +295,11 @@ bool ProcessConsensusVote(CConsensusVote& ctx) { int n = GetMasternodeRank(ctx.vinMasternode, ctx.nBlockHeight, MIN_INSTANTX_PROTO_VERSION); + int x = GetMasternodeByVin(ctx.vinMasternode); + if(x != -1){ + LogPrintf("InstantX::ProcessConsensusVote - Masternode ADDR %s %d\n", vecMasternodes[x].addr.ToString().c_str(), n); + } + if(n == -1) { LogPrintf("InstantX::ProcessConsensusVote - Unknown Masternode\n"); @@ -303,7 +308,7 @@ bool ProcessConsensusVote(CConsensusVote& ctx) if(n > INSTANTX_SIGNATURES_TOTAL) { - LogPrintf("InstantX::ProcessConsensusVote - Masternode not in the top %d (%d)\n", INSTANTX_SIGNATURES_TOTAL, n); + LogPrintf("InstantX::ProcessConsensusVote - Masternode not in the top %d (%d) - %s\n", INSTANTX_SIGNATURES_TOTAL, n, ctx.GetHash().ToString().c_str()); return false; } From dfb3da5ec32e1a475d745660412bf6a721c8e4dc Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Fri, 6 Feb 2015 09:03:50 -0700 Subject: [PATCH 2/6] version/protocol bump/min protocol --- configure.ac | 2 +- src/clientversion.h | 2 +- src/darksend.h | 2 +- src/instantx.cpp | 9 +++++---- src/instantx.h | 2 +- src/version.h | 4 ++-- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/configure.ac b/configure.ac index 9b17c6dea3..f255ea5d3d 100644 --- a/configure.ac +++ b/configure.ac @@ -3,7 +3,7 @@ AC_PREREQ([2.60]) define(_CLIENT_VERSION_MAJOR, 0) define(_CLIENT_VERSION_MINOR, 11) define(_CLIENT_VERSION_REVISION, 1) -define(_CLIENT_VERSION_BUILD, 11) +define(_CLIENT_VERSION_BUILD, 12) define(_CLIENT_VERSION_IS_RELEASE, true) define(_COPYRIGHT_YEAR, 2015) AC_INIT([Darkcoin Core],[_CLIENT_VERSION_MAJOR._CLIENT_VERSION_MINOR._CLIENT_VERSION_REVISION],[info@darkcoin.io],[darkcoin]) diff --git a/src/clientversion.h b/src/clientversion.h index ebdad62abd..a145984f95 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -12,7 +12,7 @@ #define CLIENT_VERSION_MAJOR 0 #define CLIENT_VERSION_MINOR 11 #define CLIENT_VERSION_REVISION 1 -#define CLIENT_VERSION_BUILD 11 +#define CLIENT_VERSION_BUILD 12 diff --git a/src/darksend.h b/src/darksend.h index 06717395e5..1d8671ad5f 100644 --- a/src/darksend.h +++ b/src/darksend.h @@ -222,7 +222,7 @@ class CDarksendSession class CDarkSendPool { public: - static const int MIN_PEER_PROTO_VERSION = 70061; + static const int MIN_PEER_PROTO_VERSION = 70062; // clients entries std::vector myEntries; diff --git a/src/instantx.cpp b/src/instantx.cpp index 7056c545da..3f06c952cb 100644 --- a/src/instantx.cpp +++ b/src/instantx.cpp @@ -158,9 +158,9 @@ void ProcessMessageInstantX(CNode* pfrom, std::string& strCommand, CDataStream& LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) - { + {/* if(!pnode->fRelayTxes) - continue; + continue;*/ pnode->PushMessage("txlvote", ctx); } @@ -297,12 +297,13 @@ bool ProcessConsensusVote(CConsensusVote& ctx) int x = GetMasternodeByVin(ctx.vinMasternode); if(x != -1){ - LogPrintf("InstantX::ProcessConsensusVote - Masternode ADDR %s %d\n", vecMasternodes[x].addr.ToString().c_str(), n); + if(fDebug) LogPrintf("InstantX::ProcessConsensusVote - Masternode ADDR %s %d\n", vecMasternodes[x].addr.ToString().c_str(), n); } if(n == -1) { - LogPrintf("InstantX::ProcessConsensusVote - Unknown Masternode\n"); + //can be caused by past versions trying to vote with an invalid protocol + if(fDebug) LogPrintf("InstantX::ProcessConsensusVote - Unknown Masternode\n"); return false; } diff --git a/src/instantx.h b/src/instantx.h index 2308d62168..b7a71c17f2 100644 --- a/src/instantx.h +++ b/src/instantx.h @@ -23,7 +23,7 @@ class CConsensusVote; class CTransaction; class CTransactionLock; -static const int MIN_INSTANTX_PROTO_VERSION = 70061; +static const int MIN_INSTANTX_PROTO_VERSION = 70062; extern map mapTxLockReq; extern map mapTxLocks; diff --git a/src/version.h b/src/version.h index 8d3daa41e0..2afd7bc830 100644 --- a/src/version.h +++ b/src/version.h @@ -27,13 +27,13 @@ extern const std::string CLIENT_DATE; // network protocol versioning // -static const int PROTOCOL_VERSION = 70061; +static const int PROTOCOL_VERSION = 70062; // intial proto version, to be increased after version/verack negotiation static const int INIT_PROTO_VERSION = 209; // disconnect from peers older than this proto version -static const int MIN_PEER_PROTO_VERSION = 70051; +static const int MIN_PEER_PROTO_VERSION = 70062; //70051 // nTime field added to CAddress, starting with this version; // if possible, avoid requesting addresses nodes older than this From 012f0e56601dfd4a43b23ef9117938cce1526d3c Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Fri, 6 Feb 2015 12:07:22 -0700 Subject: [PATCH 3/6] Implemented inventory system for IX messages --- src/instantx.cpp | 46 +++++++++++++++++++++++++--------------------- src/instantx.h | 4 +++- src/main.cpp | 25 +++++++++++++++++++++++++ src/protocol.cpp | 4 +++- 4 files changed, 56 insertions(+), 23 deletions(-) diff --git a/src/instantx.cpp b/src/instantx.cpp index 3f06c952cb..ce9ca034e8 100644 --- a/src/instantx.cpp +++ b/src/instantx.cpp @@ -20,7 +20,7 @@ using namespace boost; std::map mapTxLockReq; std::map mapTxLockReqRejected; -std::map mapTxLockVote; +std::map mapTxLockVote; std::map mapTxLocks; std::map mapLockedInputs; std::map mapUnknownVotes; //track votes with no tx for DOS @@ -70,7 +70,12 @@ void ProcessMessageInstantX(CNode* pfrom, std::string& strCommand, CDataStream& if (AcceptToMemoryPool(mempool, state, tx, true, &fMissingInputs)) { - RelayTransactionLockReq(tx, tx.GetHash()); + vector vInv; + vInv.push_back(inv); + LOCK(cs_vNodes); + BOOST_FOREACH(CNode* pnode, vNodes) + pnode->PushMessage("inv", vInv); + DoConsensusVote(tx, nBlockHeight); mapTxLockReq.insert(make_pair(tx.GetHash(), tx)); @@ -87,8 +92,6 @@ void ProcessMessageInstantX(CNode* pfrom, std::string& strCommand, CDataStream& // can we get the conflicting transaction as proof? - RelayTransactionLockReq(tx, inv.hash); - LogPrintf("ProcessMessageInstantX::txlreq - Transaction Lock Request: %s %s : rejected %s\n", pfrom->addr.ToString().c_str(), pfrom->cleanSubVer.c_str(), tx.GetHash().ToString().c_str() @@ -130,7 +133,7 @@ void ProcessMessageInstantX(CNode* pfrom, std::string& strCommand, CDataStream& return; } - mapTxLockVote.insert(make_pair(ctx.GetHash(), 1)); + mapTxLockVote.insert(make_pair(ctx.GetHash(), ctx)); if(ProcessConsensusVote(ctx)){ //Spam/Dos protection @@ -155,15 +158,12 @@ void ProcessMessageInstantX(CNode* pfrom, std::string& strCommand, CDataStream& mapUnknownVotes[ctx.vinMasternode.prevout.hash] = GetTime()+(60*10); } } - + vector vInv; + vInv.push_back(inv); LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) - {/* - if(!pnode->fRelayTxes) - continue;*/ + pnode->PushMessage("inv", vInv); - pnode->PushMessage("txlvote", ctx); - } } return; @@ -253,20 +253,20 @@ void DoConsensusVote(CTransaction& tx, int64_t nBlockHeight) if(n == -1) { - LogPrintf("InstantX::DoConsensusVote - Unknown Masternode\n"); + if(fDebug) LogPrintf("InstantX::DoConsensusVote - Unknown Masternode\n"); return; } if(n > INSTANTX_SIGNATURES_TOTAL) { - LogPrintf("InstantX::DoConsensusVote - Masternode not in the top %d (%d)\n", INSTANTX_SIGNATURES_TOTAL, n); + if(fDebug) LogPrintf("InstantX::DoConsensusVote - Masternode not in the top %d (%d)\n", INSTANTX_SIGNATURES_TOTAL, n); return; } /* nBlockHeight calculated from the transaction is the authoritive source */ - LogPrintf("InstantX::DoConsensusVote - In the top %d (%d)\n", INSTANTX_SIGNATURES_TOTAL, n); + if(fDebug) LogPrintf("InstantX::DoConsensusVote - In the top %d (%d)\n", INSTANTX_SIGNATURES_TOTAL, n); CConsensusVote ctx; ctx.vinMasternode = activeMasternode.vin; @@ -281,13 +281,17 @@ void DoConsensusVote(CTransaction& tx, int64_t nBlockHeight) return; } - LOCK(cs_vNodes); - BOOST_FOREACH(CNode* pnode, vNodes) - { - //LogPrintf("%s::check -- %s %s\n", vecMasternodes[winner].addr.ToString().c_str(), pnode->addr.ToString().c_str()); + mapTxLockVote[ctx.GetHash()] = ctx; - pnode->PushMessage("txlvote", ctx); + CInv inv(MSG_TXLOCK_VOTE, ctx.GetHash()); + + vector vInv; + vInv.push_back(inv); + LOCK(cs_vNodes); + BOOST_FOREACH(CNode* pnode, vNodes){ + pnode->PushMessage("inv", vInv); } + } //received a consensus vote @@ -309,7 +313,7 @@ bool ProcessConsensusVote(CConsensusVote& ctx) if(n > INSTANTX_SIGNATURES_TOTAL) { - LogPrintf("InstantX::ProcessConsensusVote - Masternode not in the top %d (%d) - %s\n", INSTANTX_SIGNATURES_TOTAL, n, ctx.GetHash().ToString().c_str()); + if(fDebug) LogPrintf("InstantX::ProcessConsensusVote - Masternode not in the top %d (%d) - %s\n", INSTANTX_SIGNATURES_TOTAL, n, ctx.GetHash().ToString().c_str()); return false; } @@ -555,7 +559,7 @@ bool CTransactionLock::SignaturesValid() return true; } -void CTransactionLock::AddSignature(CConsensusVote cv) +void CTransactionLock::AddSignature(CConsensusVote& cv) { vecConsensusVotes.push_back(cv); } diff --git a/src/instantx.h b/src/instantx.h index b7a71c17f2..72963a4a23 100644 --- a/src/instantx.h +++ b/src/instantx.h @@ -26,6 +26,8 @@ class CTransactionLock; static const int MIN_INSTANTX_PROTO_VERSION = 70062; extern map mapTxLockReq; +extern map mapTxLockReqRejected; +extern map mapTxLockVote; extern map mapTxLocks; extern std::map mapLockedInputs; extern int nCompleteTXLocks; @@ -84,7 +86,7 @@ public: bool SignaturesValid(); int CountSignatures(); - void AddSignature(CConsensusVote cv); + void AddSignature(CConsensusVote& cv); uint256 GetHash() { diff --git a/src/main.cpp b/src/main.cpp index 9e5de867fc..9e22e328ed 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3857,6 +3857,11 @@ bool static AlreadyHave(const CInv& inv) case MSG_BLOCK: return mapBlockIndex.count(inv.hash) || mapOrphanBlocks.count(inv.hash); + case MSG_TXLOCK_REQUEST: + return mapTxLockReq.count(inv.hash) || + mapTxLockReqRejected.count(inv.hash); + case MSG_TXLOCK_VOTE: + return mapTxLockVote.count(inv.hash); } // Don't know what it is, just say we already got one return true; @@ -3956,6 +3961,7 @@ void static ProcessGetData(CNode* pfrom) pushed = true; } } + if (!pushed && inv.type == MSG_TX) { if(mapDarksendBroadcastTxes.count(inv.hash)){ @@ -3980,6 +3986,25 @@ void static ProcessGetData(CNode* pfrom) } } } + if (!pushed && inv.type == MSG_TXLOCK_VOTE) { + if(mapTxLockVote.count(inv.hash)){ + CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); + ss.reserve(1000); + ss << mapTxLockVote[inv.hash]; + pfrom->PushMessage("txlvote", ss); + pushed = true; + } + } + if (!pushed && inv.type == MSG_TXLOCK_REQUEST) { + if(mapTxLockReq.count(inv.hash)){ + CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); + ss.reserve(1000); + ss << mapTxLockReq[inv.hash]; + pfrom->PushMessage("txlreq", ss); + pushed = true; + } + } + if (!pushed) { vNotFound.push_back(inv); } diff --git a/src/protocol.cpp b/src/protocol.cpp index c77a92f020..78a69a91d4 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -16,7 +16,9 @@ static const char* ppszTypeName[] = "ERROR", "tx", "block", - "filtered block" + "filtered block", + "tx lock request", + "tx lock vote" }; CMessageHeader::CMessageHeader() From c56a54d211c211373b27c8fda4133717b69a42f1 Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Fri, 6 Feb 2015 12:41:39 -0700 Subject: [PATCH 4/6] enforce mn port on mainnet only --- src/activemasternode.cpp | 9 +++++++++ src/masternode.cpp | 4 ++++ src/version.h | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/activemasternode.cpp b/src/activemasternode.cpp index ce825fffcf..42adef3d91 100644 --- a/src/activemasternode.cpp +++ b/src/activemasternode.cpp @@ -41,6 +41,15 @@ void CActiveMasternode::ManageStatus() LogPrintf("CActiveMasternode::ManageStatus() - Checking inbound connection to '%s'\n", service.ToString().c_str()); + if(Params().NetworkID() == CChainParams::MAIN){ + if(service.GetPort() != 9999) { + notCapableReason = "Invalid port: " + boost::lexical_cast(service.GetPort()) + " -only 9999 is supported on mainnet."; + status = MASTERNODE_NOT_CAPABLE; + LogPrintf("CActiveMasternode::ManageStatus() - not capable: %s\n", notCapableReason.c_str()); + return; + } + } + if(Params().NetworkID() != CChainParams::REGTEST){ if(!ConnectNode((CAddress)service, service.ToString().c_str())){ notCapableReason = "Could not connect to " + service.ToString(); diff --git a/src/masternode.cpp b/src/masternode.cpp index 6c7df96287..57ffea73bf 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -105,6 +105,10 @@ void ProcessMessageMasternode(CNode* pfrom, std::string& strCommand, CDataStream return; } + if(Params().NetworkID() == CChainParams::MAIN){ + if(addr.GetPort() != 9999) return; + } + //search existing masternode list, this is where we update existing masternodes with new dsee broadcasts BOOST_FOREACH(CMasterNode& mn, vecMasternodes) { diff --git a/src/version.h b/src/version.h index 2afd7bc830..4cee8ef5fc 100644 --- a/src/version.h +++ b/src/version.h @@ -33,7 +33,7 @@ static const int PROTOCOL_VERSION = 70062; static const int INIT_PROTO_VERSION = 209; // disconnect from peers older than this proto version -static const int MIN_PEER_PROTO_VERSION = 70062; //70051 +static const int MIN_PEER_PROTO_VERSION = 70051; // nTime field added to CAddress, starting with this version; // if possible, avoid requesting addresses nodes older than this From 3b35672bb87ed56e4e6121d632ef72843ea63f88 Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Fri, 6 Feb 2015 12:53:31 -0700 Subject: [PATCH 5/6] version/proto bump --- configure.ac | 2 +- src/clientversion.h | 2 +- src/darksend.h | 2 +- src/instantx.h | 2 +- src/version.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index f255ea5d3d..61338913c5 100644 --- a/configure.ac +++ b/configure.ac @@ -3,7 +3,7 @@ AC_PREREQ([2.60]) define(_CLIENT_VERSION_MAJOR, 0) define(_CLIENT_VERSION_MINOR, 11) define(_CLIENT_VERSION_REVISION, 1) -define(_CLIENT_VERSION_BUILD, 12) +define(_CLIENT_VERSION_BUILD, 13) define(_CLIENT_VERSION_IS_RELEASE, true) define(_COPYRIGHT_YEAR, 2015) AC_INIT([Darkcoin Core],[_CLIENT_VERSION_MAJOR._CLIENT_VERSION_MINOR._CLIENT_VERSION_REVISION],[info@darkcoin.io],[darkcoin]) diff --git a/src/clientversion.h b/src/clientversion.h index a145984f95..82759a6e10 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -12,7 +12,7 @@ #define CLIENT_VERSION_MAJOR 0 #define CLIENT_VERSION_MINOR 11 #define CLIENT_VERSION_REVISION 1 -#define CLIENT_VERSION_BUILD 12 +#define CLIENT_VERSION_BUILD 13 diff --git a/src/darksend.h b/src/darksend.h index 1d8671ad5f..249d26cd4a 100644 --- a/src/darksend.h +++ b/src/darksend.h @@ -222,7 +222,7 @@ class CDarksendSession class CDarkSendPool { public: - static const int MIN_PEER_PROTO_VERSION = 70062; + static const int MIN_PEER_PROTO_VERSION = 70063; // clients entries std::vector myEntries; diff --git a/src/instantx.h b/src/instantx.h index 72963a4a23..8f82f399f6 100644 --- a/src/instantx.h +++ b/src/instantx.h @@ -23,7 +23,7 @@ class CConsensusVote; class CTransaction; class CTransactionLock; -static const int MIN_INSTANTX_PROTO_VERSION = 70062; +static const int MIN_INSTANTX_PROTO_VERSION = 70063; extern map mapTxLockReq; extern map mapTxLockReqRejected; diff --git a/src/version.h b/src/version.h index 4cee8ef5fc..4499bded0d 100644 --- a/src/version.h +++ b/src/version.h @@ -27,7 +27,7 @@ extern const std::string CLIENT_DATE; // network protocol versioning // -static const int PROTOCOL_VERSION = 70062; +static const int PROTOCOL_VERSION = 70063; // intial proto version, to be increased after version/verack negotiation static const int INIT_PROTO_VERSION = 209; From 3a72da77acdc9c07e8790ae99ab7dfcdc9b72563 Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Fri, 6 Feb 2015 12:58:03 -0700 Subject: [PATCH 6/6] clean up tx lock votes on expiration --- src/instantx.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/instantx.cpp b/src/instantx.cpp index ce9ca034e8..8766acb68a 100644 --- a/src/instantx.cpp +++ b/src/instantx.cpp @@ -445,6 +445,9 @@ void CleanTransactionLocksList() mapTxLockReq.erase(it->second.txHash); mapTxLockReqRejected.erase(it->second.txHash); + + BOOST_FOREACH(CConsensusVote& v, it->second.vecConsensusVotes) + mapTxLockVote.erase(v.GetHash()); } mapTxLocks.erase(it++);