From d3b3af90343b7671231afd7dff87e87ff86d31d7 Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Thu, 14 Dec 2023 12:23:36 +0100 Subject: [PATCH 01/39] log: deduplicate category names and improve logging.cpp The code in `logging.cpp` needs to: * Get the category name given the flag (e.g. `BCLog::PRUNE` -> `"prune"`) * Get the flag given the category name (e.g. `"prune"` -> `BCLog::PRUNE`) * Get the list of category names sorted in alphabetical order Achieve this by using the proper std containers. The result is * less code (this diff is +62 / -129) * faster code (to linear search and no copy+sort) * more maintainable code (the categories are no longer duplicated in `LogCategories[]` and `LogCategoryToStr()`) This behavior is preserved: `BCLog::NONE` -> `""` (lookup by `LogCategoryToStr()`) `""` -> `BCLog::ALL` (lookup by `GetLogCategory("")`) --- src/logging.cpp | 191 ++++++++++++++++-------------------------------- 1 file changed, 62 insertions(+), 129 deletions(-) diff --git a/src/logging.cpp b/src/logging.cpp index 42f100ded6..2e3cffb8c1 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -9,9 +9,8 @@ #include #include -#include #include -#include +#include #include const char * const DEFAULT_DEBUGLOGFILE = "debug.log"; @@ -142,49 +141,58 @@ bool BCLog::Logger::DefaultShrinkDebugFile() const return m_categories == BCLog::NONE; } -struct CLogCategoryDesc { - BCLog::LogFlags flag; - std::string category; -}; - -const CLogCategoryDesc LogCategories[] = -{ - {BCLog::NONE, "0"}, - {BCLog::NONE, ""}, - {BCLog::NET, "net"}, - {BCLog::TOR, "tor"}, - {BCLog::MEMPOOL, "mempool"}, - {BCLog::HTTP, "http"}, - {BCLog::BENCH, "bench"}, - {BCLog::ZMQ, "zmq"}, - {BCLog::WALLETDB, "walletdb"}, - {BCLog::RPC, "rpc"}, - {BCLog::ESTIMATEFEE, "estimatefee"}, - {BCLog::ADDRMAN, "addrman"}, - {BCLog::SELECTCOINS, "selectcoins"}, - {BCLog::REINDEX, "reindex"}, - {BCLog::CMPCTBLOCK, "cmpctblock"}, - {BCLog::RAND, "rand"}, - {BCLog::PRUNE, "prune"}, - {BCLog::PROXY, "proxy"}, - {BCLog::MEMPOOLREJ, "mempoolrej"}, - {BCLog::LIBEVENT, "libevent"}, - {BCLog::COINDB, "coindb"}, - {BCLog::QT, "qt"}, - {BCLog::LEVELDB, "leveldb"}, - {BCLog::VALIDATION, "validation"}, - {BCLog::I2P, "i2p"}, - {BCLog::IPC, "ipc"}, +static const std::map LOG_CATEGORIES_BY_STR{ + {"0", BCLog::NONE}, + {"", BCLog::NONE}, + {"net", BCLog::NET}, + {"tor", BCLog::TOR}, + {"mempool", BCLog::MEMPOOL}, + {"http", BCLog::HTTP}, + {"bench", BCLog::BENCH}, + {"zmq", BCLog::ZMQ}, + {"walletdb", BCLog::WALLETDB}, + {"rpc", BCLog::RPC}, + {"estimatefee", BCLog::ESTIMATEFEE}, + {"addrman", BCLog::ADDRMAN}, + {"selectcoins", BCLog::SELECTCOINS}, + {"reindex", BCLog::REINDEX}, + {"cmpctblock", BCLog::CMPCTBLOCK}, + {"rand", BCLog::RAND}, + {"prune", BCLog::PRUNE}, + {"proxy", BCLog::PROXY}, + {"mempoolrej", BCLog::MEMPOOLREJ}, + {"libevent", BCLog::LIBEVENT}, + {"coindb", BCLog::COINDB}, + {"qt", BCLog::QT}, + {"leveldb", BCLog::LEVELDB}, + {"validation", BCLog::VALIDATION}, + {"i2p", BCLog::I2P}, + {"ipc", BCLog::IPC}, #ifdef DEBUG_LOCKCONTENTION - {BCLog::LOCK, "lock"}, + {"lock", BCLog::LOCK}, #endif - {BCLog::UTIL, "util"}, - {BCLog::BLOCKSTORAGE, "blockstorage"}, - {BCLog::TXRECONCILIATION, "txreconciliation"}, - {BCLog::SCAN, "scan"}, - {BCLog::TXPACKAGES, "txpackages"}, - {BCLog::ALL, "1"}, - {BCLog::ALL, "all"}, + {"util", BCLog::UTIL}, + {"blockstorage", BCLog::BLOCKSTORAGE}, + {"txreconciliation", BCLog::TXRECONCILIATION}, + {"scan", BCLog::SCAN}, + {"txpackages", BCLog::TXPACKAGES}, + {"1", BCLog::ALL}, + {"all", BCLog::ALL}, +}; + +static const std::unordered_map LOG_CATEGORIES_BY_FLAG{ + // Swap keys and values from LOG_CATEGORIES_BY_STR. + [](const std::map& in) { + std::unordered_map out; + for (const auto& [k, v] : in) { + switch (v) { + case BCLog::NONE: out.emplace(BCLog::NONE, ""); break; + case BCLog::ALL: out.emplace(BCLog::ALL, "all"); break; + default: out.emplace(v, k); + } + } + return out; + }(LOG_CATEGORIES_BY_STR) }; bool GetLogCategory(BCLog::LogFlags& flag, const std::string& str) @@ -193,11 +201,10 @@ bool GetLogCategory(BCLog::LogFlags& flag, const std::string& str) flag = BCLog::ALL; return true; } - for (const CLogCategoryDesc& category_desc : LogCategories) { - if (category_desc.category == str) { - flag = category_desc.flag; - return true; - } + auto it = LOG_CATEGORIES_BY_STR.find(str); + if (it != LOG_CATEGORIES_BY_STR.end()) { + flag = it->second; + return true; } return false; } @@ -221,76 +228,9 @@ std::string BCLog::Logger::LogLevelToStr(BCLog::Level level) std::string LogCategoryToStr(BCLog::LogFlags category) { - // Each log category string representation should sync with LogCategories - switch (category) { - case BCLog::LogFlags::NONE: - return ""; - case BCLog::LogFlags::NET: - return "net"; - case BCLog::LogFlags::TOR: - return "tor"; - case BCLog::LogFlags::MEMPOOL: - return "mempool"; - case BCLog::LogFlags::HTTP: - return "http"; - case BCLog::LogFlags::BENCH: - return "bench"; - case BCLog::LogFlags::ZMQ: - return "zmq"; - case BCLog::LogFlags::WALLETDB: - return "walletdb"; - case BCLog::LogFlags::RPC: - return "rpc"; - case BCLog::LogFlags::ESTIMATEFEE: - return "estimatefee"; - case BCLog::LogFlags::ADDRMAN: - return "addrman"; - case BCLog::LogFlags::SELECTCOINS: - return "selectcoins"; - case BCLog::LogFlags::REINDEX: - return "reindex"; - case BCLog::LogFlags::CMPCTBLOCK: - return "cmpctblock"; - case BCLog::LogFlags::RAND: - return "rand"; - case BCLog::LogFlags::PRUNE: - return "prune"; - case BCLog::LogFlags::PROXY: - return "proxy"; - case BCLog::LogFlags::MEMPOOLREJ: - return "mempoolrej"; - case BCLog::LogFlags::LIBEVENT: - return "libevent"; - case BCLog::LogFlags::COINDB: - return "coindb"; - case BCLog::LogFlags::QT: - return "qt"; - case BCLog::LogFlags::LEVELDB: - return "leveldb"; - case BCLog::LogFlags::VALIDATION: - return "validation"; - case BCLog::LogFlags::I2P: - return "i2p"; - case BCLog::LogFlags::IPC: - return "ipc"; -#ifdef DEBUG_LOCKCONTENTION - case BCLog::LogFlags::LOCK: - return "lock"; -#endif - case BCLog::LogFlags::UTIL: - return "util"; - case BCLog::LogFlags::BLOCKSTORAGE: - return "blockstorage"; - case BCLog::LogFlags::TXRECONCILIATION: - return "txreconciliation"; - case BCLog::LogFlags::SCAN: - return "scan"; - case BCLog::LogFlags::TXPACKAGES: - return "txpackages"; - case BCLog::LogFlags::ALL: - return "all"; - } - assert(false); + auto it = LOG_CATEGORIES_BY_FLAG.find(category); + assert(it != LOG_CATEGORIES_BY_FLAG.end()); + return it->second; } static std::optional GetLogLevel(const std::string& level_str) @@ -312,18 +252,11 @@ static std::optional GetLogLevel(const std::string& level_str) std::vector BCLog::Logger::LogCategoriesList() const { - // Sort log categories by alphabetical order. - std::array categories; - std::copy(std::begin(LogCategories), std::end(LogCategories), categories.begin()); - std::sort(categories.begin(), categories.end(), [](auto a, auto b) { return a.category < b.category; }); - std::vector ret; - for (const CLogCategoryDesc& category_desc : categories) { - if (category_desc.flag == BCLog::NONE || category_desc.flag == BCLog::ALL) continue; - LogCategory catActive; - catActive.category = category_desc.category; - catActive.active = WillLogCategory(category_desc.flag); - ret.push_back(catActive); + for (const auto& [category, flag] : LOG_CATEGORIES_BY_STR) { + if (flag != BCLog::NONE && flag != BCLog::ALL) { + ret.push_back(LogCategory{.category = category, .active = WillLogCategory(flag)}); + } } return ret; } From b0344c219a641b759fb0cc4f53afebe675b8ca27 Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Sun, 11 Feb 2024 15:24:46 +0100 Subject: [PATCH 02/39] logging: remove unused BCLog::UTIL Suggested by: David Gumberg (https://github.com/bitcoin/bitcoin/pull/29415#discussion_r1485310634) --- src/logging.cpp | 1 - src/logging.h | 9 ++++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/logging.cpp b/src/logging.cpp index 2e3cffb8c1..578650f856 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -171,7 +171,6 @@ static const std::map LOG_CATEGORIES_BY_STR{ #ifdef DEBUG_LOCKCONTENTION {"lock", BCLog::LOCK}, #endif - {"util", BCLog::UTIL}, {"blockstorage", BCLog::BLOCKSTORAGE}, {"txreconciliation", BCLog::TXRECONCILIATION}, {"scan", BCLog::SCAN}, diff --git a/src/logging.h b/src/logging.h index 525e0aec6d..54af9d3a42 100644 --- a/src/logging.h +++ b/src/logging.h @@ -65,11 +65,10 @@ namespace BCLog { #ifdef DEBUG_LOCKCONTENTION LOCK = (1 << 24), #endif - UTIL = (1 << 25), - BLOCKSTORAGE = (1 << 26), - TXRECONCILIATION = (1 << 27), - SCAN = (1 << 28), - TXPACKAGES = (1 << 29), + BLOCKSTORAGE = (1 << 25), + TXRECONCILIATION = (1 << 26), + SCAN = (1 << 27), + TXPACKAGES = (1 << 28), ALL = ~(uint32_t)0, }; enum class Level { From fa2c486afc8501f2678cc19c9e9518a23c4ebcbd Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Thu, 14 Dec 2023 18:19:58 +0100 Subject: [PATCH 03/39] Revert "time: add runtime sanity check" This reverts commit 3c2e16be22ae04bf56663ee5ec1554d0d569741b. --- src/kernel/checks.cpp | 5 ----- src/test/sanity_tests.cpp | 2 -- src/util/time.cpp | 43 --------------------------------------- src/util/time.h | 3 --- 4 files changed, 53 deletions(-) diff --git a/src/kernel/checks.cpp b/src/kernel/checks.cpp index bf8a2ec74c..45a5e25093 100644 --- a/src/kernel/checks.cpp +++ b/src/kernel/checks.cpp @@ -6,7 +6,6 @@ #include #include -#include #include #include @@ -23,10 +22,6 @@ util::Result SanityChecks(const Context&) return util::Error{Untranslated("OS cryptographic RNG sanity check failure. Aborting.")}; } - if (!ChronoSanityCheck()) { - return util::Error{Untranslated("Clock epoch mismatch. Aborting.")}; - } - return {}; } diff --git a/src/test/sanity_tests.cpp b/src/test/sanity_tests.cpp index 451bc99d44..68f82b760c 100644 --- a/src/test/sanity_tests.cpp +++ b/src/test/sanity_tests.cpp @@ -4,7 +4,6 @@ #include #include -#include #include @@ -13,7 +12,6 @@ BOOST_FIXTURE_TEST_SUITE(sanity_tests, BasicTestingSetup) BOOST_AUTO_TEST_CASE(basic_sanity) { BOOST_CHECK_MESSAGE(ECC_InitSanityCheck() == true, "secp256k1 sanity test"); - BOOST_CHECK_MESSAGE(ChronoSanityCheck() == true, "chrono epoch test"); } BOOST_AUTO_TEST_SUITE_END() diff --git a/src/util/time.cpp b/src/util/time.cpp index 5ca9d21f8d..ccb1f50610 100644 --- a/src/util/time.cpp +++ b/src/util/time.cpp @@ -24,49 +24,6 @@ void UninterruptibleSleep(const std::chrono::microseconds& n) { std::this_thread static std::atomic nMockTime(0); //!< For testing -bool ChronoSanityCheck() -{ - // std::chrono::system_clock.time_since_epoch and time_t(0) are not guaranteed - // to use the Unix epoch timestamp, prior to C++20, but in practice they almost - // certainly will. Any differing behavior will be assumed to be an error, unless - // certain platforms prove to consistently deviate, at which point we'll cope - // with it by adding offsets. - - // Create a new clock from time_t(0) and make sure that it represents 0 - // seconds from the system_clock's time_since_epoch. Then convert that back - // to a time_t and verify that it's the same as before. - const time_t time_t_epoch{}; - auto clock = std::chrono::system_clock::from_time_t(time_t_epoch); - if (std::chrono::duration_cast(clock.time_since_epoch()).count() != 0) { - return false; - } - - time_t time_val = std::chrono::system_clock::to_time_t(clock); - if (time_val != time_t_epoch) { - return false; - } - - // Check that the above zero time is actually equal to the known unix timestamp. - struct tm epoch; -#ifdef HAVE_GMTIME_R - if (gmtime_r(&time_val, &epoch) == nullptr) { -#else - if (gmtime_s(&epoch, &time_val) != 0) { -#endif - return false; - } - - if ((epoch.tm_sec != 0) || - (epoch.tm_min != 0) || - (epoch.tm_hour != 0) || - (epoch.tm_mday != 1) || - (epoch.tm_mon != 0) || - (epoch.tm_year != 70)) { - return false; - } - return true; -} - NodeClock::time_point NodeClock::now() noexcept { const std::chrono::seconds mocktime{nMockTime.load(std::memory_order_relaxed)}; diff --git a/src/util/time.h b/src/util/time.h index 6aa776137c..108560e0e0 100644 --- a/src/util/time.h +++ b/src/util/time.h @@ -116,7 +116,4 @@ struct timeval MillisToTimeval(int64_t nTimeout); */ struct timeval MillisToTimeval(std::chrono::milliseconds ms); -/** Sanity check epoch match normal Unix epoch */ -bool ChronoSanityCheck(); - #endif // BITCOIN_UTIL_TIME_H From fa72dcbfa56177ca878375bae7c7bca6ca6a1f40 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Thu, 14 Dec 2023 18:20:48 +0100 Subject: [PATCH 04/39] refactor: FormatISO8601* without gmtime* --- src/test/util_tests.cpp | 5 +++++ src/util/time.cpp | 45 ++++++++++++++--------------------------- 2 files changed, 20 insertions(+), 30 deletions(-) diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index 47808a2a58..9a2add748e 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -290,13 +290,18 @@ BOOST_AUTO_TEST_CASE(util_TrimString) BOOST_AUTO_TEST_CASE(util_FormatISO8601DateTime) { + BOOST_CHECK_EQUAL(FormatISO8601DateTime(971890963199), "32767-12-31T23:59:59Z"); + BOOST_CHECK_EQUAL(FormatISO8601DateTime(971890876800), "32767-12-31T00:00:00Z"); BOOST_CHECK_EQUAL(FormatISO8601DateTime(1317425777), "2011-09-30T23:36:17Z"); BOOST_CHECK_EQUAL(FormatISO8601DateTime(0), "1970-01-01T00:00:00Z"); } BOOST_AUTO_TEST_CASE(util_FormatISO8601Date) { + BOOST_CHECK_EQUAL(FormatISO8601Date(971890963199), "32767-12-31"); + BOOST_CHECK_EQUAL(FormatISO8601Date(971890876800), "32767-12-31"); BOOST_CHECK_EQUAL(FormatISO8601Date(1317425777), "2011-09-30"); + BOOST_CHECK_EQUAL(FormatISO8601Date(0), "1970-01-01"); } BOOST_AUTO_TEST_CASE(util_FormatMoney) diff --git a/src/util/time.cpp b/src/util/time.cpp index ccb1f50610..456662bd84 100644 --- a/src/util/time.cpp +++ b/src/util/time.cpp @@ -3,22 +3,16 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#if defined(HAVE_CONFIG_H) -#include -#endif +#include #include #include -#include #include #include #include -#include -#include -#include -#include #include +#include void UninterruptibleSleep(const std::chrono::microseconds& n) { std::this_thread::sleep_for(n); } @@ -53,30 +47,21 @@ std::chrono::seconds GetMockTime() int64_t GetTime() { return GetTime().count(); } -std::string FormatISO8601DateTime(int64_t nTime) { - struct tm ts; - time_t time_val = nTime; -#ifdef HAVE_GMTIME_R - if (gmtime_r(&time_val, &ts) == nullptr) { -#else - if (gmtime_s(&ts, &time_val) != 0) { -#endif - return {}; - } - return strprintf("%04i-%02i-%02iT%02i:%02i:%02iZ", ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec); +std::string FormatISO8601DateTime(int64_t nTime) +{ + const std::chrono::sys_seconds secs{std::chrono::seconds{nTime}}; + const auto days{std::chrono::floor(secs)}; + const std::chrono::year_month_day ymd{days}; + const std::chrono::hh_mm_ss hms{secs - days}; + return strprintf("%04i-%02u-%02uT%02i:%02i:%02iZ", signed{ymd.year()}, unsigned{ymd.month()}, unsigned{ymd.day()}, hms.hours().count(), hms.minutes().count(), hms.seconds().count()); } -std::string FormatISO8601Date(int64_t nTime) { - struct tm ts; - time_t time_val = nTime; -#ifdef HAVE_GMTIME_R - if (gmtime_r(&time_val, &ts) == nullptr) { -#else - if (gmtime_s(&ts, &time_val) != 0) { -#endif - return {}; - } - return strprintf("%04i-%02i-%02i", ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday); +std::string FormatISO8601Date(int64_t nTime) +{ + const std::chrono::sys_seconds secs{std::chrono::seconds{nTime}}; + const auto days{std::chrono::floor(secs)}; + const std::chrono::year_month_day ymd{days}; + return strprintf("%04i-%02u-%02u", signed{ymd.year()}, unsigned{ymd.month()}, unsigned{ymd.day()}); } struct timeval MillisToTimeval(int64_t nTimeout) From fa9f36babaceba6ab2f88e64bc4bc2956f58871f Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Thu, 14 Dec 2023 18:30:56 +0100 Subject: [PATCH 05/39] build: Remove HAVE_GMTIME_R --- configure.ac | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/configure.ac b/configure.ac index 03b5ff1d69..af66493ed6 100644 --- a/configure.ac +++ b/configure.ac @@ -1092,22 +1092,6 @@ if test "$use_thread_local" = "yes" || test "$use_thread_local" = "auto"; then LDFLAGS="$TEMP_LDFLAGS" fi -dnl check for gmtime_r(), fallback to gmtime_s() if that is unavailable -dnl fail if neither are available. -AC_MSG_CHECKING([for gmtime_r]) -AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], - [[ gmtime_r((const time_t *) nullptr, (struct tm *) nullptr); ]])], - [ AC_MSG_RESULT([yes]); AC_DEFINE([HAVE_GMTIME_R], [1], [Define this symbol if gmtime_r is available]) ], - [ AC_MSG_RESULT([no]); - AC_MSG_CHECKING([for gmtime_s]); - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], - [[ gmtime_s((struct tm *) nullptr, (const time_t *) nullptr); ]])], - [ AC_MSG_RESULT([yes])], - [ AC_MSG_RESULT([no]); AC_MSG_ERROR([Both gmtime_r and gmtime_s are unavailable]) ] - ) - ] -) - dnl Check for different ways of gathering OS randomness AC_MSG_CHECKING([for Linux getrandom function]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ @@ -1879,7 +1863,6 @@ AC_SUBST(MINIUPNPC_CPPFLAGS) AC_SUBST(MINIUPNPC_LIBS) AC_SUBST(NATPMP_CPPFLAGS) AC_SUBST(NATPMP_LIBS) -AC_SUBST(HAVE_GMTIME_R) AC_SUBST(HAVE_FDATASYNC) AC_SUBST(HAVE_FULLFSYNC) AC_SUBST(HAVE_O_CLOEXEC) From 80f8b92f4f2311b9e9a25361c9dd973244e6f95c Mon Sep 17 00:00:00 2001 From: fanquake Date: Mon, 11 Mar 2024 12:12:12 +0000 Subject: [PATCH 06/39] remove libbitcoinconsensus This was deprecated in v27.0, for removal in v28.0. See discussion in PR #29189. --- .gitignore | 1 - Makefile.am | 5 - .../libbitcoin_consensus.vcxproj | 1 - .../00_setup_env_native_previous_releases.sh | 2 +- configure.ac | 26 +- doc/README.md | 1 - doc/design/libraries.md | 9 +- doc/shared-libraries.md | 78 ------ libbitcoinconsensus.pc.in | 10 - src/Makefile.am | 19 -- src/Makefile.test.include | 1 - src/bench/verify_script.cpp | 18 -- src/script/bitcoinconsensus.cpp | 157 ------------ src/script/bitcoinconsensus.h | 96 -------- src/test/fuzz/script_bitcoin_consensus.cpp | 50 ---- src/test/script_tests.cpp | 228 ------------------ src/validation.h | 2 +- 17 files changed, 10 insertions(+), 694 deletions(-) delete mode 100644 doc/shared-libraries.md delete mode 100644 libbitcoinconsensus.pc.in delete mode 100644 src/script/bitcoinconsensus.cpp delete mode 100644 src/script/bitcoinconsensus.h delete mode 100644 src/test/fuzz/script_bitcoin_consensus.cpp diff --git a/.gitignore b/.gitignore index 3fe36aba89..f604b7aeee 100644 --- a/.gitignore +++ b/.gitignore @@ -136,7 +136,6 @@ test/lint/test_runner/target/ /doc/doxygen/ -libbitcoinconsensus.pc contrib/devtools/split-debug.sh # Output from running db4 installation diff --git a/Makefile.am b/Makefile.am index 5ea690dec8..9e9270d7a3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -14,11 +14,6 @@ endif .PHONY: deploy FORCE .INTERMEDIATE: $(COVERAGE_INFO) -if BUILD_BITCOIN_LIBS -pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = libbitcoinconsensus.pc -endif - BITCOIND_BIN=$(top_builddir)/src/$(BITCOIN_DAEMON_NAME)$(EXEEXT) BITCOIN_QT_BIN=$(top_builddir)/src/qt/$(BITCOIN_GUI_NAME)$(EXEEXT) BITCOIN_TEST_BIN=$(top_builddir)/src/test/$(BITCOIN_TEST_NAME)$(EXEEXT) diff --git a/build_msvc/libbitcoin_consensus/libbitcoin_consensus.vcxproj b/build_msvc/libbitcoin_consensus/libbitcoin_consensus.vcxproj index 95fdcdb79b..a34ef41d16 100644 --- a/build_msvc/libbitcoin_consensus/libbitcoin_consensus.vcxproj +++ b/build_msvc/libbitcoin_consensus/libbitcoin_consensus.vcxproj @@ -15,7 +15,6 @@ - diff --git a/ci/test/00_setup_env_native_previous_releases.sh b/ci/test/00_setup_env_native_previous_releases.sh index 3166686d9a..9da3b18999 100755 --- a/ci/test/00_setup_env_native_previous_releases.sh +++ b/ci/test/00_setup_env_native_previous_releases.sh @@ -16,5 +16,5 @@ export RUN_UNIT_TESTS_SEQUENTIAL="true" export RUN_UNIT_TESTS="false" export GOAL="install" export DOWNLOAD_PREVIOUS_RELEASES="true" -export BITCOIN_CONFIG="--enable-zmq --with-libs=no --with-gui=qt5 --enable-reduce-exports --enable-debug \ +export BITCOIN_CONFIG="--enable-zmq --with-gui=qt5 --enable-reduce-exports --enable-debug \ CFLAGS=\"-g0 -O2 -funsigned-char\" CPPFLAGS='-DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE' CXXFLAGS=\"-g0 -O2 -funsigned-char\"" diff --git a/configure.ac b/configure.ac index 03b5ff1d69..964b7d0942 100644 --- a/configure.ac +++ b/configure.ac @@ -626,15 +626,9 @@ AC_ARG_ENABLE([experimental-util-chainstate], [build_bitcoin_chainstate=$enableval], [build_bitcoin_chainstate=no]) -AC_ARG_WITH([libs], - [AS_HELP_STRING([--with-libs], - [build libraries (default=yes)])], - [build_bitcoin_libs=$withval], - [build_bitcoin_libs=yes]) - AC_ARG_WITH([experimental-kernel-lib], [AS_HELP_STRING([--with-experimental-kernel-lib], - [build experimental bitcoinkernel library (default is to build if we're building libraries and the experimental build-chainstate executable)])], + [build experimental bitcoinkernel library (default is to build if we're building the experimental build-chainstate executable)])], [build_experimental_kernel_lib=$withval], [build_experimental_kernel_lib=auto]) @@ -1262,7 +1256,6 @@ if test "$enable_fuzz" = "yes"; then build_bitcoin_chainstate=no build_bitcoin_wallet=no build_bitcoind=no - build_bitcoin_libs=no bitcoin_enable_qt=no bitcoin_enable_qt_test=no bitcoin_enable_qt_dbus=no @@ -1421,7 +1414,7 @@ if test "$use_boost" = "yes"; then dnl Check for Boost headers AX_BOOST_BASE([1.73.0],[],[AC_MSG_ERROR([Boost is not available!])]) if test "$want_boost" = "no"; then - AC_MSG_ERROR([only libbitcoinconsensus can be built without Boost]) + AC_MSG_ERROR([Boost is required]) fi dnl we don't use multi_index serialization @@ -1635,18 +1628,8 @@ fi AM_CONDITIONAL([BUILD_BITCOIN_CHAINSTATE], [test $build_bitcoin_chainstate = "yes"]) AC_MSG_RESULT($build_bitcoin_chainstate) -AC_MSG_CHECKING([whether to build libraries]) -AM_CONDITIONAL([BUILD_BITCOIN_LIBS], [test $build_bitcoin_libs = "yes"]) - -if test "$build_bitcoin_libs" = "yes"; then - AC_DEFINE([HAVE_CONSENSUS_LIB], [1], [Define this symbol if the consensus lib has been built]) - AC_CONFIG_FILES([libbitcoinconsensus.pc:libbitcoinconsensus.pc.in]) -fi - AM_CONDITIONAL([BUILD_BITCOIN_KERNEL_LIB], [test "$build_experimental_kernel_lib" != "no" && ( test "$build_experimental_kernel_lib" = "yes" || test "$build_bitcoin_chainstate" = "yes" )]) -AC_MSG_RESULT($build_bitcoin_libs) - AC_LANG_POP if test "$use_ccache" != "no"; then @@ -1780,8 +1763,8 @@ else AC_MSG_RESULT([no]) fi -if test "$build_bitcoin_wallet$build_bitcoin_cli$build_bitcoin_tx$build_bitcoin_util$build_bitcoin_libs$build_bitcoind$bitcoin_enable_qt$enable_fuzz_binary$use_bench$use_tests" = "nononononononononono"; then - AC_MSG_ERROR([No targets! Please specify at least one of: --with-utils --with-libs --with-daemon --with-gui --enable-fuzz(-binary) --enable-bench or --enable-tests]) +if test "$build_bitcoin_wallet$build_bitcoin_cli$build_bitcoin_tx$build_bitcoin_util$build_bitcoind$bitcoin_enable_qt$enable_fuzz_binary$use_bench$use_tests" = "nonononononononono"; then + AC_MSG_ERROR([No targets! Please specify at least one of: --with-utils --with-daemon --with-gui --enable-fuzz(-binary) --enable-bench or --enable-tests]) fi AM_CONDITIONAL([TARGET_DARWIN], [test "$TARGET_OS" = "darwin"]) @@ -1941,7 +1924,6 @@ echo echo "Options used to compile and link:" echo " external signer = $use_external_signer" echo " multiprocess = $build_multiprocess" -echo " with libs = $build_bitcoin_libs" echo " with wallet = $enable_wallet" if test "$enable_wallet" != "no"; then echo " with sqlite = $use_sqlite" diff --git a/doc/README.md b/doc/README.md index 446684b482..7b6dacaf4f 100644 --- a/doc/README.md +++ b/doc/README.md @@ -59,7 +59,6 @@ The Bitcoin repo's [root README](/README.md) contains relevant information on th - [Translation Strings Policy](translation_strings_policy.md) - [JSON-RPC Interface](JSON-RPC-interface.md) - [Unauthenticated REST Interface](REST-interface.md) -- [Shared Libraries](shared-libraries.md) - [BIPS](bips.md) - [Dnsseed Policy](dnsseed-policy.md) - [Benchmarking](benchmarking.md) diff --git a/doc/design/libraries.md b/doc/design/libraries.md index 7cda64e713..3346c8e81b 100644 --- a/doc/design/libraries.md +++ b/doc/design/libraries.md @@ -4,10 +4,9 @@ |--------------------------|-------------| | *libbitcoin_cli* | RPC client functionality used by *bitcoin-cli* executable | | *libbitcoin_common* | Home for common functionality shared by different executables and libraries. Similar to *libbitcoin_util*, but higher-level (see [Dependencies](#dependencies)). | -| *libbitcoin_consensus* | Stable, backwards-compatible consensus functionality used by *libbitcoin_node* and *libbitcoin_wallet* and also exposed as a [shared library](../shared-libraries.md). | -| *libbitcoinconsensus* | Shared library build of static *libbitcoin_consensus* library | -| *libbitcoin_kernel* | Consensus engine and support library used for validation by *libbitcoin_node* and also exposed as a [shared library](../shared-libraries.md). | -| *libbitcoinqt* | GUI functionality used by *bitcoin-qt* and *bitcoin-gui* executables | +| *libbitcoin_consensus* | Stable, backwards-compatible consensus functionality used by *libbitcoin_node* and *libbitcoin_wallet*. | +| *libbitcoin_kernel* | Consensus engine and support library used for validation by *libbitcoin_node*. | +| *libbitcoinqt* | GUI functionality used by *bitcoin-qt* and *bitcoin-gui* executables. | | *libbitcoin_ipc* | IPC functionality used by *bitcoin-node*, *bitcoin-wallet*, *bitcoin-gui* executables to communicate when [`--enable-multiprocess`](multiprocess.md) is used. | | *libbitcoin_node* | P2P and RPC server functionality used by *bitcoind* and *bitcoin-qt* executables. | | *libbitcoin_util* | Home for common functionality shared by different executables and libraries. Similar to *libbitcoin_common*, but lower-level (see [Dependencies](#dependencies)). | @@ -17,7 +16,7 @@ ## Conventions -- Most libraries are internal libraries and have APIs which are completely unstable! There are few or no restrictions on backwards compatibility or rules about external dependencies. Exceptions are *libbitcoin_consensus* and *libbitcoin_kernel* which have external interfaces documented at [../shared-libraries.md](../shared-libraries.md). +- Most libraries are internal libraries and have APIs which are completely unstable! There are few or no restrictions on backwards compatibility or rules about external dependencies. An exception is *libbitcoin_kernel*, which, at some future point, will have a documented external interface. - Generally each library should have a corresponding source directory and namespace. Source code organization is a work in progress, so it is true that some namespaces are applied inconsistently, and if you look at [`libbitcoin_*_SOURCES`](../../src/Makefile.am) lists you can see that many libraries pull in files from outside their source directory. But when working with libraries, it is good to follow a consistent pattern like: diff --git a/doc/shared-libraries.md b/doc/shared-libraries.md deleted file mode 100644 index 3a448c6556..0000000000 --- a/doc/shared-libraries.md +++ /dev/null @@ -1,78 +0,0 @@ -Shared Libraries -================ - -## bitcoinconsensus -***This library is deprecated and will be removed in v28*** - -The purpose of this library is to make the verification functionality that is critical to Bitcoin's consensus available to other applications, e.g. to language bindings. - -### API - -The interface is defined in the C header `bitcoinconsensus.h` located in `src/script/bitcoinconsensus.h`. - -#### Version - -`bitcoinconsensus_version` returns an `unsigned int` with the API version *(currently `2`)*. - -#### Script Validation - -`bitcoinconsensus_verify_script`, `bitcoinconsensus_verify_script_with_amount` and `bitcoinconsensus_verify_script_with_spent_outputs` return an `int` with the status of the verification. It will be `1` if the input script correctly spends the previous output `scriptPubKey`. - -##### Parameters -###### bitcoinconsensus_verify_script -- `const unsigned char *scriptPubKey` - The previous output script that encumbers spending. -- `unsigned int scriptPubKeyLen` - The number of bytes for the `scriptPubKey`. -- `const unsigned char *txTo` - The transaction with the input that is spending the previous output. -- `unsigned int txToLen` - The number of bytes for the `txTo`. -- `unsigned int nIn` - The index of the input in `txTo` that spends the `scriptPubKey`. -- `unsigned int flags` - The script validation flags *(see below)*. -- `bitcoinconsensus_error* err` - Will have the error/success code for the operation *(see below)*. - -###### bitcoinconsensus_verify_script_with_amount -- `const unsigned char *scriptPubKey` - The previous output script that encumbers spending. -- `unsigned int scriptPubKeyLen` - The number of bytes for the `scriptPubKey`. -- `int64_t amount` - The amount spent in the input -- `const unsigned char *txTo` - The transaction with the input that is spending the previous output. -- `unsigned int txToLen` - The number of bytes for the `txTo`. -- `unsigned int nIn` - The index of the input in `txTo` that spends the `scriptPubKey`. -- `unsigned int flags` - The script validation flags *(see below)*. -- `bitcoinconsensus_error* err` - Will have the error/success code for the operation *(see below)*. - -###### bitcoinconsensus_verify_script_with_spent_outputs -- `const unsigned char *scriptPubKey` - The previous output script that encumbers spending. -- `unsigned int scriptPubKeyLen` - The number of bytes for the `scriptPubKey`. -- `int64_t amount` - The amount spent in the input -- `const unsigned char *txTo` - The transaction with the input that is spending the previous output. -- `unsigned int txToLen` - The number of bytes for the `txTo`. -- `UTXO *spentOutputs` - Previous outputs spent in the transaction. `UTXO` is a struct composed by `const unsigned char *scriptPubKey`, `unsigned int scriptPubKeySize` (the number of bytes for the `scriptPubKey`) and `unsigned int value`. -- `unsigned int spentOutputsLen` - The number of bytes for the `spentOutputs`. -- `unsigned int nIn` - The index of the input in `txTo` that spends the `scriptPubKey`. -- `unsigned int flags` - The script validation flags *(see below)*. -- `bitcoinconsensus_error* err` - Will have the error/success code for the operation *(see below)*. - -##### Script Flags -- `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_NONE` -- `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_P2SH` - Evaluate P2SH ([BIP16](https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki)) subscripts -- `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_DERSIG` - Enforce strict DER ([BIP66](https://github.com/bitcoin/bips/blob/master/bip-0066.mediawiki)) compliance -- `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_NULLDUMMY` - Enforce NULLDUMMY ([BIP147](https://github.com/bitcoin/bips/blob/master/bip-0147.mediawiki)) -- `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_CHECKLOCKTIMEVERIFY` - Enable CHECKLOCKTIMEVERIFY ([BIP65](https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki)) -- `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_CHECKSEQUENCEVERIFY` - Enable CHECKSEQUENCEVERIFY ([BIP112](https://github.com/bitcoin/bips/blob/master/bip-0112.mediawiki)) -- `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_WITNESS` - Enable WITNESS ([BIP141](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki)) -- `bitcoinconsensus_SCRIPT_FLAGS_VERIFY_TAPROOT` - Enable TAPROOT ([BIP340](https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki), [BIP341](https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki), [BIP342](https://github.com/bitcoin/bips/blob/master/bip-0342.mediawiki)) - -##### Errors -- `bitcoinconsensus_ERR_OK` - No errors with input parameters *(see the return value of `bitcoinconsensus_verify_script` for the verification status)* -- `bitcoinconsensus_ERR_TX_INDEX` - An invalid index for `txTo` -- `bitcoinconsensus_ERR_TX_SIZE_MISMATCH` - `txToLen` did not match with the size of `txTo` -- `bitcoinconsensus_ERR_DESERIALIZE` - An error deserializing `txTo` -- `bitcoinconsensus_ERR_AMOUNT_REQUIRED` - Input amount is required if WITNESS is used -- `bitcoinconsensus_ERR_INVALID_FLAGS` - Script verification `flags` are invalid (i.e. not part of the libconsensus interface) -- `bitcoinconsensus_ERR_SPENT_OUTPUTS_REQUIRED` - Spent outputs are required if TAPROOT is used -- `bitcoinconsensus_ERR_SPENT_OUTPUTS_MISMATCH` - Spent outputs size doesn't match tx inputs size - -### Example Implementations -- [NBitcoin](https://github.com/MetacoSA/NBitcoin/blob/5e1055cd7c4186dee4227c344af8892aea54faec/NBitcoin/Script.cs#L979-#L1031) (.NET Bindings) -- [node-libbitcoinconsensus](https://github.com/bitpay/node-libbitcoinconsensus) (Node.js Bindings) -- [java-libbitcoinconsensus](https://github.com/dexX7/java-libbitcoinconsensus) (Java Bindings) -- [bitcoinconsensus-php](https://github.com/Bit-Wasp/bitcoinconsensus-php) (PHP Bindings) -- [rust-bitcoinconsensus](https://github.com/rust-bitcoin/rust-bitcoinconsensus) (Rust Bindings) \ No newline at end of file diff --git a/libbitcoinconsensus.pc.in b/libbitcoinconsensus.pc.in deleted file mode 100644 index 1ceab280bb..0000000000 --- a/libbitcoinconsensus.pc.in +++ /dev/null @@ -1,10 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ - -Name: @PACKAGE_NAME@ consensus library -Description: Library for the Bitcoin consensus protocol. -Version: @PACKAGE_VERSION@ -Libs: -L${libdir} -lbitcoinconsensus -Cflags: -I${includedir} diff --git a/src/Makefile.am b/src/Makefile.am index 1f55bfbafd..84e8bd5cef 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -39,9 +39,6 @@ LIBSECP256K1=secp256k1/libsecp256k1.la if ENABLE_ZMQ LIBBITCOIN_ZMQ=libbitcoin_zmq.a endif -if BUILD_BITCOIN_LIBS -LIBBITCOINCONSENSUS=libbitcoinconsensus.la -endif if BUILD_BITCOIN_KERNEL_LIB LIBBITCOINKERNEL=libbitcoinkernel.la endif @@ -648,7 +645,6 @@ libbitcoin_consensus_a_SOURCES = \ primitives/transaction.h \ pubkey.cpp \ pubkey.h \ - script/bitcoinconsensus.cpp \ script/interpreter.cpp \ script/interpreter.h \ script/script.cpp \ @@ -1007,21 +1003,6 @@ libbitcoinkernel_la-clientversion.l$(OBJEXT): obj/build.h endif # BUILD_BITCOIN_KERNEL_LIB # -# bitcoinconsensus library # -if BUILD_BITCOIN_LIBS -lib_LTLIBRARIES += $(LIBBITCOINCONSENSUS) - -include_HEADERS = script/bitcoinconsensus.h -libbitcoinconsensus_la_SOURCES = support/cleanse.cpp $(crypto_libbitcoin_crypto_base_la_SOURCES) $(libbitcoin_consensus_a_SOURCES) - -libbitcoinconsensus_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS) -libbitcoinconsensus_la_LIBADD = $(LIBSECP256K1) -libbitcoinconsensus_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -DBUILD_BITCOIN_INTERNAL -DDISABLE_OPTIMIZED_SHA256 -libbitcoinconsensus_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) - -endif -# - CTAES_DIST = crypto/ctaes/bench.c CTAES_DIST += crypto/ctaes/ctaes.c CTAES_DIST += crypto/ctaes/ctaes.h diff --git a/src/Makefile.test.include b/src/Makefile.test.include index 9f9bdbbd0c..8d44e8df0a 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -362,7 +362,6 @@ test_fuzz_fuzz_SOURCES = \ test/fuzz/rpc.cpp \ test/fuzz/script.cpp \ test/fuzz/script_assets_test_minimizer.cpp \ - test/fuzz/script_bitcoin_consensus.cpp \ test/fuzz/script_descriptor_cache.cpp \ test/fuzz/script_flags.cpp \ test/fuzz/script_format.cpp \ diff --git a/src/bench/verify_script.cpp b/src/bench/verify_script.cpp index e7166a91cf..ee750bc1f8 100644 --- a/src/bench/verify_script.cpp +++ b/src/bench/verify_script.cpp @@ -2,15 +2,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#if defined(HAVE_CONFIG_H) -#include -#endif - #include #include -#if defined(HAVE_CONSENSUS_LIB) -#include