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

refactor(scripts): improve user prompts for single-node.sh #3685

Merged
merged 6 commits into from
Jul 16, 2024

Conversation

najeal
Copy link
Contributor

@najeal najeal commented Jul 15, 2024

Closes #3652

Overview

It modifies single-node.sh script.
This rewrites the first prompt and deletes the second one.
I wanted write Do you want to start a new local testnet? [y/n] only when $HOME/.celestia-app does not exist. But it looks like as soon as celestia-app is invoked, it creates the directory. Hence I cannot use this information.

@najeal najeal requested a review from a team as a code owner July 15, 2024 23:03
@najeal najeal requested review from rootulp and staheri14 and removed request for a team July 15, 2024 23:03
Copy link
Contributor

coderabbitai bot commented Jul 15, 2024

Walkthrough

Walkthrough

The single-node.sh script has been enhanced to improve user interaction and functionality. The changes include a user prompt to start a new local testnet, which, if confirmed, leads to the deletion of the existing setup and reinitialization. Additionally, local tracing capabilities have been introduced for data extraction. The redundant confirmation prompt has been removed to streamline the process.

Changes

File Path Change Summary
scripts/single-node.sh Added user prompt for starting a new local testnet, deletion of existing setup if confirmed, reinitialization of node and validator configurations, and addition of local tracing capabilities.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Script
    
    User->>Script: Run single-node.sh
    Script->>User: Prompt "Do you want to start a new local testnet? (y/n)"
    alt User confirms
        User->>Script: y
        Script->>Script: Delete existing setup
        Script->>Script: Initialize node and validator config
        Script->>Script: Add new key and genesis account
        Script->>Script: Create genesis transaction
        Script->>Script: Configure settings
        Script->>Script: Set up local tracing
    else User declines
        User->>Script: n
        Script->>Script: Start node with existing setup
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Remove the second prompt and always set up the local tracing stuff (#3652)
Replace the first prompt with a confirmation to start a new local testnet (#3652)
If the user responds with n, start the node with the previous local testnet (#3652)

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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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.

@celestia-bot celestia-bot requested a review from a team July 15, 2024 23:03
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

Comment on lines 27 to 96
# Propose to start a new local testnet when a testnet already exists
if [ -d "${CELESTIA_APP_HOME}" ]; then
echo "Do you want to start a new local testnet? [y/n]"
read -r response
if [ "$response" == "y" ]; then
# Delete existing app if the user responded with "y"
echo "Deleting $CELESTIA_APP_HOME..."
rm -r "$CELESTIA_APP_HOME"
app_home_exists=false

echo "Initializing validator and node config files..."
celestia-appd init ${CHAIN_ID} \
--chain-id ${CHAIN_ID} \
--home "${CELESTIA_APP_HOME}" \
> /dev/null 2>&1 # Hide output to reduce terminal noise

echo "Adding a new key to the keyring..."
celestia-appd keys add ${KEY_NAME} \
--keyring-backend=${KEYRING_BACKEND} \
--home "${CELESTIA_APP_HOME}" \
> /dev/null 2>&1 # Hide output to reduce terminal noise

echo "Adding genesis account..."
celestia-appd add-genesis-account \
"$(celestia-appd keys show ${KEY_NAME} -a --keyring-backend=${KEYRING_BACKEND} --home "${CELESTIA_APP_HOME}")" \
$COINS \
--home "${CELESTIA_APP_HOME}"

echo "Creating a genesis tx..."
celestia-appd gentx ${KEY_NAME} ${DELEGATION_AMOUNT} \
--fees ${FEES} \
--keyring-backend=${KEYRING_BACKEND} \
--chain-id ${CHAIN_ID} \
--home "${CELESTIA_APP_HOME}" \
> /dev/null 2>&1 # Hide output to reduce terminal noise

echo "Collecting genesis txs..."
celestia-appd collect-gentxs \
--home "${CELESTIA_APP_HOME}" \
> /dev/null 2>&1 # Hide output to reduce terminal noise

# If you encounter: `sed: -I or -i may not be used with stdin` on MacOS you can mitigate by installing gnu-sed
# https://gist.github.com/andre3k1/e3a1a7133fded5de5a9ee99c87c6fa0d?permalink_comment_id=3082272#gistcomment-3082272

# Override the default RPC servier listening address
sed -i'.bak' 's#"tcp://127.0.0.1:26657"#"tcp://0.0.0.0:26657"#g' "${CELESTIA_APP_HOME}"/config/config.toml

# Enable transaction indexing
sed -i'.bak' 's#"null"#"kv"#g' "${CELESTIA_APP_HOME}"/config/config.toml

# Persist ABCI responses
sed -i'.bak' 's#discard_abci_responses = true#discard_abci_responses = false#g' "${CELESTIA_APP_HOME}"/config/config.toml

# Override the log level to debug
# sed -i'.bak' 's#log_level = "info"#log_level = "debug"#g' "${CELESTIA_APP_HOME}"/config/config.toml

# Override the VotingPeriod from 1 week to 1 minute
sed -i'.bak' 's#"604800s"#"60s"#g' "${CELESTIA_APP_HOME}"/config/genesis.json

# Override the genesis to use app version 1 and then upgrade to app version 2 later.
sed -i'.bak' 's#"app_version": "2"#"app_version": "1"#g' "${CELESTIA_APP_HOME}"/config/genesis.json

trace_type="local"
sed -i.bak -e "s/^trace_type *=.*/trace_type = \"$trace_type\"/" ${CELESTIA_APP_HOME}/config/config.toml
trace_pull_address=":26661"
sed -i.bak -e "s/^trace_pull_address *=.*/trace_pull_address = \"$trace_pull_address\"/" ${CELESTIA_APP_HOME}/config/config.toml
trace_push_batch_size=1000
sed -i.bak -e "s/^trace_push_batch_size *=.*/trace_push_batch_size = \"$trace_push_batch_size\"/" ${CELESTIA_APP_HOME}/config/config.toml
echo "Tracing is set up with the ability to pull traced data from the node on the address http://127.0.0.1${trace_pull_address}"
fi
Copy link
Contributor

Choose a reason for hiding this comment

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

Review: Modified Prompt and Configuration Changes

  1. Prompt Logic Change:

    • The prompt now only appears if the CELESTIA_APP_HOME directory exists, which aligns with the PR's objective to streamline the confirmation prompts. This is a sensible change given the context that the directory is created when celestia-appd is invoked.
  2. Shellcheck Warning (SC3014):

    • The use of == in the comparison on line 31 should be replaced with = for POSIX compliance.
    • Fix:
      - if [ "$response" == "y" ]; then
      + if [ "$response" = "y" ]; then
  3. Unused Variable (SC2034):

    • The variable app_home_exists on line 35 appears to be set but never used. This could be a remnant from a previous version of the script or planned for future use. If it's not needed, it should be removed to clean up the script.
    • Suggested Action: Verify the usage of app_home_exists and remove if unnecessary.
  4. Configuration Changes:

    • Changes to the configuration files (lines 71-94) are extensive and seem to be part of the setup process. These include setting RPC server address, enabling transaction indexing, changing log levels, adjusting the voting period, and setting up tracing. These changes are likely aligned with the objectives to enhance the local testnet setup.
    • Potential Issue: The commented-out line 81 changing the log level to debug might be useful for troubleshooting but could lead to performance issues if left enabled in a production environment. It's good practice to leave such options commented out but documented for optional use.
  5. Tracing Setup:

    • The setup for tracing on lines 89-95 is well-documented within the script, which is beneficial for maintenance and understanding the purpose of these configurations.

Overall, the changes are aligned with the PR objectives and improve the script's usability and functionality. However, the minor issues identified should be addressed to ensure the script adheres to best practices and avoids potential pitfalls in maintenance and performance.

Tools
Shellcheck

[warning] 31-31: In POSIX sh, == in place of = is undefined.

(SC3014)


[warning] 35-35: app_home_exists appears unused. Verify use (or export if used externally).

(SC2034)

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

Comment on lines 27 to 96
# Propose to start a new local testnet when a testnet already exists
if [ -d "${CELESTIA_APP_HOME}" ]; then
echo "Do you want to start a new local testnet? [y/n]"
read -r response
if [ "$response" = "y" ]; then
# Delete existing app if the user responded with "y"
echo "Deleting $CELESTIA_APP_HOME..."
rm -r "$CELESTIA_APP_HOME"
app_home_exists=false

echo "Initializing validator and node config files..."
celestia-appd init ${CHAIN_ID} \
--chain-id ${CHAIN_ID} \
--home "${CELESTIA_APP_HOME}" \
> /dev/null 2>&1 # Hide output to reduce terminal noise

echo "Adding a new key to the keyring..."
celestia-appd keys add ${KEY_NAME} \
--keyring-backend=${KEYRING_BACKEND} \
--home "${CELESTIA_APP_HOME}" \
> /dev/null 2>&1 # Hide output to reduce terminal noise

echo "Adding genesis account..."
celestia-appd add-genesis-account \
"$(celestia-appd keys show ${KEY_NAME} -a --keyring-backend=${KEYRING_BACKEND} --home "${CELESTIA_APP_HOME}")" \
$COINS \
--home "${CELESTIA_APP_HOME}"

echo "Creating a genesis tx..."
celestia-appd gentx ${KEY_NAME} ${DELEGATION_AMOUNT} \
--fees ${FEES} \
--keyring-backend=${KEYRING_BACKEND} \
--chain-id ${CHAIN_ID} \
--home "${CELESTIA_APP_HOME}" \
> /dev/null 2>&1 # Hide output to reduce terminal noise

echo "Collecting genesis txs..."
celestia-appd collect-gentxs \
--home "${CELESTIA_APP_HOME}" \
> /dev/null 2>&1 # Hide output to reduce terminal noise

# If you encounter: `sed: -I or -i may not be used with stdin` on MacOS you can mitigate by installing gnu-sed
# https://gist.github.com/andre3k1/e3a1a7133fded5de5a9ee99c87c6fa0d?permalink_comment_id=3082272#gistcomment-3082272

# Override the default RPC servier listening address
sed -i'.bak' 's#"tcp://127.0.0.1:26657"#"tcp://0.0.0.0:26657"#g' "${CELESTIA_APP_HOME}"/config/config.toml

# Enable transaction indexing
sed -i'.bak' 's#"null"#"kv"#g' "${CELESTIA_APP_HOME}"/config/config.toml

# Persist ABCI responses
sed -i'.bak' 's#discard_abci_responses = true#discard_abci_responses = false#g' "${CELESTIA_APP_HOME}"/config/config.toml

# Override the log level to debug
# sed -i'.bak' 's#log_level = "info"#log_level = "debug"#g' "${CELESTIA_APP_HOME}"/config/config.toml

# Override the VotingPeriod from 1 week to 1 minute
sed -i'.bak' 's#"604800s"#"60s"#g' "${CELESTIA_APP_HOME}"/config/genesis.json

# Override the genesis to use app version 1 and then upgrade to app version 2 later.
sed -i'.bak' 's#"app_version": "2"#"app_version": "1"#g' "${CELESTIA_APP_HOME}"/config/genesis.json

trace_type="local"
sed -i.bak -e "s/^trace_type *=.*/trace_type = \"$trace_type\"/" ${CELESTIA_APP_HOME}/config/config.toml
trace_pull_address=":26661"
sed -i.bak -e "s/^trace_pull_address *=.*/trace_pull_address = \"$trace_pull_address\"/" ${CELESTIA_APP_HOME}/config/config.toml
trace_push_batch_size=1000
sed -i.bak -e "s/^trace_push_batch_size *=.*/trace_push_batch_size = \"$trace_push_batch_size\"/" ${CELESTIA_APP_HOME}/config/config.toml
echo "Tracing is set up with the ability to pull traced data from the node on the address http://127.0.0.1${trace_pull_address}"
fi
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactored prompt logic and setup process.

The changes streamline the user experience by reducing the number of prompts and automating the setup process. However, there are a few points to consider:

  1. Safety of rm -r: Using rm -r without further confirmation after the initial prompt can be dangerous. Consider adding a double confirmation or a more explicit warning about what will be deleted.
  2. Unused Variable: The variable app_home_exists is set but never used, which could lead to confusion or maintenance issues.
  3. Shellcheck Warning: Ensure POSIX compliance by using = instead of == in comparisons.
- app_home_exists=false
- if [ "$response" == "y" ]; then
+ if [ "$response" = "y" ]; then

Would you like me to help remove the unused variable or adjust the confirmation logic for safety?

Committable suggestion was skipped due to low confidence.

Tools
Shellcheck

[warning] 35-35: app_home_exists appears unused. Verify use (or export if used externally).

(SC2034)

@rootulp
Copy link
Collaborator

rootulp commented Jul 16, 2024

I wanted write Do you want to start a new local testnet? [y/n] only when $HOME/.celestia-app does not exist.

Good idea!

But it looks like as soon as celestia-app is invoked, it creates the directory.

Update: nvm I was wrong. celestia-appd version creates a few directories like ~/.celestia-app/config and ~/.celestia-app/data. We can modify the conditional to something like:

if $HOME/.celestia-app/config/genesis.json exists {
    // promt user to start a new local testnet (delete existing $HOME/.celestia-app) or use existing local testnet
} else {
    // skip prompt and create a new local testnet
}

@rootulp
Copy link
Collaborator

rootulp commented Jul 16, 2024

Pushed a commit with the changes I had in mind. Tested:

$ ./scripts/single-node.sh
celestia-app home: /Users/rootulp/.celestia-app
celestia-app version: 2.0.0-rc2

Do you want to delete existing /Users/rootulp/.celestia-app and start a new local testnet? [y/n]
y
Deleting /Users/rootulp/.celestia-app...
Initializing validator and node config files...
Adding a new key to the keyring...
Adding genesis account...
Creating a genesis tx...
Collecting genesis txs...
Tracing is set up with the ability to pull traced data from the node on the address http://127.0.0.1:26661
Starting celestia-app...
$ ./scripts/single-node.sh
celestia-app home: /Users/rootulp/.celestia-app
celestia-app version: 2.0.0-rc2

Do you want to delete existing /Users/rootulp/.celestia-app and start a new local testnet? [y/n]
n
Starting celestia-app...

@celestia-bot celestia-bot requested review from a team and rach-id and removed request for a team July 16, 2024 15:46
@najeal
Copy link
Contributor Author

najeal commented Jul 16, 2024

Makes sense ! I did not think about the genesis file ! 👍

@rootulp
Copy link
Collaborator

rootulp commented Jul 16, 2024

Thanks for the PR!

@rootulp rootulp enabled auto-merge (squash) July 16, 2024 17:18
@celestia-bot celestia-bot requested a review from a team July 16, 2024 17:18
@rootulp rootulp changed the title refactor: single-node.sh - modify prompts refactor(scripts): improve user prompts for single-node.sh Jul 16, 2024
@rootulp rootulp merged commit a11ee9f into celestiaorg:main Jul 16, 2024
35 checks passed
Copy link

gitpoap-bot bot commented Jul 16, 2024

Congrats, your important contribution to this open-source project has earned you a GitPOAP!

GitPOAP: 2024 Celestia Contributor:

GitPOAP: 2024 Celestia Contributor GitPOAP Badge

Head to gitpoap.io & connect your GitHub account to mint!

Learn more about GitPOAPs here.

@najeal najeal deleted the single-node-prompt branch July 16, 2024 21:34
@rootulp rootulp added backport:v2.x PR will be backported automatically to the v2.x branch upon merging backport:v1.x PR will be backported automatically to the v1.x branch upon merging labels Jul 18, 2024
mergify bot pushed a commit that referenced this pull request Jul 18, 2024
Closes #3652

## Overview

It modifies `single-node.sh` script.
This rewrites the first prompt and deletes the second one.
I wanted write `Do you want to start a new local testnet? [y/n]` only
when `$HOME/.celestia-app` does not exist. But it looks like as soon as
`celestia-app` is invoked, it creates the directory. Hence I cannot use
this information.

---------

Co-authored-by: Rootul Patel <rootulp@gmail.com>
(cherry picked from commit a11ee9f)

# Conflicts:
#	scripts/single-node.sh
mergify bot pushed a commit that referenced this pull request Jul 18, 2024
Closes #3652

## Overview

It modifies `single-node.sh` script.
This rewrites the first prompt and deletes the second one.
I wanted write `Do you want to start a new local testnet? [y/n]` only
when `$HOME/.celestia-app` does not exist. But it looks like as soon as
`celestia-app` is invoked, it creates the directory. Hence I cannot use
this information.

---------

Co-authored-by: Rootul Patel <rootulp@gmail.com>
(cherry picked from commit a11ee9f)
rootulp added a commit that referenced this pull request Jul 19, 2024
…3685) (#3707)

Closes #3652 

## Overview

It modifies `single-node.sh` script.
This rewrites the first prompt and deletes the second one.
I wanted write `Do you want to start a new local testnet? [y/n]` only
when `$HOME/.celestia-app` does not exist. But it looks like as soon as
`celestia-app` is invoked, it creates the directory. Hence I cannot use
this information.
<hr>This is an automatic backport of pull request #3685 done by
[Mergify](https://mergify.com).

---------

Co-authored-by: nathan haim <nathan.haim@free.fr>
Co-authored-by: Rootul Patel <rootulp@gmail.com>
rootulp pushed a commit that referenced this pull request Jul 19, 2024
…3685) (#3708)

Closes #3652 

## Overview

It modifies `single-node.sh` script.
This rewrites the first prompt and deletes the second one.
I wanted write `Do you want to start a new local testnet? [y/n]` only
when `$HOME/.celestia-app` does not exist. But it looks like as soon as
`celestia-app` is invoked, it creates the directory. Hence I cannot use
this information.
<hr>This is an automatic backport of pull request #3685 done by
[Mergify](https://mergify.com).

Co-authored-by: nathan haim <nathan.haim@free.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:v1.x PR will be backported automatically to the v1.x branch upon merging backport:v2.x PR will be backported automatically to the v2.x branch upon merging external
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve confirmation prompts for single-node.sh
3 participants