Replace RelayMessage with RelayTransaction.

This commit is contained in:
Matt Corallo 2012-08-13 05:26:30 +02:00
parent 422d122537
commit 269d9c6492
7 changed files with 56 additions and 56 deletions

View File

@ -88,11 +88,11 @@ bool CBloomFilter::IsWithinSizeConstraints() const
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
// for finding tx when they appear in a block
if (contains(tx.GetHash()))
if (contains(hash))
return true;
BOOST_FOREACH(const CTxOut& txout, tx.vout)

View File

@ -64,7 +64,7 @@ public:
// (catch a filter which was just deserialized which was too big)
bool IsWithinSizeConstraints() const;
bool IsTransactionRelevantToFilter(const CTransaction& tx) const;
bool IsTransactionRelevantToFilter(const CTransaction& tx, const uint256& hash) const;
};
#endif /* BITCOIN_BLOOM_H */

View File

@ -3184,7 +3184,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
if (tx.AcceptToMemoryPool(true, &fMissingInputs))
{
SyncWithWallets(inv.hash, tx, NULL, true);
RelayMessage(inv, vMsg);
RelayTransaction(tx, inv.hash, vMsg);
mapAlreadyAskedFor.erase(inv);
vWorkQueue.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());
SyncWithWallets(inv.hash, tx, NULL, true);
RelayMessage(inv, vMsg);
RelayTransaction(tx, inv.hash, vMsg);
mapAlreadyAskedFor.erase(inv);
vWorkQueue.push_back(inv.hash);
vEraseQueue.push_back(inv.hash);

View File

@ -9,6 +9,7 @@
#include "init.h"
#include "addrman.h"
#include "ui_interface.h"
#include "script.h"
#ifdef WIN32
#include <string.h>
@ -1996,3 +1997,46 @@ public:
}
}
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);
}
}

View File

@ -562,51 +562,8 @@ public:
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);
}
class CTransaction;
void RelayTransaction(const CTransaction& tx, const uint256& hash);
void RelayTransaction(const CTransaction& tx, const uint256& hash, const CDataStream& ss);
#endif

View File

@ -558,7 +558,7 @@ Value sendrawtransaction(const Array& params, bool fHelp)
} else {
SyncWithWallets(hashTx, tx, NULL, true);
}
RelayMessage(CInv(MSG_TX, hashTx), tx);
RelayTransaction(tx, hashTx);
return hashTx.GetHex();
}

View File

@ -826,17 +826,16 @@ void CWalletTx::RelayWalletTransaction()
{
BOOST_FOREACH(const CMerkleTx& tx, vtxPrev)
{
if (!tx.IsCoinBase()) {
if (!tx.IsCoinBase())
if (tx.GetDepthInMainChain() == 0)
RelayMessage(CInv(MSG_TX, tx.GetHash()), (CTransaction)tx);
}
RelayTransaction((CTransaction)tx, tx.GetHash());
}
if (!IsCoinBase())
{
if (GetDepthInMainChain() == 0) {
uint256 hash = GetHash();
printf("Relaying wtx %s\n", hash.ToString().substr(0,10).c_str());
RelayMessage(CInv(MSG_TX, hash), (CTransaction)*this);
RelayTransaction((CTransaction)*this, hash);
}
}
}