forked from Ferret-san/nitro-testnode
-
Notifications
You must be signed in to change notification settings - Fork 9
/
celestia-start.sh
executable file
·161 lines (136 loc) · 4.25 KB
/
celestia-start.sh
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
#!/bin/bash
# Exit on error
set -e
# Store the root directory
ROOT_DIR=$(pwd)
# Function to cleanup processes on exit
cleanup() {
echo "Cleaning up processes..."
# Kill celestia-light-node process
pkill -f "celestia light" || true
# Kill celestia-server process
pkill -f "celestia-server" || true
# Kill any remaining background processes
jobs -p | xargs kill -9 2>/dev/null || true
# Cleanup Docker containers
echo "Cleaning up Docker containers..."
docker compose down || true
leftoverContainers=$(docker container ls -a --filter label=com.docker.compose.project=nitro-testnode -q)
if [ ! -z "$leftoverContainers" ]; then
docker rm -f $leftoverContainers || true
fi
}
# Set trap for cleanup on script exit
trap cleanup EXIT INT TERM
# Initialize flags
VALIDATE=false
ANYTRUST=false
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
--validate)
VALIDATE=true
shift
;;
--anytrust)
ANYTRUST=true
shift
;;
*)
echo "Unknown parameter: $1"
echo "Usage: $0 [--validate] [--anytrust]"
exit 1
;;
esac
done
# Create logs directory if it doesn't exist and clean previous logs
echo "Cleaning previous logs..."
rm -rf ${ROOT_DIR}/logs
mkdir -p ${ROOT_DIR}/logs
# Check if git is installed
if ! command -v git &> /dev/null; then
echo "Git is not installed. Please install Git first."
exit 1
fi
# Check if just is installed
if ! command -v just &> /dev/null; then
echo "Just is not installed. Please install Just first."
exit 1
fi
# Check if go is installed
if ! command -v go &> /dev/null; then
echo "Go is not installed. Please install Go first."
exit 1
fi
# Kill any existing celestia processes and docker containers
echo "Checking for existing processes and containers..."
pkill -f "celestia light" || true
pkill -f "celestia-server" || true
docker compose down || true
leftoverContainers=$(docker container ls -a --filter label=com.docker.compose.project=nitro-testnode -q)
if [ ! -z "$leftoverContainers" ]; then
docker rm -f $leftoverContainers || true
fi
sleep 2 # Give processes time to shut down
# Clone or use existing celestia-node
if [ ! -d "${ROOT_DIR}/celestia-node" ]; then
echo "Cloning celestia-node repository..."
git clone https://github.com/Ferret-san/celestia-node.git
else
echo "Using existing celestia-node repository..."
fi
cd ${ROOT_DIR}/celestia-node
git checkout easy-node
# Start light node in the background with logging
echo "Starting light node..."
just light arabica up > ${ROOT_DIR}/logs/light-node.log 2>&1 &
LIGHT_PID=$!
# Give the light node some time to start
echo "Waiting for light node to initialize..."
sleep 30
# Get auth token
echo "Getting auth token..."
AUTH_TOKEN=$(celestia light auth admin --p2p.network arabica)
echo "Auth token obtained: $AUTH_TOKEN"
# Clone or use existing nitro-das-celestia
cd ${ROOT_DIR}
if [ ! -d "nitro-das-celestia" ]; then
echo "Cloning nitro-das-celestia repository..."
git clone https://github.com/celestiaorg/nitro-das-celestia.git
else
echo "Using existing nitro-das-celestia repository..."
fi
cd nitro-das-celestia/cmd
echo "Building celestia-server..."
go build -o celestia-server
# Run celestia-server with logging in background
echo "Starting celestia-server..."
./celestia-server \
--enable-rpc \
--celestia.gas-price 0.01 \
--celestia.gas-multiplier 1.01 \
--celestia.namespace-id "000008e5f679bf7116cb" \
--celestia.rpc "http://localhost:26658" \
--celestia.keyname "my_celes_key" \
--celestia.auth-token "${AUTH_TOKEN}" \
--rpc-port 9875 > ${ROOT_DIR}/logs/celestia-server.log 2>&1 &
SERVER_PID=$!
# Wait for celestia-server to initialize
echo "Waiting for celestia-server to initialize..."
sleep 30
# Build testnode command with optional flags
TESTNODE_CMD="./test-node.bash --init-force --dev"
if $VALIDATE; then
TESTNODE_CMD="$TESTNODE_CMD --validate"
fi
if $ANYTRUST; then
TESTNODE_CMD="$TESTNODE_CMD --l2-anytrust"
fi
# Change to the root directory to run test-node.bash
cd ${ROOT_DIR}
echo "Starting Arbitrum test node with command: $TESTNODE_CMD"
chmod +x test-node.bash
# Run the command
$TESTNODE_CMD
# Keep the script running
wait