diff options
author | Matt Corallo <git@bluematt.me> | 2012-08-13 05:26:30 +0200 |
---|---|---|
committer | Matt Corallo <git@bluematt.me> | 2013-01-16 12:48:02 -0500 |
commit | 269d9c6492dc275650d2137d53f4afdca88e3216 (patch) | |
tree | 32ded97569c406479d8393eda9163f3ba488b7b9 | |
parent | 422d1225374e2d879dbd116151e0113aa7162500 (diff) |
Replace RelayMessage with RelayTransaction.
-rw-r--r-- | src/bloom.cpp | 4 | ||||
-rw-r--r-- | src/bloom.h | 2 | ||||
-rw-r--r-- | src/main.cpp | 4 | ||||
-rw-r--r-- | src/net.cpp | 44 | ||||
-rw-r--r-- | src/net.h | 49 | ||||
-rw-r--r-- | src/rpcrawtransaction.cpp | 2 | ||||
-rw-r--r-- | src/wallet.cpp | 7 |
7 files changed, 56 insertions, 56 deletions
diff --git a/src/bloom.cpp b/src/bloom.cpp index 5fac1d06ab..73b04aa3d6 100644 --- a/src/bloom.cpp +++ b/src/bloom.cpp @@ -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) diff --git a/src/bloom.h b/src/bloom.h index ce84e66552..335bb5e0bb 100644 --- a/src/bloom.h +++ b/src/bloom.h @@ -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 */ diff --git a/src/main.cpp b/src/main.cpp index 9a498ff273..93079693c3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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); diff --git a/src/net.cpp b/src/net.cpp index 7867c85b7f..aafc7206cd 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -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); + } +} @@ -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 diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 9531b12678..09fbaa30cd 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -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(); } diff --git a/src/wallet.cpp b/src/wallet.cpp index 37b86c35b5..f49bfb5f8f 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -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); } } } |