Skip to content

chore(deps): timed-map migration#2247

Merged
shamardy merged 9 commits intodevfrom
use-timed-map-crate
Jan 23, 2025
Merged

chore(deps): timed-map migration#2247
shamardy merged 9 commits intodevfrom
use-timed-map-crate

Conversation

@shamardy
Copy link
Copy Markdown
Collaborator

@shamardy shamardy commented Oct 21, 2024

Complete timed-map migration from TimeCache, DuplicateCache, ExpirableMap and ExpirableEntry.

@shamardy shamardy changed the title chore(deps): use timed-map crate instead of internal ExpirableMap type chore(deps): use timed-map crate instead of internal ExpirableMap Oct 21, 2024
Signed-off-by: onur-ozkan <work@onurozkan.dev>
@onur-ozkan onur-ozkan force-pushed the use-timed-map-crate branch from e2b814e to ff4038d Compare January 9, 2025 14:37
@onur-ozkan onur-ozkan marked this pull request as ready for review January 9, 2025 14:41
@onur-ozkan onur-ozkan changed the title chore(deps): use timed-map crate instead of internal ExpirableMap chore(deps): timed-map migration Jan 9, 2025
tx: Mutex::new(None),
establishing_connection: AsyncMutex::new(()),
responses: Mutex::new(JsonRpcPendingRequests::new()),
responses: Mutex::new(JsonRpcPendingRequests::new_with_map_kind(MapKind::BTreeMap)),
Copy link
Copy Markdown

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.

Copy link
Copy Markdown
Collaborator

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?

Copy link
Copy Markdown

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah where is that 😂

Copy link
Copy Markdown

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)

https://github.com/KomodoPlatform/komodo-defi-framework/blob/405bcb7daf316477497eb6925cba0ca9640ab383/mm2src/coins/utxo/rpc_clients/electrum_rpc/connection.rs#L340-L344

thought this was the loop iterating over the responses map..

Copy link
Copy Markdown

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.

Copy link
Copy Markdown
Collaborator

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 <work@onurozkan.dev>
Copy link
Copy Markdown
Collaborator

@mariocynicys mariocynicys left a 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.

@shamardy
Copy link
Copy Markdown
Collaborator Author

lp_ordermatch::ordermatch_tests::test_orderbook_order_pairs_trie_state_history_updates_expiration_on_insert and lp_ordermatch::ordermatch_tests::test_orderbook_sync_trie_diff_time_cache are both failing after the recent changes

Copy link
Copy Markdown
Collaborator

@mariocynicys mariocynicys left a 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

@onur-ozkan
Copy link
Copy Markdown

onur-ozkan commented Jan 13, 2025

lp_ordermatch::ordermatch_tests::test_orderbook_order_pairs_trie_state_history_updates_expiration_on_insert and lp_ordermatch::ordermatch_tests::test_orderbook_sync_trie_diff_time_cache are both failing after the recent changes

The order trie logic highly depends on timecache internals, which is covered in the test_orderbook_order_pairs_trie_state_history_updates_expiration_on_insert test.

We have 3 options:

  1. Change the order trie expiration logic (timecache has quite different expiration logic (e.g., bulk mode expirations) and removes expired entries on remove and entry functions, not on inserts. Also, reading functions do not consider expirations.)
  2. Change the expectations on test_orderbook_order_pairs_trie_state_history_updates_expiration_on_insert flow.
  3. Stay with timecache for order trie (this requires to keep time_cache module with ExpirableEntry in the expirable_map module)

I am ok with any of them.

Signed-off-by: onur-ozkan <work@onurozkan.dev>
@shamardy
Copy link
Copy Markdown
Collaborator Author

I think the problem with test_orderbook_order_pairs_trie_state_history_updates_expiration_on_insert is that we don't update expiration of existing entries like before https://github.com/KomodoPlatform/komodo-defi-framework/blob/6aa5d66a91833d36d68a18e30f049bdee95ea7f5/mm2src/common/time_cache.rs#L132-L134 https://github.com/KomodoPlatform/komodo-defi-framework/blob/6aa5d66a91833d36d68a18e30f049bdee95ea7f5/mm2src/common/time_cache.rs#L85
TimedMap doesn't have update_expiration function, maybe if we added it and used it like the below, the problem will be fixed

