Skip to content

Commit

Permalink
Merge pull request #2158 from eseiker/thor-toolchain
Browse files Browse the repository at this point in the history
Add thor to github workflows and scripts
  • Loading branch information
eseiker authored Nov 13, 2024
2 parents 7242597 + 3f13f2b commit 7244e8e
Show file tree
Hide file tree
Showing 16 changed files with 132 additions and 108 deletions.
25 changes: 11 additions & 14 deletions .github/scripts/reset-snapshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ set -ex
BASEDIR=$(dirname "$0")
echo "$BASEDIR"

BUCKET="s3://9c-snapshots-v2"

# AWS configuration must be already set on your environment
reset_snapshot() {
CHAIN=$3
PREFIX="s3://9c-snapshots-v2/"
PREFIX="$BUCKET/"
PREVIOUS_MAINNET_EPOCH_PATH="${1#$PREFIX}"
BASE_URL_PATH="${2#$PREFIX}"
NEW_SNAPSHOT_TIP=0
Expand Down Expand Up @@ -90,14 +92,13 @@ reset_snapshot() {

fi

BUCKET="s3://9c-snapshots-v2"
BUCKET_PREFIX=$(echo $BUCKET | awk '{gsub(/\//,"\\/");print}')
CF_PATH=$(echo $1/ | sed -e "s/^$BUCKET_PREFIX//" | sed "s/.*/&*/")

# reset cf path
CF_DISTRIBUTION_ID="EAU4XRUZSBUD5"
aws cloudfront create-invalidation --distribution-id "$CF_DISTRIBUTION_ID" --paths "$CF_PATH"
if [ "$CHAIN" = "odin" ] || [ "$CHAIN" = "heimdall" ]; then
if [[ $CHAIN != *-preview ]]; then
curl --data "[9C-INFRA] Internal $CHAIN snapshot file reset complete. New tip: \`#$NEW_SNAPSHOT_TIP\`." "https://planetariumhq.slack.com/services/hooks/slackbot?token=$SLACK_TOKEN&channel=%239c-internal"
else
curl --data "[9C-INFRA] Preview $CHAIN snapshot file reset complete. New tip: \`#$NEW_SNAPSHOT_TIP\`." "https://planetariumhq.slack.com/services/hooks/slackbot?token=$SLACK_TOKEN&channel=%239c-previewnet"
Expand All @@ -107,20 +108,16 @@ reset_snapshot() {
# Type "y" to reset the cluster with a new snapshot and "n" to just deploy the cluster.
echo "Do you want to reset the cluster with a new snapshot(y/n)?"
read response
CHAIN_NAME=$1
CHAIN=$1

if [ "$response" = "y" ]; then
echo "Reset cluster with a new snapshot"

if [ "$CHAIN_NAME" = "odin" ]; then
reset_snapshot "s3://9c-snapshots-v2/internal" "s3://9c-snapshots-v2/main/partition/internal" "$CHAIN_NAME" || true
elif [ "$CHAIN_NAME" = "heimdall" ]; then
reset_snapshot "s3://9c-snapshots-v2/internal/heimdall" "s3://9c-snapshots-v2/main/heimdall/partition/internal" "$CHAIN_NAME" || true
elif [ "$CHAIN_NAME" = "odin-preview" ]; then
reset_snapshot "s3://9c-snapshots-v2/preview" "s3://9c-snapshots-v2/main/partition/internal" "$CHAIN_NAME" || true
else
reset_snapshot "s3://9c-snapshots-v2/preview/heimdall" "s3://9c-snapshots-v2/main/heimdall/partition/internal" "$CHAIN_NAME" || true
fi

INTERNAL_OR_PREVIEW=$([[ $CHAIN != *-preview ]] && echo "internal" || echo "preview")
CHAIN_NAME=${CHAIN%-preview}
CHAIN_PATH=$([[ $CHAIN_NAME = odin ]] && echo "" || echo "/$CHAIN_NAME")

reset_snapshot "$BUCKET/$INTERNAL_OR_PREVIEW$CHAIN_PATH" "$BUCKET/main$CHAIN_PATH/partition/internal" "$CHAIN_NAME" || true

else
echo "Reset cluster without resetting snapshot."
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/validate-charts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ done

# Check multiplanetary networks manually
CLUSTERS=("9c-main" "9c-internal")
NETWORKS=("9c-network" "heimdall" "idun")
NETWORKS=("9c-network" "heimdall" "thor" "idun")
for cluster in "${CLUSTERS[@]}"; do
for network in "${NETWORKS[@]}"; do
helm template --values "$cluster/multiplanetary/network/$network.yaml" \
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/apv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ on:
default: 'main'
type: choice
options:
- main-heimdall
- main-odin
- internal-heimdall
- main-heimdall
- main-thor
- internal-odin
- internal-heimdall
- internal-thor
number:
required: true
description: 'Apv number (e.g. 100310)'
Expand All @@ -32,6 +34,7 @@ on:
- general
- 9c-network
- heimdall
- thor

jobs:
manage-apv:
Expand Down
11 changes: 4 additions & 7 deletions .github/workflows/reset-bridge-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ on:
default: 'internal'
type: choice
options:
- internal
- preview
- heimdall-internal
- thor-internal
- heimdall-preview

jobs:
reset-bridge-service:
Expand All @@ -32,11 +33,7 @@ jobs:
- name: Set namespace based on input
run: |
if [ "${{ github.event.inputs.network }}" = "internal" ]; then
echo "NAMESPACE=heimdall" >> $GITHUB_ENV
else
echo "NAMESPACE=heimdall-preview" >> $GITHUB_ENV
fi
echo ${${{ github.event.inputs.network }}%"-internal"} >> $GITHUB_ENV
- uses: actions-hub/kubectl@master
env:
Expand Down
68 changes: 65 additions & 3 deletions .github/workflows/snapshot-reset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ on:
default: 'odin'
type: choice
options:
- internal-all
- odin
- heimdall
- thor
- preview-all
- odin-preview
- heimdall-preview
- internal-all
- preview-all

concurrency:
group: release
Expand Down Expand Up @@ -51,6 +52,22 @@ jobs:
AWS_REGION: ${{ secrets.AWS_REGION }}
SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }}

release-thor:
if: ${{ github.event.inputs.chain == 'thor' || github.event.inputs.chain == 'internal-all' }}
runs-on: ubuntu-latest
environment:
name: internal
steps:
- uses: actions/checkout@v3
- name: reset internal snapshot
run: |
echo "y" | bash .github/scripts/reset-snapshot.sh thor
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }}

