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

Build testnet validator images #2049

Merged
merged 1 commit into from
Aug 7, 2024
Merged

Build testnet validator images #2049

merged 1 commit into from
Aug 7, 2024

Conversation

roy-dydx
Copy link
Contributor

@roy-dydx roy-dydx commented Aug 6, 2024

Changelist

Build testnet validator images on push and PR to release branches. Makes testnet deploys easier.

Test Plan

Built and tried image on on release branch.

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If the PR has breaking postgres changes to the indexer add the indexer-postgres-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

Summary by CodeRabbit

  • New Features

    • Introduced a new GitHub Actions workflow for building and pushing Docker images to AWS ECR for the testnet protocol.
    • Added several scripts to streamline the setup and management of testnet environments, including automation for starting nodes and creating snapshots.
  • Bug Fixes

    • Enhanced error handling in script execution to improve reliability during node management tasks.
  • Documentation

    • Added comments and usage instructions in scripts to facilitate user understanding and ease of use.

Copy link
Contributor

coderabbitai bot commented Aug 6, 2024

Walkthrough

This update introduces a comprehensive setup for testing the DYDX protocol on a testnet. Key changes include a new GitHub Actions workflow for automated Docker image builds and deployments, along with several scripts for managing blockchain nodes. These scripts enhance the efficiency of initializing, operating, and snapshotting nodes, streamlining the testing process in a cloud environment.

Changes

Files Change Summary
.github/workflows/protocol-build-and-push-testnet.yml New workflow for building and pushing Docker images to AWS ECR for the DYDX testnet.
protocol/testing/testnet/Dockerfile, protocol/testing/testnet/testnet.sh New Dockerfile and testnet setup script for configuring testnet environments and managing node directories.
protocol/testing/testnet/snapshot.sh, protocol/testing/testnet/start.sh New scripts for snapshotting blockchain data and starting validator/full-node instances with CosmosVisor.
protocol/testing/testnet/vars.sh New script for setting environment variables and configurations for validators in the testnet setup.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant GitHub Actions
    participant AWS ECR
    participant Docker
    participant Testnet Scripts

    User->>GitHub Actions: Trigger workflow on push or PR
    GitHub Actions->>Docker: Build Docker image
    Docker->>GitHub Actions: Image built successfully
    GitHub Actions->>AWS ECR: Push Docker image
    AWS ECR->>GitHub Actions: Image pushed
    GitHub Actions->>Testnet Scripts: Execute setup scripts
    Testnet Scripts->>User: Testnet environment ready
Loading

Poem

In the garden of code, we hop and play,
With Docker and scripts, we pave the way.
Testnet's a playground, our happy zone,
Building and pushing, we're never alone.
🐇✨ Let’s dance with the bits, in a joyful array!


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

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: 5

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2afb412 and a1cec37.

Files selected for processing (6)
  • .github/workflows/protocol-build-and-push-testnet.yml (1 hunks)
  • protocol/testing/testnet/Dockerfile (1 hunks)
  • protocol/testing/testnet/snapshot.sh (1 hunks)
  • protocol/testing/testnet/start.sh (1 hunks)
  • protocol/testing/testnet/testnet.sh (1 hunks)
  • protocol/testing/testnet/vars.sh (1 hunks)
Additional context used
Shellcheck
protocol/testing/testnet/vars.sh

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

(SC2034)


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

(SC2034)


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

(SC2034)

protocol/testing/testnet/snapshot.sh

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

(SC2034)


[warning] 85-85: p2p_seeds is referenced but not assigned.

(SC2154)


[warning] 85-85: dd_agent_host is referenced but not assigned.

(SC2154)


[warning] 87-87: upload_period is referenced but not assigned.

(SC2154)


[warning] 88-88: Quote this to prevent word splitting.

(SC2046)


[warning] 92-92: s3_snapshot_bucket is referenced but not assigned.

(SC2154)


[warning] 93-93: Use "${var:?}" to ensure this never expands to / .

(SC2115)

Additional comments not posted (25)
protocol/testing/testnet/Dockerfile (7)

1-1: LGTM! Base image usage is appropriate.

