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

(DAL) Data Availability Layer Beta #1720

Merged
merged 25 commits into from
Jul 8, 2024
Merged

(DAL) Data Availability Layer Beta #1720

merged 25 commits into from
Jul 8, 2024

Conversation

nick-bisonai
Copy link
Collaborator

Description

Data Availability Layer Beta

default port 8090

Rest API

  • get /api/v1/dal/latest-data-feeds/all: get data for onchain submission for all possible pairs
  • get /api/v1/dal/latest-data-feeds/btc-usdt: get data for onchain submission for certain pair

Websockert API

/api/v1/dal/ws

  • subscribe
{"method":"SUBSCRIBE", "params":["submission@ETH-USDT", "submission@BTC-USDT", "submission@ADA-USDT"]}

Response Example

{
    "symbol": "ETH-USDT",
    "value": "343723184555",
    "aggregateTime": "1719907644",
    "proof": "KPYuhGTwoeaUm3ZHGj/q3gXRl//+y17jHxzf4IrAr4pV9RZXHVOVP9W96ICCQcj5LZAUDxyqYeH7Twn7ZYmDnxs=",
    "feedHash": "cCC1KEG7Joy8eBN6VNS/H1MF7tEDn7XQA7qVuO3txGw=",
    "decimals": "8"
}

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 Jul 2, 2024
Copy link
Contributor

coderabbitai bot commented Jul 2, 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 3 minutes and 24 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 66186cb and 90bf7e8.

Walkthrough

Walkthrough

This update introduces improved testing functionality and a new GitHub Actions workflow for the Data Access Layer (DAL) component. Enhancements include testing for the collector, API controller, and various database operations, setup and cleanup routines, and the addition of new constants and functions to the collector. The new CI workflow tests DAL functionality with PostgreSQL and Redis, ensuring code quality and automated tests.

Changes

File Summary
node/pkg/dal/tests/main_test.go Introduces test functions for publishing data, sample data generation, setup/cleanup, and test execution.
node/pkg/dal/collector/collector.go Adds Collector type to manage data streams, process submission data, and monitor oracle additions.
node/pkg/dal/tests/api_test.go Adds tests for API controller: run, fetch latest data, and WebSocket interactions.
node/pkg/dal/tests/collector_test.go Adds tests for starting, stopping, and streaming functionality of the collector component.
.github/workflows/dal.test.yaml Introduces a GitHub Actions workflow for testing the DAL component with PostgreSQL and Redis services.

Poem

In the land of code where data flows,
Tests ensure that everything glows.
Collectors, oracles, setup with care,
GitHub Actions running everywhere.
From API to WebSocket, all in place,
The data layer runs the race.
🎉 Your system's now a better space! 🚀


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.

@nick-bisonai
Copy link
Collaborator Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Jul 2, 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: 6

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 67fb2bd and 12f9a63.

Files ignored due to path filters (4)
  • go.work.sum is excluded by !**/*.sum, !**/*.sum
  • node/go.mod is excluded by !**/*.mod
  • node/go.sum is excluded by !**/*.sum, !**/*.sum
  • node/taskfiles/taskfile.local.yml is excluded by !**/*.yml
Files selected for processing (14)
  • node/cmd/dal/main.go (1 hunks)
  • node/pkg/chain/websocketchainreader/type.go (1 hunks)
  • node/pkg/chain/websocketchainreader/websocketreader.go (1 hunks)
  • node/pkg/dalapi/api/controller.go (1 hunks)
  • node/pkg/dalapi/api/route.go (1 hunks)
  • node/pkg/dalapi/app.go (1 hunks)
  • node/pkg/dalapi/collector/collector.go (1 hunks)
  • node/pkg/dalapi/collector/utils.go (1 hunks)
  • node/pkg/dalapi/common/types.go (1 hunks)
  • node/pkg/dalapi/utils/utils.go (1 hunks)
  • node/pkg/error/sentinel.go (1 hunks)
  • node/pkg/websocketfetcher/app.go (1 hunks)
  • node/script/test_websocketDexFetcher/main.go (1 hunks)
  • node/script/test_websocketchainreader/main.go (1 hunks)
Files not reviewed due to errors (1)
  • node/pkg/error/sentinel.go (no review received)
Files skipped from review due to trivial changes (2)
  • node/cmd/dal/main.go
  • node/pkg/dalapi/common/types.go
Additional comments not posted (41)
node/pkg/dalapi/api/route.go (2)

13-13: Verify WebSocket route setup.

Ensure that the WebSocket route is correctly configured and tested.

Do you have tests verifying the WebSocket connection and data flow?


8-14: LGTM!

The route definitions are clear and well-structured.

node/pkg/dalapi/app.go (2)

18-19: Good error handling practice.

Logging the error before returning is a good practice for debugging.


22-26: Ensure background tasks are properly managed.

