Skip to content

Commit

Permalink
Merge branch 'auxpow'
Browse files Browse the repository at this point in the history
  • Loading branch information
domob1812 committed Sep 30, 2024
2 parents 1b283f6 + 92a2e17 commit 3c9c99e
Show file tree
Hide file tree
Showing 58 changed files with 649 additions and 278 deletions.
15 changes: 7 additions & 8 deletions .cirrus.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
env: # Global defaults
CIRRUS_CLONE_DEPTH: 1
PACKAGE_MANAGER_INSTALL: "apt-get update && apt-get install -y"
CIRRUS_LOG_TIMESTAMP: true
MAKEJOBS: "-j10"
TEST_RUNNER_PORT_MIN: "14000" # Must be larger than 12321, which is used for the http cache. See https://cirrus-ci.org/guide/writing-tasks/#http-cache
CI_FAILFAST_TEST_LEAVE_DANGLING: "1" # Cirrus CI does not care about dangling processes and setting this variable avoids killing the CI script itself on error
Expand All @@ -13,9 +13,9 @@ env: # Global defaults
# Generally, a persistent worker must run Ubuntu 23.04+ or Debian 12+.
#
# The following specific types should exist, with the following requirements:
# - small: For an x86_64 machine, recommended to have 2 CPUs and 8 GB of memory.
# - medium: For an x86_64 machine, recommended to have 4 CPUs and 16 GB of memory.
# - arm64: For an aarch64 machine, recommended to have 2 CPUs and 8 GB of memory.
# - small: For an x86_64 machine, with at least 2 vCPUs and 8 GB of memory.
# - medium: For an x86_64 machine, with at least 4 vCPUs and 16 GB of memory.
# - arm64: For an aarch64 machine, with at least 2 vCPUs and 8 GB of memory.
#
# CI jobs for the latter configuration can be run on x86_64 hardware
# by installing qemu-user-static, which works out of the box with
Expand All @@ -36,14 +36,13 @@ env: # Global defaults
# This requires installing Podman instead of Docker.
#
# Futhermore:
# - apt-get is required due to PACKAGE_MANAGER_INSTALL
# - podman-docker-4.1+ is required due to the bugfix in 4.1
# (https://github.com/bitcoin/bitcoin/pull/21652#issuecomment-1657098200)
# - The ./ci/ dependencies (with cirrus-cli) should be installed. One-liner example
# for a single user setup with sudo permission:
#
# ```
# apt update && apt install git screen python3 bash podman-docker curl -y && curl -L -o cirrus "https://github.com/cirruslabs/cirrus-cli/releases/latest/download/cirrus-linux-$(dpkg --print-architecture)" && mv cirrus /usr/local/bin/cirrus && chmod +x /usr/local/bin/cirrus
# apt update && apt install git screen python3 bash podman-docker uidmap slirp4netns curl -y && curl -L -o cirrus "https://github.com/cirruslabs/cirrus-cli/releases/latest/download/cirrus-linux-$(dpkg --print-architecture)" && mv cirrus /usr/local/bin/cirrus && chmod +x /usr/local/bin/cirrus
# ```
#
# - There are no strict requirements on the hardware. Having fewer CPU threads
Expand Down Expand Up @@ -72,8 +71,8 @@ filter_template: &FILTER_TEMPLATE
base_template: &BASE_TEMPLATE
<< : *FILTER_TEMPLATE
merge_base_script:
# Unconditionally install git (used in fingerprint_script).
- git --version || bash -c "$PACKAGE_MANAGER_INSTALL git"
# Require git (used in fingerprint_script).
- git --version || ( apt-get update && apt-get install -y git )
- if [ "$CIRRUS_PR" = "" ]; then exit 0; fi
- git fetch --depth=1 $CIRRUS_REPO_CLONE_URL "pull/${CIRRUS_PR}/merge"
- git checkout FETCH_HEAD # Use merged changes to detect silent merge conflicts
Expand Down
1 change: 1 addition & 0 deletions ci/test/00_setup_env_native_fuzz_with_valgrind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ export BITCOIN_CONFIG="\
-DCMAKE_C_COMPILER=clang-16 \
-DCMAKE_CXX_COMPILER=clang++-16 \
"
export LLVM_SYMBOLIZER_PATH="/usr/bin/llvm-symbolizer-16"
2 changes: 1 addition & 1 deletion depends/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ The following can be set when running make: `make FOO=bar`
- `NO_UPNP`: Don't download/build/cache packages needed for enabling UPnP
- `NO_NATPMP`: Don't download/build/cache packages needed for enabling NAT-PMP
- `NO_USDT`: Don't download/build/cache packages needed for enabling USDT tracepoints
- `MULTIPROCESS`: Build libmultiprocess (experimental, requires CMake)
- `MULTIPROCESS`: Build libmultiprocess (experimental)
- `DEBUG`: Disable some optimizations and enable more runtime checking
- `HOST_ID_SALT`: Optional salt to use when generating host package ids
- `BUILD_ID_SALT`: Optional salt to use when generating build package ids
Expand Down
1 change: 1 addition & 0 deletions depends/packages/capnp.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ define $(package)_set_vars :=
$(package)_config_opts := -DBUILD_TESTING=OFF
$(package)_config_opts += -DWITH_OPENSSL=OFF
$(package)_config_opts += -DWITH_ZLIB=OFF
$(package)_cxxflags += -ffile-prefix-map=$$($(package)_extract_dir)=/usr
endef

