mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
merge bitcoin#22221: Pass block reference instead of pointer to PeerManagerImpl::BlockRequested
This commit is contained in:
parent
68657efc03
commit
e24324d266
@ -910,7 +910,7 @@ private:
|
|||||||
* Returns false, still setting pit, if the block was already in flight from the same peer
|
* Returns false, still setting pit, if the block was already in flight from the same peer
|
||||||
* pit will only be valid as long as the same cs_main lock is being held
|
* pit will only be valid as long as the same cs_main lock is being held
|
||||||
*/
|
*/
|
||||||
bool BlockRequested(NodeId nodeid, const CBlockIndex* pindex, std::list<QueuedBlock>::iterator** pit = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
bool BlockRequested(NodeId nodeid, const CBlockIndex& block, std::list<QueuedBlock>::iterator** pit = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
|
|
||||||
bool TipMayBeStale() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
bool TipMayBeStale() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
|
|
||||||
@ -1109,10 +1109,9 @@ void PeerManagerImpl::RemoveBlockRequest(const uint256& hash)
|
|||||||
mapBlocksInFlight.erase(it);
|
mapBlocksInFlight.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PeerManagerImpl::BlockRequested(NodeId nodeid, const CBlockIndex *pindex, std::list<QueuedBlock>::iterator **pit)
|
bool PeerManagerImpl::BlockRequested(NodeId nodeid, const CBlockIndex& block, std::list<QueuedBlock>::iterator **pit)
|
||||||
{
|
{
|
||||||
assert(pindex);
|
const uint256& hash{block.GetBlockHash()};
|
||||||
const uint256& hash{pindex->GetBlockHash()};
|
|
||||||
|
|
||||||
CNodeState *state = State(nodeid);
|
CNodeState *state = State(nodeid);
|
||||||
assert(state != nullptr);
|
assert(state != nullptr);
|
||||||
@ -1130,7 +1129,7 @@ bool PeerManagerImpl::BlockRequested(NodeId nodeid, const CBlockIndex *pindex, s
|
|||||||
RemoveBlockRequest(hash);
|
RemoveBlockRequest(hash);
|
||||||
|
|
||||||
std::list<QueuedBlock>::iterator it = state->vBlocksInFlight.insert(state->vBlocksInFlight.end(),
|
std::list<QueuedBlock>::iterator it = state->vBlocksInFlight.insert(state->vBlocksInFlight.end(),
|
||||||
{pindex, std::unique_ptr<PartiallyDownloadedBlock>(pit ? new PartiallyDownloadedBlock(&m_mempool) : nullptr)});
|
{&block, std::unique_ptr<PartiallyDownloadedBlock>(pit ? new PartiallyDownloadedBlock(&m_mempool) : nullptr)});
|
||||||
state->nBlocksInFlight++;
|
state->nBlocksInFlight++;
|
||||||
if (state->nBlocksInFlight == 1) {
|
if (state->nBlocksInFlight == 1) {
|
||||||
// We're starting a block download (batch) from this peer.
|
// We're starting a block download (batch) from this peer.
|
||||||
@ -1138,8 +1137,9 @@ bool PeerManagerImpl::BlockRequested(NodeId nodeid, const CBlockIndex *pindex, s
|
|||||||
m_peers_downloading_from++;
|
m_peers_downloading_from++;
|
||||||
}
|
}
|
||||||
itInFlight = mapBlocksInFlight.insert(std::make_pair(hash, std::make_pair(nodeid, it))).first;
|
itInFlight = mapBlocksInFlight.insert(std::make_pair(hash, std::make_pair(nodeid, it))).first;
|
||||||
if (pit)
|
if (pit) {
|
||||||
*pit = &itInFlight->second.second;
|
*pit = &itInFlight->second.second;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1822,7 +1822,7 @@ std::optional<std::string> PeerManagerImpl::FetchBlock(NodeId peer_id, const CBl
|
|||||||
// Mark block as in-flight unless it already is (for this peer).
|
// Mark block as in-flight unless it already is (for this peer).
|
||||||
// If a block was already in-flight for a different peer, its BLOCKTXN
|
// If a block was already in-flight for a different peer, its BLOCKTXN
|
||||||
// response will be dropped.
|
// response will be dropped.
|
||||||
if (!BlockRequested(peer_id, &block_index)) return "Already requested from this peer";
|
if (!BlockRequested(peer_id, block_index)) return "Already requested from this peer";
|
||||||
|
|
||||||
// Construct message to request the block
|
// Construct message to request the block
|
||||||
const uint256& hash{block_index.GetBlockHash()};
|
const uint256& hash{block_index.GetBlockHash()};
|
||||||
@ -2812,7 +2812,7 @@ void PeerManagerImpl::HeadersDirectFetchBlocks(CNode& pfrom, const Peer& peer, c
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
vGetData.push_back(CInv(MSG_BLOCK, pindex->GetBlockHash()));
|
vGetData.push_back(CInv(MSG_BLOCK, pindex->GetBlockHash()));
|
||||||
BlockRequested(pfrom.GetId(), pindex);
|
BlockRequested(pfrom.GetId(), *pindex);
|
||||||
LogPrint(BCLog::NET, "Requesting block %s from peer=%d\n",
|
LogPrint(BCLog::NET, "Requesting block %s from peer=%d\n",
|
||||||
pindex->GetBlockHash().ToString(), pfrom.GetId());
|
pindex->GetBlockHash().ToString(), pfrom.GetId());
|
||||||
}
|
}
|
||||||
@ -4353,7 +4353,7 @@ void PeerManagerImpl::ProcessMessage(
|
|||||||
if ((!fAlreadyInFlight && nodestate->nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) ||
|
if ((!fAlreadyInFlight && nodestate->nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) ||
|
||||||
(fAlreadyInFlight && blockInFlightIt->second.first == pfrom.GetId())) {
|
(fAlreadyInFlight && blockInFlightIt->second.first == pfrom.GetId())) {
|
||||||
std::list<QueuedBlock>::iterator *queuedBlockIt = nullptr;
|
std::list<QueuedBlock>::iterator *queuedBlockIt = nullptr;
|
||||||
if (!BlockRequested(pfrom.GetId(), pindex, &queuedBlockIt)) {
|
if (!BlockRequested(pfrom.GetId(), *pindex, &queuedBlockIt)) {
|
||||||
if (!(*queuedBlockIt)->partialBlock)
|
if (!(*queuedBlockIt)->partialBlock)
|
||||||
(*queuedBlockIt)->partialBlock.reset(new PartiallyDownloadedBlock(&m_mempool));
|
(*queuedBlockIt)->partialBlock.reset(new PartiallyDownloadedBlock(&m_mempool));
|
||||||
else {
|
else {
|
||||||
@ -5910,7 +5910,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
|
|||||||
FindNextBlocksToDownload(*peer, MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.nBlocksInFlight, vToDownload, staller);
|
FindNextBlocksToDownload(*peer, MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.nBlocksInFlight, vToDownload, staller);
|
||||||
for (const CBlockIndex *pindex : vToDownload) {
|
for (const CBlockIndex *pindex : vToDownload) {
|
||||||
vGetData.push_back(CInv(MSG_BLOCK, pindex->GetBlockHash()));
|
vGetData.push_back(CInv(MSG_BLOCK, pindex->GetBlockHash()));
|
||||||
BlockRequested(pto->GetId(), pindex);
|
BlockRequested(pto->GetId(), *pindex);
|
||||||
LogPrint(BCLog::NET, "Requesting block %s (%d) peer=%d\n", pindex->GetBlockHash().ToString(),
|
LogPrint(BCLog::NET, "Requesting block %s (%d) peer=%d\n", pindex->GetBlockHash().ToString(),
|
||||||
pindex->nHeight, pto->GetId());
|
pindex->nHeight, pto->GetId());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user