sync-status: dRPC-homogeneous block-lag status + fix never-used reference fallbacks

Match the dRPC gateway's per-chain "how many blocks behind is ok" model instead of a
fixed 2s/5s timestamp tolerance:
- check-health.sh: compare the reference head vs local head by BLOCK NUMBER and classify
  with the chain's dRPC lag thresholds (LAGGING_LAG/SYNCING_LAG, in blocks, from
  chains.yaml). dRPC uses the two thresholds inconsistently across chains (sometimes
  lagging<syncing, sometimes the reverse) so the smaller is the online boundary and the
  larger the syncing/drop boundary. Defaults 2/6 when a chain has no thresholds.
- multicurl.sh: also skip responses with result:null (a lagging endpoint lacking the
  requested block) so the fallback reference URLs are actually tried. Previously the first
  endpoint's {"result":null} was accepted as success -> fallbacks never ran, and the null
  reference hash made check-health report false "forked" (the online/forked flapping).
- sync-status.sh: resolve the lag thresholds (by drpc slug or chain id) and export
  LAGGING_LAG/SYNCING_LAG.
- reference-rpc-endpoint.sh: add --lags and --block-time-ms lookups.
- reference-rpc-endpoint.json: regenerated with per-chain block_time_ms + lagging_lag +
  syncing_lag (additive).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-16 05:47:33 +00:00
parent df6c17f5cc
commit 1134a3774a
5 changed files with 1088 additions and 15 deletions

View File

@@ -189,12 +189,12 @@ if [ $? -eq 0 ]; then
response3=$(cat "$response_file3")
if $is_starknet; then
latest_block_timestamp_decimal3=$(echo "$response3" | jq -r '.result.timestamp')
ref_num=$(echo "$response3" | jq -r '.result.block_number // empty')
elif $is_aztec; then
latest_block_timestamp_decimal3=$(echo "$response3" | jq -r '.result.header.globalVariables.timestamp')
ref_num=$(echo "$response3" | jq -r '.result.header.globalVariables.blockNumber // empty')
else
latest_block_timestamp3=$(echo "$response3" | jq -r '.result.timestamp')
latest_block_timestamp_decimal3=$((16#${latest_block_timestamp3#0x}))
ref_num_hex=$(echo "$response3" | jq -r '.result.number // empty')
ref_num=$([ -n "$ref_num_hex" ] && printf '%d' "$ref_num_hex" 2>/dev/null)
fi
# echo "refer: $latest_block_timestamp_decimal3"
@@ -205,25 +205,35 @@ if [ $? -eq 0 ]; then
response4=$(cat "$response_file4")
if $is_starknet; then
latest_block_timestamp_decimal4=$(echo "$response4" | jq -r '.result.timestamp')
local_num=$(echo "$response4" | jq -r '.result.block_number // empty')
elif $is_aztec; then
latest_block_timestamp_decimal4=$(echo "$response4" | jq -r '.result.header.globalVariables.timestamp')
local_num=$(echo "$response4" | jq -r '.result.header.globalVariables.blockNumber // empty')
else
latest_block_timestamp4=$(echo "$response4" | jq -r '.result.timestamp')
latest_block_timestamp_decimal4=$((16#${latest_block_timestamp4#0x}))
local_num_hex=$(echo "$response4" | jq -r '.result.number // empty')
local_num=$([ -n "$local_num_hex" ] && printf '%d' "$local_num_hex" 2>/dev/null)
fi
#echo "local: $latest_block_timestamp_decimal4"
rm "$response_file4"
time_difference3=$(echo "scale=6; (${latest_block_timestamp_decimal3} - ${request_time3}) - (${latest_block_timestamp_decimal4} - ${request_time4})" | bc)
#echo "diff after network latency: $time_difference3 s"
if (( $(echo "$time_difference3 < 2" | bc -l) )); then
# Lag in BLOCKS between the reference head and the local head
# (positive => local behind). Compare against dRPC's own per-chain
# thresholds (LAGGING_LAG / SYNCING_LAG from chains.yaml via
# sync-status.sh) so our status matches the dRPC gateway's view.
# dRPC uses the two thresholds inconsistently (sometimes
# lagging<syncing, sometimes the reverse), so treat the smaller as
# the online boundary and the larger as the syncing/drop boundary.
if [ -z "$ref_num" ] || [ -z "$local_num" ]; then
echo "error"
exit 1
fi
lag=$(( ref_num - local_num ))
lo=${LAGGING_LAG:-2}; hi=${SYNCING_LAG:-6}
if [ "$lo" -gt "$hi" ]; then tmp=$lo; lo=$hi; hi=$tmp; fi
if [ "$lag" -le "$lo" ]; then
echo "online"
exit 0
elif (( $(echo "$time_difference3 < 5" | bc -l) )); then
elif [ "$lag" -le "$hi" ]; then
echo "lagging"
exit 0
else