Skip to content

Commit 75dc828

Browse files
committed
Rewrite electrs start scripts into a single script
1 parent 69c97c1 commit 75dc828

File tree

6 files changed

+141
-223
lines changed

6 files changed

+141
-223
lines changed

electrs-start-liquid

Lines changed: 0 additions & 33 deletions
This file was deleted.

electrs-start-liquidtestnet

Lines changed: 0 additions & 33 deletions
This file was deleted.

electrs-start-mainnet

Lines changed: 0 additions & 67 deletions
This file was deleted.

electrs-start-signet

Lines changed: 0 additions & 45 deletions
This file was deleted.

electrs-start-testnet

Lines changed: 0 additions & 45 deletions
This file was deleted.

start

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#!/usr/bin/env zsh
2+
3+
# initialize variables
4+
DAEMON=bitcoin
5+
NETWORK=mainnet
6+
FEATURES=default
7+
DB_FOLDER=/electrs
8+
NODENAME=$(hostname|cut -d . -f1)
9+
LOCATION=$(hostname|cut -d . -f2)
10+
11+
# load rust if necessary
12+
if [ -e "${HOME}/.cargo/env" ];then
13+
source "${HOME}/.cargo/env"
14+
export PATH="${HOME}/.cargo/bin:${PATH}"
15+
fi
16+
17+
# which OS?
18+
case "$(uname -s)" in
19+
FreeBSD)
20+
OS=FreeBSD
21+
NPROC=$(sysctl -n hw.ncpu)
22+
;;
23+
Darwin)
24+
OS=Darwin
25+
NPROC=$(sysctl -n hw.ncpu)
26+
;;
27+
Linux)
28+
OS=Linux
29+
NPROC=$(grep -c proc /proc/cpuinfo)
30+
;;
31+
*)
32+
OS=Unknown
33+
NPROC=4
34+
;;
35+
esac
36+
37+
# which network?
38+
case "${1}" in
39+
mainnet)
40+
THREADS=$((NPROC * 3))
41+
;;
42+
testnet)
43+
NETWORK=testnet
44+
THREADS=$((NPROC * 1))
45+
;;
46+
signet)
47+
NETWORK=signet
48+
THREADS=$((NPROC * 1))
49+
;;
50+
liquid)
51+
DAEMON=elements
52+
NETWORK=liquid
53+
FEATURES=liquid
54+
THREADS=$((NPROC * 1))
55+
;;
56+
liquidtestnet)
57+
DAEMON=elements
58+
NETWORK=liquidtestnet
59+
FEATURES=liquid
60+
THREADS=$((NPROC * 1))
61+
;;
62+
*)
63+
echo "Usage: $0 (mainnet|testnet|signet|liquid|liquidtestnet)"
64+
exit 1
65+
;;
66+
esac
67+
68+
# run in loop in case of crash
69+
until false
70+
do
71+
# reset CWD
72+
cd "${HOME}/electrs"
73+
74+
# disable making electrs.core files
75+
ulimit -c 0
76+
77+
# prepare run-time variables
78+
UTXOS_LIMIT=500
79+
ELECTRUM_TXS_LIMIT=500
80+
DAEMON_CONF="${HOME}/${DAEMON}.conf"
81+
HTTP_SOCKET_FILE="${HOME}/socket/esplora-${DAEMON}-${NETWORK}"
82+
RPC_SOCKET_FILE="${HOME}/socket/electrum-${DAEMON}-${NETWORK}"
83+
84+
# get RPC credentials from bitcoin.conf or elements.conf directly
85+
echo "[*] Getting RPC credentials from ${DAEMON_CONF}"
86+
RPC_USER=$(grep 'rpcuser=' "${DAEMON_CONF}"|cut -d = -f2|head -1)
87+
RPC_PASS=$(grep 'rpcpassword=' "${DAEMON_CONF}"|cut -d = -f2|head -1)
88+
89+
# override limits based on hostname
90+
if [ "${NODENAME}" = "node201" ];then
91+
UTXOS_LIMIT=9000
92+
ELECTRUM_TXS_LIMIT=9000
93+
fi
94+
95+
# Run the popular address txt file generator before each run
96+
POPULAR_SCRIPTS_FOLDER="${HOME}/popular-scripts/${NETWORK}"
97+
POPULAR_SCRIPTS_FILE_RAW="${POPULAR_SCRIPTS_FOLDER}/popular-scripts-raw.txt"
98+
POPULAR_SCRIPTS_FILE="${POPULAR_SCRIPTS_FOLDER}/popular-scripts.txt"
99+
mkdir -p "${POPULAR_SCRIPTS_FOLDER}"
100+
rm -f "${POPULAR_SCRIPTS_FILE_RAW}" "${POPULAR_SCRIPTS_FILE}"
101+
102+
## Use nproc * 4 threads to generate the txt file (lots of iowait, so 2x~4x core count is ok)
103+
## Only pick up addresses with 101 history events or more
104+
## (Without lowering MIN_HISTORY_ITEMS_TO_CACHE this is the lowest we can go)
105+
## It prints out progress to STDERR
106+
echo "[*] Generating popular-scripts using ${THREADS} threads..."
107+
HIGH_USAGE_THRESHOLD=101 \
108+
JOB_THREAD_COUNT=${THREADS} \
109+
cargo run \
110+
--release \
111+
--bin popular-scripts \
112+
--features "${FEATURES}" \
113+
-- \
114+
--network "${NETWORK}" \
115+
--db-dir "${DB_FOLDER}" \
116+
> "${POPULAR_SCRIPTS_FILE_RAW}"
117+
118+
## Sorted and deduplicated just in case
119+
sort "${POPULAR_SCRIPTS_FILE_RAW}" | uniq > "${POPULAR_SCRIPTS_FILE}"
120+
121+
# Run the electrs process (Note: db-dir is used in both commands)
122+
cargo run \
123+
--release \
124+
--bin electrs \
125+
--features "${FEATURES}" \
126+
-- \
127+
--network "${NETWORK}" \
128+
--daemon-dir "${HOME}" \
129+
--db-dir "${DB_FOLDER}" \
130+
--rpc-socket-file "${RPC_SOCKET_FILE}" \
131+
--http-socket-file "${HTTP_SOCKET_FILE}" \
132+
--precache-scripts "${POPULAR_SCRIPTS_FILE}" \
133+
--precache-threads "${THREADS}" \
134+
--cookie "${RPC_USER}:${RPC_PASS}" \
135+
--cors '*' \
136+
--address-search \
137+
--utxos-limit "${UTXOS_LIMIT}" \
138+
--electrum-txs-limit "${ELECTRUM_TXS_LIMIT}" \
139+
-vvv
140+
sleep 1
141+
done

0 commit comments

Comments
 (0)