Verify that the background tasks managed by ApiController.Run are properly started and stopped, especially during shutdown.

Do you have a mechanism to gracefully stop background tasks during server shutdown?

node/pkg/chain/websocketchainreader/type.go (6)

18-22: LGTM!

The struct ChainReaderConfig is well-defined and the field names are clear.


Line range hint 43-49: LGTM!

The struct ChainReader is well-defined and the field names are clear.


26-30: LGTM!

The function WithKaiaWebsocketUrl is well-defined and the function name is clear.


32-36: LGTM!

The function WithEthWebsocketUrl is well-defined and the function name is clear.


38-42: LGTM!

The function WithRetryInterval is well-defined and the function name is clear.


41-42: LGTM!

The function WithStartBlockNumber is well-defined and the function name is clear.

node/script/test_websocketchainreader/main.go (2)

30-33: LGTM!

The code for creating the websocketchainreader with the provided WebSocket URLs is clear and well-structured.


Line range hint 37-38: Good practice: Closing the channel.

Closing the channel after use is a good practice to avoid memory leaks.

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

78-97: LGTM!

The code changes are approved.

node/pkg/dalapi/collector/utils.go (3)

17-29: Enhance error handling with descriptive messages.

The error message "failed to cast result to []interface{}" can be more descriptive to include the context of the operation.

- return nil, errors.New("failed to cast result to []interface{}")
+ return nil, fmt.Errorf("failed to cast result to []interface{} for contract address %s", submissionProxyContractAddr)

31-67: Enhance error handling with descriptive messages.

The error messages can be more descriptive to include the context of the operation.

- return eventParseErr
+ return fmt.Errorf("failed to parse method signature for OracleAdded event: %w", eventParseErr)
- return err
+ return fmt.Errorf("failed to generate event ABI for OracleAdded event: %w", err)

70-89: LGTM!

The code changes are approved.

node/script/test_websocketDexFetcher/main.go (1)

107-110: Improve error handling granularity.

The error handling can be more granular to provide specific error messages for each operation.

chainReader, err := websocketchainreader.New(
  websocketchainreader.WithEthWebsocketUrl(ethWebsocketUrl),
  websocketchainreader.WithKaiaWebsocketUrl(kaiaWebsocketUrl),
)
if err != nil {
  log.Error().Err(err).Msg("failed to create websocketchainreader with provided URLs")
  return
}
node/pkg/dalapi/collector/collector.go (9)

84-96: LGTM!

The Start function is well-implemented and handles initialization and context setup correctly.


98-101: LGTM!

The Stop function correctly handles stopping the collector.


104-107: LGTM!

The receive function correctly starts goroutines for each config ID.


110-122: LGTM!

The receiveEach function correctly subscribes to the submission stream and processes incoming data.


125-133: LGTM!

The processIncomingData function correctly processes incoming data and handles errors.


135-167: LGTM!

The IncomingDataToOutgoingData function correctly converts data and handles proof ordering, including refreshing the whitelist if necessary.


170-191: LGTM!

The trackOracleAdded function correctly subscribes to the oracle added event and updates the whitelist.


59-62: Ensure getAllOracles is implemented correctly.

The function getAllOracles is not provided in the current context. Ensure it is implemented correctly and used appropriately.


139-145: Ensure orderProof is implemented correctly.

The function orderProof is not provided in the current context. Ensure it is implemented correctly and used appropriately.

node/pkg/websocketfetcher/app.go (6)

Line range hint 55-57: LGTM!

The New function correctly initializes a new App instance.


Line range hint 59-78: LGTM!

The Init function correctly sets up necessary configurations and initializes CEX and DEX fetchers.


Line range hint 80-110: LGTM!

The initializeCex function correctly initializes CEX fetchers and handles errors appropriately.


Line range hint 201-223: LGTM!

The Start function correctly starts the app and its fetchers, handling the context and ticker appropriately.


Line range hint 225-247: LGTM!

The storeFeedData function correctly stores feed data from the buffer and handles errors appropriately.


197-199: LGTM!

The getEnvOrDefault function correctly retrieves environment variables with a default value fallback.

node/pkg/dalapi/api/controller.go (9)

35-44: LGTM!

The NewController function correctly initializes a new Controller instance.


47-87: LGTM!

The getLatestSubmissionData function correctly retrieves the latest submission data and handles errors appropriately.


89-108: LGTM!

The getLatestSubmissionDataSingle function correctly retrieves the latest submission data for a single symbol and handles errors appropriately.


111-137: LGTM!

The handleWebsocket function correctly handles websocket connections and subscriptions, including error handling.


140-146: LGTM!

The configIdToSymbol function correctly converts a config ID to a symbol.


149-158: LGTM!

The broadcastDataForSymbol function correctly broadcasts data for a specific symbol to subscribed clients and handles errors appropriately.


161-187: LGTM!

