Skip to content

Commit

Permalink
Add env variable for RETRY_TX_INTERVAL (#1036)
Browse files Browse the repository at this point in the history
* Add env variable for RETRY_TX_INTERVAL

* print each 5 mins

* fix import

* update

* use trace

* clean upà

* add back RETRY_TX_INTERVAL in hive
  • Loading branch information
tcoratger authored Apr 30, 2024
1 parent 2fbec79 commit f6e9197
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ EVM_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff

# Number of Felt (bytes) allowed in a single call data
MAX_FELTS_IN_CALLDATA=22500

# Interval between retries of transactions (in seconds)
RETRY_TX_INTERVAL=10
1 change: 1 addition & 0 deletions docker-compose.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ services:
- UNINITIALIZED_ACCOUNT_CLASS_HASH=0x600f6862938312a05a0cfecba0dcaf37693efc9e4075a6adfb62e196022678e
- ACCOUNT_CONTRACT_CLASS_HASH=0x490cccb64e3917ecf0a80a59d0c3e449766f745c1d6db54e0050f89eb59aba1
- MAX_FELTS_IN_CALLDATA=30000
- RETRY_TX_INTERVAL=10
restart: on-failure
volumes:
# Mount the indexer code
Expand Down
1 change: 1 addition & 0 deletions docker-compose.staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ services:
- UNINITIALIZED_ACCOUNT_CLASS_HASH=0x1d8b8047e26b484d3f6262d1967217d980d0f2dfc69afa5661492bd5bfe2954
- ACCOUNT_CONTRACT_CLASS_HASH=0x56d311021950bf65ee500426e007b9e3ced0db97f9c1e0d29a9e03d79a9bf6c
- MAX_FELTS_IN_CALLDATA=30000
- RETRY_TX_INTERVAL=10
restart: on-failure
volumes:
# Mount the indexer code
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ services:
- MONGO_CONNECTION_STRING=mongodb://mongo:mongo@mongo:27017
- MONGO_DATABASE_NAME=kakarot-local
- MAX_FELTS_IN_CALLDATA=30000
- RETRY_TX_INTERVAL=1
volumes:
# Mount the volume on workdir and use .env stored in root of the volume
- deployments:/usr/src/app
Expand Down
3 changes: 2 additions & 1 deletion docker/hive/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ ENV KAKAROT_RPC_URL=0.0.0.0:8545
ENV STARKNET_NETWORK=http://localhost:5050
ENV RUST_LOG=kakarot_rpc=info
ENV MAX_FELTS_IN_CALLDATA=30000
ENV DEFAULT_BLOCK_GAS_LIMIT=7000000
ENV RETRY_TX_INTERVAL=10
ENV DEFAULT_BLOCK_GAS_LIMIT=7000000

HEALTHCHECK --interval=10s --timeout=10s --start-period=15s --retries=5 \
CMD response=$(curl --silent --request POST \
Expand Down
30 changes: 28 additions & 2 deletions src/eth_provider/pending_pool.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
use crate::eth_provider::provider::EthDataProvider;
use lazy_static::lazy_static;
use std::str::FromStr;
use std::time::Instant;
use tokio::time::{sleep, Duration};

lazy_static! {
// Interval between retries of transactions (in seconds)
pub static ref RETRY_TX_INTERVAL: usize = usize::from_str(
&std::env::var("RETRY_TX_INTERVAL")
.unwrap_or_else(|_| panic!("Missing environment variable RETRY_TX_INTERVAL"))
).expect("failing to parse RETRY_TX_INTERVAL");
}

pub async fn start_retry_service<SP>(eth_provider: EthDataProvider<SP>)
where
SP: starknet::providers::Provider + Send + Sync,
{
// Initialize last print time
let mut last_print_time = Instant::now();

// Start an infinite loop.
loop {
// Measure start time
let start_time_fn = Instant::now();
// Call the retry_transactions method
if let Err(err) = eth_provider.retry_transactions().await {
tracing::error!("Error while retrying transactions: {:?}", err);
}
// 30-second pause
sleep(Duration::from_secs(30)).await;
// Calculate elapsed time in milliseconds
let elapsed_time_ms = start_time_fn.elapsed().as_millis();

// Check if 5 minutes have passed since the last print
if last_print_time.elapsed() >= Duration::from_secs(300) {
tracing::info!("Elapsed time to retry transactions (milliseconds): {}", elapsed_time_ms);
// Update last print time
last_print_time = Instant::now();
}

// pause
sleep(Duration::from_secs(*RETRY_TX_INTERVAL as u64)).await;
}
}

0 comments on commit f6e9197

Please sign in to comment.