Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions .github/actions/install-bitcoin/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: 'Install and Verify Bitcoin Core'
description: 'Downloads, Verify signatures and installs Bitcoin Core'

inputs:
version:
description: 'Bitcoin Core version to install'
required: true
default: '31.0'
trusted_keys:
description: 'List of GPG fingerprints to validate'
required: false
# Signatures from the following GPG public keys checked during verification of the source code.
# The list can be found at https://github.com/bitcoin-core/guix.sigs/tree/main/builder-keys
# 15281230078...: achow101.gpg
# 9EDAFF80E08...: Emzy.gpg
# D1DBF2C4B96...: hebasto.gpg
default: >-
152812300785C96444D3334D17565732E08E5E41
9EDAFF80E080659604F4A76B2EBB056FD847F8A7
D1DBF2C4B96F2DEBF4C16654410108112E7EA81F

runs:
using: "composite"
steps:
- name: Install verification dependencies
shell: bash
run: sudo apt-get update && sudo apt-get install -y gnupg wget

- name: Download and Verify Bitcoin Core
shell: bash
run: |
VERSION="${{ inputs.version }}"

# 1. Download Binaries & Manifests
wget -q "https://bitcoincore.org/bin/bitcoin-core-${VERSION}/bitcoin-${VERSION}-x86_64-linux-gnu.tar.gz"
wget -q "https://bitcoincore.org/bin/bitcoin-core-${VERSION}/SHA256SUMS"
wget -q "https://bitcoincore.org/bin/bitcoin-core-${VERSION}/SHA256SUMS.asc"

# 2. Fetch builder keys
git clone --depth 1 https://github.com/bitcoin-core/guix.sigs

