Skip to content

Eliminate mainnet/testnet script duplication, standardize API config, add shellcheck CI, fix typos#106

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/refactor-mainnet-testnet-scripts
Draft

Eliminate mainnet/testnet script duplication, standardize API config, add shellcheck CI, fix typos#106
Copilot wants to merge 2 commits intomainfrom
copilot/refactor-mainnet-testnet-scripts

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 1, 2026

chains/update-validator-mainnet.sh and chains/update-validator-testnet.sh were 95% identical (only VM_ID/SUBNET_ID differed), install-subnet-cli.sh existed in two identical copies, all API scripts had inconsistent URL sourcing, and node IDs were hardcoded inline.

Validator scripts

  • Created chains/update-validator.sh — unified script accepting --network mainnet|testnet; sets network-specific VM_ID/SUBNET_ID from a single source of truth. Added set -euo pipefail.
  • Replaced update-validator-mainnet.sh / update-validator-testnet.sh with thin wrappers that exec the unified script — backward compatible.
  • Fixed typo: download_sunbet_evm()download_subnet_evm()
# Before: two 67-line near-identical files
# After:
exec "${SCRIPT_DIR}/update-validator.sh" --network mainnet "$@"

install-subnet-cli.sh deduplication

  • Removed chains/install-subnet-cli.sh; canonical copy lives in subnet-cli/. Added missing #!/bin/bash shebang.

API script standardization

  • All 13 API scripts now source env.sh for $URL — no more hardcoded 127.0.0.1:9650.
  • Added # shellcheck source=env.sh directives and properly quoted all "${URL}" usages.
  • Extracted hardcoded node IDs from info.peers.sh into api/peers.conf (SNOW_NODE_IDS, JADE_NODE_IDS as JSON arrays).

Shell linting CI

  • Added .github/workflows/shellcheck.yml running shellcheck --severity=error -x on all .sh files.
  • Added # shellcheck shell=bash to api/env.sh to resolve SC2148; # shellcheck source= directives across sourcing scripts.
Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature][Medium] Eliminate mainnet/testnet code duplication, add shell linting, and fix typos</issue_title>
<issue_description>## Summary

Significant code duplication and quality gaps increase maintenance burden and risk of divergence between mainnet and testnet configurations.

Findings

1. 95% Code Duplication Between Mainnet/Testnet Scripts

  • Files: chains/update-validator-mainnet.sh (67 lines) vs chains/update-validator-testnet.sh (67 lines)
  • Issue: The two scripts are nearly identical — only VM_ID and SUBNET_ID differ (lines 7-8). Any bug fix must be applied to both files.
  • Recommendation: Refactor into a single update-validator.sh that accepts --network mainnet|testnet parameter and reads environment-specific values from a config file.

2. Duplicate install-subnet-cli.sh

  • Files: chains/install-subnet-cli.sh and subnet-cli/install-subnet-cli.sh are identical (25 lines each)
  • Issue: Two copies of the same script; changes to one may not be reflected in the other.
  • Recommendation: Keep one canonical location and symlink or remove the duplicate.

3. Typo in Function Name

  • Files: chains/update-validator-mainnet.sh (line 18), chains/update-validator-testnet.sh (line 18)
  • Issue: Function named download_sunbet_evm() instead of download_subnet_evm().
  • Recommendation: Rename to download_subnet_evm().

4. No Shell Script Linting

5. Inconsistent API Script Patterns

  • Location: api/ directory
  • Issue: Some scripts source env.sh for the URL, while others hardcode 127.0.0.1:9650. This inconsistency makes endpoint management difficult.
  • Recommendation: Standardize all scripts to use env.sh or a shared configuration mechanism.

6. Hardcoded Node IDs

  • File: api/info.peers.sh (lines 10-16, 27-28)
  • Issue: Node IDs are hardcoded in the script rather than loaded from a configuration file.
  • Recommendation: Move node IDs to a config file that can be updated without modifying the script.

Suggested Approach

  1. Create a shared lib/ directory with common functions and config loading
  2. Refactor mainnet/testnet scripts to use a single parameterized script
  3. Add shellcheck to CI
  4. Fix the function name typo
  5. Standardize API scripts to use env.sh

Generated by Health Monitor with Omni</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…po and inconsistencies

Co-authored-by: numbers-official <181934381+numbers-official@users.noreply.github.com>
Copilot AI changed the title [WIP] Eliminate mainnet/testnet code duplication and fix typos Eliminate mainnet/testnet script duplication, standardize API config, add shellcheck CI, fix typos Mar 1, 2026
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.

[Feature][Medium] Eliminate mainnet/testnet code duplication, add shell linting, and fix typos

2 participants