diff --git a/src/net_processing.cpp b/src/net_processing.cpp index bcf4521ea3..4e0d7322cb 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -3812,8 +3812,12 @@ bool PeerLogicValidation::SendMessages(CNode* pto, std::atomic& interruptM // std::vector vInv; { + size_t reserve = std::min(pto->setInventoryTxToSend.size(), INVENTORY_BROADCAST_MAX_PER_1MB_BLOCK * MaxBlockSize(true) / 1000000); + reserve = std::max(reserve, pto->vInventoryBlockToSend.size()); + reserve = std::min(reserve, MAX_INV_SZ); + vInv.reserve(reserve); + LOCK(pto->cs_inventory); - vInv.reserve(std::max(pto->vInventoryBlockToSend.size(), INVENTORY_BROADCAST_MAX_PER_1MB_BLOCK * MaxBlockSize(true) / 1000000)); // Add blocks for (const uint256& hash : pto->vInventoryBlockToSend) {