# 3. Setup temporary GPG environment
export GNUPGHOME=$(mktemp -d)
gpg --batch --import guix.sigs/builder-keys/*.gpg

# 4. Verify the SHA256SUMS signature
gpg --batch --verify --status-fd 1 SHA256SUMS.asc SHA256SUMS > verify.log

# 5. Check against trusted fingerprints
TRUSTED_KEYS=(${{ inputs.trusted_keys }})
MATCH=false
for KEY in "${TRUSTED_KEYS[@]}"; do
if grep -q "VALIDSIG .* $KEY" verify.log; then
echo "Verified signature from trusted developer: $KEY"
MATCH=true
break
fi
done

if [ "$MATCH" != true ]; then
echo "No signatures from the trusted key list were found."
exit 1
fi

# 6. Verify checksum and extract
sha256sum --ignore-missing --check SHA256SUMS
tar -xzf bitcoin-${VERSION}-x86_64-linux-gnu.tar.gz

# 7. Install to path (core v31.0 lists `bitcoin-node` in libexec/)
sudo install -m 0755 -o root -g root -t /usr/local/bin bitcoin-${VERSION}/bin/*
sudo install -m 0755 -o root -g root -t /usr/local/bin bitcoin-${VERSION}/libexec/*

# Cleanup workspace
rm -rf guix.sigs bitcoin-${VERSION}* SHA256SUMS* verify.log
echo "Bitcoin Core v${VERSION} installed successfully."

- name: Verify Installation
shell: bash
run: bitcoind --version
4 changes: 3 additions & 1 deletion .github/actions/setup-ubuntu-action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ runs:
zstd \
binutils-dev \
elfutils \
gcc-multilib
gcc-multilib \
libcapnp-dev \
capnproto

- name: Cache cargo
uses: actions/cache@v3
Expand Down
30 changes: 19 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,40 +106,48 @@ jobs:
steps:
- uses: actions/checkout@v6
- uses: ./.github/actions/setup-ubuntu-action
- name: Setup Bitcoin
uses: ./.github/actions/install-bitcoin
with:
version: '31.0'
- name: Install integration test dependecies
run: sudo apt-get install -y nats-server
- name: Run tests and integration tests
run: NATS_SERVER_BINARY=$(which nats-server) cargo test --all-features
run: NATS_SERVER_BINARY=$(which nats-server) BITCOIN_NODE_EXE=$(which bitcoin-node) cargo test --all-features

ubuntu-test-detect-intermittent-failures:
runs-on: ubuntu-latest
needs: ubuntu-test
steps:
- uses: actions/checkout@v6
- uses: ./.github/actions/setup-ubuntu-action
- name: Setup Bitcoin
uses: ./.github/actions/install-bitcoin
with:
version: '31.0'
- name: Install integration test dependecies
run: sudo apt-get install -y nats-server
# use separate steps for iterations here to easily see on GHA the time it took
- name: Iteration 0
run: NATS_SERVER_BINARY=$(which nats-server) cargo test --all-features
run: NATS_SERVER_BINARY=$(which nats-server) BITCOIN_NODE_EXE=$(which bitcoin-node) cargo test --all-features
- name: Iteration 1
run: NATS_SERVER_BINARY=$(which nats-server) cargo test --all-features
run: NATS_SERVER_BINARY=$(which nats-server) BITCOIN_NODE_EXE=$(which bitcoin-node) cargo test --all-features
- name: Iteration 2
run: NATS_SERVER_BINARY=$(which nats-server) cargo test --all-features
run: NATS_SERVER_BINARY=$(which nats-server) BITCOIN_NODE_EXE=$(which bitcoin-node) cargo test --all-features
- name: Iteration 3
run: NATS_SERVER_BINARY=$(which nats-server) cargo test --all-features
run: NATS_SERVER_BINARY=$(which nats-server) BITCOIN_NODE_EXE=$(which bitcoin-node) cargo test --all-features
- name: Iteration 4
run: NATS_SERVER_BINARY=$(which nats-server) cargo test --all-features
run: NATS_SERVER_BINARY=$(which nats-server) BITCOIN_NODE_EXE=$(which bitcoin-node) cargo test --all-features
- name: Iteration 5
run: NATS_SERVER_BINARY=$(which nats-server) cargo test --all-features
run: NATS_SERVER_BINARY=$(which nats-server) BITCOIN_NODE_EXE=$(which bitcoin-node) cargo test --all-features
- name: Iteration 6
run: NATS_SERVER_BINARY=$(which nats-server) cargo test --all-features
run: NATS_SERVER_BINARY=$(which nats-server) BITCOIN_NODE_EXE=$(which bitcoin-node) cargo test --all-features
- name: Iteration 7
run: NATS_SERVER_BINARY=$(which nats-server) cargo test --all-features
run: NATS_SERVER_BINARY=$(which nats-server) BITCOIN_NODE_EXE=$(which bitcoin-node) cargo test --all-features
- name: Iteration 8
run: NATS_SERVER_BINARY=$(which nats-server) cargo test --all-features
run: NATS_SERVER_BINARY=$(which nats-server) BITCOIN_NODE_EXE=$(which bitcoin-node) cargo test --all-features
- name: Iteration 9
run: NATS_SERVER_BINARY=$(which nats-server) cargo test --all-features
run: NATS_SERVER_BINARY=$(which nats-server) BITCOIN_NODE_EXE=$(which bitcoin-node) cargo test --all-features

ubuntu-docs-tools:
needs: ubuntu-build
Expand Down
61 changes: 59 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"extractors/rpc",
"extractors/p2p",
"extractors/log",
"extractors/ipc",
"tools/logger",
"tools/websocket",
"tools/metrics",
Expand Down
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ selected P2P measurements as events into a NATS pub-sub queue.

The `log-extractor` publishes them parsed `debug.log` log messages as events to NATS.

And finally an experimental `ipc-extractor` which periodically fetch data from a `bitcoin-node` binary through a UNIX socket created with the `-ipcbind` option. Publishes to NATS as IPC events.

The tools are written in Rust (or any other language that supports NATS
and protobuf). They subscribe to the NATS server. For example, the `logger` tool
simply prints out all messages that it receives, the `metrics` tool produces prometheus
Expand All @@ -36,21 +38,27 @@ messages. For other languages, types can be generated directly from the Protobuf
messages
┌─────────────┐ ┌───────────────┐ ┌─────────┐ ┌──────────────────────┐
│ ├────► ebpf-extractor├─────┤ │ │ │
│ │ └───────────────┘ │ │ │ Tools │
│ │ │ │ │ │
│ │ ┌───────────────┐ │ ├──────┼──►logger │
│ │ └───────────────┘ │ │ │ │
│ │ │ │ │ Tools │
│ │ ┌───────────────┐ │ │ │ │
│ ├────► rpc-extractor │─────┤ │ │ │
│ Bitcoin │ └───────────────┘ │ NATS.io ├──────┼──►metrics │
│ │ └───────────────┘ │ ├──────┼──►logger │
│ │ │ │ │ │
│ Node │ ┌───────────────┐ │ PUB-SUB ├──────┼──►websocket │
│ Bitcoin │ ┌───────────────┐ │ NATS.io ├──────┼──►metrics │
│ ├────► p2p-extractor │─────┤ │ │ │
│ │ └───────────────┘ │ ├──────┼──►connectivity-check │
│ Node │ └───────────────┘ │ PUB-SUB ├──────┼──►websocket │
│ │ │ │ │ │
│ │ ┌───────────────┐ │ │ │ ... │
│ │ ┌───────────────┐ │ ├──────┼──►connectivity-check │
│ ├────► log-extractor │─────┤ │ │ │
│ │ └───────────────┘ │ │ │ ... │
│ │ │ │ │ │
│ │ ┌───────────────┐ │ │ │ │
│ ├────► ipc-extractor ├─────┤ │ │ │
└─────────────┘ └───────────────┘ └─────────┘ └──────────────────────┘

(edit on asciiflow.com)


```

[nats.io]: https://nats.io
Expand All @@ -69,6 +77,7 @@ NATS server. Each extractor connects to a different interface:
| rpc | periodically fetches RPC for events | [extractors/rpc/](extractors/rpc) |
| p2p |Bitcoin P2P events from an inbound node| [extractors/p2p/](extractors/p2p) |
| log | parses the debug.log of a node | [extractors/log/](extractors/log) |
| ipc | Fetch data over via IPC socket (experimental) | [extractors/ipc/](extractors/ipc) |

## Tools

Expand Down Expand Up @@ -101,7 +110,7 @@ I'll do my best to add more documentation.

To run the integration tests, run with the feature `nats_integration_tests` and
`node_integration_tests`. If you are not using the nix-shell, you need to set the
`NATS_SERVER_BINARY` to the path to your `nats-server` binary. Addtionally,
`NATS_SERVER_BINARY` to the path to your `nats-server` binary and `BITCOIN_NODE_EXE` to the path to a `bitcoin-node` binary. Additionally,
`BITCOIND_EXE` can be set to a custom `bitcoind` binary. By default, a recent
release will be downloaded and used if `BITCOIND_SKIP_DOWNLOAD` is unset.

Expand Down
23 changes: 23 additions & 0 deletions extractors/ipc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "ipc-extractor"
version = "0.1.0"
edition = "2024"

[dependencies]
capnp = "0.25.1"
capnp-rpc = "0.25.0"
shared = { path = "../../shared" }
tokio-util = { version = "0.7.18", features = ["compat"] }

[features]
# Treat warnings as a build error.
strict = []

# Run integration tests needing a NATS server.
nats_integration_tests = []

# Run integration tests needing a Bitcoin Core node.
node_integration_tests = []

[build-dependencies]
capnpc = "0.25.0"
47 changes: 47 additions & 0 deletions extractors/ipc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# `ipc` extractor

> publishes data fetched from IPC

The peer-observer ipc-extractor periodically queries data from the Bitcoin Core IPC interface and publishes the results as events into a NATS pub-sub queue

## Example

Start `bitcoin-node` with `-ipcbind=unix` to expose the IPC interface over a UNIX socket. With the bare `unix` value the socket is created at `<datadir>/node.sock` relative to the *network* data directory, for instance regtest with a default datadir results in the socket located at `~/.bitcoin/regtest/node.sock`. `~/.bitcoin/node.sock` for mainnet.

For example, run a regtest node and point the ipc-extractor at the generated socket:

```bash
$ bitcoin-node -regtest -ipcbind=unix &
$ cargo run --bin ipc-extractor -- --ipc-socket-path ~/.bitcoin/regtest/node.sock
```

Note that `bitcoin-node` is compiled by setting `-DENABLE_IPC=ON` when building from source. Alternatively, there is also a proxy binary named `bitcoin` that lets you spawn a specific process with the `-m` option. That's it, running `bitcoin -m node -regtest -ipcbind=unix` is equivalent to the start command above.

## Usage

```
$ cargo run --bin ipc-extractor -- --help
The peer-observer ipc-extractor periodically queries data from the Bitcoin Core IPC endpoint and publishes the results as events into a NATS pub-sub queue

Usage: ipc-extractor [OPTIONS] --ipc-socket-path <IPC_SOCKET_PATH>

Options:
-i, --ipc-socket-path <IPC_SOCKET_PATH>
A path to an UNIX socket to read IPC data from
-a, --nats-address <ADDRESS>
The NATS server address the extractor/tool should connect and subscribe to [default: 127.0.0.1:4222]
-u, --nats-username <USERNAME>
The NATS username the extractor/tool should try to authentificate to the NATS server with
-p, --nats-password <PASSWORD>
The NATS password the extractor/tool should try to authentificate to the NATS server with
-f, --nats-password-file <PASSWORD_FILE>
A path to a file containing a password the extractor/tool should try to authentificate to the NATS server with
-l, --log-level <LOG_LEVEL>
The log level the extractor should run with. Valid log levels are "trace", "debug", "info", "warn", "error". See https://docs.rs/log/latest/log/enum.Level.html [default: DEBUG]
--query-interval <QUERY_INTERVAL>
Interval (in seconds) in which to query from the Bitcoin Core IPC interface [default: 10]
-h, --help
Print help
-V, --version
Print version
```
Loading
Loading