From a7d3a3fee8e97a2ed7395c50d92028090d4812ad Mon Sep 17 00:00:00 2001 From: Uncle Stretch Date: Fri, 30 Oct 2026 12:28:17 +0300 Subject: [PATCH] update RPC scripts to support weaver Signed-off-by: Uncle Stretch --- scripts/rpc-tester.sh | 92 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 76 insertions(+), 16 deletions(-) diff --git a/scripts/rpc-tester.sh b/scripts/rpc-tester.sh index 6868ec9..5bb25dd 100755 --- a/scripts/rpc-tester.sh +++ b/scripts/rpc-tester.sh @@ -24,6 +24,8 @@ HOODI_RPC=( "https://rpc.sentio.xyz/hoodi" ) +HOODI_GATEKEEPER="0xc9D5f50e17eeEAF39E0D0cDbbcF4B04FA4A4Bbd6" + show_help() { cat << EOF Usage: $(basename "$0") [OPTIONS] @@ -58,20 +60,66 @@ spinner() { tput cnorm } +pad32() { + local h="$1" + h="${h#0x}" + printf "%064s" "$h" | tr ' ' '0' +} + +build_calldata() { + local selector="$1" + local at_block="$2" + local s_hex + local b_hex + + s_hex=$(printf "%x" 0) + b_hex=$(printf "%x" "$at_block") + + echo "0x${selector#0x}$(pad32 "$s_hex")$(pad32 "$b_hex")" +} + +decode_get_root() { + local res_json="$1" + local hex + + hex=$(echo "$res_json" | grep -o '"result":"[^"]*' | cut -d'"' -f4) + if [[ -z "$hex" || "$hex" == "null" ]]; then + echo "ERROR" + return + fi + + hex="${hex#0x}" + if (( ${#hex} < 128 )); then + echo "ERROR" + return + fi + + local word1="${hex:0:64}" + local word2="${hex:64:64}" + local num + + num=$(printf "%d" "0x$word2" 2>/dev/null) + [[ -z "$num" ]] && num="$word2" + echo "0x${word1} ${num}" +} + check_network() { local name=$1 - shift + local gatekeeper=$2 + shift 2 local rpcs=("$@") local target_dir="${OUT_DIR:-/tmp}" local tmp_file="${target_dir}/$(date +%s)_${name,,}" + local root_width=66 + local sess_width=6 local max_len=0 for e in "${rpcs[@]}"; do (( ${#e} > max_len )) && max_len=${#e}; done [[ $max_len -lt 20 ]] && max_len=20 - local total_width=$(( max_len + 32 )) + local total_width=$(( max_len + 95 )) local line=$(printf "%.0s-" $(seq 1 $total_width)) - local header_fmt="| %-${max_len}s | %-12s | %-10s |\n" + local header_fmt="| %-${max_len}s | %-10s | %-${root_width}s | %-${sess_width}s |\n" ( for endpoint in "${rpcs[@]}"; do @@ -80,11 +128,15 @@ check_network() { hex=$(echo "$res_b" | grep -o '"result":"[^"]*' | cut -d'"' -f4) [[ -n "$hex" && "$hex" != "null" ]] && blk=$(printf "%d" "$hex") || blk="ERROR" - res_l=$(curl -s -X POST -H "Content-Type: application/json" --max-time 10 \ - --data '{"jsonrpc":"2.0","method":"eth_getLogs","params":[{"fromBlock":"0x1","toBlock":"0x2"}],"id":1}' "$endpoint") - echo "$res_l" | grep -q '"result"' && ev="YES" || ev="NO" + root="N/A" + if [[ -n "$blk" && "$blk" != "ERROR" ]]; then + calldata=$(build_calldata "$SELECTOR" "$blk") + payload=$(printf '{"jsonrpc":"2.0","method":"eth_call","params":[{"to":"%s","data":"%s"},"latest"],"id":1}' "$gatekeeper" "$calldata") + res_c=$(curl -s -X POST -H "Content-Type: application/json" --max-time 10 --data "$payload" "$endpoint") + root=$(decode_get_root "$res_c") + fi - echo "$endpoint|$blk|$ev" + echo "$endpoint|$blk|$root" done ) > "$tmp_file" & @@ -94,10 +146,17 @@ check_network() { spinner $worker_pid "$name" local table_output="$line\n" - table_output+=$(printf "$header_fmt" "Endpoint" "Block" "Events")"\n" + table_output+=$(printf "$header_fmt" "Endpoint" "Block" "Merkle Root" "Session")"\n" table_output+="$line\n" - while IFS="|" read -r url blk ev; do - table_output+=$(printf "$header_fmt" "$url" "$blk" "$ev")"\n" + while IFS="|" read -r url blk root; do + if [[ "$root" == *" "* ]]; then + hash="${root%% *}" + sess="${root##* }" + else + hash="$root" + sess="-" + fi + table_output+=$(printf "$header_fmt" "$url" "$blk" "$hash" "$sess")"\n" done < "$tmp_file" table_output+="$line" @@ -111,6 +170,7 @@ check_network() { CHOSEN_CHAIN="" BASE_OUT_DIR="" CUSTOM_RPCS="" +SELECTOR="d4be7935" while [[ $# -gt 0 ]]; do case "$1" in @@ -132,14 +192,14 @@ if [[ -n "$CUSTOM_RPCS" ]]; then check_network "Custom" "${USER_RPC_ARRAY[@]}" else if [ "$CHOSEN_CHAIN" == "sepolia" ]; then - check_network "Sepolia" "${SEPOLIA_RPC[@]}" + check_network "Sepolia" "$SEPOLIA_GATEKEEPER" "${HOODI_RPC[@]}" elif [ "$CHOSEN_CHAIN" == "mordor" ]; then - check_network "Mordor" "${MORDOR_RPC[@]}" + check_network "Mordor" "$MORDOR_GATEKEEPER" "${HOODI_RPC[@]}" elif [ "$CHOSEN_CHAIN" == "hoodi" ]; then - check_network "Hoodi" "${HOODI_RPC[@]}" + check_network "Hoodi" "$HOODI_GATEKEEPER" "${HOODI_RPC[@]}" else - check_network "Sepolia" "${SEPOLIA_RPC[@]}" - check_network "Mordor" "${MORDOR_RPC[@]}" - check_network "Hoodi" "${HOODI_RPC[@]}" + check_network "Sepolia" "$SEPOLIA_GATEKEEPER" "${SEPOLIA_RPC[@]}" + check_network "Mordor" "$MORDOR_GATEKEEPER" "${MORDOR_RPC[@]}" + check_network "Hoodi" "$HOODI_GATEKEEPER" "${HOODI_RPC[@]}" fi fi