diff --git a/Cargo.lock b/Cargo.lock index 4138a0b0f0..944baa5fc9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6961,9 +6961,9 @@ dependencies = [ [[package]] name = "timed-map" -version = "1.2.4" +version = "1.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea2a27094b9edb49c6004ae347d48f1ec92ffb66c2c417686a3eb56e4519aca0" +checksum = "80e3ea595549a7a7abddb819737c7fa2fa40a6437822f5d120f97d58200e4968" dependencies = [ "rustc-hash", "web-time", diff --git a/mm2src/coins/eth/web3_transport/websocket_transport.rs b/mm2src/coins/eth/web3_transport/websocket_transport.rs index d86e365173..e530bbefdf 100644 --- a/mm2src/coins/eth/web3_transport/websocket_transport.rs +++ b/mm2src/coins/eth/web3_transport/websocket_transport.rs @@ -144,7 +144,7 @@ impl WebsocketTransport { serialized_request, response_notifier, })) => { - response_notifiers.insert_expirable_unchecked( + response_notifiers.insert_expirable( request_id, response_notifier, // Since request will be cancelled when timeout occurs, we are free to drop its state. @@ -248,7 +248,8 @@ impl WebsocketTransport { let _guard = self.connection_guard.lock().await; // List of awaiting requests - let mut response_notifiers: TimedMap>> = TimedMap::default(); + let mut response_notifiers: TimedMap>> = + TimedMap::new_with_map_kind(timed_map::MapKind::FxHashMap).expiration_tick_cap(30); let mut wsocket = match self .attempt_to_establish_socket_connection(MAX_ATTEMPTS, SLEEP_DURATION) diff --git a/mm2src/coins/utxo/rpc_clients/electrum_rpc/connection.rs b/mm2src/coins/utxo/rpc_clients/electrum_rpc/connection.rs index 3e52493d39..6782c68759 100644 --- a/mm2src/coins/utxo/rpc_clients/electrum_rpc/connection.rs +++ b/mm2src/coins/utxo/rpc_clients/electrum_rpc/connection.rs @@ -177,7 +177,7 @@ impl ElectrumConnection { settings, tx: Mutex::new(None), establishing_connection: AsyncMutex::new(()), - responses: Mutex::new(JsonRpcPendingRequests::new_with_map_kind(MapKind::BTreeMap)), + responses: Mutex::new(JsonRpcPendingRequests::new_with_map_kind(MapKind::BTreeMap).expiration_tick_cap(50)), protocol_version: Mutex::new(None), last_error: Mutex::new(None), abortable_system, @@ -251,7 +251,7 @@ impl ElectrumConnection { self.responses .lock() .unwrap() - .insert_expirable_unchecked(rpc_id, req_tx, Duration::from_secs_f64(timeout)); + .insert_expirable(rpc_id, req_tx, Duration::from_secs_f64(timeout)); let tx = self .tx .lock() diff --git a/mm2src/mm2_main/src/lp_ordermatch.rs b/mm2src/mm2_main/src/lp_ordermatch.rs index cb43caff06..2780ad234f 100644 --- a/mm2src/mm2_main/src/lp_ordermatch.rs +++ b/mm2src/mm2_main/src/lp_ordermatch.rs @@ -2398,10 +2398,10 @@ struct OrderbookPubkeyState { } impl OrderbookPubkeyState { - pub fn with_history_timeout() -> OrderbookPubkeyState { + pub fn new() -> OrderbookPubkeyState { OrderbookPubkeyState { last_keep_alive: now_sec(), - order_pairs_trie_state_history: TimedMap::new_with_map_kind(MapKind::FxHashMap).expiration_tick_cap(25), + order_pairs_trie_state_history: TimedMap::new_with_map_kind(MapKind::FxHashMap), orders_uuids: HashSet::default(), trie_roots: HashMap::default(), } @@ -2426,7 +2426,7 @@ fn pubkey_state_mut<'a>( match state.raw_entry_mut().from_key(from_pubkey) { RawEntryMut::Occupied(e) => e.into_mut(), RawEntryMut::Vacant(e) => { - let state = OrderbookPubkeyState::with_history_timeout(); + let state = OrderbookPubkeyState::new(); e.insert(from_pubkey.to_string(), state).1 }, } @@ -2484,7 +2484,7 @@ impl Default for Orderbook { unordered: HashMap::default(), order_set: HashMap::default(), pubkeys_state: HashMap::default(), - recently_cancelled: TimedMap::new_with_map_kind(MapKind::FxHashMap).expiration_tick_cap(25), + recently_cancelled: TimedMap::new_with_map_kind(MapKind::FxHashMap), topics_subscribed_to: HashMap::default(), memory_db: MemoryDB::default(), my_p2p_pubkeys: HashSet::default(), @@ -2552,16 +2552,17 @@ impl Orderbook { let history = match pubkey_state.order_pairs_trie_state_history.get_mut(&alb_ordered) { Some(t) => t, None => { - pubkey_state.order_pairs_trie_state_history.insert_expirable_unchecked( + pubkey_state.order_pairs_trie_state_history.insert_expirable( alb_ordered.clone(), TrieOrderHistory { - inner: TimedMap::new_with_map_kind(MapKind::FxHashMap).expiration_tick_cap(25), + inner: TimedMap::new_with_map_kind(MapKind::FxHashMap), }, - Duration::new(TRIE_STATE_HISTORY_TIMEOUT, 0), + Duration::from_secs(TRIE_STATE_HISTORY_TIMEOUT), ); + pubkey_state .order_pairs_trie_state_history - .get_unchecked_mut(&alb_ordered) + .get_mut_unchecked(&alb_ordered) .expect("must exist") }, }; @@ -2667,16 +2668,16 @@ impl Orderbook { let history = match pubkey_state.order_pairs_trie_state_history.get_mut(&alb_ordered) { Some(t) => t, None => { - pubkey_state.order_pairs_trie_state_history.insert_expirable_unchecked( + pubkey_state.order_pairs_trie_state_history.insert_expirable( alb_ordered.clone(), TrieOrderHistory { - inner: TimedMap::new_with_map_kind(MapKind::FxHashMap).expiration_tick_cap(25), + inner: TimedMap::new_with_map_kind(MapKind::FxHashMap), }, - Duration::new(TRIE_STATE_HISTORY_TIMEOUT, 0), + Duration::from_secs(TRIE_STATE_HISTORY_TIMEOUT), ); pubkey_state .order_pairs_trie_state_history - .get_unchecked_mut(&alb_ordered) + .get_mut_unchecked(&alb_ordered) .expect("must exist") }, }; diff --git a/mm2src/mm2_main/src/ordermatch_tests.rs b/mm2src/mm2_main/src/ordermatch_tests.rs index 56a9c6a135..457a3159cc 100644 --- a/mm2src/mm2_main/src/ordermatch_tests.rs +++ b/mm2src/mm2_main/src/ordermatch_tests.rs @@ -2861,6 +2861,7 @@ fn test_orderbook_order_pairs_trie_state_history_updates_expiration_on_insert() std::thread::sleep(Duration::from_secs(2)); // On inserting 5 more orders expiration for RICK:MORTY pair trie state history will be reset + // TODO: need expiration update logic for order in &rick_morty_orders[10..] { insert_or_update_order(&ctx_bob, order.clone()); } diff --git a/mm2src/mm2_p2p/src/behaviours/atomicdex.rs b/mm2src/mm2_p2p/src/behaviours/atomicdex.rs index 6d3ccb9d69..eb057b5fb9 100644 --- a/mm2src/mm2_p2p/src/behaviours/atomicdex.rs +++ b/mm2src/mm2_p2p/src/behaviours/atomicdex.rs @@ -195,7 +195,7 @@ fn check_and_mark_dialed( return false; } - recently_dialed_peers.insert_expirable_unchecked(addr.clone(), (), DIAL_RETRY_DELAY); + recently_dialed_peers.insert_expirable(addr.clone(), (), DIAL_RETRY_DELAY); true }