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

Function PushGetBlocksOnCondition

src/main.cpp:2074–2104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2072}
2073
2074void PushGetBlocksOnCondition(CNode *pNode, CBlockIndex *pIndexBegin, uint256 hashEnd) {
2075 // Ask this guy to fill in what we're missing
2076 AssertLockHeld(cs_main);
2077 // Filter out duplicate requests
2078 if (pIndexBegin == pNode->pIndexLastGetBlocksBegin && hashEnd == pNode->hashLastGetBlocksEnd) {
2079 LogPrint(BCLog::NET, "filter the same GetLocator from peer %s\n", pNode->addr.ToString());
2080 static CBloomFilter filter(5000, 0.0001, 0, BLOOM_UPDATE_NONE);
2081 static uint32_t count = 0;
2082 string key = to_string(pNode->id) + ":" + to_string((GetTime() / 2));
2083 if (!filter.contains(vector<uint8_t>(key.begin(), key.end()))) {
2084 filter.insert(vector<uint8_t>(key.begin(), key.end()));
2085 ++count;
2086 pNode->pIndexLastGetBlocksBegin = pIndexBegin;
2087 pNode->hashLastGetBlocksEnd = hashEnd;
2088 CBlockLocator blockLocator = chainActive.GetLocator(pIndexBegin);
2089 pNode->PushMessage(NetMsgType::GETBLOCKS, blockLocator, hashEnd);
2090 LogPrint(BCLog::NET, "getblocks from peer %s, hashEnd:%s\n", pNode->addr.ToString(), hashEnd.GetHex());
2091 } else {
2092 if (count >= 5000) {
2093 count = 0;
2094 filter.Clear();
2095 }
2096 }
2097 } else {
2098 pNode->pIndexLastGetBlocksBegin = pIndexBegin;
2099 pNode->hashLastGetBlocksEnd = hashEnd;
2100 CBlockLocator blockLocator = chainActive.GetLocator(pIndexBegin);
2101 pNode->PushMessage(NetMsgType::GETBLOCKS, blockLocator, hashEnd);
2102 LogPrint(BCLog::NET, "getblocks from peer %s, hashEnd:%s\n", pNode->addr.ToString(), hashEnd.GetHex());
2103 }
2104}
2105
2106bool ProcessBlock(CValidationState &state, CNode *pFrom, CBlock *pBlock, CDiskBlockPos *dbp) {
2107 int64_t llBeginTime = GetTimeMillis();

Callers 2

ProcessBlockFunction · 0.85
ProcessInvMessageFunction · 0.85

Calls 10

GetTimeFunction · 0.85
containsMethod · 0.80
GetLocatorMethod · 0.80
PushMessageMethod · 0.80
ToStringMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
insertMethod · 0.45
GetHexMethod · 0.45
ClearMethod · 0.45

Tested by

no test coverage detected