-
Notifications
You must be signed in to change notification settings - Fork 15
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) refactor websocketchainreader init code #1717
Conversation
WalkthroughWalkthroughThe recent changes introduce a Changes
Poem
Tip Early access features: enabledWe are currently testing the following features in early access:
Note:
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this 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
Files selected for processing (6)
- node/pkg/chain/websocketchainreader/type.go (1 hunks)
- node/pkg/chain/websocketchainreader/websocketreader.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 summarized due to errors (3)
- node/pkg/chain/websocketchainreader/type.go: Error: Server error. Please try again later.
- node/script/test_websocketchainreader/main.go: Error: Server error. Please try again later.
- node/script/test_websocketDexFetcher/main.go: Error: Server error. Please try again later.
Additional comments not posted (7)
node/pkg/chain/websocketchainreader/type.go (2)
18-22
: NewChainReaderConfig
struct definition is well-designed.The
ChainReaderConfig
struct is clear and concise, providing a straightforward way to configure theChainReader
. It includes URLs for both Ethereum and Kaia chains, as well as a retry interval which is a good practice for network-related operations.
24-42
: Functional options pattern implemented effectively.The functional options pattern is a good choice for configuration flexibility. Each option function (
WithKaiaWebsocketUrl
,WithEthWebsocketUrl
,WithRetryInterval
) is well-implemented, correctly modifying theChainReaderConfig
struct.node/script/test_websocketchainreader/main.go (1)
30-33
: Correct implementation ofChainReader
initialization using functional options.The initialization of
ChainReader
usingWithEthWebsocketUrl
andWithKaiaWebsocketUrl
demonstrates the flexibility of the functional options pattern. The error handling following the initialization is also correctly implemented, ensuring that the script terminates if theChainReader
cannot be created.node/script/test_websocketDexFetcher/main.go (1)
107-110
: Proper use ofChainReader
initialization in a data-fetching context.The script correctly initializes the
ChainReader
with both Ethereum and Kaia WebSocket URLs using the functional options pattern. The subsequent data fetching logic is dependent on the correct initialization, which is handled well here.node/pkg/chain/websocketchainreader/websocketreader.go (1)
18-62
: RefactoredNew
function correctly implements error handling and client initialization.The refactored
New
function now correctly initializes Ethereum and Kaia clients based on the provided URLs and handles errors appropriately. The use of a consolidated error for missing URLs (ErrChainWebsocketUrlNotProvided
) simplifies the error handling logic.node/pkg/websocketfetcher/app.go (1)
197-199
: Refactored initialization using functional options is clean and modular.The updated initialization of
chainReader
using the functional options pattern (WithEthWebsocketUrl
andWithKaiaWebsocketUrl
) is a good use of modern Go practices for configuration. This approach enhances readability and flexibility in setting up thechainReader
.However, ensure that the environment variables
KAIA_WEBSOCKET_URL
andETH_WEBSOCKET_URL
are always set before deployment as the application will fail to start without them.node/pkg/error/sentinel.go (1)
124-124
: Consolidated error for WebSocket URL enhances maintainability.Replacing specific errors for missing WebSocket URLs with a generic
ErrChainWebsocketUrlNotProvided
error simplifies the error handling logic and reduces potential redundancy. This change is consistent with the PR's objective to streamline error handling.
There was a problem hiding this 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
Files selected for processing (6)
- node/pkg/chain/websocketchainreader/type.go (1 hunks)
- node/pkg/chain/websocketchainreader/websocketreader.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 summarized due to errors (1)
- node/script/test_websocketDexFetcher/main.go: Error: Server error. Please try again later.
Additional comments not posted (9)
node/pkg/chain/websocketchainreader/type.go (2)
18-22
: Configuration struct is well-defined.The
ChainReaderConfig
struct is properly defined and aligns with the PR objectives to allow flexible initialization ofChainReader
. This struct now contains fields for both websocket URLs and a retry interval, providing clear configuration points for theChainReader
.
26-30
: Functional options are correctly implemented.The functional options
WithKaiaWebsocketUrl
,WithEthWebsocketUrl
, andWithRetryInterval
are correctly implemented. They modify theChainReaderConfig
struct as expected, allowing for flexible and dynamic configuration of theChainReader
.Also applies to: 32-36, 38-42
node/script/test_websocketchainreader/main.go (1)
30-33
: Correct usage of functional options inChainReader
initialization.The
ChainReader
is initialized using the functional options pattern correctly, which matches the changes made in thetype.go
file. This ensures that theChainReader
can be flexibly configured based on environment variables.node/script/test_websocketDexFetcher/main.go (1)
107-110
: Functional options are correctly used forChainReader
initialization.The initialization of
ChainReader
using the functional options pattern is correctly implemented here as well. This allows the script to dynamically configure theChainReader
based on provided environment variables, aligning with the changes in thetype.go
file.node/pkg/chain/websocketchainreader/websocketreader.go (2)
18-62
: RefactoredNew
function correctly implements functional options and handles errors appropriately.The
New
function has been refactored to use functional options, which is correctly implemented. The error handling is robust, checking for the absence of both websocket URLs and returning a specific error if both are missing, which aligns with the PR description.
Line range hint
65-148
: Subscription handling and error management are well-implemented.The
Subscribe
method and related subscription handling logic are correctly implemented. The method uses a configuration struct and functional options pattern for flexible subscription setup. Error handling is thorough, with specific errors returned for missing configuration details, and retry logic is in place for handling failures.node/pkg/websocketfetcher/app.go (2)
197-199
: Ensure both websocket URLs are provided.The current implementation checks for both
kaiaWebsocketUrl
andethWebsocketUrl
to be set. This is correct as per the new error handling logic.
199-199
: LGTM!The use of functional options pattern for
websocketchainreader.New
is correct and improves the code flexibility.node/pkg/error/sentinel.go (1)
124-124
: LGTM!The new error
ErrChainWebsocketUrlNotProvided
is correctly added to handle the case where both websocket URLs are not provided.
There was a problem hiding this 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
Files selected for processing (1)
- node/pkg/chain/websocketchainreader/websocketreader.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- node/pkg/chain/websocketchainreader/websocketreader.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
Description
Use functional options pattern for initialization
return error only when both eth websocket url and kaia websocket url are not provided
Fixes # (issue)
Type of change
Please delete options that are not relevant.
Checklist before requesting a review
Deployment