Skip to content

Commit bef0361

Browse files
laanwjcodablock
authored andcommitted
Merge bitcoin#7877: Change mapRelay to store CTransactions
38c3102 Change mapRelay to store CTransactions (Pieter Wuille)
1 parent 2dc71e8 commit bef0361

File tree

3 files changed

+9
-30
lines changed

3 files changed

+9
-30
lines changed

src/net.cpp

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ static bool vfLimited[NET_MAX] = {};
8181
static CNode* pnodeLocalHost = NULL;
8282
std::string strSubVersion;
8383

84-
std::map<CInv, CDataStream> mapRelay;
85-
std::deque<pair<int64_t, CInv> > vRelayExpiration;
84+
std::map<uint256, CTransaction> mapRelay;
85+
std::deque<pair<int64_t, uint256> > vRelayExpiration;
8686
CCriticalSection cs_mapRelay;
8787
limitedmap<uint256, int64_t> mapAlreadyAskedFor(MAX_INV_SZ);
8888

@@ -2475,23 +2475,6 @@ bool CConnman::DisconnectNode(NodeId id)
24752475
}
24762476

24772477
void CConnman::RelayTransaction(const CTransaction& tx)
2478-
{
2479-
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
2480-
ss.reserve(10000);
2481-
uint256 hash = tx.GetHash();
2482-
CTxLockRequest txLockRequest;
2483-
CDarksendBroadcastTx dstx = CPrivateSend::GetDSTX(hash);
2484-
if(dstx) { // MSG_DSTX
2485-
ss << dstx;
2486-
} else if(instantsend.GetTxLockRequest(hash, txLockRequest)) { // MSG_TXLOCK_REQUEST
2487-
ss << txLockRequest;
2488-
} else { // MSG_TX
2489-
ss << tx;
2490-
}
2491-
RelayTransaction(tx, ss);
2492-
}
2493-
2494-
void CConnman::RelayTransaction(const CTransaction& tx, const CDataStream& ss)
24952478
{
24962479
uint256 hash = tx.GetHash();
24972480
int nInv = static_cast<bool>(CPrivateSend::GetDSTX(hash)) ? MSG_DSTX :
@@ -2506,9 +2489,8 @@ void CConnman::RelayTransaction(const CTransaction& tx, const CDataStream& ss)
25062489
vRelayExpiration.pop_front();
25072490
}
25082491

2509-
// Save original serialized message so newer versions are preserved
2510-
mapRelay.insert(std::make_pair(inv, ss));
2511-
vRelayExpiration.push_back(std::make_pair(GetTime() + 15 * 60, inv));
2492+
mapRelay.insert(std::make_pair(inv.hash, tx));
2493+
vRelayExpiration.push_back(std::make_pair(GetTime() + 15 * 60, inv.hash));
25122494
}
25132495
LOCK(cs_vNodes);
25142496
BOOST_FOREACH(CNode* pnode, vNodes)

src/net.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,8 @@ extern bool fDiscover;
572572
extern bool fListen;
573573
extern bool fRelayTxes;
574574

575-
extern std::map<CInv, CDataStream> mapRelay;
576-
extern std::deque<std::pair<int64_t, CInv> > vRelayExpiration;
575+
extern std::map<uint256, CTransaction> mapRelay;
576+
extern std::deque<std::pair<int64_t, uint256> > vRelayExpiration;
577577
extern CCriticalSection cs_mapRelay;
578578
extern limitedmap<uint256, int64_t> mapAlreadyAskedFor;
579579

src/net_processing.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -886,20 +886,17 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
886886
bool pushed = false;
887887
{
888888
LOCK(cs_mapRelay);
889-
map<CInv, CDataStream>::iterator mi = mapRelay.find(inv);
889+
map<uint256, CTransaction>::iterator mi = mapRelay.find(inv.hash);
890890
if (mi != mapRelay.end()) {
891-
pfrom->PushMessage(inv.GetCommand(), (*mi).second);
891+
connman.PushMessage(pfrom, inv.GetCommand(), (*mi).second);
892892
pushed = true;
893893
}
894894
}
895895

896896
if (!pushed && inv.type == MSG_TX) {
897897
CTransaction tx;
898898
if (mempool.lookup(inv.hash, tx)) {
899-
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
900-
ss.reserve(1000);
901-
ss << tx;
902-
connman.PushMessage(pfrom, NetMsgType::TX, ss);
899+
connman.PushMessage(pfrom, NetMsgType::TX, tx);
903900
pushed = true;
904901
}
905902
}

0 commit comments

Comments
 (0)