2022-06-27 08:34:12 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2023-05-25 15:05:38 +00:00
|
|
|
# Copyright (c) 2023 Status Research & Development GmbH.
|
|
|
|
# Licensed under either of:
|
|
|
|
# - Apache License, version 2.0
|
|
|
|
# - MIT license
|
|
|
|
# at your option. This file may not be copied, modified, or distributed
|
|
|
|
# except according to those terms.
|
|
|
|
|
2022-06-27 08:34:12 +00:00
|
|
|
set -euo pipefail
|
|
|
|
|
2023-02-23 02:10:07 +00:00
|
|
|
SCRIPTS_DIR="$(dirname "${BASH_SOURCE[0]}")"
|
2022-06-27 08:34:12 +00:00
|
|
|
|
2023-02-23 02:10:07 +00:00
|
|
|
source "${SCRIPTS_DIR}/geth_binaries.sh"
|
|
|
|
source "${SCRIPTS_DIR}/geth_vars.sh"
|
2022-06-27 08:34:12 +00:00
|
|
|
|
|
|
|
#These are used in the caller script
|
|
|
|
GETH_ENODES=()
|
|
|
|
|
|
|
|
log "Using ${GETH_BINARY}"
|
|
|
|
|
2023-03-01 16:27:55 +00:00
|
|
|
for GETH_NODE_IDX in $(seq 0 $GETH_LAST_NODE_IDX); do
|
2023-02-23 02:10:07 +00:00
|
|
|
mkdir -p "${GETH_DATA_DIRS[GETH_NODE_IDX]}"
|
2023-05-25 15:05:38 +00:00
|
|
|
GETH_LOG="${DATA_DIR}/logs/geth.${GETH_NODE_IDX}.txt"
|
|
|
|
${GETH_BINARY} version > "$GETH_LOG"
|
|
|
|
${GETH_BINARY} --datadir "${GETH_DATA_DIRS[GETH_NODE_IDX]}" init "${EXECUTION_GENESIS_JSON}" >> "$GETH_LOG" 2>&1
|
2023-02-23 02:10:07 +00:00
|
|
|
${GETH_BINARY} \
|
|
|
|
--syncmode full \
|
|
|
|
--datadir "${GETH_DATA_DIRS[GETH_NODE_IDX]}" \
|
|
|
|
${DISCOVER} \
|
|
|
|
--http \
|
|
|
|
--http.port ${GETH_RPC_PORTS[GETH_NODE_IDX]} \
|
|
|
|
--port ${GETH_NET_PORTS[GETH_NODE_IDX]} \
|
|
|
|
--authrpc.port ${GETH_AUTH_RPC_PORTS[GETH_NODE_IDX]} \
|
2023-03-01 16:27:55 +00:00
|
|
|
--authrpc.jwtsecret "${JWT_FILE}" \
|
2023-05-25 15:05:38 +00:00
|
|
|
>> "${GETH_LOG}" 2>&1 &
|
|
|
|
PID=$!
|
|
|
|
echo $PID > "${DATA_DIR}/pids/geth.${GETH_NODE_IDX}"
|
2023-02-23 02:10:07 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
for GETH_NODE_IDX in $(seq 0 $GETH_LAST_NODE_IDX); do
|
|
|
|
GETH_RETRY=0
|
|
|
|
while :; do
|
|
|
|
if [[ -S "${GETH_DATA_DIRS[GETH_NODE_IDX]}/geth.ipc" ]]; then
|
|
|
|
echo "Geth ${GETH_NODE_IDX} started in $(( GETH_RETRY * 100 ))ms"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
if (( ++GETH_RETRY >= 300 )); then
|
|
|
|
echo "Geth ${GETH_NODE_IDX} failed to start"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
sleep 0.1
|
|
|
|
done
|
|
|
|
NODE_ID=$(${GETH_BINARY} attach --datadir "${GETH_DATA_DIRS[GETH_NODE_IDX]}" --exec admin.nodeInfo.enode)
|
|
|
|
GETH_ENODES+=("${NODE_ID}")
|
2022-06-27 08:34:12 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
#Add all nodes as peers
|
|
|
|
for dir in "${GETH_DATA_DIRS[@]}"
|
|
|
|
do
|
2023-02-23 02:10:07 +00:00
|
|
|
for enode in "${GETH_ENODES[@]}"
|
|
|
|
do
|
|
|
|
${GETH_BINARY} attach --datadir "${dir}" --exec "admin.addPeer(${enode})" &
|
|
|
|
done
|
2022-06-27 08:34:12 +00:00
|
|
|
done
|
|
|
|
|
2023-02-23 02:10:07 +00:00
|
|
|
log "GETH RPC Ports: ${GETH_AUTH_RPC_PORTS[*]}"
|