The Run function correctly starts the controller and its collector, handling the context and channels appropriately.


190-209: LGTM!

The init function correctly initializes the API controller and handles errors appropriately.


211-227: LGTM!

The getLatestFeeds function correctly retrieves the latest feeds and converts them to outgoing data, handling errors appropriately.

node/pkg/dalapi/app.go Outdated Show resolved Hide resolved
node/pkg/dalapi/collector/collector.go Outdated Show resolved Hide resolved
node/pkg/websocketfetcher/app.go Outdated Show resolved Hide resolved
node/pkg/dalapi/utils/utils.go Outdated Show resolved Hide resolved
node/pkg/dalapi/utils/utils.go Outdated Show resolved Hide resolved
node/pkg/chain/websocketchainreader/websocketreader.go Outdated Show resolved Hide resolved
@nick-bisonai nick-bisonai marked this pull request as ready for review July 3, 2024 01:15
@nick-bisonai nick-bisonai requested a review from a team as a code owner July 3, 2024 01:15
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: 24

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 12f9a63 and e76023e.

Files ignored due to path filters (4)
  • go.work.sum is excluded by !**/*.sum, !**/*.sum
  • node/go.mod is excluded by !**/*.mod
  • node/go.sum is excluded by !**/*.sum, !**/*.sum
  • node/taskfiles/taskfile.local.yml is excluded by !**/*.yml
Files selected for processing (14)
  • node/.env.example (1 hunks)
  • node/cmd/dal/main.go (1 hunks)
  • node/pkg/chain/websocketchainreader/websocketreader.go (1 hunks)
  • node/pkg/dal/api/controller.go (1 hunks)
  • node/pkg/dal/api/route.go (1 hunks)
  • node/pkg/dal/api/types.go (1 hunks)
  • node/pkg/dal/app.go (1 hunks)
  • node/pkg/dal/collector/collector.go (1 hunks)
  • node/pkg/dal/collector/utils.go (1 hunks)
  • node/pkg/dal/common/types.go (1 hunks)
  • node/pkg/dal/tests/api_test.go (1 hunks)
  • node/pkg/dal/tests/collector_test.go (1 hunks)
  • node/pkg/dal/tests/main_test.go (1 hunks)
  • node/pkg/dal/utils/utils.go (1 hunks)
Files skipped from review due to trivial changes (2)
  • node/.env.example
  • node/cmd/dal/main.go
Additional comments not posted (20)
node/pkg/dal/common/types.go (1)

3-10: LGTM! Verify the consistency of data types.

The struct definition looks good.

However, ensure that the data types (string for Value and AggregateTime, []byte for Proof and FeedHash) are consistent with the rest of the codebase and the expected data format.

node/pkg/dal/api/route.go (1)

8-13: LGTM! Verify the correctness of WebSocket integration.

The route definitions look good.

However, ensure that the WebSocket integration (websocket.New(ApiController.handleWebsocket)) is correctly implemented and handles edge cases such as connection errors and client disconnections.

node/pkg/dal/api/types.go (2)

10-13: LGTM!

The struct definition looks good.


15-23: LGTM! Verify the consistency of data types.

The struct definition looks good.

However, ensure that the data types (map[*websocket.Conn]map[string]bool for clients, chan *websocket.Conn for register and unregister, and map[string]chan dalcommon.OutgoingSubmissionData for broadcast) are consistent with the rest of the codebase and the expected data format.

node/pkg/dal/app.go (1)

14-38: LGTM! Verify the correctness of error handling and environment variable usage.

The function implementation looks good.

However, ensure that the error handling is comprehensive and that the environment variable DAL_API_PORT is correctly set and used.

node/pkg/dal/tests/collector_test.go (2)

13-33: LGTM! Verify the comprehensiveness of assertions and cleanup.

The test implementation looks good.

However, ensure that the assertions are comprehensive and that the cleanup is properly handled.


35-79: LGTM! Verify the comprehensiveness of assertions and cleanup.

The test implementation looks good.

However, ensure that the assertions are comprehensive and that the cleanup is properly handled.

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

1-1: Ensure package name consistency.

Ensure the package name utils is consistent with other utility files to maintain a standard naming convention.

node/pkg/dal/collector/utils.go (1)

1-1: Ensure package name consistency.

Ensure the package name collector is consistent with other collector files to maintain a standard naming convention.

node/pkg/dal/tests/main_test.go (1)

1-1: Ensure package name consistency.

Ensure the package name test is consistent with other test files to maintain a standard naming convention.

node/pkg/dal/tests/api_test.go (1)

1-1: Ensure package name consistency.

Ensure the package name test is consistent with other test files to maintain a standard naming convention.

node/pkg/dal/collector/collector.go (4)

99-104: LGTM!

The Stop method correctly handles stopping the collector.


112-124: LGTM!

