Browse Source

Replace RelayMessage with RelayTransaction.

0.8
Matt Corallo 12 years ago
parent
commit
269d9c6492
  1. 4
      src/bloom.cpp
  2. 2
      src/bloom.h
  3. 4
      src/main.cpp
  4. 44
      src/net.cpp
  5. 49
      src/net.h
  6. 2
      src/rpcrawtransaction.cpp
  7. 7
      src/wallet.cpp

4
src/bloom.cpp

@ -88,11 +88,11 @@ bool CBloomFilter::IsWithinSizeConstraints() const @@ -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)

2
src/bloom.h

@ -64,7 +64,7 @@ public: @@ -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 */

4
src/main.cpp

@ -3184,7 +3184,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) @@ -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) @@ -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);

44
src/net.cpp

@ -9,6 +9,7 @@ @@ -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: @@ -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);
}
}

49
src/net.h

@ -562,51 +562,8 @@ public: @@ -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

2
src/rpcrawtransaction.cpp

@ -558,7 +558,7 @@ Value sendrawtransaction(const Array& params, bool fHelp) @@ -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();
}

7
src/wallet.cpp

@ -826,17 +826,16 @@ void CWalletTx::RelayWalletTransaction() @@ -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);
}
}
}

Loading…
Cancel
Save