MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / ProcessGetBlocksMessage

Function ProcessGetBlocksMessage

src/p2p/chainmessage.cpp:554–601  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

552}
553
554void ProcessGetBlocksMessage(CNode *pFrom, CDataStream &vRecv) {
555 CBlockLocator locator;
556 uint256 hashStop;
557 vRecv >> locator >> hashStop;
558
559 LOCK(cs_main);
560
561 // Find the last block the caller has in the main chain
562 auto *pStartIndex = chainActive.FindFork(mapBlockIndex, locator);
563
564 // Send the rest of the chain
565 if (pStartIndex)
566 pStartIndex = chainActive.Next(pStartIndex);
567
568 int32_t nLimit = 500;
569 LogPrint(BCLog::NET, "recv getblocks msg! start_block=%s, end_block=%s, tip_block=%s, limit=%d, peer=%s\n",
570 (pStartIndex ? pStartIndex->GetIdString() : ""), hashStop.ToString(),
571 chainActive.Tip()->GetIdString(), nLimit, pFrom->addrName);
572
573 CBlockIndex *pIndex = pStartIndex;
574 for (; pIndex; pIndex = chainActive.Next(pIndex)) {
575 if (pIndex->GetBlockHash() == hashStop) {
576 LogPrint(BCLog::NET, "[%d] stoped by hash_end! end_block=%s, peer=%s\n", pIndex->height,
577 pIndex->GetIdString(), pFrom->addrName);
578 break;
579 }
580
581 // bool forced = false;
582 // if (pIndex == pStartIndex || pIndex->pprev == pStartIndex)
583 // forced = true;
584 // pFrom->PushInventory(CInv(MSG_BLOCK, pIndex->GetBlockHash()), forced);
585 bool force_to_send_again = false;
586 if (pIndex == pStartIndex || pIndex->pprev == pStartIndex)
587 force_to_send_again = true;
588
589 pFrom->PushInventory(CInv(MSG_BLOCK, pIndex->GetBlockHash()), force_to_send_again);
590
591 if (--nLimit <= 0) {
592 // When this block is requested, we'll send an inv that'll make them
593 // getblocks the next batch of inventory.
594 LogPrint(BCLog::NET, "processing getblocks stopped by limit! end_block=%s, limit=%d, peer=%s\n",
595 pIndex->GetIdString(), 500, pFrom->addrName);
596
597 pFrom->hashContinue = pIndex->GetBlockHash();
598 break;
599 }
600 }
601}
602
603bool ProcessInvMessage(CNode *pFrom, CDataStream &vRecv) {
604 vector<CInv> vInv;

Callers 1

ProcessMessageFunction · 0.85

Calls 8

FindForkMethod · 0.80
GetIdStringMethod · 0.80
TipMethod · 0.80
PushInventoryMethod · 0.80
CInvClass · 0.70
NextMethod · 0.45
ToStringMethod · 0.45
GetBlockHashMethod · 0.45

Tested by

no test coverage detected