From db681b5a7444e4e3f69255070ceae8f6710bb009 Mon Sep 17 00:00:00 2001 From: rob Date: Thu, 15 Jan 2026 09:07:36 +0000 Subject: [PATCH] Add Starknet RPC support to sync check scripts --- success-if-almost-synced.sh | 27 ++++++++++++++++++++++----- timestamp.sh | 25 ++++++++++++++++++++----- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/success-if-almost-synced.sh b/success-if-almost-synced.sh index 23599348..316efcfc 100755 --- a/success-if-almost-synced.sh +++ b/success-if-almost-synced.sh @@ -23,17 +23,34 @@ for path in $pathlist; do RPC_URL="https://$DOMAIN/$path" response_file=$(mktemp) - http_status_code=$(curl --ipv4 -m 1 -s -X POST -w "%{http_code}" -o "$response_file" -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest", false],"id":1}' "$RPC_URL") + # Detect Starknet vs Ethereum based on path + if echo "$path" | grep -qi "starknet"; then + rpc_method='{"jsonrpc":"2.0","method":"starknet_getBlockWithTxHashes","params":["latest"],"id":1}' + is_starknet=true + else + rpc_method='{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest", false],"id":1}' + is_starknet=false + fi + + http_status_code=$(curl --ipv4 -m 1 -s -X POST -w "%{http_code}" -o "$response_file" -H "Content-Type: application/json" --data "$rpc_method" "$RPC_URL") if [ $? -eq 0 ]; then if [[ $http_status_code -eq 200 ]]; then response=$(cat "$response_file") - latest_block_timestamp=$(echo "$response" | jq -r '.result.timestamp') current_timestamp=$(date +%s) - age=$((current_timestamp - ("16#${latest_block_timestamp#0x}"))) - + + if $is_starknet; then + # Starknet returns decimal timestamp + latest_block_timestamp_decimal=$(echo "$response" | jq -r '.result.timestamp') + age=$((current_timestamp - latest_block_timestamp_decimal)) + else + # Ethereum returns hex timestamp + latest_block_timestamp=$(echo "$response" | jq -r '.result.timestamp') + age=$((current_timestamp - (16#${latest_block_timestamp#0x}))) + fi + echo "$age" - + if (( age < ${2:-3600} )); then exit 0 else diff --git a/timestamp.sh b/timestamp.sh index 15de97f1..f2dcbc43 100755 --- a/timestamp.sh +++ b/timestamp.sh @@ -30,18 +30,33 @@ for path in $pathlist; do RPC_URL="$PROTO://$DOMAIN/$path" response_file=$(mktemp) - http_status_code=$(curl -L --ipv4 -m 1 -s -X POST -w "%{http_code}" -o "$response_file" -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest", false],"id":1}' $RPC_URL) + # Detect Starknet vs Ethereum based on path + if echo "$path" | grep -qi "starknet"; then + rpc_method='{"jsonrpc":"2.0","method":"starknet_getBlockWithTxHashes","params":["latest"],"id":1}' + is_starknet=true + else + rpc_method='{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest", false],"id":1}' + is_starknet=false + fi + + http_status_code=$(curl -L --ipv4 -m 1 -s -X POST -w "%{http_code}" -o "$response_file" -H "Content-Type: application/json" --data "$rpc_method" $RPC_URL) if [ $? -eq 0 ]; then - + if [[ $http_status_code -eq 200 ]]; then response=$(cat "$response_file") - latest_block_timestamp=$(echo "$response" | jq -r '.result.timestamp') - latest_block_timestamp_decimal=$((16#${latest_block_timestamp#0x})) + if $is_starknet; then + # Starknet returns decimal timestamp + latest_block_timestamp_decimal=$(echo "$response" | jq -r '.result.timestamp') + else + # Ethereum returns hex timestamp + latest_block_timestamp=$(echo "$response" | jq -r '.result.timestamp') + latest_block_timestamp_decimal=$((16#${latest_block_timestamp#0x})) + fi echo "$latest_block_timestamp_decimal" - + exit 0; fi fi