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

feat: add local testnet guide #1815

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

jcstein
Copy link
Member

@jcstein jcstein commented Nov 28, 2024

Overview

PREVIEW

Resolves #1813

Screenshot 2024-11-28 at 00 16 13 Screenshot 2024-11-28 at 00 28 52

Tasks

  • Add document explaining how to set up local ephemeral testnet manually
  • Add setup for validator, bridge node, and light node
  • Review coderabbit suggestions
  • Add local Celenium support (nice-to-have)

Summary by CodeRabbit

  • New Features
    • Added a new sidebar item for "Set up a local testnet" in the documentation.
    • Introduced a comprehensive guide on setting up a local Celestia testnet, covering validator, bridge, and light node configurations.
    • Launched a new script to automate the setup of a local testnet, including necessary checks and initialization steps.

Copy link
Contributor

coderabbitai bot commented Nov 28, 2024

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes in this pull request introduce a new sidebar item titled "Set up a local testnet" in the VitePress configuration file, linking to a new guide. This guide, located in how-to-guides/local-testnet.md, provides detailed instructions for setting up a local Celestia testnet, covering the configuration of various nodes. Additionally, a new script start-local.sh is added to automate the setup process for the local testnet, including necessary checks and commands for node initialization.

Changes

File Change Summary
.vitepress/config.ts Added sidebar item: { text: "Set up a local testnet", link: "/how-to-guides/local-testnet" }
how-to-guides/local-testnet.md Created a guide detailing steps to set up a local Celestia testnet, including node configurations.
public/start-local.sh Added a script to automate the setup of a local testnet, including checks and node initialization.

Possibly related PRs

Suggested labels

documentation

Suggested reviewers

  • S1nus

🐰 In the meadow, where ideas bloom,
A guide for testnets dispels the gloom.
With scripts and steps, we hop with glee,
Setting up nodes, as easy as can be!
So gather 'round, let's start the quest,
For local testnets, we’ll do our best! 🌼


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

Copy link
Contributor

github-actions bot commented Nov 28, 2024

PR Preview Action v1.4.8
🚀 Deployed preview to https://celestiaorg.github.io/docs-preview/./pr-1815/
on branch main at 2024-11-28 14:16 UTC

@jcstein jcstein self-assigned this Nov 28, 2024
@jcstein jcstein requested a review from Bidon15 November 28, 2024 07:17
@jcstein jcstein marked this pull request as ready for review November 28, 2024 07:17
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: 10

🧹 Outside diff range and nitpick comments (7)
how-to-guides/local-testnet.md (5)

41-44: Add note about example data

The example genesis hash should be clearly marked as example data that will differ for each setup.

🧰 Tools
🪛 Markdownlint (0.35.0)

42-42: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


48-50: Address environment variable persistence

Consider adding instructions for:

  1. Making the environment variable persistent across sessions
  2. Verifying the variable is set correctly

124-124: Document port selection

Add a note explaining:

  1. Why port 42069 was chosen
  2. That users can choose a different available port
  3. How to verify port availability

153-156: Enhance blob submission documentation

Consider adding:

  1. Explanation of the blob data format (0x4772756763686174)
  2. Expected success response
  3. How to verify the blob was submitted successfully

42-44: Add language specification to code block

Add a language identifier to the fenced code block for proper syntax highlighting.

-```
+```text
 1D53B32ACB02563E425BA1F8B5178B06A748E0F7B9748A8B1D07C34B454AF595

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 Markdownlint (0.35.0)</summary>

42-42: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

</details>

</details>

</blockquote></details>
<details>
<summary>public/start-local.sh (2)</summary><blockquote>

`3-10`: **Enhance the warning message with specific details**

While the warning is good practice, it could be more specific about which data will be deleted and the potential impact.

