1
+ #! /bin/bash
2
+ set -euo pipefail
3
+
4
+ # Configuration
5
+ RPC1=" http://localhost:8547"
6
+ RPC2=" http://localhost:8647"
7
+
8
+ function rpc_call() {
9
+ local endpoint=$1
10
+ local method=$2
11
+ local params=$3
12
+ curl -s -X POST \
13
+ -H " Content-Type: application/json" \
14
+ -d " {\" jsonrpc\" :\" 2.0\" ,\" method\" :\" $method \" ,\" params\" :$params ,\" id\" :1}" \
15
+ $endpoint
16
+ }
17
+
18
+ function get_latest_block() {
19
+ local response=$( rpc_call $RPC1 " eth_blockNumber" " []" )
20
+ local block_hex=$( echo " $response " | jq -r .result)
21
+ printf " %d" $(( block_hex))
22
+ }
23
+
24
+ function verify_block() {
25
+ local block_num=$1
26
+ local block_hex=$( printf " 0x%x" $block_num )
27
+
28
+ echo -n " Verifying block $block_num (0x${block_hex# 0x} )..."
29
+ echo
30
+
31
+ block1=$( rpc_call $RPC1 " eth_getBlockByNumber" " [\" $block_hex \" , true]" )
32
+ block2=$( rpc_call $RPC2 " eth_getBlockByNumber" " [\" $block_hex \" , true]" )
33
+
34
+ if [ " $( echo " $block1 " | jq -r .result) " == " null" ] || [ " $( echo " $block2 " | jq -r .result) " == " null" ]; then
35
+ echo " ❌ Block not found on one or both endpoints!"
36
+ return 1
37
+ fi
38
+
39
+ hash1=$( echo " $block1 " | jq -r .result.hash)
40
+ hash2=$( echo " $block2 " | jq -r .result.hash)
41
+
42
+ if [ " $hash1 " != " $hash2 " ]; then
43
+ echo " ❌ Hash mismatch! $RPC1 : $hash1 , $RPC2 : $hash2 "
44
+ return 1
45
+ fi
46
+
47
+ tx_count=$( echo " $block1 " | jq -r ' .result.transactions | length' )
48
+ echo -n " $tx_count tx..."
49
+ echo
50
+
51
+ for (( i= 0 ; i< tx_count; i++ )) ; do
52
+ tx_hash1=$( echo " $block1 " | jq -r .result.transactions[$i ].hash)
53
+ tx_hash2=$( echo " $block2 " | jq -r .result.transactions[$i ].hash)
54
+
55
+ # Verify transaction order and hash match
56
+ if [ " $tx_hash1 " != " $tx_hash2 " ]; then
57
+ echo " ❌ Transaction order mismatch at position $i !"
58
+ echo " $RPC1 : $tx_hash1 "
59
+ echo " $RPC2 : $tx_hash2 "
60
+ return 1
61
+ fi
62
+
63
+ tx1=$( rpc_call $RPC1 " eth_getTransactionByHash" " [\" $tx_hash1 \" ]" )
64
+ tx2=$( rpc_call $RPC2 " eth_getTransactionByHash" " [\" $tx_hash2 \" ]" )
65
+
66
+ if [ " $tx1 " != " $tx2 " ]; then
67
+ echo " ❌ Tx content mismatch for $tx_hash1 !"
68
+ return 1
69
+ fi
70
+ printf " ✅ Tx content match for $tx_hash1 !"
71
+ echo
72
+ done
73
+ echo
74
+ return 0
75
+ }
76
+
77
+ echo " === Starting Chain Verification ==="
78
+ latest_block=$( get_latest_block)
79
+ echo " Latest block: $latest_block "
80
+
81
+ for (( block= 0 ; block<= latest_block; block++ )) ; do
82
+ if ! verify_block $block ; then
83
+ echo " ❌ Failed for block $block "
84
+ exit 1
85
+ fi
86
+ done
87
+
88
+ echo " === Verification Complete ==="
89
+ echo " Successfully verified $(( latest_block+ 1 )) blocks"
0 commit comments