-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_bsc_block_height.sh
67 lines (53 loc) · 2.13 KB
/
check_bsc_block_height.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
#!/bin/bash
nodeServiceName=bsc
# 检测服务是否同步完成 因链改动
est_time=0
old_dHeight=0
total_run_time=0
interval_time=10
base_speed=0.00
get_block_height() {
globalHeight=$(curl -s -X POST 'https://bsc.blockpi.network/v1/rpc/e327b3000e169e55155e986d82d9f4e1252abe7f' -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0","method": "eth_blockNumber","params": [],"id": 1}' | jq -r ".result" | tr 'a-f' 'A-F')
LocalHeight=$(curl -Ls -X POST 'http://127.0.0.1:31041' -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0","method": "eth_blockNumber","params": [],"id": 1}' | jq -r ".result" | tr 'a-f' 'A-F')
}
while true
do
get_block_height
if [ -z $LocalHeight ]; then
printf "项目名称:%s " ${nodeServiceName}
printf "本地同步未开始,请等待 \n"
else
dHeight=$(echo "obase=10; ibase=16; ${globalHeight:2}-${LocalHeight:2}" | bc)
old_dHeight=$dHeight
break
fi
sleep 1
done
while true
do
printf "项目名称:%s " ${nodeServiceName}
if [ $total_run_time -ne 0 ]; then
if [ $old_dHeight -gt $dHeight ]; then
sync_speed=$(echo "scale=2; ((($old_dHeight - $dHeight) / $total_run_time)-$base_speed)" | bc)
est_time=$(echo "($dHeight / $sync_speed)/1" | bc)
est_time_hours=$(echo "($est_time/3600)" | bc)
est_time_minutes=$(echo "($est_time%3600)/60" | bc)
est_time_seconds=$(echo "($est_time%3600)%60" | bc)
printf "相差高度:%d " $dHeight
printf "同步速度:%5.2f blocks/s " $sync_speed
printf "剩余时间:%02d:%02d:%02d \n" $est_time_hours $est_time_minutes $est_time_seconds
else
printf "相差高度:%d 同步速度太慢! \n" $dHeight
fi
else
printf "相差高度:%d \n" $dHeight
fi
# 判断高度是否小于特定值
if [ ${dHeight#-} -lt 5 ]; then
break
fi
get_block_height
dHeight=$(echo "obase=10; ibase=16; ${globalHeight:2}-${LocalHeight:2}" | bc)
total_run_time=$(echo "$total_run_time+$interval_time" | bc)
sleep $interval_time
done