Skip to content

Commit b1c8554

Browse files
committed
p2p: use CInv block message helpers in net_processing.cpp
1 parent acd6642 commit b1c8554

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/net_processing.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,7 +1555,7 @@ void static ProcessGetBlockData(CNode& pfrom, const CChainParams& chainparams, c
15551555
// disconnect node in case we have reached the outbound limit for serving historical blocks
15561556
if (send &&
15571557
connman.OutboundTargetReached(true) &&
1558-
(((pindexBestHeader != nullptr) && (pindexBestHeader->GetBlockTime() - pindex->GetBlockTime() > HISTORICAL_BLOCK_AGE)) || inv.type == MSG_FILTERED_BLOCK) &&
1558+
(((pindexBestHeader != nullptr) && (pindexBestHeader->GetBlockTime() - pindex->GetBlockTime() > HISTORICAL_BLOCK_AGE)) || inv.IsMsgFilteredBlk()) &&
15591559
!pfrom.HasPermission(PF_DOWNLOAD) // nodes with the download permission may exceed target
15601560
) {
15611561
LogPrint(BCLog::NET, "historical block serving limit reached, disconnect peer=%d\n", pfrom.GetId());
@@ -1581,7 +1581,7 @@ void static ProcessGetBlockData(CNode& pfrom, const CChainParams& chainparams, c
15811581
std::shared_ptr<const CBlock> pblock;
15821582
if (a_recent_block && a_recent_block->GetHash() == pindex->GetBlockHash()) {
15831583
pblock = a_recent_block;
1584-
} else if (inv.type == MSG_WITNESS_BLOCK) {
1584+
} else if (inv.IsMsgWitnessBlk()) {
15851585
// Fast-path: in this case it is possible to serve the block directly from disk,
15861586
// as the network format matches the format on disk
15871587
std::vector<uint8_t> block_data;
@@ -1598,12 +1598,11 @@ void static ProcessGetBlockData(CNode& pfrom, const CChainParams& chainparams, c
15981598
pblock = pblockRead;
15991599
}
16001600
if (pblock) {
1601-
if (inv.type == MSG_BLOCK)
1601+
if (inv.IsMsgBlk()) {
16021602
connman.PushMessage(&pfrom, msgMaker.Make(SERIALIZE_TRANSACTION_NO_WITNESS, NetMsgType::BLOCK, *pblock));
1603-
else if (inv.type == MSG_WITNESS_BLOCK)
1603+
} else if (inv.IsMsgWitnessBlk()) {
16041604
connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::BLOCK, *pblock));
1605-
else if (inv.type == MSG_FILTERED_BLOCK)
1606-
{
1605+
} else if (inv.IsMsgFilteredBlk()) {
16071606
bool sendMerkleBlock = false;
16081607
CMerkleBlock merkleBlock;
16091608
if (pfrom.m_tx_relay != nullptr) {
@@ -1627,9 +1626,7 @@ void static ProcessGetBlockData(CNode& pfrom, const CChainParams& chainparams, c
16271626
}
16281627
// else
16291628
// no response
1630-
}
1631-
else if (inv.type == MSG_CMPCT_BLOCK)
1632-
{
1629+
} else if (inv.IsMsgCmpctBlk()) {
16331630
// If a peer is asking for old blocks, we're almost guaranteed
16341631
// they won't have a useful mempool to match against a compact block,
16351632
// and we don't feel like constructing the object for them, so
@@ -1757,7 +1754,7 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm
17571754
// expensive to process.
17581755
if (it != pfrom.vRecvGetData.end() && !pfrom.fPauseSend) {
17591756
const CInv &inv = *it++;
1760-
if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK || inv.type == MSG_CMPCT_BLOCK || inv.type == MSG_WITNESS_BLOCK) {
1757+
if (inv.IsGenBlkMsg()) {
17611758
ProcessGetBlockData(pfrom, chainparams, inv, connman);
17621759
}
17631760
// else: If the first item on the queue is an unknown type, we erase it
@@ -2661,7 +2658,7 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
26612658
if (inv.IsMsgWtx()) continue;
26622659
}
26632660

2664-
if (inv.type == MSG_BLOCK) {
2661+
if (inv.IsMsgBlk()) {
26652662
bool fAlreadyHave = AlreadyHaveBlock(inv.hash);
26662663
LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId());
26672664

0 commit comments

Comments
 (0)