The receiveEach method correctly handles data reception and processing.


127-135: LGTM!

The processIncomingData method correctly handles data processing and sending to the outgoing stream.


172-194: LGTM!

The trackOracleAdded method correctly handles event subscription and whitelist updating.

node/pkg/dal/api/controller.go (5)

40-50: LGTM!

The NewController function correctly initializes a new Controller instance.


77-84: LGTM!

The configIdToSymbol method correctly maps a configuration ID to its corresponding symbol.


100-127: LGTM!

The handleWebsocket method correctly handles WebSocket connections and subscription management.


129-169: LGTM!

The getLatestSubmissionData method correctly retrieves the latest submission data for all configurations.


171-191: LGTM!

The getLatestSubmissionDataSingle method correctly retrieves the latest submission data for a specific symbol.

node/pkg/dal/collector/collector.go Outdated Show resolved Hide resolved
node/pkg/dal/collector/collector.go Outdated Show resolved Hide resolved
node/pkg/dal/collector/collector.go Outdated Show resolved Hide resolved
node/pkg/dal/api/controller.go Outdated Show resolved Hide resolved
node/pkg/dal/api/controller.go Show resolved Hide resolved
node/pkg/chain/websocketchainreader/websocketreader.go Outdated Show resolved Hide resolved
node/pkg/dal/tests/api_test.go Outdated Show resolved Hide resolved
node/pkg/dal/tests/api_test.go Show resolved Hide resolved
node/pkg/dal/tests/api_test.go Outdated Show resolved Hide resolved
node/pkg/dal/tests/api_test.go Outdated Show resolved Hide resolved
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 e76023e and 133bcef.

Files selected for processing (7)
  • node/.env.example (1 hunks)
  • node/pkg/dal/api/controller.go (1 hunks)
  • node/pkg/dal/app.go (1 hunks)
  • node/pkg/dal/collector/collector.go (1 hunks)
  • node/pkg/dal/collector/utils.go (1 hunks)
  • node/pkg/dal/tests/main_test.go (1 hunks)
  • node/pkg/dal/utils/utils.go (1 hunks)
Files skipped from review as they are similar to previous changes (6)
  • node/.env.example
  • node/pkg/dal/api/controller.go
  • node/pkg/dal/app.go
  • node/pkg/dal/collector/utils.go
  • node/pkg/dal/tests/main_test.go
  • node/pkg/dal/utils/utils.go
Additional comments not posted (8)
node/pkg/dal/collector/collector.go (8)

22-25: LGTM! Constants are appropriately defined.

The constants DefaultDecimals, GetAllOracles, and OracleAdded are straightforward and correctly defined.


28-42: LGTM! Struct fields are well-defined.

The Collector struct fields are appropriately defined to manage data streams, symbols, feed hashes, cached whitelist, context, cancellation function, and synchronization.


99-104: LGTM! Function is correctly implemented.

The Stop function is straightforward and correctly implemented to cancel the context and set it to nil.


106-114: Add error handling or logging for goroutines.

Consider adding error handling or logging for the goroutines to ensure any issues are captured.

-  go c.receiveEach(ctx, id)
+  go func(id int32) {
+      if err := c.receiveEach(ctx, id); err != nil {
+          log.Error().Err(err).Str("Player", "DalCollector").Msg("Error in receiveEach goroutine")
+      }
+  }(id)

Likely invalid or redundant comment.


141-174: Add more context to error logs.

Consider adding more context to error logs for better debugging.

-  log.Error().Err(err).Str("Player", "DalCollector").Msg("failed to order proof")
+  log.Error().Err(err).Str("Player", "DalCollector").Str("Symbol", c.Symbols[data.GlobalAggregate.ConfigID]).Msg("failed to order proof")

-  log.Error().Err(getAllOraclesErr).Str("Player", "DalCollector").Msg("failed to refresh oracles")
+  log.Error().Err(getAllOraclesErr).Str("Player", "DalCollector").Str("Symbol", c.Symbols[data.GlobalAggregate.ConfigID]).Msg("failed to refresh oracles")

Likely invalid or redundant comment.


176-198: LGTM! Verify error handling in subscribeAddOracleEvent.

The trackOracleAdded function is correctly implemented to subscribe to the oracle added event and update the cached whitelist. Ensure that the subscribeAddOracleEvent method handles errors appropriately.

Verification successful

Verified: Error handling in subscribeAddOracleEvent is appropriate.

The subscribeAddOracleEvent function correctly handles errors by returning them if the subscription fails. No further action is needed.

  • node/pkg/dal/collector/utils.go: Proper error handling in subscribeAddOracleEvent.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify error handling in `subscribeAddOracleEvent`.

# Test: Search for the `subscribeAddOracleEvent` function. Expect: Proper error handling.
rg --type go --pattern 'func subscribeAddOracleEvent' --context 10

Length of output: 480