The base image dydxprotocol-base is appropriate for this context.


3-3: LGTM! Package installations are necessary.

The packages bash, jq, and aws-cli are necessary for the script operations.


4-4: LGTM! cosmovisor installation command is correct.

The command go install cosmossdk.io/tools/cosmovisor/cmd/cosmovisor@v1.5.0 is correct for installing cosmovisor.


6-6: LGTM! Copy command is correct and necessary.

The command COPY ./testing/testnet/. /dydxprotocol/ is correct for copying necessary files.


8-9: LGTM! Environment variable and working directory setup are correct.

The environment variable HOME and working directory $HOME are set correctly.


11-11: LGTM! Script execution is necessary.

The command RUN /dydxprotocol/testnet.sh is necessary for setting up the testnet.


13-13: LGTM! Entry point setup is correct.

The entry point ENTRYPOINT ["/dydxprotocol/start.sh"] is correctly set.

protocol/testing/testnet/vars.sh (4)

1-2: LGTM! Shebang and error handling setup are correct.

The shebang #!/bin/bash and set -eo pipefail are correctly set.


4-4: Verify the usage of CURRENT_VERSION_DIR.

The variable CURRENT_VERSION_DIR is defined but not used in this file. Verify its usage in the codebase.

Verification successful

The variable CURRENT_VERSION_DIR is used in the codebase.

The variable CURRENT_VERSION_DIR defined in protocol/testing/testnet/vars.sh is utilized in the following files:

  • protocol/testing/testnet/testnet.sh
  • protocol/testing/mainnet/mainnet.sh
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `CURRENT_VERSION_DIR` in the codebase.

# Test: Search for the variable usage. Expect: Occurrences of `CURRENT_VERSION_DIR`.
rg --type shell -A 5 $'CURRENT_VERSION_DIR'

Length of output: 72


Script:

#!/bin/bash
# Description: Verify the usage of `CURRENT_VERSION_DIR` in the codebase.

# Test: Search for the variable usage. Expect: Occurrences of `CURRENT_VERSION_DIR`.
rg -A 5 $'CURRENT_VERSION_DIR'

Length of output: 1528

Tools
Shellcheck

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

(SC2034)


7-7: Verify the usage of LAST_FULL_NODE_INDEX.

The variable LAST_FULL_NODE_INDEX is defined but not used in this file. Verify its usage in the codebase.

Verification successful

Verified usage of LAST_FULL_NODE_INDEX.

The variable LAST_FULL_NODE_INDEX is used in multiple shell scripts within the codebase, confirming its necessity.

  • protocol/testing/testnet/testnet.sh
  • protocol/testing/testnet/start.sh
  • protocol/testing/testnet/vars.sh
  • protocol/testing/mainnet/start.sh
  • protocol/testing/mainnet/vars.sh
  • protocol/testing/testnet/snapshot.sh
  • protocol/testing/mainnet/mainnet.sh
  • protocol/testing/mainnet/snapshot.sh
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `LAST_FULL_NODE_INDEX` in the codebase.

# Test: Search for the variable usage. Expect: Occurrences of `LAST_FULL_NODE_INDEX`.
rg --type shell -A 5 $'LAST_FULL_NODE_INDEX'

Length of output: 73


Script:

#!/bin/bash
# Description: Verify the usage of `LAST_FULL_NODE_INDEX` in the codebase.

# Test: Search for the variable usage in all shell script files. Expect: Occurrences of `LAST_FULL_NODE_INDEX`.
rg 'LAST_FULL_NODE_INDEX' --glob '*.sh' -A 5

Length of output: 4713

Tools
Shellcheck

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

(SC2034)


11-14: Verify the usage of MONIKERS.

The array MONIKERS is defined but not used in this file. Verify its usage in the codebase.

Verification successful

The MONIKERS array is correctly defined and used extensively across multiple scripts in the codebase.

  • protocol/testing/testnet/testnet.sh
  • protocol/testing/testnet/start.sh
  • protocol/testing/testnet-staging/staging.sh
  • protocol/testing/testnet-local/local.sh
  • protocol/testing/testnet-external/pregenesis.sh
  • protocol/testing/testnet-dev/dev.sh
  • protocol/testing/e2etest-local/local.sh
  • protocol/testing/containertest/containertest.sh
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `MONIKERS` in the codebase.

