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

feat: queue block process updates waiting on pre-computation to be finished before starting next #370

Merged
merged 2 commits into from
Jun 29, 2024

Conversation

p0mvn
Copy link
Member

@p0mvn p0mvn commented Jun 29, 2024

Summary by CodeRabbit

  • New Features

    • Introduced mechanisms to ensure the first block is fully processed before subsequent blocks, preventing system overload.
    • Added asynchronous and synchronous methods for updating token prices.
  • Refactor

    • Renamed UpdatePrices to UpdatePricesSync for clarity.
    • Enhanced worker processes to differentiate updates by height and manage block processing more effectively.

@p0mvn p0mvn marked this pull request as ready for review June 29, 2024 21:08
Copy link
Contributor

coderabbitai bot commented Jun 29, 2024

Warning

Rate limit exceeded

@p0mvn has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 3 minutes and 23 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between f6b7475 and 014d929.

Walkthrough

In version v25.2.0, the primary enhancement is a synchronization mechanism ensuring the first block completes processing before subsequent ones start, preventing overload. This affects block processing, pricing updates, and worker behavior to handle jobs effectively, using wait groups and atomic flags. The PricingWorker interface now includes asynchronous and synchronous methods for price updates. Various structural changes ensure synchronized processing and proper handling of block data.

Changes

Files Change Summary
CHANGELOG.md Added a summary for version v25.2.0 detailing the synchronization mechanism introduced in block processing.
docs/architecture/ingest.md Updated mvc.IngestUsecase to include a wait group for synchronized block processing and worker updates by height.
domain/pricing.go Updated PricingWorker interface with UpdatePricesAsync and UpdatePricesSync methods for handling price updates.
ingest/usecase/ingest_usecase.go Added synchronization using sync and sync/atomic to ensure orderly processing of blocks and updated the ingestUseCase struct.
tokens/usecase/pricing/worker/pricing_worker.go Renamed UpdatePrices to UpdatePricesSync and updated UpdatePricesAsync to call UpdatePricesSync in pricingWorker struct.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant IngestUseCase
    participant PricingWorker

    Client->>IngestUseCase: Start Processing Blocks
    IngestUseCase->>IngestUseCase: Check hasProcessedFirstBlock
    alt is false
        IngestUseCase->>IngestUseCase: Process first block
        IngestUseCase->>IngestUseCase: Set hasProcessedFirstBlock true
        IngestUseCase->>PricingWorker: Invoke UpdatePricesSync
    else is true
        IngestUseCase->>IngestUseCase: Wait for firstBlockWg
        IngestUseCase->>PricingWorker: Invoke UpdatePricesAsync
    end
    PricingWorker->>Client: Block Processing Complete
Loading

Poem

In code's domain where logic hops,
A rabbit tweaks, and never stops.
Blocks in sync, they now align,
Price updates flow through async lines.
Systems hum, no overload,
As code-gen tales of progress told.


Tip

Early access features: enabled

We are currently testing the following features in early access:

  • OpenAI gpt-4o model for code reviews and chat: OpenAI claims that this model is better at understanding and generating code than the previous models. We seek your feedback over the next few weeks before making it generally available.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues.
  • OSS projects are always opted into early access features.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Outside diff range and nitpick comments (13)
CHANGELOG.md (4)

Line range hint 87-87: Fix grammatical issue: "fallback" should be "fall back".

The word “fallback” is a noun. The verb is spelled with a white space.

- Hack to fallback to precision of 18 when estimating spot price for Astroport pools via quotes.
+ Hack to fall back to precision of 18 when estimating spot price for Astroport pools via quotes.

Line range hint 139-139: Fix grammatical issue: "ingest" should be "ingests" or "ingested".

There seems to be a noun/verb agreement error.

- Pricing ingest worker
+ Pricing ingests worker

Line range hint 203-203: Fix typographical issue: "clean ups" should be "clean-ups".

This expression is normally spelled as one or with a hyphen.

- light clean ups from the data ingest refactor.
+ light clean-ups from the data ingest refactor.

Line range hint 266-266: Fix typographical issue: "Human readable" should be "Human-readable".

This word is normally spelled with a hyphen.

- Human readable denom params in router
+ Human-readable denom params in router
docs/architecture/ingest.md (9)

Line range hint 96-96: Fix grammatical issue: "in" should be "at".

The preposition “at” seems more likely in this position than the preposition “in”.