Script:

#!/bin/bash
# Description: Verify error handling in `subscribeAddOracleEvent`.

# Test: Search for the `subscribeAddOracleEvent` function. Expect: Proper error handling.
rg 'func subscribeAddOracleEvent' --type go -C 10

Length of output: 1360


116-128: LGTM! Verify error handling in db.Subscribe.

The receiveEach function is correctly implemented to subscribe to a data stream and process incoming data. Ensure that the db.Subscribe method handles errors appropriately.

Verification successful

LGTM! Verify error handling in db.Subscribe.

The receiveEach function is correctly implemented to subscribe to a data stream and process incoming data. The db.Subscribe method handles errors appropriately, including empty channels, unmarshalling errors, and retryable errors through executeWithRetry.

  • node/pkg/db/redis.go: Comprehensive error handling in db.Subscribe.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify error handling in `db.Subscribe`.

# Test: Search for the `Subscribe` method in the `db` package. Expect: Proper error handling.
rg --type go --pattern 'func Subscribe' --context 10

Length of output: 466



Script:

#!/bin/bash
# Description: Verify error handling in `db.Subscribe`.

# Corrected Test: Search for the `Subscribe` method in the `db` package. Expect: Proper error handling.
rg 'func Subscribe' --type go --context 10

Length of output: 1047



Script:

#!/bin/bash
# Description: Verify comprehensive error handling in `db.Subscribe`.

# Test: Display the full implementation of the `Subscribe` method to review all error handling cases.
rg 'func Subscribe' --type go --context 30

Length of output: 2731


131-139: LGTM! Verify error handling in IncomingDataToOutgoingData.

The processIncomingData function is correctly implemented to convert incoming data to outgoing data and send it to the outgoing stream. Ensure that the IncomingDataToOutgoingData method handles errors appropriately.

node/pkg/dal/collector/collector.go Outdated Show resolved Hide resolved
node/pkg/dal/collector/collector.go Show resolved Hide resolved
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: 7

Outside diff range and nitpick comments (9)
node/script/test_dal_consumer/main.go (6)

29-33: Improve error logging for chain helper initialization.

The error log message can be more descriptive to aid in debugging.

-	log.Error().Err(err).Msg("NewTxHelper")
+	log.Error().Err(err).Str("Player", "TestConsumer").Msg("failed to create chain helper")

35-39: Improve error logging for data feed request.

The error log message can be more descriptive to aid in debugging.

-	log.Error().Err(err).Str("Player", "TestConsumer").Msg("failed to get data feed")
+	log.Error().Err(err).Str("Player", "TestConsumer").Str("URL", url).Msg("failed to get data feed")

42-46: Improve error logging for string to big.Int conversion.

The error log message can be more descriptive to aid in debugging.

-	log.Error().Str("Player", "TestConsumer").Msg("failed to convert string to big int")
+	log.Error().Str("Player", "TestConsumer").Str("Value", result.Value).Msg("failed to convert string to big int")

49-53: Improve error logging for string to big.Int conversion.

The error log message can be more descriptive to aid in debugging.

-	log.Error().Str("Player", "TestConsumer").Msg("failed to convert string to big int")
+	log.Error().Str("Player", "TestConsumer").Str("AggregateTime", result.AggregateTime).Msg("failed to convert string to big int")

60-64: Improve error logging for transaction creation.

The error log message can be more descriptive to aid in debugging.

-	log.Error().Err(err).Msg("MakeDirect")
+	log.Error().Err(err).Str("Player", "TestConsumer").Msg("failed to create transaction")

73-77: Improve error logging for transaction submission.

The error log message can be more descriptive to aid in debugging.

-	log.Error().Err(err).Msg("SubmitRawTx")
+	log.Error().Err(err).Str("Player", "TestConsumer").Msg("failed to submit transaction")
.github/workflows/dal.test.yaml (1)

61-67: Improve error logging for vet step.

Consider adding more context to the error logs for the vet step.

-	go vet ./...
+	go vet ./... || { echo 'Go vet failed'; exit 1; }
-	go vet -vettool=$(which shadow) ./...
+	go vet -vettool=$(which shadow) ./... || { echo 'Go vet with shadow failed'; exit 1; }
node/pkg/dal/collector/collector.go (2)

57-58: Improve error logging for chain reader initialization.

The error log message can be more descriptive to aid in debugging.

-	return nil, err
+	return nil, fmt.Errorf("failed to create chain reader: %w", err)

62-63: Improve error logging for initial whitelist retrieval.

The error log message can be more descriptive to aid in debugging.

-	return nil, err
+	return nil, fmt.Errorf("failed to retrieve initial whitelist: %w", err)
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 133bcef and 371bb06.