define $(package)_config_cmds
Expand Down
1 change: 1 addition & 0 deletions depends/packages/libmultiprocess.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ifneq ($(host),$(build))
$(package)_config_opts := -DCAPNP_EXECUTABLE="$$(native_capnp_prefixbin)/capnp"
$(package)_config_opts += -DCAPNPC_CXX_EXECUTABLE="$$(native_capnp_prefixbin)/capnpc-c++"
endif
$(package)_cxxflags += -ffile-prefix-map=$$($(package)_extract_dir)=/usr
endef

define $(package)_config_cmds
Expand Down
4 changes: 2 additions & 2 deletions depends/packages/native_libmultiprocess.mk
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package=native_libmultiprocess
$(package)_version=c1b4ab4eb897d3af09bc9b3cc30e2e6fff87f3e2
$(package)_version=015e95f7ebaa47619a213a19801e7fffafc56864
$(package)_download_path=https://github.com/chaincodelabs/libmultiprocess/archive
$(package)_file_name=$($(package)_version).tar.gz
$(package)_sha256_hash=6edf5ad239ca9963c78f7878486fb41411efc9927c6073928a7d6edf947cac4a
$(package)_sha256_hash=4b1266b121337f3f6f37e1863fba91c1a5ee9ad126bcffc6fe6b9ca47ad050a1
$(package)_dependencies=native_capnp

define $(package)_config_cmds
Expand Down
3 changes: 2 additions & 1 deletion depends/toolchain.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ endif()

