-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
WalkthroughThis update broadly encompasses enhanced logging, improved code structure, and new functionalities for a staking module. Notably, Changes
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: 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
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 theunsafeParameterDecoratorsEnabled
option totrue
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 theunsafeParameterDecoratorsEnabled
option totrue
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 theunsafeParameterDecoratorsEnabled
option totrue
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 theunsafeParameterDecoratorsEnabled
option totrue
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 theunsafeParameterDecoratorsEnabled
option totrue
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 theunsafeParameterDecoratorsEnabled
option totrue
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 theunsafeParameterDecoratorsEnabled
option totrue
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 ofLAST_BLOCK
toStakingCachePrefix
enum is well-placed and follows the naming conventions of the existing entries.src/modules/staking/staking.gateway.ts (3)
9-10
: Theserver
property is correctly annotated with@WebSocketServer()
, ensuring it is properly initialized for use within the class.
10-15
: TheuptimeUpdate
method now usesthis.server.emit
for emitting events, which is a more direct and appropriate way to handle WebSocket communications in NestJS.
[APROVED]
20-21
: TheblockUpdate
method has been updated to include anaddr
parameter and usesthis.server.emit
, aligning with the changes inuptimeUpdate
for consistency and direct server access.src/modules/staking/staking.controller.ts (1)
71-75
: The methodgetValidatorRecentlyProposedBlocks
correctly includes theaddress
parameter with validation usingSchemaValidatePipe
. 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 theunsafeParameterDecoratorsEnabled
option totrue
in your configuration file.src/modules/staking/services/staking.cache.ts (4)
95-96
: ThesetRecentlyProposedBlock
method correctly constructs a unique Redis key for each block and address combination, which is essential for avoiding collisions in data storage.
100-101
: ThegetRecentlyProposedBlock
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
: ThesetLastBlock
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
: ThegetLastBlock
method includes proper error handling for cases where the block data might not be present in Redis, returningnull
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 forEventEmitter2
.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.
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)
- 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.
No description provided.