Files ignored due to path filters (1)
  • node/taskfiles/taskfile.local.yml is excluded by !**/*.yml
Files selected for processing (7)
  • .github/workflows/dal.test.yaml (1 hunks)
  • node/pkg/dal/collector/collector.go (1 hunks)
  • node/pkg/dal/common/types.go (1 hunks)
  • node/pkg/dal/tests/api_test.go (1 hunks)
  • node/pkg/dal/tests/collector_test.go (1 hunks)
  • node/pkg/dal/tests/main_test.go (1 hunks)
  • node/script/test_dal_consumer/main.go (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • node/pkg/dal/common/types.go
  • node/pkg/dal/tests/api_test.go
  • node/pkg/dal/tests/collector_test.go
  • node/pkg/dal/tests/main_test.go
Additional comments not posted (3)
node/pkg/dal/collector/collector.go (3)

99-103: LGTM!

The Stop function is well-structured and stops the collector gracefully.


131-139: LGTM!

The processIncomingData function is well-structured and processes incoming data efficiently.


108-112: Add error handling or logging for goroutines.

Consider adding error handling or logging for the goroutines to ensure any issues are captured.

-	go func(id int32) {
-		if err := c.receiveEach(ctx, id); err != nil {
-			log.Error().Err(err).Str("Player", "DalCollector").Msg("Error in receiveEach goroutine")
-		}
-	}(id)
+	go func(id int32) {
+		if err := c.receiveEach(ctx, id); err != nil {
+			log.Error().Err(err).Str("Player", "DalCollector").Msg("Error in receiveEach goroutine")
+		}
+	}(id)

Likely invalid or redundant comment.

node/script/test_dal_consumer/main.go Show resolved Hide resolved
.github/workflows/dal.test.yaml Show resolved Hide resolved
.github/workflows/dal.test.yaml Show resolved Hide resolved
node/pkg/dal/collector/collector.go Show resolved Hide resolved
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 371bb06 and 83bd550.

Files selected for processing (2)
  • .github/workflows/dal.test.yaml (1 hunks)
  • .github/workflows/node.test.yaml (1 hunks)
Files skipped from review due to trivial changes (1)
  • .github/workflows/node.test.yaml
Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/dal.test.yaml

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: 5

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 83bd550 and 04e723c.

Files ignored due to path filters (4)
  • go.work.sum is excluded by !**/*.sum, !**/*.sum
  • node/go.mod is excluded by !**/*.mod
  • node/go.sum is excluded by !**/*.sum, !**/*.sum
  • node/taskfiles/taskfile.local.yml is excluded by !**/*.yml
Files selected for processing (15)
  • .github/workflows/dal.test.yaml (1 hunks)
  • node/.env.example (1 hunks)
  • node/cmd/dal/main.go (1 hunks)
  • node/pkg/dal/api/controller.go (1 hunks)
  • node/pkg/dal/api/route.go (1 hunks)
  • node/pkg/dal/api/types.go (1 hunks)
  • node/pkg/dal/app.go (1 hunks)
  • node/pkg/dal/collector/collector.go (1 hunks)
  • node/pkg/dal/collector/utils.go (1 hunks)
  • node/pkg/dal/common/types.go (1 hunks)
  • node/pkg/dal/tests/api_test.go (1 hunks)
  • node/pkg/dal/tests/collector_test.go (1 hunks)
  • node/pkg/dal/tests/main_test.go (1 hunks)
  • node/pkg/dal/utils/utils.go (1 hunks)
  • node/script/test_dal_consumer/main.go (1 hunks)
Files skipped from review as they are similar to previous changes (14)
  • .github/workflows/dal.test.yaml
  • node/.env.example
  • node/cmd/dal/main.go
  • node/pkg/dal/api/controller.go
  • node/pkg/dal/api/route.go
  • node/pkg/dal/api/types.go
  • node/pkg/dal/app.go
  • node/pkg/dal/collector/utils.go
  • node/pkg/dal/common/types.go
  • node/pkg/dal/tests/api_test.go
  • node/pkg/dal/tests/collector_test.go
  • node/pkg/dal/tests/main_test.go
  • node/pkg/dal/utils/utils.go
  • node/script/test_dal_consumer/main.go
Additional comments not posted (1)
node/pkg/dal/collector/collector.go (1)

106-112: Add error handling or logging for goroutines.

Consider adding error handling or logging for the goroutines to ensure any issues are captured.

-  go c.receiveEach(ctx, id)
+  go func(id int32) {
+      if err := c.receiveEach(ctx, id); err != nil {
+          log.Error().Err(err).Str("Player", "DalCollector").Msg("Error in receiveEach goroutine")
+      }
+  }(id)

Likely invalid or redundant comment.

node/pkg/dal/collector/collector.go Outdated Show resolved Hide resolved
node/pkg/dal/collector/collector.go Show resolved Hide resolved
node/pkg/dal/collector/collector.go Show resolved Hide resolved
node/pkg/dal/collector/collector.go Show resolved Hide resolved
node/pkg/dal/collector/collector.go Outdated Show resolved Hide resolved
@nick-bisonai nick-bisonai changed the title (OraklNode) Data Availability Layer Beta (DAL) Data Availability Layer Beta Jul 3, 2024
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 04e723c and 5eb6485.

Files ignored due to path filters (3)
  • go.work.sum is excluded by !**/*.sum, !**/*.sum
  • node/go.mod is excluded by !**/*.mod
  • node/go.sum is excluded by !**/*.sum, !**/*.sum
