From dc9958ac3a21db426f9d3bd3bc72ea033dcb03d0 Mon Sep 17 00:00:00 2001 From: Tom Beynon Date: Sun, 17 Nov 2024 21:12:44 +0000 Subject: [PATCH 1/2] Automatically configure and use Chain Registry CHAIN_JSON --- README.md | 2 +- run.sh | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 238a57d21..32c1d17ed 100644 --- a/README.md +++ b/README.md @@ -163,7 +163,7 @@ The omnibus images allow some specific variables and shortcuts to configure extr ### Chain configuration -Chain config can be sourced from a `chain.json` file [as seen in the Cosmos Chain Registry](https://github.com/cosmos/chain-registry). +Chain config can be sourced from a `chain.json` file [as seen in the Cosmos Chain Registry](https://github.com/cosmos/chain-registry). The [Chain Registry](https://github.com/cosmos/chain-registry) will be used automatically for all pre-built images, or whenever the `PROJECT` environment variable matches a [Chain Registry](https://github.com/cosmos/chain-registry) ID. Set `CHAIN_JSON` to an alternative URL if required, or `0` to disable this behaviour entirely. |Variable|Description|Default|Examples| |---|---|---|---| diff --git a/run.sh b/run.sh index bbcd2e3bc..9208e8887 100755 --- a/run.sh +++ b/run.sh @@ -5,7 +5,19 @@ set -e [ "$DEBUG" == "2" ] && set -x export CHAIN_JSON="${CHAIN_JSON:-$CHAIN_URL}" # deprecate CHAIN_URL -if [ -n "$CHAIN_JSON" ]; then +if [[ -z "$CHAIN_JSON" && -n "$PROJECT" ]]; then + CHAIN_JSON="https://raw.githubusercontent.com/cosmos/chain-registry/master/${PROJECT}/chain.json" +fi + +CHAIN_JSON_EXISTS=false +if [[ -n "$CHAIN_JSON" && "$CHAIN_JSON" != "0" ]]; then + if curl --output /dev/null --silent --head --fail "$CHAIN_JSON"; then + CHAIN_JSON_EXISTS=true + else + echo "Chain JSON not found" + fi +fi +if [[ $CHAIN_JSON_EXISTS == true ]]; then CHAIN_METADATA=$(curl -Ls $CHAIN_JSON) export CHAIN_ID="${CHAIN_ID:-$(echo $CHAIN_METADATA | jq -r .chain_id)}" export P2P_SEEDS="${P2P_SEEDS:-$(echo $CHAIN_METADATA | jq -r '.peers.seeds | map(.id+"@"+.address) | join(",")')}" From 17969c191d2dec326873bffab312fde70b5628ae Mon Sep 17 00:00:00 2001 From: Tom Beynon Date: Mon, 18 Nov 2024 16:34:15 +0000 Subject: [PATCH 2/2] Add 0.5 second sleep to avoid any CHAIN_JSON rate limiting --- run.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/run.sh b/run.sh index 9208e8887..230dcb782 100755 --- a/run.sh +++ b/run.sh @@ -18,6 +18,7 @@ if [[ -n "$CHAIN_JSON" && "$CHAIN_JSON" != "0" ]]; then fi fi if [[ $CHAIN_JSON_EXISTS == true ]]; then + sleep 0.5 # avoid rate limiting CHAIN_METADATA=$(curl -Ls $CHAIN_JSON) export CHAIN_ID="${CHAIN_ID:-$(echo $CHAIN_METADATA | jq -r .chain_id)}" export P2P_SEEDS="${P2P_SEEDS:-$(echo $CHAIN_METADATA | jq -r '.peers.seeds | map(.id+"@"+.address) | join(",")')}"