aboutsummaryrefslogtreecommitdiff
path: root/src/net_processing.cpp
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2023-05-12 09:51:42 +0100
committerfanquake <fanquake@gmail.com>2023-05-12 10:07:58 +0100
commit2e9fc2e353fe56e8e9ea2b2505aa69b9825122f7 (patch)
treec147e25bfec46db1f674306eaa2c27e20cb94d14 /src/net_processing.cpp
parent7b7636ead18fd006815d867aa580b34e3e70731e (diff)
parenta26ff204f0f0355749a1b61136437623b325f8fb (diff)
downloadbitcoin-2e9fc2e353fe56e8e9ea2b2505aa69b9825122f7.tar.xz
Merge bitcoin/bitcoin#27624: [23.2] Backports for rc1v23.2rc1
a26ff204f0f0355749a1b61136437623b325f8fb doc: add initial release notes for v23.2 (fanquake) 60edfd57f1334497041655384238c43d3fc76184 doc: update manual pages for v23.2rc1 (fanquake) b93814b234e4cf5ec95017b3cd54ce59c0aa59e8 doc: update version in bips.md to v23.2 (fanquake) 67bbe6d371fc33e0b17f2dc0a6a7faa5ab64dad0 build: bump version to v23.2rc1 (fanquake) 06731d19bc00820037961138c79cf3d3677e39ba net_processing: Boost inv trickle rate (Anthony Towns) d0a2c87214d2a8ad350c86fd4a3202695569ca99 txmempool: have CompareDepthAndScore sort missing txs first (Anthony Towns) ce8f812b0ac0905c26edd826c57886a08079b4a7 p2p: Avoid prematurely clearing download state for other peers (Suhas Daftuar) Pull request description: Final backports for `rc1`. Currently: * https://github.com/bitcoin/bitcoin/pull/27608 (not a clean cherry-pick) * https://github.com/bitcoin/bitcoin/pull/27610 (second commit is not clean) ACKs for top commit: achow101: ACK a26ff204f0f0355749a1b61136437623b325f8fb dergoegge: ACK a26ff204f0f0355749a1b61136437623b325f8fb ajtowns: utACK a26ff204f0f0355749a1b61136437623b325f8fb Tree-SHA512: 59e43ec4d5004b3543d5c0366c9dc8c5f8a6a777b147628ebc0c03aeb0846312a7780376ebf40f389e3403e4501ba2b70bb97925479670bee13c89e5b6925137
Diffstat (limited to 'src/net_processing.cpp')
-rw-r--r--src/net_processing.cpp34
1 files changed, 25 insertions, 9 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index aee1e4c30c..0e75ec99ec 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -541,8 +541,11 @@ private:
/** Remove this block from our tracked requested blocks. Called if:
* - the block has been received from a peer
* - the request for the block has timed out
+ * If "from_peer" is specified, then only remove the block if it is in
+ * flight from that peer (to avoid one peer's network traffic from
+ * affecting another's state).
*/
- void RemoveBlockRequest(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
+ void RemoveBlockRequest(const uint256& hash, std::optional<NodeId> from_peer) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
/* Mark a block as in flight
* Returns false, still setting pit, if the block was already in flight from the same peer
@@ -853,7 +856,7 @@ bool PeerManagerImpl::IsBlockRequested(const uint256& hash)
return mapBlocksInFlight.find(hash) != mapBlocksInFlight.end();
}
-void PeerManagerImpl::RemoveBlockRequest(const uint256& hash)
+void PeerManagerImpl::RemoveBlockRequest(const uint256& hash, std::optional<NodeId> from_peer)
{
auto it = mapBlocksInFlight.find(hash);
if (it == mapBlocksInFlight.end()) {
@@ -862,6 +865,12 @@ void PeerManagerImpl::RemoveBlockRequest(const uint256& hash)
}
auto [node_id, list_it] = it->second;
+
+ if (from_peer && node_id != *from_peer) {
+ // Block was requested by another peer
+ return;
+ }
+
CNodeState *state = State(node_id);
assert(state != nullptr);
@@ -897,7 +906,7 @@ bool PeerManagerImpl::BlockRequested(NodeId nodeid, const CBlockIndex& block, st
}
// Make sure it's not listed somewhere already.
- RemoveBlockRequest(hash);
+ RemoveBlockRequest(hash, std::nullopt);
std::list<QueuedBlock>::iterator it = state->vBlocksInFlight.insert(state->vBlocksInFlight.end(),
{&block, std::unique_ptr<PartiallyDownloadedBlock>(pit ? new PartiallyDownloadedBlock(&m_mempool) : nullptr)});
@@ -2545,6 +2554,11 @@ void PeerManagerImpl::ProcessBlock(CNode& node, const std::shared_ptr<const CBlo
m_chainman.ProcessNewBlock(m_chainparams, block, force_processing, &new_block);
if (new_block) {
node.m_last_block_time = GetTime<std::chrono::seconds>();
+ // In case this block came from a different peer than we requested
+ // from, we can erase the block request now anyway (as we just stored
+ // this block to disk).
+ LOCK(cs_main);
+ RemoveBlockRequest(block->GetHash(), std::nullopt);
} else {
LOCK(cs_main);
mapBlockSource.erase(block->GetHash());
@@ -3604,7 +3618,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
PartiallyDownloadedBlock& partialBlock = *(*queuedBlockIt)->partialBlock;
ReadStatus status = partialBlock.InitData(cmpctblock, vExtraTxnForCompact);
if (status == READ_STATUS_INVALID) {
- RemoveBlockRequest(pindex->GetBlockHash()); // Reset in-flight state in case Misbehaving does not result in a disconnect
+ RemoveBlockRequest(pindex->GetBlockHash(), pfrom.GetId()); // Reset in-flight state in case Misbehaving does not result in a disconnect
Misbehaving(pfrom.GetId(), 100, "invalid compact block");
return;
} else if (status == READ_STATUS_FAILED) {
@@ -3699,7 +3713,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
// process from some other peer. We do this after calling
// ProcessNewBlock so that a malleated cmpctblock announcement
// can't be used to interfere with block relay.
- RemoveBlockRequest(pblock->GetHash());
+ RemoveBlockRequest(pblock->GetHash(), std::nullopt);
}
}
return;
@@ -3731,7 +3745,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
PartiallyDownloadedBlock& partialBlock = *it->second.second->partialBlock;
ReadStatus status = partialBlock.FillBlock(*pblock, resp.txn);
if (status == READ_STATUS_INVALID) {
- RemoveBlockRequest(resp.blockhash); // Reset in-flight state in case Misbehaving does not result in a disconnect
+ RemoveBlockRequest(resp.blockhash, pfrom.GetId()); // Reset in-flight state in case Misbehaving does not result in a disconnect
Misbehaving(pfrom.GetId(), 100, "invalid compact block/non-matching block transactions");
return;
} else if (status == READ_STATUS_FAILED) {
@@ -3757,7 +3771,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
// though the block was successfully read, and rely on the
// handling in ProcessNewBlock to ensure the block index is
// updated, etc.
- RemoveBlockRequest(resp.blockhash); // it is now an empty pointer
+ RemoveBlockRequest(resp.blockhash, pfrom.GetId()); // it is now an empty pointer
fBlockRead = true;
// mapBlockSource is used for potentially punishing peers and
// updating which peers send us compact blocks, so the race
@@ -3825,7 +3839,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
// Always process the block if we requested it, since we may
// need it even when it's not a candidate for a new best tip.
forceProcessing = IsBlockRequested(hash);
- RemoveBlockRequest(hash);
+ RemoveBlockRequest(hash, pfrom.GetId());
// mapBlockSource is only used for punishing peers and setting
// which peers send us compact blocks, so the race between here and
// cs_main in ProcessNewBlock is fine.
@@ -4876,7 +4890,9 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
// especially since we have many peers and some will draw much shorter delays.
unsigned int nRelayedTransactions = 0;
LOCK(pto->m_tx_relay->cs_filter);
- while (!vInvTx.empty() && nRelayedTransactions < INVENTORY_BROADCAST_MAX) {
+ size_t broadcast_max{INVENTORY_BROADCAST_MAX + (pto->m_tx_relay->setInventoryTxToSend.size()/1000)*5};
+ broadcast_max = std::min<size_t>(1000, broadcast_max);
+ while (!vInvTx.empty() && nRelayedTransactions < broadcast_max) {
// Fetch the top element from the heap
std::pop_heap(vInvTx.begin(), vInvTx.end(), compareInvMempoolOrder);
std::set<uint256>::iterator it = vInvTx.back();