From 75313664490e770fc7f5cede9e43e658cb5ebb8a Mon Sep 17 00:00:00 2001 From: Delweng Date: Thu, 25 Jul 2024 05:32:32 +0800 Subject: [PATCH] fix(rpc/eth): remove cache when reorg occured (#9775) Signed-off-by: jsvisa --- .../rpc/rpc-eth-types/src/cache/multi_consumer.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/crates/rpc/rpc-eth-types/src/cache/multi_consumer.rs b/crates/rpc/rpc-eth-types/src/cache/multi_consumer.rs index 77d8613433..8ca7208d22 100644 --- a/crates/rpc/rpc-eth-types/src/cache/multi_consumer.rs +++ b/crates/rpc/rpc-eth-types/src/cache/multi_consumer.rs @@ -61,15 +61,12 @@ where } } - /// Remove consumers for a given key. + /// Remove consumers for a given key, this will also remove the key from the cache. pub fn remove(&mut self, key: &K) -> Option> { - match self.queued.remove(key) { - Some(removed) => { - self.metrics.queued_consumers_count.decrement(removed.len() as f64); - Some(removed) - } - None => None, - } + let _ = self.cache.remove(key); + self.queued + .remove(key) + .inspect(|removed| self.metrics.queued_consumers_count.decrement(removed.len() as f64)) } /// Returns a reference to the value for a given key and promotes that element to be the most