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

Function ProcessInvMessage

src/p2p/chainmessage.cpp:603–675  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

601}
602
603bool ProcessInvMessage(CNode *pFrom, CDataStream &vRecv) {
604 vector<CInv> vInv;
605 vRecv >> vInv;
606 if (vInv.size() > MAX_INV_SZ) {
607 Misbehaving(pFrom->GetId(), 20);
608 return ERRORMSG("message inv size() = %u from peer %s", vInv.size(), pFrom->addrName);
609 }
610
611 LOCK(cs_main);
612
613 int i = 0;
614 for (CInv &inv : vInv) {
615 boost::this_thread::interruption_point();
616 pFrom->AddInventoryKnown(inv);
617
618 bool fAlreadyHave = false;
619 const char* msgName = "UNKNOWN";
620 if (inv.type == MSG_TX) {
621 msgName = "MSG_TX";
622 if (mempool.Exists(inv.hash)) {
623 LogPrint(BCLog::NET, "recv inv old data! time_ms=%lld, i=%d, msg=%s, hash=%s, peer=%s\n",
624 GetTimeMillis(), i, msgName, inv.ToString(), pFrom->addrName);
625 fAlreadyHave = true;
626 }
627 if(chainActive.Tip()->GetBlockTime() < GetTime() - 24 * 60 * 60){
628 LogPrint(BCLog::NET, "recv tx inv data when initialBlockDownload,reject it! time_ms=%lld, i=%d, msg=%s, hash=%s, peer=%s\n",
629 GetTimeMillis(), i, msgName, inv.ToString(), pFrom->addrName);
630 fAlreadyHave = true;
631 }
632 } else if (inv.type == MSG_BLOCK) {
633 msgName = "MSG_BLOCK";
634 auto blockIndexIt = mapBlockIndex.find(inv.hash);
635 if (blockIndexIt != mapBlockIndex.end()) {
636 LogPrint(BCLog::NET, "recv inv old data! time_ms=%lld, i=%d, msg=%s, hash=%s, peer=%s, found_in=%s, height=%d\n",
637 GetTimeMillis(), i, msgName, inv.ToString(), pFrom->addrName, "BlockIndex", blockIndexIt->second->height);
638 fAlreadyHave = true;
639 } else {
640 auto orphanBlockIt = mapOrphanBlocks.find(inv.hash);
641 if (orphanBlockIt != mapOrphanBlocks.end()) {
642 LogPrint(BCLog::NET, "recv inv old data! time_ms=%lld, i=%d, msg=%s, hash=%s, peer=%s, found_in=%s, height=%d\n",
643 GetTimeMillis(), i, msgName, inv.ToString(), pFrom->addrName, "OrphanBlock", orphanBlockIt->second->height);
644 fAlreadyHave = true;
645
646 LogPrint(BCLog::NET, "recv orphan block and lead to getblocks! height=%d, hash=%s, "
647 "tip_height=%d, tip_hash=%s, peer=%s\n",
648 orphanBlockIt->second->height, inv.hash.GetHex(), chainActive.Height(),
649 chainActive.Tip()->GetBlockHash().GetHex(), pFrom->addrName);
650 PushGetBlocksOnCondition(pFrom, chainActive.Tip(), GetOrphanRoot(inv.hash));
651 // TODO: should get the headmost block of this fork from current peer
652 }
653 }
654 }
655
656 if (!fAlreadyHave) {
657 LogPrint(BCLog::NET, "recv msg=%s inv=%s, ts=%lld, i=%d, peer=%s\n", msgName, inv.ToString(),
658 GetTimeMillis(), i, pFrom->addrName);
659
660 if (!SysCfg().IsImporting() && !SysCfg().IsReindex()) {

Callers 1

ProcessMessageFunction · 0.85

Calls 15

MisbehavingFunction · 0.85
GetTimeFunction · 0.85
PushGetBlocksOnConditionFunction · 0.85
GetOrphanRootFunction · 0.85
AddBlockToQueueFunction · 0.85
SendBufferSizeFunction · 0.85
GetIdMethod · 0.80
AddInventoryKnownMethod · 0.80
TipMethod · 0.80
HeightMethod · 0.80
IsImportingMethod · 0.80
IsReindexMethod · 0.80

Tested by

no test coverage detected