Skip to content
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

offchain - commit store updates fetching optimization #195

Closed
wants to merge 21 commits into from

Conversation

dimkouv
Copy link
Contributor

@dimkouv dimkouv commented Oct 10, 2023

So far the commit plugin keeps fetching multiple logs/events that were already fetched on the previous ocr2 round

func getTokenPriceUpdates() {
          updates = db.getTokenPriceUpdatesOfLast24Hours()
          ...
}

But this is not efficient for the performance of the db and the plugin.


A better approach would be to only get the new token price updates since the last time this call was made.

func getTokenPriceUpdates() {
          if there are no updates in mem {
                    updates = db.getTokenPriceUpdatesOfLast24Hours()
          } else {
                    newUpdates = db.getUpdatesThatHappenedAfterTheLastQuery()
                    updates.include(newUpdates)
         }
}

@dimkouv dimkouv requested a review from a team as a code owner October 10, 2023 10:26
@dimkouv dimkouv requested a review from reductionista October 11, 2023 09:31
@dimkouv dimkouv changed the title offchain - commit store token price updates fetching optimization offchain - commit store updates fetching optimization Oct 13, 2023
@dimkouv dimkouv requested a review from jarnaud October 13, 2023 11:46
func (c *priceUpdatesCache) updateTokenPriceIfMoreRecent(ts time.Time, tk common.Address, val *big.Int) bool {
c.mu.RLock()
v, exists := c.tokenPriceUpdates[tk]
c.mu.RUnlock()
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we keep the lock over the entire method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we keep the lock over the entire method we will have a deadlock.

If we use only a Lock() over the entire method, instead of both RLock() for read and Lock() for updates then it's slightly less efficient.

@dimkouv dimkouv requested a review from jarnaud October 16, 2023 10:30
@dimkouv
Copy link
Contributor Author

dimkouv commented Nov 29, 2023

Closing, seems that we are not going with this approach atm.
Will re-open if required.

@dimkouv dimkouv closed this Nov 29, 2023
@RensR RensR deleted the perf/ccip736-optimize-price-updates-fetch branch May 7, 2024 14:16
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.

3 participants