mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-21 06:12:30 +02:00
p2p: use CInv block message helpers in net_processing.cpp
This commit is contained in:
parent
acd6642167
commit
b1c855453b
@ -1555,7 +1555,7 @@ void static ProcessGetBlockData(CNode& pfrom, const CChainParams& chainparams, c
|
|||||||
// disconnect node in case we have reached the outbound limit for serving historical blocks
|
// disconnect node in case we have reached the outbound limit for serving historical blocks
|
||||||
if (send &&
|
if (send &&
|
||||||
connman.OutboundTargetReached(true) &&
|
connman.OutboundTargetReached(true) &&
|
||||||
(((pindexBestHeader != nullptr) && (pindexBestHeader->GetBlockTime() - pindex->GetBlockTime() > HISTORICAL_BLOCK_AGE)) || inv.type == MSG_FILTERED_BLOCK) &&
|
(((pindexBestHeader != nullptr) && (pindexBestHeader->GetBlockTime() - pindex->GetBlockTime() > HISTORICAL_BLOCK_AGE)) || inv.IsMsgFilteredBlk()) &&
|
||||||
!pfrom.HasPermission(PF_DOWNLOAD) // nodes with the download permission may exceed target
|
!pfrom.HasPermission(PF_DOWNLOAD) // nodes with the download permission may exceed target
|
||||||
) {
|
) {
|
||||||
LogPrint(BCLog::NET, "historical block serving limit reached, disconnect peer=%d\n", pfrom.GetId());
|
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
|
|||||||
std::shared_ptr<const CBlock> pblock;
|
std::shared_ptr<const CBlock> pblock;
|
||||||
if (a_recent_block && a_recent_block->GetHash() == pindex->GetBlockHash()) {
|
if (a_recent_block && a_recent_block->GetHash() == pindex->GetBlockHash()) {
|
||||||
pblock = a_recent_block;
|
pblock = a_recent_block;
|
||||||
} else if (inv.type == MSG_WITNESS_BLOCK) {
|
} else if (inv.IsMsgWitnessBlk()) {
|
||||||
// Fast-path: in this case it is possible to serve the block directly from disk,
|
// Fast-path: in this case it is possible to serve the block directly from disk,
|
||||||
// as the network format matches the format on disk
|
// as the network format matches the format on disk
|
||||||
std::vector<uint8_t> block_data;
|
std::vector<uint8_t> block_data;
|
||||||
@ -1598,12 +1598,11 @@ void static ProcessGetBlockData(CNode& pfrom, const CChainParams& chainparams, c
|
|||||||
pblock = pblockRead;
|
pblock = pblockRead;
|
||||||
}
|
}
|
||||||
if (pblock) {
|
if (pblock) {
|
||||||
if (inv.type == MSG_BLOCK)
|
if (inv.IsMsgBlk()) {
|
||||||
connman.PushMessage(&pfrom, msgMaker.Make(SERIALIZE_TRANSACTION_NO_WITNESS, NetMsgType::BLOCK, *pblock));
|
connman.PushMessage(&pfrom, msgMaker.Make(SERIALIZE_TRANSACTION_NO_WITNESS, NetMsgType::BLOCK, *pblock));
|
||||||
else if (inv.type == MSG_WITNESS_BLOCK)
|
} else if (inv.IsMsgWitnessBlk()) {
|
||||||
connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::BLOCK, *pblock));
|
connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::BLOCK, *pblock));
|
||||||
else if (inv.type == MSG_FILTERED_BLOCK)
|
} else if (inv.IsMsgFilteredBlk()) {
|
||||||
{
|
|
||||||
bool sendMerkleBlock = false;
|
bool sendMerkleBlock = false;
|
||||||
CMerkleBlock merkleBlock;
|
CMerkleBlock merkleBlock;
|
||||||
if (pfrom.m_tx_relay != nullptr) {
|
if (pfrom.m_tx_relay != nullptr) {
|
||||||
@ -1627,9 +1626,7 @@ void static ProcessGetBlockData(CNode& pfrom, const CChainParams& chainparams, c
|
|||||||
}
|
}
|
||||||
// else
|
// else
|
||||||
// no response
|
// no response
|
||||||
}
|
} else if (inv.IsMsgCmpctBlk()) {
|
||||||
else if (inv.type == MSG_CMPCT_BLOCK)
|
|
||||||
{
|
|
||||||
// If a peer is asking for old blocks, we're almost guaranteed
|
// If a peer is asking for old blocks, we're almost guaranteed
|
||||||
// they won't have a useful mempool to match against a compact block,
|
// they won't have a useful mempool to match against a compact block,
|
||||||
// and we don't feel like constructing the object for them, so
|
// 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
|
|||||||
// expensive to process.
|
// expensive to process.
|
||||||
if (it != pfrom.vRecvGetData.end() && !pfrom.fPauseSend) {
|
if (it != pfrom.vRecvGetData.end() && !pfrom.fPauseSend) {
|
||||||
const CInv &inv = *it++;
|
const CInv &inv = *it++;
|
||||||
if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK || inv.type == MSG_CMPCT_BLOCK || inv.type == MSG_WITNESS_BLOCK) {
|
if (inv.IsGenBlkMsg()) {
|
||||||
ProcessGetBlockData(pfrom, chainparams, inv, connman);
|
ProcessGetBlockData(pfrom, chainparams, inv, connman);
|
||||||
}
|
}
|
||||||
// else: If the first item on the queue is an unknown type, we erase it
|
// 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
|
|||||||
if (inv.IsMsgWtx()) continue;
|
if (inv.IsMsgWtx()) continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inv.type == MSG_BLOCK) {
|
if (inv.IsMsgBlk()) {
|
||||||
bool fAlreadyHave = AlreadyHaveBlock(inv.hash);
|
bool fAlreadyHave = AlreadyHaveBlock(inv.hash);
|
||||||
LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId());
|
LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user