From 93eed48112b7c59864831f72b56fd1a1ff8186d8 Mon Sep 17 00:00:00 2001 From: Pravdyvy Date: Fri, 24 Jul 2026 08:02:03 +0300 Subject: [PATCH] fix(wallet): suggestion fix 3 --- lez/wallet/src/lib.rs | 2 +- lez/wallet/src/multi_client.rs | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lez/wallet/src/lib.rs b/lez/wallet/src/lib.rs index e38b33b9..3388755d 100644 --- a/lez/wallet/src/lib.rs +++ b/lez/wallet/src/lib.rs @@ -273,7 +273,7 @@ impl WalletCore { pub async fn client_rotation(&mut self) -> Result<()> { self.multi_sequencer_client .update_statistics(&mut self.statistics) - .await; + .await?; self.multi_sequencer_client .rotate( diff --git a/lez/wallet/src/multi_client.rs b/lez/wallet/src/multi_client.rs index a8a63861..3c9da807 100644 --- a/lez/wallet/src/multi_client.rs +++ b/lez/wallet/src/multi_client.rs @@ -152,7 +152,11 @@ impl MultiSequencerClient { ) .ok_or_else(|| anyhow::anyhow!("Failed to find leader"))?; - assert_ne!(leader_list.len(), 0); + if leader_list.is_empty() { + anyhow::bail!( + "Leader search algorithm failure: Sorted out all clients during leader search" + ); + } log::info!("Chosen leaders is {leader_list:?}"); @@ -322,18 +326,20 @@ impl MultiSequencerClient { } /// Update statistics of a leader, clear statistic updates log. - pub async fn update_statistics(&self, statistics: &mut HashMap) { + pub async fn update_statistics(&self, statistics: &mut HashMap) -> Result<()> { let mut statistic_updates = self.statistic_updates.write().await; #[expect(clippy::iter_over_hash_type, reason = "Ordering is unnecesary here")] for (addr, statistic_updates_vec) in statistic_updates.iter() { let leader_statistic = statistics .get_mut(addr) - .expect("Leader statistic must be present after setup"); + .ok_or_else(|| anyhow::anyhow!("Leader statistic must be present after setup"))?; leader_statistic.apply_updates(statistic_updates_vec.as_slice()); } statistic_updates.clear(); + + Ok(()) } }