dgb-wallet/ops/blockbook-upstream.sh
Digibyte.X 690959a983 p2p: BIP158 matching in WebAssembly (gcs.c), Number-based JS fallback; Blockbook upstream → Atomic
The daemon's wallet scan hashed every watched script against every block
filter with a BigInt SipHash: ~3 filters/s on the VPS once the gap limits
went to 200/100 (~3,300 scripts), i.e. days for a one-year window. The
matcher now lives in dgbpow.wasm next to the PoW hashes — scripts are
uploaded once per scan, each filter is one call, the set is decoded once
and each target binary-searched — ~5,500 filters/s locally, ~2,000/s on
the VPS with block fetches. The JS path was rewritten with uint32 lanes
and exact 32×32 partial products as a fallback (module missing or filter
beyond its buffers). scripts/gcs-check.ts cross-checks both against a
BigInt reference on random filters; `npm run gcs:test -w @dgb-wallet/p2p`.

NOWNodes stopped accepting the proxy's API key ("Unknown API_key" on every
endpoint), which is why the wallet showed "Blockbook HTTP 401" for every
path. The vhost mirror now proxies /blockbook/ to Atomic Wallet's public
Blockbook; ops/blockbook-upstream.sh switches the live vhost either way.
2026-10-11 23:37:28 +02:00

50 lines
2.3 KiB
Bash

#!/usr/bin/env bash
# Point the live digibyte.x vhost's /blockbook/ proxy at a Blockbook
# upstream, test the config, reload nginx and prove the route works.
#
# ops/blockbook-upstream.sh atomic # Atomic Wallet's public Blockbook (no key)
# ops/blockbook-upstream.sh nownodes # NOWNodes, key from /etc/dgb-core/nownodes.env on the VPS
#
# Runs over `ssh silentmode`; the previous vhost is kept under
# /etc/nginx/sites-enabled-stale-baks/. The repo mirror
# ops/nginx-digibyte-x.conf documents the same two blocks.
set -euo pipefail
target="${1:-}"
case "$target" in
atomic) host=digibyte.atomicwallet.io; keyhdr=0 ;;
nownodes) host=dgbbook.nownodes.io; keyhdr=1 ;;
*) echo "usage: $0 atomic|nownodes" >&2; exit 2 ;;
esac
ssh silentmode "HOST=$host KEYHDR=$keyhdr bash -s" <<'REMOTE'
set -euo pipefail
F=/etc/nginx/sites-enabled/digibyte-x
mkdir -p /etc/nginx/sites-enabled-stale-baks
cp "$F" "/etc/nginx/sites-enabled-stale-baks/digibyte-x.bak.$(date +%s)"
KEY=""
if [ "$KEYHDR" = 1 ]; then
KEY="$(. /etc/dgb-core/nownodes.env; printf %s "$NOWNODES_API_KEY" | tr -d '\r\n ')"
[ -n "$KEY" ] || { echo "no NOWNODES_API_KEY in /etc/dgb-core/nownodes.env" >&2; exit 1; }
fi
HOST="$HOST" KEY="$KEY" python3 - "$F" <<'PY'
import os, re, sys
p = sys.argv[1]; s = open(p).read()
host, key = os.environ['HOST'], os.environ['KEY']
a = s.index(' location /blockbook/ {'); b = s.index('\n }\n', a) + 7
blk = s[a:b]
blk = re.sub(r'proxy_pass https://[^/]+/api/v2/;', f'proxy_pass https://{host}/api/v2/;', blk)
blk = re.sub(r'proxy_ssl_name [^;]+;', f'proxy_ssl_name {host};', blk)
blk = re.sub(r'proxy_set_header Host [^;]+;', f'proxy_set_header Host {host};', blk)
blk = re.sub(r'\n proxy_set_header api-key "[^"]*";', '', blk)
if key:
blk = blk.replace(' proxy_set_header X-Real-IP "";\n', f' proxy_set_header X-Real-IP "";\n proxy_set_header api-key "{key}";\n')
open(p, 'w').write(s[:a] + blk + s[b:])
print('vhost now proxies /blockbook/ ->', host, '(api-key header)' if key else '(no key)')
PY
nginx -t
systemctl reload nginx
sleep 1
code=$(curl -sk -o /dev/null -w '%{http_code}' --resolve digibyte.x:443:127.0.0.1 'https://digibyte.x/blockbook/')
echo "GET /blockbook/ via vhost -> HTTP $code"
[ "$code" = 200 ] || { echo "upstream not answering 200 — check the key / host" >&2; exit 1; }
REMOTE