Skip to content

Commit 1efa0b3

Browse files
Add a fallback RPC URL for fetching the eth gas price
1 parent 5317e93 commit 1efa0b3

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

alerts/.env.devnet

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
# # Variables for contract_alerts.sh
66
# RPC_URL=<YOUR_RPC_URL>
7+
# RPC_URL_FALLBACK=<YOUR_FALLBACK_RPC_URL>
78
# CONTRACT_ADDRESS=<YOUR_CONTRACT_ADDRESS>
89
# NEW_BATCH_TOPIC=<YOUR_NEW_BATCH_TOPIC>
910
# VERIFIED_BATCH_TOPIC=<YOUR_VERIFIED_BATCH_TOPIC>
@@ -17,6 +18,7 @@
1718

1819
# # Variables for balance_alerts.sh
1920
# RPC_URL=<YOUR_RPC_URL>
21+
# RPC_URL_FALLBACK=<YOUR_FALLBACK_RPC_URL>
2022
# PAYMENT_CONTRACT_ADDRESS=<YOUR_PAYMENT_CONTRACT_ADDRESS>
2123
# BALANCE_THRESHOLD=<YOUR_BALANCE_THRESHOLD_IN_ETH>
2224
# WALLET_ADDRESS=<YOUR_WALLET_ADDRESS>

alerts/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ EXPRESSION=<GREP_EXPRESSION>
1717

1818
# Variables for balance_alerts.sh
1919
RPC_URL=<YOUR_RPC_URL>
20+
RPC_URL_FALLBACK=<YOUR_FALLBACK_RPC_URL>
2021
PAYMENT_CONTRACT_ADDRESS=<YOUR_PAYMENT_CONTRACT_ADDRESS>
2122
BALANCE_THRESHOLD=<YOUR_BALANCE_THRESHOLD_IN_ETH>
2223
WALLET_NAME=<YOUR_WALLET_NAME> # Example: "Task sender"
@@ -37,6 +38,7 @@ LOGS_BLOCK_RANGE=<LOGS_BLOCK_RANGE>
3738
CONTRACT_ADDRESS=<YOUR_CONTRACT_ADDRESS>
3839
AGGREGATED_PROOF_VERIFIED_TOPIC=0xfe3e9e971000ab9c80c7e06aba2933aae5419d0e44693e3046913e9e58053f62
3940
RPC_URL=<YOUR_RPC_URL>
41+
RPC_URL_FALLBACK=<YOUR_FALLBACK_RPC_URL>
4042
LOGS_BLOCK_RANGE=7500
4143
SLEEP_TIME=3600
4244
PAGER_DUTY_KEY=<YOUR_PAGER_DUTY_KEY>

alerts/periodic_sender.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ fi
1414
function fetch_gas_price() {
1515
# TODO: We should have a second RPC_URL for fetching gas price to avoid being rate limited
1616
gas_price=$(cast gas-price --rpc-url $RPC_URL)
17+
if [[ -z "$gas_price" || "$gas_price" == "0" ]]; then
18+
echo "Primary RPC_URL failed to fetch gas price, trying fallback..."
19+
gas_price=$(cast gas-price --rpc-url $RPC_URL_FALLBACK)
20+
fi
21+
1722
echo $gas_price
1823
}
1924

@@ -27,6 +32,15 @@ while true; do
2732
echo "Starting pass #$tic"
2833

2934
current_gas_price=$(fetch_gas_price)
35+
if [[ -z "$current_gas_price" || "$current_gas_price" == "0" ]]; then
36+
echo "Failed to fetch current gas price from both RPC URLs, skipping this pass."
37+
38+
tic=$((tic + 1))
39+
40+
echo "Sleeping $sleep_time seconds (($((sleep_time / 60)) minutes))"
41+
sleep "$sleep_time"
42+
continue
43+
fi
3044
echo "Current gas price: $current_gas_price wei"
3145

3246
# In case current tic and gas price meet the criteria, send a proof and reset tic counter

0 commit comments

Comments
 (0)