# Test: Search for the array usage. Expect: Occurrences of `MONIKERS`.
rg --type shell -A 5 $'MONIKERS'

Length of output: 61


Script:

#!/bin/bash
# Description: Verify the usage of `MONIKERS` in the codebase.

# Test: Search for the array usage. Expect: Occurrences of `MONIKERS`.
rg MONIKERS

Length of output: 7931

Tools
Shellcheck

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

(SC2034)

protocol/testing/testnet/start.sh (6)

1-2: LGTM! Shebang and error handling setup are correct.

The shebang #!/bin/bash and set -eo pipefail are correctly set.


4-7: LGTM! Comments are clear and accurate.

The comments explaining the script's purpose and usage are clear and accurate.


9-9: LGTM! Source command is correct and necessary.

The command source "./vars.sh" is correct for sourcing the necessary variables.


11-17: LGTM! CosmosVisor setup for validators is correct.

The commands for setting up CosmosVisor for validators are correct and necessary.


19-25: LGTM! CosmosVisor setup for full-nodes is correct.

The commands for setting up CosmosVisor for full-nodes are correct and necessary.


27-27: LGTM! Command execution is correct and necessary.

The command cosmovisor "$@" is correct for running cosmovisor with the provided arguments.

.github/workflows/protocol-build-and-push-testnet.yml (4)

1-11: Workflow name and trigger conditions look good.

The workflow name is clear and the branch patterns are correctly defined to match release branches.


13-19: Job definition and environment setup look good.

The job is appropriately defined to run on ubuntu-latest with the correct working directory.


20-30: Steps for checking out the code and configuring AWS credentials look good.

The steps are correctly defined and use the appropriate actions.


32-49: Steps for logging into Amazon ECR and handling the Docker image look good.

The steps are correctly defined and use the appropriate actions and commands.

protocol/testing/testnet/snapshot.sh (2)

1-23: Script header and usage information look good.

The script header and usage information are clear and informative.


25-46: Verify the presence of the vars.sh file.

The script assumes the presence of the vars.sh file in the same directory. Ensure that this file exists and is correctly configured.

protocol/testing/testnet/testnet.sh (2)

1-19: Script header and prerequisites installation look good.

The script header and prerequisites installation are clear and correctly defined.


124-131: Function for configuring seed nodes looks good.

The function is correctly defined to enable seed mode for a seed node.

Comment on lines +48 to +55
# local path to temporary snapshots. snapshots are deleted after uploading to S3.
SNAP_PATH="/dydxprotocol/chain/.full-node-0/snapshots/dydxprotocol/"
# logfile containing snapshot timestamps
LOG_PATH="/dydxprotocol/chain/.full-node-0/snapshots/dydxprotocol/dydxprotocol_log.txt"
# data directory to snapshot. this contains the blockchain state.
DATA_PATH="/dydxprotocol/chain/.full-node-0/data/"
RPC_ADDRESS="http://127.0.0.1:26657"

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the unused RPC_ADDRESS variable.

The RPC_ADDRESS variable is declared but not used in the script.

- RPC_ADDRESS="http://127.0.0.1:26657"
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
# local path to temporary snapshots. snapshots are deleted after uploading to S3.
SNAP_PATH="/dydxprotocol/chain/.full-node-0/snapshots/dydxprotocol/"
# logfile containing snapshot timestamps
LOG_PATH="/dydxprotocol/chain/.full-node-0/snapshots/dydxprotocol/dydxprotocol_log.txt"
# data directory to snapshot. this contains the blockchain state.
DATA_PATH="/dydxprotocol/chain/.full-node-0/data/"
RPC_ADDRESS="http://127.0.0.1:26657"
# local path to temporary snapshots. snapshots are deleted after uploading to S3.
SNAP_PATH="/dydxprotocol/chain/.full-node-0/snapshots/dydxprotocol/"
# logfile containing snapshot timestamps
LOG_PATH="/dydxprotocol/chain/.full-node-0/snapshots/dydxprotocol/dydxprotocol_log.txt"
# data directory to snapshot. this contains the blockchain state.
DATA_PATH="/dydxprotocol/chain/.full-node-0/data/"
Tools
Shellcheck

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

