-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(deps): timed-map
migration
#2247
base: dev
Are you sure you want to change the base?
Conversation
timed-map
crate instead of internal ExpirableMap
typetimed-map
crate instead of internal ExpirableMap
Signed-off-by: onur-ozkan <[email protected]>
e2b814e
to
ff4038d
Compare
timed-map
crate instead of internal ExpirableMap
timed-map
migration
@@ -177,7 +177,7 @@ impl ElectrumConnection { | |||
settings, | |||
tx: Mutex::new(None), | |||
establishing_connection: AsyncMutex::new(()), | |||
responses: Mutex::new(JsonRpcPendingRequests::new()), | |||
responses: Mutex::new(JsonRpcPendingRequests::new_with_map_kind(MapKind::BTreeMap)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Picked BTreeMap
intentionally to process entries in order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wdym by processing entries in order? what processing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wdym by processing entries in order? what processing?
Making sure to process responses in the FIFO way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah where is that 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fell into this terrible naming (there is no separation at all at the first glance)
komodo-defi-framework/mm2src/coins/utxo/rpc_clients/electrum_rpc/connection.rs
Lines 340 to 344 in 405bcb7
for response in responses { | |
// `split` returns empty slice if it ends with separator which is our case. | |
if !response.is_empty() { | |
self.process_electrum_response(response, event_handlers) | |
} |
thought this was the loop iterating over the responses map..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly I still believe we should prefer BTreeMap
here to avoid difficult-to-debug magical future bugs. If we add any logic with the expectation of running FIFO processing, it will accidentally run in a random order and that will be super annoying to catch on runtime. The fact that I already falled in this trap makes it very likely to happen again to me or anyone in the team.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aha cool, im fine with BTree or others, i only nitted to make sure im not missing something with the in-order comment.
Signed-off-by: onur-ozkan <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
One comment inline. LGTM otherwise.
|
@@ -251,7 +251,7 @@ impl ElectrumConnection { | |||
self.responses | |||
.lock() | |||
.unwrap() | |||
.insert(rpc_id, req_tx, Duration::from_secs_f64(timeout)); | |||
.insert_expirable_unchecked(rpc_id, req_tx, Duration::from_secs_f64(timeout)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the only insert being unchecked basically makes this map susceptible to memory leaks. this acts pretty much similar (with an *) to a normal hashmap at this point.
you can instead make it a checked insert but use a high tick cap.
there are other never-checked maps also introduced in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the only insert being unchecked basically makes this map susceptible to memory leaks. this acts pretty much similar (with an *) to a normal hashmap at this point.
you can instead make it a checked insert but use a high tick cap.
We don't need to include expiration overhead on inserts on electrum requests. The check is performed at end of process_electrum_response
which should be enough.
there are other never-checked maps also introduced in this PR.
Can you mark them? I tried to minimize the expiration overhead in various places where it's unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to include expiration overhead on inserts on electrum requests. The check is performed at end of process_electrum_response which should be enough.
i can't find no check for outdated entries in process_electrum_response
!
you aren't talking about the .remove
right? .remove
will not help with requests that we got no responses for, these request handles will reside in the timed map forever (until the connection terminates*).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
labeled the never checked maps below
) -> OuterAction { | ||
match request { | ||
Some(ControllerMessage::Request(WsRequest { | ||
request_id, | ||
serialized_request, | ||
response_notifier, | ||
})) => { | ||
response_notifiers.insert( | ||
response_notifiers.insert_expirable_unchecked( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this
@@ -251,7 +251,7 @@ impl ElectrumConnection { | |||
self.responses | |||
.lock() | |||
.unwrap() | |||
.insert(rpc_id, req_tx, Duration::from_secs_f64(timeout)); | |||
.insert_expirable_unchecked(rpc_id, req_tx, Duration::from_secs_f64(timeout)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this
mm2src/mm2_main/src/lp_ordermatch.rs
Outdated
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( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and this
The order trie logic highly depends on timecache internals, which is covered in the We have 3 options:
I am ok with any of them. |
Signed-off-by: onur-ozkan <[email protected]>
5094612
to
5563e9d
Compare
Complete timed-map migration from
TimeCache
,DuplicateCache
,ExpirableMap
andExpirableEntry
.