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

chore: set lower tally params for localnet #3067

Merged
merged 1 commit into from
Oct 30, 2024

Conversation

gartnera
Copy link
Member

@gartnera gartnera commented Oct 29, 2024

Description

This will allow for running upgrade tests with more than two nodes. I want to do this in developnet (performance tests + automated upgrades).

image

References:

How Has This Been Tested?

  • Tested CCTX in localnet
  • Tested in development environment
  • Go unit tests
  • Go integration tests
  • Tested via GitHub Actions

Summary by CodeRabbit

  • New Features

    • Enhanced governance configuration for localnet with updated voting parameters: quorum and threshold.
    • Streamlined governance parameter updates in the genesis file for improved efficiency.
  • Documentation

    • Updated comments for better clarity on genesis creation and SSH key handling.

@gartnera gartnera added no-changelog Skip changelog CI check UPGRADE_LIGHT_TESTS Run make start-upgrade-test-light labels Oct 29, 2024
Copy link
Contributor

coderabbitai bot commented Oct 29, 2024

📝 Walkthrough

Walkthrough

The pull request introduces modifications to the start-zetacored.sh script, focusing on governance parameters and genesis file creation. It enhances the governance configuration by adding quorum and threshold parameters, both set to 0.1, and streamlines the update process using a single jq command. The script retains its logic for checking the init_complete file and updates comments for clarity. Overall, the changes aim to improve localnet operations without altering exported or public entity declarations.

Changes

File Path Change Summary
contrib/localnet/scripts/start-zetacored.sh Enhanced governance parameters with quorum and threshold, streamlined updates using jq, and clarified comments regarding genesis creation and SSH key handling.

Possibly related PRs

Suggested reviewers

  • fbac
  • kingpinXD
  • ws4charlie
  • brewmaster012
  • skosito
  • lumtis
  • swift1337

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.

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

@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)
contrib/localnet/scripts/start-zetacored.sh (4)

Line range hint 39-52: Enhance SSH key generation security and error handling.

The current SSH key setup has several security and reliability concerns:

  1. Keys are generated with empty passphrase
  2. No validation of key copying
  3. Missing error handling for SSH operations

Consider implementing these security improvements:

 if [ $HOSTNAME == "zetacore0" ]; then
   if [[ ! -f ~/.ssh/id_rsa ]]; then
-    ssh-keygen -t rsa -q -N "" -f ~/.ssh/id_rsa
-    cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
-    # keep localtest.pem for compatibility
-    cp ~/.ssh/id_rsa ~/.ssh/localtest.pem
-    chmod 600 ~/.ssh/*
+    if ! ssh-keygen -t ed25519 -q -N "" -f ~/.ssh/id_rsa; then
+      echo "Failed to generate SSH key" >&2
+      exit 1
+    fi
+    if ! cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys; then
+      echo "Failed to copy public key to authorized_keys" >&2
+      exit 1
+    fi
+    # keep localtest.pem for compatibility
+    if ! cp ~/.ssh/id_rsa ~/.ssh/localtest.pem; then
+      echo "Failed to copy private key to localtest.pem" >&2
+      exit 1
+    fi
+    chmod 600 ~/.ssh/id_rsa ~/.ssh/localtest.pem
+    chmod 644 ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
   fi
 fi

Line range hint 65-294: Improve maintainability by modularizing genesis creation steps.

The genesis creation logic is complex and would benefit from being broken down into functions for better maintainability and testing.

Consider restructuring the code into functions:

+# Initialize node configuration
+init_node_config() {
+  mkdir -p ~/.backup/config
+  zetacored init Zetanode-Localnet --chain-id=$CHAINID
+  rm -rf ~/.zetacored/config/{app,client,config}.toml
+  cp -r ~/zetacored/common/{app,client,config}.toml ~/.zetacored/config/
+  sed -i -e "/moniker =/s/=.*/= \"$HOSTNAME\"/" "$HOME"/.zetacored/config/config.toml
+}
+
+# Collect observer information from nodes
+collect_observer_info() {
+  for NODE in "${NODELIST[@]}"; do
+    INDEX=${NODE:0-1}
+    ssh zetaclient"$INDEX" mkdir -p ~/.zetacored/
+    while ! scp "$NODE":~/.zetacored/os_info/os.json ~/.zetacored/os_info/os_z"$INDEX".json; do
+      echo "Waiting for os_info.json from node $NODE"
+      sleep 1
+    done
+    scp ~/.zetacored/os_info/os_z"$INDEX".json zetaclient"$INDEX":~/.zetacored/os.json
+  done
+}

Then use these functions in the main flow:

if [[ $HOSTNAME == "zetacore0" && ! -f ~/.zetacored/init_complete ]]; then
  init_node_config
  collect_observer_info
  # ... rest of the logic
fi

296-301: LGTM! Consider optimizing the jq commands.

The governance parameter updates align well with the PR objectives, enabling upgrade tests with more than two nodes by setting appropriate quorum and threshold values.

Consider combining all governance-related jq operations into a single command for better performance:

-  jq '.app_state["gov"]["params"]["voting_period"]="100s" |
-    .app_state["gov"]["params"]["quorum"]="0.1" |
-    .app_state["gov"]["params"]["threshold"]="0.1"' \
-  $HOME/.zetacored/config/genesis.json > tmp.json && mv tmp.json $HOME/.zetacored/config/genesis.json
+  jq '.app_state.gov.params |= . + {
+    "voting_period": "100s",
+    "quorum": "0.1",
+    "threshold": "0.1"
+  }' $HOME/.zetacored/config/genesis.json > tmp.json && mv tmp.json $HOME/.zetacored/config/genesis.json

Line range hint 303-359: Enhance account setup with better balance management and reduced repetition.

The current implementation has several areas for improvement:

  1. Extremely large initial balances might pose risks
  2. Repetitive account funding code reduces maintainability

Consider implementing these improvements:

+# Define a reasonable initial balance
+INITIAL_BALANCE="1000000000000000000000azeta"  # 1000 ZETA
+
+# Function to add account with balance
+add_account_with_balance() {
+  local address=$1
+  local balance=${2:-$INITIAL_BALANCE}
+  if ! zetacored add-genesis-account "$address" "$balance"; then
+    echo "Failed to add genesis account: $address" >&2
+    return 1
+  fi
+}
+
+# Read and fund accounts from config
+fund_accounts() {
+  local accounts=(
+    "default_account"
+    "additional_accounts.user_erc20"
+    "additional_accounts.user_zeta_test"
+    # ... add other accounts
+  )
+
+  for account in "${accounts[@]}"; do
+    address=$(yq -r ".$account.bech32_address" /root/config.yml)
+    add_account_with_balance "$address"
+  done
+}

Then use this function instead of repetitive code:

fund_accounts
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between df8b0e8 and 1353801.

📒 Files selected for processing (1)
  • contrib/localnet/scripts/start-zetacored.sh (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
contrib/localnet/scripts/start-zetacored.sh (1)

Pattern **/*.sh: Review the shell scripts, point out issues relative to security, performance, and maintainability.

@lumtis lumtis added this pull request to the merge queue Oct 30, 2024
Merged via the queue into develop with commit 04d2b3a Oct 30, 2024
37 checks passed
@lumtis lumtis deleted the localnet-lower-tally-params branch October 30, 2024 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog Skip changelog CI check UPGRADE_LIGHT_TESTS Run make start-upgrade-test-light
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants