mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 13:03:17 +01:00
Implemented inventory system for IX messages
This commit is contained in:
parent
dfb3da5ec3
commit
012f0e5660
@ -20,7 +20,7 @@ using namespace boost;
|
|||||||
|
|
||||||
std::map<uint256, CTransaction> mapTxLockReq;
|
std::map<uint256, CTransaction> mapTxLockReq;
|
||||||
std::map<uint256, CTransaction> mapTxLockReqRejected;
|
std::map<uint256, CTransaction> mapTxLockReqRejected;
|
||||||
std::map<uint256, int> mapTxLockVote;
|
std::map<uint256, CConsensusVote> mapTxLockVote;
|
||||||
std::map<uint256, CTransactionLock> mapTxLocks;
|
std::map<uint256, CTransactionLock> mapTxLocks;
|
||||||
std::map<COutPoint, uint256> mapLockedInputs;
|
std::map<COutPoint, uint256> mapLockedInputs;
|
||||||
std::map<uint256, int64_t> mapUnknownVotes; //track votes with no tx for DOS
|
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))
|
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);
|
DoConsensusVote(tx, nBlockHeight);
|
||||||
|
|
||||||
mapTxLockReq.insert(make_pair(tx.GetHash(), tx));
|
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?
|
// can we get the conflicting transaction as proof?
|
||||||
|
|
||||||
RelayTransactionLockReq(tx, inv.hash);
|
|
||||||
|
|
||||||
LogPrintf("ProcessMessageInstantX::txlreq - Transaction Lock Request: %s %s : rejected %s\n",
|
LogPrintf("ProcessMessageInstantX::txlreq - Transaction Lock Request: %s %s : rejected %s\n",
|
||||||
pfrom->addr.ToString().c_str(), pfrom->cleanSubVer.c_str(),
|
pfrom->addr.ToString().c_str(), pfrom->cleanSubVer.c_str(),
|
||||||
tx.GetHash().ToString().c_str()
|
tx.GetHash().ToString().c_str()
|
||||||
@ -130,7 +133,7 @@ void ProcessMessageInstantX(CNode* pfrom, std::string& strCommand, CDataStream&
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mapTxLockVote.insert(make_pair(ctx.GetHash(), 1));
|
mapTxLockVote.insert(make_pair(ctx.GetHash(), ctx));
|
||||||
|
|
||||||
if(ProcessConsensusVote(ctx)){
|
if(ProcessConsensusVote(ctx)){
|
||||||
//Spam/Dos protection
|
//Spam/Dos protection
|
||||||
@ -155,15 +158,12 @@ void ProcessMessageInstantX(CNode* pfrom, std::string& strCommand, CDataStream&
|
|||||||
mapUnknownVotes[ctx.vinMasternode.prevout.hash] = GetTime()+(60*10);
|
mapUnknownVotes[ctx.vinMasternode.prevout.hash] = GetTime()+(60*10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
vector<CInv> vInv;
|
||||||
|
vInv.push_back(inv);
|
||||||
LOCK(cs_vNodes);
|
LOCK(cs_vNodes);
|
||||||
BOOST_FOREACH(CNode* pnode, vNodes)
|
BOOST_FOREACH(CNode* pnode, vNodes)
|
||||||
{/*
|
pnode->PushMessage("inv", vInv);
|
||||||
if(!pnode->fRelayTxes)
|
|
||||||
continue;*/
|
|
||||||
|
|
||||||
pnode->PushMessage("txlvote", ctx);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -253,20 +253,20 @@ void DoConsensusVote(CTransaction& tx, int64_t nBlockHeight)
|
|||||||
|
|
||||||
if(n == -1)
|
if(n == -1)
|
||||||
{
|
{
|
||||||
LogPrintf("InstantX::DoConsensusVote - Unknown Masternode\n");
|
if(fDebug) LogPrintf("InstantX::DoConsensusVote - Unknown Masternode\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(n > INSTANTX_SIGNATURES_TOTAL)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
nBlockHeight calculated from the transaction is the authoritive source
|
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;
|
CConsensusVote ctx;
|
||||||
ctx.vinMasternode = activeMasternode.vin;
|
ctx.vinMasternode = activeMasternode.vin;
|
||||||
@ -281,13 +281,17 @@ void DoConsensusVote(CTransaction& tx, int64_t nBlockHeight)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOCK(cs_vNodes);
|
mapTxLockVote[ctx.GetHash()] = ctx;
|
||||||
BOOST_FOREACH(CNode* pnode, vNodes)
|
|
||||||
{
|
|
||||||
//LogPrintf("%s::check -- %s %s\n", vecMasternodes[winner].addr.ToString().c_str(), pnode->addr.ToString().c_str());
|
|
||||||
|
|
||||||
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
|
//received a consensus vote
|
||||||
@ -309,7 +313,7 @@ bool ProcessConsensusVote(CConsensusVote& ctx)
|
|||||||
|
|
||||||
if(n > INSTANTX_SIGNATURES_TOTAL)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -555,7 +559,7 @@ bool CTransactionLock::SignaturesValid()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTransactionLock::AddSignature(CConsensusVote cv)
|
void CTransactionLock::AddSignature(CConsensusVote& cv)
|
||||||
{
|
{
|
||||||
vecConsensusVotes.push_back(cv);
|
vecConsensusVotes.push_back(cv);
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,8 @@ class CTransactionLock;
|
|||||||
static const int MIN_INSTANTX_PROTO_VERSION = 70062;
|
static const int MIN_INSTANTX_PROTO_VERSION = 70062;
|
||||||
|
|
||||||
extern map<uint256, CTransaction> mapTxLockReq;
|
extern map<uint256, CTransaction> mapTxLockReq;
|
||||||
|
extern map<uint256, CTransaction> mapTxLockReqRejected;
|
||||||
|
extern map<uint256, CConsensusVote> mapTxLockVote;
|
||||||
extern map<uint256, CTransactionLock> mapTxLocks;
|
extern map<uint256, CTransactionLock> mapTxLocks;
|
||||||
extern std::map<COutPoint, uint256> mapLockedInputs;
|
extern std::map<COutPoint, uint256> mapLockedInputs;
|
||||||
extern int nCompleteTXLocks;
|
extern int nCompleteTXLocks;
|
||||||
@ -84,7 +86,7 @@ public:
|
|||||||
|
|
||||||
bool SignaturesValid();
|
bool SignaturesValid();
|
||||||
int CountSignatures();
|
int CountSignatures();
|
||||||
void AddSignature(CConsensusVote cv);
|
void AddSignature(CConsensusVote& cv);
|
||||||
|
|
||||||
uint256 GetHash()
|
uint256 GetHash()
|
||||||
{
|
{
|
||||||
|
25
src/main.cpp
25
src/main.cpp
@ -3857,6 +3857,11 @@ bool static AlreadyHave(const CInv& inv)
|
|||||||
case MSG_BLOCK:
|
case MSG_BLOCK:
|
||||||
return mapBlockIndex.count(inv.hash) ||
|
return mapBlockIndex.count(inv.hash) ||
|
||||||
mapOrphanBlocks.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
|
// Don't know what it is, just say we already got one
|
||||||
return true;
|
return true;
|
||||||
@ -3956,6 +3961,7 @@ void static ProcessGetData(CNode* pfrom)
|
|||||||
pushed = true;
|
pushed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pushed && inv.type == MSG_TX) {
|
if (!pushed && inv.type == MSG_TX) {
|
||||||
|
|
||||||
if(mapDarksendBroadcastTxes.count(inv.hash)){
|
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) {
|
if (!pushed) {
|
||||||
vNotFound.push_back(inv);
|
vNotFound.push_back(inv);
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,9 @@ static const char* ppszTypeName[] =
|
|||||||
"ERROR",
|
"ERROR",
|
||||||
"tx",
|
"tx",
|
||||||
"block",
|
"block",
|
||||||
"filtered block"
|
"filtered block",
|
||||||
|
"tx lock request",
|
||||||
|
"tx lock vote"
|
||||||
};
|
};
|
||||||
|
|
||||||
CMessageHeader::CMessageHeader()
|
CMessageHeader::CMessageHeader()
|
||||||
|
Loading…
Reference in New Issue
Block a user