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

[Separate Reporter Part 5] Implement deviation reporter #1900

Merged
merged 9 commits into from
Jul 25, 2024

Conversation

Intizar-T
Copy link
Contributor

@Intizar-T Intizar-T commented Jul 25, 2024

Description

Please include a summary of the changes and the related issue.
Please also include relevant motivation and context.
List any dependencies that are required for this change.

Related issue #1777

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

@Intizar-T Intizar-T self-assigned this Jul 25, 2024
@Intizar-T Intizar-T requested a review from a team as a code owner July 25, 2024 06:37
Copy link
Contributor

coderabbitai bot commented Jul 25, 2024

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Walkthrough

This update introduces significant improvements across several components in the node/pkg/reporter package. Key enhancements include streamlined resource handling in the App struct, an expanded Reporter functionality that adapts to different job types, and refined data structures for better performance and clarity. New data processing functions enhance error handling and type safety, promoting robust data integrity throughout the reporting process.

Changes

Files Change Summary
node/pkg/reporter/app.go Streamlined setReporters and enhanced handleWsMessage for improved resource management and data processing.
node/pkg/reporter/reporter.go Introduced JobType in NewReporter, modified reporting logic in Run, and added deviationJob method.
node/pkg/reporter/types.go Changed data types in SubmissionPair and RawSubmissionData, clarified LatestData structure, removed a function.
node/pkg/reporter/utils.go Restructured GetDeviatingAggregates, removed several functions, updated address types, and added ProcessDalWsRawData.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant Reporter
    participant DataProcessor
    participant WSHandler

    App->>Reporter: create NewReporter(JobType)
    Reporter->>App: store SubmissionPairs
    App->>WSHandler: handleWsMessage(data)
    WSHandler->>DataProcessor: ProcessDalWsRawData(data)
    DataProcessor-->>WSHandler: return SubmissionData
    WSHandler-->>App: send processed data
Loading

🐇 In the code, I hop and prance,
With changes bold, I take a chance.
New types and flows, oh what a treat,
Reporting now is swift and neat!
So gather 'round, let’s share the cheer,
For cleaner code is finally here! 🌟


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.

Copy link
Collaborator

@nick-bisonai nick-bisonai left a comment

Choose a reason for hiding this comment

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

lgtm! left few comments

node/pkg/reporter/app.go Show resolved Hide resolved
node/pkg/reporter/app.go Outdated Show resolved Hide resolved
node/pkg/reporter/reporter.go Outdated Show resolved Hide resolved
@nick-bisonai
Copy link
Collaborator

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Jul 25, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 60c625e and ffa0d0d.

Files selected for processing (4)
  • node/pkg/reporter/app.go (4 hunks)
  • node/pkg/reporter/reporter.go (5 hunks)
  • node/pkg/reporter/types.go (4 hunks)
  • node/pkg/reporter/utils.go (4 hunks)
Additional comments not posted (11)
node/pkg/reporter/types.go (3)

48-48: Approve the change to LastSubmission field type.

Changing the LastSubmission field type from int32 to int64 increases the range of values it can store, which is beneficial for handling larger values.


137-140: Verify the impact of changing Proof and FeedHash fields to string.

Changing the Proof and FeedHash fields from []byte and [32]byte to string may simplify serialization and deserialization processes. However, ensure that these changes do not introduce issues if the data is expected to be in byte format.


127-127: Approve the addition of the comment for LatestData field.

Adding the comment indicating the mapping structure of the LatestData field improves code readability and clarifies its intended use.

node/pkg/reporter/app.go (3)

47-52: Approve the streamlined handling of chainHelper.

The changes simplify resource management by eliminating the need for a temporary variable and its associated cleanup.


93-106: Approve the integration of deviationReporter logic.

The changes ensure proper instantiation and integration of the deviationReporter. Verify that the new logic does not introduce any issues.


171-176: Approve the enhanced data processing logic in handleWsMessage.

The changes improve data integrity and handling by validating or transforming the data before storing it. Verify the correctness of the ProcessDalWsRawData function.

node/pkg/reporter/reporter.go (4)

38-38: Approve the addition of JobType field to Reporter struct.

The addition of the JobType field allows for more dynamic behavior based on job types, enhancing the functionality of the Reporter class.


59-73: Approve the conditional logic based on JobType in Run method.

The changes enhance the control flow by allowing the reporter to execute different methods based on the JobType, improving the flexibility and maintainability of the code.


Line range hint 78-162: Approve the changes to the report method.

The changes allow for more flexible handling of submission data by processing any set of pairs passed to it, enhancing the functionality of the method.


164-177: Approve the addition of deviationJob method.

The new method isolates the logic for handling deviations from standard reporting, enhancing the clarity and maintainability of the code.

