From 9cc7c804eb394ee1afa52704e22671e6944f0102 Mon Sep 17 00:00:00 2001 From: Donovan Tjemmes <37707055+Tjemmmic@users.noreply.github.com> Date: Wed, 20 Nov 2024 11:05:55 -0600 Subject: [PATCH] fix: solve aggregator initialization race condition (#491) --- .../src/contexts/aggregator.rs | 10 ++++++++++ blueprints/incredible-squaring-eigenlayer/src/tests.rs | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/blueprints/incredible-squaring-eigenlayer/src/contexts/aggregator.rs b/blueprints/incredible-squaring-eigenlayer/src/contexts/aggregator.rs index 7b039081..d79a67b1 100644 --- a/blueprints/incredible-squaring-eigenlayer/src/contexts/aggregator.rs +++ b/blueprints/incredible-squaring-eigenlayer/src/contexts/aggregator.rs @@ -291,6 +291,16 @@ impl AggregatorContext { let task_index = task_response.referenceTaskIndex; let task_response_digest = keccak256(TaskResponse::abi_encode(&task_response)); + // Check if we have the task initialized first + if !self.tasks.lock().await.contains_key(&task_index) { + info!( + "Task {} not yet initialized, caching response for later processing", + task_index + ); + self.response_cache.lock().await.push_back(resp); + return Ok(()); + } + if self .tasks_responses .lock() diff --git a/blueprints/incredible-squaring-eigenlayer/src/tests.rs b/blueprints/incredible-squaring-eigenlayer/src/tests.rs index c3f3d05d..a6d9a5fd 100644 --- a/blueprints/incredible-squaring-eigenlayer/src/tests.rs +++ b/blueprints/incredible-squaring-eigenlayer/src/tests.rs @@ -245,7 +245,8 @@ pub async fn setup_task_spawner( let quorums = Bytes::from(vec![0]); async move { loop { - tokio::time::sleep(std::time::Duration::from_millis(5000)).await; + // Increased delay to allow for proper task initialization + tokio::time::sleep(std::time::Duration::from_secs(10)).await; info!("Creating a new task..."); if get_receipt( @@ -270,6 +271,9 @@ pub async fn setup_task_spawner( info!("Updated operators for quorum..."); } + // Wait for task initialization to complete + tokio::time::sleep(std::time::Duration::from_secs(2)).await; + tokio::process::Command::new("sh") .arg("-c") .arg(format!(