mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-21 17:42:37 +02:00
Bugfix: net_processing: Restore "Already requested" error for FetchBlock
This commit is contained in:
parent
79e8247ddb
commit
2b67ea465c
@ -878,6 +878,9 @@ private:
|
|||||||
/** Have we requested this block from an outbound peer */
|
/** Have we requested this block from an outbound peer */
|
||||||
bool IsBlockRequestedFromOutbound(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
bool IsBlockRequestedFromOutbound(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
|
|
||||||
|
/** Have we requested this block from a specific peer */
|
||||||
|
bool IsBlockRequestedFromPeer(const uint256& hash, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
|
|
||||||
/** Remove this block from our tracked requested blocks. Called if:
|
/** Remove this block from our tracked requested blocks. Called if:
|
||||||
* - the block has been received from a peer
|
* - the block has been received from a peer
|
||||||
* - the request for the block has timed out
|
* - the request for the block has timed out
|
||||||
@ -1132,6 +1135,16 @@ bool PeerManagerImpl::IsBlockRequestedFromOutbound(const uint256& hash)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PeerManagerImpl::IsBlockRequestedFromPeer(const uint256& hash, NodeId peer)
|
||||||
|
{
|
||||||
|
for (auto range = mapBlocksInFlight.equal_range(hash); range.first != range.second; range.first++) {
|
||||||
|
auto [nodeid, block_it] = range.first->second;
|
||||||
|
if (nodeid == peer) return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void PeerManagerImpl::RemoveBlockRequest(const uint256& hash, std::optional<NodeId> from_peer)
|
void PeerManagerImpl::RemoveBlockRequest(const uint256& hash, std::optional<NodeId> from_peer)
|
||||||
{
|
{
|
||||||
auto range = mapBlocksInFlight.equal_range(hash);
|
auto range = mapBlocksInFlight.equal_range(hash);
|
||||||
@ -1781,16 +1794,19 @@ std::optional<std::string> PeerManagerImpl::FetchBlock(NodeId peer_id, const CBl
|
|||||||
// Ignore pre-segwit peers
|
// Ignore pre-segwit peers
|
||||||
if (!CanServeWitnesses(*peer)) return "Pre-SegWit peer";
|
if (!CanServeWitnesses(*peer)) return "Pre-SegWit peer";
|
||||||
|
|
||||||
|
const uint256& hash{block_index.GetBlockHash()};
|
||||||
|
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
|
|
||||||
|
if (IsBlockRequestedFromPeer(hash, peer_id)) return "Already requested from this peer";
|
||||||
|
|
||||||
// Forget about all prior requests
|
// Forget about all prior requests
|
||||||
RemoveBlockRequest(block_index.GetBlockHash(), std::nullopt);
|
RemoveBlockRequest(hash, std::nullopt);
|
||||||
|
|
||||||
// Mark block as in-flight
|
// Mark block as in-flight
|
||||||
if (!BlockRequested(peer_id, block_index)) return "Already requested from this peer";
|
Assume(BlockRequested(peer_id, block_index));
|
||||||
|
|
||||||
// Construct message to request the block
|
// Construct message to request the block
|
||||||
const uint256& hash{block_index.GetBlockHash()};
|
|
||||||
std::vector<CInv> invs{CInv(MSG_BLOCK | MSG_WITNESS_FLAG, hash)};
|
std::vector<CInv> invs{CInv(MSG_BLOCK | MSG_WITNESS_FLAG, hash)};
|
||||||
|
|
||||||
// Send block request message to the peer
|
// Send block request message to the peer
|
||||||
|
Loading…
Reference in New Issue
Block a user