-
Notifications
You must be signed in to change notification settings - Fork 114
/
progress.sh
executable file
·54 lines (41 loc) · 1.2 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
#!/bin/bash
set -eu
# Load Environment Variables
if [ -f .env ]; then
export $(cat .env | grep -v '#' | sed 's/\r$//' | awk '/=/ {print $1}' )
fi
export ETH_RPC_URL=http://localhost:${PORT__OP_GETH_HTTP:-9993}
# Cast is provided by Foundry: https://getfoundry.sh/.
# Run `pnpm install:foundry` in the optimism repo root.
CHAIN_ID=`cast chain-id`
echo Chain ID: $CHAIN_ID
echo Sampling, please wait
if [ $CHAIN_ID -eq 10 ]; then
L2_URL=https://mainnet.optimism.io
fi
if [ $CHAIN_ID -eq 11155420 ]; then
L2_URL=https://sepolia.optimism.io
fi
T0=`cast block-number --rpc-url $ETH_RPC_URL` ; sleep 10 ; T1=`cast block-number --rpc-url $ETH_RPC_URL`
PER_MIN=$(($T1 - $T0))
PER_MIN=$(($PER_MIN * 6))
echo Blocks per minute: $PER_MIN
if [ $PER_MIN -eq 0 ]; then
echo Not syncing
exit;
fi
# How many more blocks do we need?
HEAD=`cast block-number --rpc-url $L2_URL`
BEHIND=`expr $HEAD - $T1`
MINUTES=`expr $BEHIND / $PER_MIN`
HOURS=`expr $MINUTES / 60`
if [ $MINUTES -le 60 ] ; then
echo Minutes until sync completed: $MINUTES
fi
if [ $MINUTES -gt 60 ] ; then
echo Hours until sync completed: $HOURS
fi
if [ $HOURS -gt 24 ] ; then
DAYS=`expr $HOURS / 24`
echo Days until sync complete: $DAYS
fi