@@ -476,7 +476,7 @@ class PeerManagerImpl final : public PeerManager
476
476
* Returns false, still setting pit, if the block was already in flight from the same peer
477
477
* pit will only be valid as long as the same cs_main lock is being held
478
478
*/
479
- bool BlockRequested (NodeId nodeid, const CBlockIndex* pindex , std::list<QueuedBlock>::iterator** pit = nullptr ) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
479
+ bool BlockRequested (NodeId nodeid, const CBlockIndex& block , std::list<QueuedBlock>::iterator** pit = nullptr ) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
480
480
481
481
bool TipMayBeStale () EXCLUSIVE_LOCKS_REQUIRED(cs_main);
482
482
@@ -793,10 +793,9 @@ void PeerManagerImpl::RemoveBlockRequest(const uint256& hash)
793
793
mapBlocksInFlight.erase (it);
794
794
}
795
795
796
- bool PeerManagerImpl::BlockRequested (NodeId nodeid, const CBlockIndex* pindex , std::list<QueuedBlock>::iterator** pit)
796
+ bool PeerManagerImpl::BlockRequested (NodeId nodeid, const CBlockIndex& block , std::list<QueuedBlock>::iterator** pit)
797
797
{
798
- assert (pindex);
799
- const uint256& hash{pindex->GetBlockHash ()};
798
+ const uint256& hash{block.GetBlockHash ()};
800
799
801
800
CNodeState *state = State (nodeid);
802
801
assert (state != nullptr );
@@ -814,16 +813,17 @@ bool PeerManagerImpl::BlockRequested(NodeId nodeid, const CBlockIndex* pindex, s
814
813
RemoveBlockRequest (hash);
815
814
816
815
std::list<QueuedBlock>::iterator it = state->vBlocksInFlight .insert (state->vBlocksInFlight .end (),
817
- {pindex , std::unique_ptr<PartiallyDownloadedBlock>(pit ? new PartiallyDownloadedBlock (&m_mempool) : nullptr )});
816
+ {&block , std::unique_ptr<PartiallyDownloadedBlock>(pit ? new PartiallyDownloadedBlock (&m_mempool) : nullptr )});
818
817
state->nBlocksInFlight ++;
819
818
if (state->nBlocksInFlight == 1 ) {
820
819
// We're starting a block download (batch) from this peer.
821
820
state->m_downloading_since = GetTime<std::chrono::microseconds>();
822
821
m_peers_downloading_from++;
823
822
}
824
823
itInFlight = mapBlocksInFlight.insert (std::make_pair (hash, std::make_pair (nodeid, it))).first ;
825
- if (pit)
824
+ if (pit) {
826
825
*pit = &itInFlight->second .second ;
826
+ }
827
827
return true ;
828
828
}
829
829
@@ -2091,7 +2091,7 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, const Peer& peer,
2091
2091
}
2092
2092
uint32_t nFetchFlags = GetFetchFlags (pfrom);
2093
2093
vGetData.push_back (CInv (MSG_BLOCK | nFetchFlags, pindex->GetBlockHash ()));
2094
- BlockRequested (pfrom.GetId (), pindex);
2094
+ BlockRequested (pfrom.GetId (), * pindex);
2095
2095
LogPrint (BCLog::NET, " Requesting block %s from peer=%d\n " ,
2096
2096
pindex->GetBlockHash ().ToString (), pfrom.GetId ());
2097
2097
}
@@ -3394,7 +3394,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
3394
3394
if ((!fAlreadyInFlight && nodestate->nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) ||
3395
3395
(fAlreadyInFlight && blockInFlightIt->second .first == pfrom.GetId ())) {
3396
3396
std::list<QueuedBlock>::iterator* queuedBlockIt = nullptr ;
3397
- if (!BlockRequested (pfrom.GetId (), pindex, &queuedBlockIt)) {
3397
+ if (!BlockRequested (pfrom.GetId (), * pindex, &queuedBlockIt)) {
3398
3398
if (!(*queuedBlockIt)->partialBlock )
3399
3399
(*queuedBlockIt)->partialBlock .reset (new PartiallyDownloadedBlock (&m_mempool));
3400
3400
else {
@@ -4778,7 +4778,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
4778
4778
for (const CBlockIndex *pindex : vToDownload) {
4779
4779
uint32_t nFetchFlags = GetFetchFlags (*pto);
4780
4780
vGetData.push_back (CInv (MSG_BLOCK | nFetchFlags, pindex->GetBlockHash ()));
4781
- BlockRequested (pto->GetId (), pindex);
4781
+ BlockRequested (pto->GetId (), * pindex);
4782
4782
LogPrint (BCLog::NET, " Requesting block %s (%d) peer=%d\n " , pindex->GetBlockHash ().ToString (),
4783
4783
pindex->nHeight , pto->GetId ());
4784
4784
}
0 commit comments