Skip to content
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

fix(host): Backoff after MAX_RETRIES #429

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions bin/host/src/fetcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ where

/// Get the preimage for the given key.
pub async fn get_preimage(&self, key: B256) -> Result<Vec<u8>> {
const MAX_RETRIES: usize = 32;

trace!(target: "fetcher", "Pre-image requested. Key: {key}");

// Acquire a read lock on the key-value store.
Expand All @@ -77,12 +79,20 @@ where
drop(kv_lock);

// Use a loop to keep retrying the prefetch as long as the key is not found
let mut retries = 0;
while preimage.is_none() && self.last_hint.is_some() {
if retries >= MAX_RETRIES {
tracing::error!(target: "fetcher", "Max retries exceeded.");
anyhow::bail!("Max retries exceeded.");
}

let hint = self.last_hint.as_ref().expect("Cannot be None");
self.prefetch(hint).await?;

let kv_lock = self.kv_store.read().await;
preimage = kv_lock.get(key);

retries += 1;
}

preimage.ok_or_else(|| anyhow!("Preimage not found."))
Expand Down
5 changes: 4 additions & 1 deletion bin/host/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ where
// Spawn tasks for the futures and wait for them to complete.
let server = tokio::task::spawn(server_fut);
let hint_router = tokio::task::spawn(hinter_fut);
tokio::try_join!(server, hint_router).map_err(|e| anyhow!(e))?;
tokio::select! {
s = server => s.map_err(|e| anyhow!(e))?,
h = hint_router => h.map_err(|e| anyhow!(e))?,
}

Ok(())
}
Expand Down
Loading