diff --git a/mutiny-core/src/hermes.rs b/mutiny-core/src/hermes.rs index 4a730b25d..0b37015e9 100644 --- a/mutiny-core/src/hermes.rs +++ b/mutiny-core/src/hermes.rs @@ -159,6 +159,7 @@ impl HermesClient { let current_address_check_clone = self.current_address.clone(); let first_federation = self.get_first_federation().await.clone(); utils::spawn(async move { + let mut count = 1; loop { if stop_check_clone.load(Ordering::Relaxed) { break; @@ -263,7 +264,10 @@ impl HermesClient { } }; - utils::sleep(1_000).await; + // exponential backoff + let sleep_time = std::cmp::min(1_000 * (2_i32.pow(count)), 60_000); + utils::sleep(sleep_time).await; + count += 1; } }); diff --git a/mutiny-core/src/lib.rs b/mutiny-core/src/lib.rs index 43a668bc7..74af9cbd7 100644 --- a/mutiny-core/src/lib.rs +++ b/mutiny-core/src/lib.rs @@ -1482,12 +1482,16 @@ impl MutinyWallet { let self_clone = self.clone(); utils::spawn(async move { // keep trying until it succeeds + let mut count = 1; loop { match self_clone.sync_nostr().await { Ok(_) => break, Err(e) => { log_error!(self_clone.logger, "Failed to sync nostr: {e}"); - sleep(5_000).await; + + // exponential backoff + let sleep_time = std::cmp::min(1_000 * (2_i32.pow(count)), 60_000); + sleep(sleep_time).await; } }