Skip to content

Commit c251d71

Browse files
committed
p2p, refactoring: use CInv helpers in net_processing.cpp
to simplify the code and reach less from it into the CInv class internals
1 parent 4254cd9 commit c251d71

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/net_processing.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,9 +1445,9 @@ bool static AlreadyHave(const CInv& inv, const CTxMemPool& mempool) EXCLUSIVE_LO
14451445

14461446
{
14471447
LOCK(g_cs_orphans);
1448-
if (inv.type != MSG_WTX && mapOrphanTransactions.count(inv.hash)) {
1448+
if (!inv.IsMsgWtx() && mapOrphanTransactions.count(inv.hash)) {
14491449
return true;
1450-
} else if (inv.type == MSG_WTX && g_orphans_by_wtxid.count(inv.hash)) {
1450+
} else if (inv.IsMsgWtx() && g_orphans_by_wtxid.count(inv.hash)) {
14511451
return true;
14521452
}
14531453
}
@@ -1457,8 +1457,7 @@ bool static AlreadyHave(const CInv& inv, const CTxMemPool& mempool) EXCLUSIVE_LO
14571457
if (g_recent_confirmed_transactions->contains(inv.hash)) return true;
14581458
}
14591459

1460-
const bool by_wtxid = (inv.type == MSG_WTX);
1461-
return recentRejects->contains(inv.hash) || mempool.exists(inv.hash, by_wtxid);
1460+
return recentRejects->contains(inv.hash) || mempool.exists(inv.hash, inv.IsMsgWtx());
14621461
}
14631462
case MSG_BLOCK:
14641463
case MSG_WITNESS_BLOCK:
@@ -1719,7 +1718,7 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm
17191718
// Process as many TX items from the front of the getdata queue as
17201719
// possible, since they're common and it's efficient to batch process
17211720
// them.
1722-
while (it != pfrom.vRecvGetData.end() && (it->type == MSG_TX || it->type == MSG_WITNESS_TX || it->type == MSG_WTX)) {
1721+
while (it != pfrom.vRecvGetData.end() && it->IsGenTxMsg()) {
17231722
if (interruptMsgProc) return;
17241723
// The send buffer provides backpressure. If there's no space in
17251724
// the buffer, pause processing until the next call.
@@ -1732,10 +1731,10 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm
17321731
continue;
17331732
}
17341733

1735-
CTransactionRef tx = FindTxForGetData(pfrom, inv.hash, inv.type == MSG_WTX, mempool_req, now);
1734+
CTransactionRef tx = FindTxForGetData(pfrom, inv.hash, inv.IsMsgWtx(), mempool_req, now);
17361735
if (tx) {
17371736
// WTX and WITNESS_TX imply we serialize with witness
1738-
int nSendFlags = (inv.type == MSG_TX ? SERIALIZE_TRANSACTION_NO_WITNESS : 0);
1737+
int nSendFlags = (inv.IsMsgTx() ? SERIALIZE_TRANSACTION_NO_WITNESS : 0);
17391738
connman.PushMessage(&pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *tx));
17401739
mempool.RemoveUnbroadcastTx(tx->GetHash());
17411740
// As we're going to send tx, make sure its unconfirmed parents are made requestable.
@@ -2654,15 +2653,15 @@ void ProcessMessage(
26542653

26552654
// ignore INVs that don't match wtxidrelay setting
26562655
if (State(pfrom.GetId())->m_wtxid_relay) {
2657-
if (inv.type == MSG_TX) continue;
2656+
if (inv.IsMsgTx()) continue;
26582657
} else {
2659-
if (inv.type == MSG_WTX) continue;
2658+
if (inv.IsMsgWtx()) continue;
26602659
}
26612660

26622661
bool fAlreadyHave = AlreadyHave(inv, mempool);
26632662
LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId());
26642663

2665-
if (inv.type == MSG_TX) {
2664+
if (inv.IsMsgTx()) {
26662665
inv.type |= nFetchFlags;
26672666
}
26682667

@@ -3694,7 +3693,7 @@ void ProcessMessage(
36943693
vRecv >> vInv;
36953694
if (vInv.size() <= MAX_PEER_TX_IN_FLIGHT + MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
36963695
for (CInv &inv : vInv) {
3697-
if (inv.type == MSG_TX || inv.type == MSG_WITNESS_TX || inv.type == MSG_WTX) {
3696+
if (inv.IsGenTxMsg()) {
36983697
// If we receive a NOTFOUND message for a txid we requested, erase
36993698
// it from our data structures for this peer.
37003699
auto in_flight_it = state->m_tx_download.m_tx_in_flight.find(inv.hash);

0 commit comments

Comments
 (0)