Skip to content

Commit 8fd27b2

Browse files
authored
[Scripts] Add scripts to curl endpoints (#398)
Usage: ```bash ./local/scripts/curl_abci_info_monitor.sh # --help ./local/scripts/curl_load_test_session_rollover.sh # --help ``` <img width="1840" height="1191" alt="Screenshot 2025-08-08 at 3 14 02 PM" src="https://github.com/user-attachments/assets/a4e6f98f-b65c-4f73-b791-df33d488f7ca" />
1 parent 7960005 commit 8fd27b2

File tree

2 files changed

+306
-0
lines changed

2 files changed

+306
-0
lines changed
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
#!/bin/bash
2+
3+
# Monitor Cosmos RPC abci_info endpoint at regular intervals
4+
5+
show_help() {
6+
cat << EOF
7+
Usage: $(basename "$0") [OPTIONS]
8+
9+
Monitor Cosmos RPC abci_info endpoint and display results with timing information.
10+
11+
OPTIONS:
12+
--block Track only block height changes from abci_info response
13+
--node <URL> Override default RPC endpoint (default: https://shannon-grove-rpc.mainnet.poktroll.com)
14+
--help Show this help message and exit
15+
16+
EXAMPLES:
17+
$(basename "$0")
18+
Monitor full abci_info response using default endpoint
19+
20+
$(basename "$0") --block
21+
Monitor only block height changes
22+
23+
$(basename "$0") --node http://localhost:26657
24+
Use custom RPC endpoint
25+
26+
$(basename "$0") --block --node http://localhost:26657
27+
Monitor block height using custom endpoint
28+
29+
EOF
30+
exit 0
31+
}
32+
33+
# Parse command line arguments
34+
MONITOR_BLOCK=false
35+
RPC_ENDPOINT="https://shannon-grove-rpc.mainnet.poktroll.com"
36+
37+
while [[ $# -gt 0 ]]; do
38+
case $1 in
39+
--block)
40+
MONITOR_BLOCK=true
41+
shift
42+
;;
43+
--node)
44+
if [ -z "$2" ] || [[ "$2" == --* ]]; then
45+
echo "Error: --node requires a URL argument"
46+
exit 1
47+
fi
48+
RPC_ENDPOINT="$2"
49+
shift 2
50+
;;
51+
--help)
52+
show_help
53+
;;
54+
*)
55+
echo "Unknown option: $1"
56+
echo "Use --help for usage information"
57+
exit 1
58+
;;
59+
esac
60+
done
61+
62+
# Print configuration mode at the beginning
63+
if [ "$MONITOR_BLOCK" = true ]; then
64+
echo "📊 MODE: BLOCK HEIGHT MONITORING"
65+
else
66+
echo "🔍 MODE: ABCI INFO MONITORING"
67+
fi
68+
echo "🌐 ENDPOINT: $RPC_ENDPOINT"
69+
echo ""
70+
71+
echo "Starting Cosmos RPC abci_info monitor..."
72+
echo "Press Ctrl+C to stop"
73+
echo ""
74+
75+
# Initialize variables for delta calculation
76+
last_request_time=0
77+
last_block_height=""
78+
79+
while true; do
80+
# Get current timestamp for display and delta calculation
81+
current_time=$(date +%s.%N)
82+
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
83+
84+
# Calculate delta from last request
85+
if [ "$last_request_time" != "0" ]; then
86+
delta=$(echo "$current_time - $last_request_time" | bc -l)
87+
delta_formatted=$(printf "%.2f" "$delta")
88+
89+
# Color code based on delta (assuming 0.5s target interval)
90+
# Green: <= 0.7s (quick), Yellow: 0.7-1.5s (moderate), Red: > 1.5s (slow)
91+
if (( $(echo "$delta <= 0.7" | bc -l) )); then
92+
delta_color="\033[32m" # Green
93+
delta_status=""
94+
elif (( $(echo "$delta <= 1.5" | bc -l) )); then
95+
delta_color="\033[33m" # Yellow
96+
delta_status="⏱️"
97+
else
98+
delta_color="\033[31m" # Red
99+
delta_status="🐌"
100+
fi
101+
reset_color="\033[0m"
102+
delta_display=" ${delta_color}${delta_formatted}s ${delta_status}]${reset_color}"
103+
else
104+
delta_display=""
105+
fi
106+
107+
# Make the curl request to abci_info endpoint
108+
response=$(curl -s "$RPC_ENDPOINT/abci_info" 2>&1)
109+
110+
# Check if curl command was successful
111+
curl_exit_code=$?
112+
113+
if [ $curl_exit_code -ne 0 ]; then
114+
echo -e "❌ [$timestamp] ERROR: curl failed with exit code $curl_exit_code: $response$delta_display"
115+
else
116+
# Check if response contains an error
117+
if echo "$response" | grep -q '"error"'; then
118+
echo -e "❌ [$timestamp] API ERROR: $response$delta_display"
119+
else
120+
if [ "$MONITOR_BLOCK" = true ]; then
121+
# Extract block height from abci_info response
122+
block_height=$(echo "$response" | jq -r '.result.response.last_block_height // empty' 2>/dev/null)
123+
124+
if [ -z "$block_height" ] || [ "$block_height" = "null" ]; then
125+
echo -e "❌ [$timestamp] PARSE ERROR: Could not extract block height from response$delta_display"
126+
else
127+
# Check if block height changed
128+
if [ "$last_block_height" != "" ] && [ "$block_height" != "$last_block_height" ]; then
129+
height_change="📈"
130+
height_diff=$((block_height - last_block_height))
131+
height_info=" (↑$height_diff)"
132+
else
133+
height_change="📊"
134+
height_info=""
135+
fi
136+
137+
echo -e "✅ [$timestamp] $height_change Block Height: $block_height$height_info$delta_display"
138+
last_block_height="$block_height"
139+
fi
140+
else
141+
# Display full abci_info response details
142+
app_name=$(echo "$response" | jq -r '.result.response.data // "N/A"' 2>/dev/null)
143+
version=$(echo "$response" | jq -r '.result.response.version // "N/A"' 2>/dev/null)
144+
block_height=$(echo "$response" | jq -r '.result.response.last_block_height // "N/A"' 2>/dev/null)
145+
146+
if [ "$app_name" = "null" ] || [ "$app_name" = "" ]; then
147+
app_name="N/A"
148+
fi
149+
if [ "$version" = "null" ] || [ "$version" = "" ]; then
150+
version="N/A"
151+
fi
152+
if [ "$block_height" = "null" ] || [ "$block_height" = "" ]; then
153+
block_height="N/A"
154+
fi
155+
156+
echo -e "✅ [$timestamp] ABCI Info - App: $app_name, Version: $version, Height: $block_height$delta_display"
157+
fi
158+
fi
159+
fi
160+
161+
# Update last request time for next iteration
162+
last_request_time="$current_time"
163+
164+
# Wait 0.5 seconds
165+
sleep 0.5
166+
done
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
#!/bin/bash
2+
3+
# Monitor XRPL EVM testnet block number
4+
5+
show_help() {
6+
cat << EOF
7+
Usage: $(basename "$0") [OPTIONS]
8+
9+
Monitor XRPL EVM testnet block numbers via JSON-RPC eth_blockNumber calls.
10+
11+
OPTIONS:
12+
--local Use localhost endpoint (http://localhost:3070/v1) instead of remote
13+
--help Show this help message and exit
14+
15+
EXAMPLES:
16+
$(basename "$0")
17+
Monitor using remote Grove endpoint
18+
19+
$(basename "$0") --local
20+
Monitor using local PATH gateway
21+
22+
EOF
23+
exit 0
24+
}
25+
26+
# Parse command line arguments
27+
USE_LOCAL=false
28+
while [[ $# -gt 0 ]]; do
29+
case $1 in
30+
--local)
31+
USE_LOCAL=true
32+
shift
33+
;;
34+
--help)
35+
show_help
36+
;;
37+
*)
38+
echo "Unknown option: $1"
39+
echo "Use --help for usage information"
40+
exit 1
41+
;;
42+
esac
43+
done
44+
45+
# Print configuration mode at the beginning
46+
if [ "$USE_LOCAL" = true ]; then
47+
echo "🔧 MODE: LOCAL"
48+
else
49+
echo "🌐 MODE: REMOTE"
50+
fi
51+
echo ""
52+
53+
# Configure endpoint based on mode
54+
if [ "$USE_LOCAL" = true ]; then
55+
ENDPOINT="http://localhost:3070/v1"
56+
echo "Starting XRPL EVM testnet block number monitor (LOCAL)..."
57+
else
58+
ENDPOINT="https://xrpl-evm-testnet.rpc.grove.city/v1/6c5de5ff"
59+
echo "Starting XRPL EVM testnet block number monitor (REMOTE)..."
60+
fi
61+
62+
echo "Press Ctrl+C to stop"
63+
echo ""
64+
65+
# Initialize variables for delta calculation
66+
last_request_time=0
67+
68+
while true; do
69+
# Get current timestamp for display and delta calculation
70+
current_time=$(date +%s.%N)
71+
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
72+
73+
# Calculate delta from last request
74+
if [ "$last_request_time" != "0" ]; then
75+
delta=$(echo "$current_time - $last_request_time" | bc -l)
76+
delta_formatted=$(printf "%.2f" "$delta")
77+
78+
# Color code based on delta (assuming 0.5s target interval)
79+
# Green: <= 1s (quick), Yellow: 1-3s (moderate), Red: > 3s (slow)
80+
if (( $(echo "$delta <= 1" | bc -l) )); then
81+
delta_color="\033[32m" # Green
82+
delta_status=""
83+
elif (( $(echo "$delta <= 3" | bc -l) )); then
84+
delta_color="\033[33m" # Yellow
85+
delta_status="⏱️"
86+
else
87+
delta_color="\033[31m" # Red
88+
delta_status="🐌"
89+
fi
90+
reset_color="\033[0m"
91+
delta_display=" ${delta_color}${delta_formatted}s ${delta_status}]${reset_color}"
92+
else
93+
delta_display=""
94+
fi
95+
96+
# Execute RPC call to get current block number
97+
if [ "$USE_LOCAL" = true ]; then
98+
response=$(curl -s "$ENDPOINT" \
99+
-H "Target-Service-Id: xrplevm" \
100+
-H "Authorization: test_api_key" \
101+
-d '{"jsonrpc": "2.0", "id": 1, "method": "eth_blockNumber" }' 2>&1)
102+
else
103+
response=$(curl -s "$ENDPOINT" \
104+
-X POST \
105+
-H "Content-Type: application/json" \
106+
--data '{"method":"eth_blockNumber","params":[],"id":1,"jsonrpc":"2.0"}' 2>&1)
107+
fi
108+
109+
# Check if curl command was successful
110+
curl_exit_code=$?
111+
112+
if [ $curl_exit_code -ne 0 ]; then
113+
echo -e "❌ [$timestamp] ERROR: curl failed with exit code $curl_exit_code: $response$delta_display"
114+
else
115+
# Check if response contains an error
116+
if echo "$response" | grep -q '"error"'; then
117+
echo -e "❌ [$timestamp] API ERROR: $response$delta_display"
118+
else
119+
# Extract block number from response (remove 0x prefix and convert from hex)
120+
block_hex=$(echo "$response" | grep -o '"result":"0x[^"]*"' | cut -d'"' -f4)
121+
122+
if [ -z "$block_hex" ]; then
123+
echo -e "❌ [$timestamp] PARSE ERROR: Could not extract block number from response: $response$delta_display"
124+
else
125+
# Convert hex to decimal, handle potential conversion errors
126+
if block_decimal=$((16#${block_hex#0x})) 2>/dev/null; then
127+
echo -e "✅ [$timestamp] Block: $block_decimal (hex: $block_hex)$delta_display"
128+
else
129+
echo -e "❌ [$timestamp] CONVERSION ERROR: Could not convert hex $block_hex to decimal$delta_display"
130+
fi
131+
fi
132+
fi
133+
fi
134+
135+
# Update last request time for next iteration
136+
last_request_time="$current_time"
137+
138+
# Wait 0.5 seconds
139+
sleep 0.5
140+
done

0 commit comments

Comments
 (0)