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

fix: fixed blocks and signatures logic #34

Merged
merged 2 commits into from
Jun 19, 2024
Merged

Conversation

yevhen-burkovskyi
Copy link
Contributor

No description provided.

Copy link

coderabbitai bot commented Jun 18, 2024

Walkthrough

This update broadly encompasses enhanced logging, improved code structure, and new functionalities for a staking module. Notably, StakingCache sees additions and modifications related to block handling. StakingService and other related classes get refactored for clarity and maintainability without significant functional changes. A new entry was added to the StakingCachePrefix enum.

Changes

Files Change Summary
src/main.ts Updated logging to include the application's URL instead of just host and port details.
src/modules/staking/enums/staking-cache-prefix.enum.ts Added a new entry LAST_BLOCK to the StakingCachePrefix enum.
src/modules/staking/services/staking.cache.ts Methods setRecentlyProposedBlock and getRecentlyProposedBlock modified to include an address parameter; new setLastBlock and getLastBlock methods were introduced.
src/modules/staking/staking.controller.ts Modified getValidatorRecentlyProposedBlocks to accept an address parameter validated by SchemaValidatePipe.
src/modules/staking/staking.gateway.ts Refactored to remove the OnGatewayConnection interface, utilize @WebSocketServer, and modify event handling methods.
src/modules/staking/services/staking.service.ts Comprehensive restructure aimed at enhancing readability and maintainability; includes reformatting of code blocks and parameter placements.

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.

@yevhen-burkovskyi yevhen-burkovskyi self-assigned this Jun 18, 2024
Copy link

@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

Outside diff range and nitpick comments (1)
src/modules/staking/services/staking.service.ts (1)

Line range hint 256-273: Properly handle asynchronous operations and potential errors in delegation fetching.

This function could benefit from additional error handling mechanisms to manage exceptions that might occur during the fetching of delegation data:

+ try {
- const rez = await Promise.all([
-   this.fetchMyStakedAmount(payload.address, payload.validatorAddress),
-   this.fetchDelegatorsRewards(payload.address, payload.validatorAddress),
- ]);
+ } catch (error) {
+   Log.error(`Error fetching delegation data: ${error}`);
+   throw new BadRequestException('Failed to fetch delegation data');
+ }
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0bd0b65 and 2a71e3d.

Files selected for processing (6)
  • src/main.ts (1 hunks)
  • src/modules/staking/enums/staking-cache-prefix.enum.ts (1 hunks)
  • src/modules/staking/services/staking.cache.ts (1 hunks)
  • src/modules/staking/services/staking.service.ts (12 hunks)
  • src/modules/staking/staking.controller.ts (1 hunks)
  • src/modules/staking/staking.gateway.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/main.ts
Additional context used
Biome
src/modules/staking/staking.controller.ts

[error] 22-22: Decorators are not valid here. (parse)

Decorators are only valid on class declarations, class expressions, and class methods.
You can enable parameter decorators by setting the unsafeParameterDecoratorsEnabled option to true in your configuration file.


[error] 40-40: Decorators are not valid here. (parse)

Decorators are only valid on class declarations, class expressions, and class methods.
You can enable parameter decorators by setting the unsafeParameterDecoratorsEnabled option to true in your configuration file.


[error] 48-48: Decorators are not valid here. (parse)

Decorators are only valid on class declarations, class expressions, and class methods.
You can enable parameter decorators by setting the unsafeParameterDecoratorsEnabled option to true in your configuration file.


[error] 56-56: Decorators are not valid here. (parse)

Decorators are only valid on class declarations, class expressions, and class methods.
You can enable parameter decorators by setting the unsafeParameterDecoratorsEnabled option to true in your configuration file.


[error] 64-64: Decorators are not valid here. (parse)

Decorators are only valid on class declarations, class expressions, and class methods.
You can enable parameter decorators by setting the unsafeParameterDecoratorsEnabled option to true in your configuration file.


[error] 72-72: Decorators are not valid here. (parse)

Decorators are only valid on class declarations, class expressions, and class methods.
You can enable parameter decorators by setting the unsafeParameterDecoratorsEnabled option to true in your configuration file.