Files selected for processing (2)
  • .github/workflows/deployment.yaml (1 hunks)
  • dockerfiles/orakl-dal.Dockerfile (1 hunks)
Files skipped from review due to trivial changes (2)
  • .github/workflows/deployment.yaml
  • dockerfiles/orakl-dal.Dockerfile

FeedHashes map[int32][]byte
CachedWhitelist []klaytncommon.Address

Ctx context.Context
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a specific reason we are storing the context in a struct? Apparently it's not a good practice to store context in a struct, rather it should be passed to functions that require it, unless there it's necessary: https://go.dev/blog/context-and-structs

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I kept ctx to track its running state,

ctx here is the one which is generated from param passed through Start func below.

Copy link
Contributor

@Intizar-T Intizar-T 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 some suggestions

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 5eb6485 and 3bb8ce0.

Files selected for processing (7)
  • .github/workflows/dal.test.yaml (1 hunks)
  • node/.env.example (1 hunks)
  • node/pkg/admin/tests/test_helper.go (2 hunks)
  • node/pkg/dal/collector/collector.go (1 hunks)
  • node/pkg/dal/tests/api_test.go (1 hunks)
  • node/pkg/dal/utils/utils.go (1 hunks)
  • node/pkg/wss/utils.go (4 hunks)
Files skipped from review as they are similar to previous changes (4)
  • .github/workflows/dal.test.yaml
  • node/pkg/dal/collector/collector.go
  • node/pkg/dal/tests/api_test.go
  • node/pkg/dal/utils/utils.go
Additional comments not posted (10)
node/.env.example (7)

55-58: LGTM!

The addition of the DAL_API_PORT variable is clear and well-commented.


60-61: LGTM!

The addition of the KAIA_WEBSOCKET_URL variable is clear and well-commented.


63-64: LGTM!

The addition of the SUBMISSION_PROXY_CONTRACT variable is clear and well-commented.


66-67: LGTM!

The addition of the API_KEY variable is clear and well-commented.


69-70: LGTM!

The addition of the DATABASE_URL variable is clear and well-commented.


71-71: LGTM!

The addition of the REDIS_HOST variable is clear and well-commented.


72-72: LGTM!

The addition of the REDIS_PORT variable is clear and well-commented.

node/pkg/admin/tests/test_helper.go (1)

59-65: LGTM!

The code correctly sets the Content-Type and X-API-Key headers for HTTP requests.

node/pkg/wss/utils.go (2)

25-35: LGTM!

The code correctly adds support for request headers in the ConnectionConfig struct and provides a function to set these headers.

Also applies to: 79-83


101-105: LGTM!

The code correctly sets the request headers in the WebSocket connection options.

Also applies to: 137-143

wip

feat: encapsulate

wip

wip

feat: rest api
fix: linter err and vet err fix

feat: rename and separate types

fix: change function order, remove err return

fix: update based on feedbacks

docs: update .env.example
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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3bb8ce0 and 25443d3.

Files ignored due to path filters (3)
  • node/go.mod is excluded by !**/*.mod
  • node/go.sum is excluded by !**/*.sum, !**/*.sum
  • node/taskfiles/taskfile.local.yml is excluded by !**/*.yml
Files selected for processing (19)
  • .github/workflows/dal.test.yaml (1 hunks)
  • .github/workflows/deployment.yaml (1 hunks)
  • dockerfiles/orakl-dal.Dockerfile (1 hunks)
  • node/.env.example (1 hunks)
  • node/cmd/dal/main.go (1 hunks)
  • node/pkg/admin/tests/test_helper.go (2 hunks)
  • node/pkg/dal/api/controller.go (1 hunks)
  • node/pkg/dal/api/route.go (1 hunks)
  • node/pkg/dal/api/types.go (1 hunks)
  • node/pkg/dal/app.go (1 hunks)
  • node/pkg/dal/collector/collector.go (1 hunks)
  • node/pkg/dal/collector/utils.go (1 hunks)
  • node/pkg/dal/common/types.go (1 hunks)
  • node/pkg/dal/tests/api_test.go (1 hunks)
  • node/pkg/dal/tests/collector_test.go (1 hunks)
  • node/pkg/dal/tests/main_test.go (1 hunks)
  • node/pkg/dal/utils/utils.go (1 hunks)
  • node/pkg/wss/utils.go (4 hunks)
  • node/script/test_dal_consumer/main.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • node/pkg/wss/utils.go
