Replace RelayMessage with RelayTransaction.
This commit is contained in:
parent
422d122537
commit
269d9c6492
@ -88,11 +88,11 @@ bool CBloomFilter::IsWithinSizeConstraints() const
|
|||||||
return vData.size() <= MAX_BLOOM_FILTER_SIZE && nHashFuncs <= MAX_HASH_FUNCS;
|
return vData.size() <= MAX_BLOOM_FILTER_SIZE && nHashFuncs <= MAX_HASH_FUNCS;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBloomFilter::IsTransactionRelevantToFilter(const CTransaction& tx) const
|
bool CBloomFilter::IsTransactionRelevantToFilter(const CTransaction& tx, const uint256& hash) const
|
||||||
{
|
{
|
||||||
// Match if the filter contains the hash of tx
|
// Match if the filter contains the hash of tx
|
||||||
// for finding tx when they appear in a block
|
// for finding tx when they appear in a block
|
||||||
if (contains(tx.GetHash()))
|
if (contains(hash))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
BOOST_FOREACH(const CTxOut& txout, tx.vout)
|
BOOST_FOREACH(const CTxOut& txout, tx.vout)
|
||||||
|
@ -64,7 +64,7 @@ public:
|
|||||||
// (catch a filter which was just deserialized which was too big)
|
// (catch a filter which was just deserialized which was too big)
|
||||||
bool IsWithinSizeConstraints() const;
|
bool IsWithinSizeConstraints() const;
|
||||||
|
|
||||||
bool IsTransactionRelevantToFilter(const CTransaction& tx) const;
|
bool IsTransactionRelevantToFilter(const CTransaction& tx, const uint256& hash) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* BITCOIN_BLOOM_H */
|
#endif /* BITCOIN_BLOOM_H */
|
||||||
|
@ -3184,7 +3184,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
|||||||
if (tx.AcceptToMemoryPool(true, &fMissingInputs))
|
if (tx.AcceptToMemoryPool(true, &fMissingInputs))
|
||||||
{
|
{
|
||||||
SyncWithWallets(inv.hash, tx, NULL, true);
|
SyncWithWallets(inv.hash, tx, NULL, true);
|
||||||
RelayMessage(inv, vMsg);
|
RelayTransaction(tx, inv.hash, vMsg);
|
||||||
mapAlreadyAskedFor.erase(inv);
|
mapAlreadyAskedFor.erase(inv);
|
||||||
vWorkQueue.push_back(inv.hash);
|
vWorkQueue.push_back(inv.hash);
|
||||||
vEraseQueue.push_back(inv.hash);
|
vEraseQueue.push_back(inv.hash);
|
||||||
@ -3207,7 +3207,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
|||||||
{
|
{
|
||||||
printf(" accepted orphan tx %s\n", inv.hash.ToString().substr(0,10).c_str());
|
printf(" accepted orphan tx %s\n", inv.hash.ToString().substr(0,10).c_str());
|
||||||
SyncWithWallets(inv.hash, tx, NULL, true);
|
SyncWithWallets(inv.hash, tx, NULL, true);
|
||||||
RelayMessage(inv, vMsg);
|
RelayTransaction(tx, inv.hash, vMsg);
|
||||||
mapAlreadyAskedFor.erase(inv);
|
mapAlreadyAskedFor.erase(inv);
|
||||||
vWorkQueue.push_back(inv.hash);
|
vWorkQueue.push_back(inv.hash);
|
||||||
vEraseQueue.push_back(inv.hash);
|
vEraseQueue.push_back(inv.hash);
|
||||||
|
44
src/net.cpp
44
src/net.cpp
@ -9,6 +9,7 @@
|
|||||||
#include "init.h"
|
#include "init.h"
|
||||||
#include "addrman.h"
|
#include "addrman.h"
|
||||||
#include "ui_interface.h"
|
#include "ui_interface.h"
|
||||||
|
#include "script.h"
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -1996,3 +1997,46 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
instance_of_cnetcleanup;
|
instance_of_cnetcleanup;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void RelayTransaction(const CTransaction& tx, const uint256& hash)
|
||||||
|
{
|
||||||
|
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
||||||
|
ss.reserve(10000);
|
||||||
|
ss << tx;
|
||||||
|
RelayTransaction(tx, hash, ss);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RelayTransaction(const CTransaction& tx, const uint256& hash, const CDataStream& ss)
|
||||||
|
{
|
||||||
|
CInv inv(MSG_TX, hash);
|
||||||
|
{
|
||||||
|
LOCK(cs_mapRelay);
|
||||||
|
// Expire old relay messages
|
||||||
|
while (!vRelayExpiration.empty() && vRelayExpiration.front().first < GetTime())
|
||||||
|
{
|
||||||
|
mapRelay.erase(vRelayExpiration.front().second);
|
||||||
|
vRelayExpiration.pop_front();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save original serialized message so newer versions are preserved
|
||||||
|
mapRelay.insert(std::make_pair(inv, ss));
|
||||||
|
vRelayExpiration.push_back(std::make_pair(GetTime() + 15 * 60, inv));
|
||||||
|
}
|
||||||
|
LOCK(cs_vNodes);
|
||||||
|
BOOST_FOREACH(CNode* pnode, vNodes)
|
||||||
|
{
|
||||||
|
LOCK(pnode->cs_filter);
|
||||||
|
if (pnode->pfilter)
|
||||||
|
{
|
||||||
|
if (pnode->pfilter->IsTransactionRelevantToFilter(tx, hash))
|
||||||
|
pnode->PushInventory(inv);
|
||||||
|
} else
|
||||||
|
pnode->PushInventory(inv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
49
src/net.h
49
src/net.h
@ -562,51 +562,8 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class CTransaction;
|
||||||
|
void RelayTransaction(const CTransaction& tx, const uint256& hash);
|
||||||
|
void RelayTransaction(const CTransaction& tx, const uint256& hash, const CDataStream& ss);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline void RelayInventory(const CInv& inv)
|
|
||||||
{
|
|
||||||
// Put on lists to offer to the other nodes
|
|
||||||
{
|
|
||||||
LOCK(cs_vNodes);
|
|
||||||
BOOST_FOREACH(CNode* pnode, vNodes)
|
|
||||||
pnode->PushInventory(inv);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
void RelayMessage(const CInv& inv, const T& a)
|
|
||||||
{
|
|
||||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
|
||||||
ss.reserve(10000);
|
|
||||||
ss << a;
|
|
||||||
RelayMessage(inv, ss);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
inline void RelayMessage<>(const CInv& inv, const CDataStream& ss)
|
|
||||||
{
|
|
||||||
{
|
|
||||||
LOCK(cs_mapRelay);
|
|
||||||
// Expire old relay messages
|
|
||||||
while (!vRelayExpiration.empty() && vRelayExpiration.front().first < GetTime())
|
|
||||||
{
|
|
||||||
mapRelay.erase(vRelayExpiration.front().second);
|
|
||||||
vRelayExpiration.pop_front();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save original serialized message so newer versions are preserved
|
|
||||||
mapRelay.insert(std::make_pair(inv, ss));
|
|
||||||
vRelayExpiration.push_back(std::make_pair(GetTime() + 15 * 60, inv));
|
|
||||||
}
|
|
||||||
|
|
||||||
RelayInventory(inv);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -558,7 +558,7 @@ Value sendrawtransaction(const Array& params, bool fHelp)
|
|||||||
} else {
|
} else {
|
||||||
SyncWithWallets(hashTx, tx, NULL, true);
|
SyncWithWallets(hashTx, tx, NULL, true);
|
||||||
}
|
}
|
||||||
RelayMessage(CInv(MSG_TX, hashTx), tx);
|
RelayTransaction(tx, hashTx);
|
||||||
|
|
||||||
return hashTx.GetHex();
|
return hashTx.GetHex();
|
||||||
}
|
}
|
||||||
|
@ -826,17 +826,16 @@ void CWalletTx::RelayWalletTransaction()
|
|||||||
{
|
{
|
||||||
BOOST_FOREACH(const CMerkleTx& tx, vtxPrev)
|
BOOST_FOREACH(const CMerkleTx& tx, vtxPrev)
|
||||||
{
|
{
|
||||||
if (!tx.IsCoinBase()) {
|
if (!tx.IsCoinBase())
|
||||||
if (tx.GetDepthInMainChain() == 0)
|
if (tx.GetDepthInMainChain() == 0)
|
||||||
RelayMessage(CInv(MSG_TX, tx.GetHash()), (CTransaction)tx);
|
RelayTransaction((CTransaction)tx, tx.GetHash());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!IsCoinBase())
|
if (!IsCoinBase())
|
||||||
{
|
{
|
||||||
if (GetDepthInMainChain() == 0) {
|
if (GetDepthInMainChain() == 0) {
|
||||||
uint256 hash = GetHash();
|
uint256 hash = GetHash();
|
||||||
printf("Relaying wtx %s\n", hash.ToString().substr(0,10).c_str());
|
printf("Relaying wtx %s\n", hash.ToString().substr(0,10).c_str());
|
||||||
RelayMessage(CInv(MSG_TX, hash), (CTransaction)*this);
|
RelayTransaction((CTransaction)*this, hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user