Skip to content

Commit

Permalink
Add support for fallback bootstrap endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
aljazs-flare committed Nov 22, 2023
1 parent cb5ff5b commit 4d4e258
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
1 change: 1 addition & 0 deletions README-docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ These are the environment variables you can edit and their default values:
| `AUTOCONFIGURE_PUBLIC_IP` | `0` | Set to `1` to autoconfigure `PUBLIC_IP`, skipped if PUBLIC_IP is set |
| `AUTOCONFIGURE_BOOTSTRAP` | `0` | Set to `1` to autoconfigure `BOOTSTRAP_IPS` and `BOOTSTRAP_IDS` |
| `AUTOCONFIGURE_BOOTSTRAP_ENDPOINT` | `https://coston2.flare.network/ext/info` | Endpoint used for [bootstrapping](https://docs.avax.network/nodes/maintain/avalanchego-config-flags#bootstrapping) when `AUTOCONFIGURE_BOOTSTRAP` is enabled. Possible values are `https://coston2.flare.network/ext/info` or `https://flare.flare.network/ext/info`. |
| `AUTOCONFIGURE_FALLBACK_ENDPOINTS` | _(empty)_ | Comma-divided fallback bootstrap endpoints, used if `AUTOCONFIGURE_BOOTSTRAP_ENDPOINT` is not valid (not whitelisted / unreachable / etc), tested from first-to-last until one is valid |
| `BOOTSTRAP_BEACON_CONNECTION_TIMEOUT` | `1m` | Set the duration value (eg. `45s` / `5m` / `1h`) for [--bootstrap-beacon-connection-timeout](https://docs.avax.network/nodes/maintain/avalanchego-config-flags#--bootstrap-beacon-connection-timeout-duration) AvalancheGo flag. |
| `EXTRA_ARGUMENTS` | | Extra arguments passed to flare binary |

Expand Down
43 changes: 33 additions & 10 deletions entrypoint.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,50 @@ then
if [ "$PUBLIC_IP" = "" ];
then
echo "Autoconfiguring public IP"
PUBLIC_IP=$(curl https://api.ipify.org/)
PUBLIC_IP=$(curl -s https://api.ipify.org/)
echo " Got public address '${PUBLIC_IP}'"
else
echo "/!\\ AUTOCONFIGURE_PUBLIC_IP is enabled, but PUBLIC_IP is already set to '$PUBLIC_IP'! Skipping autoconfigure and using current PUBLIC_IP value!"
fi
fi

# Check if we can connect to the bootstrap endpoint (whitelisting)
BOOTSTRAP_STATUS=$(curl -m 10 -s -w %{http_code} -X POST --data '{ "jsonrpc":"2.0", "id":1, "method":"info.getNodeIP" }' -H 'content-type:application/json;' "$AUTOCONFIGURE_BOOTSTRAP_ENDPOINT" -o /dev/null)
if [ "$BOOTSTRAP_STATUS" != "200" ]; then
echo "Could not connect to bootstrap endpoint. Is your IP whitelisted?"
exit 1
fi

if [ "$AUTOCONFIGURE_BOOTSTRAP" = "1" ];
then


__BOOTSTRAP_ENDPOINTS=("${AUTOCONFIGURE_BOOTSTRAP_ENDPOINT}" ${AUTOCONFIGURE_FALLBACK_ENDPOINTS//,/ })

echo "Trying provided bootstrap endpoints"
for __ENDPOINT in "${__BOOTSTRAP_ENDPOINTS[@]}"; do
echo " Trying endpoint $__ENDPOINT"

RESPONSE_CODE=$(curl -X POST -m 5 -s -o /dev/null -w '%{http_code}' "$__ENDPOINT" -H 'Content-Type: application/json' --data '{ "jsonrpc":"2.0", "id":1, "method":"info.getNodeIP" }' || true)
if [ "$RESPONSE_CODE" = "200" ]; then
__BOOTSTRAP_ENDPOINT="$__ENDPOINT"
break
else
echo " Failed! The endpoint is unreachable or your IP is not whitelisted."
continue
fi
done

if [ -z "$__BOOTSTRAP_ENDPOINT" ]; then
echo " None of provided bootstrap endpoints worked!"
exit 1
fi


echo "Autoconfiguring bootstrap IPs and IDs"

BOOTSTRAP_IPS=$(curl -m 10 -sX POST --data '{ "jsonrpc":"2.0", "id":1, "method":"info.getNodeIP" }' -H 'content-type:application/json;' "$AUTOCONFIGURE_BOOTSTRAP_ENDPOINT" | jq -r ".result.ip")
BOOTSTRAP_IDS=$(curl -m 10 -sX POST --data '{ "jsonrpc":"2.0", "id":1, "method":"info.getNodeID" }' -H 'content-type:application/json;' "$AUTOCONFIGURE_BOOTSTRAP_ENDPOINT" | jq -r ".result.nodeID")
BOOTSTRAP_IPS=$(curl -m 10 -sX POST --data '{ "jsonrpc":"2.0", "id":1, "method":"info.getNodeIP" }' -H 'content-type:application/json;' "$__BOOTSTRAP_ENDPOINT" | jq -r ".result.ip")
BOOTSTRAP_IDS=$(curl -m 10 -sX POST --data '{ "jsonrpc":"2.0", "id":1, "method":"info.getNodeID" }' -H 'content-type:application/json;' "$__BOOTSTRAP_ENDPOINT" | jq -r ".result.nodeID")

echo " Got bootstrap ips: '${BOOTSTRAP_IPS}'"
echo " Got bootstrap ids: '${BOOTSTRAP_IDS}'"
fi

exit 0

/app/build/avalanchego \
--http-host=$HTTP_HOST \
--http-port=$HTTP_PORT \
Expand Down

0 comments on commit 4d4e258

Please sign in to comment.