2022-06-27 08:34:12 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
BASEDIR="$(dirname "${BASH_SOURCE[0]}")"
|
|
|
|
|
|
|
|
. "${BASEDIR}/geth_vars.sh"
|
|
|
|
|
|
|
|
#These are used in the caller script
|
|
|
|
GETH_ENODES=()
|
|
|
|
GETH_HTTP_PORTS=()
|
|
|
|
GETH_NET_PORTS=()
|
|
|
|
GETH_WS_PORTS=()
|
|
|
|
GETH_RPC_PORTS=()
|
|
|
|
GETH_DATA_DIRS=()
|
|
|
|
|
|
|
|
log "Using ${GETH_BINARY}"
|
|
|
|
|
2022-06-28 11:33:49 +00:00
|
|
|
for GETH_NUM_NODE in $(seq 0 $(( GETH_NUM_NODES - 1 ))); do
|
|
|
|
GETH_NET_PORT=$(( GETH_NUM_NODE * GETH_PORT_OFFSET + GETH_NET_BASE_PORT ))
|
|
|
|
GETH_HTTP_PORT=$(( GETH_NUM_NODE * GETH_PORT_OFFSET + GETH_HTTP_BASE_PORT ))
|
|
|
|
GETH_WS_PORT=$(( GETH_NUM_NODE * GETH_PORT_OFFSET + GETH_WS_BASE_PORT ))
|
|
|
|
GETH_AUTH_RPC_PORT=$(( GETH_NUM_NODE * GETH_PORT_OFFSET + GETH_AUTH_RPC_PORT_BASE ))
|
|
|
|
log "Starting geth node ${GETH_NUM_NODE} on net port ${GETH_NET_PORT} HTTP port ${GETH_HTTP_PORT} WS port ${GETH_WS_PORT}"
|
|
|
|
GETHDATADIR=$(mktemp -d "${DATA_DIR}"/geth-data-XXX)
|
2022-06-27 08:34:12 +00:00
|
|
|
GETH_DATA_DIRS+=(${GETHDATADIR})
|
|
|
|
${GETH_BINARY} --http --ws -http.api "engine" --datadir "${GETHDATADIR}" init "${GENESISJSON}"
|
2022-06-28 11:33:49 +00:00
|
|
|
${GETH_BINARY} --http --ws --http.corsdomain '*' --http.api "eth,net,engine" -ws.api "eth,net,engine" --datadir "${GETHDATADIR}" ${DISCOVER} --port ${GETH_NET_PORT} --http.port ${GETH_HTTP_PORT} --ws.port ${GETH_WS_PORT} --authrpc.port ${GETH_AUTH_RPC_PORT} --authrpc.jwtsecret /tmp/jwtsecret &> "${DATA_DIR}/geth-log${GETH_NUM_NODE}.txt" &
|
2022-06-27 08:34:12 +00:00
|
|
|
sleep 5
|
|
|
|
NODE_ID=$(${GETH_BINARY} attach --datadir "${GETHDATADIR}" --exec admin.nodeInfo.enode)
|
2022-06-28 11:33:49 +00:00
|
|
|
GETH_ENODES+=("${NODE_ID}")
|
|
|
|
GETH_HTTP_PORTS+=("${GETH_HTTP_PORT}")
|
|
|
|
GETH_NET_PORTS+=("${GETH_NET_PORT}")
|
|
|
|
GETH_WS_PORTS+=("${GETH_WS_PORT}")
|
|
|
|
GETH_RPC_PORTS+=("${GETH_AUTH_RPC_PORT}")
|
2022-06-27 08:34:12 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
#Add all nodes as peers
|
|
|
|
for dir in "${GETH_DATA_DIRS[@]}"
|
|
|
|
do
|
|
|
|
for enode in "${GETH_ENODES[@]}"
|
|
|
|
do
|
2022-06-28 11:33:49 +00:00
|
|
|
${GETH_BINARY} attach --datadir "${dir}" --exec "admin.addPeer(${enode})"
|
2022-06-27 08:34:12 +00:00
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
log "GETH HTTP Ports: ${GETH_HTTP_PORTS[*]}"
|