From e68e0cdbafe482da942a10e69f03ef2ae15dbc90 Mon Sep 17 00:00:00 2001 From: Davidhsb Date: Wed, 29 Oct 2025 13:24:40 -0300 Subject: [PATCH 1/8] Refactor bitcoin-node-entrypoint.sh to improve extractor startup logic and error handling --- docker/bitcoin-node-entrypoint.sh | 101 ++++++++++++++++++++++++------ 1 file changed, 83 insertions(+), 18 deletions(-) diff --git a/docker/bitcoin-node-entrypoint.sh b/docker/bitcoin-node-entrypoint.sh index 516a921..e7ee976 100755 --- a/docker/bitcoin-node-entrypoint.sh +++ b/docker/bitcoin-node-entrypoint.sh @@ -2,8 +2,14 @@ set -e BITCOIND_PID="" +EXTRACTOR_PID="" cleanup() { + if [ -n "$EXTRACTOR_PID" ] && kill -0 "$EXTRACTOR_PID" 2>/dev/null; then + echo "Shutting down extractor (PID $EXTRACTOR_PID)..." + kill "$EXTRACTOR_PID" + wait "$EXTRACTOR_PID" + fi if [ -n "$BITCOIND_PID" ] && kill -0 "$BITCOIND_PID" 2>/dev/null; then echo "Shutting down bitcoind (PID $BITCOIND_PID)..." kill "$BITCOIND_PID" @@ -15,7 +21,7 @@ trap cleanup EXIT # Fix permissions on the data directory chown -R bitcoin:bitcoin /home/bitcoin/.bitcoin 2>/dev/null || true -# Determine network flag +# Determine network flag for bitcoin-cli NETWORK="" case "$BITCOIN_NETWORK" in mainnet) NETWORK="" ;; @@ -28,23 +34,82 @@ case "$BITCOIN_NETWORK" in ;; esac -# Start bitcoind as bitcoin user, in the background -echo "Launching Bitcoin node in $BITCOIN_NETWORK mode..." -/usr/sbin/runuser -u bitcoin -- $BTC_BIN_PATH/bitcoind $NETWORK & -BITCOIND_PID=$! +# Set default P2P port and address based on extractor type +P2P_EXTRACTOR_PORT=${P2P_EXTRACTOR_PORT:-8555} +P2P_EXTRACTOR_HOST=${P2P_EXTRACTOR_HOST:-0.0.0.0} -# Now wait for the RPC -for i in {1..30}; do - /usr/sbin/runuser -u bitcoin -- $BTC_BIN_PATH/bitcoin-cli $NETWORK getblockchaininfo >/dev/null 2>&1 && break - sleep 1 -done +echo "Starting $EXTRACTOR_TYPE-extractor setup..." -# Final check -if ! /usr/sbin/runuser -u bitcoin -- $BTC_BIN_PATH/bitcoin-cli $NETWORK getblockchaininfo >/dev/null 2>&1; then - echo "Error: bitcoind did not start in time." >&2 +# Different startup logic based on extractor type +case "$EXTRACTOR_TYPE" in + ebpf) + # For eBPF: start bitcoind normally, then attach extractor + echo "Launching Bitcoin node in $BITCOIN_NETWORK mode..." + /usr/sbin/runuser -u bitcoin -- $BTC_BIN_PATH/bitcoind $NETWORK & + BITCOIND_PID=$! + + # Wait for RPC to be ready + for i in {1..30}; do + /usr/sbin/runuser -u bitcoin -- $BTC_BIN_PATH/bitcoin-cli $NETWORK getblockchaininfo >/dev/null 2>&1 && break + sleep 1 + done + + if ! /usr/sbin/runuser -u bitcoin -- $BTC_BIN_PATH/bitcoin-cli $NETWORK getblockchaininfo >/dev/null 2>&1; then + echo "Error: bitcoind did not start in time." >&2 + exit 1 + fi + + echo "Starting ebpf-extractor..." + exec /usr/local/bin/ebpf-extractor \ + --no-idle-exit \ + --nats-address nats://nats:4222 \ + --bitcoind-path $BTC_BIN_PATH/bitcoind \ + --bitcoind-pid $BITCOIND_PID + ;; + + p2p) + # For P2P: start extractor first (listening), then bitcoind connects to it + echo "Starting p2p-extractor on $P2P_EXTRACTOR_HOST:$P2P_EXTRACTOR_PORT..." + /usr/local/bin/p2p-extractor \ + --nats-address nats://nats:4222 \ + --p2p-network ${BITCOIN_NETWORK:-regtest} \ + --p2p-address $P2P_EXTRACTOR_HOST:$P2P_EXTRACTOR_PORT & + EXTRACTOR_PID=$! + + # Give extractor time to start listening + sleep 2 + + # Check if extractor is still running + if ! kill -0 "$EXTRACTOR_PID" 2>/dev/null; then + echo "Error: p2p-extractor failed to start." >&2 + exit 1 + fi + + echo "Launching Bitcoin node in $BITCOIN_NETWORK mode (connecting to p2p-extractor)..." + # Start bitcoind with addnode pointing to the p2p-extractor + /usr/sbin/runuser -u bitcoin -- $BTC_BIN_PATH/bitcoind $NETWORK \ + -addnode=127.0.0.1:$P2P_EXTRACTOR_PORT & + BITCOIND_PID=$! + + # Wait for RPC to be ready + for i in {1..30}; do + /usr/sbin/runuser -u bitcoin -- $BTC_BIN_PATH/bitcoin-cli $NETWORK getblockchaininfo >/dev/null 2>&1 && break + sleep 1 + done + + if ! /usr/sbin/runuser -u bitcoin -- $BTC_BIN_PATH/bitcoin-cli $NETWORK getblockchaininfo >/dev/null 2>&1; then + echo "Error: bitcoind did not start in time." >&2 + exit 1 + fi + + echo "Bitcoin node connected to p2p-extractor successfully" + # Keep both processes running + wait $EXTRACTOR_PID + ;; + + *) + echo "Unknown EXTRACTOR_TYPE: $EXTRACTOR_TYPE" >&2 + echo "Supported types: ebpf, p2p, rpc" >&2 exit 1 -fi - -echo "Starting ebpf-extractor" -# Run ebpf-extractor as root (needs CAP_SYS_ADMIN for BPF) -exec /usr/local/bin/ebpf-extractor --no-idle-exit --nats-address nats://nats:4222 --bitcoind-path $BTC_BIN_PATH/bitcoind + ;; +esac \ No newline at end of file From e9af2dfb1d4f2fdb798747debbcaac4d9ddd099d Mon Sep 17 00:00:00 2001 From: Davidhsb Date: Wed, 29 Oct 2025 13:25:22 -0300 Subject: [PATCH 2/8] Update: bitcoin-node.dockerfile to support configurable extractor type for builds --- docker/bitcoin-node.dockerfile | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/docker/bitcoin-node.dockerfile b/docker/bitcoin-node.dockerfile index fdd4928..be3ec75 100644 --- a/docker/bitcoin-node.dockerfile +++ b/docker/bitcoin-node.dockerfile @@ -29,6 +29,7 @@ FROM ubuntu:22.04 AS peer-observer-builder ARG PEER_EXTRACTOR_REPO=https://github.com/0xB10C/peer-observer.git ARG PEER_EXTRACTOR_BRANCH=master +ARG EXTRACTOR_TYPE=ebpf # Install peer-extractor dependencies RUN apt-get update && apt-get install -y \ @@ -57,14 +58,16 @@ RUN chmod +x scripts/bitcoin-node-entrypoint.sh COPY docker/bitcoin-node-healthcheck.sh scripts/bitcoin-node-healthcheck.sh RUN chmod +x scripts/bitcoin-node-healthcheck.sh -# Build the project -RUN bash -c ". scripts/set-bpf-environment.sh && cargo build --release" +# Build only the specified extractor (faster build, smaller cache) +# Valid values: ebpf, p2p, rpc +RUN bash -c ". scripts/set-bpf-environment.sh && cargo build --release -p ${EXTRACTOR_TYPE}-extractor" ### Runtime stage ### FROM ubuntu:22.04 AS runtime ENV DEBIAN_FRONTEND=noninteractive +ARG EXTRACTOR_TYPE=ebpf # Install runtime dependencies RUN apt-get update && apt-get install -y \ @@ -91,7 +94,10 @@ ENV BTC_BIN_PATH=/bitcoin/build/bin COPY --from=btc-core-builder $BTC_BIN_PATH $BTC_BIN_PATH COPY --from=peer-observer-builder /peer-observer/scripts/bitcoin-node-entrypoint.sh /peer-observer/scripts/bitcoin-node-entrypoint.sh COPY --from=peer-observer-builder /peer-observer/scripts/bitcoin-node-healthcheck.sh /peer-observer/scripts/bitcoin-node-healthcheck.sh -COPY --from=peer-observer-builder /peer-observer/target/release/ebpf-extractor /usr/local/bin/ebpf-extractor +COPY --from=peer-observer-builder /peer-observer/target/release/${EXTRACTOR_TYPE}-extractor /usr/local/bin/${EXTRACTOR_TYPE}-extractor + +# Set which extractor is being used (for scripts/debugging) +ENV EXTRACTOR_TYPE=${EXTRACTOR_TYPE} # Expose Bitcoin ports (RPC: 8332, P2P: 8333) EXPOSE 8332 8333 From 15beb1bde24d807cf0d30ec982c299fc152c7f39 Mon Sep 17 00:00:00 2001 From: Davidhsb Date: Wed, 29 Oct 2025 13:26:01 -0300 Subject: [PATCH 3/8] Add: extractor type argument to bitcoin-node build configuration --- docker-compose/node.usdt.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-compose/node.usdt.yml b/docker-compose/node.usdt.yml index cd37c42..fcaa3da 100644 --- a/docker-compose/node.usdt.yml +++ b/docker-compose/node.usdt.yml @@ -4,6 +4,8 @@ services: build: context: ../ dockerfile: docker/bitcoin-node.dockerfile + args: + EXTRACTOR_TYPE: ${EXTRACTOR_TYPE:-ebpf} cap_add: - SYS_ADMIN - SYS_PTRACE From 0d8418d93c6951dd16564c69551eff20cf028b78 Mon Sep 17 00:00:00 2001 From: Davidhsb Date: Thu, 6 Nov 2025 14:34:37 -0300 Subject: [PATCH 4/8] Fix: improve bitcoind startup logic and error handling in entrypoint script --- docker/bitcoin-node-entrypoint.sh | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/docker/bitcoin-node-entrypoint.sh b/docker/bitcoin-node-entrypoint.sh index e7ee976..bb5da1e 100755 --- a/docker/bitcoin-node-entrypoint.sh +++ b/docker/bitcoin-node-entrypoint.sh @@ -46,7 +46,19 @@ case "$EXTRACTOR_TYPE" in # For eBPF: start bitcoind normally, then attach extractor echo "Launching Bitcoin node in $BITCOIN_NETWORK mode..." /usr/sbin/runuser -u bitcoin -- $BTC_BIN_PATH/bitcoind $NETWORK & - BITCOIND_PID=$! + + # Wait a moment for bitcoind process to start + sleep 1 + + # Get the actual bitcoind PID (not runuser's PID) + BITCOIND_PID=$(pgrep -f "bitcoind.*$NETWORK" | head -n1) + + if [ -z "$BITCOIND_PID" ]; then + echo "Error: Could not find bitcoind process." >&2 + exit 1 + fi + + echo "bitcoind started with PID: $BITCOIND_PID" # Wait for RPC to be ready for i in {1..30}; do @@ -89,7 +101,19 @@ case "$EXTRACTOR_TYPE" in # Start bitcoind with addnode pointing to the p2p-extractor /usr/sbin/runuser -u bitcoin -- $BTC_BIN_PATH/bitcoind $NETWORK \ -addnode=127.0.0.1:$P2P_EXTRACTOR_PORT & - BITCOIND_PID=$! + + # Wait a moment for bitcoind process to start + sleep 1 + + # Get the actual bitcoind PID (not runuser's PID) + BITCOIND_PID=$(pgrep -f "bitcoind.*$NETWORK" | head -n1) + + if [ -z "$BITCOIND_PID" ]; then + echo "Error: Could not find bitcoind process." >&2 + exit 1 + fi + + echo "bitcoind started with PID: $BITCOIND_PID" # Wait for RPC to be ready for i in {1..30}; do From 5f1f22d05bfd62a116aac64fe87e081485e1d51e Mon Sep 17 00:00:00 2001 From: Davidhsb Date: Thu, 6 Nov 2025 15:13:45 -0300 Subject: [PATCH 5/8] Add: implement rpc-extractor startup logic in bitcoin-node entrypoint script --- docker/bitcoin-node-entrypoint.sh | 78 +++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/docker/bitcoin-node-entrypoint.sh b/docker/bitcoin-node-entrypoint.sh index bb5da1e..52f98dd 100755 --- a/docker/bitcoin-node-entrypoint.sh +++ b/docker/bitcoin-node-entrypoint.sh @@ -130,6 +130,84 @@ case "$EXTRACTOR_TYPE" in # Keep both processes running wait $EXTRACTOR_PID ;; + + rpc) + # For RPC: start bitcoind normally, then start rpc-extractor + echo "Launching Bitcoin node in $BITCOIN_NETWORK mode..." + /usr/sbin/runuser -u bitcoin -- $BTC_BIN_PATH/bitcoind $NETWORK & + + # Wait a moment for bitcoind process to start + sleep 1 + + # Get the actual bitcoind PID (not runuser's PID) + BITCOIND_PID=$(pgrep -f "bitcoind.*$NETWORK" | head -n1) + + if [ -z "$BITCOIND_PID" ]; then + echo "Error: Could not find bitcoind process." >&2 + exit 1 + fi + + echo "bitcoind started with PID: $BITCOIND_PID" + + # Wait for RPC to be ready + for i in {1..30}; do + /usr/sbin/runuser -u bitcoin -- $BTC_BIN_PATH/bitcoin-cli $NETWORK getblockchaininfo >/dev/null 2>&1 && break + sleep 1 + done + + if ! /usr/sbin/runuser -u bitcoin -- $BTC_BIN_PATH/bitcoin-cli $NETWORK getblockchaininfo >/dev/null 2>&1; then + echo "Error: bitcoind did not start in time." >&2 + exit 1 + fi + + # Set default query interval (in seconds) + RPC_QUERY_INTERVAL=${RPC_QUERY_INTERVAL:-20} + + # RPC credentials - use cookie file by default, or user/password if provided + RPC_AUTH_ARGS="" + if [ -n "$RPC_USER" ] && [ -n "$RPC_PASSWORD" ]; then + echo "Starting rpc-extractor with user/password authentication..." + RPC_AUTH_ARGS="--rpc-user $RPC_USER --rpc-password $RPC_PASSWORD" + else + echo "Starting rpc-extractor with cookie file authentication..." + RPC_COOKIE_FILE=${RPC_COOKIE_FILE:-/home/bitcoin/.bitcoin${NETWORK}/.cookie} + + # Verify cookie file exists (it should be auto-created by bitcoind) + if [ ! -f "$RPC_COOKIE_FILE" ]; then + echo "Warning: Cookie file not found at $RPC_COOKIE_FILE" >&2 + echo "Waiting for bitcoind to create it..." >&2 + for i in {1..10}; do + [ -f "$RPC_COOKIE_FILE" ] && break + sleep 1 + done + if [ ! -f "$RPC_COOKIE_FILE" ]; then + echo "Error: Cookie file was not created. Check if bitcoind RPC is enabled." >&2 + exit 1 + fi + fi + + echo "Using cookie file: $RPC_COOKIE_FILE" + RPC_AUTH_ARGS="--rpc-cookie-file $RPC_COOKIE_FILE" + fi + + echo "Starting rpc-extractor (query interval: ${RPC_QUERY_INTERVAL}s)..." + /usr/local/bin/rpc-extractor \ + --nats-address nats://nats:4222 \ + --query-interval $RPC_QUERY_INTERVAL \ + $RPC_AUTH_ARGS & + EXTRACTOR_PID=$! + + # Check if extractor is still running + sleep 1 + if ! kill -0 "$EXTRACTOR_PID" 2>/dev/null; then + echo "Error: rpc-extractor failed to start." >&2 + exit 1 + fi + + echo "rpc-extractor started successfully" + # Keep both processes running + wait $EXTRACTOR_PID + ;; *) echo "Unknown EXTRACTOR_TYPE: $EXTRACTOR_TYPE" >&2 From a8b80c2fec5766025e287690821840f9920b87ff Mon Sep 17 00:00:00 2001 From: Davidhsb Date: Thu, 6 Nov 2025 15:14:25 -0300 Subject: [PATCH 6/8] Add: configure RPC Extractor environment variables in docker-compose for bitcoin-node --- docker-compose/node.usdt.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docker-compose/node.usdt.yml b/docker-compose/node.usdt.yml index fcaa3da..9d58f11 100644 --- a/docker-compose/node.usdt.yml +++ b/docker-compose/node.usdt.yml @@ -12,6 +12,12 @@ services: security_opt: - apparmor:unconfined privileged: true + environment: + # RPC Extractor configuration (only used when EXTRACTOR_TYPE=rpc) + - RPC_QUERY_INTERVAL=${RPC_QUERY_INTERVAL:-20} + - RPC_USER=${RPC_USER:-} + - RPC_PASSWORD=${RPC_PASSWORD:-} + - RPC_COOKIE_FILE=${RPC_COOKIE_FILE:-} volumes: - bitcoin-data:/home/bitcoin/.bitcoin - /sys/kernel/debug:/sys/kernel/debug From 8b1df1f328fd7410eeaa14c3904679abf971c275 Mon Sep 17 00:00:00 2001 From: Davidhsb Date: Thu, 6 Nov 2025 15:45:51 -0300 Subject: [PATCH 7/8] Update: enhance README to include new extractor types and usage instructions --- README.md | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 87 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0198908..6d429fa 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,13 @@ This project contains Docker configurations and orchestration files for running The base system consists of: - **Bitcoin Node**: A full Bitcoin Core node instrumented for monitoring. -- **ebpf-extractor**: An extractor tool that consumes ebpf kernel events and routes messages to the NATS server. +- **Extractor**: Tool that extracts Bitcoin network events and routes messages to the NATS server. Three types are available: + - **ebpf-extractor** (default): Uses eBPF kernel events to monitor Bitcoin Core internals + - **p2p-extractor**: Acts as a Bitcoin P2P node to observe network messages + - **rpc-extractor**: Periodically queries Bitcoin Core RPC interfaces - **NATS**: Message broker for inter-service communication. -The default network is regtest for test and development, it is provided by [docker-compose.yml](docker-compose.yml) and doesn't require command line arguments. +The default network is regtest for test and development, it is provided by [docker-compose.yml](docker-compose.yml) and doesn't require command line arguments. The default extractor is **ebpf-extractor**. Other networks are provided by [node.mainnet.yml](node.mainnet.yml), [node.signet.yml](node.signet.yml), and [node.regtest.yml](node.regtest.yml). You refer to one of them using the `-f` option, e.g., `docker compose -f node.mainnet.yml up`. @@ -52,7 +55,7 @@ Each tool is configured as a service with the `monitoring` profile and a profile docker compose --profile monitoring build --no-cache ``` -3. **Start the base system in regtest**: +3. **Start the base system in regtest** (with default eBPF extractor): ```bash docker compose up -d ``` @@ -62,7 +65,7 @@ Each tool is configured as a service with the `monitoring` profile and a profile docker compose ps ``` -You should see two containers running since the bitcoin node and the ebpf-extractor tool should run in the same container. +You should see two containers running since the bitcoin node and the extractor tool run in the same container. 5. **Start the logger tool**: ```bash @@ -76,6 +79,86 @@ You should now have three containers. docker compose --profile logger logs -f ``` +## Choosing an Extractor + +You can choose which extractor to use by setting the `EXTRACTOR_TYPE` environment variable: + +### eBPF Extractor (Default) + +Uses eBPF (extended Berkeley Packet Filter) to monitor Bitcoin Core at the kernel level. Provides the most detailed insights but requires privileged container access. + +```bash +# Default - no need to specify +docker compose up -d + +# Or explicitly +EXTRACTOR_TYPE=ebpf docker compose up -d +``` + +**Requirements:** +- Privileged container +- `SYS_ADMIN` and `SYS_PTRACE` capabilities +- Access to `/sys/kernel/debug` + +### P2P Extractor + +Acts as a Bitcoin P2P peer, intercepting and analyzing network messages between Bitcoin nodes. + +```bash +EXTRACTOR_TYPE=p2p docker compose up -d +``` + +**Configuration Options:** +- `P2P_EXTRACTOR_PORT`: Port for P2P connections (default: 8555) +- `P2P_EXTRACTOR_HOST`: Host address to bind (default: 0.0.0.0) + +**Example with custom port:** +```bash +EXTRACTOR_TYPE=p2p P2P_EXTRACTOR_PORT=9000 docker compose up -d +``` + +### RPC Extractor + +Periodically queries Bitcoin Core's RPC interface and publishes the results as events. + +```bash +EXTRACTOR_TYPE=rpc docker compose up -d +``` + +**Configuration Options:** +- `RPC_QUERY_INTERVAL`: Time between queries in seconds (default: 20) +- `RPC_USER`: RPC username (optional, uses cookie file by default) +- `RPC_PASSWORD`: RPC password (optional, uses cookie file by default) + +**Example with custom interval:** +```bash +EXTRACTOR_TYPE=rpc RPC_QUERY_INTERVAL=30 docker compose up -d +``` + +**Example with authentication:** +```bash +EXTRACTOR_TYPE=rpc RPC_USER=peer-observer RPC_PASSWORD=hunter2 docker compose up -d +``` + +**Note:** If `RPC_USER` and `RPC_PASSWORD` are not provided, the extractor will automatically use Bitcoin Core's cookie file for authentication. + +### Using Environment Files + +For convenience, create a `.env` file in the project root: + +```bash +# .env +EXTRACTOR_TYPE=rpc +RPC_QUERY_INTERVAL=30 +RPC_USER=peer-observer +RPC_PASSWORD=hunter2 +``` + +Then simply run: +```bash +docker compose up -d +``` + ## Services and Ports | Service | Port | Description | From 4102bf25dc9ba84834e1e9a3081cf3faaabb5237 Mon Sep 17 00:00:00 2001 From: Davidhsb Date: Thu, 6 Nov 2025 16:46:51 -0300 Subject: [PATCH 8/8] Fix: Merge master commit --- docker/bitcoin-node-entrypoint.sh | 48 ++++++------------------------- 1 file changed, 8 insertions(+), 40 deletions(-) diff --git a/docker/bitcoin-node-entrypoint.sh b/docker/bitcoin-node-entrypoint.sh index 34e9f20..db79706 100755 --- a/docker/bitcoin-node-entrypoint.sh +++ b/docker/bitcoin-node-entrypoint.sh @@ -46,19 +46,11 @@ case "$EXTRACTOR_TYPE" in # For eBPF: start bitcoind normally, then attach extractor echo "Launching Bitcoin node in $BITCOIN_NETWORK mode..." /usr/sbin/runuser -u bitcoin -- $BTC_BIN_PATH/bitcoind $NETWORK & - - # Wait a moment for bitcoind process to start - sleep 1 - - # Get the actual bitcoind PID (not runuser's PID) - BITCOIND_PID=$(pgrep -f "bitcoind.*$NETWORK" | head -n1) - - if [ -z "$BITCOIND_PID" ]; then - echo "Error: Could not find bitcoind process." >&2 - exit 1 - fi - - echo "bitcoind started with PID: $BITCOIND_PID" + BITCOIND_PID=$! + + # Determine the bitcoind PID file path + BITCOIND_PID_FILE="/home/bitcoin/.bitcoin/$BITCOIN_NETWORK/bitcoind.pid" + echo "Reading Bitcoind PID from: $BITCOIND_PID_FILE" # Wait for RPC to be ready for i in {1..30}; do @@ -76,7 +68,7 @@ case "$EXTRACTOR_TYPE" in --no-idle-exit \ --nats-address nats://nats:4222 \ --bitcoind-path $BTC_BIN_PATH/bitcoind \ - --bitcoind-pid $BITCOIND_PID + --bitcoind-pid-file $BITCOIND_PID_FILE ;; p2p) @@ -101,19 +93,7 @@ case "$EXTRACTOR_TYPE" in # Start bitcoind with addnode pointing to the p2p-extractor /usr/sbin/runuser -u bitcoin -- $BTC_BIN_PATH/bitcoind $NETWORK \ -addnode=127.0.0.1:$P2P_EXTRACTOR_PORT & - - # Wait a moment for bitcoind process to start - sleep 1 - - # Get the actual bitcoind PID (not runuser's PID) - BITCOIND_PID=$(pgrep -f "bitcoind.*$NETWORK" | head -n1) - - if [ -z "$BITCOIND_PID" ]; then - echo "Error: Could not find bitcoind process." >&2 - exit 1 - fi - - echo "bitcoind started with PID: $BITCOIND_PID" + BITCOIND_PID=$! # Wait for RPC to be ready for i in {1..30}; do @@ -135,19 +115,7 @@ case "$EXTRACTOR_TYPE" in # For RPC: start bitcoind normally, then start rpc-extractor echo "Launching Bitcoin node in $BITCOIN_NETWORK mode..." /usr/sbin/runuser -u bitcoin -- $BTC_BIN_PATH/bitcoind $NETWORK & - - # Wait a moment for bitcoind process to start - sleep 1 - - # Get the actual bitcoind PID (not runuser's PID) - BITCOIND_PID=$(pgrep -f "bitcoind.*$NETWORK" | head -n1) - - if [ -z "$BITCOIND_PID" ]; then - echo "Error: Could not find bitcoind process." >&2 - exit 1 - fi - - echo "bitcoind started with PID: $BITCOIND_PID" + BITCOIND_PID=$! # Wait for RPC to be ready for i in {1..30}; do