mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
Merge fae300f159
into c5e44a0435
This commit is contained in:
commit
bd666bfa1e
12 changed files with 234 additions and 10 deletions
|
@ -675,6 +675,7 @@ message(" bitcoin-util ........................ ${BUILD_UTIL}")
|
|||
message(" bitcoin-wallet ...................... ${BUILD_WALLET_TOOL}")
|
||||
message(" bitcoin-chainstate (experimental) ... ${BUILD_UTIL_CHAINSTATE}")
|
||||
message(" libbitcoinkernel (experimental) ..... ${BUILD_KERNEL_LIB}")
|
||||
message(" bitcoin-mine (experimental) ......... ${bitcoin_daemon_status}")
|
||||
message("Optional features:")
|
||||
message(" wallet support ...................... ${ENABLE_WALLET}")
|
||||
if(ENABLE_WALLET)
|
||||
|
|
|
@ -44,12 +44,6 @@ declare -A SUPPRESS
|
|||
# init.cpp file currently calls Berkeley DB sanity check function on startup, so
|
||||
# there is an undocumented dependency of the node library on the wallet library.
|
||||
SUPPRESS["init.cpp.o bdb.cpp.o _ZN6wallet27BerkeleyDatabaseSanityCheckEv"]=1
|
||||
# init/common.cpp file calls InitError and InitWarning from interface_ui which
|
||||
# is currently part of the node library. interface_ui should just be part of the
|
||||
# common library instead, and is moved in
|
||||
# https://github.com/bitcoin/bitcoin/issues/10102
|
||||
SUPPRESS["common.cpp.o interface_ui.cpp.o _Z11InitWarningRK13bilingual_str"]=1
|
||||
SUPPRESS["common.cpp.o interface_ui.cpp.o _Z9InitErrorRK13bilingual_str"]=1
|
||||
|
||||
usage() {
|
||||
echo "Usage: $(basename "${BASH_SOURCE[0]}") [BUILD_DIR]"
|
||||
|
|
|
@ -11,6 +11,7 @@ import argparse
|
|||
BINARIES = [
|
||||
'bin/bitcoind',
|
||||
'bin/bitcoin-cli',
|
||||
'bin/bitcoin-mine',
|
||||
'bin/bitcoin-tx',
|
||||
'bin/bitcoin-wallet',
|
||||
'bin/bitcoin-util',
|
||||
|
|
|
@ -165,6 +165,7 @@ add_library(bitcoin_common STATIC EXCLUDE_FROM_ALL
|
|||
net_types.cpp
|
||||
netaddress.cpp
|
||||
netbase.cpp
|
||||
node/interface_ui.cpp
|
||||
outputtype.cpp
|
||||
policy/feerate.cpp
|
||||
policy/policy.cpp
|
||||
|
@ -262,7 +263,6 @@ add_library(bitcoin_node STATIC EXCLUDE_FROM_ALL
|
|||
node/context.cpp
|
||||
node/database_args.cpp
|
||||
node/eviction.cpp
|
||||
node/interface_ui.cpp
|
||||
node/interfaces.cpp
|
||||
node/kernel_notifications.cpp
|
||||
node/mempool_args.cpp
|
||||
|
@ -358,6 +358,17 @@ if(ENABLE_IPC AND BUILD_DAEMON)
|
|||
$<TARGET_NAME_IF_EXISTS:bitcoin_wallet>
|
||||
)
|
||||
install_binary_component(bitcoin-node)
|
||||
|
||||
add_executable(bitcoin-mine
|
||||
bitcoin-mine.cpp
|
||||
init/bitcoin-mine.cpp
|
||||
)
|
||||
target_link_libraries(bitcoin-mine
|
||||
core_interface
|
||||
bitcoin_common
|
||||
bitcoin_ipc
|
||||
)
|
||||
install_binary_component(bitcoin-mine)
|
||||
endif()
|
||||
|
||||
if(ENABLE_IPC AND BUILD_TESTS)
|
||||
|
|
124
src/bitcoin-mine.cpp
Normal file
124
src/bitcoin-mine.cpp
Normal file
|
@ -0,0 +1,124 @@
|
|||
// Copyright (c) 2025 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 <bitcoin-build-config.h> // IWYU pragma: keep
|
||||
|
||||
#include <chainparams.h>
|
||||
#include <chainparamsbase.h>
|
||||
#include <clientversion.h>
|
||||
#include <common/args.h>
|
||||
#include <common/system.h>
|
||||
#include <compat/compat.h>
|
||||
#include <init/common.h>
|
||||
#include <interfaces/init.h>
|
||||
#include <interfaces/ipc.h>
|
||||
#include <logging.h>
|
||||
#include <tinyformat.h>
|
||||
#include <util/translation.h>
|
||||
|
||||
static const char* const HELP_USAGE{R"(
|
||||
bitcoin-mine is a test program for interacting with bitcoin-node via IPC.
|
||||
|
||||
Usage:
|
||||
bitcoin-mine [options]
|
||||
)"};
|
||||
|
||||
static const char* HELP_EXAMPLES{R"(
|
||||
Examples:
|
||||
# Start separate bitcoin-node that bitcoin-mine can connect to.
|
||||
bitcoin-node -regtest -ipcbind=unix
|
||||
|
||||
# Connect to bitcoin-node and print tip block hash.
|
||||
bitcoin-mine -regtest
|
||||
|
||||
# Run with debug output.
|
||||
bitcoin-mine -regtest -debug
|
||||
)"};
|
||||
|
||||
const TranslateFn G_TRANSLATION_FUN{nullptr};
|
||||
|
||||
static void AddArgs(ArgsManager& args)
|
||||
{
|
||||
SetupHelpOptions(args);
|
||||
SetupChainParamsBaseOptions(args);
|
||||
args.AddArg("-version", "Print version and exit", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||
args.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||
args.AddArg("-ipcconnect=<address>", "Connect to bitcoin-node process in the background to perform online operations. Valid <address> values are 'unix' to connect to the default socket, 'unix:<socket path>' to connect to a socket at a nonstandard path. Default value: unix", ArgsManager::ALLOW_ANY, OptionsCategory::IPC);
|
||||
init::AddLoggingArgs(args);
|
||||
}
|
||||
|
||||
MAIN_FUNCTION
|
||||
{
|
||||
ArgsManager& args = gArgs;
|
||||
AddArgs(args);
|
||||
std::string error_message;
|
||||
if (!args.ParseParameters(argc, argv, error_message)) {
|
||||
tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error_message);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (!args.ReadConfigFiles(error_message, true)) {
|
||||
tfm::format(std::cerr, "Error reading config files: %s\n", error_message);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (HelpRequested(args) || args.IsArgSet("-version")) {
|
||||
std::string output{strprintf("%s bitcoin-mine version", CLIENT_NAME) + " " + FormatFullVersion() + "\n"};
|
||||
if (args.IsArgSet("-version")) {
|
||||
output += FormatParagraph(LicenseInfo());
|
||||
} else {
|
||||
output += HELP_USAGE;
|
||||
output += args.GetHelpMessage();
|
||||
output += HELP_EXAMPLES;
|
||||
}
|
||||
tfm::format(std::cout, "%s", output);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if (!CheckDataDirOption(args)) {
|
||||
tfm::format(std::cerr, "Error: Specified data directory \"%s\" does not exist.\n", args.GetArg("-datadir", ""));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
SelectParams(args.GetChainType());
|
||||
|
||||
// Set logging options but override -printtoconsole default to depend on -debug rather than -daemon
|
||||
init::SetLoggingOptions(args);
|
||||
if (auto result{init::SetLoggingCategories(args)}; !result) {
|
||||
tfm::format(std::cerr, "Error: %s\n", util::ErrorString(result).original);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (auto result{init::SetLoggingLevel(args)}; !result) {
|
||||
tfm::format(std::cerr, "Error: %s\n", util::ErrorString(result).original);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
LogInstance().m_print_to_console = args.GetBoolArg("-printtoconsole", LogInstance().GetCategoryMask());
|
||||
if (!init::StartLogging(args)) {
|
||||
tfm::format(std::cerr, "Error: StartLogging failed\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Connect to existing bitcoin-node process or spawn new one.
|
||||
std::unique_ptr<interfaces::Init> mine_init{interfaces::MakeMineInit(argc, argv)};
|
||||
assert(mine_init);
|
||||
std::unique_ptr<interfaces::Init> node_init;
|
||||
try {
|
||||
std::string address{args.GetArg("-ipcconnect", "unix")};
|
||||
node_init = mine_init->ipc()->connectAddress(address);
|
||||
} catch (const std::exception& exception) {
|
||||
tfm::format(std::cerr, "Error: %s\n", exception.what());
|
||||
tfm::format(std::cerr, "Probably bitcoin-node is not running or not listening on a unix socket. Can be started with:\n\n");
|
||||
tfm::format(std::cerr, " bitcoin-node -chain=%s -ipcbind=unix\n", args.GetChainTypeString());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
assert(node_init);
|
||||
tfm::format(std::cout, "Connected to bitcoin-node\n");
|
||||
std::unique_ptr<interfaces::Mining> mining{node_init->makeMining()};
|
||||
assert(mining);
|
||||
|
||||
auto tip{mining->getTip()};
|
||||
if (tip) {
|
||||
tfm::format(std::cout, "Tip hash is %s.\n", tip->hash.ToString());
|
||||
} else {
|
||||
tfm::format(std::cout, "Tip hash is null.\n");
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
29
src/init/bitcoin-mine.cpp
Normal file
29
src/init/bitcoin-mine.cpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
// Copyright (c) 2025 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 <interfaces/init.h>
|
||||
#include <interfaces/ipc.h>
|
||||
|
||||
namespace init {
|
||||
namespace {
|
||||
const char* EXE_NAME = "bitcoin-mine";
|
||||
|
||||
class BitcoinMineInit : public interfaces::Init
|
||||
{
|
||||
public:
|
||||
BitcoinMineInit(const char* arg0) : m_ipc(interfaces::MakeIpc(EXE_NAME, arg0, *this))
|
||||
{
|
||||
}
|
||||
interfaces::Ipc* ipc() override { return m_ipc.get(); }
|
||||
std::unique_ptr<interfaces::Ipc> m_ipc;
|
||||
};
|
||||
} // namespace
|
||||
} // namespace init
|
||||
|
||||
namespace interfaces {
|
||||
std::unique_ptr<Init> MakeMineInit(int argc, char* argv[])
|
||||
{
|
||||
return std::make_unique<init::BitcoinMineInit>(argc > 0 ? argv[0] : "");
|
||||
}
|
||||
} // namespace interfaces
|
|
@ -53,6 +53,9 @@ std::unique_ptr<Init> MakeWalletInit(int argc, char* argv[], int& exit_status);
|
|||
|
||||
//! Return implementation of Init interface for the gui process.
|
||||
std::unique_ptr<Init> MakeGuiInit(int argc, char* argv[]);
|
||||
|
||||
//! Return implementation of Init interface for the bitcoin-mine process.
|
||||
std::unique_ptr<Init> MakeMineInit(int argc, char* argv[]);
|
||||
} // namespace interfaces
|
||||
|
||||
#endif // BITCOIN_INTERFACES_INIT_H
|
||||
|
|
|
@ -26,6 +26,7 @@ function(create_test_config)
|
|||
set_configure_variable(WITH_ZMQ ENABLE_ZMQ)
|
||||
set_configure_variable(ENABLE_EXTERNAL_SIGNER ENABLE_EXTERNAL_SIGNER)
|
||||
set_configure_variable(WITH_USDT ENABLE_USDT_TRACEPOINTS)
|
||||
set_configure_variable(WITH_MULTIPROCESS WITH_MULTIPROCESS)
|
||||
|
||||
configure_file(config.ini.in config.ini USE_SOURCE_PERMISSIONS @ONLY)
|
||||
endfunction()
|
||||
|
|
|
@ -26,3 +26,4 @@ RPCAUTH=@abs_top_srcdir@/share/rpcauth/rpcauth.py
|
|||
@ENABLE_ZMQ_TRUE@ENABLE_ZMQ=true
|
||||
@ENABLE_EXTERNAL_SIGNER_TRUE@ENABLE_EXTERNAL_SIGNER=true
|
||||
@ENABLE_USDT_TRACEPOINTS_TRUE@ENABLE_USDT_TRACEPOINTS=true
|
||||
@WITH_MULTIPROCESS_TRUE@WITH_MULTIPROCESS=true
|
||||
|
|
46
test/functional/interface_ipc_mining.py
Executable file
46
test/functional/interface_ipc_mining.py
Executable file
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2025 The Bitcoin Core developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
"""Test bitcoin-mine"""
|
||||
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import (
|
||||
assert_equal,
|
||||
)
|
||||
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
class TestBitcoinMine(BitcoinTestFramework):
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 1
|
||||
|
||||
def skip_test_if_missing_module(self):
|
||||
self.skip_if_no_multiprocess()
|
||||
|
||||
def setup_nodes(self):
|
||||
# Always run multiprocess binaries
|
||||
self.binary_paths.bitcoind = self.binary_paths.bitcoin_node
|
||||
|
||||
# Work around default CI path exceeding maximum socket path length.
|
||||
# On Linux sun_path is 108 bytes, on macOS it's only 104. Includes
|
||||
# null terminator.
|
||||
socket_path = self.options.tmpdir + "/node0/regtest/node.sock"
|
||||
if len(socket_path.encode('utf-8')) < 104:
|
||||
self.extra_args = [["-ipcbind=unix"]]
|
||||
self.mine_args = []
|
||||
else:
|
||||
sock_path = tempfile.mktemp()
|
||||
self.extra_args = [[f"-ipcbind=unix:{sock_path}"]]
|
||||
self.mine_args = [f"-ipcconnect=unix:{sock_path}"]
|
||||
super().setup_nodes()
|
||||
|
||||
def run_test(self):
|
||||
args = [self.binary_paths.bitcoin_mine, f"-datadir={self.nodes[0].datadir_path}"] + self.mine_args
|
||||
result = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, check=True)
|
||||
assert_equal(result.stdout, "Connected to bitcoin-node\nTip hash is 0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206.\n")
|
||||
|
||||
if __name__ == '__main__':
|
||||
TestBitcoinMine(__file__).main()
|
|
@ -285,13 +285,16 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
|
|||
"bitcoin-chainstate": ("bitcoinchainstate", "BITCOINCHAINSTATE"),
|
||||
"bitcoin-wallet": ("bitcoinwallet", "BITCOINWALLET"),
|
||||
}
|
||||
for binary, [attribute_name, env_variable_name] in binaries.items():
|
||||
default_filename = os.path.join(
|
||||
def binary_path(binary):
|
||||
return os.path.join(
|
||||
self.config["environment"]["BUILDDIR"],
|
||||
"bin",
|
||||
binary + self.config["environment"]["EXEEXT"],
|
||||
)
|
||||
setattr(paths, attribute_name, os.getenv(env_variable_name, default=default_filename))
|
||||
for binary, [attribute_name, env_variable_name] in binaries.items():
|
||||
setattr(paths, attribute_name, os.getenv(env_variable_name) or binary_path(binary))
|
||||
paths.bitcoin_mine = binary_path("bitcoin-mine")
|
||||
paths.bitcoin_node = binary_path("bitcoin-node")
|
||||
return paths
|
||||
|
||||
def get_binaries(self, bin_dir=None):
|
||||
|
@ -1007,6 +1010,11 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
|
|||
if not self.is_cli_compiled():
|
||||
raise SkipTest("bitcoin-cli has not been compiled.")
|
||||
|
||||
def skip_if_no_multiprocess(self):
|
||||
"""Skip the running test if multiprocess binaries are not compiled."""
|
||||
if not self.is_multiprocess_compiled():
|
||||
raise SkipTest("multiprocess binaries have not been compiled.")
|
||||
|
||||
def skip_if_no_previous_releases(self):
|
||||
"""Skip the running test if previous releases are not available."""
|
||||
if not self.has_previous_releases():
|
||||
|
@ -1061,5 +1069,9 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
|
|||
"""Checks whether the wallet module was compiled with BDB support."""
|
||||
return self.config["components"].getboolean("USE_BDB")
|
||||
|
||||
def is_multiprocess_compiled(self):
|
||||
"""Checks whether multiprocess binaries are compiled."""
|
||||
return self.config["components"].getboolean("WITH_MULTIPROCESS")
|
||||
|
||||
def has_blockfile(self, node, filenum: str):
|
||||
return (node.blocks_path/ f"blk{filenum}.dat").is_file()
|
||||
|
|
|
@ -355,6 +355,7 @@ BASE_SCRIPTS = [
|
|||
'rpc_help.py',
|
||||
'p2p_handshake.py',
|
||||
'p2p_handshake.py --v2transport',
|
||||
'interface_ipc_mining.py',
|
||||
'feature_dirsymlinks.py',
|
||||
'feature_help.py',
|
||||
'feature_shutdown.py',
|
||||
|
|
Loading…
Add table
Reference in a new issue