```diff
-echo "WARNING: This script will DELETE your existing .celestia-app directory and start a new local testnet."
-echo "Make sure you have backed up any important data from .celestia-app"
+echo "WARNING: This script will DELETE the following directories:"
+echo "  - $HOME/.celestia-app"
+echo "  - $HOME/.celestia-custom-bridge"
+echo "  - $HOME/.celestia-custom-light"
+echo "This will remove all existing chain data, keys, and configurations."
+echo "Please ensure you have backed up any important data before proceeding."

1-139: Consider improving script documentation and modularity

While the script is functional, consider the following architectural improvements:

  1. Add a comprehensive help/usage section with command-line arguments for customization
  2. Break down the script into modules for better maintainability
  3. Add logging levels and verbose mode for debugging
  4. Consider creating a configuration file for customizable parameters

Example help section to add at the beginning:

#!/bin/bash

show_help() {
    cat << EOF
Usage: $(basename "$0") [OPTIONS]

Sets up a local Celestia testnet with validator, bridge, and light nodes.

Options:
    -h, --help              Show this help message
    -v, --verbose          Enable verbose logging
    --no-cleanup           Skip cleanup on exit
    --timeout SECONDS      Service startup timeout (default: 60)
    --stabilization SECONDS Post-startup stabilization delay (default: 5)

Example:
    $(basename "$0") --verbose --timeout 120

For more information, visit: https://docs.celestia.org/nodes/local-testnet
EOF
    exit 0
}

# Parse command line arguments
while [[ $# -gt 0 ]]; do
    case $1 in
        -h|--help) show_help ;;
        -v|--verbose) VERBOSE=1 ;;
        --no-cleanup) NO_CLEANUP=1 ;;
        --timeout) TIMEOUT="$2"; shift ;;
        --stabilization) STABILIZATION="$2"; shift ;;
        *) echo "Unknown option: $1"; show_help ;;
    esac
    shift
done
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 10ce530 and 4fc6552.

📒 Files selected for processing (3)
  • .vitepress/config.ts (1 hunks)
  • how-to-guides/local-testnet.md (1 hunks)
  • public/start-local.sh (1 hunks)
🧰 Additional context used
🪛 Markdownlint (0.35.0)
how-to-guides/local-testnet.md

42-42: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🔇 Additional comments (2)
how-to-guides/local-testnet.md (1)

7-10: Consider enhancing the prerequisites section

While the prerequisites are clearly listed, consider:

  1. Specifying minimum required versions for each tool
  2. Adding installation instructions or links for jq and nc

Let's verify the relative link to compatible versions:

.vitepress/config.ts (1)

391-394: LGTM! The sidebar item is well-placed and properly structured.

The new "Set up a local testnet" item is appropriately placed under the "Getting started" section, following the existing pattern and hierarchy. The link path follows the documentation's convention.

Comment on lines +28 to +31
```bash
cd celestia-app/scripts
bash single-node.sh
```
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add validation steps for successful node startup

Consider adding:

  1. Expected output or success indicators
  2. Commands to verify the validator node is running correctly
  3. Troubleshooting steps for common issues

Send funds to the light node:

```bash
celestia-appd tx bank send validator celestia1p8yx4yveuu6ushyccepsuknaqpqn9ppq07m4n3 10000000utia \
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Document address usage

Replace the hardcoded address with a placeholder and explain:

  1. How to obtain the correct address
  2. The expected address format

