-
Notifications
You must be signed in to change notification settings - Fork 293
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
Conversation
…for local tracing stuff
WalkthroughWalkthroughThe Changes
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
Assessment against linked issues
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 Configuration 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: 1
scripts/single-node.sh
Outdated
# 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 |
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.
Review: Modified Prompt and Configuration Changes
-
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 whencelestia-appd
is invoked.
- The prompt now only appears if the
-
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
- The use of
-
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.
- The variable
-
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.
-
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)
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
scripts/single-node.sh
Outdated
# 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 |
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.
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:
- Safety of
rm -r
: Usingrm -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. - Unused Variable: The variable
app_home_exists
is set but never used, which could lead to confusion or maintenance issues. - 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)
Good idea!
Update: nvm I was wrong.
|
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... |
Makes sense ! I did not think about the genesis file ! 👍 |
Thanks for the PR! |
Congrats, your important contribution to this open-source project has earned you a GitPOAP! GitPOAP: 2024 Celestia Contributor: Head to gitpoap.io & connect your GitHub account to mint! Learn more about GitPOAPs here. |
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
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)
…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>
…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>
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 ascelestia-app
is invoked, it creates the directory. Hence I cannot use this information.