| 2072 | } |
| 2073 | |
| 2074 | void 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 | |
| 2106 | bool ProcessBlock(CValidationState &state, CNode *pFrom, CBlock *pBlock, CDiskBlockPos *dbp) { |
| 2107 | int64_t llBeginTime = GetTimeMillis(); |
no test coverage detected