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

(OraklNode) Optimize aggregator #1988

Merged
merged 2 commits into from
Aug 2, 2024
Merged

Conversation

nick-bisonai
Copy link
Collaborator

Description

  • reduce aggregation steps
  • reduce mutex locks

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist before requesting a review

  • I have performed a self-review of my code.
  • If it is a core feature, I have added thorough tests.

Deployment

  • Should publish npm package
  • Should publish Docker image

@nick-bisonai nick-bisonai self-assigned this Aug 1, 2024
Copy link
Contributor

coderabbitai bot commented Aug 1, 2024

Warning

Rate limit exceeded

@nick-bisonai has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 50 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 c309fcb and 5532745.

Walkthrough

Walkthrough

The recent changes to the aggregator package enhance internal state management and message handling by introducing new data structures, RoundPrices and RoundProofs. These changes replace the previous maps, promoting better encapsulation and clarity. The message handling system has shifted towards an event-driven model, with refactored functions that streamline the process of managing round-specific data, improving both code maintainability and operational efficiency.

Changes

File Path Change Summary
node/pkg/aggregator/aggregator.go Restructured Aggregator class with new data structures for prices and proofs. Updated message handling to use Trigger messages, enhancing control flow. Functions for handling messages have been refactored or removed, promoting better clarity and efficiency.
node/pkg/aggregator/types.go Introduced RoundPrices and RoundProofs types for better management of round data. Added new methods for efficient data handling and structured message types for price data and proofs.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Aggregator
    participant PubSub

    Client->>Aggregator: PublishTriggerMessage()
    Aggregator->>PubSub: Trigger message sent
    PubSub->>Aggregator: Acknowledge trigger
    Aggregator->>Client: Trigger acknowledged
Loading

🐇 In the garden where the code does play,
New structures bloom in a bright array.
Prices and proofs, all neat and clear,
Message flows dance, bringing cheer!
With each hop, the logic flows,
A joyful leap, as progress grows! 🌼


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 Configuration 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.

@nick-bisonai nick-bisonai marked this pull request as ready for review August 2, 2024 01:19
@nick-bisonai nick-bisonai requested a review from a team as a code owner August 2, 2024 01:19
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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 738a413 and c309fcb.

Files selected for processing (2)
  • node/pkg/aggregator/aggregator.go (12 hunks)
  • node/pkg/aggregator/types.go (2 hunks)
Additional comments not posted (20)
node/pkg/aggregator/types.go (12)

58-61: Ensure thread safety and correct initialization

The RoundPrices struct encapsulates a map and a mutex for managing prices. Ensure that the map is correctly initialized and accessed in a thread-safe manner.


103-110: Ensure thread safety and correct usage of mutex

The push method locks the mutex, modifies the map, and then unlocks the mutex. This is correct for ensuring thread safety.


113-119: Ensure thread safety in len method

The len method correctly uses a read lock to ensure thread safety while reading from the map.


122-131: Ensure thread safety and correct snapshot creation

The snapshot method correctly uses a read lock and creates a snapshot of the prices for a given round.


134-138: Ensure thread safety in delete method

The delete method correctly uses a write lock to ensure thread safety while deleting an entry from the map.


63-66: Ensure thread safety and correct initialization

The RoundProofs struct encapsulates a map and a mutex for managing proofs. Ensure that the map is correctly initialized and accessed in a thread-safe manner.


140-147: Ensure thread safety and correct usage of mutex

The push method locks the mutex, modifies the map, and then unlocks the mutex. This is correct for ensuring thread safety.


150-156: Ensure thread safety in len method

The len method correctly uses a read lock to ensure thread safety while reading from the map.


159-167: Ensure thread safety and correct concatenation

The concat method correctly uses a read lock and concatenates the proofs for a given round.


169-172: Ensure thread safety in delete method

The delete method correctly uses a write lock to ensure thread safety while deleting an entry from the map.


84-88: Ensure completeness of PriceDataMessage

The PriceDataMessage struct is well-defined for structured communication regarding price data.


90-95: Ensure completeness of ProofMessage

The ProofMessage struct is well-defined for structured communication regarding proofs.

node/pkg/aggregator/aggregator.go (8)

34-39: Ensure correct initialization of new data structures

The NewAggregator function correctly initializes the new data structures RoundPrices and RoundProofs.


64-64: Ensure correct incrementation and message publishing

The LeaderJob function correctly increments the round ID and publishes a Trigger message.


80-99: Ensure correct handling of Trigger messages

The HandleTriggerMessage function correctly processes Trigger messages, including validation and logging.


113-113: Ensure correct publishing of price data messages

The function correctly publishes PriceDataMessage after processing the Trigger message.


Line range hint 129-153:
Ensure correct handling of PriceData messages

The HandlePriceDataMessage function correctly processes PriceData messages, including validation, logging, and median calculation.


171-179: Ensure correct handling of Proof messages

The HandleProofMessage function correctly processes Proof messages, including validation, logging, and proof concatenation.


Line range hint 191-240:
Ensure correct publishing of messages

The PublishTriggerMessage, PublishPriceDataMessage, and PublishProofMessage functions correctly publish their respective messages with appropriate error handling.


259-260: Ensure correct cleanup of round data

The cleanUpRoundData function correctly deletes round-specific data from the new data structures.

@nick-bisonai nick-bisonai force-pushed the feat/reduce-aggregation-steps branch from c309fcb to 5532745 Compare August 2, 2024 01:48
@nick-bisonai nick-bisonai merged commit f239082 into master Aug 2, 2024
2 checks passed
@nick-bisonai nick-bisonai deleted the feat/reduce-aggregation-steps branch August 2, 2024 01:51
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