From d23bf6bb5c5a89810951978954c4495e8964bf70 Mon Sep 17 00:00:00 2001 From: rustaceanrob Date: Sat, 16 May 2026 14:32:35 +0100 Subject: [PATCH] Remove the `bitcoin-util` executable This is only used for grinding hashes and is no longer linked anywhere --- CMakeLists.txt | 3 - cmake/module/Maintenance.cmake | 3 +- contrib/completions/fish/bitcoin-util.fish | 38 ---- contrib/devtools/gen-manpages.py | 1 - doc/files.md | 1 - doc/man/bitcoin-util.1 | 5 - src/CMakeLists.txt | 12 -- src/bitcoin-util-res.rc | 33 ---- src/bitcoin-util.cpp | 196 --------------------- src/bitcoin.cpp | 2 - test/CMakeLists.txt | 1 - test/config.ini.in | 1 - 12 files changed, 1 insertion(+), 295 deletions(-) delete mode 100644 contrib/completions/fish/bitcoin-util.fish delete mode 100644 doc/man/bitcoin-util.1 delete mode 100644 src/bitcoin-util-res.rc delete mode 100644 src/bitcoin-util.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index bccd308d7dee..1315eade7aec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,7 +109,6 @@ option(BUILD_CLI "Build bitcoin-cli executable." ON) option(BUILD_TESTS "Build test_bitcoin and other unit test executables." ON) option(BUILD_TX "Build bitcoin-tx executable." ${BUILD_TESTS}) -option(BUILD_UTIL "Build bitcoin-util executable." ${BUILD_TESTS}) option(BUILD_UTIL_CHAINSTATE "Build experimental bitcoin-chainstate executable." OFF) option(BUILD_KERNEL_LIB "Build experimental bitcoinkernel library." ${BUILD_UTIL_CHAINSTATE}) @@ -185,7 +184,6 @@ if(BUILD_FOR_FUZZING) set(BUILD_DAEMON OFF) set(BUILD_CLI OFF) set(BUILD_TX OFF) - set(BUILD_UTIL OFF) set(BUILD_UTIL_CHAINSTATE OFF) set(BUILD_KERNEL_LIB OFF) set(BUILD_KERNEL_TEST OFF) @@ -593,7 +591,6 @@ message(" bitcoind ............................ ${BUILD_DAEMON}") message(" bitcoin-node (multiprocess) ......... ${BUILD_DAEMON}") message(" bitcoin-cli ......................... ${BUILD_CLI}") message(" bitcoin-tx .......................... ${BUILD_TX}") -message(" bitcoin-util ........................ ${BUILD_UTIL}") message(" bitcoin-chainstate (experimental) ... ${BUILD_UTIL_CHAINSTATE}") message(" libbitcoinkernel (experimental) ..... ${BUILD_KERNEL_LIB}") message(" kernel-test (experimental) .......... ${BUILD_KERNEL_TEST}") diff --git a/cmake/module/Maintenance.cmake b/cmake/module/Maintenance.cmake index 7570fe28f36e..ba0514005094 100644 --- a/cmake/module/Maintenance.cmake +++ b/cmake/module/Maintenance.cmake @@ -19,7 +19,7 @@ function(setup_split_debug_script) endfunction() function(add_windows_deploy_target) - if(MINGW AND TARGET bitcoin AND TARGET bitcoind AND TARGET bitcoin-cli AND TARGET bitcoin-tx AND TARGET bitcoin-util AND TARGET test_bitcoin) + if(MINGW AND TARGET bitcoin AND TARGET bitcoind AND TARGET bitcoin-cli AND TARGET bitcoin-tx AND TARGET test_bitcoin) find_program(MAKENSIS_EXECUTABLE makensis) if(NOT MAKENSIS_EXECUTABLE) add_custom_target(deploy @@ -39,7 +39,6 @@ function(add_windows_deploy_target) COMMAND ${CMAKE_STRIP} $ -o ${PROJECT_BINARY_DIR}/release/$ COMMAND ${CMAKE_STRIP} $ -o ${PROJECT_BINARY_DIR}/release/$ COMMAND ${CMAKE_STRIP} $ -o ${PROJECT_BINARY_DIR}/release/$ - COMMAND ${CMAKE_STRIP} $ -o ${PROJECT_BINARY_DIR}/release/$ COMMAND ${CMAKE_STRIP} $ -o ${PROJECT_BINARY_DIR}/release/$ COMMAND ${MAKENSIS_EXECUTABLE} -V2 ${PROJECT_BINARY_DIR}/bitcoin-win64-setup.nsi VERBATIM diff --git a/contrib/completions/fish/bitcoin-util.fish b/contrib/completions/fish/bitcoin-util.fish deleted file mode 100644 index 0650bf2cb6d3..000000000000 --- a/contrib/completions/fish/bitcoin-util.fish +++ /dev/null @@ -1,38 +0,0 @@ -# Disable files from being included in completions by default -complete --command bitcoin-util --no-files - -# Extract options -function __fish_bitcoin_util_get_options - set --local cmd (commandline -opc)[1] - set --local options - - set --append options ($cmd -help 2>&1 | string match -r '^ -.*' | string replace -r ' -' '-' | string replace -r '=.*' '=') - - for option in $options - echo $option - end -end - -# Extract commands -function __fish_bitcoin_util_get_commands - set --local cmd (commandline -opc)[1] - set --local commands - - set --append commands ($cmd -help | sed -e '1,/Commands:/d' -e 's/=/=\t/' -e 's/(=/=/' -e '/^ [a-z]/ p' -e d | string replace -r '\ \ ' '') - for command in $commands - echo $command - end -end - -# Add options -complete \ - --command bitcoin-util \ - --condition "not __fish_seen_subcommand_from (__fish_bitcoin_util_get_commands)" \ - --arguments "(__fish_bitcoin_util_get_options)" - -# Add commands -complete \ - --command bitcoin-util \ - --condition "not __fish_seen_subcommand_from (__fish_bitcoin_util_get_commands)" \ - --arguments "(__fish_bitcoin_util_get_commands)" - diff --git a/contrib/devtools/gen-manpages.py b/contrib/devtools/gen-manpages.py index b01650e71806..81c835e214a7 100755 --- a/contrib/devtools/gen-manpages.py +++ b/contrib/devtools/gen-manpages.py @@ -14,7 +14,6 @@ 'bin/bitcoind', 'bin/bitcoin-cli', 'bin/bitcoin-tx', -'bin/bitcoin-util', ] parser = argparse.ArgumentParser( diff --git a/doc/files.md b/doc/files.md index 760e2664bc47..37812d07c1b5 100644 --- a/doc/files.md +++ b/doc/files.md @@ -91,7 +91,6 @@ This table describes the files installed by Bitcoin Core across different platfo | bin/bitcoin | Command-line tool for interacting with Bitcoin. Calls other binaries below. | | bin/bitcoin-cli | Tool for making node RPC calls. | | bin/bitcoin-tx | Tool for creating and modifying transactions | -| bin/bitcoin-util | Miscellaneous utilities | | bin/bitcoind | Bitcoin node daemon | | *lib/libbitcoinkernel.so* | Shared library containing core consensus and validation code | | *lib/pkgconfig/libbitcoinkernel.pc* | Pkg-config metadata for linking to `libbitcoinkernel` | diff --git a/doc/man/bitcoin-util.1 b/doc/man/bitcoin-util.1 deleted file mode 100644 index 5c733c6e21dc..000000000000 --- a/doc/man/bitcoin-util.1 +++ /dev/null @@ -1,5 +0,0 @@ -.TH BITCOIN-UTIL "1" -.SH NAME -bitcoin-util \- manual page for bitcoin-util - -This is a placeholder file. Please follow the instructions in \fIcontrib/devtools/README.md\fR to generate the manual pages after a release. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1aeb43ad7d51..b983c8378d6b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -316,18 +316,6 @@ if(BUILD_TX) endif() -if(BUILD_UTIL) - add_executable(bitcoin-util bitcoin-util.cpp) - add_windows_resources(bitcoin-util bitcoin-util-res.rc) - add_windows_application_manifest(bitcoin-util) - target_link_libraries(bitcoin-util - core_interface - bitcoin_common - bitcoin_util - ) - install_binary_component(bitcoin-util HAS_MANPAGE) -endif() - if(BUILD_KERNEL_LIB) add_subdirectory(kernel) diff --git a/src/bitcoin-util-res.rc b/src/bitcoin-util-res.rc deleted file mode 100644 index 8dda22b77f06..000000000000 --- a/src/bitcoin-util-res.rc +++ /dev/null @@ -1,33 +0,0 @@ -#include // needed for VERSIONINFO -#include "clientversion.h" // holds the needed client version information - -#define VER_PRODUCTVERSION CLIENT_VERSION_MAJOR,CLIENT_VERSION_MINOR,CLIENT_VERSION_BUILD -#define VER_FILEVERSION VER_PRODUCTVERSION - -VS_VERSION_INFO VERSIONINFO -FILEVERSION VER_FILEVERSION -PRODUCTVERSION VER_PRODUCTVERSION -FILEOS VOS_NT_WINDOWS32 -FILETYPE VFT_APP -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904E4" // U.S. English - multilingual (hex) - BEGIN - VALUE "CompanyName", CLIENT_NAME " project" - VALUE "FileDescription", "bitcoin-util (CLI Bitcoin utility)" - VALUE "FileVersion", CLIENT_VERSION_STRING - VALUE "InternalName", "bitcoin-util" - VALUE "LegalCopyright", COPYRIGHT_STR - VALUE "LegalTrademarks1", "Distributed under the MIT software license, see the accompanying file COPYING or http://www.opensource.org/licenses/mit-license.php." - VALUE "OriginalFilename", "bitcoin-util.exe" - VALUE "ProductName", "bitcoin-util" - VALUE "ProductVersion", CLIENT_VERSION_STRING - END - END - - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x0, 1252 // language neutral - multilingual (decimal) - END -END diff --git a/src/bitcoin-util.cpp b/src/bitcoin-util.cpp deleted file mode 100644 index aa3fd3066792..000000000000 --- a/src/bitcoin-util.cpp +++ /dev/null @@ -1,196 +0,0 @@ -// Copyright (c) 2009-present The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include // IWYU pragma: keep - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -static const int CONTINUE_EXECUTION=-1; - -const TranslateFn G_TRANSLATION_FUN{nullptr}; - -static void SetupBitcoinUtilArgs(ArgsManager &argsman) -{ - SetupHelpOptions(argsman); - - argsman.AddArg("-version", "Print version and exit", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); - - argsman.AddCommand("grind", "Perform proof of work on hex header string"); - - SetupChainParamsBaseOptions(argsman); -} - -// This function returns either one of EXIT_ codes when it's expected to stop the process or -// CONTINUE_EXECUTION when it's expected to continue further. -static int AppInitUtil(ArgsManager& args, int argc, char* argv[]) -{ - SetupBitcoinUtilArgs(args); - std::string error; - if (!args.ParseParameters(argc, argv, error)) { - tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error); - return EXIT_FAILURE; - } - - if (HelpRequested(args) || args.GetBoolArg("-version", false)) { - // First part of help message is specific to this utility - std::string strUsage = CLIENT_NAME " bitcoin-util utility version " + FormatFullVersion() + "\n"; - - if (args.GetBoolArg("-version", false)) { - strUsage += FormatParagraph(LicenseInfo()); - } else { - strUsage += "\n" - "The bitcoin-util tool provides bitcoin related functionality that does not rely on the ability to access a running node. Available [commands] are listed below.\n" - "\n" - "Usage: bitcoin-util [options] [command]\n" - "or: bitcoin-util [options] grind \n"; - strUsage += "\n" + args.GetHelpMessage(); - } - - tfm::format(std::cout, "%s", strUsage); - - if (argc < 2) { - tfm::format(std::cerr, "Error: too few parameters\n"); - return EXIT_FAILURE; - } - return EXIT_SUCCESS; - } - - // Check for chain settings (Params() calls are only valid after this clause) - try { - SelectParams(args.GetChainType()); - } catch (const std::exception& e) { - tfm::format(std::cerr, "Error: %s\n", e.what()); - return EXIT_FAILURE; - } - - return CONTINUE_EXECUTION; -} - -static void grind_task(uint32_t nBits, CBlockHeader header, uint32_t offset, uint32_t step, std::atomic& found, uint32_t& proposed_nonce) -{ - arith_uint256 target; - bool neg, over; - target.SetCompact(nBits, &neg, &over); - if (target == 0 || neg || over) return; - header.nNonce = offset; - - uint32_t finish = std::numeric_limits::max() - step; - finish = finish - (finish % step) + offset; - - while (!found && header.nNonce < finish) { - const uint32_t next = (finish - header.nNonce < 5000*step) ? finish : header.nNonce + 5000*step; - do { - if (UintToArith256(header.GetHash()) <= target) { - if (!found.exchange(true)) { - proposed_nonce = header.nNonce; - } - return; - } - header.nNonce += step; - } while(header.nNonce != next); - } -} - -static int Grind(const std::vector& args, std::string& strPrint) -{ - if (args.size() != 1) { - strPrint = "Must specify block header to grind"; - return EXIT_FAILURE; - } - - CBlockHeader header; - if (!DecodeHexBlockHeader(header, args[0])) { - strPrint = "Could not decode block header"; - return EXIT_FAILURE; - } - - uint32_t nBits = header.nBits; - std::atomic found{false}; - uint32_t proposed_nonce{}; - - std::vector threads; - int n_tasks = std::max(1u, std::thread::hardware_concurrency()); - threads.reserve(n_tasks); - for (int i = 0; i < n_tasks; ++i) { - threads.emplace_back(grind_task, nBits, header, i, n_tasks, std::ref(found), std::ref(proposed_nonce)); - } - for (auto& t : threads) { - t.join(); - } - if (found) { - header.nNonce = proposed_nonce; - } else { - strPrint = "Could not satisfy difficulty target"; - return EXIT_FAILURE; - } - - DataStream ss{}; - ss << header; - strPrint = HexStr(ss); - return EXIT_SUCCESS; -} - -MAIN_FUNCTION -{ - ArgsManager& args = gArgs; - SetupEnvironment(); - - try { - int ret = AppInitUtil(args, argc, argv); - if (ret != CONTINUE_EXECUTION) { - return ret; - } - } catch (const std::exception& e) { - PrintExceptionContinue(&e, "AppInitUtil()"); - return EXIT_FAILURE; - } catch (...) { - PrintExceptionContinue(nullptr, "AppInitUtil()"); - return EXIT_FAILURE; - } - - const auto cmd = args.GetCommand(); - if (!cmd) { - tfm::format(std::cerr, "Error: must specify a command\n"); - return EXIT_FAILURE; - } - - int ret = EXIT_FAILURE; - std::string strPrint; - try { - if (cmd->command == "grind") { - ret = Grind(cmd->args, strPrint); - } else { - assert(false); // unknown command should be caught earlier - } - } catch (const std::exception& e) { - strPrint = std::string("error: ") + e.what(); - } catch (...) { - strPrint = "unknown error"; - } - - if (strPrint != "") { - tfm::format(ret == 0 ? std::cout : std::cerr, "%s\n", strPrint); - } - - return ret; -} diff --git a/src/bitcoin.cpp b/src/bitcoin.cpp index 0bb79a791294..08ccd10a0347 100644 --- a/src/bitcoin.cpp +++ b/src/bitcoin.cpp @@ -98,8 +98,6 @@ int main(int argc, char* argv[]) args.emplace_back("bitcoin-chainstate"); } else if (cmd.command == "test") { args.emplace_back("test_bitcoin"); - } else if (cmd.command == "util") { - args.emplace_back("bitcoin-util"); } else { throw std::runtime_error(strprintf("Unrecognized command: '%s'", cmd.command)); } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4473dc6ae8cd..6580b7cdd56e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -18,7 +18,6 @@ function(create_test_config) set_configure_variable(BUILD_BENCH BUILD_BENCH) set_configure_variable(BUILD_CLI BUILD_BITCOIN_CLI) set_configure_variable(BUILD_TX BUILD_BITCOIN_TX) - set_configure_variable(BUILD_UTIL BUILD_BITCOIN_UTIL) set_configure_variable(BUILD_UTIL_CHAINSTATE BUILD_BITCOIN_CHAINSTATE) set_configure_variable(BUILD_DAEMON BUILD_BITCOIND) set_configure_variable(BUILD_FUZZ_BINARY ENABLE_FUZZ_BINARY) diff --git a/test/config.ini.in b/test/config.ini.in index 7f1e2f677a0a..48c06542deeb 100644 --- a/test/config.ini.in +++ b/test/config.ini.in @@ -18,7 +18,6 @@ RPCAUTH=@abs_top_srcdir@/share/rpcauth/rpcauth.py @BUILD_BENCH_TRUE@BUILD_BENCH=true @BUILD_BITCOIN_CLI_TRUE@ENABLE_CLI=true @BUILD_BITCOIN_TX_TRUE@BUILD_BITCOIN_TX=true -@BUILD_BITCOIN_UTIL_TRUE@ENABLE_BITCOIN_UTIL=true @BUILD_BITCOIN_CHAINSTATE_TRUE@ENABLE_BITCOIN_CHAINSTATE=true @BUILD_BITCOIND_TRUE@ENABLE_BITCOIND=true @ENABLE_FUZZ_BINARY_TRUE@ENABLE_FUZZ_BINARY=true