Index: mm2src/mm2_main/src/lp_ordermatch.rs
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/mm2src/mm2_main/src/lp_ordermatch.rs b/mm2src/mm2_main/src/lp_ordermatch.rs
--- a/mm2src/mm2_main/src/lp_ordermatch.rs	(revision 5563e9d6c99366dd19d256d52ef6ba49c7481225)
+++ b/mm2src/mm2_main/src/lp_ordermatch.rs	(date 1737460248340)
@@ -2550,7 +2550,10 @@
 
         if prev_root != H64::default() {
             let history = match pubkey_state.order_pairs_trie_state_history.get_mut(&alb_ordered) {
-                Some(t) => t,
+                Some(t) => {
+                    pubkey_state.order_pairs_trie_state_history.update_expiration(alb_ordered, Duration::from_secs(TRIE_STATE_HISTORY_TIMEOUT));
+                    t
+                },
                 None => {
                     pubkey_state.order_pairs_trie_state_history.insert_expirable(
                         alb_ordered.clone(),

P.S. I am going with option 1 if we can

@onur-ozkan
Copy link
Copy Markdown

TimedMap doesn't have update_expiration function, maybe if we added it and used it like the below, the problem will be fixed

I tried that too but it didn't work either; like I said, time-cache internal logic is tightly coupled with the test expectations.

@onur-ozkan
Copy link
Copy Markdown

trie test expectation logic is 1:1 ported now

Signed-off-by: onur-ozkan <work@onurozkan.dev>
@shamardy
Copy link
Copy Markdown
Collaborator Author

@onur-ozkan please resolve conflicts so that I can approve the PR. It LGTM now.

… into use-timed-map-crate

Signed-off-by: onur-ozkan <work@onurozkan.dev>
Copy link
Copy Markdown
Collaborator

@mariocynicys mariocynicys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@shamardy shamardy merged commit a873525 into dev Jan 23, 2025
@shamardy shamardy deleted the use-timed-map-crate branch January 23, 2025 12:02
shamardy added a commit that referenced this pull request Jan 28, 2025
shamardy added a commit that referenced this pull request Jan 30, 2025
shamardy added a commit that referenced this pull request Jan 30, 2025
dimxy pushed a commit to dimxy/komodo-defi-framework that referenced this pull request Feb 4, 2025
* dev:
  fix(hash-types): remove panic, enforce fixed-size arrays (GLEECBTC#2279)
  fix(ARRR): store unconfirmed change output (GLEECBTC#2276)
  feat(tendermint): staking/delegation (GLEECBTC#2322)
  chore(deps): `timed-map` migration (GLEECBTC#2247)
  fix(mem-leak): `running_swap` never shrinks (GLEECBTC#2301)
  chore(dep-bump): libp2p (GLEECBTC#2326)
  refactor(build script): rewrite the main build script (GLEECBTC#2319)
dimxy pushed a commit to dimxy/komodo-defi-framework that referenced this pull request Feb 4, 2025
* dev:
  fix(hash-types): remove panic, enforce fixed-size arrays (GLEECBTC#2279)
  fix(ARRR): store unconfirmed change output (GLEECBTC#2276)
  feat(tendermint): staking/delegation (GLEECBTC#2322)
  chore(deps): `timed-map` migration (GLEECBTC#2247)
  fix(mem-leak): `running_swap` never shrinks (GLEECBTC#2301)
  chore(dep-bump): libp2p (GLEECBTC#2326)
  refactor(build script): rewrite the main build script (GLEECBTC#2319)
dimxy pushed a commit that referenced this pull request Feb 16, 2025
* dev:
  fix(derive_key_from_path): check length of current_key_material (#2356)
  chore(release): bump mm2 version to 2.4.0-beta (#2346)
  fix(tests): add additional testnet sepolia nodes to test code (#2358)
  fix(swaps): maintain legacy compatibility for negotiation messages (#2353)
  refactor(SwapOps): impl defaults for protocol specific swapops fns (#2354)
  feat(tpu-v2): provide swap protocol versioning (#2324)
  feat(wallet): add change mnemonic password rpc (#2317)
  fix(tpu-v2): fix tpu-v2 wait for payment spend and extract secret (#2261)
  feat(tendermint): unstaking/undelegation (#2330)
  fix(utxo-withdraw): get hw ctx only when `PrivKeyPolicy` is trezor (#2333)
  feat(event-streaming): API-driven subscription management (#2172)
  fix(hash-types): remove panic, enforce fixed-size arrays (#2279)
  fix(ARRR): store unconfirmed change output (#2276)
  feat(tendermint): staking/delegation (#2322)
  chore(deps): `timed-map` migration (#2247)
  fix(mem-leak): `running_swap` never shrinks (#2301)
  chore(dep-bump): libp2p (#2326)
  refactor(build script): rewrite the main build script (#2319)
dimxy pushed a commit that referenced this pull request Feb 16, 2025
* dev:
  fix(derive_key_from_path): check length of current_key_material (#2356)
  chore(release): bump mm2 version to 2.4.0-beta (#2346)
  fix(tests): add additional testnet sepolia nodes to test code (#2358)
  fix(swaps): maintain legacy compatibility for negotiation messages (#2353)
  refactor(SwapOps): impl defaults for protocol specific swapops fns (#2354)
  feat(tpu-v2): provide swap protocol versioning (#2324)
  feat(wallet): add change mnemonic password rpc (#2317)
  fix(tpu-v2): fix tpu-v2 wait for payment spend and extract secret (#2261)
  feat(tendermint): unstaking/undelegation (#2330)
  fix(utxo-withdraw): get hw ctx only when `PrivKeyPolicy` is trezor (#2333)
  feat(event-streaming): API-driven subscription management (#2172)
  fix(hash-types): remove panic, enforce fixed-size arrays (#2279)
  fix(ARRR): store unconfirmed change output (#2276)
  feat(tendermint): staking/delegation (#2322)
  chore(deps): `timed-map` migration (#2247)
  fix(mem-leak): `running_swap` never shrinks (#2301)
  chore(dep-bump): libp2p (#2326)
  refactor(build script): rewrite the main build script (#2319)
dimxy pushed a commit to dimxy/komodo-defi-framework that referenced this pull request Feb 24, 2025
* dev: (24 commits)
  fix(eth-tpu): remove state from funding validation (GLEECBTC#2334)
  improvement(rpc-server): rpc server dynamic port allocation (GLEECBTC#2342)
  fix(tests): fix or ignore unstable tests (GLEECBTC#2365)
  fix(fs): make `filter_files_by_extension` return only files (GLEECBTC#2364)
  fix(derive_key_from_path): check length of current_key_material (GLEECBTC#2356)
  chore(release): bump mm2 version to 2.4.0-beta (GLEECBTC#2346)
  fix(tests): add additional testnet sepolia nodes to test code (GLEECBTC#2358)
  fix(swaps): maintain legacy compatibility for negotiation messages (GLEECBTC#2353)
  refactor(SwapOps): impl defaults for protocol specific swapops fns (GLEECBTC#2354)
  feat(tpu-v2): provide swap protocol versioning (GLEECBTC#2324)
  feat(wallet): add change mnemonic password rpc (GLEECBTC#2317)
  fix(tpu-v2): fix tpu-v2 wait for payment spend and extract secret (GLEECBTC#2261)
  feat(tendermint): unstaking/undelegation (GLEECBTC#2330)
  fix(utxo-withdraw): get hw ctx only when `PrivKeyPolicy` is trezor (GLEECBTC#2333)
  feat(event-streaming): API-driven subscription management (GLEECBTC#2172)
  fix(hash-types): remove panic, enforce fixed-size arrays (GLEECBTC#2279)
  fix(ARRR): store unconfirmed change output (GLEECBTC#2276)
  feat(tendermint): staking/delegation (GLEECBTC#2322)
  chore(deps): `timed-map` migration (GLEECBTC#2247)
  fix(mem-leak): `running_swap` never shrinks (GLEECBTC#2301)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants