[bug] quick fix by removing commit msg from cache to allow retry

This commit is contained in:
NicolasCantu 2025-02-04 10:47:31 +01:00 committed by Nicolas Cantu
parent 44adac04d7
commit dcf76a6df6

View File

@ -31,7 +31,12 @@ impl MessageCache {
fn insert(&self, key: String) {
let mut store = self.store.lock().unwrap();
store.insert(key.clone(), Instant::now());
store.insert(key, Instant::now());
}
fn remove(&self, key: &str) {
let mut store = self.store.lock().unwrap();
store.remove(key);
}
fn contains(&self, key: &str) -> bool {
@ -50,8 +55,8 @@ impl MessageCache {
let mut store = cache.store.lock().unwrap();
let now = Instant::now();
store.retain(|_, &mut entrytime| {
now.duration_since(entrytime) <= MESSAGECACHEDURATION
store.retain(|_, entrytime| {
now.duration_since(*entrytime) <= MESSAGECACHEDURATION
});
}
}
@ -179,6 +184,9 @@ fn process_commit_message(ank_msg: Envelope, addr: SocketAddr) {
Ok(new_outpoint) => log::debug!("Processed commit msg for outpoint {}", new_outpoint),
Err(e) => {
log::error!("handle_commit_request returned error: {}", e);
// Temporary fix: we remove the message from the cache in case the client wants to try again
let cache = MESSAGECACHE.get().expect("Cache should be initialized");
cache.remove(ank_msg.to_string().as_str());
commit_msg.error = Some(e.into());
if let Err(e) = broadcast_message(
AnkFlag::Commit,