node/pkg/reporter/utils.go (1)

Line range hint 60-73:
LGTM!

The changes reflect a shift in dependency or data structure and the function handles contract reading and type assertions with error handling.

node/pkg/reporter/utils.go Outdated Show resolved Hide resolved
node/pkg/reporter/utils.go Outdated Show resolved Hide resolved
@Intizar-T Intizar-T merged commit 367b2b7 into feat/separate-reporter Jul 25, 2024
1 check passed
@Intizar-T Intizar-T deleted the feat/separate-reporter-part-5 branch July 25, 2024 08:59
@@ -78,78 +78,46 @@ func (a *App) setReporters(ctx context.Context) error {
WithInterval(groupInterval),
WithContractAddress(contractAddress),
WithCachedWhitelist(cachedWhitelist),
WithKaiaHelper(chainHelper),
WithLatestData(&a.LatestData),
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's define app.LatestData as *sync.Map type, and allocate memory from App.New() func. then, we can remove & here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done! will be reflected in the next PR

Intizar-T added a commit that referenced this pull request Jul 25, 2024
* update last submission for deviation job

* deviation reporter implemented

* refactor data processing logic

* remove retrier from deviation job

* update feedHash and proof conversion

* fix feedhash and proof conversion issue

* clean up

* reflect feedback

* comment out app test
Intizar-T added a commit that referenced this pull request Jul 26, 2024
* update last submission for deviation job

* deviation reporter implemented

* refactor data processing logic

* remove retrier from deviation job

* update feedHash and proof conversion

* fix feedhash and proof conversion issue

* clean up

* reflect feedback

* comment out app test
Intizar-T added a commit that referenced this pull request Jul 26, 2024
* update last submission for deviation job

* deviation reporter implemented

* refactor data processing logic

* remove retrier from deviation job

* update feedHash and proof conversion

* fix feedhash and proof conversion issue

* clean up

* reflect feedback

* comment out app test
Intizar-T added a commit that referenced this pull request Jul 26, 2024
* update last submission for deviation job

* deviation reporter implemented

* refactor data processing logic

* remove retrier from deviation job

* update feedHash and proof conversion

* fix feedhash and proof conversion issue

* clean up

* reflect feedback

* comment out app test
Intizar-T added a commit that referenced this pull request Jul 29, 2024
* [Separate Reporter Part 1] Copy proof functions from reporter to dal (#1839)

* copy proof related util functions from reporter to dal utils

* check error in gopax to pass lint

* rename import packages

* placeholder for error return in gopax, pass lint

* make proof functions lowercase in dal collector (#1841)

* [Separate Reporter Part 2] base report logic with rest api (#1873)

* comment out / remove unused code from reporter

* comment out tests and create reporter entrypoint

* temp comment out deviation reporter

* initial dal fetch and submit logic

* report logic implemented

* temp disable reporter tests

* remove reporter from node entrypoint

* replace zerolog with zeropglog in reporter entrypoing

* shared chain helper and mutex

* clean up unused reporter utils (#1881)

* [Separate Reporter Part 3] Websocket implementation (#1887)

* initial dal fetch and submit logic

* fix lint issues

* replace const ticker time with submission interval

* initial implementation of dal websocket

* uncomment report delegated to pass linting

* websocket implemented

* remove manual dial from reporter app

* reflect feedback

* make reporting concurrent

* remove unnecessary comments

* resolve reporter conflicts

* [Separate Reporter Part 5] Implement deviation reporter (#1900)

* update last submission for deviation job

* deviation reporter implemented

* refactor data processing logic

* remove retrier from deviation job

* update feedHash and proof conversion

* fix feedhash and proof conversion issue

* clean up

* reflect feedback

* comment out app test

* [Separate Reporter Part 6] implement tests (#1902)

* implement main and app test

* refactor latest data

* fetch configs from admin and save in local db

* reporter and util tests

* handle edge cases utils_test

* uncomment reporter test in taskfile

* remove reporter from admin

* give more timeout for fethcing configs

* remove hardcoded test name from taskfile

* replace config fetching with mock data

* reflect feedback

* fix faulty deviation reporter logic and udpate tests

* refactor regular and deviation reporter job functions

* rename latest data variable names

* rename reporter opt functions

* rename GetLatestData param name

* reporter health check endpoint and sentinel check (#1912)

* reporter health endpoint

* include reporter health check to sentinel

* move healthcheck creation from run to cmd

* remove sentinel updates

* fetch configs in reporter (#1915)

* replace db config query logic with fetch

* fix test issue

* remove db from tests

* remove db from config struct

* remove count from taskfile

* remove duplicate log

* fix go lint issue

* reflect feedback

* add error log in deviation reporter

* get dal api key from secrets
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