release-odin-preview:
if: ${{ github.event.inputs.chain == 'odin-preview' || github.event.inputs.chain == 'preview-all' }}
runs-on: ubuntu-latest
Expand Down Expand Up @@ -83,7 +100,7 @@ jobs:
AWS_REGION: ${{ secrets.AWS_REGION }}
SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }}

reset-bridge-service:
reset-bridge-service-heimdall:
if: ${{ github.event.inputs.chain == 'internal-all' || github.event.inputs.chain == 'odin' || github.event.inputs.chain == 'heimdall' }}
runs-on: ubuntu-latest
needs: [release-odin, release-heimdall]
Expand Down Expand Up @@ -128,6 +145,51 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.P_GITHUB_TOKEN }}

reset-bridge-service-thor:
if: ${{ github.event.inputs.chain == 'internal-all' || github.event.inputs.chain == 'odin' || github.event.inputs.chain == 'thor' }}
runs-on: ubuntu-latest
needs: [release-odin, release-thor]
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Set up kubectl
uses: azure/setup-kubectl@v1
with:
version: 'v1.29.0'
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y jq
- uses: actions-hub/kubectl@master
env:
KUBE_CONFIG: ${{ secrets.KUBECONFIG }}
with:
args: scale --replicas=0 statefulset/bridge-service -n thor
- uses: actions-hub/kubectl@master
env:
KUBE_CONFIG: ${{ secrets.KUBECONFIG }}
with:
args: scale --replicas=0 statefulset/bridge-service-db -n thor
- uses: actions-hub/kubectl@master
env:
KUBE_CONFIG: ${{ secrets.KUBECONFIG }}
with:
args: delete pvc/bridge-service-db-data-bridge-service-db-0 --namespace=thor
- uses: actions/[email protected]
with:
python-version: 3.10.13
- run: |
python -m pip install -r requirements.txt
flit install
name: install dependencies
working-directory: ./scripts
- name: Update 'bridgeService.rdb.defaultStartBlockIndex'
run: |
python cli.py update-bridge-service 9c-internal thor
working-directory: ./scripts
env:
GITHUB_TOKEN: ${{ secrets.P_GITHUB_TOKEN }}

reset-bridge-service-preview:
if: ${{ github.event.inputs.chain == 'preview-all' || github.event.inputs.chain == 'odin-preview' || github.event.inputs.chain == 'heimdall-preview' }}
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-internal-chain.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
options:
- odin-internal
- heimdall-internal
- thor-internal
offset:
required: true
description: 'Insert the snapshot tip index of the internal network (e.g. 1115268)'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/update-paev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
options:
- odin
- heimdall
- thor
description: 'Choose the mainnet network to update the appsettings.json'
previous_version_block_index:
required: true
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/update-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ on:
- general
- 9c-network
- heimdall
- thor
- idun
headless:
description: 'Dockerhub tag for headless (e.g. 30, git-5db812731f7fef1156b00a90ff0267e95dd31820)'
Expand Down
7 changes: 5 additions & 2 deletions scripts/app/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
RELEASE_BASE_URL = "https://release.nine-chronicles.com"
RELEASE_BUCKET = "9c-release.planetariumhq.com"