how-to-guides/local-testnet.md Show resolved Hide resolved
Comment on lines +121 to +139
# Get addresses and fund light node
echo "Getting node addresses..."
BRIDGE_ADDRESS=$(celestia state account-address --node.store "$HOME/.celestia-custom-bridge" | jq -r '.result')
LIGHT_ADDRESS=$(celestia state account-address --node.store "$HOME/.celestia-custom-light" --url http://localhost:42069 | jq -r '.result')
echo "Funding light node..."
celestia-appd tx bank send validator "$LIGHT_ADDRESS" 10000000utia \
--chain-id test \
--keyring-backend test \
--fees 500utia -y
echo "Waiting for funding transaction to be included in a block..."
sleep 5
echo "Testing blob submission..."
celestia blob submit 0x4772756763686174 '"Simplicity is the ultimate sophistication." -Leonardo da Vinci' \
--node.store "$HOME/.celestia-custom-light" \
--url http://localhost:42069
echo "Setup complete!"
echo "Bridge node address: $BRIDGE_ADDRESS"
echo "Light node address: $LIGHT_ADDRESS"
echo "Custom network: $CELESTIA_CUSTOM"
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve final setup reliability and add cleanup

The current implementation needs better transaction validation and cleanup handling.

+# Trap for cleanup on script exit
+cleanup() {
+    echo "Cleaning up..."
+    stop_process "celestia-appd"
+    stop_process "celestia"
+    rm -f light.log bridge.log
+}
+trap cleanup EXIT
+
 # Get addresses and fund light node
 echo "Getting node addresses..."
-BRIDGE_ADDRESS=$(celestia state account-address --node.store "$HOME/.celestia-custom-bridge" | jq -r '.result')
-LIGHT_ADDRESS=$(celestia state account-address --node.store "$HOME/.celestia-custom-light" --url http://localhost:42069 | jq -r '.result')
+BRIDGE_ADDRESS=$(celestia state account-address --node.store "$HOME/.celestia-custom-bridge" | jq -r '.result') || {
+    echo "Error: Failed to get bridge address"
+    exit 1
+}
+LIGHT_ADDRESS=$(celestia state account-address --node.store "$HOME/.celestia-custom-light" --url http://localhost:42069 | jq -r '.result') || {
+    echo "Error: Failed to get light address"
+    exit 1
+}
+
 echo "Funding light node..."
-celestia-appd tx bank send validator "$LIGHT_ADDRESS" 10000000utia \
+TX_HASH=$(celestia-appd tx bank send validator "$LIGHT_ADDRESS" 10000000utia \
     --chain-id test \
     --keyring-backend test \
-    --fees 500utia -y
+    --fees 500utia -y | jq -r '.txhash') || {
+    echo "Error: Funding transaction failed"
+    exit 1
+}
+
 echo "Waiting for funding transaction to be included in a block..."
-sleep 5
+for i in {1..30}; do
+    if celestia-appd query tx "$TX_HASH" 2>/dev/null; then
+        break
+    fi
+    if [ "$i" -eq 30 ]; then
+        echo "Error: Funding transaction not confirmed after 30 seconds"
+        exit 1
+    fi
+    sleep 1
+done
+
 echo "Testing blob submission..."
 celestia blob submit 0x4772756763686174 '"Simplicity is the ultimate sophistication." -Leonardo da Vinci' \
     --node.store "$HOME/.celestia-custom-light" \
-    --url http://localhost:42069
+    --url http://localhost:42069 || {
+    echo "Error: Blob submission failed"
+    exit 1
+}
+
 echo "Setup complete!"
 echo "Bridge node address: $BRIDGE_ADDRESS"
 echo "Light node address: $LIGHT_ADDRESS"
 echo "Custom network: $CELESTIA_CUSTOM"
+echo "Logs available at: bridge.log and light.log"

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +21 to +30
wait_for_service() {
local port=$1
local service=$2
echo "Waiting for $service to be ready..."
while ! nc -z localhost "$port"; do
sleep 1
done
echo "$service is ready!"
sleep 5 # Give it a little extra time to stabilize
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add timeout and configurable stabilization delay to wait_for_service

The current implementation has two potential issues:

  1. No timeout mechanism could lead to an infinite wait
  2. Fixed 5-second stabilization delay might not be sufficient for all services
 wait_for_service() {
     local port=$1
     local service=$2
+    local timeout=${3:-60}  # Default 60 seconds timeout
+    local stabilization_delay=${4:-5}  # Default 5 seconds stabilization
+    local start_time=$(date +%s)
     echo "Waiting for $service to be ready..."
     while ! nc -z localhost "$port"; do
+        if [ $(($(date +%s) - start_time)) -gt "$timeout" ]; then
+            echo "Timeout waiting for $service after $timeout seconds"
+            exit 1
+        fi
         sleep 1
     done
     echo "$service is ready!"
-    sleep 5  # Give it a little extra time to stabilize
+    sleep "$stabilization_delay"
 }
📝 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
wait_for_service() {
local port=$1
local service=$2
echo "Waiting for $service to be ready..."
while ! nc -z localhost "$port"; do
sleep 1
done
echo "$service is ready!"
sleep 5 # Give it a little extra time to stabilize
}
wait_for_service() {
local port=$1
local service=$2
local timeout=${3:-60} # Default 60 seconds timeout
local stabilization_delay=${4:-5} # Default 5 seconds stabilization
local start_time=$(date +%s)
echo "Waiting for $service to be ready..."
while ! nc -z localhost "$port"; do
if [ $(($(date +%s) - start_time)) -gt "$timeout" ]; then
echo "Timeout waiting for $service after $timeout seconds"
exit 1
fi
sleep 1
done
echo "$service is ready!"
sleep "$stabilization_delay"
}

Comment on lines +98 to +119
# Initialize and start light node
echo "Initializing light node..."
celestia light init \
--p2p.network test \
--core.ip localhost:26657 \
--node.store "$HOME/.celestia-custom-light/"

# Construct the light node start command
LIGHT_NODE_CMD="celestia light start \
--p2p.network test \
--core.ip localhost:26657 \
--node.store \"$HOME/.celestia-custom-light/\" \
--headers.trusted-peers \"$PEER_ADDR/p2p/$PEER_ID\" \
--rpc.port 42069"

# Log the command
echo "Starting light node with command:"
echo "$LIGHT_NODE_CMD"

# Execute the command
eval "$LIGHT_NODE_CMD" &
wait_for_service 42069 "light node"
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Improve light node setup security and reliability

The current implementation uses eval and lacks proper error handling.

 # Initialize and start light node
 echo "Initializing light node..."
 celestia light init \
     --p2p.network test \
     --core.ip localhost:26657 \
-    --node.store "$HOME/.celestia-custom-light/"
+    --node.store "$HOME/.celestia-custom-light/" || {
+        echo "Error: Light node initialization failed"
+        exit 1
+    }
 
-# Construct the light node start command
-LIGHT_NODE_CMD="celestia light start \
-    --p2p.network test \
-    --core.ip localhost:26657 \
-    --node.store \"$HOME/.celestia-custom-light/\" \
-    --headers.trusted-peers \"$PEER_ADDR/p2p/$PEER_ID\" \
-    --rpc.port 42069"
-
-# Log the command
-echo "Starting light node with command:"
-echo "$LIGHT_NODE_CMD"
-
-# Execute the command
-eval "$LIGHT_NODE_CMD" &
+# Start light node directly without eval
+echo "Starting light node..."
+celestia light start \
+    --p2p.network test \
+    --core.ip localhost:26657 \
+    --node.store "$HOME/.celestia-custom-light/" \
+    --headers.trusted-peers "$PEER_ADDR/p2p/$PEER_ID" \
+    --rpc.port 42069 > light.log 2>&1 &
+LIGHT_PID=$!
+
 wait_for_service 42069 "light node"
+
+# Verify light node is still running
+if ! kill -0 $LIGHT_PID 2>/dev/null; then
+    echo "Error: Light node failed to start. Check light.log for details"
+    exit 1
+fi
📝 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
# Initialize and start light node
echo "Initializing light node..."
celestia light init \
--p2p.network test \
--core.ip localhost:26657 \
--node.store "$HOME/.celestia-custom-light/"
# Construct the light node start command
LIGHT_NODE_CMD="celestia light start \
--p2p.network test \
--core.ip localhost:26657 \
--node.store \"$HOME/.celestia-custom-light/\" \
--headers.trusted-peers \"$PEER_ADDR/p2p/$PEER_ID\" \
--rpc.port 42069"
# Log the command
echo "Starting light node with command:"
echo "$LIGHT_NODE_CMD"
# Execute the command
eval "$LIGHT_NODE_CMD" &
wait_for_service 42069 "light node"
# Initialize and start light node
echo "Initializing light node..."
celestia light init \
--p2p.network test \
--core.ip localhost:26657 \
--node.store "$HOME/.celestia-custom-light/" || {
echo "Error: Light node initialization failed"
exit 1
}
# Start light node directly without eval
echo "Starting light node..."
celestia light start \
--p2p.network test \
--core.ip localhost:26657 \
--node.store "$HOME/.celestia-custom-light/" \
--headers.trusted-peers "$PEER_ADDR/p2p/$PEER_ID" \
--rpc.port 42069 > light.log 2>&1 &
LIGHT_PID=$!
wait_for_service 42069 "light node"
# Verify light node is still running
if ! kill -0 $LIGHT_PID 2>/dev/null; then
echo "Error: Light node failed to start. Check light.log for details"
exit 1
fi

Comment on lines +38 to +49
# Clean up existing directories
rm -rf "$HOME/.celestia-custom-bridge"
rm -rf "$HOME/.celestia-custom-light"

# Create necessary directories
mkdir -p "$HOME/.celestia-custom-bridge"
mkdir -p "$HOME/.celestia-custom-light"

# Kill any existing celestia processes
pkill celestia-appd
pkill celestia
sleep 2
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve error handling and process cleanup

The current implementation could be enhanced with better error handling and cleaner process management.

+# Function to safely remove directory
+safe_remove_dir() {
+    if [ -d "$1" ]; then
+        rm -rf "$1" || {
+            echo "Error: Failed to remove directory $1"
+            exit 1
+        }
+    fi
+}
+
+# Function to safely stop process
+stop_process() {
+    if pgrep "$1" >/dev/null; then
+        pkill "$1"
+        sleep 2
+        if pgrep "$1" >/dev/null; then
+            pkill -9 "$1"  # Force kill if still running
+        fi
+    fi
+}
+
 # Clean up existing directories
-rm -rf "$HOME/.celestia-custom-bridge"
-rm -rf "$HOME/.celestia-custom-light"
+safe_remove_dir "$HOME/.celestia-custom-bridge"
+safe_remove_dir "$HOME/.celestia-custom-light"
 
 # Kill any existing celestia processes
-pkill celestia-appd
-pkill celestia
-sleep 2
+stop_process "celestia-appd"
+stop_process "celestia"
📝 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
# Clean up existing directories
rm -rf "$HOME/.celestia-custom-bridge"
rm -rf "$HOME/.celestia-custom-light"
# Create necessary directories
mkdir -p "$HOME/.celestia-custom-bridge"
mkdir -p "$HOME/.celestia-custom-light"
# Kill any existing celestia processes
pkill celestia-appd
pkill celestia
sleep 2
# Function to safely remove directory
safe_remove_dir() {
if [ -d "$1" ]; then
rm -rf "$1" || {
echo "Error: Failed to remove directory $1"
exit 1
}
fi
}
# Function to safely stop process
stop_process() {
if pgrep "$1" >/dev/null; then
pkill "$1"
sleep 2
if pgrep "$1" >/dev/null; then
pkill -9 "$1" # Force kill if still running
fi
fi
}
# Clean up existing directories
safe_remove_dir "$HOME/.celestia-custom-bridge"
safe_remove_dir "$HOME/.celestia-custom-light"
# Create necessary directories
mkdir -p "$HOME/.celestia-custom-bridge"
mkdir -p "$HOME/.celestia-custom-light"
# Kill any existing celestia processes
stop_process "celestia-appd"
stop_process "celestia"

Comment on lines +51 to +65
# Start the validator node
echo "Starting validator node..."
cd "$HOME/celestia-app/scripts" || exit 1

# Automatically answer "y" to the prompt
echo "y" | bash single-node.sh &
wait_for_service 26657 "validator node"

# Get the genesis block hash
echo "Getting genesis block hash..."
BLOCK_HASH=$(curl -s "localhost:26657/block?height=1" | jq -r '.result.block_id.hash')
if [ -z "$BLOCK_HASH" ]; then
echo "Error: Could not get block hash"
exit 1
fi
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Improve validator setup reliability

The current implementation has several potential points of failure that should be addressed.

 # Start the validator node
 echo "Starting validator node..."
-cd "$HOME/celestia-app/scripts" || exit 1
+SCRIPT_PATH="$HOME/celestia-app/scripts/single-node.sh"
+if [ ! -f "$SCRIPT_PATH" ]; then
+    echo "Error: single-node.sh not found at $SCRIPT_PATH"
+    exit 1
+fi
 
 # Automatically answer "y" to the prompt
-echo "y" | bash single-node.sh &
+TMPFILE=$(mktemp)
+trap 'rm -f $TMPFILE' EXIT
+expect << EOF
+spawn bash $SCRIPT_PATH
+expect "Do you want to proceed? (y/n):"
+send "y\r"
+expect eof
+EOF
 wait_for_service 26657 "validator node"
 
 # Get the genesis block hash
 echo "Getting genesis block hash..."
-BLOCK_HASH=$(curl -s "localhost:26657/block?height=1" | jq -r '.result.block_id.hash')
+BLOCK_HASH=$(curl -s --max-time 10 "localhost:26657/block?height=1" | jq -r '.result.block_id.hash')
 if [ -z "$BLOCK_HASH" ]; then
     echo "Error: Could not get block hash"
     exit 1
 fi

Note: This change requires the expect utility. Please add it to the command check list:

 check_command "celestia-appd"
 check_command "celestia"
 check_command "jq"
 check_command "nc"
+check_command "expect"

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +71 to +96
# Initialize and start bridge node
echo "Initializing bridge node..."
celestia bridge init \
--node.store "$HOME/.celestia-custom-bridge" \
--core.ip localhost \
--core.grpc.port 9090 \
--core.rpc.port 26657 \
--p2p.network test
echo "Starting bridge node..."
celestia bridge start \
--node.store "$HOME/.celestia-custom-bridge" \
--core.ip localhost \
--core.grpc.port 9090 \
--core.rpc.port 26657 \
--p2p.network test &
wait_for_service 2121 "bridge node"

# Get bridge node info
echo "Getting bridge node peer info..."
BRIDGE_INFO=$(celestia p2p info --node.store "$HOME/.celestia-custom-bridge")
PEER_ID=$(echo "$BRIDGE_INFO" | jq -r '.result.id')
PEER_ADDR=$(echo "$BRIDGE_INFO" | jq -r '.result.peer_addr[] | select(contains("/ip4/10.0.0.125") and contains("/udp/") and contains("/webrtc-direct/"))' | head -n 1)
if [ -z "$PEER_ID" ] || [ -z "$PEER_ADDR" ]; then
echo "Error: Could not get peer information"
exit 1
fi
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Enhance bridge node setup reliability

The bridge node setup needs better error handling and more robust peer address selection.

+# Function to verify bridge node initialization
+verify_bridge_init() {
+    local store_path="$1"
+    if [ ! -d "$store_path/keys" ] || [ ! -f "$store_path/config.toml" ]; then
+        echo "Error: Bridge node initialization failed"
+        exit 1
+    fi
+}
+
 # Initialize and start bridge node
 echo "Initializing bridge node..."
 celestia bridge init \
     --node.store "$HOME/.celestia-custom-bridge" \
     --core.ip localhost \
     --core.grpc.port 9090 \
     --core.rpc.port 26657 \
-    --p2p.network test
+    --p2p.network test || exit 1
+
+verify_bridge_init "$HOME/.celestia-custom-bridge"
+
 echo "Starting bridge node..."
 celestia bridge start \
     --node.store "$HOME/.celestia-custom-bridge" \
     --core.ip localhost \
     --core.grpc.port 9090 \
     --core.rpc.port 26657 \
-    --p2p.network test &
+    --p2p.network test > bridge.log 2>&1 &
+BRIDGE_PID=$!
+
 wait_for_service 2121 "bridge node"
 
+# Verify bridge node is still running
+if ! kill -0 $BRIDGE_PID 2>/dev/null; then
+    echo "Error: Bridge node failed to start. Check bridge.log for details"
+    exit 1
+fi
+
 # Get bridge node info
 echo "Getting bridge node peer info..."
-BRIDGE_INFO=$(celestia p2p info --node.store "$HOME/.celestia-custom-bridge")
+BRIDGE_INFO=$(celestia p2p info --node.store "$HOME/.celestia-custom-bridge") || {
+    echo "Error: Failed to get bridge node info"
+    exit 1
+}
+
-PEER_ADDR=$(echo "$BRIDGE_INFO" | jq -r '.result.peer_addr[] | select(contains("/ip4/10.0.0.125") and contains("/udp/") and contains("/webrtc-direct/"))' | head -n 1)
+# More robust peer address selection
+PEER_ADDR=$(echo "$BRIDGE_INFO" | jq -r '.result.peer_addr[] | 
+    select(contains("/ip4/") and (contains("/tcp/") or contains("/udp/")))' | head -n 1)
📝 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
# Initialize and start bridge node
echo "Initializing bridge node..."
celestia bridge init \
--node.store "$HOME/.celestia-custom-bridge" \
--core.ip localhost \
--core.grpc.port 9090 \
--core.rpc.port 26657 \
--p2p.network test
echo "Starting bridge node..."
celestia bridge start \
--node.store "$HOME/.celestia-custom-bridge" \
--core.ip localhost \
--core.grpc.port 9090 \
--core.rpc.port 26657 \
--p2p.network test &
wait_for_service 2121 "bridge node"
# Get bridge node info
echo "Getting bridge node peer info..."
BRIDGE_INFO=$(celestia p2p info --node.store "$HOME/.celestia-custom-bridge")
PEER_ID=$(echo "$BRIDGE_INFO" | jq -r '.result.id')
PEER_ADDR=$(echo "$BRIDGE_INFO" | jq -r '.result.peer_addr[] | select(contains("/ip4/10.0.0.125") and contains("/udp/") and contains("/webrtc-direct/"))' | head -n 1)
if [ -z "$PEER_ID" ] || [ -z "$PEER_ADDR" ]; then
echo "Error: Could not get peer information"
exit 1
fi
# Function to verify bridge node initialization
verify_bridge_init() {
local store_path="$1"
if [ ! -d "$store_path/keys" ] || [ ! -f "$store_path/config.toml" ]; then
echo "Error: Bridge node initialization failed"
exit 1
fi
}
# Initialize and start bridge node
echo "Initializing bridge node..."
celestia bridge init \
--node.store "$HOME/.celestia-custom-bridge" \
--core.ip localhost \
--core.grpc.port 9090 \
--core.rpc.port 26657 \
--p2p.network test || exit 1
verify_bridge_init "$HOME/.celestia-custom-bridge"
echo "Starting bridge node..."
celestia bridge start \
--node.store "$HOME/.celestia-custom-bridge" \
--core.ip localhost \
--core.grpc.port 9090 \
--core.rpc.port 26657 \
--p2p.network test > bridge.log 2>&1 &
BRIDGE_PID=$!
wait_for_service 2121 "bridge node"
# Verify bridge node is still running
if ! kill -0 $BRIDGE_PID 2>/dev/null; then
echo "Error: Bridge node failed to start. Check bridge.log for details"
exit 1
fi
# Get bridge node info
echo "Getting bridge node peer info..."
BRIDGE_INFO=$(celestia p2p info --node.store "$HOME/.celestia-custom-bridge") || {
echo "Error: Failed to get bridge node info"
exit 1
}
PEER_ID=$(echo "$BRIDGE_INFO" | jq -r '.result.id')
# More robust peer address selection
PEER_ADDR=$(echo "$BRIDGE_INFO" | jq -r '.result.peer_addr[] |
select(contains("/ip4/") and (contains("/tcp/") or contains("/udp/")))' | head -n 1)
if [ -z "$PEER_ID" ] || [ -z "$PEER_ADDR" ]; then
echo "Error: Could not get peer information"
exit 1
fi

@celestiaorg celestiaorg deleted a comment from coderabbitai bot Nov 28, 2024
@jcstein jcstein marked this pull request as draft November 28, 2024 14:12
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: 0

🧹 Outside diff range and nitpick comments (4)
how-to-guides/local-testnet.md (4)

7-10: Enhance prerequisites section with installation links

Consider adding links to installation guides for each prerequisite:

  • Link to jq installation guide
  • Link to nc (netcat) installation guide
  • Add version requirements for jq and nc

48-50: Improve environment variable handling

Consider adding:

  1. Instructions for persisting the environment variable in shell configuration files
  2. Verification step to confirm the variable is set correctly
  3. Troubleshooting steps if the genesis hash is incorrect

118-125: Improve light node configuration clarity

The light node startup command needs improvements:

  1. Explain the choice of port 42069 and whether it can be customized
  2. Consider using environment variables for peer info to avoid long command lines
  3. Add validation steps to confirm successful connection to the bridge node

42-44: Add language specification to code block

Add a language specification to the fenced code block:

-```
+```text
 1D53B32ACB02563E425BA1F8B5178B06A748E0F7B9748A8B1D07C34B454AF595

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 Markdownlint (0.35.0)</summary>

42-42: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

</details>

</details>

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 4fc655299d579a2da38c2f21514d7fda186603f4 and 6b8a280f26550e932fd9b7e207f5eacc3f23d30b.

</details>

<details>
<summary>📒 Files selected for processing (1)</summary>

* `how-to-guides/local-testnet.md` (1 hunks)

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🪛 Markdownlint (0.35.0)</summary>

<details>
<summary>how-to-guides/local-testnet.md</summary>

42-42: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

</details>

</details>

</details>

<details>
<summary>🔇 Additional comments (3)</summary>

<details>
<summary>how-to-guides/local-testnet.md (3)</summary>

`28-31`: **Add validation steps for successful node startup**

The validator node setup instructions need more detail about success indicators.


Previous review comment still applies regarding:
1. Expected output
2. Validation commands
3. Troubleshooting steps

---

`16-18`: _:warning: Potential issue_

**Add security advisory for script execution**

The current curl-to-bash execution method should include security precautions.


Previous review comment still applies regarding:
1. Adding a warning to inspect scripts before execution
2. Providing SHA256 checksum verification
3. Adding direct link to view script content

---

`144-144`: _:hammer_and_wrench: Refactor suggestion_

**Document address usage and parameters**

The funding command uses hardcoded values that need documentation.


Previous review comment still applies regarding:
1. Replacing hardcoded address with placeholder
2. Explaining address format
3. Adding instructions for obtaining correct addresses

</details>

</details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

feat: add local testnet guide

docs: add to sidebar

feat: mvp of script for local testnet

feat: mvp of script for local testnet

docs: updates
@jcstein jcstein force-pushed the jcs/add-local-testnet-guide branch from 6b8a280 to b4bac15 Compare November 28, 2024 14:16
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.

docs: write local testnet guide
1 participant