static void RollingBloom(benchmark::State &state) { CRollingBloomFilter filter(120000, 0.000001); std::vector<uint8_t> data(32); uint32_t count = 0; uint32_t nEntriesPerGeneration = (120000 + 1) / 2; uint32_t countnow = 0; uint64_t match = 0; while (state.KeepRunning()) { count++; data[0] = count; data[1] = count >> 8; data[2] = count >> 16; data[3] = count >> 24; if (countnow == nEntriesPerGeneration) { int64_t b = GetTimeMicros(); filter.insert(data); int64_t e = GetTimeMicros(); std::cout << "RollingBloom-refresh,1," << (e - b) * 0.000001 << "," << (e - b) * 0.000001 << "," << (e - b) * 0.000001 << "\n"; countnow = 0; } else { filter.insert(data); } countnow++; data[0] = count >> 24; data[1] = count >> 16; data[2] = count >> 8; data[3] = count; match += filter.contains(data); } }
void CBlockPolicyEstimator::FlushUnconfirmed(CTxMemPool& pool) { int64_t startclear = GetTimeMicros(); std::vector<uint256> txids; pool.queryHashes(txids); LOCK(cs_feeEstimator); for (auto& txid : txids) { removeTx(txid, false); } int64_t endclear = GetTimeMicros(); LogPrint(BCLog::ESTIMATEFEE, "Recorded %u unconfirmed txs from mempool in %gs\n",txids.size(), (endclear - startclear)*0.000001); }
void CBlockPolicyEstimator::FlushUnconfirmed() { int64_t startclear = GetTimeMicros(); LOCK(cs_feeEstimator); size_t num_entries = mapMemPoolTxs.size(); // Remove every entry in mapMemPoolTxs while (!mapMemPoolTxs.empty()) { auto mi = mapMemPoolTxs.begin(); removeTx(mi->first, false); // this calls erase() on mapMemPoolTxs } int64_t endclear = GetTimeMicros(); LogPrint(BCLog::ESTIMATEFEE, "Recorded %u unconfirmed txs from mempool in %gs\n", num_entries, (endclear - startclear)*0.000001); }
void CMempoolComponent::DumpMempool(void) { int64_t start = GetTimeMicros(); std::map<uint256, CAmount> mapDeltas; std::vector<TxMempoolInfo> vinfo; { LOCK(cs); for (const auto &i : mempool.mapDeltas) { mapDeltas[i.first] = i.second; } vinfo = mempool.infoAll(); } int64_t mid = GetTimeMicros(); try { FILE *filestr = fsbridge::fopen(Args().GetDataDir() / "mempool.dat.new", "wb"); if (!filestr) { return; } CAutoFile file(filestr, SER_DISK, CLIENT_VERSION); uint64_t version = MEMPOOL_DUMP_VERSION; file << version; file << (uint64_t)vinfo.size(); for (const auto &i : vinfo) { file << *(i.tx); file << (int64_t)i.nTime; file << (int64_t)i.nFeeDelta; mapDeltas.erase(i.tx->GetHash()); } file << mapDeltas; FileCommit(file.Get()); file.fclose(); RenameOver(Args().GetDataDir() / "mempool.dat.new", Args().GetDataDir() / "mempool.dat"); int64_t last = GetTimeMicros(); NLogFormat("Dumped mempool: %gs to copy, %gs to dump", (mid - start) * 0.000001, (last - mid) * 0.000001); } catch (const std::exception &e) { ELogFormat("Failed to dump mempool: %s. Continuing anyway", e.what()); } }
/** * fStartedNewLine is a state variable held by the calling context that will * suppress printing of the timestamp when multiple calls are made that don't * end in a newline. Initialize it to true, and hold it, in the calling context. */ static std::string LogTimestampStr(const std::string &str, std::atomic_bool *fStartedNewLine) { std::string strStamped; if (!fLogTimestamps) return str; if (*fStartedNewLine) { int64_t nTimeMicros = GetTimeMicros(); strStamped = FormatISO8601DateTime(nTimeMicros/1000000); if (fLogTimeMicros) { strStamped.pop_back(); strStamped += strprintf(".%06dZ", nTimeMicros%1000000); } int64_t mocktime = GetMockTime(); if (mocktime) { strStamped += " (mocktime: " + FormatISO8601DateTime(mocktime) + ")"; } strStamped += ' ' + str; } else strStamped = str; if (!str.empty() && str[str.size()-1] == '\n') *fStartedNewLine = true; else *fStartedNewLine = false; return strStamped; }
/** * fStartedNewLine is a state variable held by the calling context that will * suppress printing of the timestamp when multiple calls are made that don't * end in a newline. Initialize it to true, and hold it, in the calling context. */ static std::string LogTimestampStr(const std::string &str, std::atomic_bool *fStartedNewLine) { std::string strStamped; if (!fLogTimestamps) return str; if (*fStartedNewLine) { int64_t nTimeMicros = GetTimeMicros(); strStamped = DateTimeStrFormat("%Y-%m-%d %H:%M:%S", nTimeMicros/1000000); if (fLogTimeMicros) strStamped += strprintf(".%06d", nTimeMicros%1000000); int64_t mocktime = GetMockTime(); if (mocktime) { strStamped += " (mocktime: " + DateTimeStrFormat("%Y-%m-%d %H:%M:%S", mocktime) + ")"; } strStamped += ' ' + str; } else strStamped = str; if (!str.empty() && str[str.size()-1] == '\n') *fStartedNewLine = true; else *fStartedNewLine = false; return strStamped; }
void DepositHandler::HandlePostEncodedRequest( uint160 request_hash, uint160 post_encoding_credit_hash) { log_ << "HandlePostEncodedRequest: " << request_hash << "\n"; DepositAddressPartMessage part_msg; std::vector<uint160> part_hashes = depositdata[request_hash]["parts"]; foreach_(uint160 part_msg_hash, part_hashes) { part_msg = msgdata[part_msg_hash]["deposit_part"]; Point relay = part_msg.VerificationKey(); log_ << "part " << part_msg_hash << " was sent by " << relay << "\n"; if (keydata[relay].HasProperty("privkey")) { log_ << "have key for " << relay << "; sending disclosure\n"; DepositAddressPartDisclosure disclosure( post_encoding_credit_hash, part_msg_hash); BroadcastMessage(disclosure); log_ << "sent disclosure\n"; } flexnode.scheduler.Schedule("disclosure_timeout_check", part_msg_hash, GetTimeMicros() + COMPLAINT_WAIT_TIME); }
std::string BCLog::Logger::LogTimestampStr(const std::string &str) { std::string strStamped; if (!m_log_timestamps) return str; if (m_started_new_line) { int64_t nTimeMicros = GetTimeMicros(); strStamped = FormatISO8601DateTime(nTimeMicros/1000000); if (m_log_time_micros) { strStamped.pop_back(); strStamped += strprintf(".%06dZ", nTimeMicros%1000000); } int64_t mocktime = GetMockTime(); if (mocktime) { strStamped += " (mocktime: " + FormatISO8601DateTime(mocktime) + ")"; } strStamped += ' ' + str; } else strStamped = str; if (!str.empty() && str[str.size()-1] == '\n') m_started_new_line = true; else m_started_new_line = false; return strStamped; }
void OutgoingResourceLimiter::DoForwarding() { CLocationIterator<> message_scanner; int64_t time_elapsed, time_to_sleep, started_handling; uint160 hash; Priority priority; while (running) { message_scanner = msgdata.LocationIterator("forwarding"); message_scanner.SeekEnd(); while (message_scanner.GetPreviousObjectAndLocation(hash, priority)) { started_handling = GetTimeMicros(); string_t type = msgdata[hash]["type"]; log_ << "DoForwarding(): found " << hash << " with type " << type << "\n"; if (!msgdata[hash]["forwarded"]) { ForwardMessage(type, hash); msgdata[hash]["forwarded"] = true; } msgdata.RemoveFromLocation("forwarding", priority); message_scanner = msgdata.LocationIterator("forwarding"); message_scanner.SeekEnd(); time_elapsed = GetTimeMicros() - started_handling; time_to_sleep = (1000000 / MAX_MESSAGE_RATE) - time_elapsed; if (time_to_sleep > 0) SleepMilliseconds(time_to_sleep / 1000); } SleepMilliseconds(100); if (fRequestShutdown) running = false; } }
int64_t GetSystemTimeInSeconds() { return GetTimeMicros()/1000000; }
std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn, bool fMineWitnessTx) { int64_t nTimeStart = GetTimeMicros(); resetBlock(); pblocktemplate.reset(new CBlockTemplate()); if(!pblocktemplate.get()) return nullptr; pblock = &pblocktemplate->block; // pointer for convenience // Add dummy coinbase tx as first transaction pblock->vtx.emplace_back(); pblocktemplate->vTxFees.push_back(-1); // updated at end pblocktemplate->vTxSigOpsCost.push_back(-1); // updated at end LOCK2(cs_main, mempool.cs); CBlockIndex* pindexPrev = chainActive.Tip(); assert(pindexPrev != nullptr); nHeight = pindexPrev->nHeight + 1; pblock->nVersion = ComputeBlockVersion(pindexPrev, chainparams.GetConsensus()); // -regtest only: allow overriding block.nVersion with // -blockversion=N to test forking scenarios if (chainparams.MineBlocksOnDemand()) pblock->nVersion = gArgs.GetArg("-blockversion", pblock->nVersion); pblock->nTime = GetAdjustedTime(); const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast(); nLockTimeCutoff = (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST) ? nMedianTimePast : pblock->GetBlockTime(); // Decide whether to include witness transactions // This is only needed in case the witness softfork activation is reverted // (which would require a very deep reorganization) or when // -promiscuousmempoolflags is used. // TODO: replace this with a call to main to assess validity of a mempool // transaction (which in most cases can be a no-op). fIncludeWitness = IsWitnessEnabled(pindexPrev, chainparams.GetConsensus()) && fMineWitnessTx; int nPackagesSelected = 0; int nDescendantsUpdated = 0; addPackageTxs(nPackagesSelected, nDescendantsUpdated); int64_t nTime1 = GetTimeMicros(); nLastBlockTx = nBlockTx; nLastBlockWeight = nBlockWeight; // Create coinbase transaction. CMutableTransaction coinbaseTx; coinbaseTx.vin.resize(1); coinbaseTx.vin[0].prevout.SetNull(); coinbaseTx.vout.resize(1); coinbaseTx.vout[0].scriptPubKey = scriptPubKeyIn; coinbaseTx.vout[0].nValue = nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus()); coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0; pblock->vtx[0] = MakeTransactionRef(std::move(coinbaseTx)); pblocktemplate->vchCoinbaseCommitment = GenerateCoinbaseCommitment(*pblock, pindexPrev, chainparams.GetConsensus()); pblocktemplate->vTxFees[0] = -nFees; LogPrintf("CreateNewBlock(): block weight: %u txs: %u fees: %ld sigops %d\n", GetBlockWeight(*pblock), nBlockTx, nFees, nBlockSigOpsCost); // Fill in header pblock->hashPrevBlock = pindexPrev->GetBlockHash(); UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, chainparams.GetConsensus()); pblock->nNonce = 0; pblocktemplate->vTxSigOpsCost[0] = WITNESS_SCALE_FACTOR * GetLegacySigOpCount(*pblock->vtx[0]); CValidationState state; if (!TestBlockValidity(state, chainparams, *pblock, pindexPrev, false, false)) { throw std::runtime_error(strprintf("%s: TestBlockValidity failed: %s", __func__, FormatStateMessage(state))); } int64_t nTime2 = GetTimeMicros(); LogPrint(BCLog::BENCH, "CreateNewBlock() packages: %.2fms (%d packages, %d updated descendants), validity: %.2fms (total %.2fms)\n", 0.001 * (nTime1 - nTimeStart), nPackagesSelected, nDescendantsUpdated, 0.001 * (nTime2 - nTime1), 0.001 * (nTime2 - nTimeStart)); return std::move(pblocktemplate); }
/** Return a time useful for the debug log */ int64_t GetLogTimeMicros() { if (nMockTime) return nMockTime*1000000; return GetTimeMicros(); }
void ScheduleCancellation(uint160 complaint_hash) { flexnode.scheduler.Schedule("cancellation", complaint_hash, GetTimeMicros() + COMPLAINT_WAIT_TIME); }
void ScheduleSendBackupSecrets(uint160 accept_commit_hash, uint8_t direction) { flexnode.scheduler.Schedule("send_backup_secrets", accept_commit_hash, GetTimeMicros() + SEND_BACKUP_SECRETS_AFTER); }