anchorage_layer_simple/test-mempool-rpc-config.sh
ncantu 937646cc45 Daily backup to git cron, backup/restore scripts, docs
**Motivations:**
- Export Signet and mining wallet backups to git with only 2 versions kept
- Document and add backup/restore scripts for signet and mining wallet

**Correctifs:**
- Backup-to-git uses SSH URL for passwordless cron; copy timestamped files only; prune to 2 versions; remove *-latest from backup repo

**Evolutions:**
- data/backup-to-git-cron.sh: daily export to git.4nkweb.com/4nk/backup
- save-signet-datadir-backup.sh, restore-signet-from-backup.sh, export-mining-wallet.sh, import-mining-wallet.sh
- features/backup-to-git-daily-cron.md, docs/MAINTENANCE.md backup section
- .gitignore: data/backup-to-git.log

**Pages affectées:**
- .gitignore, data/backup-to-git-cron.sh, docs/MAINTENANCE.md, features/backup-to-git-daily-cron.md
- save-signet-datadir-backup.sh, restore-signet-from-backup.sh, export-mining-wallet.sh, import-mining-wallet.sh
- Plus autres fichiers modifiés ou non suivis déjà présents dans le working tree
2026-02-04 03:07:57 +01:00

73 lines
2.5 KiB
Bash
Executable File

#!/bin/bash
#
# Test the RPC configuration that Mempool uses (host.docker.internal:38332
# = host's 127.0.0.1:38332 when Mempool runs in Docker on that host).
# Run on the machine where Mempool runs to verify the node has ~11535 blocks;
# then align Dashboard, Anchorage and Faucet to the same host:port.
#
# Usage: ./test-mempool-rpc-config.sh [RPC_HOST] [RPC_PORT]
# Default: 127.0.0.1 38332
# Example (node on another machine): ./test-mempool-rpc-config.sh 192.168.1.105 38332
#
# Author: 4NK Team
# Date: 2026-02-02
set -e
RPC_HOST="${1:-127.0.0.1}"
RPC_PORT="${2:-38332}"
RPC_USER="${BITCOIN_RPC_USER:-bitcoin}"
RPC_PASS="${BITCOIN_RPC_PASSWORD:-bitcoin}"
EXPECTED_MIN="${EXPECTED_HEIGHT_MIN:-11000}"
EXPECTED_MAX="${EXPECTED_HEIGHT_MAX:-12000}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TMP_JSON="$SCRIPT_DIR/.test-mempool-rpc-$$.json"
trap 'rm -f "$TMP_JSON"' EXIT
echo "=== Test Mempool RPC config (same node as Mempool uses) ==="
echo "Host: $RPC_HOST Port: $RPC_PORT"
echo ""
# JSON-RPC getblockchaininfo
HTTP_CODE=$(curl -s -o "$TMP_JSON" -w "%{http_code}" \
--user "$RPC_USER:$RPC_PASS" \
--data-binary '{"jsonrpc":"1.0","id":"test","method":"getblockchaininfo","params":[]}' \
-H "content-type: text/plain;" \
"http://${RPC_HOST}:${RPC_PORT}/" 2>/dev/null || echo "000")
if [ "$HTTP_CODE" != "200" ]; then
echo "FAIL: RPC returned HTTP $HTTP_CODE (node unreachable or auth failed)."
exit 1
fi
if [ ! -f "$TMP_JSON" ] || ! grep -q '"result"' "$TMP_JSON" 2>/dev/null; then
echo "FAIL: RPC response missing result."
exit 1
fi
CHAIN=$(grep -o '"chain"[[:space:]]*:[[:space:]]*"[^"]*"' "$TMP_JSON" | sed 's/.*:[[:space:]]*"\([^"]*\)".*/\1/')
BLOCKS=$(grep -o '"blocks"[[:space:]]*:[[:space:]]*[0-9]*' "$TMP_JSON" | head -1 | grep -o '[0-9]*$')
if [ -z "$BLOCKS" ]; then
echo "FAIL: Could not parse 'blocks' from getblockchaininfo."
exit 1
fi
echo "Node: chain=$CHAIN blocks=$BLOCKS"
if [ "$CHAIN" != "signet" ]; then
echo "WARN: chain is not 'signet' (got '$CHAIN')."
fi
if [ "$BLOCKS" -ge "$EXPECTED_MIN" ] && [ "$BLOCKS" -le "$EXPECTED_MAX" ]; then
echo "OK: Height $BLOCKS is in expected range [$EXPECTED_MIN..$EXPECTED_MAX] (same as Mempool)."
echo ""
echo "Align Dashboard, Anchorage and Faucet to this node: BITCOIN_RPC_HOST=$RPC_HOST BITCOIN_RPC_PORT=$RPC_PORT"
exit 0
else
echo "WARN: Height $BLOCKS is outside expected range [$EXPECTED_MIN..$EXPECTED_MAX]."
echo " This may not be the node Mempool uses, or the chain is not synced."
exit 1
fi