forked from celo-org/celo-l2-node-docker-compose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogress.sh
executable file
·55 lines (44 loc) · 1.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
#!/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
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
case $CHAIN_ID in
10) L2_URL=https://mainnet.optimism.io ;;
11155420) L2_URL=https://sepolia.optimism.io ;;
*) L2_URL=$HEALTHCHECK__REFERENCE_RPC_PROVIDER ;;
esac
if [ -z ${L2_URL-} ]; then
echo "No L2 RPC service to compare against, won't estimate remaining time"
exit
fi
# How many more blocks do we need?
HEAD=`cast block-number --rpc-url $L2_URL`
BEHIND=$((HEAD - T1))
MINUTES=$((BEHIND / PER_MIN))
HOURS=$((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