(SC2034)

Comment on lines +56 to +64
while [ $# -gt 0 ]; do

if [[ $1 == *"--"* ]]; then
v="${1/--/}"
export $v="$2"
fi

shift
done
Copy link
Contributor

Choose a reason for hiding this comment

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

Add validation for required arguments.

The script does not handle cases where required arguments are missing. Add validation to ensure that all required arguments are provided.

while [ $# -gt 0 ]; do
  if [[ $1 == *"--"* ]]; then
    v="${1/--/}"
    export $v="$2"
  fi
  shift
done

# Validate required arguments
if [ -z "$genesis_file_rpc_address" ] || [ -z "$p2p_seeds" ] || [ -z "$upload_period" ] || [ -z "$s3_snapshot_bucket" ]; then
  echo "Error: Missing required arguments."
  display_usage
  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
while [ $# -gt 0 ]; do
if [[ $1 == *"--"* ]]; then
v="${1/--/}"
export $v="$2"
fi
shift
done
while [ $# -gt 0 ]; do
if [[ $1 == *"--"* ]]; then
v="${1/--/}"
export $v="$2"
fi
shift
done
# Validate required arguments
if [ -z "$genesis_file_rpc_address" ] || [ -z "$p2p_seeds" ] || [ -z "$upload_period" ] || [ -z "$s3_snapshot_bucket" ]; then
echo "Error: Missing required arguments."
display_usage
exit 1
fi

Comment on lines +82 to +95
# TODO: add metrics around snapshot upload latency/frequency/success rate
while true; do
# p2p.seeds taken from --p2p.persistent_peers flag of full node
cosmovisor run start --log_level info --home /dydxprotocol/chain/.full-node-0 --p2p.seeds "${p2p_seeds}" --non-validating-full-node=true --dd-agent-host=${dd_agent_host} &

sleep ${upload_period}
kill -TERM $(pidof cosmovisor)

SNAP_NAME=$(echo "${CHAIN_ID}_$(date '+%Y-%m-%d-%H-%M').tar.gz")
tar cvzf ${SNAP_PATH}/${SNAP_NAME} ${DATA_PATH}
aws s3 cp ${SNAP_PATH}/${SNAP_NAME} s3://${s3_snapshot_bucket}/ --region ap-northeast-1 --debug || true
rm -rf ${SNAP_PATH}/${SNAP_NAME}

done
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix unassigned variables and improve command safety.

The cosmovisor command uses unassigned variables, the kill command should quote the process ID to prevent word splitting, and the rm command should ensure it never expands to /.

-  cosmovisor run start --log_level info --home /dydxprotocol/chain/.full-node-0 --p2p.seeds "${p2p_seeds}" --non-validating-full-node=true --dd-agent-host=${dd_agent_host} &
+  cosmovisor run start --log_level info --home /dydxprotocol/chain/.full-node-0 --p2p.seeds "${p2p_seeds:?}" --non-validating-full-node=true --dd-agent-host=${dd_agent_host:?} &

  sleep ${upload_period}
-  kill -TERM $(pidof cosmovisor)
+  kill -TERM "$(pidof cosmovisor)"

  SNAP_NAME=$(echo "${CHAIN_ID}_$(date '+%Y-%m-%d-%H-%M').tar.gz")
  tar cvzf ${SNAP_PATH}/${SNAP_NAME} ${DATA_PATH}
-  aws s3 cp ${SNAP_PATH}/${SNAP_NAME} s3://${s3_snapshot_bucket}/ --region ap-northeast-1 --debug || true
-  rm -rf ${SNAP_PATH}/${SNAP_NAME}
+  aws s3 cp ${SNAP_PATH}/${SNAP_NAME:?} s3://${s3_snapshot_bucket:?}/ --region ap-northeast-1 --debug || true
+  rm -rf ${SNAP_PATH:?}/${SNAP_NAME:?}
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
# TODO: add metrics around snapshot upload latency/frequency/success rate
while true; do
# p2p.seeds taken from --p2p.persistent_peers flag of full node
cosmovisor run start --log_level info --home /dydxprotocol/chain/.full-node-0 --p2p.seeds "${p2p_seeds}" --non-validating-full-node=true --dd-agent-host=${dd_agent_host} &
sleep ${upload_period}
kill -TERM $(pidof cosmovisor)
SNAP_NAME=$(echo "${CHAIN_ID}_$(date '+%Y-%m-%d-%H-%M').tar.gz")
tar cvzf ${SNAP_PATH}/${SNAP_NAME} ${DATA_PATH}
aws s3 cp ${SNAP_PATH}/${SNAP_NAME} s3://${s3_snapshot_bucket}/ --region ap-northeast-1 --debug || true
rm -rf ${SNAP_PATH}/${SNAP_NAME}
done
# TODO: add metrics around snapshot upload latency/frequency/success rate
while true; do
# p2p.seeds taken from --p2p.persistent_peers flag of full node
cosmovisor run start --log_level info --home /dydxprotocol/chain/.full-node-0 --p2p.seeds "${p2p_seeds:?}" --non-validating-full-node=true --dd-agent-host=${dd_agent_host:?} &
sleep ${upload_period}
kill -TERM "$(pidof cosmovisor)"
SNAP_NAME=$(echo "${CHAIN_ID}_$(date '+%Y-%m-%d-%H-%M').tar.gz")
tar cvzf ${SNAP_PATH}/${SNAP_NAME} ${DATA_PATH}
aws s3 cp ${SNAP_PATH}/${SNAP_NAME:?} s3://${s3_snapshot_bucket:?}/ --region ap-northeast-1 --debug || true
rm -rf ${SNAP_PATH:?}/${SNAP_NAME:?}
done
Tools
Shellcheck

[warning] 85-85: p2p_seeds is referenced but not assigned.

(SC2154)


[warning] 85-85: dd_agent_host is referenced but not assigned.

(SC2154)


[warning] 87-87: upload_period is referenced but not assigned.

(SC2154)


[warning] 88-88: Quote this to prevent word splitting.

(SC2046)


[warning] 92-92: s3_snapshot_bucket is referenced but not assigned.

(SC2154)


[warning] 93-93: Use "${var:?}" to ensure this never expands to / .

(SC2115)

Comment on lines +48 to +121
create_validators() {
# Create directories for full-nodes to use.
for i in $(seq 0 $LAST_FULL_NODE_INDEX); do
FULL_NODE_HOME_DIR="$HOME/chain/.full-node-$i"
FULL_NODE_CONFIG_DIR="$FULL_NODE_HOME_DIR/config"
dydxprotocold init "full-node" -o --chain-id=$CHAIN_ID --home "$FULL_NODE_HOME_DIR"

if [[ "$i" == 0 ]]; then
# First full-node config is for the Indexer, don't enable seed mode.
continue
fi

# All other full-nodes should be seed nodes.
configure_seed "$FULL_NODE_CONFIG_DIR"
done

# Iterate over all validators and set up their home directories.
for i in "${!MONIKERS[@]}"; do
VAL_HOME_DIR="$HOME/chain/.${MONIKERS[$i]}"
VAL_CONFIG_DIR="$VAL_HOME_DIR/config"

# Initialize the chain and validator files.
dydxprotocold init "${MONIKERS[$i]}" -o --chain-id=$CHAIN_ID --home "$VAL_HOME_DIR"
done

# Copy this genesis file to each of the other validators
for i in "${!MONIKERS[@]}"; do
VAL_HOME_DIR="$HOME/chain/.${MONIKERS[$i]}"
VAL_CONFIG_DIR="$VAL_HOME_DIR/config"
rm -rf "$VAL_CONFIG_DIR/genesis.json"
cp "$HOME/genesis.json" "$VAL_CONFIG_DIR/genesis.json"
done

# Set up CosmosVisor.
for i in "${!MONIKERS[@]}"; do
VAL_HOME_DIR="$HOME/chain/.${MONIKERS[$i]}"
# DAEMON_NAME is the name of the binary.
export DAEMON_NAME=dydxprotocold

# DAEMON_HOME is the location where the cosmovisor/ directory is kept
# that contains the genesis binary, the upgrade binaries, and any additional
# auxiliary files associated with each binary
export DAEMON_HOME="$HOME/chain/.${MONIKERS[$i]}"

# Create the folder structure required for using cosmovisor.
cosmovisor init /bin/dydxprotocold

cp -r "$HOME/cosmovisor" "$VAL_HOME_DIR/"
done

# Copy the genesis file to the full-node directories.
for i in "${!FULL_NODE_KEYS[@]}"; do
FULL_NODE_HOME_DIR="$HOME/chain/.full-node-$i"
FULL_NODE_CONFIG_DIR="$FULL_NODE_HOME_DIR/config"

cp "$HOME/genesis.json" "$FULL_NODE_CONFIG_DIR/genesis.json"
done

# Set up CosmosVisor for full-nodes.
for i in "${!FULL_NODE_KEYS[@]}"; do
FULL_NODE_HOME_DIR="$HOME/chain/.full-node-$i"
# DAEMON_NAME is the name of the binary.
export DAEMON_NAME=dydxprotocold

# DAEMON_HOME is the location where the cosmovisor/ directory is kept
# that contains the genesis binary, the upgrade binaries, and any additional
# auxiliary files associated with each binary
export DAEMON_HOME="$HOME/chain/.full-node-$i"

# Create the folder structure required for using cosmovisor.
cosmovisor init /bin/dydxprotocold

cp -r "$HOME/cosmovisor" "$FULL_NODE_HOME_DIR/"
done
Copy link
Contributor

Choose a reason for hiding this comment

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

Verify the presence of required environment variables and directories.

The function assumes the presence of certain environment variables and directories. Add checks to verify their presence before proceeding.

create_validators() {
  # Create directories for full-nodes to use.
  for i in $(seq 0 $LAST_FULL_NODE_INDEX); do
    FULL_NODE_HOME_DIR="$HOME/chain/.full-node-$i"
    FULL_NODE_CONFIG_DIR="$FULL_NODE_HOME_DIR/config"
    dydxprotocold init "full-node" -o --chain-id=$CHAIN_ID --home "$FULL_NODE_HOME_DIR"

    if [[ "$i" == 0 ]]; then
      # First full-node config is for the Indexer, don't enable seed mode.
      continue
    fi

    # All other full-nodes should be seed nodes.
    configure_seed "$FULL_NODE_CONFIG_DIR"
  done

  # Iterate over all validators and set up their home directories.
  for i in "${!MONIKERS[@]}"; do
    VAL_HOME_DIR="$HOME/chain/.${MONIKERS[$i]}"
    VAL_CONFIG_DIR="$VAL_HOME_DIR/config"

    # Initialize the chain and validator files.
    dydxprotocold init "${MONIKERS[$i]}" -o --chain-id=$CHAIN_ID --home "$VAL_HOME_DIR"
  done

  # Copy this genesis file to each of the other validators
  for i in "${!MONIKERS[@]}"; do
    VAL_HOME_DIR="$HOME/chain/.${MONIKERS[$i]}"
    VAL_CONFIG_DIR="$VAL_HOME_DIR/config"
    rm -rf "$VAL_CONFIG_DIR/genesis.json"
    cp "$HOME/genesis.json" "$VAL_CONFIG_DIR/genesis.json"
  done

  # Set up CosmosVisor.
  for i in "${!MONIKERS[@]}"; do
    VAL_HOME_DIR="$HOME/chain/.${MONIKERS[$i]}"
    # DAEMON_NAME is the name of the binary.
    export DAEMON_NAME=dydxprotocold

    # DAEMON_HOME is the location where the cosmovisor/ directory is kept
    # that contains the genesis binary, the upgrade binaries, and any additional
    # auxiliary files associated with each binary
    export DAEMON_HOME="$HOME/chain/.${MONIKERS[$i]}"

    # Create the folder structure required for using cosmovisor.
    cosmovisor init /bin/dydxprotocold

    cp -r "$HOME/cosmovisor" "$VAL_HOME_DIR/"
  done

  # Copy the genesis file to the full-node directories.
  for i in "${!FULL_NODE_KEYS[@]}"; do
    FULL_NODE_HOME_DIR="$HOME/chain/.full-node-$i"
    FULL_NODE_CONFIG_DIR="$FULL_NODE_HOME_DIR/config"

    cp "$HOME/genesis.json" "$FULL_NODE_CONFIG_DIR/genesis.json"
  done

  # Set up CosmosVisor for full-nodes.
  for i in "${!FULL_NODE_KEYS[@]}"; do
    FULL_NODE_HOME_DIR="$HOME/chain/.full-node-$i"
    # DAEMON_NAME is the name of the binary.
    export DAEMON_NAME=dydxprotocold

    # DAEMON_HOME is the location where the cosmovisor/ directory is kept
    # that contains the genesis binary, the upgrade binaries, and any additional
    # auxiliary files associated with each binary
    export DAEMON_HOME="$HOME/chain/.full-node-$i"

    # Create the folder structure required for using cosmovisor.
    cosmovisor init /bin/dydxprotocold

    cp -r "$HOME/cosmovisor" "$FULL_NODE_HOME_DIR/"
  done
}

Committable suggestion was skipped due to low confidence.

Comment on lines +21 to +46
set_cosmovisor_binary_permissions() {
# The genesis binary should always exist.
for f in $HOME/cosmovisor/genesis/bin/* ; do
chmod 755 $f
done
# Set up upgrade binaries.
for version in "${!version_to_url[@]}"; do
echo "Setting up version ${version}..."
version_dir="$HOME/cosmovisor/upgrades/$version"
mkdir -p "$version_dir/bin"
url=${version_to_url[$version]}
tar_file=$(basename $url)

echo "Downloading tar file from ${url}..."
wget -O $tar_file $url
tar -xzf $tar_file -C "$version_dir"
rm $tar_file
binary_file="${tar_file%.tar.gz}"
mv "$version_dir/build/$binary_file" "$version_dir/bin/dydxprotocold"
chmod 755 "$version_dir/bin/dydxprotocold"
echo "Successfully set up $version_dir/bin/dydxprotocold"
done
current_version_path="$HOME/cosmovisor/upgrades/$CURRENT_VERSION_DIR/bin"
mkdir -p $current_version_path
cp /bin/dydxprotocold $current_version_path
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Verify the presence of binaries before setting permissions.

The function assumes the presence of binaries in specific directories. Add checks to verify the presence of the binaries before setting permissions.

set_cosmovisor_binary_permissions() {
  # The genesis binary should always exist.
  for f in $HOME/cosmovisor/genesis/bin/* ; do
    if [ -f "$f" ]; then
      chmod 755 $f
    else
      echo "Warning: Genesis binary $f not found."
    fi
  done
  # Set up upgrade binaries.
  for version in "${!version_to_url[@]}"; do
    echo "Setting up version ${version}..."
    version_dir="$HOME/cosmovisor/upgrades/$version"
    mkdir -p "$version_dir/bin"
    url=${version_to_url[$version]}
    tar_file=$(basename $url)
    echo "Downloading tar file from ${url}..."
    wget -O $tar_file $url
    tar -xzf $tar_file -C "$version_dir"
    rm $tar_file
    binary_file="${tar_file%.tar.gz}"
    if [ -f "$version_dir/build/$binary_file" ]; then
      mv "$version_dir/build/$binary_file" "$version_dir/bin/dydxprotocold"
      chmod 755 "$version_dir/bin/dydxprotocold"
      echo "Successfully set up $version_dir/bin/dydxprotocold"
    else
      echo "Warning: Upgrade binary $version_dir/build/$binary_file not found."
    fi
  done
  current_version_path="$HOME/cosmovisor/upgrades/$CURRENT_VERSION_DIR/bin"
  mkdir -p $current_version_path
  cp /bin/dydxprotocold $current_version_path
}
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
set_cosmovisor_binary_permissions() {
# The genesis binary should always exist.
for f in $HOME/cosmovisor/genesis/bin/* ; do
chmod 755 $f
done
# Set up upgrade binaries.
for version in "${!version_to_url[@]}"; do
echo "Setting up version ${version}..."
version_dir="$HOME/cosmovisor/upgrades/$version"
mkdir -p "$version_dir/bin"
url=${version_to_url[$version]}
tar_file=$(basename $url)
echo "Downloading tar file from ${url}..."
wget -O $tar_file $url
tar -xzf $tar_file -C "$version_dir"
rm $tar_file
binary_file="${tar_file%.tar.gz}"
mv "$version_dir/build/$binary_file" "$version_dir/bin/dydxprotocold"
chmod 755 "$version_dir/bin/dydxprotocold"
echo "Successfully set up $version_dir/bin/dydxprotocold"
done
current_version_path="$HOME/cosmovisor/upgrades/$CURRENT_VERSION_DIR/bin"
mkdir -p $current_version_path
cp /bin/dydxprotocold $current_version_path
}
set_cosmovisor_binary_permissions() {
# The genesis binary should always exist.
for f in $HOME/cosmovisor/genesis/bin/* ; do
if [ -f "$f" ]; then
chmod 755 $f
else
echo "Warning: Genesis binary $f not found."
fi
done
# Set up upgrade binaries.
for version in "${!version_to_url[@]}"; do
echo "Setting up version ${version}..."
version_dir="$HOME/cosmovisor/upgrades/$version"
mkdir -p "$version_dir/bin"
url=${version_to_url[$version]}
tar_file=$(basename $url)
echo "Downloading tar file from ${url}..."
wget -O $tar_file $url
tar -xzf $tar_file -C "$version_dir"
rm $tar_file
binary_file="${tar_file%.tar.gz}"
if [ -f "$version_dir/build/$binary_file" ]; then
mv "$version_dir/build/$binary_file" "$version_dir/bin/dydxprotocold"
chmod 755 "$version_dir/bin/dydxprotocold"
echo "Successfully set up $version_dir/bin/dydxprotocold"
else
echo "Warning: Upgrade binary $version_dir/build/$binary_file not found."
fi
done
current_version_path="$HOME/cosmovisor/upgrades/$CURRENT_VERSION_DIR/bin"
mkdir -p $current_version_path
cp /bin/dydxprotocold $current_version_path
}

Copy link
Contributor

@teddyding teddyding Aug 7, 2024

Choose a reason for hiding this comment

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

Which version is this for my understanding? v5.2.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

genesis (v1.0.0)


# Define the mapping from version to URL
declare -A version_to_url
version_to_url["v5.1.0"]="https://github.com/dydxprotocol/v4-chain/releases/download/protocol%2Fv5.1.1/dydxprotocold-v5.1.1-linux-amd64.tar.gz"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add v5.2.0 here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah we should specify previous version. This is getting backported to v5.2.0 branch first though. Will follow up with a PR to set everything for v6.0.0

done

# Set up CosmosVisor for full-nodes.
for i in $(seq 0 $LAST_FULL_NODE_INDEX); do
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this 0 through 2? I thought there are only 2 full nodes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No harm in initializing more home directories

@roy-dydx roy-dydx merged commit 84eed16 into main Aug 7, 2024
18 checks passed
@roy-dydx roy-dydx deleted the roy/testnettest branch August 7, 2024 15:36
@roy-dydx
Copy link
Contributor Author

roy-dydx commented Aug 7, 2024

@Mergifyio backport release/protocol/v5.2.x

Copy link
Contributor

mergify bot commented Aug 7, 2024

backport release/protocol/v5.2.x

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Aug 7, 2024
roy-dydx added a commit that referenced this pull request Aug 7, 2024
Co-authored-by: roy-dydx <133032749+roy-dydx@users.noreply.github.com>
@roy-dydx
Copy link
Contributor Author

roy-dydx commented Aug 7, 2024

https://github.com/Mergifyio backport release/protocol/v6.x

Copy link
Contributor

mergify bot commented Aug 7, 2024

backport release/protocol/v6.x

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Aug 7, 2024
roy-dydx added a commit that referenced this pull request Aug 7, 2024
Co-authored-by: roy-dydx <133032749+roy-dydx@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants