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 multiple preconfirmations for the same slot in demo #110

Merged
merged 3 commits into from
Jul 25, 2024

Conversation

thedevbirb
Copy link
Contributor

@thedevbirb thedevbirb commented Jul 4, 2024

Closes #107. Note that this doesn't really allow spamming continuously the button since there is a little delay between update of React state variables.

Summary by CodeRabbit

  • New Features

    • Enhanced the Home component for better handling of preconfirmation requests and wallet integration.
    • Introduced constants for secure interactions with the Kurtosis development network.
  • Improvements

    • Updated the transaction handling to ensure accuracy and responsiveness to blockchain events.
    • Streamlined payload creation for preconfirmation requests and improved function modularity.
  • Bug Fixes

    • Improved event handling logic to filter out outdated requests.
  • Chores

    • Reformatted the startup script for better readability and added a delay before opening the browser to enhance user experience.

@thedevbirb thedevbirb added the T: bug Type: Bug label Jul 4, 2024
Copy link
Contributor

coderabbitai bot commented Jul 4, 2024

Walkthrough

The recent updates enhance the Home component's ability to manage preconfirmation requests and improve wallet interactions using the ethers library. Key changes include dynamic nonce handling, optimized event filtering, and a modular approach to payload creation, addressing edge cases in transaction processing. These modifications lead to improved accuracy and efficiency in transaction management, particularly for scenarios involving rapid preconfirmation requests at the same blockchain slot.

Changes

Files Change Summary
src/app/page.tsx Enhanced Home component with state management for preconfirmation requests and nonce, improved event handling, and optimized sendPreconfirmation function using useCallback.
src/lib/constants.ts Introduced constants for blockchain interactions, including a private key, chain ID, and server URL for better maintainability.
src/lib/wallet.ts Modified createPreconfPayload function to accept an ethers.Wallet instance and nonce directly, removing hardcoded values and improving flexibility.
scripts/start-demo.sh Reformatted for readability with minor structural changes, added a sleep 1 command for service initialization.

Assessment against linked issues

Objective Addressed Explanation
Handle two or more pre-confirmations at the same slot (#[107])

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.

@thedevbirb thedevbirb changed the base branch from unstable to feat/sidecar/builder-api July 4, 2024 08:23
@thedevbirb thedevbirb added the C: bolt-frontend-demo Component: bolt frontend demo label Jul 4, 2024
Base automatically changed from feat/sidecar/builder-api to unstable July 4, 2024 08:52
@thedevbirb thedevbirb marked this pull request as ready for review July 25, 2024 10:37
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: 3

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 6205121 and 2f83d39.

Files selected for processing (4)
  • bolt-web-demo/frontend/src/app/page.tsx (8 hunks)
  • bolt-web-demo/frontend/src/lib/constants.ts (1 hunks)
  • bolt-web-demo/frontend/src/lib/wallet.ts (4 hunks)
  • scripts/start-demo.sh (2 hunks)
Additional context used
Gitleaks
bolt-web-demo/frontend/src/lib/constants.ts

2-3: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

Shellcheck
scripts/start-demo.sh

[warning] 14-14: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)

Additional comments not posted (9)
bolt-web-demo/frontend/src/lib/wallet.ts (1)

12-13: LGTM! But verify the function usage in the codebase.

The refactor to accept a wallet instance and nonce improves flexibility and security by removing the hardcoded private key.

However, ensure that all function calls to createPreconfPayload match the new signature.

Verification successful

Function usage verified

The function createPreconfPayload is used in bolt-web-demo/frontend/src/app/page.tsx, and the call matches the new signature with the wallet and nonceWithPreconfs arguments.

  • bolt-web-demo/frontend/src/app/page.tsx: Lines 25-28
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `createPreconfPayload` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type javascript -A 5 $'createPreconfPayload'

Length of output: 83


Script:

#!/bin/bash
# Description: Verify all function calls to `createPreconfPayload` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type js -A 5 'createPreconfPayload'

Length of output: 40


Script:

#!/bin/bash
# Description: Verify all function calls to `createPreconfPayload` match the new signature.

# Test: Search for the function usage across all file types. Expect: Only occurrences of the new signature.
rg -A 5 'createPreconfPayload'

Length of output: 1378

bolt-web-demo/frontend/src/app/page.tsx (8)

5-5: LGTM!

The import statement for useState, useEffect, useMemo, and useCallback is correct and necessary for the changes in the file.


11-12: LGTM!

The import statement for the ethers library and constants is correct and necessary for wallet interactions and managing constants.


40-43: LGTM!

The new state variables preconfirmationRequests and nonce are essential for managing preconfirmation requests and nonce handling.


45-49: LGTM!

The useMemo hook optimizes the creation of the wallet instance, ensuring it is only recreated when providerUrl changes.


62-81: LGTM!

The event handling logic ensures that only relevant requests are retained and the nonce is updated dynamically.


127-127: LGTM!

Including wallet in the dependency array ensures that the effect runs when the wallet instance changes.


Line range hint 171-228:
LGTM!

The useCallback hook optimizes the sendPreconfirmation function by preventing unnecessary re-creations on re-renders. The nonce calculation ensures correct sequencing of transactions.


206-206: LGTM!

Dispatching this event provides useful information about the preconfirmation request, including the transaction hash, slot, and nonce.

Comment on lines +2 to +3
export const PRIVATE_KEY =
"39725efee3fb28614de3bacaffe4cc4bd8c436257e2c8bb887c4b5c4be45e76d";
Copy link
Contributor

@coderabbitai coderabbitai bot Jul 25, 2024

Choose a reason for hiding this comment

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

Security Risk: Hardcoded Private Key

Hardcoding a private key is a significant security risk as it can lead to unauthorized access and misuse. Consider using environment variables or a secure vault to manage sensitive information.

- export const PRIVATE_KEY = "39725efee3fb28614de3bacaffe4cc4bd8c436257e2c8bb887c4b5c4be45e76d";
+ export const PRIVATE_KEY = process.env.PRIVATE_KEY || "";
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const PRIVATE_KEY =
"39725efee3fb28614de3bacaffe4cc4bd8c436257e2c8bb887c4b5c4be45e76d";
export const PRIVATE_KEY = process.env.PRIVATE_KEY || "";
Tools
Gitleaks

2-3: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

Copy link
Contributor Author

@thedevbirb thedevbirb Jul 25, 2024

Choose a reason for hiding this comment

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

yolo

Copy link
Contributor

Choose a reason for hiding this comment

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

@thedevbirb, I understand that it might seem convenient to hardcode the private key for testing purposes, but it's crucial to avoid this practice even in development environments. Hardcoding sensitive information like private keys can lead to significant security vulnerabilities. Using environment variables or a secure vault to manage such data is a safer approach. This helps prevent unauthorized access and misuse.

Let me know if you need any assistance in implementing these changes.

bolt-web-demo/frontend/src/lib/constants.ts Show resolved Hide resolved
"cd bolt-web-demo/frontend && yarn && yarn dev"
"cd bolt-web-demo/backend && yarn && yarn dev"
"cd bolt-web-demo/frontend && yarn && yarn dev"
"cd bolt-web-demo/backend && yarn && yarn dev"
)

# Function to quit all processes on Ctrl+C
quit_all() {
echo "Caught SIGINT, quitting all processes."
pids=($(jobs -p))
Copy link
Contributor

Choose a reason for hiding this comment

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

Shellcheck Warning: Prefer mapfile or read -a

To avoid splitting command output, use mapfile or read -a. This ensures that the output is handled correctly, especially if it contains spaces.

- pids=($(jobs -p))
+ mapfile -t pids < <(jobs -p)
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
pids=($(jobs -p))
mapfile -t pids < <(jobs -p)
Tools
Shellcheck

[warning] 14-14: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)

done

# Open the browser
sleep 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

very nice DX improvement 😄

Copy link
Collaborator

@merklefruit merklefruit left a comment

Choose a reason for hiding this comment

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

lgtm, can I try it on the demo on this branch?

@thedevbirb
Copy link
Contributor Author

lgtm, can I try it on the demo on this branch?

Screen.Recording.2024-07-25.at.14.40.10.mov

@merklefruit
Copy link
Collaborator

Very nice :)

@merklefruit merklefruit merged commit fca6055 into unstable Jul 25, 2024
2 checks passed
@merklefruit merklefruit deleted the fix/demo/multiple-preconfs branch July 25, 2024 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: bolt-frontend-demo Component: bolt frontend demo T: bug Type: Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle two or more pre-confirmations at the same slot in the demo
2 participants