-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode.sh
executable file
·164 lines (126 loc) · 6.35 KB
/
node.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
162
163
164
#!/bin/bash
set -exu
set -o pipefail
# Check if jq is installed
if ! command -v jq &> /dev/null; then
echo "Error: jq is not installed. Please install jq first."
exit 1
fi
trap 'echo "Error on line $LINENO"; exit 1' ERR
# Function to handle the cleanup
cleanup() {
echo "Caught Ctrl+C. Killing active background processes and exiting."
kill $(jobs -p) # Kills all background processes started in this script
exit
}
# Trap the SIGINT signal and call the cleanup function when it's caught
trap 'cleanup' SIGINT
# Kill any hanging geth or beaconkit instances to prevent port clashes
pkill geth || echo "No existing geth processes"
pkill beacond || echo "No existing beaconkit processes"
# Detect if a node has already been started before. If the config directory already exists, it is assumed that we will
# continue operations from a previously started node. Delete the 'config' directory to start from scratch
echo "🐻⛓️ BM. You're off to a bearilliant start 🐻⛓️"
if [ -d "config" ]; then
echo "Config directory exists. Continuing from a previously started node."
FRESH_START=false
else
echo "Starting node from scratch."
FRESH_START=true
fi
BEACON_CONFIG_DIR=./config/beacond
EL_CONFIG_DIR=./config/geth
# Make the configuration directories
mkdir -p $BEACON_CONFIG_DIR
mkdir -p $EL_CONFIG_DIR
############################## START: TWEAK THESE AS NECESSARY ###########################
# The CL network to operate on. Default is bArtio. Should be updated alongside the EL_CHAIN_ID
CL_CHAIN_ID=bartio-beacon-80084
EL_CHAIN_ID=80084
# The location of the beacond binary. This location is the default if following the README
BEACOND_BINARY=./dependencies/beacon-kit/build/bin/beacond
# The location of the geth binary. This location is the default if following the README
GETH_BINARY=./dependencies/go-ethereum/build/bin/geth
# Feel free to replace the name below with a node name of your choice. It has little impact. It will node be used
MONIKER_NAME=BIG_BERA_DEFAULT_QUICKSTART_NODE_$(date +"%s")
# If USE_SNAPSHOT is true, then a snapshot will be downloaded to bootstrap the state, allowing for faster sync time.
# Introduces a trust assumption that the snapshot provider is trustworthy. Defaults to false
USE_SNAPSHOT=${USE_SNAPSHOT:-false}
SNAPSHOTS_DIRECTORY=./snapshots
# Update to use a source closer to your geography.
# Sources can be found here https://storage.googleapis.com/bartio-snapshot-as/index.html
CL_SNAPSHOT_SOURCE=https://storage.googleapis.com/bartio-snapshot-as/beacon/pruned/snapshot_beacond_pruned_20241216120039.tar
EL_SNAPSHOT_SOURCE=https://storage.googleapis.com/bartio-snapshot-as/exec/geth/pruned/snapshot_geth_pruned_20241216120535.tar
############################## END: TWEAK THESE AS NECESSARY ###########################
# Rename the jwt path in app.toml
JWT_PATH=$BEACON_CONFIG_DIR/jwt.hex;
# If starting node from scratch, execute the following
if [ "$FRESH_START" = true ]; then
# Cleanup any dirty state or files
# Initialise the config files necessary for beaconkit
$BEACOND_BINARY init $MONIKER_NAME --chain-id $CL_CHAIN_ID --consensus-key-algo bls12_381 --home ./config/beacond
# Copy network files for the chosen network into working config directory
cp networks/$EL_CHAIN_ID/genesis.json $BEACON_CONFIG_DIR/config/genesis.json
cp networks/$EL_CHAIN_ID/kzg-trusted-setup.json $BEACON_CONFIG_DIR/kzg-trusted-setup.json
cp networks/$EL_CHAIN_ID/app.toml $BEACON_CONFIG_DIR/config/app.toml
cp networks/$EL_CHAIN_ID/config.toml $BEACON_CONFIG_DIR/config/config.toml
# Rename the moniker in config.toml to the one configured in this script
sed -i.bak "s/^moniker = \".*\"/moniker = \"$MONIKER_NAME\"/" "$BEACON_CONFIG_DIR/config/config.toml" && rm -f "$BEACON_CONFIG_DIR/config/config.toml.bak"
# Update the jwt-secret-path in app.toml
sed -i.bak "s|^jwt-secret-path = \".*\"|jwt-secret-path = \"$JWT_PATH\"|" "$BEACON_CONFIG_DIR/config/app.toml" && rm -f "$BEACON_CONFIG_DIR/config/app.toml.bak"
# Add the CL seeds to the config.toml
seeds=$(cat networks/$EL_CHAIN_ID/cl-seeds.txt | tail -n +2 | tr '\n' ',' | sed 's/,$//')
sed -i.bak "s/^seeds = \".*\"/seeds = \"$seeds\"/" "$BEACON_CONFIG_DIR/config/config.toml" && rm -f "$BEACON_CONFIG_DIR/config/config.toml.bak"
# Comma-separated list of nodes to keep persistent connections to
sed -i.bak "s/^persistent_peers = \".*\"/persistent_peers = \"$seeds\"/" "$BEACON_CONFIG_DIR/config/config.toml" && rm -f "$BEACON_CONFIG_DIR/config/config.toml.bak"
# Create JWT token for auth between Consensus Client and Execution Client
$BEACOND_BINARY jwt generate -o $JWT_PATH;
# Initialise geth state from genesis file
$GETH_BINARY init \
--datadir=$EL_CONFIG_DIR \
networks/$EL_CHAIN_ID/el-genesis.json
# Check if there's a local snapshot. If there is use that to avoid downloading again, even though it may be a bit behind
if [ "$USE_SNAPSHOT" = true ]; then
# Check if the SNAPSHOTS_DIRECTORY directory exists
if [ ! -d "$SNAPSHOTS_DIRECTORY" ]; then
echo "Directory $SNAPSHOTS_DIRECTORY does not exist. Creating it and downloading files..."
# Create the directory
mkdir -p "$SNAPSHOTS_DIRECTORY/beacond"
mkdir -p "$SNAPSHOTS_DIRECTORY/geth"
# Download CL Snapshot file
curl --parallel --parallel-max 10 -L $CL_SNAPSHOT_SOURCE > $SNAPSHOTS_DIRECTORY/CL_SNAPSHOT_FIILE.tar.lz4;
# Download EL Snapshot file
curl --parallel --parallel-max 10 -L $EL_SNAPSHOT_SOURCE > $SNAPSHOTS_DIRECTORY/EL_SNAPSHOT_FIILE.tar.lz4;
echo "Files downloaded successfully."
else
echo "Directory $directory already exists. Continuing processing as normal."
fi
fi
# Continue processing as normal
echo "Processing complete."
fi
$BEACOND_BINARY start \
--home=$BEACON_CONFIG_DIR > "beaconkit.log" 2>&1 &
el_bootnodes=$(cat networks/$EL_CHAIN_ID/el-bootnodes.txt | grep '^enode://' | tr '\n' ',' | sed 's/,$//');
# Start geth execution client for this node
$GETH_BINARY \
--networkid=$EL_CHAIN_ID \
--authrpc.vhosts="*" \
--authrpc.addr=127.0.0.1 \
--authrpc.jwtsecret=$JWT_PATH \
--datadir=$EL_CONFIG_DIR \
--bootnodes=$el_bootnodes \
--identity=$MONIKER_NAME \
--syncmode=snap \
--verbosity=3 \
--http \
--http.addr=0.0.0.0 \
--http.port=8545 \
--http.api="eth,net,web3,debug" \
--http.corsdomain="*" > "geth.log" 2>&1 &
echo "Sleeping for 10s"
sleep 10
while true; do
$BEACOND_BINARY --home=$BEACON_CONFIG_DIR status | jq .sync_info;
sleep 10
done