Skip to content

Commit

Permalink
Merge branch 'fix_622_nits' into 'master'
Browse files Browse the repository at this point in the history
[net] Follow-up to !622, reduce/remove some double-copies and other nits

Closes Bitcoin-ABC#133

See merge request bitcoin-cash-node/bitcoin-cash-node!672
  • Loading branch information
dagurval committed Aug 18, 2020
2 parents 7bff4b5 + c9830c7 commit 534469c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
10 changes: 5 additions & 5 deletions src/net.h
Expand Up @@ -856,13 +856,13 @@ class CNode {
void PushInventory(const CInv &inv) {
LOCK(cs_inventory);
if (inv.type == MSG_TX) {
const TxId txid(inv.hash);
if (!filterInventoryKnown.contains(txid)) {
setInventoryTxToSend.insert(txid);
// inv.hash is a TxId
if (!filterInventoryKnown.contains(inv.hash)) {
setInventoryTxToSend.emplace(inv.hash);
}
} else if (inv.type == MSG_BLOCK) {
const BlockHash hash(inv.hash);
vInventoryBlockToSend.push_back(hash);
// inv.hash is a BlockHash
vInventoryBlockToSend.emplace_back(inv.hash);
}
}

Expand Down
28 changes: 12 additions & 16 deletions src/net_processing.cpp
Expand Up @@ -1672,8 +1672,8 @@ static void ProcessGetBlockData(const Config &config, CNode *pfrom,
// want it right after the last block so they don't wait for other
// stuff first.
std::vector<CInv> vInv;
vInv.push_back(
CInv(MSG_BLOCK, ::ChainActive().Tip()->GetBlockHash()));
vInv.emplace_back(
MSG_BLOCK, ::ChainActive().Tip()->GetBlockHash());
connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::INV, vInv));
pfrom->hashContinue = BlockHash();
}
Expand Down Expand Up @@ -1981,7 +1981,7 @@ static bool ProcessHeadersMessage(const Config &config, CNode *pfrom,
// Can't download any more from this peer
break;
}
vGetData.push_back(CInv(MSG_BLOCK, pindex->GetBlockHash()));
vGetData.emplace_back(MSG_BLOCK, pindex->GetBlockHash());
MarkBlockAsInFlight(config, pfrom->GetId(),
pindex->GetBlockHash(),
chainparams.GetConsensus(), pindex);
Expand Down Expand Up @@ -2661,10 +2661,7 @@ static bool ProcessMessage(const Config &config, CNode *pfrom,
LogPrint(BCLog::NET,
"Peer %d sent us a getblocktxn for a block > %i deep\n",
pfrom->GetId(), MAX_BLOCKTXN_DEPTH);
CInv inv;
inv.type = MSG_BLOCK;
inv.hash = req.blockhash;
pfrom->vRecvGetData.push_back(inv);
pfrom->vRecvGetData.emplace_back(MSG_BLOCK, req.blockhash);
// The message processing loop will go around again (without
// pausing) and we'll respond then (without cs_main)
return true;
Expand Down Expand Up @@ -3325,7 +3322,7 @@ static bool ProcessMessage(const Config &config, CNode *pfrom,
} else if (status == READ_STATUS_FAILED) {
// Might have collided, fall back to getdata now :(
std::vector<CInv> invs;
invs.push_back(CInv(MSG_BLOCK, resp.blockhash));
invs.emplace_back(MSG_BLOCK, resp.blockhash);
connman->PushMessage(pfrom,
msgMaker.Make(NetMsgType::GETDATA, invs));
} else {
Expand Down Expand Up @@ -4435,7 +4432,7 @@ bool PeerLogicValidation::SendMessages(const Config &config, CNode *pto,

// Add blocks
for (const BlockHash &hash : pto->vInventoryBlockToSend) {
vInv.push_back(CInv(MSG_BLOCK, hash));
vInv.emplace_back(MSG_BLOCK, hash);
if (vInv.size() == MAX_INV_SZ) {
connman->PushMessage(pto, msgMaker.Make(NetMsgType::INV, vInv));
vInv.clear();
Expand Down Expand Up @@ -4480,7 +4477,6 @@ bool PeerLogicValidation::SendMessages(const Config &config, CNode *pto,

for (const auto &txinfo : vtxinfo) {
const TxId &txid = txinfo.tx->GetId();
CInv inv(MSG_TX, txid);
pto->setInventoryTxToSend.erase(txid);
if (filterrate != Amount::zero() &&
txinfo.feeRate.GetFeePerK() < filterrate) {
Expand All @@ -4491,7 +4487,7 @@ bool PeerLogicValidation::SendMessages(const Config &config, CNode *pto,
continue;
}
pto->filterInventoryKnown.insert(txid);
vInv.push_back(inv);
vInv.emplace_back(MSG_TX, txid);
if (vInv.size() == MAX_INV_SZ) {
connman->PushMessage(pto,
msgMaker.Make(NetMsgType::INV, vInv));
Expand Down Expand Up @@ -4557,7 +4553,7 @@ bool PeerLogicValidation::SendMessages(const Config &config, CNode *pto,
continue;
}
// Send
vInv.push_back(CInv(MSG_TX, txid));
vInv.emplace_back(MSG_TX, txid);
nRelayedTransactions++;
{
// Expire old relay messages
Expand All @@ -4570,8 +4566,8 @@ bool PeerLogicValidation::SendMessages(const Config &config, CNode *pto,
auto ret = mapRelay.insert(
std::make_pair(txid, std::move(txinfo.tx)));
if (ret.second) {
vRelayExpiration.push_back(std::make_pair(
nNow + 15 * 60 * 1000000, ret.first));
vRelayExpiration.emplace_back(
nNow + 15 * 60 * 1000000, ret.first);
}
}
if (vInv.size() == MAX_INV_SZ) {
Expand Down Expand Up @@ -4682,7 +4678,7 @@ bool PeerLogicValidation::SendMessages(const Config &config, CNode *pto,
state.nBlocksInFlight,
vToDownload, staller, consensusParams);
for (const CBlockIndex *pindex : vToDownload) {
vGetData.push_back(CInv(MSG_BLOCK, pindex->GetBlockHash()));
vGetData.emplace_back(MSG_BLOCK, pindex->GetBlockHash());
MarkBlockAsInFlight(config, pto->GetId(), pindex->GetBlockHash(),
consensusParams, pindex);
LogPrint(BCLog::NET, "Requesting block %s (%d) peer=%d\n",
Expand Down Expand Up @@ -4730,7 +4726,7 @@ bool PeerLogicValidation::SendMessages(const Config &config, CNode *pto,
// Erase this entry from tx_process_time (it may be added back for
// processing at a later time, see below)
tx_process_time.erase(tx_process_time.begin());
CInv inv(MSG_TX, txid);
const CInv inv(MSG_TX, txid);
if (!AlreadyHave(inv)) {
// If this transaction was last requested more than 1 minute ago,
// then request.
Expand Down

0 comments on commit 534469c

Please sign in to comment.