@@ -25,6 +25,12 @@ function fetch_gas_price() {
2525 echo $gas_price
2626}
2727
28+ # Get batcher queue len
29+ function get_queue_length() {
30+ queue_len=$( curl $BATCHER_METRICS_URL -s | grep queue_len | awk ' {print $2}' | tail -n 1)
31+ echo $queue_len
32+ }
33+
2834source " $ENV_FILE "
2935
3036# Each elapsed interval lasts for 5 minutes
@@ -48,45 +54,59 @@ while true; do
4854 fi
4955 echo " Current gas price: $current_gas_price wei"
5056
57+ queue_len=$( get_queue_length)
58+ if [ " $queue_len " -eq 0 ]; then
59+ echo " There are no pending proofs in the queue, skipping this pass."
60+ echo " Sleeping $sleep_time seconds (($(( sleep_time / 60 )) minutes))"
61+ sleep " $sleep_time "
62+ continue
63+ fi
64+
5165 # In case current and gas price meet the criteria, send a proof and reset counter
52- if { [ $elapsed_intervals -ge 1 ] && [ $elapsed_intervals -lt 3 ] && [ $current_gas_price -lt 1500000000 ]; }; then
53- # Between 1 and 3 elapsed intervals (5 to 15 minutes), if gas price is below 1.5 gwei, send a proof
66+ if { [ $elapsed_intervals -ge 1 ] && [ $elapsed_intervals -lt 3 ] && [ $current_gas_price -lt 500000000 ]; }; then
67+ # At 1 tick (5 minutes), if gas price is below 0.5 gwei, send a proof
68+ message=" Sending proof at $elapsed_intervals with gas price $current_gas_price wei"
69+ echo " $message "
70+ send_proof_background
71+ elapsed_intervals=0
72+ elif { [ $elapsed_intervals -ge 3 ] && [ $elapsed_intervals -lt 6 ] && [ $current_gas_price -lt 1500000000 ]; }; then
73+ # At 3 ticks (15 minutes), if gas price is below 1.5 gwei, send a proof
5474 message=" Sending proof at $elapsed_intervals with gas price $current_gas_price wei"
5575 echo " $message "
5676 send_proof_background
5777 elapsed_intervals=0
58- elif { [ $elapsed_intervals -ge 3 ] && [ $elapsed_intervals -lt 6 ] && [ $current_gas_price -lt 4500000000 ]; }; then
59- # Between 3 and 6 elapsed intervals (15 to 30 minutes), if gas price is below 4.5 gwei, send a proof
78+ elif { [ $elapsed_intervals -ge 6 ] && [ $elapsed_intervals -lt 12 ] && [ $current_gas_price -lt 3000000000 ]; }; then
79+ # At 6 ticks ( 30 minutes), if gas price is below 3 gwei, send a proof
6080 message=" Sending proof at $elapsed_intervals with gas price $current_gas_price wei"
6181 echo " $message "
6282 send_proof_background
6383 elapsed_intervals=0
64- elif { [ $elapsed_intervals -ge 6 ] && [ $elapsed_intervals -lt 12 ] && [ $current_gas_price -lt 9000000000 ]; }; then
65- # Between 6 and 12 elapsed intervals (30 minutes to 1 hour), if gas price is below 9 gwei, send a proof
84+ elif { [ $elapsed_intervals -ge 12 ] && [ $elapsed_intervals -lt 24 ] && [ $current_gas_price -lt 6000000000 ]; }; then
85+ # At 12 ticks ( 1 hour), if gas price is below 6 gwei, send a proof
6686 message=" Sending proof at $elapsed_intervals with gas price $current_gas_price wei"
6787 echo " $message "
6888 send_proof_background
6989 elapsed_intervals=0
70- elif { [ $elapsed_intervals -ge 12 ] && [ $elapsed_intervals -lt 24 ] && [ $current_gas_price -lt 24000000000 ]; }; then
71- # Between 12 and 24 elapsed intervals (1 to 2 hours), if gas price is below 24 gwei, send a proof
90+ elif { [ $elapsed_intervals -ge 24 ] && [ $elapsed_intervals -lt 48 ] && [ $current_gas_price -lt 12000000000 ]; }; then
91+ # At 24 ticks ( 2 hours), if gas price is below 12 gwei, send a proof
7292 message=" Sending proof at $elapsed_intervals with gas price $current_gas_price wei"
7393 echo " $message "
7494 send_proof_background
7595 elapsed_intervals=0
76- elif { [ $elapsed_intervals -ge 24 ] && [ $elapsed_intervals -lt 48 ] && [ $current_gas_price -lt 48000000000 ]; }; then
77- # Between 24 and 48 elapsed intervals (2 to 4 hours), if gas price is below 48 gwei, send a proof
96+ elif { [ $elapsed_intervals -ge 48 ] && [ $elapsed_intervals -lt 96 ] && [ $current_gas_price -lt 24000000000 ]; }; then
97+ # At 48 ticks ( 4 hours), if gas price is below 24 gwei, send a proof
7898 message=" Sending proof at $elapsed_intervals with gas price $current_gas_price wei"
7999 echo " $message "
80100 send_proof_background
81101 elapsed_intervals=0
82- elif { [ $elapsed_intervals -ge 48 ] && [ $elapsed_intervals -lt 96 ] && [ $current_gas_price -lt 96000000000 ]; }; then
83- # Between 48 and 96 elapsed intervals (4 to 8 hours), if gas price is below 96 gwei, send a proof
102+ elif { [ $elapsed_intervals -ge 96 ] && [ $elapsed_intervals -lt 192 ] && [ $current_gas_price -lt 48000000000 ]; }; then
103+ # At 96 ticks ( 8 hours), if gas price is below 48 gwei, send a proof
84104 message=" Sending proof at $elapsed_intervals with gas price $current_gas_price wei"
85105 echo " $message "
86106 send_proof_background
87107 elapsed_intervals=0
88- elif { [ $elapsed_intervals -ge 96 ] && [ $current_gas_price -lt 192000000000 ]; }; then
89- # After 96 elapsed intervals (8 hours), if gas price is below 192 gwei, send a proof
108+ elif { [ $elapsed_intervals -ge 192 ] && [ $current_gas_price -lt 96000000000 ]; }; then
109+ # At 192 ticks (16 hours), if gas price is below 96 gwei, send a proof
90110 message=" Sending proof at $elapsed_intervals with gas price $current_gas_price wei"
91111 echo " $message "
92112 send_proof_background
0 commit comments