From 012f0e56601dfd4a43b23ef9117938cce1526d3c Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Fri, 6 Feb 2015 12:07:22 -0700 Subject: [PATCH] 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 3f06c952c..ce9ca034e 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 b7a71c17f..72963a4a2 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 9e5de867f..9e22e328e 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 c77a92f02..78a69a91d 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()