-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·143 lines (130 loc) · 4.97 KB
/
Copy pathstart.sh
File metadata and controls
executable file
·143 lines (130 loc) · 4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env bash
# Start the regtest stack: bitcoind-patched, bip300301_enforcer, thunder.
#
# Each process gets a pidfile under .regtest/run/ and a logfile under
# .regtest/logs/. Re-running this script is a no-op for processes whose
# pidfile is alive (idempotent).
#
# Env:
# REGTEST_DIR chain state/log location (default: <repo>/.regtest)
# REGTEST_BIN_DIR binary cache (default: $REGTEST_DIR/bin)
# REGTEST_SKIP_THUNDER =1 to not start thunder (CI)
# REGTEST_WALLETLESS =1 to run the enforcer without its wallet.
# Template rewards then go to a fixed regtest
# address and WalletService RPCs (e.g.
# CreateDepositTransaction) are unavailable.
# Mine with MiningService/GenerateToAddress
# (enforcer PR #477).
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
REGTEST="${REGTEST_DIR:-$ROOT/.regtest}"
BIN="${REGTEST_BIN_DIR:-$REGTEST/bin}"
DATA="$REGTEST/data"
LOGS="$REGTEST/logs"
RUN="$REGTEST/run"
SKIP_THUNDER="${REGTEST_SKIP_THUNDER:-0}"
WALLETLESS="${REGTEST_WALLETLESS:-0}"
mkdir -p "$RUN"
BINARIES=(bitcoind bitcoin-cli bip300301_enforcer)
[[ "$SKIP_THUNDER" == 1 ]] || BINARIES+=(thunder thunder-cli)
for b in "${BINARIES[@]}"; do
if [[ ! -x "$BIN/$b" ]]; then
echo "missing $BIN/$b — run scripts/regtest/setup.sh first" >&2
exit 1
fi
done
is_alive() {
local pid="$1"
[[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null
}
start_if_dead() {
local name="$1"; shift
local pidfile="$RUN/$name.pid"
if [[ -f "$pidfile" ]] && is_alive "$(cat "$pidfile")"; then
echo " $name already running (pid $(cat "$pidfile"))"
return
fi
echo " starting $name"
"$@" >> "$LOGS/$name.log" 2>&1 &
echo $! > "$pidfile"
disown $!
}
wait_for() {
local name="$1"; local check="$2"; local timeout="${3:-30}"
for ((i = 0; i < timeout; i++)); do
if eval "$check" >/dev/null 2>&1; then
echo " $name ready"
return
fi
sleep 1
done
echo " $name failed to come up in ${timeout}s; check $LOGS/$name.log" >&2
exit 2
}
echo "==> starting bitcoind"
start_if_dead bitcoind \
"$BIN/bitcoind" \
-datadir="$DATA/bitcoind" \
-conf="$DATA/bitcoind/bitcoin.conf" \
-daemonwait=0
wait_for bitcoind "$BIN/bitcoin-cli -datadir=$DATA/bitcoind -regtest \
-rpcuser=user -rpcpassword=password getblockchaininfo"
# Create / load the miner wallet (descriptor wallet is the only supported
# kind on Bitcoin Core v30). Idempotent — already-loaded is fine.
"$BIN/bitcoin-cli" -datadir="$DATA/bitcoind" -regtest \
-rpcuser=user -rpcpassword=password \
-named createwallet wallet_name=miner descriptors=true 2>/dev/null \
|| "$BIN/bitcoin-cli" -datadir="$DATA/bitcoind" -regtest \
-rpcuser=user -rpcpassword=password loadwallet miner true 2>/dev/null \
|| true
echo "==> starting bip300301_enforcer"
# No electrs / electrum sync: with --wallet-sync-source=disabled the wallet
# is updated purely by incoming blocks, which is complete on a from-genesis
# regtest chain. Walletless mode drops the wallet entirely; the template
# server then needs an explicit --coinbase-recipient (any valid regtest
# address — the pool builds its own coinbase anyway).
if [[ "$WALLETLESS" == 1 ]]; then
WALLET_ARGS=(--coinbase-recipient=bcrt1qw508d6qejxtdg4y5r3zarvary0c5xw7kygt080)
else
WALLET_ARGS=(--enable-wallet --wallet-auto-create --wallet-sync-source=disabled)
fi
start_if_dead bip300301_enforcer \
"$BIN/bip300301_enforcer" \
--data-dir="$DATA/enforcer" \
--enable-mempool \
"${WALLET_ARGS[@]}" \
--node-rpc-addr=127.0.0.1:18443 \
--node-rpc-user=user \
--node-rpc-pass=password \
--node-zmq-addr-sequence=tcp://127.0.0.1:29010 \
--enable-block-template-server \
--serve-rpc-addr=127.0.0.1:18444 \
--serve-grpc-addr=127.0.0.1:50051
wait_for bip300301_enforcer "nc -z 127.0.0.1 18444" 30
# Thunder connects to the enforcer's gRPC — make sure that's actually
# up before launching it (18444 GBT can come up first).
wait_for enforcer-grpc "nc -z 127.0.0.1 50051" 15
if [[ "$SKIP_THUNDER" != 1 ]]; then
echo "==> starting thunder (sidechain #9)"
start_if_dead thunder \
"$BIN/thunder" \
--headless \
--datadir "$DATA/thunder" \
--network regtest \
--mainchain-grpc-url http://127.0.0.1:50051 \
--net-addr 127.0.0.1:4009 \
--rpc-addr 127.0.0.1:6009 \
--log-level INFO
wait_for thunder "nc -z 127.0.0.1 6009" 30
fi
echo ""
echo "stack up. endpoints:"
echo " bitcoind RPC: 127.0.0.1:18443 (user/password)"
echo " enforcer GBT: 127.0.0.1:18444 (point simplepool at this)"
echo " enforcer gRPC: 127.0.0.1:50051"
if [[ "$SKIP_THUNDER" != 1 ]]; then
echo " thunder RPC: 127.0.0.1:6009 (point payout worker at this)"
echo " thunder P2P: 127.0.0.1:4009"
fi
echo ""
echo "next: scripts/regtest/validate.sh"