diff --git a/.github/workflows/build-src.yml b/.github/workflows/build-src.yml index 9af8b19b2e00b..6f9d3279b845b 100644 --- a/.github/workflows/build-src.yml +++ b/.github/workflows/build-src.yml @@ -76,7 +76,7 @@ jobs: - name: Build source run: | - CCACHE_SIZE="400M" + CCACHE_MAXSIZE="400M" CACHE_DIR="/cache" mkdir /output BASE_OUTDIR="/output" diff --git a/ci/dash/build_src.sh b/ci/dash/build_src.sh index 3ebdc910dea2d..ad1201e4599d7 100755 --- a/ci/dash/build_src.sh +++ b/ci/dash/build_src.sh @@ -27,7 +27,7 @@ if [ "$CHECK_DOC" = 1 ]; then test/lint/all-lint.py fi -ccache --zero-stats --max-size="$CCACHE_SIZE" +ccache --zero-stats if [ -n "$CONFIG_SHELL" ]; then export CONFIG_SHELL="$CONFIG_SHELL" diff --git a/ci/lint/04_install.sh b/ci/lint/04_install.sh index bcd636641f7f0..431672ba1fb3f 100755 --- a/ci/lint/04_install.sh +++ b/ci/lint/04_install.sh @@ -35,6 +35,7 @@ fi ${CI_RETRY_EXE} pip3 install codespell==2.0.0 ${CI_RETRY_EXE} pip3 install flake8==3.8.3 +${CI_RETRY_EXE} pip3 install lief==0.13.1 ${CI_RETRY_EXE} pip3 install mypy==0.910 ${CI_RETRY_EXE} pip3 install pyzmq==22.3.0 ${CI_RETRY_EXE} pip3 install vulture==2.3 diff --git a/ci/test/00_setup_env.sh b/ci/test/00_setup_env.sh index d4840e9ebfd8e..9ff3c333754ea 100755 --- a/ci/test/00_setup_env.sh +++ b/ci/test/00_setup_env.sh @@ -55,7 +55,7 @@ export BOOST_TEST_RANDOM=${BOOST_TEST_RANDOM:-1} export DEBIAN_FRONTEND=noninteractive export HOST_CACHE_DIR=${HOST_CACHE_DIR:-$BASE_ROOT_DIR/ci-cache-$BUILD_TARGET} export CACHE_DIR=${CACHE_DIR:-$HOST_CACHE_DIR} -export CCACHE_SIZE=${CCACHE_SIZE:-100M} +export CCACHE_MAXSIZE=${CCACHE_MAXSIZE:-100M} export CCACHE_TEMPDIR=${CCACHE_TEMPDIR:-/tmp/.ccache-temp} export CCACHE_COMPRESS=${CCACHE_COMPRESS:-1} # The cache dir. diff --git a/ci/test/00_setup_env_mac_native_x86_64.sh b/ci/test/00_setup_env_mac_native_x86_64.sh index 0ac2d62eb6c5f..252b95c2178fd 100755 --- a/ci/test/00_setup_env_mac_native_x86_64.sh +++ b/ci/test/00_setup_env_mac_native_x86_64.sh @@ -14,6 +14,6 @@ export BITCOIN_CONFIG="--with-gui --enable-reduce-exports --disable-miner --with export CI_OS_NAME="macos" export NO_DEPENDS=1 export OSX_SDK="" -export CCACHE_SIZE=300M +export CCACHE_MAXSIZE=300M export RUN_SECURITY_TESTS="true" diff --git a/ci/test/00_setup_env_native_fuzz_with_valgrind.sh b/ci/test/00_setup_env_native_fuzz_with_valgrind.sh index 1b5728feb84cc..f379d8ee7edcd 100755 --- a/ci/test/00_setup_env_native_fuzz_with_valgrind.sh +++ b/ci/test/00_setup_env_native_fuzz_with_valgrind.sh @@ -7,7 +7,7 @@ export LC_ALL=C.UTF-8 export CONTAINER_NAME=ci_native_fuzz_valgrind -export PACKAGES="clang llvm python3 libevent-dev bsdmainutils libboost-dev valgrind" +export PACKAGES="clang llvm libclang-rt-dev python3 libevent-dev bsdmainutils libboost-dev valgrind" export NO_DEPENDS=1 export RUN_UNIT_TESTS=false export RUN_FUNCTIONAL_TESTS=false @@ -16,4 +16,4 @@ export FUZZ_TESTS_CONFIG="--valgrind" export GOAL="install" # Temporarily pin dwarf 4, until valgrind can understand clang's dwarf 5 export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer CC=clang-18 CXX=clang++-18 CFLAGS='-gdwarf-4' CXXFLAGS='-gdwarf-4'" -export CCACHE_SIZE=200M +export CCACHE_MAXSIZE=200M diff --git a/ci/test/00_setup_env_native_valgrind.sh b/ci/test/00_setup_env_native_valgrind.sh index d0a217a1f659e..d7bf8b2f35501 100755 --- a/ci/test/00_setup_env_native_valgrind.sh +++ b/ci/test/00_setup_env_native_valgrind.sh @@ -6,7 +6,7 @@ export LC_ALL=C.UTF-8 -export PACKAGES="valgrind clang llvm python3-zmq libevent-dev bsdmainutils libboost-dev libdb5.3++-dev libminiupnpc-dev libzmq3-dev" +export PACKAGES="valgrind clang llvm libclang-rt-dev python3-zmq libevent-dev bsdmainutils libboost-dev libdb5.3++-dev libminiupnpc-dev libzmq3-dev" export USE_VALGRIND=1 export NO_DEPENDS=1 export TEST_RUNNER_EXTRA="--exclude rpc_bind,feature_bind_extra --timeout-factor=4" # Excluded for now, see https://github.com/bitcoin/bitcoin/issues/17765#issuecomment-602068547 diff --git a/ci/test/04_install.sh b/ci/test/04_install.sh index 3ea6d24e6b86d..993708686c916 100755 --- a/ci/test/04_install.sh +++ b/ci/test/04_install.sh @@ -97,7 +97,7 @@ if [ "$CI_OS_NAME" == "macos" ]; then echo "Number of CPUs: $(sysctl -n hw.logicalcpu)" else CI_EXEC free -m -h - CI_EXEC echo "Number of CPUs \(nproc\):" \$\(nproc\) + CI_EXEC echo "Number of CPUs (nproc): $(nproc)" CI_EXEC echo "$(lscpu | grep Endian)" fi CI_EXEC echo "Free disk space:" diff --git a/contrib/dash-cli.bash-completion b/contrib/dash-cli.bash similarity index 100% rename from contrib/dash-cli.bash-completion rename to contrib/dash-cli.bash diff --git a/contrib/dash-tx.bash-completion b/contrib/dash-tx.bash similarity index 100% rename from contrib/dash-tx.bash-completion rename to contrib/dash-tx.bash diff --git a/contrib/dashd.bash-completion b/contrib/dashd.bash similarity index 100% rename from contrib/dashd.bash-completion rename to contrib/dashd.bash diff --git a/contrib/devtools/security-check.py b/contrib/devtools/security-check.py index 2cbb861d57c35..001e46ceeef77 100755 --- a/contrib/devtools/security-check.py +++ b/contrib/devtools/security-check.py @@ -10,7 +10,7 @@ import sys from typing import List -import lief #type:ignore +import lief def check_ELF_RELRO(binary) -> bool: ''' diff --git a/contrib/devtools/symbol-check.py b/contrib/devtools/symbol-check.py index d6bdb193eb643..a89cd32e83d29 100755 --- a/contrib/devtools/symbol-check.py +++ b/contrib/devtools/symbol-check.py @@ -13,7 +13,7 @@ import sys from typing import Dict, List -import lief #type:ignore +import lief # Debian 11 (Bullseye) EOL: 2026. https://wiki.debian.org/LTS # diff --git a/contrib/devtools/test-security-check.py b/contrib/devtools/test-security-check.py index 5d9dc169045a8..035a6e696877f 100755 --- a/contrib/devtools/test-security-check.py +++ b/contrib/devtools/test-security-check.py @@ -5,7 +5,7 @@ ''' Test script for security-check.py ''' -import lief #type:ignore +import lief import os import subprocess from typing import List diff --git a/src/Makefile.am b/src/Makefile.am index 1b26de7005fcb..55c8f03ae4750 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -434,7 +434,7 @@ BITCOIN_CORE_H = \ obj/build.h: FORCE @$(MKDIR_P) $(builddir)/obj - @$(top_srcdir)/share/genbuild.sh "$(abs_top_builddir)/src/obj/build.h" \ + $(AM_V_GEN) $(top_srcdir)/share/genbuild.sh "$(abs_top_builddir)/src/obj/build.h" \ "$(abs_top_srcdir)" libbitcoin_util_a-clientversion.$(OBJEXT): obj/build.h @@ -1071,7 +1071,7 @@ clean-local: -rm -rf *.dSYM test/*.dSYM bench/*.dSYM qt/*.dSYM qt/test/*.dSYM .rc.o: - @test -f $(WINDRES) + @test -f $(WINDRES) || (echo "windres $(WINDRES) not found, but is required to compile windows resource files"; exit 1) ## FIXME: How to get the appropriate modulename_CPPFLAGS in here? $(AM_V_GEN) $(WINDRES) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(CPPFLAGS) -DWINDRES_PREPROC -i $< -o $@ @@ -1130,12 +1130,11 @@ endif %.raw.h: %.raw @$(MKDIR_P) $(@D) - @{ \ + $(AM_V_GEN) { \ echo "static unsigned const char $(*F)_raw[] = {" && \ $(HEXDUMP) -v -e '8/1 "0x%02x, "' -e '"\n"' $< | $(SED) -e 's/0x ,//g' && \ echo "};"; \ } > "$@.new" && mv -f "$@.new" "$@" - @echo "Generated $@" include Makefile.minisketch.include diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index c9f918c764676..da0ddfaf708de 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -444,13 +444,13 @@ translate: $(srcdir)/qt/dashstrings.cpp $(QT_FORMS_UI) $(QT_FORMS_UI) $(BITCOIN_ $(AM_V_GEN) QT_SELECT=$(QT_SELECT) $(LCONVERT) -o $(srcdir)/qt/locale/dash_en.xlf -i $(srcdir)/qt/locale/dash_en.ts $(QT_QRC_LOCALE_CPP): $(QT_QRC_LOCALE) $(QT_QM) - @test -f $(RCC) + @test -f $(RCC) || (echo "rcc $(RCC) not found, but is required for generating qrc cpp files"; exit 1) @cp -f $< $(@D)/temp_$( $@ @rm $(@D)/temp_$( $@ CLEAN_QT = $(nodist_qt_libbitcoinqt_a_SOURCES) $(QT_QM) $(QT_FORMS_H) qt/*.gcda qt/*.gcno qt/temp_dash_locale.qrc qt/res/css/colors/* @@ -463,7 +463,7 @@ dash_qt_clean: FORCE dash_qt : qt/dash-qt$(EXEEXT) ui_%.h: %.ui - @test -f $(UIC) + @test -f $(UIC) || (echo "uic $(UIC) not found, but is required for generating ui headers"; exit 1) @$(MKDIR_P) $(@D) $(AM_V_GEN) QT_SELECT=$(QT_SELECT) $(UIC) -o $@ $< || (echo "Error creating $@"; false) @@ -474,6 +474,6 @@ moc_%.cpp: %.h $(AM_V_GEN) QT_SELECT=$(QT_SELECT) $(MOC) $(DEFAULT_INCLUDES) $(QT_INCLUDES_UNSUPPRESSED) $(MOC_DEFS) $< > $@ %.qm: %.ts - @test -f $(LRELEASE) + @test -f $(LRELEASE) || (echo "lrelease $(LRELEASE) not found, but is required for generating translations"; exit 1) @$(MKDIR_P) $(@D) $(AM_V_GEN) QT_SELECT=$(QT_SELECT) $(LRELEASE) -silent $< -qm $@ diff --git a/src/Makefile.test.include b/src/Makefile.test.include index 432bf0a0688eb..d60c8aedab1d2 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -448,10 +448,9 @@ endif %.json.h: %.json @$(MKDIR_P) $(@D) - @{ \ + $(AM_V_GEN) { \ echo "namespace json_tests{" && \ echo "static unsigned const char $(*F)[] = {" && \ $(HEXDUMP) -v -e '8/1 "0x%02x, "' -e '"\n"' $< | $(SED) -e 's/0x ,//g' && \ echo "};};"; \ } > "$@.new" && mv -f "$@.new" "$@" - @echo "Generated $@" diff --git a/src/bench/util_time.cpp b/src/bench/util_time.cpp index afc733482e8ac..c45584988d9ab 100644 --- a/src/bench/util_time.cpp +++ b/src/bench/util_time.cpp @@ -32,7 +32,7 @@ static void BenchTimeMillis(benchmark::Bench& bench) static void BenchTimeMillisSys(benchmark::Bench& bench) { bench.run([&] { - (void)GetTimeMillis(); + (void)TicksSinceEpoch(SystemClock::now()); }); } diff --git a/src/instantsend/instantsend.cpp b/src/instantsend/instantsend.cpp index b46b6ceee3d40..c7a5b317b40ad 100644 --- a/src/instantsend/instantsend.cpp +++ b/src/instantsend/instantsend.cpp @@ -156,7 +156,7 @@ PeerMsgRet CInstantSendManager::ProcessMessageInstantSendLock(const CNode& pfrom LOCK(cs_timingsTxSeen); if (auto it = timingsTxSeen.find(islock->txid); it != timingsTxSeen.end()) { // This is the normal case where we received the TX before the islock - auto diff = GetTimeMillis() - it->second; + auto diff = TicksSinceEpoch(SystemClock::now()) - it->second; timingsTxSeen.erase(it); return diff; } @@ -549,7 +549,7 @@ void CInstantSendManager::AddNonLockedTx(const CTransactionRef& tx, const CBlock if (ShouldReportISLockTiming()) { LOCK(cs_timingsTxSeen); // Only insert the time the first time we see the tx, as we sometimes try to resign - timingsTxSeen.try_emplace(tx->GetHash(), GetTimeMillis()); + timingsTxSeen.try_emplace(tx->GetHash(), TicksSinceEpoch(SystemClock::now())); } LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- txid=%s, pindexMined=%s\n", __func__, diff --git a/src/llmq/chainlocks.cpp b/src/llmq/chainlocks.cpp index 8e8917180ae8d..155e1117260a5 100644 --- a/src/llmq/chainlocks.cpp +++ b/src/llmq/chainlocks.cpp @@ -111,7 +111,7 @@ MessageProcessingResult CChainLocksHandler::ProcessNewChainLock(const NodeId fro { LOCK(cs); - if (!seenChainLocks.emplace(hash, GetTimeMillis()).second) { + if (!seenChainLocks.emplace(hash, TicksSinceEpoch(SystemClock::now())).second) { return {}; } @@ -611,15 +611,15 @@ void CChainLocksHandler::Cleanup() return; } - if (GetTimeMillis() - lastCleanupTime < CLEANUP_INTERVAL) { + if (TicksSinceEpoch(SystemClock::now()) - lastCleanupTime < CLEANUP_INTERVAL) { return; } - lastCleanupTime = GetTimeMillis(); + lastCleanupTime = TicksSinceEpoch(SystemClock::now()); { LOCK(cs); for (auto it = seenChainLocks.begin(); it != seenChainLocks.end(); ) { - if (GetTimeMillis() - it->second >= CLEANUP_SEEN_TIMEOUT) { + if (TicksSinceEpoch(SystemClock::now()) - it->second >= CLEANUP_SEEN_TIMEOUT) { it = seenChainLocks.erase(it); } else { ++it; diff --git a/src/llmq/dkgsessionhandler.cpp b/src/llmq/dkgsessionhandler.cpp index beb111533e9e0..7ef53456c8d49 100644 --- a/src/llmq/dkgsessionhandler.cpp +++ b/src/llmq/dkgsessionhandler.cpp @@ -301,13 +301,13 @@ void CDKGSessionHandler::SleepBeforePhase(QuorumPhase curPhase, double adjustedPhaseSleepTimePerMember = phaseSleepTimePerMember * randomSleepFactor; int64_t sleepTime = (int64_t)(adjustedPhaseSleepTimePerMember * curSession->GetMyMemberIndex().value_or(0)); - int64_t endTime = GetTimeMillis() + sleepTime; + int64_t endTime = TicksSinceEpoch(SystemClock::now()) + sleepTime; int heightTmp{currentHeight.load()}; int heightStart{heightTmp}; LogPrint(BCLog::LLMQ_DKG, "CDKGSessionManager::%s -- %s qi[%d] - starting sleep for %d ms, curPhase=%d\n", __func__, params.name, quorumIndex, sleepTime, ToUnderlying(curPhase)); - while (GetTimeMillis() < endTime) { + while (TicksSinceEpoch(SystemClock::now()) < endTime) { if (stopRequested) { LogPrint(BCLog::LLMQ_DKG, "CDKGSessionManager::%s -- %s qi[%d] - aborting due to stop/shutdown requested\n", __func__, params.name, quorumIndex); throw AbortPhaseException(); diff --git a/src/llmq/dkgsessionmgr.cpp b/src/llmq/dkgsessionmgr.cpp index 6386d9487ab46..72270ed4d5032 100644 --- a/src/llmq/dkgsessionmgr.cpp +++ b/src/llmq/dkgsessionmgr.cpp @@ -331,7 +331,7 @@ bool CDKGSessionManager::GetVerifiedContributions(Consensus::LLMQType llmqType, CBLSSecretKey skContribution; db->Read(std::make_tuple(DB_SKCONTRIB, llmqType, pQuorumBaseBlockIndex->GetBlockHash(), proTxHash), skContribution); - it = contributionsCache.emplace(cacheKey, ContributionsCacheEntry{GetTimeMillis(), vvecPtr, skContribution}).first; + it = contributionsCache.emplace(cacheKey, ContributionsCacheEntry{TicksSinceEpoch(SystemClock::now()), vvecPtr, skContribution}).first; } memberIndexesRet.emplace_back(i); @@ -378,7 +378,7 @@ bool CDKGSessionManager::GetEncryptedContributions(Consensus::LLMQType llmqType, void CDKGSessionManager::CleanupCache() const { LOCK(contributionsCacheCs); - auto curTime = GetTimeMillis(); + auto curTime = TicksSinceEpoch(SystemClock::now()); for (auto it = contributionsCache.begin(); it != contributionsCache.end(); ) { if (curTime - it->second.entryTime > MAX_CONTRIBUTION_CACHE_TIME) { it = contributionsCache.erase(it); diff --git a/src/llmq/signing.cpp b/src/llmq/signing.cpp index f543cd3990873..b05375c63d620 100644 --- a/src/llmq/signing.cpp +++ b/src/llmq/signing.cpp @@ -656,7 +656,7 @@ void CSigningManager::TruncateRecoveredSig(Consensus::LLMQType llmqType, const u void CSigningManager::Cleanup() { - int64_t now = GetTimeMillis(); + int64_t now = TicksSinceEpoch(SystemClock::now()); if (now - lastCleanupTime < 5000) { return; } @@ -666,7 +666,7 @@ void CSigningManager::Cleanup() db.CleanupOldRecoveredSigs(maxAge); db.CleanupOldVotes(maxAge); - lastCleanupTime = GetTimeMillis(); + lastCleanupTime = TicksSinceEpoch(SystemClock::now()); } void CSigningManager::RegisterRecoveredSigsListener(CRecoveredSigsListener* l) diff --git a/src/llmq/signing_shares.cpp b/src/llmq/signing_shares.cpp index 35aaddbb7fc67..d0b5d3ed8d227 100644 --- a/src/llmq/signing_shares.cpp +++ b/src/llmq/signing_shares.cpp @@ -1488,9 +1488,9 @@ void CSigSharesManager::WorkThreadMain(CConnman& connman, PeerManager& peerman) bool fMoreWork = ProcessPendingSigShares(peerman, connman); SignPendingSigShares(connman, peerman); - if (GetTimeMillis() - lastSendTime > 100) { + if (TicksSinceEpoch(SystemClock::now()) - lastSendTime > 100) { SendMessages(connman); - lastSendTime = GetTimeMillis(); + lastSendTime = TicksSinceEpoch(SystemClock::now()); } Cleanup(connman); diff --git a/src/masternode/sync.cpp b/src/masternode/sync.cpp index c653778fd401c..fca0f0cde5cf8 100644 --- a/src/masternode/sync.cpp +++ b/src/masternode/sync.cpp @@ -119,7 +119,7 @@ void CMasternodeSync::ProcessTick(const PeerManager& peerman, const CGovernanceM static int nTick = 0; nTick++; - const static int64_t nSyncStart = GetTimeMillis(); + const static int64_t nSyncStart = TicksSinceEpoch(SystemClock::now()); const static std::string strAllow = strprintf("allow-sync-%lld", nSyncStart); // reset the sync process if the last call to this function was more than 60 minutes ago (client was in sleep mode) diff --git a/src/net.cpp b/src/net.cpp index 659841ee5dbde..5c44be1d8307f 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2117,9 +2117,9 @@ void CConnman::DisconnectNodes() // 1. vSendMsg must be empty and all messages sent via send(). This is ensured by SocketHandler() // being called before DisconnectNodes and also by the linger time // 2. Internal socket send buffers must be flushed. This is ensured solely by the linger time - pnode->nDisconnectLingerTime = GetTimeMillis() + 100; + pnode->nDisconnectLingerTime = TicksSinceEpoch(SystemClock::now()) + 100; } - if (GetTimeMillis() < pnode->nDisconnectLingerTime) { + if (TicksSinceEpoch(SystemClock::now()) < pnode->nDisconnectLingerTime) { // everything flushed to the kernel? const auto& [to_send, more, _msg_type] = pnode->m_transport->GetBytesToSend(pnode->nSendMsgSize != 0); const bool queue_is_empty{to_send.empty() && !more}; @@ -2638,11 +2638,11 @@ void CConnman::ThreadSocketHandler(CMasternodeSync& mn_sync) // Handle sockets before we do the next round of disconnects. This allows us to flush send buffers one last time // before actually closing sockets. Receiving is however skipped in case a peer is pending to be disconnected SocketHandler(mn_sync); - if (GetTimeMillis() - nLastCleanupNodes > 1000) { + if (TicksSinceEpoch(SystemClock::now()) - nLastCleanupNodes > 1000) { ForEachNode(AllNodes, [&](CNode* pnode) { if (InactivityCheck(*pnode)) pnode->fDisconnect = true; }); - nLastCleanupNodes = GetTimeMillis(); + nLastCleanupNodes = TicksSinceEpoch(SystemClock::now()); } DisconnectNodes(); NotifyNumConnectionsChanged(mn_sync); @@ -3650,9 +3650,9 @@ void CConnman::ThreadMessageHandler() bool fMoreWork = false; bool fSkipSendMessagesForMasternodes = true; - if (GetTimeMillis() - nLastSendMessagesTimeMasternodes >= 100) { + if (TicksSinceEpoch(SystemClock::now()) - nLastSendMessagesTimeMasternodes >= 100) { fSkipSendMessagesForMasternodes = false; - nLastSendMessagesTimeMasternodes = GetTimeMillis(); + nLastSendMessagesTimeMasternodes = TicksSinceEpoch(SystemClock::now()); } // Randomize the order in which we process messages from/to our peers. diff --git a/src/net.h b/src/net.h index 2dfc9d32b08ac..957aff1b4fd34 100644 --- a/src/net.h +++ b/src/net.h @@ -1935,7 +1935,6 @@ friend class CNode; */ static constexpr size_t MAX_UNUSED_I2P_SESSIONS_SIZE{10}; - friend struct CConnmanTest; friend struct ConnmanTestMsg; }; diff --git a/src/netbase.cpp b/src/netbase.cpp index 850044f00c3da..95d95f3f31ccf 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -320,7 +320,7 @@ enum class IntrRecvError { */ static IntrRecvError InterruptibleRecv(uint8_t* data, size_t len, int timeout, const Sock& sock) { - int64_t curTime = GetTimeMillis(); + int64_t curTime = TicksSinceEpoch(SystemClock::now()); int64_t endTime = curTime + timeout; while (len > 0 && curTime < endTime) { ssize_t ret = sock.Recv(data, len, 0); // Optimistically try the recv first @@ -345,7 +345,7 @@ static IntrRecvError InterruptibleRecv(uint8_t* data, size_t len, int timeout, c } if (interruptSocks5Recv) return IntrRecvError::Interrupted; - curTime = GetTimeMillis(); + curTime = TicksSinceEpoch(SystemClock::now()); } return len == 0 ? IntrRecvError::OK : IntrRecvError::Timeout; } diff --git a/src/outputtype.cpp b/src/outputtype.cpp index c2c69dd9b72d2..440372c0b5ea2 100644 --- a/src/outputtype.cpp +++ b/src/outputtype.cpp @@ -25,9 +25,6 @@ bool ParseOutputType(const std::string& type, OutputType& output_type) if (type == OUTPUT_TYPE_STRING_LEGACY) { output_type = OutputType::LEGACY; return true; - } else if (type == OUTPUT_TYPE_STRING_UNKNOWN) { - output_type = OutputType::UNKNOWN; - return true; } return false; } diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp index 7b20ce368b970..fb6b90e86ce71 100644 --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -263,7 +263,7 @@ void ClientModel::TipChanged(SynchronizationState sync_state, interfaces::BlockT // Throttle GUI notifications about (a) blocks during initial sync, and (b) both blocks and headers during reindex. const bool throttle = (sync_state != SynchronizationState::POST_INIT && !header) || sync_state == SynchronizationState::INIT_REINDEX; - const int64_t now = throttle ? GetTimeMillis() : 0; + const int64_t now = throttle ? TicksSinceEpoch(SystemClock::now()) : 0; int64_t& nLastUpdateNotification = header ? nLastHeaderTipUpdateNotification : nLastBlockTipUpdateNotification; if (throttle && now < nLastUpdateNotification + count_milliseconds(MODEL_UPDATE_DELAY)) { return; diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 95cdfdf6cb114..4973acc7bb7a5 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -542,15 +542,15 @@ static RPCHelpMan getaddednodeinfo() static RPCHelpMan getnettotals() { return RPCHelpMan{"getnettotals", - "\nReturns information about network traffic, including bytes in, bytes out,\n" - "and current time.\n", + "Returns information about network traffic, including bytes in, bytes out,\n" + "and current system time.", {}, RPCResult{ RPCResult::Type::OBJ, "", "", { {RPCResult::Type::NUM, "totalbytesrecv", "Total bytes received"}, {RPCResult::Type::NUM, "totalbytessent", "Total bytes sent"}, - {RPCResult::Type::NUM_TIME, "timemillis", "Current " + UNIX_EPOCH_TIME + " in milliseconds"}, + {RPCResult::Type::NUM_TIME, "timemillis", "Current system " + UNIX_EPOCH_TIME + " in milliseconds"}, {RPCResult::Type::OBJ, "uploadtarget", "", { {RPCResult::Type::NUM, "timeframe", "Length of the measuring timeframe in seconds"}, @@ -574,7 +574,7 @@ static RPCHelpMan getnettotals() UniValue obj(UniValue::VOBJ); obj.pushKV("totalbytesrecv", connman.GetTotalBytesRecv()); obj.pushKV("totalbytessent", connman.GetTotalBytesSent()); - obj.pushKV("timemillis", GetTimeMillis()); + obj.pushKV("timemillis", TicksSinceEpoch(SystemClock::now())); UniValue outboundLimit(UniValue::VOBJ); outboundLimit.pushKV("timeframe", count_seconds(connman.GetMaxOutboundTimeframe())); diff --git a/src/util/time.cpp b/src/util/time.cpp index e04f43ae61513..548b1b015c896 100644 --- a/src/util/time.cpp +++ b/src/util/time.cpp @@ -57,11 +57,6 @@ std::chrono::seconds GetMockTime() return g_mock_time.load(std::memory_order_relaxed); } -int64_t GetTimeMillis() -{ - return int64_t{GetSystemTime().count()}; -} - int64_t GetTimeMicros() { return int64_t{GetSystemTime().count()}; diff --git a/src/util/time.h b/src/util/time.h index d1fca85e85a6b..8da7c650bbc70 100644 --- a/src/util/time.h +++ b/src/util/time.h @@ -29,6 +29,8 @@ using SteadySeconds = std::chrono::time_point; using SteadyMicroseconds = std::chrono::time_point; +using SystemClock = std::chrono::system_clock; + void UninterruptibleSleep(const std::chrono::microseconds& n); /** @@ -68,11 +70,8 @@ using SecondsDouble = std::chrono::duration(SystemClock::now()); crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod); - pMasterKey.second.nDeriveIterations = static_cast(pMasterKey.second.nDeriveIterations * (100 / ((double)(GetTimeMillis() - nStartTime)))); + pMasterKey.second.nDeriveIterations = static_cast(pMasterKey.second.nDeriveIterations * (100 / ((double)(TicksSinceEpoch(SystemClock::now()) - nStartTime)))); - nStartTime = GetTimeMillis(); + nStartTime = TicksSinceEpoch(SystemClock::now()); crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod); - pMasterKey.second.nDeriveIterations = (pMasterKey.second.nDeriveIterations + static_cast(pMasterKey.second.nDeriveIterations * 100 / ((double)(GetTimeMillis() - nStartTime)))) / 2; + pMasterKey.second.nDeriveIterations = (pMasterKey.second.nDeriveIterations + static_cast(pMasterKey.second.nDeriveIterations * 100 / ((double)(TicksSinceEpoch(SystemClock::now()) - nStartTime)))) / 2; if (pMasterKey.second.nDeriveIterations < 25000) pMasterKey.second.nDeriveIterations = 25000; @@ -694,13 +694,13 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) GetStrongRandBytes(kMasterKey.vchSalt); CCrypter crypter; - int64_t nStartTime = GetTimeMillis(); + int64_t nStartTime = TicksSinceEpoch(SystemClock::now()); crypter.SetKeyFromPassphrase(strWalletPassphrase, kMasterKey.vchSalt, 25000, kMasterKey.nDerivationMethod); - kMasterKey.nDeriveIterations = static_cast(2500000 / ((double)(GetTimeMillis() - nStartTime))); + kMasterKey.nDeriveIterations = static_cast(2500000 / ((double)(TicksSinceEpoch(SystemClock::now()) - nStartTime))); - nStartTime = GetTimeMillis(); + nStartTime = TicksSinceEpoch(SystemClock::now()); crypter.SetKeyFromPassphrase(strWalletPassphrase, kMasterKey.vchSalt, kMasterKey.nDeriveIterations, kMasterKey.nDerivationMethod); - kMasterKey.nDeriveIterations = (kMasterKey.nDeriveIterations + static_cast(kMasterKey.nDeriveIterations * 100 / ((double)(GetTimeMillis() - nStartTime)))) / 2; + kMasterKey.nDeriveIterations = (kMasterKey.nDeriveIterations + static_cast(kMasterKey.nDeriveIterations * 100 / ((double)(TicksSinceEpoch(SystemClock::now()) - nStartTime)))) / 2; if (kMasterKey.nDeriveIterations < 25000) kMasterKey.nDeriveIterations = 25000; diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 10a363c62fb72..551897349e0ac 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -574,7 +574,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati void AbortRescan() { fAbortRescan = true; } bool IsAbortingRescan() const { return fAbortRescan; } bool IsScanning() const { return fScanningWallet; } - int64_t ScanningDuration() const { return fScanningWallet ? GetTimeMillis() - m_scanning_start : 0; } + int64_t ScanningDuration() const { return fScanningWallet ? TicksSinceEpoch(SystemClock::now()) - m_scanning_start : 0; } double ScanningProgress() const { return fScanningWallet ? (double) m_scanning_progress : 0; } //! Upgrade stored CKeyMetadata objects to store key origin info as KeyOriginInfo @@ -1085,7 +1085,7 @@ class WalletRescanReserver if (m_wallet.fScanningWallet.exchange(true)) { return false; } - m_wallet.m_scanning_start = GetTimeMillis(); + m_wallet.m_scanning_start = TicksSinceEpoch(SystemClock::now()); m_wallet.m_scanning_progress = 0; m_wallet.fAbortRescan = false; m_could_reserve = true; diff --git a/test/README.md b/test/README.md index fac2d4506d051..68053af28e32a 100644 --- a/test/README.md +++ b/test/README.md @@ -311,6 +311,7 @@ Use the `-v` option for verbose output. | Lint test | Dependency | |-----------|:----------:| | [`lint-python.py`](lint/lint-python.py) | [flake8](https://gitlab.com/pycqa/flake8) +| [`lint-python.py`](lint/lint-python.py) | [lief](https://github.com/lief-project/LIEF) | [`lint-python.py`](lint/lint-python.py) | [mypy](https://github.com/python/mypy) | [`lint-python.py`](lint/lint-python.py) | [pyzmq](https://github.com/zeromq/pyzmq) | [`lint-python-dead-code.py`](lint/lint-python-dead-code.py) | [vulture](https://github.com/jendrikseipp/vulture) diff --git a/test/functional/feature_addrman.py b/test/functional/feature_addrman.py index 51203f8d49106..490b554a3225e 100755 --- a/test/functional/feature_addrman.py +++ b/test/functional/feature_addrman.py @@ -9,11 +9,11 @@ import struct from test_framework.messages import ser_uint256, hash256, MAGIC_BYTES +from test_framework.netutil import ADDRMAN_NEW_BUCKET_COUNT, ADDRMAN_TRIED_BUCKET_COUNT, ADDRMAN_BUCKET_SIZE from test_framework.test_framework import BitcoinTestFramework from test_framework.test_node import ErrorMatch from test_framework.util import assert_equal - def serialize_addrman( *, format=1, @@ -116,17 +116,34 @@ def run_test(self): self.log.info("Check that corrupt addrman cannot be read (len_tried)") self.stop_node(0) + max_len_tried = ADDRMAN_TRIED_BUCKET_COUNT * ADDRMAN_BUCKET_SIZE write_addrman(peers_dat, len_tried=-1) self.nodes[0].assert_start_raises_init_error( - expected_msg=init_error("Corrupt AddrMan serialization: nTried=-1, should be in \\[0, 16384\\]:.*"), + expected_msg=init_error(f"Corrupt AddrMan serialization: nTried=-1, should be in \\[0, {max_len_tried}\\]:.*"), + match=ErrorMatch.FULL_REGEX, + ) + + self.log.info("Check that corrupt addrman cannot be read (large len_tried)") + write_addrman(peers_dat, len_tried=max_len_tried + 1) + self.nodes[0].assert_start_raises_init_error( + expected_msg=init_error(f"Corrupt AddrMan serialization: nTried={max_len_tried + 1}, should be in \\[0, {max_len_tried}\\]:.*"), match=ErrorMatch.FULL_REGEX, ) self.log.info("Check that corrupt addrman cannot be read (len_new)") self.stop_node(0) + max_len_new = ADDRMAN_NEW_BUCKET_COUNT * ADDRMAN_BUCKET_SIZE write_addrman(peers_dat, len_new=-1) self.nodes[0].assert_start_raises_init_error( - expected_msg=init_error("Corrupt AddrMan serialization: nNew=-1, should be in \\[0, 65536\\]:.*"), + expected_msg=init_error(f"Corrupt AddrMan serialization: nNew=-1, should be in \\[0, {max_len_new}\\]:.*"), + match=ErrorMatch.FULL_REGEX, + ) + + self.log.info("Check that corrupt addrman cannot be read (large len_new)") + self.stop_node(0) + write_addrman(peers_dat, len_new=max_len_new + 1) + self.nodes[0].assert_start_raises_init_error( + expected_msg=init_error(f"Corrupt AddrMan serialization: nNew={max_len_new + 1}, should be in \\[0, {max_len_new}\\]:.*"), match=ErrorMatch.FULL_REGEX, ) diff --git a/test/functional/test_framework/netutil.py b/test/functional/test_framework/netutil.py index 7d6d813f15da4..7669ba55f15e6 100644 --- a/test/functional/test_framework/netutil.py +++ b/test/functional/test_framework/netutil.py @@ -25,6 +25,11 @@ STATE_LISTEN = '0A' # STATE_CLOSING = '0B' +# Address manager size constants as defined in addrman_impl.h +ADDRMAN_NEW_BUCKET_COUNT = 1 << 10 +ADDRMAN_TRIED_BUCKET_COUNT = 1 << 8 +ADDRMAN_BUCKET_SIZE = 1 << 6 + def get_socket_inodes(pid): ''' Get list of socket inodes for process pid. diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index 8b325b480bd45..2c1c056098b2c 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -263,6 +263,23 @@ def parse_args(self): PortSeed.n = self.options.port_seed + def set_binary_paths(self): + """Update self.options with the paths of all binaries from environment variables or their default values""" + + binaries = { + "dashd": ("bitcoind", "DASHD"), + "dash-cli": ("bitcoincli", "DASHCLI"), + "dash-util": ("bitcoinutil", "DASHUTIL"), + "dash-wallet": ("bitcoinwallet", "DASHWALLET"), + } + for binary, [attribute_name, env_variable_name] in binaries.items(): + default_filename = os.path.join( + self.config["environment"]["BUILDDIR"], + "src", + binary + self.config["environment"]["EXEEXT"], + ) + setattr(self.options, attribute_name, os.getenv(env_variable_name, default=default_filename)) + def setup(self): """Call this method to start up the test framework object with options set.""" @@ -272,18 +289,7 @@ def setup(self): config = self.config - fname_bitcoind = os.path.join( - config["environment"]["BUILDDIR"], - "src", - "dashd" + config["environment"]["EXEEXT"], - ) - fname_bitcoincli = os.path.join( - config["environment"]["BUILDDIR"], - "src", - "dash-cli" + config["environment"]["EXEEXT"], - ) - self.options.bitcoind = os.getenv("BITCOIND", default=fname_bitcoind) - self.options.bitcoincli = os.getenv("BITCOINCLI", default=fname_bitcoincli) + self.set_binary_paths() self.extra_args_from_options = self.options.dashd_extra_args diff --git a/test/functional/tool_wallet.py b/test/functional/tool_wallet.py index 7f5b47bb6feca..585a229d4d96f 100755 --- a/test/functional/tool_wallet.py +++ b/test/functional/tool_wallet.py @@ -28,12 +28,11 @@ def skip_test_if_missing_module(self): self.skip_if_no_wallet_tool() def dash_wallet_process(self, *args): - binary = self.config["environment"]["BUILDDIR"] + '/src/dash-wallet' + self.config["environment"]["EXEEXT"] default_args = ['-datadir={}'.format(self.nodes[0].datadir), '-chain=%s' % self.chain] if self.options.descriptors and 'create' in args: default_args.append('-descriptors') - return subprocess.Popen([binary] + default_args + list(args), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) + return subprocess.Popen([self.options.bitcoinwallet] + default_args + list(args), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) def assert_raises_tool_error(self, error, *args): p = self.dash_wallet_process(*args) diff --git a/test/lint/lint-python.py b/test/lint/lint-python.py index 61d2c49a4629d..574cb65cc05e8 100755 --- a/test/lint/lint-python.py +++ b/test/lint/lint-python.py @@ -13,7 +13,7 @@ import subprocess import sys -DEPS = ['flake8', 'mypy', 'pyzmq'] +DEPS = ['flake8', 'lief', 'mypy', 'pyzmq'] MYPY_CACHE_DIR = f"{os.getenv('BASE_ROOT_DIR', '')}/test/.mypy_cache" FILES_ARGS = ['git', 'ls-files', '--','test/functional/*.py', 'contrib/devtools/*.py', ':(exclude)contrib/devtools/github-merge.py'] EXCLUDE_DIRS = ['src/dashbls/',