From 8b695401a2dd629763808de91abd966d33c88232 Mon Sep 17 00:00:00 2001 From: Keyao Shen Date: Sat, 30 Sep 2023 16:28:42 -0700 Subject: [PATCH] Fix index update and parameter --- crates/web_server/src/lib.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/crates/web_server/src/lib.rs b/crates/web_server/src/lib.rs index 2bd746e1cd..fe80e0c129 100644 --- a/crates/web_server/src/lib.rs +++ b/crates/web_server/src/lib.rs @@ -317,7 +317,12 @@ impl WebServerDataSource for WebServerState { .or_insert_with(|| vec![(*highest_index, vote)]); self.view_sync_vote_index .entry(view_number) - .and_modify(|index| *index += 1); + .and_modify(|index| { + // Update the index if it's not just added. + if *index > 0 { + *index += 1 + } + }); Ok(()) } /// Stores a received proposal in the `WebServerState` @@ -349,7 +354,8 @@ impl WebServerDataSource for WebServerState { ) -> Result<(), Error> { // Only keep proposal history for MAX_VIEWS number of view if self.view_sync_proposals.len() >= MAX_VIEWS { - self.view_sync_proposals.remove(&self.oldest_view_sync_vote); + self.view_sync_proposals + .remove(&self.oldest_view_sync_proposal); while !self .view_sync_proposals .contains_key(&self.oldest_view_sync_proposal) @@ -367,7 +373,12 @@ impl WebServerDataSource for WebServerState { .or_insert_with(|| vec![(*highest_index, proposal)]); self.view_sync_proposal_index .entry(view_number) - .and_modify(|index| *index += 1); + .and_modify(|index| { + // Update the index if it's not just added. + if *index > 0 { + *index += 1 + } + }); Ok(()) }