- in a previous height.
+ at a previous height.

Line range hint 122-122: Fix grammatical issue: Misplaced comma.

The comma may be misplaced. Try moving it before ‘and’, or removing it altogether.

- TotalLiquidity and, finally add the new contributions to the total.
+ TotalLiquidity, and finally add the new contributions to the total.

Line range hint 122-122: Fix grammatical issue: Missing comma.

Possible missing comma found.

- TotalLiquidity and, finally add the new contributions to the total.
+ TotalLiquidity, and finally, add the new contributions to the total.

Line range hint 130-130: Fix style issue: Use "can" instead of "able to".

As a shorter alternative for ‘able to’, consider using “can”.

- we are able to recompute the liquidity capitalization
+ we can recompute the liquidity capitalization

Line range hint 84-84: Fix Markdownlint issue: Use dashes for unordered lists.

Expected: dash; Actual: asterisk

- * Value of all pool liquidity of a token across all pools
- * Value of all pool balances in USDC
- * This happens at cold start or if any error is returned in a previois block.
- * This assumes that all other pools have already been ingested in a previous height.
+ - Value of all pool liquidity of a token across all pools
+ - Value of all pool balances in USDC
+ - This happens at cold start or if any error is returned in a previois block.
+ - This assumes that all other pools have already been ingested in a previous height.

Also applies to: 86-86, 94-94, 96-96


Line range hint 84-84: Fix Markdownlint issue: Unordered list indentation.

Expected: 0; Actual: 2

-   * Value of all pool liquidity of a token across all pools
-   * Value of all pool balances in USDC
+ - Value of all pool liquidity of a token across all pools
+ - Value of all pool balances in USDC

Also applies to: 86-86


Line range hint 159-159: Fix Markdownlint issue: Trailing spaces.

Expected: 0 or 2; Actual: 1

- 
+ 

Line range hint 41-47: Fix Markdownlint issue: Hard tabs.

Column: 1

-	if x < y:
-		return x
-  while x >= y:
-    x -= y
-  return x
+  if x < y:
+    return x
+  while x >= y:
+    x -= y
+  return x

Also applies to: 108-112, 159-164


Line range hint 12-12: Fix Markdownlint issue: Lists should be surrounded by blank lines.

- 1. Token liquidity capitalization across all pools
-   * Value of all pool liquidity of a token across all pools
- 2. Pool liqudity capitalization
-   * Value of all pool balances in USDC
+ 
+ 1. Token liquidity capitalization across all pools
+   - Value of all pool liquidity of a token across all pools
+ 2. Pool liqudity capitalization
+   - Value of all pool balances in USDC
+ 

Also applies to: 83-83, 84-84, 85-85, 86-86, 89-89, 93-93, 146-146, 164-164

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d28397a and f6b7475.

Files selected for processing (5)
  • CHANGELOG.md (1 hunks)
  • docs/architecture/ingest.md (1 hunks)
  • domain/pricing.go (1 hunks)
  • ingest/usecase/ingest_usecase.go (4 hunks)
  • tokens/usecase/pricing/worker/pricing_worker.go (1 hunks)
Additional context used
LanguageTool
CHANGELOG.md

[grammar] ~87-~87: The word “fallback” is a noun. The verb is spelled with a white space.
Context: ...ther & clean up tokens/prices - Hack to fallback to precision of 18 when estimating spot...

(NOUN_VERB_CONFUSION)


[grammar] ~139-~139: There seems to be a noun/verb agreement error. Did you mean “ingests” or “ingested”?
Context: ...utes parameter ## v0.17.0 - Pricing ingest worker - Remove support for unlisted ...

(SINGULAR_NOUN_VERB_AGREEMENT)


[misspelling] ~203-~203: This expression is normally spelled as one or with a hyphen.
Context: ...ub.com//pull/143) light clean ups from the data ingest refactor. - [#14...

(EN_COMPOUNDS_CLEAN_UPS)


[misspelling] ~266-~266: This word is normally spelled with a hyphen.
Context: ...85) /tokens/prices endpoint ## v0.5.0 Human readable denom params in router - [#84](https...

(EN_COMPOUNDS_HUMAN_READABLE)

docs/architecture/ingest.md

[uncategorized] ~96-~96: The preposition “at” seems more likely in this position than the preposition “in”.
Context: ... other pools have already been ingested in a previous height. In the current sys...

