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

Function AddBlockToQueue

src/p2p/chainmessage.cpp:199–239  ·  view source on GitHub ↗

Requires cs_main.

Source from the content-addressed store, hash-verified

197
198// Requires cs_main.
199bool 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
241int32_t ProcessVersionMessage(CNode *pFrom, string strCommand, CDataStream &vRecv) {
242 // Each connection can only send one version message

Callers 1

ProcessInvMessageFunction · 0.85

Calls 11

MarkBlockAsReceivedFunction · 0.85
MisbehavingFunction · 0.85
GetBoolArgMethod · 0.80
StateFunction · 0.70
GetTimeMicrosFunction · 0.50
GetTimeMillisFunction · 0.50
countMethod · 0.45
GetHexMethod · 0.45
ToStringMethod · 0.45
insertMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected