Skip to content

Commit d7830a2

Browse files
authored
feat(task sender): send a batch every 24hs (#2195)
1 parent 761f761 commit d7830a2

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

alerts/periodic_sender_24hs.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
# This script is responsible for the handling of periodic sending, and the clauses for sending proofs.
3+
# It forwards the path of the .env file as the first argument to the sender_with_alert.sh script when
4+
# the conditions are met.
5+
6+
ENV_FILE="$1"
7+
8+
if [[ -z "$ENV_FILE" ]]; then
9+
echo "Usage: $0 path/to/.env"
10+
exit 1
11+
fi
12+
13+
function send_proof_background() {
14+
./alerts/sender_with_alert.sh "$ENV_FILE" &
15+
}
16+
17+
# Fetches the current ETH gas price
18+
function fetch_gas_price() {
19+
gas_price=$(cast gas-price --rpc-url $RPC_URL)
20+
if [[ -z "$gas_price" || "$gas_price" == "0" ]]; then
21+
echo "Primary RPC_URL failed to fetch gas price, trying fallback..."
22+
gas_price=$(cast gas-price --rpc-url $RPC_URL_FALLBACK)
23+
fi
24+
25+
echo $gas_price
26+
}
27+
28+
source "$ENV_FILE"
29+
30+
# Each elapsed interval lasts for 5 minutes
31+
sleep_time=300
32+
elapsed_intervals=0
33+
34+
./alerts/sender_with_alert.sh "$ENV_FILE"
35+
36+
while true; do
37+
echo "Starting pass #$elapsed_intervals"
38+
39+
current_gas_price=$(fetch_gas_price)
40+
if [[ -z "$current_gas_price" || "$current_gas_price" == "0" ]]; then
41+
echo "Failed to fetch current gas price from both RPC URLs, skipping this pass."
42+
43+
elapsed_intervals=$((elapsed_intervals + 1))
44+
45+
echo "Sleeping $sleep_time seconds (($((sleep_time / 60)) minutes))"
46+
sleep "$sleep_time"
47+
continue
48+
fi
49+
echo "Current gas price: $current_gas_price wei"
50+
51+
# In case current and gas price meet the criteria, send a proof and reset counter
52+
if { [ $elapsed_intervals -ge 264 ] && [ $current_gas_price -lt 10000000000 ]; }; then
53+
# At 264 tick (22 hours), if gas price is below 10 gwei, send a proof
54+
# It is set to 22 hours instead of 24 to add a buffer in case of high gas prices
55+
message="Sending proof at $elapsed_intervals with gas price $current_gas_price wei"
56+
echo "$message"
57+
send_proof_background
58+
elapsed_intervals=0
59+
fi
60+
61+
elapsed_intervals=$((elapsed_intervals + 1))
62+
63+
echo "Sleeping $sleep_time seconds (($((sleep_time / 60)) minutes))"
64+
sleep "$sleep_time"
65+
done

0 commit comments

Comments
 (0)