Requires cs_main.
| 197 | |
| 198 | // Requires cs_main. |
| 199 | bool AddBlockToQueue(const uint256 &hash, NodeId nodeId) { |
| 200 | int64_t now = GetTimeMicros(); |
| 201 | bool isMiner = SysCfg().GetBoolArg("-genblock", false); |
| 202 | |
| 203 | int64_t blocksToDownloadTimeout = isMiner ? MINER_NODE_BLOCKS_TO_DOWNLOAD_TIMEOUT : WITNESS_NODE_BLOCKS_TO_DOWNLOAD_TIMEOUT; |
| 204 | int64_t blockInFlightTimeout = isMiner ? MINER_NODE_BLOCKS_IN_FLIGHT_TIMEOUT : WITNESS_NODE_BLOCKS_IN_FLIGHT_TIMEOUT; |
| 205 | |
| 206 | if ((mapBlocksToDownload.count(hash) && |
| 207 | (now - std::get<2>(mapBlocksToDownload[hash]) < blocksToDownloadTimeout * 1000000)) || |
| 208 | (mapBlocksInFlight.count(hash) && |
| 209 | (now - std::get<2>(mapBlocksInFlight[hash]) < blockInFlightTimeout * 1000000))) { |
| 210 | LogPrint(BCLog::NET, "block (%s) being downloaded from another peer, ignore! ts=%lld\n", hash.GetHex(), GetTimeMillis()); |
| 211 | |
| 212 | return false; |
| 213 | } |
| 214 | |
| 215 | LOCK(cs_mapNodeState); |
| 216 | CNodeState *state = State(nodeId); |
| 217 | if (state == nullptr) { |
| 218 | LogPrint(BCLog::NET, "peer (%d) not found! ts=%lld, block(%s) \n", |
| 219 | nodeId, GetTimeMillis(), hash.ToString()); |
| 220 | return false; |
| 221 | } |
| 222 | |
| 223 | // Make sure it's not listed somewhere already. |
| 224 | MarkBlockAsReceived(hash); |
| 225 | |
| 226 | list<uint256>::iterator it = state->vBlocksToDownload.insert(state->vBlocksToDownload.end(), hash); |
| 227 | state->nBlocksToDownload++; |
| 228 | if (state->nBlocksToDownload > 5000) { |
| 229 | LogPrint(BCLog::INFO, "Misbehaving: AddBlockToQueue download too many times, nMisbehavior add 10\n"); |
| 230 | Misbehaving(nodeId, 10); |
| 231 | } |
| 232 | |
| 233 | LogPrint(BCLog::NET, "start downloading block(%s)! time_ms=%lld, peer=%s\n", hash.ToString(), |
| 234 | GetTimeMillis(), state->name); |
| 235 | |
| 236 | mapBlocksToDownload[hash] = std::make_tuple(nodeId, it, GetTimeMicros()); |
| 237 | |
| 238 | return true; |
| 239 | } |
| 240 | |
| 241 | int32_t ProcessVersionMessage(CNode *pFrom, string strCommand, CDataStream &vRecv) { |
| 242 | // Each connection can only send one version message |
no test coverage detected