-
Notifications
You must be signed in to change notification settings - Fork 239
/
progress.sh
executable file
·83 lines (69 loc) · 2.33 KB
/
progress.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
# Make script exit on error and undefined variables
set -eu
# Function to handle errors
error_exit() {
echo "Error: $1" >&2
exit 1
}
# Load Environment Variables
if [ -f .env ]; then
export $(cat .env | grep -v '#' | sed 's/\r$//' | awk '/=/ {print $1}' ) || error_exit "Failed to load .env file"
fi
# Set default RPC URL with error checking
export ETH_RPC_URL=${ETH_RPC_URL:-http://localhost:${PORT__OP_GETH_HTTP:-9993}}
[ -z "$ETH_RPC_URL" ] && error_exit "ETH_RPC_URL is not set"
# Get chain ID with error handling
CHAIN_ID=$(cast chain-id 2>/dev/null) || error_exit "Failed to get chain ID"
echo "Chain ID: $CHAIN_ID"
echo "Sampling, please wait"
# Set L2_URL based on chain ID
echo "Determining L2_URL for chain ID: $CHAIN_ID"
case $CHAIN_ID in
763373)
echo "Using Sepolia testnet RPC endpoint"
L2_URL="https://rpc-gel-sepolia.inkonchain.com"
;;
57073)
echo "Using mainnet RPC endpoint"
L2_URL="https://rpc-gel.inkonchain.com/"
;;
*)
error_exit "Unsupported chain ID: $CHAIN_ID"
;;
esac
echo "L2_URL set to: $L2_URL"
echo "Getting initial block number..."
T0=$(cast block-number --rpc-url "$ETH_RPC_URL" 2>/dev/null) || error_exit "Failed to get initial block number"
echo "Initial block: $T0"
echo "Waiting 10 seconds..."
sleep 10
echo "Getting final block number..."
T1=$(cast block-number --rpc-url "$ETH_RPC_URL" 2>/dev/null) || error_exit "Failed to get final block number"
echo "Final block: $T1"
# Calculate blocks per minute
PER_MIN=$(($T1 - $T0))
PER_MIN=$(($PER_MIN * 6))
echo "Blocks per minute: $PER_MIN"
[ $PER_MIN -eq 0 ] && error_exit "Not syncing"
# Get L2 head block with error handling
HEAD=$(cast block-number --rpc-url "$L2_URL" 2>/dev/null) || error_exit "Failed to get L2 block number"
BEHIND=$((HEAD - T1))
[ $BEHIND -lt 0 ] && error_exit "L2 is ahead of local node"
# Calculate time estimates
echo "Calculating time estimates..."
MINUTES=$((BEHIND / PER_MIN))
HOURS=$((MINUTES / 60))
if [ $MINUTES -le 60 ] ; then
echo "Sync will complete in minutes"
echo "Minutes until sync completed: $MINUTES"
fi
if [ $MINUTES -gt 60 ] ; then
echo "Sync will take hours"
echo "Hours until sync completed: $HOURS"
fi
if [ $HOURS -gt 24 ] ; then
echo "Sync will take days"
DAYS=$((HOURS / 24))
echo "Days until sync complete: $DAYS"
fi