Files skipped from review as they are similar to previous changes (17)
  • .github/workflows/dal.test.yaml
  • .github/workflows/deployment.yaml
  • dockerfiles/orakl-dal.Dockerfile
  • node/.env.example
  • node/pkg/admin/tests/test_helper.go
  • node/pkg/dal/api/controller.go
  • node/pkg/dal/api/route.go
  • node/pkg/dal/api/types.go
  • node/pkg/dal/app.go
  • node/pkg/dal/collector/collector.go
  • node/pkg/dal/collector/utils.go
  • node/pkg/dal/common/types.go
  • node/pkg/dal/tests/api_test.go
  • node/pkg/dal/tests/collector_test.go
  • node/pkg/dal/tests/main_test.go
  • node/pkg/dal/utils/utils.go
  • node/script/test_dal_consumer/main.go

node/cmd/dal/main.go Outdated Show resolved Hide resolved
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

Outside diff range and nitpick comments (2)
node/cmd/dal/main.go (1)

24-27: Enhance error logging.

The error handling could be improved by providing more context in the log message.

- log.Fatal().Err(err).Msg("Failed to start DAL")
+ log.Fatal().Err(err).Msg("Failed to start DAL in main function")
node/pkg/dal/tests/main_test.go (1)

1-2: Remove unnecessary nolint directive.

The //nolint:all directive suppresses all linting errors, which is generally not recommended.

- //nolint:all
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 25443d3 and 965c1ac.

Files selected for processing (2)
  • node/cmd/dal/main.go (1 hunks)
  • node/pkg/dal/tests/main_test.go (1 hunks)
Additional comments not posted (10)
node/cmd/dal/main.go (3)

1-11: Ensure proper package and import usage.

The package and imports are necessary and correctly included.


13-15: Ensure proper context cancellation.

The context is created and properly canceled using defer cancel().


17-22: Handle OS interrupts and cancel context.

The code correctly handles OS interrupts to cancel the context.

node/pkg/dal/tests/main_test.go (7)

3-22: Ensure proper package and import usage.

The package and imports are necessary and correctly included.


24-29: Ensure proper struct definition.

The TestItems struct is defined correctly to hold test-related items.


31-33: Improve error handling in testPublishData.

The function should handle errors properly to avoid silent failures.

if err := db.Publish(ctx, keys.SubmissionDataStreamKey(submissionData.GlobalAggregate.ConfigID), submissionData); err != nil {
	log.Error().Err(err).Msg("failed to publish data in testPublishData")
}

35-64: Improve error handling and logging in generateSampleSubmissionData.

The function should handle errors properly and log them for better debugging.

if err != nil {
	log.Error().Err(err).Msg("failed to create sign helper in generateSampleSubmissionData")
	return nil, err
}
if err != nil {
	log.Error().Err(err).Msg("failed to make global aggregate proof in generateSampleSubmissionData")
	return nil, err
}
return &aggregator.SubmissionData{
	GlobalAggregate: sampleGlobalAggregate,
	Proof:           proof,
}, nil

66-101: Improve setup function with detailed error logging.

The setup function initializes test items and should log errors with more context for better debugging.

if err != nil {
	log.Error().Err(err).Msg("error inserting config in setup")
	return nil, nil, err
}
if err != nil {
	log.Error().Err(err).Msg("error setting up Fiber app in setup")
	return nil, nil, err
}

103-122: Ensure proper resource cleanup in test functions.

The cleanup function should handle errors properly and ensure all resources are cleaned up to avoid resource leaks.

if err != nil {
	log.Error().Err(err).Msg("error deleting config in cleanup")
	return err
}
if err != nil {
	log.Error().Err(err).Msg("error shutting down app in cleanup")
	return err
}

124-134: Ensure proper setup and teardown in TestMain.

The TestMain function should ensure proper setup and teardown of resources to avoid resource leaks.

// setup
code := m.Run()

// teardown
db.ClosePool()
db.CloseRedis()
os.Exit(code)

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 965c1ac and af33591.

Files selected for processing (3)
  • node/pkg/dal/collector/collector.go (1 hunks)
  • node/pkg/dal/tests/api_test.go (1 hunks)
  • node/pkg/dal/tests/collector_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • node/pkg/dal/collector/collector.go
  • node/pkg/dal/tests/api_test.go
  • node/pkg/dal/tests/collector_test.go

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 af33591 and 66186cb.

Files selected for processing (1)
  • .github/workflows/dal.test.yaml (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/dal.test.yaml

@nick-bisonai nick-bisonai merged commit 8cd84d8 into master Jul 8, 2024
1 of 2 checks passed
@nick-bisonai nick-bisonai deleted the feat/api branch July 8, 2024 04:14
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