(AI_EN_LECTOR_REPLACEMENT_PREPOSITION_IN_AT)


[typographical] ~122-~122: The comma may be misplaced. Try moving it before ‘and’, or removing it altogether.
Context: ...ibution of that pool to TotalLiquidity and, finally add the new contributions to th...

(COMMA_AFTER_AND)


[uncategorized] ~122-~122: Possible missing comma found.
Context: ...n of that pool to TotalLiquidity and, finally add the new contributions to the total ...

(AI_HYDRA_LEO_MISSING_COMMA)


[style] ~130-~130: As a shorter alternative for ‘able to’, consider using “can”.
Context: ...nd prices of each token in the pool, we are able to recompute the liquidity capitalization ...

(BE_ABLE_TO)

Markdownlint
CHANGELOG.md

57-57: Expected: 0 or 2; Actual: 1
Trailing spaces

(MD009, no-trailing-spaces)


191-191: null
Bare URL used

(MD034, no-bare-urls)

docs/architecture/ingest.md

84-84: Expected: dash; Actual: asterisk
Unordered list style

(MD004, ul-style)


86-86: Expected: dash; Actual: asterisk
Unordered list style

(MD004, ul-style)


94-94: Expected: dash; Actual: asterisk
Unordered list style

(MD004, ul-style)


96-96: Expected: dash; Actual: asterisk
Unordered list style

(MD004, ul-style)


84-84: Expected: 0; Actual: 2
Unordered list indentation

(MD007, ul-indent)


86-86: Expected: 0; Actual: 2
Unordered list indentation

(MD007, ul-indent)


159-159: Expected: 0 or 2; Actual: 1
Trailing spaces

(MD009, no-trailing-spaces)


41-41: Column: 1
Hard tabs

(MD010, no-hard-tabs)


42-42: Column: 1
Hard tabs

(MD010, no-hard-tabs)


43-43: Column: 1
Hard tabs

(MD010, no-hard-tabs)


44-44: Column: 1
Hard tabs

(MD010, no-hard-tabs)


45-45: Column: 1
Hard tabs

(MD010, no-hard-tabs)


46-46: Column: 1
Hard tabs

(MD010, no-hard-tabs)


47-47: Column: 1
Hard tabs

(MD010, no-hard-tabs)


108-108: Column: 1
Hard tabs

(MD010, no-hard-tabs)


109-109: Column: 1
Hard tabs

(MD010, no-hard-tabs)


110-110: Column: 1
Hard tabs

(MD010, no-hard-tabs)


111-111: Column: 1
Hard tabs

(MD010, no-hard-tabs)


112-112: Column: 1
Hard tabs

(MD010, no-hard-tabs)


98-98: Expected: 1; Actual: 2
Multiple consecutive blank lines

(MD012, no-multiple-blanks)


150-150: Expected: 1; Actual: 2
Multiple consecutive blank lines

(MD012, no-multiple-blanks)


12-12: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)


83-83: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)


83-83: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)


84-84: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)


84-84: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)


85-85: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)


85-85: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)


86-86: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)


89-89: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)


93-93: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)


146-146: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)


164-164: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)

Additional comments not posted (6)
tokens/usecase/pricing/worker/pricing_worker.go (3)

41-41: LGTM!

The asynchronous call to UpdatePricesSync using a goroutine is correctly implemented.


Line range hint 44-72: LGTM!

The synchronous price update process is correctly implemented with proper context handling, logging, and error handling.


Line range hint 75-77: LGTM!

The listener registration process is correctly implemented.

domain/pricing.go (1)

123-132: LGTM!

The addition of UpdatePricesAsync and UpdatePricesSync methods to the PricingWorker interface is correctly implemented.

ingest/usecase/ingest_usecase.go (2)

41-44: LGTM!

The addition of the hasProcessedFirstBlock atomic flag and firstBlockWg wait group to manage the sequencing of block processing is correctly implemented.


107-126: LGTM!

The update to the ProcessBlockData method to use the new hasProcessedFirstBlock flag and firstBlockWg wait group is correctly implemented.

docs/architecture/ingest.md Outdated Show resolved Hide resolved
ingest/usecase/ingest_usecase.go Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@p0mvn p0mvn merged commit e60eadb into v25.x Jun 29, 2024
5 of 7 checks passed
@p0mvn p0mvn deleted the roman/block-process-wait branch June 29, 2024 21:33
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.

1 participant