Skip to content

refactor: replace ipfs TimeSizedCache with Moka#4542

Open
metalurgical wants to merge 8 commits into
cowprotocol:mainfrom
metalurgical:ipfs_moka
Open

refactor: replace ipfs TimeSizedCache with Moka#4542
metalurgical wants to merge 8 commits into
cowprotocol:mainfrom
metalurgical:ipfs_moka

Conversation

@metalurgical

@metalurgical metalurgical commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Description

Replace the existing mutex IPFS cache with Moka.

Changes

  • Replace Mutex<TimedSizedCache<AppDataHash, Option<String>>> with moka::future::Cache<AppDataHash, Option<String>>
  • Remove manual cache locking
  • Preserve existing cache size, expiration and behaviour.

How to test

cargo nextest run

@metalurgical metalurgical requested a review from a team as a code owner June 21, 2026 01:33

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request replaces the cached crate with moka for caching IPFS app data in the orderbook, which simplifies the code by removing explicit Mutex locking. It also updates a test assertion in the balance overrides crate. The review feedback suggests using moka::future::Cache instead of moka::sync::Cache to perform non-blocking operations in an asynchronous context.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread crates/orderbook/src/ipfs_app_data.rs Outdated
Comment thread crates/orderbook/src/ipfs_app_data.rs Outdated
};
let result = self
.cache
.try_get_with(*contract_app_data, async {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Isn't this performing an extra, unnecessary, get call? Since we already did this and returned earlier in L99

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It could be done in one try_get_with call, though at the expense of altering the metrics. Pushed a small update to make this easier to see. Thoughts?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Since try_get_with combines get and insert, will not be able to tell source anymore.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's still performing the get in L91, why not just keep the logic like it was and use insert instead of the try_get_with? I feel like I'm missing something

@metalurgical metalurgical Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, have updated it to keep original logic. Was just used since multiple callers of the same key would be evaluated once, with the others waiting for the result, if not already found in the first get to the cache.

Comment thread crates/balance-overrides/src/balance/mod.rs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants