Skip to content

Commit

Permalink
save dev state
Browse files Browse the repository at this point in the history
Signed-off-by: onur-ozkan <[email protected]>
  • Loading branch information
onur-ozkan committed Jan 13, 2025
1 parent b698473 commit 5094612
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions mm2src/coins/eth/web3_transport/websocket_transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -248,7 +248,8 @@ impl WebsocketTransport {
let _guard = self.connection_guard.lock().await;

// List of awaiting requests
let mut response_notifiers: TimedMap<StdClock, RequestId, oneshot::Sender<Vec<u8>>> = TimedMap::default();
let mut response_notifiers: TimedMap<StdClock, RequestId, oneshot::Sender<Vec<u8>>> =
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)
Expand Down
4 changes: 2 additions & 2 deletions mm2src/coins/utxo/rpc_clients/electrum_rpc/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down
25 changes: 13 additions & 12 deletions mm2src/mm2_main/src/lp_ordermatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
Expand All @@ -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
},
}
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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")
},
};
Expand Down Expand Up @@ -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")
},
};
Expand Down
1 change: 1 addition & 0 deletions mm2src/mm2_main/src/ordermatch_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
2 changes: 1 addition & 1 deletion mm2src/mm2_p2p/src/behaviours/atomicdex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 5094612

Please sign in to comment.