Skip to content

Commit

Permalink
removed jitter from interact transaction fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaicalinluca committed May 16, 2024
1 parent 7c30447 commit 122e383
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 7 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion framework/snippets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ base64 = "0.22"
log = "0.4.17"
env_logger = "0.11"
futures = "0.3"
rand = "0.8.5"

[dependencies.multiversx-sc-scenario]
version = "=0.50.1"
Expand Down
6 changes: 1 addition & 5 deletions framework/snippets/src/interactor_retrieve.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::Interactor;
use log::info;
use multiversx_sdk::data::transaction::TransactionOnNetwork;
use rand::Rng;
use std::time::{Duration, Instant};

const INITIAL_BACKOFF_DELAY: f32 = 1.4;
Expand All @@ -11,7 +10,6 @@ const MAX_BACKOFF_DELAY: Duration = Duration::from_secs(6);
impl Interactor {
/// Retrieves a transaction from the network.
pub(crate) async fn retrieve_tx_on_network(&self, tx_hash: String) -> TransactionOnNetwork {
let mut rng = rand::thread_rng();
let mut retries = 0;
let mut backoff_delay = Duration::from_secs_f32(INITIAL_BACKOFF_DELAY);
let start_time = Instant::now();
Expand Down Expand Up @@ -47,9 +45,7 @@ impl Interactor {
break;
}

let backoff_time = backoff_delay
.mul_f32(rng.gen_range(0.8..1.2))
.min(MAX_BACKOFF_DELAY);
let backoff_time = backoff_delay.min(MAX_BACKOFF_DELAY);
tokio::time::sleep(backoff_time).await;
backoff_delay *= 2; // exponential backoff
},
Expand Down

0 comments on commit 122e383

Please sign in to comment.