Implemented inventory system for IX messages

This commit is contained in:
Evan Duffield 2015-02-06 12:07:22 -07:00
parent dfb3da5ec3
commit 012f0e5660
4 changed files with 56 additions and 23 deletions

View File

@ -20,7 +20,7 @@ using namespace boost;
std::map<uint256, CTransaction> mapTxLockReq;
std::map<uint256, CTransaction> mapTxLockReqRejected;
std::map<uint256, int> mapTxLockVote;
std::map<uint256, CConsensusVote> mapTxLockVote;
std::map<uint256, CTransactionLock> mapTxLocks;
std::map<COutPoint, uint256> mapLockedInputs;
std::map<uint256, int64_t> 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<CInv> 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<CInv> 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<CInv> 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);
}

View File

@ -26,6 +26,8 @@ class CTransactionLock;
static const int MIN_INSTANTX_PROTO_VERSION = 70062;
extern map<uint256, CTransaction> mapTxLockReq;
extern map<uint256, CTransaction> mapTxLockReqRejected;
extern map<uint256, CConsensusVote> mapTxLockVote;
extern map<uint256, CTransactionLock> mapTxLocks;
extern std::map<COutPoint, uint256> mapLockedInputs;
extern int nCompleteTXLocks;
@ -84,7 +86,7 @@ public:
bool SignaturesValid();
int CountSignatures();
void AddSignature(CConsensusVote cv);
void AddSignature(CConsensusVote& cv);
uint256 GetHash()
{

View File

@ -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);
}

View File

@ -16,7 +16,9 @@ static const char* ppszTypeName[] =
"ERROR",
"tx",
"block",
"filtered block"
"filtered block",
"tx lock request",
"tx lock vote"
};
CMessageHeader::CMessageHeader()