@@ -11,76 +11,18 @@ source "$(dirname "$0")/common-functions.sh"
1111
1212# Global variables to track state
1313START_TIME=$( date +%s)
14- INITIAL_L2GETH_BLOCK=" "
15- INITIAL_L2RETH_BLOCK=" "
1614L2GETH_STOP_BLOCK=" "
1715L2RETH_FINAL_BLOCK=" "
1816
19- pre_flight_checks () {
20- log_info " === PRE-FLIGHT CHECKS ==="
21-
22- check_rpc_connectivity
23-
24- # Get initial block states
25- local l2geth_info=$( get_latest_block_info " $L2GETH_RPC_URL " )
26- local l2reth_info=$( get_latest_block_info " $L2RETH_RPC_URL " )
27-
28- INITIAL_L2GETH_BLOCK=$( echo " $l2geth_info " | awk ' {print $1}' )
29- local l2geth_hash=$( echo " $l2geth_info " | awk ' {print $2}' )
30- INITIAL_L2RETH_BLOCK=$( echo " $l2reth_info " | awk ' {print $1}' )
31- local l2reth_hash=$( echo " $l2reth_info " | awk ' {print $2}' )
32-
33- log_info " L2GETH current block: #$INITIAL_L2GETH_BLOCK (hash: $l2geth_hash )"
34- log_info " L2RETH current block: #$INITIAL_L2RETH_BLOCK (hash: $l2reth_hash )"
17+ migrate_pre_flight_checks () {
18+ perform_pre_flight_checks
3519
3620 # Check if l2geth is mining
3721 if ! is_l2geth_mining; then
3822 log_error " L2GETH is not currently mining. Please start mining first."
3923 exit 1
4024 fi
4125 log_success " L2GETH is currently mining"
42-
43- # Verify nodes are on the same chain by comparing chain IDs
44- local l2geth_chain_id=$( get_chain_id " $L2GETH_RPC_URL " )
45- local l2reth_chain_id=$( get_chain_id " $L2RETH_RPC_URL " )
46-
47- if [[ -z " $l2geth_chain_id " || -z " $l2reth_chain_id " ]]; then
48- log_error " Failed to retrieve chain IDs from one or both nodes"
49- exit 1
50- fi
51-
52- if [[ " $l2geth_chain_id " != " $l2reth_chain_id " ]]; then
53- log_error " Nodes are on different chains! Chain IDs differ:"
54- log_error " L2GETH: $l2geth_chain_id "
55- log_error " L2RETH: $l2reth_chain_id "
56- exit 1
57- fi
58- log_success " Nodes are on the same chain (Chain ID: $l2geth_chain_id )"
59-
60- # Verify nodes are on the same chain by comparing a recent block hash
61- local compare_block=$(( INITIAL_L2 RETH_BLOCK < INITIAL_L2 GETH_BLOCK ? INITIAL_L2 RETH_BLOCK : INITIAL_L2 GETH_BLOCK))
62- if [[ $compare_block -gt 0 ]]; then
63- local l2geth_compare_info=$( get_block_info " $L2GETH_RPC_URL " " $compare_block " )
64- local l2reth_compare_info=$( get_block_info " $L2RETH_RPC_URL " " $compare_block " )
65-
66- if [[ -z " $l2geth_compare_info " || -z " $l2reth_compare_info " ]]; then
67- log_error " Failed to retrieve block #$compare_block from one or both nodes"
68- exit 1
69- fi
70-
71- local l2geth_compare_hash=$( echo " $l2geth_compare_info " | awk ' {print $2}' )
72- local l2reth_compare_hash=$( echo " $l2reth_compare_info " | awk ' {print $2}' )
73-
74- if [[ " $l2geth_compare_hash " != " $l2reth_compare_hash " ]]; then
75- log_error " Nodes are on different chains! Block #$compare_block hashes differ:"
76- log_error " L2GETH: $l2geth_compare_hash "
77- log_error " L2RETH: $l2reth_compare_hash "
78- exit 1
79- fi
80- log_success " Block hash verification passed at block #$compare_block "
81- fi
82-
83- log_success " Pre-flight checks completed"
8426}
8527
8628print_summary () {
@@ -89,8 +31,6 @@ print_summary() {
8931
9032 log_info " === MIGRATION SUMMARY ==="
9133 log_info " Migration completed in ${total_time} s"
92- log_info " Initial L2GETH block: #$INITIAL_L2GETH_BLOCK "
93- log_info " Initial L2RETH block: #$INITIAL_L2RETH_BLOCK "
9434 log_info " L2GETH stopped at block: #$L2GETH_STOP_BLOCK "
9535 log_info " L2RETH final block: #$L2RETH_FINAL_BLOCK "
9636
@@ -122,7 +62,7 @@ main() {
12262 log_info " L2RETH will produce $blocks_to_produce blocks"
12363
12464 check_env_vars
125- pre_flight_checks
65+ migrate_pre_flight_checks
12666
12767 # Double check if user wants to proceed
12868 read -p " Proceed with migration? (y/N): " confirm
0 commit comments