MAIN_ODIN_SIGNER="0xAB2da648b9154F2cCcAFBD85e0Bc3d51f97330Fc"
MAIN_HEIMDALL_SIGNER="0xeE394bb942fa7c2d807C170C7Db7F26cb3EA037F"
MAIN_SIGNERS = {
"odin": "0xAB2da648b9154F2cCcAFBD85e0Bc3d51f97330Fc",
"heimdall": "0xeE394bb942fa7c2d807C170C7Db7F26cb3EA037F",
"thor": "0xC6553c8e634bEE685F264F4C5720d65919dc9c9c",
}
37 changes: 12 additions & 25 deletions scripts/app/test_internal_chain.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,25 @@
import aiohttp
import asyncio
import sys
import os
import requests

from urllib.parse import urljoin
from app.client import GithubClient
from app.config import config

Network = str
Offset = int
Limit = int
Delay = int

class InternalChainTester:
def __init__(self) -> None:
self.github_client = GithubClient(
config.github_token, org="planetarium", repo="TEMP"
)

def test(
self,
network: Network,
offset: Offset,
limit: Limit,
delay: Delay
):

def test(self, network: str, offset: int, limit: int, delay: int):
# mainnet headless URL and initial setup
mainnet_headless = "odin-full-state.nine-chronicles.com"
internal_target_validator = "odin-internal-validator-5.nine-chronicles.com"
stripped_network = network.removesuffix("-internal")
validator_target = 5 if stripped_network == "odin" else 1

mainnet_headless = f"{stripped_network}-full-state.nine-chronicles.com"
internal_target_validator = f"{stripped_network}-internal-validator-{validator_target}.nine-chronicles.com"
sleep_time = delay
if network == "heimdall-internal":
mainnet_headless = "heimdall-full-state.nine-chronicles.com"
internal_target_validator = "heimdall-internal-validator-1.nine-chronicles.com"
mainnet_headless_url = urljoin(f"http://{mainnet_headless}", "graphql")
target_validator_url = urljoin(f"http://{internal_target_validator}", "graphql")

Expand Down Expand Up @@ -65,7 +52,7 @@ def test(
response = requests.post(mainnet_headless_url, json={'query': mainnet_headless_query}, headers={'content-type': 'application/json'})
data = response.json()
blocks = data['data']['chainQuery']['blockQuery']['blocks']

# Process the blocks here (e.g., print them out or handle them as needed)
print(f"Fetched {len(blocks)} blocks starting from offset {offset}")

Expand All @@ -91,7 +78,7 @@ async def process_block(blocks):
offset += current_limit

if hasattr(config, 'slack_token') and config.slack_token:
url = f'https://planetariumhq.slack.com/services/hooks/slackbot?token={config.slack_token}&channel=%23{config.slack_channel}'
data = f"[9C-INFRA] Finished testing `{network}` network from `#{original_offset}` to `#{tip_index}`."
headers = {'Content-Type': 'text/plain'}
response = requests.post(url, data=data, headers=headers)
url = f"https://planetariumhq.slack.com/services/hooks/slackbot?token={config.slack_token}&channel=%23{config.slack_channel}"
data = f"[9C-INFRA] Finished testing `{network}` network from `#{original_offset}` to `#{tip_index}`."
headers = {"Content-Type": "text/plain"}
response = requests.post(url, data=data, headers=headers)
3 changes: 0 additions & 3 deletions scripts/app/types.py

This file was deleted.

8 changes: 3 additions & 5 deletions scripts/app/update_apv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from app.config import config
from app.tools.planet import Apv, Planet
from app.constants import MAIN_HEIMDALL_SIGNER, MAIN_ODIN_SIGNER
from app.constants import MAIN_SIGNERS

logger = structlog.get_logger(__name__)
from tempfile import TemporaryFile
Expand Down Expand Up @@ -124,10 +124,8 @@ def update_apv(contents: str, apv: Apv):
return new_doc

def check_correct_signer(dir_name:str, file_name: str):
if "9c-main" in dir_name and file_name == "heimdall":
assert config.key_address == MAIN_HEIMDALL_SIGNER
if "9c-main" in dir_name and file_name == "odin":
assert config.key_address == MAIN_ODIN_SIGNER
if "9c-main" in dir_name:
assert config.key_address == MAIN_SIGNERS[file_name]

def generate_apv(planet: Planet, number: int) -> Apv:
timestamp = datetime.utcnow().strftime("%Y-%m-%d")
Expand Down
Loading

0 comments on commit 7244e8e

Please sign in to comment.