[error] 85-85: Decorators are not valid here. (parse)

Decorators are only valid on class declarations, class expressions, and class methods.
You can enable parameter decorators by setting the unsafeParameterDecoratorsEnabled option to true in your configuration file.

src/modules/staking/services/staking.service.ts

[error] 466-466: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


[error] 499-499: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.

Additional comments not posted (12)
src/modules/staking/enums/staking-cache-prefix.enum.ts (1)

10-10: The addition of LAST_BLOCK to StakingCachePrefix enum is well-placed and follows the naming conventions of the existing entries.

src/modules/staking/staking.gateway.ts (3)

9-10: The server property is correctly annotated with @WebSocketServer(), ensuring it is properly initialized for use within the class.


10-15: The uptimeUpdate method now uses this.server.emit for emitting events, which is a more direct and appropriate way to handle WebSocket communications in NestJS.
[APROVED]


20-21: The blockUpdate method has been updated to include an addr parameter and uses this.server.emit, aligning with the changes in uptimeUpdate for consistency and direct server access.

src/modules/staking/staking.controller.ts (1)

71-75: The method getValidatorRecentlyProposedBlocks correctly includes the address parameter with validation using SchemaValidatePipe. This ensures that only valid addresses are processed, enhancing security and data integrity.

Tools
Biome

[error] 72-72: Decorators are not valid here. (parse)

Decorators are only valid on class declarations, class expressions, and class methods.
You can enable parameter decorators by setting the unsafeParameterDecoratorsEnabled option to true in your configuration file.

src/modules/staking/services/staking.cache.ts (4)

95-96: The setRecentlyProposedBlock method correctly constructs a unique Redis key for each block and address combination, which is essential for avoiding collisions in data storage.


100-101: The getRecentlyProposedBlock method efficiently retrieves all blocks proposed by a specific address, utilizing pattern matching in Redis keys. This is a scalable way to handle data retrieval.


108-109: The setLastBlock method simplifies the interaction with Redis by directly setting the last block without additional parameters, which is appropriate for global data like the last block in the chain.


112-119: The getLastBlock method includes proper error handling for cases where the block data might not be present in Redis, returning null in such cases. This is a good practice for robust error handling.

src/modules/staking/services/staking.service.ts (3)

39-40: Ensure consistent use of dependency injection for EventEmitter2.

EventEmitter2 is correctly injected into the StakingService class, which is crucial for event-driven architectures in NestJS.


46-48: Properly handle block updates with event listeners.

This code segment effectively sets up an event listener for block updates, which is a good practice for real-time data handling in blockchain applications.


Line range hint 197-227: Ensure data consistency in the view transformation.

This method transforms validator data into a view-friendly format. It properly uses Big.js for accurate arithmetic operations and handles potential null values effectively.

src/modules/staking/services/staking.service.ts Outdated Show resolved Hide resolved
src/modules/staking/services/staking.service.ts Outdated Show resolved Hide resolved
src/modules/staking/services/staking.service.ts Outdated Show resolved Hide resolved
Copy link

@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 2a71e3d and 5111f96.

Files selected for processing (1)
  • src/modules/staking/services/staking.service.ts (12 hunks)
Additional context used
Biome
src/modules/staking/services/staking.service.ts

[error] 473-473: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.

Additional comments not posted (4)
src/modules/staking/services/staking.service.ts (4)

78-78: Ensure proper error handling when setting cache values.


167-167: Ensure that asynchronous operations are error-handled.


473-473: Use optional chaining to improve safety in accessing properties.

- if (!blocks || blocks.length === 0 || !signed) {
+ if (!blocks?.length || !signed) {
Tools
Biome

[error] 473-473: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


478-478: Consider using optional chaining for better safety and readability.

- if (!blocks?.length || !signed) {
+ if (!blocks?.length || !signed) {

Likely invalid or redundant comment.

@yevhen-burkovskyi yevhen-burkovskyi merged commit f76bc26 into main Jun 19, 2024
11 checks passed
@yevhen-burkovskyi yevhen-burkovskyi deleted the fix/blocks branch June 19, 2024 08:53
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