-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathinstall_prover.sh
More file actions
1802 lines (1649 loc) · 61.1 KB
/
install_prover.sh
File metadata and controls
1802 lines (1649 loc) · 61.1 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# =============================================================================
# Boundless Prover Node Setup Script
# Description: Automated installation and configuration of Boundless prover node
# =============================================================================
set -euo pipefail
# Color variables
CYAN='\033[0;36m'
LIGHTBLUE='\033[1;34m'
RED='\033[0;31m'
GREEN='\033[0;32m'
PURPLE='\033[0;35m'
YELLOW='\033[1;33m'
BOLD='\033[1m'
RESET='\033[0m'
# Constants
SCRIPT_NAME="$(basename "$0")"
LOG_FILE="/var/log/boundless_prover_setup.log"
ERROR_LOG="/var/log/boundless_prover_error.log"
INSTALL_DIR="$HOME/boundless"
COMPOSE_FILE="$INSTALL_DIR/compose.yml"
BROKER_CONFIG="$INSTALL_DIR/broker.toml"
# Exit codes
EXIT_SUCCESS=0
EXIT_OS_CHECK_FAILED=1
EXIT_DPKG_ERROR=2
EXIT_DEPENDENCY_FAILED=3
EXIT_GPU_ERROR=4
EXIT_NETWORK_ERROR=5
EXIT_USER_ABORT=6
EXIT_UNKNOWN=99
# Flags
ALLOW_ROOT=false
FORCE_RECLONE=false
START_IMMEDIATELY=false
# Parse command-line arguments
while [[ $# -gt 0 ]]; do
case "$1" in
--allow-root)
ALLOW_ROOT=true
shift
;;
--force-reclone)
FORCE_RECLONE=true
shift
;;
--start-immediately)
START_IMMEDIATELY=true
shift
;;
--help)
echo "Usage: $0 [options]"
echo "Options:"
echo " --allow-root Allow running as root without prompting"
echo " --force-reclone Automatically delete and re-clone the directory if it exists"
echo " --start-immediately Automatically start the prover after installation"
echo " --help Show this help message"
exit 0
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
# Trap function for exit logging
cleanup_on_exit() {
local exit_code=$?
if [ $exit_code -ne 0 ]; then
error "Installation failed with exit code: $exit_code"
echo "[EXIT] Script exited with code: $exit_code at $(date)" >> "$ERROR_LOG"
echo "[EXIT] Last command: ${BASH_COMMAND}" >> "$ERROR_LOG"
echo "[EXIT] Line number: ${BASH_LINENO[0]}" >> "$ERROR_LOG"
echo "[EXIT] Function stack: ${FUNCNAME[@]}" >> "$ERROR_LOG"
echo -e "\n${RED}${BOLD}Installation Failed!${RESET}"
echo -e "${YELLOW}Check error log at: $ERROR_LOG${RESET}"
echo -e "${YELLOW}Check full log at: $LOG_FILE${RESET}"
case $exit_code in
$EXIT_DPKG_ERROR)
echo -e "\n${RED}DPKG Configuration Error Detected!${RESET}"
echo -e "${YELLOW}Please run the following command manually:${RESET}"
echo -e "${BOLD}dpkg --configure -a${RESET}"
echo -e "${YELLOW}Then re-run this installation script.${RESET}"
;;
$EXIT_OS_CHECK_FAILED)
echo -e "\n${RED}Operating system check failed!${RESET}"
;;
$EXIT_DEPENDENCY_FAILED)
echo -e "\n${RED}Dependency installation failed!${RESET}"
;;
$EXIT_GPU_ERROR)
echo -e "\n${RED}GPU configuration error!${RESET}"
;;
$EXIT_NETWORK_ERROR)
echo -e "\n${RED}Network configuration error!${RESET}"
;;
$EXIT_USER_ABORT)
echo -e "\n${YELLOW}Installation aborted by user.${RESET}"
;;
*)
echo -e "\n${RED}Unknown error occurred!${RESET}"
;;
esac
fi
}
# Set trap
trap cleanup_on_exit EXIT
trap 'echo "[SIGNAL] Caught signal ${?} at line ${LINENO}" >> "$ERROR_LOG"' ERR
# Network configurations
declare -A NETWORKS
NETWORKS["base"]="Base Mainnet|0x0b144e07a0826182b6b59788c34b32bfa86fb711|0x26759dbB201aFbA361Bec78E097Aa3942B0b4AB8|0x8C5a8b5cC272Fe2b74D18843CF9C3aCBc952a760|https://base-mainnet.beboundless.xyz"
NETWORKS["base-sepolia"]="Base Sepolia|0x0b144e07a0826182b6b59788c34b32bfa86fb711|0x6B7ABa661041164b8dB98E30AE1454d2e9D5f14b|0x8C5a8b5cC272Fe2b74D18843CF9C3aCBc952a760|https://base-sepolia.beboundless.xyz"
NETWORKS["eth-sepolia"]="Ethereum Sepolia|0x925d8331ddc0a1F0d96E68CF073DFE1d92b69187|0x13337C76fE2d1750246B68781ecEe164643b98Ec|0x7aAB646f23D1392d4522CFaB0b7FB5eaf6821d64|https://eth-sepolia.beboundless.xyz/"
# Functions
info() {
printf "${CYAN}[INFO]${RESET} %s\n" "$1"
echo "[INFO] $(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$LOG_FILE"
}
success() {
printf "${GREEN}[SUCCESS]${RESET} %s\n" "$1"
echo "[SUCCESS] $(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$LOG_FILE"
}
error() {
printf "${RED}[ERROR]${RESET} %s\n" "$1" >&2
echo "[ERROR] $(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$LOG_FILE"
echo "[ERROR] $(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$ERROR_LOG"
}
warning() {
printf "${YELLOW}[WARNING]${RESET} %s\n" "$1"
echo "[WARNING] $(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$LOG_FILE"
}
prompt() {
printf "${PURPLE}[INPUT]${RESET} %s" "$1"
}
# Check for dpkg errors
check_dpkg_status() {
if dpkg --audit 2>&1 | grep -q "dpkg was interrupted"; then
error "dpkg was interrupted - manual intervention required"
return 1
fi
return 0
}
# Check OS compatibility
check_os() {
info "Checking operating system compatibility..."
if [[ -f /etc/os-release ]]; then
. /etc/os-release
if [[ "${ID,,}" != "ubuntu" ]]; then
error "Unsupported OS: $NAME. This script is for Ubuntu."
exit $EXIT_OS_CHECK_FAILED
elif [[ "${VERSION_ID,,}" != "22.04" && "${VERSION_ID,,}" != "20.04" ]]; then
warning "Tested on Ubuntu 20.04/22.04. Your version: $VERSION_ID"
read -e -p "Continue anyway? (y/N): " response
if [[ ! "$response" =~ ^[yY]$ ]]; then
exit $EXIT_USER_ABORT
fi
else
info "Operating System: $PRETTY_NAME"
fi
else
error "/etc/os-release not found. Unable to determine OS."
exit $EXIT_OS_CHECK_FAILED
fi
}
# Check if command exists
command_exists() {
command -v "$1" &> /dev/null
}
# Check if package is installed
is_package_installed() {
dpkg -s "$1" &> /dev/null
}
# Update system
update_system() {
info "Updating system packages..."
if ! check_dpkg_status; then
exit $EXIT_DPKG_ERROR
fi
{
if ! apt update -y 2>&1; then
error "apt update failed"
if apt update 2>&1 | grep -q "dpkg was interrupted"; then
exit $EXIT_DPKG_ERROR
fi
exit $EXIT_DEPENDENCY_FAILED
fi
if ! apt upgrade -y 2>&1; then
error "apt upgrade failed"
if apt upgrade 2>&1 | grep -q "dpkg was interrupted"; then
exit $EXIT_DPKG_ERROR
fi
exit $EXIT_DEPENDENCY_FAILED
fi
} >> "$LOG_FILE" 2>&1
success "System packages updated"
}
# Install basic dependencies
install_basic_deps() {
local packages=(
curl iptables build-essential git wget lz4 jq make gcc nano
automake autoconf tmux htop nvme-cli libgbm1 pkg-config
libssl-dev tar clang bsdmainutils ncdu unzip libleveldb-dev
libclang-dev ninja-build nvtop ubuntu-drivers-common
gnupg ca-certificates lsb-release postgresql-client
)
info "Installing basic dependencies..."
if ! check_dpkg_status; then
exit $EXIT_DPKG_ERROR
fi
{
if ! apt install -y "${packages[@]}" 2>&1; then
error "Failed to install basic dependencies"
if apt install -y "${packages[@]}" 2>&1 | grep -q "dpkg was interrupted"; then
exit $EXIT_DPKG_ERROR
fi
exit $EXIT_DEPENDENCY_FAILED
fi
} >> "$LOG_FILE" 2>&1
success "Basic dependencies installed"
}
# Install GPU drivers
install_gpu_drivers() {
info "Installing GPU drivers..."
if ! check_dpkg_status; then
exit $EXIT_DPKG_ERROR
fi
{
if ! ubuntu-drivers install 2>&1; then
error "Failed to install GPU drivers"
exit $EXIT_GPU_ERROR
fi
} >> "$LOG_FILE" 2>&1
success "GPU drivers installed"
}
# Install Docker
install_docker() {
if command_exists docker; then
info "Docker already installed"
return
fi
info "Installing Docker..."
if ! check_dpkg_status; then
exit $EXIT_DPKG_ERROR
fi
{
if ! apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common 2>&1; then
error "Failed to install Docker prerequisites"
if apt install -y apt-transport-https 2>&1 | grep -q "dpkg was interrupted"; then
exit $EXIT_DPKG_ERROR
fi
exit $EXIT_DEPENDENCY_FAILED
fi
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
if ! apt update -y 2>&1; then
error "Failed to update package list for Docker"
exit $EXIT_DEPENDENCY_FAILED
fi
if ! apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin 2>&1; then
error "Failed to install Docker"
if apt install -y docker-ce 2>&1 | grep -q "dpkg was interrupted"; then
exit $EXIT_DPKG_ERROR
fi
exit $EXIT_DEPENDENCY_FAILED
fi
systemctl enable docker
systemctl start docker
usermod -aG docker $(logname 2>/dev/null || echo "$USER")
} >> "$LOG_FILE" 2>&1
success "Docker installed"
}
# Install NVIDIA Container Toolkit
install_nvidia_toolkit() {
if is_package_installed "nvidia-docker2"; then
info "NVIDIA Container Toolkit already installed"
return
fi
info "Installing NVIDIA Container Toolkit..."
if ! check_dpkg_status; then
exit $EXIT_DPKG_ERROR
fi
{
distribution=$(grep '^ID=' /etc/os-release | cut -d'=' -f2 | tr -d '"')$(grep '^VERSION_ID=' /etc/os-release | cut -d'=' -f2 | tr -d '"')
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/"$distribution"/nvidia-docker.list | tee /etc/apt/sources.list.d/nvidia-docker.list
if ! apt update -y 2>&1; then
error "Failed to update package list for NVIDIA toolkit"
exit $EXIT_DEPENDENCY_FAILED
fi
if ! apt install -y nvidia-docker2 2>&1; then
error "Failed to install NVIDIA Docker support"
if apt install -y nvidia-docker2 2>&1 | grep -q "dpkg was interrupted"; then
exit $EXIT_DPKG_ERROR
fi
exit $EXIT_DEPENDENCY_FAILED
fi
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<EOF
{
"default-runtime": "nvidia",
"runtimes": {
"nvidia": {
"path": "nvidia-container-runtime",
"runtimeArgs": []
}
}
}
EOF
systemctl restart docker
} >> "$LOG_FILE" 2>&1
success "NVIDIA Container Toolkit installed"
}
# Install Rust
install_rust() {
if command_exists rustc; then
info "Rust already installed"
return
fi
info "Installing Rust..."
{
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"
rustup update
} >> "$LOG_FILE" 2>&1
success "Rust installed"
}
# Install Just
install_just() {
if command_exists just; then
info "Just already installed"
return
fi
info "Installing Just command runner..."
{
curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin
} >> "$LOG_FILE" 2>&1
success "Just installed"
}
# Install CUDA Toolkit
install_cuda() {
if is_package_installed "cuda-toolkit"; then
info "CUDA Toolkit already installed"
return
fi
info "Installing CUDA Toolkit..."
if ! check_dpkg_status; then
exit $EXIT_DPKG_ERROR
fi
{
distribution=$(grep '^ID=' /etc/os-release | cut -d'=' -f2 | tr -d '"')$(grep '^VERSION_ID=' /etc/os-release | cut -d'=' -f2 | tr -d '"'| tr -d '\.')
if ! wget https://developer.download.nvidia.com/compute/cuda/repos/$distribution/$(/usr/bin/uname -m)/cuda-keyring_1.1-1_all.deb 2>&1; then
error "Failed to download CUDA keyring"
exit $EXIT_DEPENDENCY_FAILED
fi
if ! dpkg -i cuda-keyring_1.1-1_all.deb 2>&1; then
error "Failed to install CUDA keyring"
rm cuda-keyring_1.1-1_all.deb
exit $EXIT_DEPENDENCY_FAILED
fi
rm cuda-keyring_1.1-1_all.deb
if ! apt-get update 2>&1; then
error "Failed to update package list for CUDA"
exit $EXIT_DEPENDENCY_FAILED
fi
if ! apt-get install -y cuda-toolkit 2>&1; then
error "Failed to install CUDA Toolkit"
if apt-get install -y cuda-toolkit 2>&1 | grep -q "dpkg was interrupted"; then
exit $EXIT_DPKG_ERROR
fi
exit $EXIT_DEPENDENCY_FAILED
fi
} >> "$LOG_FILE" 2>&1
success "CUDA Toolkit installed"
}
# Install Rust dependencies
install_rust_deps() {
info "Installing Rust dependencies..."
# Source the Rust environment
source "$HOME/.cargo/env" || {
error "Failed to source $HOME/.cargo/env. Ensure Rust is installed."
exit $EXIT_DEPENDENCY_FAILED
}
# Check and install cargo if not present
if ! command_exists cargo; then
if ! check_dpkg_status; then
exit $EXIT_DPKG_ERROR
fi
info "Installing cargo..."
apt update >> "$LOG_FILE" 2>&1 || {
error "Failed to update package list for cargo"
exit $EXIT_DEPENDENCY_FAILED
}
apt install -y cargo >> "$LOG_FILE" 2>&1 || {
error "Failed to install cargo"
if apt install -y cargo 2>&1 | grep -q "dpkg was interrupted"; then
exit $EXIT_DPKG_ERROR
fi
exit $EXIT_DEPENDENCY_FAILED
}
fi
# Always install rzup and the RISC Zero Rust toolchain
info "Installing rzup..."
curl -L https://risczero.com/install | bash >> "$LOG_FILE" 2>&1 || {
error "Failed to install rzup"
exit $EXIT_DEPENDENCY_FAILED
}
# Update PATH in the current shell
export PATH="$PATH:/root/.risc0/bin"
# Source bashrc to ensure environment is updated
PS1='' source ~/.bashrc >> "$LOG_FILE" 2>&1 || {
error "Failed to source ~/.bashrc after rzup install"
exit $EXIT_DEPENDENCY_FAILED
}
# Install RISC Zero Rust toolchain
rzup install rust >> "$LOG_FILE" 2>&1 || {
error "Failed to install RISC Zero Rust toolchain"
exit $EXIT_DEPENDENCY_FAILED
}
# Detect the RISC Zero toolchain
TOOLCHAIN=$(rustup toolchain list | grep risc0 | head -1)
if [ -z "$TOOLCHAIN" ]; then
error "No RISC Zero toolchain found after installation"
exit $EXIT_DEPENDENCY_FAILED
fi
info "Using RISC Zero toolchain: $TOOLCHAIN"
# Install cargo-risczero
if ! command_exists cargo-risczero; then
info "Installing cargo-risczero..."
cargo install cargo-risczero >> "$LOG_FILE" 2>&1 || {
error "Failed to install cargo-risczero"
exit $EXIT_DEPENDENCY_FAILED
}
rzup install cargo-risczero >> "$LOG_FILE" 2>&1 || {
error "Failed to install cargo-risczero via rzup"
exit $EXIT_DEPENDENCY_FAILED
}
fi
# Install bento-client with the RISC Zero toolchain
info "Installing bento-client..."
RUSTUP_TOOLCHAIN=$TOOLCHAIN cargo install --locked --git https://github.com/risc0/risc0 bento-client --branch release-2.3 --bin bento_cli
>> "$LOG_FILE" 2>&1 || {
error "Failed to install bento-client"
exit $EXIT_DEPENDENCY_FAILED
}
# Persist PATH for cargo binaries
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.bashrc
PS1='' source ~/.bashrc >> "$LOG_FILE" 2>&1 || {
error "Failed to source ~/.bashrc after installing bento-client"
exit $EXIT_DEPENDENCY_FAILED
}
# Install boundless-cli
info "Installing boundless-cli..."
cargo install --locked boundless-cli >> "$LOG_FILE" 2>&1 || {
error "Failed to install boundless-cli"
exit $EXIT_DEPENDENCY_FAILED
}
# Update PATH for boundless-cli
export PATH="$PATH:/root/.cargo/bin"
PS1='' source ~/.bashrc >> "$LOG_FILE" 2>&1 || {
error "Failed to source ~/.bashrc after installing boundless-cli"
exit $EXIT_DEPENDENCY_FAILED
}
success "Rust dependencies installed"
}
# Clone Boundless repository
clone_repository() {
info "Setting up Boundless repository..."
if [[ -d "$INSTALL_DIR" ]]; then
if [[ "$FORCE_RECLONE" == "true" ]]; then
warning "Deleting existing directory $INSTALL_DIR (forced via --force-reclone)"
rm -rf "$INSTALL_DIR"
else
warning "Boundless directory already exists at $INSTALL_DIR"
read -e -p "Delete and re-clone? (y/N): " response
if [[ "$response" =~ ^[yY]$ ]]; then
rm -rf "$INSTALL_DIR"
else
cd "$INSTALL_DIR"
if ! git pull origin release-0.13 2>&1 >> "$LOG_FILE"; then
error "Failed to update repository"
exit $EXIT_DEPENDENCY_FAILED
fi
return
fi
fi
fi
{
if ! git clone https://github.com/boundless-xyz/boundless "$INSTALL_DIR" 2>&1; then
error "Failed to clone repository"
exit $EXIT_DEPENDENCY_FAILED
fi
cd "$INSTALL_DIR"
if ! git checkout release-0.13 2>&1; then
error "Failed to checkout release-0.13"
exit $EXIT_DEPENDENCY_FAILED
fi
if ! git submodule update --init --recursive 2>&1; then
error "Failed to initialize submodules"
exit $EXIT_DEPENDENCY_FAILED
fi
} >> "$LOG_FILE" 2>&1
success "Repository cloned and initialized"
}
# Detect GPU configuration
detect_gpus() {
info "Detecting GPU configuration..."
if ! command_exists nvidia-smi; then
error "nvidia-smi not found. GPU drivers may not be installed correctly."
exit $EXIT_GPU_ERROR
fi
GPU_COUNT=$(nvidia-smi -L 2>/dev/null | wc -l)
if [[ $GPU_COUNT -eq 0 ]]; then
error "No GPUs detected"
exit $EXIT_GPU_ERROR
fi
info "Found $GPU_COUNT GPU(s)"
GPU_MEMORY=()
for i in $(seq 0 $((GPU_COUNT - 1))); do
MEM=$(nvidia-smi -i $i --query-gpu=memory.total --format=csv,noheader,nounits 2>/dev/null | tr -d ' ')
if [[ -z "$MEM" ]]; then
error "Failed to detect GPU $i memory"
exit $EXIT_GPU_ERROR
fi
GPU_MEMORY+=($MEM)
info "GPU $i: ${MEM}MB VRAM"
done
MIN_VRAM=$(printf '%s\n' "${GPU_MEMORY[@]}" | sort -n | head -1)
if [[ $MIN_VRAM -ge 40000 ]]; then
SEGMENT_SIZE=22
elif [[ $MIN_VRAM -ge 20000 ]]; then
SEGMENT_SIZE=21
elif [[ $MIN_VRAM -ge 16000 ]]; then
SEGMENT_SIZE=20
elif [[ $MIN_VRAM -ge 12000 ]]; then
SEGMENT_SIZE=19
elif [[ $MIN_VRAM -ge 8000 ]]; then
SEGMENT_SIZE=18
else
SEGMENT_SIZE=17
fi
info "Setting SEGMENT_SIZE=$SEGMENT_SIZE based on minimum VRAM of ${MIN_VRAM}MB"
}
# Configure compose.yml for multiple GPUs
configure_compose() {
info "Configuring compose.yml for $GPU_COUNT GPU(s)..."
cat > "$COMPOSE_FILE" << 'EOF'
name: bento
# Anchors:
x-base-environment: &base-environment
DATABASE_URL: postgresql://${POSTGRES_USER:-worker}:${POSTGRES_PASSWORD:-password}@${POSTGRES_HOST:-postgres}:${POSTGRES_PORT:-5432}/${POSTGRES_DB:-taskdb}
REDIS_URL: redis://${REDIS_HOST:-redis}:6379
S3_URL: http://${MINIO_HOST:-minio}:9000
S3_BUCKET: ${MINIO_BUCKET:-workflow}
S3_ACCESS_KEY: ${MINIO_ROOT_USER:-admin}
S3_SECRET_KEY: ${MINIO_ROOT_PASS:-password}
RUST_LOG: ${RUST_LOG:-info}
RUST_BACKTRACE: 1
x-agent-common: &agent-common
image: risczero/risc0-bento-agent:stable@sha256:c6fcc92686a5d4b20da963ebba3045f09a64695c9ba9a9aa984dd98b5ddbd6f9
restart: always
runtime: nvidia
depends_on:
- postgres
- redis
- minio
environment:
<<: *base-environment
x-exec-agent-common: &exec-agent-common
<<: *agent-common
mem_limit: 4G
cpus: 3
environment:
<<: *base-environment
RISC0_KECCAK_PO2: ${RISC0_KECCAK_PO2:-17}
entrypoint: /app/agent -t exec --segment-po2 ${SEGMENT_SIZE:-21}
x-broker-environment: &broker-environment
RUST_LOG: ${RUST_LOG:-info,broker=debug,boundless_market=debug}
# RUST_BACKTRACE: 1
PRIVATE_KEY: ${PRIVATE_KEY}
RPC_URL: ${RPC_URL}
BOUNDLESS_MARKET_ADDRESS:
SET_VERIFIER_ADDRESS:
ORDER_STREAM_URL:
# TODO these env vars are temporary for handling cancellations. These should be removed when
# updated.
POSTGRES_HOST:
POSTGRES_DB:
POSTGRES_PORT:
POSTGRES_USER:
POSTGRES_PASS:
x-broker-common: &broker-common
restart: always
depends_on:
- rest_api
EOF
for i in $(seq 0 $((GPU_COUNT - 1))); do
echo " - gpu_prove_agent$i" >> "$COMPOSE_FILE"
done
cat >> "$COMPOSE_FILE" << 'EOF'
- exec_agent0
- exec_agent1
- aux_agent
- snark_agent
- redis
- postgres
profiles: [broker]
build:
context: .
dockerfile: dockerfiles/broker.dockerfile
mem_limit: 2G
cpus: 2
stop_grace_period: 3h
network_mode: host
services:
redis:
hostname: ${REDIS_HOST:-redis}
image: ${REDIS_IMG:-redis:7.2.5-alpine3.19}
restart: always
ports:
- 6379:6379
volumes:
- redis-data:/data
postgres:
hostname: ${POSTGRES_HOST:-postgres}
image: ${POSTGRES_IMG:-postgres:16.3-bullseye}
restart: always
environment:
POSTGRES_DB: ${POSTGRES_DB:-taskdb}
POSTGRES_USER: ${POSTGRES_USER:-worker}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-password}
expose:
- '${POSTGRES_PORT:-5432}'
ports:
- '${POSTGRES_PORT:-5432}:${POSTGRES_PORT:-5432}'
volumes:
- postgres-data:/var/lib/postgresql/data
command: -p ${POSTGRES_PORT:-5432}
minio:
hostname: ${MINIO_HOST:-minio}
image: ${MINIO_IMG:-minio/minio:RELEASE.2024-05-28T17-19-04Z}
restart: always
ports:
- '9000:9000'
- '9001:9001'
volumes:
- minio-data:/data
command: server /data --console-address ":9001"
environment:
- MINIO_ROOT_USER=${MINIO_ROOT_USER:-admin}
- MINIO_ROOT_PASSWORD=${MINIO_ROOT_PASS:-password}
- MINIO_DEFAULT_BUCKETS=${MINIO_BUCKET:-workflow}
healthcheck:
test: ["CMD", "mc", "ready", "local"]
interval: 5s
timeout: 5s
retries: 5
grafana:
image: ${GRAFANA_IMG:-grafana/grafana:11.0.0}
restart: unless-stopped
ports:
- '3000:3000'
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=admin
- GF_LOG_LEVEL=WARN
- POSTGRES_HOST=${POSTGRES_HOST:-postgres}
- POSTGRES_DB=${POSTGRES_DB:-taskdb}
- POSTGRES_PORT=${POSTGRES_PORT:-5432}
- POSTGRES_USER=${POSTGRES_USER:-worker}
- POSTGRES_PASS=${POSTGRES_PASSWORD:-password}
- GF_INSTALL_PLUGINS=frser-sqlite-datasource
volumes:
- ./dockerfiles/grafana:/etc/grafana/provisioning/
- grafana-data:/var/lib/grafana
- broker-data:/db
depends_on:
- postgres
- redis
- minio
exec_agent0:
<<: *exec-agent-common
exec_agent1:
<<: *exec-agent-common
aux_agent:
<<: *agent-common
mem_limit: 256M
cpus: 1
entrypoint: /app/agent -t aux --monitor-requeue
EOF
for i in $(seq 0 $((GPU_COUNT - 1))); do
cat >> "$COMPOSE_FILE" << EOF
gpu_prove_agent$i:
<<: *agent-common
mem_limit: 4G
cpus: 4
entrypoint: /app/agent -t prove
deploy:
resources:
reservations:
devices:
- driver: nvidia
device_ids: ['$i']
capabilities: [gpu]
EOF
done
cat >> "$COMPOSE_FILE" << 'EOF'
snark_agent:
<<: *agent-common
entrypoint: /app/agent -t snark
ulimits:
stack: 90000000
rest_api:
image: risczero/risc0-bento-rest-api:stable@sha256:7b5183811675d0aa3646d079dec4a7a6d47c84fab4fa33d3eb279135f2e59207
restart: always
depends_on:
- postgres
- minio
mem_limit: 1G
cpus: 1
environment:
<<: *base-environment
ports:
- '8081:8081'
entrypoint: /app/rest_api --bind-addr 0.0.0.0:8081 --snark-timeout ${SNARK_TIMEOUT:-180}
broker:
<<: *broker-common
volumes:
- type: bind
source: ./broker.toml
target: /app/broker.toml
- broker-data:/db/
# Uncomment when using locally built set-builder and assessor guest programs
# - type: bind
# source: ./target/riscv-guest/guest-set-builder/set-builder/riscv32im-risc0-zkvm-elf/release/set-builder.bin
# target: /target/riscv-guest/guest-set-builder/set-builder/riscv32im-risc0-zkvm-elf/release/set-builder.bin
# - type: bind
# source: ./target/riscv-guest/guest-assessor/assessor-guest/riscv32im-risc0-zkvm-elf/release/assessor-guest.bin
# target: /target/riscv-guest/guest-assessor/assessor-guest/riscv32im-risc0-zkvm-elf/release/assessor-guest.bin
environment:
<<: *broker-environment
PRIVATE_KEY: ${PRIVATE_KEY}
RPC_URL: ${RPC_URL}
entrypoint: /app/broker --db-url 'sqlite:///db/broker.db' --config-file /app/broker.toml --bento-api-url http://localhost:8081
# # Example second broker with different configuration
# broker2:
# <<: *broker-common
# volumes:
# - type: bind
# source: ./broker2.toml
# target: /app/broker.toml
# - broker2-data:/db/
# environment:
# <<: *broker-environment
# # Note: use a different variable if you want to use different private keys in each broker
# PRIVATE_KEY: ${PRIVATE_KEY}
# RPC_URL: ${RPC_URL_2}
# entrypoint: /app/broker --db-url 'sqlite:///db/broker2.db' --config-file /app/broker.toml --bento-api-url http://localhost:8081
volumes:
redis-data:
postgres-data:
minio-data:
grafana-data:
broker-data:
# broker2-data:
EOF
success "compose.yml configured for $GPU_COUNT GPU(s)"
}
# Configure network
configure_network() {
info "Configuring network settings..."
echo -e "\n${BOLD}Available Networks:${RESET}"
echo "1) Base Mainnet"
echo "2) Base Sepolia (Testnet)"
echo "3) Ethereum Sepolia (Testnet)"
read -e -p "Select network (1-3): " network_choice
case $network_choice in
1) NETWORK="base" ;;
2) NETWORK="base-sepolia" ;;
3) NETWORK="eth-sepolia" ;;
*)
error "Invalid network choice"
exit $EXIT_NETWORK_ERROR
;;
esac
IFS='|' read -r NETWORK_NAME VERIFIER_ADDRESS BOUNDLESS_MARKET_ADDRESS SET_VERIFIER_ADDRESS ORDER_STREAM_URL <<< "${NETWORKS[$NETWORK]}"
info "Selected: $NETWORK_NAME"
echo -e "\n${BOLD}RPC Configuration:${RESET}"
echo "RPC must support eth_newBlockFilter. Recommended providers:"
echo "- BlockPi (free for Base networks)"
echo "- Alchemy"
echo "- Chainstack (set lookback_blocks=0)"
echo "- Your own node"
read -e -p "Enter RPC URL: " RPC_URL
if [[ -z "$RPC_URL" ]]; then
error "RPC URL cannot be empty"
exit $EXIT_NETWORK_ERROR
fi
read -e -p "Enter your wallet private key (without 0x prefix): " PRIVATE_KEY
echo
if [[ -z "$PRIVATE_KEY" ]]; then
error "Private key cannot be empty"
exit $EXIT_NETWORK_ERROR
fi
cat > "$INSTALL_DIR/.env.broker" << EOF
# Network: $NETWORK_NAME
export VERIFIER_ADDRESS=$VERIFIER_ADDRESS
export BOUNDLESS_MARKET_ADDRESS=$BOUNDLESS_MARKET_ADDRESS
export SET_VERIFIER_ADDRESS=$SET_VERIFIER_ADDRESS
export ORDER_STREAM_URL="$ORDER_STREAM_URL"
export RPC_URL="$RPC_URL"
export PRIVATE_KEY=$PRIVATE_KEY
export SEGMENT_SIZE=$SEGMENT_SIZE
# Prover node configs
RUST_LOG=info
REDIS_HOST=redis
REDIS_IMG=redis:7.2.5-alpine3.19
POSTGRES_HOST=postgres
POSTGRES_IMG=postgres:16.3-bullseye
POSTGRES_DB=taskdb
POSTGRES_PORT=5432
POSTGRES_USER=worker
POSTGRES_PASSWORD=password
MINIO_HOST=minio
MINIO_IMG=minio/minio:RELEASE.2024-05-28T17-19-04Z
MINIO_ROOT_USER=admin
MINIO_ROOT_PASS=password
MINIO_BUCKET=workflow
GRAFANA_IMG=grafana/grafana:11.0.0
RISC0_KECCAK_PO2=17
EOF
cat > "$INSTALL_DIR/.env.base" << EOF
export VERIFIER_ADDRESS=0x0b144e07a0826182b6b59788c34b32bfa86fb711
export BOUNDLESS_MARKET_ADDRESS=0x26759dbB201aFbA361Bec78E097Aa3942B0b4AB8
export SET_VERIFIER_ADDRESS=0x8C5a8b5cC272Fe2b74D18843CF9C3aCBc952a760
export ORDER_STREAM_URL="https://base-mainnet.beboundless.xyz"
export RPC_URL="$RPC_URL"
export PRIVATE_KEY=$PRIVATE_KEY
export SEGMENT_SIZE=$SEGMENT_SIZE
EOF
cat > "$INSTALL_DIR/.env.base-sepolia" << EOF
export VERIFIER_ADDRESS=0x0b144e07a0826182b6b59788c34b32bfa86fb711
export BOUNDLESS_MARKET_ADDRESS=0x6B7ABa661041164b8dB98E30AE1454d2e9D5f14b
export SET_VERIFIER_ADDRESS=0x8C5a8b5cC272Fe2b74D18843CF9C3aCBc952a760
export ORDER_STREAM_URL="https://base-sepolia.beboundless.xyz"
export RPC_URL="$RPC_URL"
export PRIVATE_KEY=$PRIVATE_KEY
export SEGMENT_SIZE=$SEGMENT_SIZE
EOF
cat > "$INSTALL_DIR/.env.eth-sepolia" << EOF
export VERIFIER_ADDRESS=0x925d8331ddc0a1F0d96E68CF073DFE1d92b69187
export BOUNDLESS_MARKET_ADDRESS=0x13337C76fE2d1750246B68781ecEe164643b98Ec
export SET_VERIFIER_ADDRESS=0x7aAB646f23D1392d4522CFaB0b7FB5eaf6821d64
export ORDER_STREAM_URL="https://eth-sepolia.beboundless.xyz/"
export RPC_URL="$RPC_URL"
export PRIVATE_KEY=$PRIVATE_KEY
export SEGMENT_SIZE=$SEGMENT_SIZE
EOF
chmod 600 "$INSTALL_DIR/.env.broker"
chmod 600 "$INSTALL_DIR/.env.base"
chmod 600 "$INSTALL_DIR/.env.base-sepolia"
chmod 600 "$INSTALL_DIR/.env.eth-sepolia"
success "Network configuration saved"
}
# Configure broker.toml
configure_broker() {
info "Configuring broker settings..."
cp "$INSTALL_DIR/broker-template.toml" "$BROKER_CONFIG"
echo -e "\n${BOLD}Broker Configuration:${RESET}"
echo "Configure key parameters (press Enter to keep defaults):"
echo -e "\n${CYAN}mcycle_price${RESET}: Price per million cycles in native token"
echo "Lower = more competitive, but less profit"
read -e -p "mcycle_price [default: 0.0000005]: " mcycle_price
mcycle_price=${mcycle_price:-0.0000005}
echo -e "\n${CYAN}peak_prove_khz${RESET}: Maximum proving speed in kHz"
echo "Later, Benchmark GPUs via managemet script, then set this based on the result"
read -e -p "peak_prove_khz [default: 100]: " peak_prove_khz
peak_prove_khz=${peak_prove_khz:-100}
echo -e "\n${CYAN}max_mcycle_limit${RESET}: Maximum cycles to accept (in millions)"
echo "Higher = accept larger proofs"
read -e -p "max_mcycle_limit [default: 8000]: " max_mcycle_limit
max_mcycle_limit=${max_mcycle_limit:-8000}
echo -e "\n${CYAN}min_deadline${RESET}: Minimum seconds before deadline"
echo "Higher = safer, but may miss orders with a deadline lower than min. value you set"
read -e -p "min_deadline [default: 300]: " min_deadline
min_deadline=${min_deadline:-300}
echo -e "\n${CYAN}max_concurrent_proofs${RESET}: Maximum parallel proofs"
echo "Higher = more throughput, but risk of missing deadlines"
read -e -p "max_concurrent_proofs [default: 2]: " max_concurrent_proofs
max_concurrent_proofs=${max_concurrent_proofs:-2}
echo -e "\n${CYAN}lockin_priority_gas${RESET}: Extra gas for lock transactions (Gwei)"
echo "Important metric to win other provers in bidding orders"
echo "Higher = better chance of winning bids"
read -e -p "lockin_priority_gas [default: 0]: " lockin_priority_gas
sed -i "s/mcycle_price = \"[^\"]*\"/mcycle_price = \"$mcycle_price\"/" "$BROKER_CONFIG"
sed -i "s/peak_prove_khz = [0-9]*/peak_prove_khz = $peak_prove_khz/" "$BROKER_CONFIG"
sed -i "s/max_mcycle_limit = [0-9]*/max_mcycle_limit = $max_mcycle_limit/" "$BROKER_CONFIG"
sed -i "s/min_deadline = [0-9]*/min_deadline = $min_deadline/" "$BROKER_CONFIG"
sed -i "s/max_concurrent_proofs = [0-9]*/max_concurrent_proofs = $max_concurrent_proofs/" "$BROKER_CONFIG"
if [[ -n "$lockin_priority_gas" ]]; then
sed -i "s/#lockin_priority_gas = [0-9]*/lockin_priority_gas = $lockin_priority_gas/" "$BROKER_CONFIG"
fi
success "Broker configuration saved"
}
# Create management script
create_management_script() {
info "Creating management script..."
cat > "$INSTALL_DIR/prover.sh" << 'EOF'
#!/bin/bash
export PATH="$HOME/.cargo/bin:$PATH"
INSTALL_DIR="$(dirname "$0")"
cd "$INSTALL_DIR"
# Color variables
CYAN='\033[0;36m'
LIGHTBLUE='\033[1;34m'
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
PURPLE='\033[0;35m'
ORANGE='\033[0;33m'
BOLD='\033[1m'
RESET='\033[0m'
GRAY='\033[0;90m'
# Menu options with categories
declare -a menu_items=(
"SERVICE:Service Management"
"Start Broker"
"Start Bento (testing only)"
"Stop Services"
"View Logs"
"Health Check"
"SEPARATOR:"
"CONFIG:Configuration"
"Change Network"
"Change Private Key"
"Edit Broker Config"
"SEPARATOR:"