if("@multiprocess@" STREQUAL "1")
set(WITH_MULTIPROCESS ON CACHE BOOL "")
set(LibmultiprocessNative_DIR "${CMAKE_FIND_ROOT_PATH}/native/lib/cmake/Libmultiprocess" CACHE PATH "")
set(Libmultiprocess_ROOT "${CMAKE_CURRENT_LIST_DIR}" CACHE PATH "")
set(LibmultiprocessNative_ROOT "${CMAKE_CURRENT_LIST_DIR}/native" CACHE PATH "")
else()
set(WITH_MULTIPROCESS OFF CACHE BOOL "")
endif()
8 changes: 4 additions & 4 deletions doc/design/multiprocess.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ This section describes the major components of the Inter-Process Communication (
- In the generated code, we have C++ client subclasses that inherit from the abstract classes in [`src/interfaces/`](../../src/interfaces/). These subclasses are the workhorses of the IPC mechanism.
- They implement all the methods of the interface, marshalling arguments into a structured format, sending them as requests to the IPC server via a UNIX socket, and handling the responses.
- These subclasses effectively mask the complexity of IPC, presenting a familiar C++ interface to developers.
- Internally, the client subclasses generated by the `mpgen` tool wrap [client classes generated by Cap'n Proto](https://capnproto.org/cxxrpc.html#clients), and use them to send IPC requests.
- Internally, the client subclasses generated by the `mpgen` tool wrap [client classes generated by Cap'n Proto](https://capnproto.org/cxxrpc.html#clients), and use them to send IPC requests. The Cap'n Proto client classes are low-level, with non-blocking methods that use asynchronous I/O and pass request and response objects, while mpgen client subclasses provide normal C++ methods that block while executing and convert between request/response objects and arguments/return values.

### C++ Server Classes in Generated Code
- On the server side, corresponding generated C++ classes receive IPC requests. These server classes are responsible for unmarshalling method arguments, invoking the corresponding methods in the local [`src/interfaces/`](../../src/interfaces/) objects, and creating the IPC response.
Expand All @@ -94,7 +94,7 @@ This section describes the major components of the Inter-Process Communication (
- **Asynchronous I/O and Thread Management**: The library is also responsible for managing I/O and threading. Particularly, it ensures that IPC requests never block each other and that new threads on either side of a connection can always make client calls. It also manages worker threads on the server side of calls, ensuring that calls from the same client thread always execute on the same server thread (to avoid locking issues and support nested callbacks).

### Type Hooks in [`src/ipc/capnp/*-types.h`](../../src/ipc/capnp/)
- **Custom Type Conversions**: In [`src/ipc/capnp/*-types.h`](../../src/ipc/capnp/), function overloads of two `libmultiprocess` C++ functions, `mp::CustomReadField` and `mp::CustomBuildFields`, are defined. These overloads are used for customizing the conversion of specific C++ types to and from Cap’n Proto types.
- **Custom Type Conversions**: In [`src/ipc/capnp/*-types.h`](../../src/ipc/capnp/), function overloads of `libmultiprocess` C++ functions, `mp::CustomReadField`, `mp::CustomBuildField`, `mp::CustomReadMessage` and `mp::CustomBuildMessage`, are defined. These overloads are used for customizing the conversion of specific C++ types to and from Cap’n Proto types.
- **Handling Special Cases**: The `mpgen` tool and `libmultiprocess` library can convert most C++ types to and from Cap’n Proto types automatically, including interface types, primitive C++ types, standard C++ types like `std::vector`, `std::set`, `std::map`, `std::tuple`, and `std::function`, as well as simple C++ structs that consist of aforementioned types and whose fields correspond 1:1 with Cap’n Proto struct fields. For other types, `*-types.h` files provide custom code to convert between C++ and Cap’n Proto data representations.

### Protocol-Agnostic IPC Code in [`src/ipc/`](../../src/ipc/)
Expand Down Expand Up @@ -197,7 +197,7 @@ sequenceDiagram
- Upon receiving the request, the Cap'n Proto dispatching code in the `bitcoin-node` process calls the `getBlockHash` method of the `Chain` [server class](#c-server-classes-in-generated-code).
- The server class is automatically generated by the `mpgen` tool from the [`chain.capnp`](https://github.com/ryanofsky/bitcoin/blob/pr/ipc/src/ipc/capnp/chain.capnp) file in [`src/ipc/capnp/`](../../src/ipc/capnp/).
- The `getBlockHash` method of the generated `Chain` server subclass in `bitcoin-wallet` receives a Cap’n Proto request object with the `height` parameter, and calls the `getBlockHash` method on its local `Chain` object with the provided `height`.
- When the call returns, it encapsulates the return value in a Cap’n Proto response, which it sends back to the `bitcoin-wallet` process,
- When the call returns, it encapsulates the return value in a Cap’n Proto response, which it sends back to the `bitcoin-wallet` process.

5. **Response and Return**
- The `getBlockHash` method of the generated `Chain` client subclass in `bitcoin-wallet` which sent the request now receives the response.
Expand Down Expand Up @@ -232,7 +232,7 @@ This modularization represents an advancement in Bitcoin Core's architecture, of

- **Cap’n Proto struct**: A structured data format used in Cap’n Proto, similar to structs in C++, for organizing and transporting data across different processes.

- **client class (in generated code)**: A C++ class generated from a Cap’n Proto interface which inherits from a Bitcoin core abstract class, and implements each virtual method to send IPC requests to another process. (see also [components section](#c-client-subclasses-in-generated-code))
- **client class (in generated code)**: A C++ class generated from a Cap’n Proto interface which inherits from a Bitcoin Core abstract class, and implements each virtual method to send IPC requests to another process. (see also [components section](#c-client-subclasses-in-generated-code))

- **IPC (inter-process communication)**: Mechanisms that enable processes to exchange requests and data.

Expand Down
12 changes: 5 additions & 7 deletions doc/fuzzing.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,11 @@ $ ./honggfuzz/honggfuzz --exit_upon_crash --quiet --timeout 4 -n 1 -Q \
# OSS-Fuzz
Bitcoin Core participates in Google's [OSS-Fuzz](https://github.com/google/oss-fuzz/tree/master/projects/bitcoin-core)
program, which includes a dashboard of [publicly disclosed vulnerabilities](https://bugs.chromium.org/p/oss-fuzz/issues/list?q=bitcoin-core).
Generally, we try to disclose vulnerabilities as soon as possible after they
are fixed to give users the knowledge they need to be protected. However,
because Bitcoin is a live P2P network, and not just standalone local software,
we might not fully disclose every issue within Google's standard
program, which includes a dashboard of [publicly disclosed vulnerabilities](https://issues.oss-fuzz.com/issues?q=bitcoin-core%20status:open).
Bitcoin Core follows its [security disclosure policy](https://bitcoincore.org/en/security-advisories/),
which may differ from Google's standard
[90-day disclosure window](https://google.github.io/oss-fuzz/getting-started/bug-disclosure-guidelines/)
if a partial or delayed disclosure is important to protect users or the
function of the network.
.
OSS-Fuzz also produces [a fuzzing coverage report](https://oss-fuzz.com/coverage-report/job/libfuzzer_asan_bitcoin-core/latest).
4 changes: 3 additions & 1 deletion doc/multiprocess.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ The multiprocess feature requires [Cap'n Proto](https://capnproto.org/) and [lib
```
cd <BITCOIN_SOURCE_DIRECTORY>
make -C depends NO_QT=1 MULTIPROCESS=1
cmake -B build --toolchain=depends/x86_64-pc-linux-gnu/toolchain.cmake
# Set host platform to output of gcc -dumpmachine or clang -dumpmachine or check the depends/ directory for the generated subdirectory name
HOST_PLATFORM="x86_64-pc-linux-gnu"
cmake -B build --toolchain=depends/$HOST_PLATFORM/toolchain.cmake
cmake --build build
build/src/bitcoin-node -regtest -printtoconsole -debug=ipc
BITCOIND=$(pwd)/build/src/bitcoin-node build/test/functional/test_runner.py
Expand Down
7 changes: 3 additions & 4 deletions doc/zmq.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ operation.

## Enabling

By default, the ZeroMQ feature is automatically compiled in if the
necessary prerequisites are found. To disable, use -DWITH_ZMQ=OFF
during the *configure* step of building bitcoind:
By default, the ZeroMQ feature is not automatically compiled.
To enable, use `-DWITH_ZMQ=ON` when configuring the build system:

$ cmake -B build -DWITH_ZMQ=OFF (other options)
$ cmake -B build -DWITH_ZMQ=ON

To actually enable operation, one must set the appropriate options on
the command line or in the configuration file.
Expand Down
16 changes: 16 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,22 @@ if(WITH_MULTIPROCESS)
$<TARGET_NAME_IF_EXISTS:bitcoin_wallet>
)
list(APPEND installable_targets namecoin-node)

if(BUILD_TESTS)
# bitcoin_ipc_test library target is defined here in src/CMakeLists.txt
# instead of src/test/CMakeLists.txt so capnp files in src/test/ are able to
# reference capnp files in src/ipc/capnp/ by relative path. The Cap'n Proto
# compiler only allows importing by relative path when the importing and
# imported files are underneath the same compilation source prefix, so the
# source prefix must be src/, not src/test/
add_library(bitcoin_ipc_test STATIC EXCLUDE_FROM_ALL
test/ipc_test.cpp
)
target_capnp_sources(bitcoin_ipc_test ${PROJECT_SOURCE_DIR}
test/ipc_test.capnp
)
add_dependencies(bitcoin_ipc_test bitcoin_ipc_headers)
endif()
endif()


Expand Down
2 changes: 1 addition & 1 deletion src/index/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ bool BaseIndex::Init()

// Child init
const CBlockIndex* start_block = m_best_block_index.load();
if (!CustomInit(start_block ? std::make_optional(interfaces::BlockKey{start_block->GetBlockHash(), start_block->nHeight}) : std::nullopt)) {
if (!CustomInit(start_block ? std::make_optional(interfaces::BlockRef{start_block->GetBlockHash(), start_block->nHeight}) : std::nullopt)) {
return false;
}

Expand Down
5 changes: 3 additions & 2 deletions src/index/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <dbwrapper.h>
#include <interfaces/chain.h>
#include <interfaces/types.h>
#include <util/string.h>
#include <util/threadinterrupt.h>
#include <validationinterface.h>
Expand Down Expand Up @@ -107,7 +108,7 @@ class BaseIndex : public CValidationInterface
void ChainStateFlushed(ChainstateRole role, const CBlockLocator& locator) override;

/// Initialize internal state from the database and block index.
[[nodiscard]] virtual bool CustomInit(const std::optional<interfaces::BlockKey>& block) { return true; }
[[nodiscard]] virtual bool CustomInit(const std::optional<interfaces::BlockRef>& block) { return true; }

/// Write update index entries for a newly connected block.
[[nodiscard]] virtual bool CustomAppend(const interfaces::BlockInfo& block) { return true; }
Expand All @@ -118,7 +119,7 @@ class BaseIndex : public CValidationInterface

/// Rewind index to an earlier chain tip during a chain reorg. The tip must
/// be an ancestor of the current best block.
[[nodiscard]] virtual bool CustomRewind(const interfaces::BlockKey& current_tip, const interfaces::BlockKey& new_tip) { return true; }
[[nodiscard]] virtual bool CustomRewind(const interfaces::BlockRef& current_tip, const interfaces::BlockRef& new_tip) { return true; }

virtual DB& GetDB() const = 0;

Expand Down
4 changes: 2 additions & 2 deletions src/index/blockfilterindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ BlockFilterIndex::BlockFilterIndex(std::unique_ptr<interfaces::Chain> chain, Blo
m_filter_fileseq = std::make_unique<FlatFileSeq>(std::move(path), "fltr", FLTR_FILE_CHUNK_SIZE);
}

bool BlockFilterIndex::CustomInit(const std::optional<interfaces::BlockKey>& block)
bool BlockFilterIndex::CustomInit(const std::optional<interfaces::BlockRef>& block)
{
if (!m_db->Read(DB_FILTER_POS, m_next_filter_pos)) {
// Check that the cause of the read failure is that the key does not exist. Any other errors
Expand Down Expand Up @@ -316,7 +316,7 @@ bool BlockFilterIndex::Write(const BlockFilter& filter, uint32_t block_height, c
return true;
}

bool BlockFilterIndex::CustomRewind(const interfaces::BlockKey& current_tip, const interfaces::BlockKey& new_tip)
bool BlockFilterIndex::CustomRewind(const interfaces::BlockRef& current_tip, const interfaces::BlockRef& new_tip)
{
CDBBatch batch(*m_db);
std::unique_ptr<CDBIterator> db_it(m_db->NewIterator());
Expand Down
4 changes: 2 additions & 2 deletions src/index/blockfilterindex.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ class BlockFilterIndex final : public BaseIndex
std::optional<uint256> ReadFilterHeader(int height, const uint256& expected_block_hash);

protected:
bool CustomInit(const std::optional<interfaces::BlockKey>& block) override;
bool CustomInit(const std::optional<interfaces::BlockRef>& block) override;

bool CustomCommit(CDBBatch& batch) override;

bool CustomAppend(const interfaces::BlockInfo& block) override;

bool CustomRewind(const interfaces::BlockKey& current_tip, const interfaces::BlockKey& new_tip) override;
bool CustomRewind(const interfaces::BlockRef& current_tip, const interfaces::BlockRef& new_tip) override;

BaseIndex::DB& GetDB() const LIFETIMEBOUND override { return *m_db; }

Expand Down
6 changes: 3 additions & 3 deletions src/index/coinstatsindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ bool CoinStatsIndex::CustomAppend(const interfaces::BlockInfo& block)
return true;
}

bool CoinStatsIndex::CustomRewind(const interfaces::BlockKey& current_tip, const interfaces::BlockKey& new_tip)
bool CoinStatsIndex::CustomRewind(const interfaces::BlockRef& current_tip, const interfaces::BlockRef& new_tip)
{
CDBBatch batch(*m_db);
std::unique_ptr<CDBIterator> db_it(m_db->NewIterator());
Expand Down Expand Up @@ -319,7 +319,7 @@ bool CoinStatsIndex::CustomRewind(const interfaces::BlockKey& current_tip, const
return true;
}

static bool LookUpOne(const CDBWrapper& db, const interfaces::BlockKey& block, DBVal& result)
static bool LookUpOne(const CDBWrapper& db, const interfaces::BlockRef& block, DBVal& result)
{
// First check if the result is stored under the height index and the value
// there matches the block hash. This should be the case if the block is on
Expand Down Expand Up @@ -366,7 +366,7 @@ std::optional<CCoinsStats> CoinStatsIndex::LookUpStats(const CBlockIndex& block_
return stats;
}

bool CoinStatsIndex::CustomInit(const std::optional<interfaces::BlockKey>& block)
bool CoinStatsIndex::CustomInit(const std::optional<interfaces::BlockRef>& block)
{
if (!m_db->Read(DB_MUHASH, m_muhash)) {
// Check that the cause of the read failure is that the key does not
Expand Down
4 changes: 2 additions & 2 deletions src/index/coinstatsindex.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ class CoinStatsIndex final : public BaseIndex
bool AllowPrune() const override { return true; }

protected:
bool CustomInit(const std::optional<interfaces::BlockKey>& block) override;
bool CustomInit(const std::optional<interfaces::BlockRef>& block) override;

bool CustomCommit(CDBBatch& batch) override;

bool CustomAppend(const interfaces::BlockInfo& block) override;

bool CustomRewind(const interfaces::BlockKey& current_tip, const interfaces::BlockKey& new_tip) override;
bool CustomRewind(const interfaces::BlockRef& current_tip, const interfaces::BlockRef& new_tip) override;

BaseIndex::DB& GetDB() const override { return *m_db; }

Expand Down
Loading

0 comments on commit 3c9c99e

Please sign in to comment.