Skip to content

Commit efc0593

Browse files
committed
Merge #7877: Change mapRelay to store CTransactions
38c3102 Change mapRelay to store CTransactions (Pieter Wuille)
2 parents bbd210d + 38c3102 commit efc0593

3 files changed

Lines changed: 8 additions & 21 deletions

File tree

src/main.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4458,7 +4458,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
44584458
bool pushed = false;
44594459
{
44604460
LOCK(cs_mapRelay);
4461-
map<CInv, CDataStream>::iterator mi = mapRelay.find(inv);
4461+
map<uint256, CTransaction>::iterator mi = mapRelay.find(inv.hash);
44624462
if (mi != mapRelay.end()) {
44634463
pfrom->PushMessage(inv.GetCommand(), (*mi).second);
44644464
pushed = true;
@@ -4467,10 +4467,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
44674467
if (!pushed && inv.type == MSG_TX) {
44684468
CTransaction tx;
44694469
if (mempool.lookup(inv.hash, tx)) {
4470-
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
4471-
ss.reserve(1000);
4472-
ss << tx;
4473-
pfrom->PushMessage(NetMsgType::TX, ss);
4470+
pfrom->PushMessage(NetMsgType::TX, tx);
44744471
pushed = true;
44754472
}
44764473
}

src/net.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ std::string strSubVersion;
9090

9191
vector<CNode*> vNodes;
9292
CCriticalSection cs_vNodes;
93-
map<CInv, CDataStream> mapRelay;
94-
deque<pair<int64_t, CInv> > vRelayExpiration;
93+
map<uint256, CTransaction> mapRelay;
94+
deque<pair<int64_t, uint256> > vRelayExpiration;
9595
CCriticalSection cs_mapRelay;
9696
limitedmap<uint256, int64_t> mapAlreadyAskedFor(MAX_INV_SZ);
9797

@@ -2054,14 +2054,6 @@ instance_of_cnetcleanup;
20542054

20552055

20562056
void RelayTransaction(const CTransaction& tx, CFeeRate feerate)
2057-
{
2058-
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
2059-
ss.reserve(10000);
2060-
ss << tx;
2061-
RelayTransaction(tx, feerate, ss);
2062-
}
2063-
2064-
void RelayTransaction(const CTransaction& tx, CFeeRate feerate, const CDataStream& ss)
20652057
{
20662058
CInv inv(MSG_TX, tx.GetHash());
20672059
{
@@ -2073,9 +2065,8 @@ void RelayTransaction(const CTransaction& tx, CFeeRate feerate, const CDataStrea
20732065
vRelayExpiration.pop_front();
20742066
}
20752067

2076-
// Save original serialized message so newer versions are preserved
2077-
mapRelay.insert(std::make_pair(inv, ss));
2078-
vRelayExpiration.push_back(std::make_pair(GetTime() + 15 * 60, inv));
2068+
mapRelay.insert(std::make_pair(inv.hash, tx));
2069+
vRelayExpiration.push_back(std::make_pair(GetTime() + 15 * 60, inv.hash));
20792070
}
20802071
LOCK(cs_vNodes);
20812072
BOOST_FOREACH(CNode* pnode, vNodes)

src/net.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ extern int nMaxConnections;
161161

162162
extern std::vector<CNode*> vNodes;
163163
extern CCriticalSection cs_vNodes;
164-
extern std::map<CInv, CDataStream> mapRelay;
165-
extern std::deque<std::pair<int64_t, CInv> > vRelayExpiration;
164+
extern std::map<uint256, CTransaction> mapRelay;
165+
extern std::deque<std::pair<int64_t, uint256> > vRelayExpiration;
166166
extern CCriticalSection cs_mapRelay;
167167
extern limitedmap<uint256, int64_t> mapAlreadyAskedFor;
168168

@@ -773,7 +773,6 @@ class CNode
773773

774774
class CTransaction;
775775
void RelayTransaction(const CTransaction& tx, CFeeRate feerate);
776-
void RelayTransaction(const CTransaction& tx, CFeeRate feerate, const CDataStream& ss);
777776

778777
/** Access to the (IP) address database (peers.dat) */
779778
class CAddrDB

0 commit comments

Comments
 (0)