From 55433a4822a54337c4ee66a285054c31f4cfdb95 Mon Sep 17 00:00:00 2001 From: Claude Agent Date: Mon, 15 Jun 2026 12:36:47 +0000 Subject: [PATCH] cosmos: fix CometBFT RPC .result wrapping in statesync + sync-status helpers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ct_configure_statesync read .block.header.height (null — CometBFT wraps in .result) so statesync silently skipped -> gaiad fell back to genesis replay (panic). Use '.result.X // .X' (robust to wrapped/unwrapped). Same fallback in check-health --cosmos. Co-Authored-By: Claude Opus 4.8 (1M context) --- check-health.sh | 6 +++--- cosmos/scripts/cometbft-common.sh | 4 ++-- scripts/cometbft-common.sh | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/check-health.sh b/check-health.sh index 2e9c8c37..33ee284b 100755 --- a/check-health.sh +++ b/check-health.sh @@ -43,14 +43,14 @@ timeout=3 # seconds if $is_cosmos; then status=$(curl -L --ipv4 -m $timeout -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","id":1,"method":"status"}' "$RPC_URL") if [ $? -ne 0 ] || [ -z "$status" ]; then echo "timeout"; exit 1; fi - catching_up=$(echo "$status" | jq -r '.result.sync_info.catching_up' 2>/dev/null) - node_height=$(echo "$status" | jq -r '.result.sync_info.latest_block_height' 2>/dev/null) + catching_up=$(echo "$status" | jq -r '.result.sync_info.catching_up // .sync_info.catching_up' 2>/dev/null) + node_height=$(echo "$status" | jq -r '.result.sync_info.latest_block_height // .sync_info.latest_block_height' 2>/dev/null) if [ -z "$node_height" ] || [ "$node_height" = "null" ]; then echo "error"; exit 1; fi if [ "$catching_up" = "true" ]; then echo "syncing"; exit 1; fi # catching_up=false => synced. If a reference endpoint is given, sanity-check head gap. if [ -n "$ref" ]; then ref_status=$($BASEPATH/multicurl.sh -L --ipv4 -m $timeout -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","id":1,"method":"status"}' $ref) - ref_height=$(echo "$ref_status" | jq -r '.result.sync_info.latest_block_height' 2>/dev/null) + ref_height=$(echo "$ref_status" | jq -r '.result.sync_info.latest_block_height // .sync_info.latest_block_height' 2>/dev/null) if [ -n "$ref_height" ] && [ "$ref_height" != "null" ] && [ "$ref_height" -gt 0 ] 2>/dev/null; then gap=$(( ref_height - node_height )) if [ "$gap" -gt 100 ]; then echo "behind ($gap)"; exit 1; fi diff --git a/cosmos/scripts/cometbft-common.sh b/cosmos/scripts/cometbft-common.sh index 0881582d..52f6c5a9 100644 --- a/cosmos/scripts/cometbft-common.sh +++ b/cosmos/scripts/cometbft-common.sh @@ -169,12 +169,12 @@ ct_configure_statesync() { [ -f "$_cfg" ] || return 0 [ -n "$_rpc" ] || { ct_log "statesync: no RPC servers given, skipping"; return 0; } _primary=$(echo "$_rpc" | cut -d, -f1) - _latest=$(curl -s "$_primary/block" | jq -r .block.header.height 2>/dev/null || true) + _latest=$(curl -s "$_primary/block" | jq -r '.result.block.header.height // .block.header.height' 2>/dev/null || true) if [ -z "$_latest" ] || [ "$_latest" = null ]; then ct_log "statesync: could not read head height from $_primary, skipping"; return 0 fi _trust_h=$((_latest - _offset)) - _trust_hash=$(curl -s "$_primary/block?height=$_trust_h" | jq -r .block_id.hash 2>/dev/null || true) + _trust_hash=$(curl -s "$_primary/block?height=$_trust_h" | jq -r '.result.block_id.hash // .block_id.hash' 2>/dev/null || true) [ -n "$_trust_hash" ] && [ "$_trust_hash" != null ] || { ct_log "statesync: no trust hash, skipping"; return 0; } # second server defaults to the first (cometbft wants >=2 for light-client cross-check) echo "$_rpc" | grep -q ',' || _rpc="$_rpc,$_rpc" diff --git a/scripts/cometbft-common.sh b/scripts/cometbft-common.sh index 0881582d..52f6c5a9 100644 --- a/scripts/cometbft-common.sh +++ b/scripts/cometbft-common.sh @@ -169,12 +169,12 @@ ct_configure_statesync() { [ -f "$_cfg" ] || return 0 [ -n "$_rpc" ] || { ct_log "statesync: no RPC servers given, skipping"; return 0; } _primary=$(echo "$_rpc" | cut -d, -f1) - _latest=$(curl -s "$_primary/block" | jq -r .block.header.height 2>/dev/null || true) + _latest=$(curl -s "$_primary/block" | jq -r '.result.block.header.height // .block.header.height' 2>/dev/null || true) if [ -z "$_latest" ] || [ "$_latest" = null ]; then ct_log "statesync: could not read head height from $_primary, skipping"; return 0 fi _trust_h=$((_latest - _offset)) - _trust_hash=$(curl -s "$_primary/block?height=$_trust_h" | jq -r .block_id.hash 2>/dev/null || true) + _trust_hash=$(curl -s "$_primary/block?height=$_trust_h" | jq -r '.result.block_id.hash // .block_id.hash' 2>/dev/null || true) [ -n "$_trust_hash" ] && [ "$_trust_hash" != null ] || { ct_log "statesync: no trust hash, skipping"; return 0; } # second server defaults to the first (cometbft wants >=2 for light-client cross-check) echo "$_rpc" | grep -q ',' || _rpc="$_rpc,$_rpc"