-
Notifications
You must be signed in to change notification settings - Fork 396
feat: improve periodic proof sending script #2156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+215
−138
Merged
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1037d7f
Initial version
maximopalopoli ed0e939
Reset the tic counter after sending a proof
maximopalopoli 433298c
Remove the gas price constraint after an amount of tocs
maximopalopoli 32f860f
Log an error in case the eth price fetch fails
maximopalopoli 50730d5
Fix the amount of time between iterations
maximopalopoli a1aab86
Remove unnecesary error handling
maximopalopoli 5317e93
Improve comments on the periodic sender script
maximopalopoli 1efa0b3
Add a fallback RPC URL for fetching the eth gas price
maximopalopoli 5c8880a
Rename tics to elapsed intervals
maximopalopoli 1d53c9a
Remove solved TODO comment
maximopalopoli 485d8e9
fix: send first proofs at the beginning of the script
JuArce 4b3e90a
Merge branch 'testnet' into feat/improve-periodic-proof-sending-script
JuArce 8ec0886
Update alerts/periodic_sender.sh
maximopalopoli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| #!/bin/bash | ||
| # This script is responsible for the handling of periodic sending, and the clauses for sending proofs. | ||
| # It forwards the path of the .env file as the first argument to the sender_with_alert.sh script when | ||
| # the conditions are met. | ||
|
|
||
| ENV_FILE="$1" | ||
|
|
||
| if [[ -z "$ENV_FILE" ]]; then | ||
| echo "Usage: $0 path/to/.env" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Fetches the current ETH gas price | ||
| function fetch_gas_price() { | ||
| gas_price=$(cast gas-price --rpc-url $RPC_URL) | ||
| if [[ -z "$gas_price" || "$gas_price" == "0" ]]; then | ||
| echo "Primary RPC_URL failed to fetch gas price, trying fallback..." | ||
| gas_price=$(cast gas-price --rpc-url $RPC_URL_FALLBACK) | ||
| fi | ||
|
|
||
| echo $gas_price | ||
| } | ||
|
|
||
| source "$ENV_FILE" | ||
|
|
||
| # Each elapsed interval lasts for 30 minutes | ||
| sleep_time=1800 | ||
| elapsed_intervals=0 | ||
|
|
||
| while true; do | ||
| echo "Starting pass #$elapsed_intervals" | ||
|
|
||
| current_gas_price=$(fetch_gas_price) | ||
| if [[ -z "$current_gas_price" || "$current_gas_price" == "0" ]]; then | ||
| echo "Failed to fetch current gas price from both RPC URLs, skipping this pass." | ||
|
|
||
| elapsed_intervals=$((elapsed_intervals + 1)) | ||
|
|
||
| echo "Sleeping $sleep_time seconds (($((sleep_time / 60)) minutes))" | ||
| sleep "$sleep_time" | ||
| continue | ||
| fi | ||
| echo "Current gas price: $current_gas_price wei" | ||
|
|
||
| # In case current and gas price meet the criteria, send a proof and reset counter | ||
| if { [ $elapsed_intervals -ge 10 ] && [ $elapsed_intervals -lt 14 ] && [ $current_gas_price -lt 2000000000 ]; }; then | ||
| # Between 10 and 14 elapsed intervals (5 to 7 hours), if gas price is below 2 gwei, send a proof | ||
| message="Sending proof at $elapsed_intervals with gas price $current_gas_price wei" | ||
| echo "$message" | ||
| ./alerts/sender_with_alert.sh "$ENV_FILE" | ||
| elapsed_intervals=0 | ||
| elif { [ $elapsed_intervals -ge 14 ] && [ $elapsed_intervals -lt 16 ] && [ $current_gas_price -lt 5000000000 ]; }; then | ||
| # Between 14 and 16 elapsed intervals (7 to 8 hours), if gas price is below 5 gwei, send a proof | ||
| message="Sending proof at $elapsed_intervals with gas price $current_gas_price wei" | ||
| echo "$message" | ||
| ./alerts/sender_with_alert.sh "$ENV_FILE" | ||
| elapsed_intervals=0 | ||
| elif { [ $elapsed_intervals -ge 16 ] && [ $elapsed_intervals -lt 24 ] && [ $current_gas_price -lt 15000000000 ]; }; then | ||
| # Between 16 and 24 elapsed intervals (8 to 12 hours), if gas price is below 15 gwei, send a proof | ||
| message="Sending proof at $elapsed_intervals with gas price $current_gas_price wei" | ||
| echo "$message" | ||
| ./alerts/sender_with_alert.sh "$ENV_FILE" | ||
| elapsed_intervals=0 | ||
| elif { [ $elapsed_intervals -ge 50 ]; }; then | ||
| # After 50 elapsed intervals (25 hours), if gas price is below 50 gwei, send a proof | ||
| message="Sending proof at $elapsed_intervals with gas price $current_gas_price wei" | ||
| echo "$message" | ||
| ./alerts/sender_with_alert.sh "$ENV_FILE" | ||
| elapsed_intervals=0 | ||
| fi | ||
|
|
||
| elapsed_intervals=$((elapsed_intervals + 1)) | ||
|
|
||
| echo "Sleeping $sleep_time seconds (($((sleep_time / 60)) minutes))" | ||
| sleep "$sleep_time" | ||
| done | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.