diff --git a/.github/workflows/cicd-prd.yml b/.github/workflows/cicd-prd.yml index 6258cb63b..fe1741ff3 100644 --- a/.github/workflows/cicd-prd.yml +++ b/.github/workflows/cicd-prd.yml @@ -28,6 +28,7 @@ jobs: devex-apollo, eth-spout, neo-savant, + zilliqa-isolated-server, ] include: - application: bluebell-playground @@ -60,6 +61,11 @@ jobs: path: products/neo-savant tag_length: 8 tag_latest: false + - application: zilliqa-isolated-server + image_name: zilliqa-isolated-server + path: products/zilliqa-isolated-server + tag_length: 8 + tag_latest: true env: DOCKER_DOMAIN: asia-docker.pkg.dev REGISTRY: asia-docker.pkg.dev/prj-p-devops-services-tvwmrf63/zilliqa-public diff --git a/.github/workflows/cicd-stg.yml b/.github/workflows/cicd-stg.yml index 455d99817..7b07fb06b 100644 --- a/.github/workflows/cicd-stg.yml +++ b/.github/workflows/cicd-stg.yml @@ -9,9 +9,6 @@ on: push: branches: - main - # On released - release: - types: [created] jobs: build-docker: @@ -19,8 +16,8 @@ jobs: id-token: write contents: write runs-on: ubuntu-22.04 - if: github.actor != 'dependabot[bot]' && github.ref_name == 'main' && github.event_name != 'release' - name: "Build and push images" + if: github.actor != 'dependabot[bot]' && github.ref_name == 'main' + name: "Deploy image" strategy: fail-fast: false matrix: @@ -78,7 +75,7 @@ jobs: username: "oauth2accesstoken" password: "${{ steps.google-auth.outputs.access_token }}" - - name: Get tag version staging - staging + - name: Get tag version - staging id: set-tag uses: Zilliqa/gh-actions-workflows/actions/generate-tag@v1 with: diff --git a/products/zilliqa-isolated-server/.gitignore b/products/zilliqa-isolated-server/.gitignore new file mode 100644 index 000000000..4c3b87979 --- /dev/null +++ b/products/zilliqa-isolated-server/.gitignore @@ -0,0 +1,3 @@ +node_modules +downloads +persistence diff --git a/products/zilliqa-isolated-server/Dockerfile b/products/zilliqa-isolated-server/Dockerfile new file mode 100644 index 000000000..ceb362c32 --- /dev/null +++ b/products/zilliqa-isolated-server/Dockerfile @@ -0,0 +1,17 @@ +#FROM 648273915458.dkr.ecr.us-west-2.amazonaws.com/zilliqa:7186a35 +FROM zilliqa/zilliqa:v9.2.6 +ARG SOURCE_DIR=/zilliqa + +WORKDIR ${SOURCE_DIR} + +RUN mkdir -p /zilliqa/logs +COPY boot.json ./boot.json +COPY constants.xml ./constants.xml +COPY dsnodes.xml ./dsnodes.xml +COPY validate.sh ./validate.sh +COPY run.sh ./run.sh +EXPOSE 5555 + +ARG MODE="" +ENV MODE=${MODE} +ENTRYPOINT ["bash", "run.sh"] diff --git a/products/zilliqa-isolated-server/Makefile b/products/zilliqa-isolated-server/Makefile new file mode 100644 index 000000000..6014b5e6e --- /dev/null +++ b/products/zilliqa-isolated-server/Makefile @@ -0,0 +1,16 @@ +.PHONY: all +all: image/build-and-push + +.ONESHELL: +SHELL := /bin/bash +.SHELLFLAGS = -ec + +IMAGE_TAG ?= localhost:5001/zilliqa-isolated-server:latest + +## Build and push the Docker image +image/build-and-push: + docker pull nginx:latest + docker tag nginx:latest $(shell echo ${IMAGE_TAG} | sed 's/zilliqa-isolated-server/nginx/') + docker push $(shell echo ${IMAGE_TAG} | sed 's/zilliqa-isolated-server/nginx/') + docker build -t "${IMAGE_TAG}" . + docker push "${IMAGE_TAG}" \ No newline at end of file diff --git a/products/zilliqa-isolated-server/README.md b/products/zilliqa-isolated-server/README.md new file mode 100644 index 000000000..9e67a935a --- /dev/null +++ b/products/zilliqa-isolated-server/README.md @@ -0,0 +1,273 @@ +# Dockerized Zilliqa Isolated Server + +## Prerequisites + +### Local Build + +Docker installed, please follow the steps [here](https://docs.docker.com/get-docker/). + +## Administration + +### Building Isolated Server Container + +#### Local Build + +The isolated server can be built locally via the following command:
+`docker build -t isolated-server:1.0 .`
+there will be an image named isolated-server:1.0 built. + +--- + +### Running Isolated Server Container + +#### Local Run + +There are a few methods to configure and run the isolated server, all of them requiring augmentations to the docker run command. + +##### Running the isolated server as is: + +``` +docker run -d -p 5555:5555 \ + --name isolated-server \ + isolated-server:1.0 +``` + +And the api will be available at `http://localhost:5555`
+The above command will launch a clean state isolated server with ephermeral storage and seeding all the default accounts via `boot.json`. + +--- + +##### Running the isolated server with persistence + +Enabling non-ephermeral persistence can be done by mounting a volume onto the container via the following argument `-v $(pwd)/persistence:/zilliqa/persistence`. + +Do note however, there is now two different docker run commands. The first one is required on all **first** launch of Isolated Server with persistence storage. + +``` +docker run -d -p 5555:5555 \ + -v $(pwd)/persistence:/zilliqa/persistence \ + --name isolated-server \ + isolated-server:1.0 +``` + +The following command must be run on all subsequent Isolated Server container launches. Note the addition of a new argument `--env MODE="load"`. This environment variable forces the Isolated Server to launch while attempting to load persistence from the container directory: `/zilliqa/persistence`. + +``` +docker run -d -p 5555:5555 \ + -v $(pwd)/persistence:/zilliqa/persistence \ + --env MODE="load" \ + --name isolated-server \ + isolated-server:1.0 +``` + +--- + +##### Running the isolated server with manual block increase + +Enabling manual mode can be done by the following command. + +If manual mode is enabled, the following api call is available `IncreaseBlocknum` + +Do note however, if you run in manual mode, persistence storage is not supported. + +``` +docker run -d -p 5555:5555 \ + --env MANUAL_MODE="true" \ + --name isolated-server \ + isolated-server:1.0 +``` + +--- + +##### Additional Run Arguments + +The Isolated Server run script also supports modifications to the following parameters +| environment variable | default value | description | +|---|---|---| +|$T|5000|The time before progressing each block in Isolated Server. +|$UUID|uuid|The uuid that's used as a verification for pausing and unpausing the Isolated server. + +Docker run command overriding the 2 variables: + +``` +docker run -d -p 5555:5555 \ + --env T="2000" \ + --env UUID="randomstring" \ + --name isolated-server \ + isolated-server:1.0 +``` + +--- + +##### Stopping the Isolated Server + +``` +docker stop isolated-server +``` + +##### Removing the Stopped Isolated Server + +``` +docker rm isolated-server +``` + +--- + +##### Available APIs + +- `CreateTransaction` : Input a transaction json payload +- `GetLatestTxBlock` : Get the information on the latest tx block, not available in manual mode. +- `IncreaseBlocknum` : Increase the blocknum by a given input, only available in manual mode. +- `GetSmartContractSubState` : Get the state of a smart contract +- `GetSmartContractCode` : Get code at a given address +- `GetMinimumGasPrice` : Get the minimum gas price +- `SetMinimumGasPrice`: Set the minimum gas price +- `GetBalance`: Get balance and nonce of a account +- `GetSmartContracts`: get smart contract for an address +- `GetNetworkID`: get the network ID of the isolated server +- `GetSmartContractInit` : get init json for a SC. +- `GetTransaction `: Get Transaction info by hash + +- `CheckPause`: Checks if the Isolated Server is paused. Requires UUID +- `TogglePause`: Toggles the Isolated Server between pause and unpause state. Requires UUID. + +## Deploying applications with z + +`z` is the one-stop shop for the Zilliqa provisioning and deployment operations. To deploy applications with z ensure the `z` +binary is installed in your operative system PATH environment variable. For more details about `z` please refer to the [documentation](https://github.com/Zilliqa/devops/blob/main/docs/z2.md). + +## Deploying applications to localdev + +To deploy the localdev/development environment go to the project folder in the zilliqa-internal repository: + +```sh +cd ./products/zilliqa-isolated-server +``` + +The `./products/zilliqa-isolated-server/z.yaml` contains all the relevant configurations for the development environment. +Now set the following environment variables to reference the project's `z.yaml` file: + +- `Z_ENV` to the path in which your `z.yaml` resides. +- `ZQ_USER` to your username (the bit before `@` in your email address) + +for example: + +```sh +export Z_ENV=z.yaml +export ZQ_USER=@zilliqa.com +``` + +Create the local kind cluster (if not created previously): + +```sh +z local create +``` + +Build and push the images: + +```sh +make image/build-and-push +``` + +And deploy the application to your local cluster with: + +```sh +z app sync +``` + +Verify your application is running correct from the `http://localhost` URL and with `kubectl` commands (if required). + +## Deploying applications to production + +To deploy the production environment we need to clone the devops repository and execute `z` from there: + +```sh +git clone https://github.com/Zilliqa/devops.git +cd devops +source setenv +``` + +### Set the following environment variables (production) + +- `Z_ENV` to the path in which your `z.yaml` resides. +- `ZQ_USER` to your username (the bit before `@` in your email address) +- `GITHUB_PAT` (if you are deploying staging or production apps) to a classic PAT with all the repo permissions ticked. + +for example: + +```sh +export Z_ENV=`pwd`/infra/live/gcp/production/prj-p-prod-apps/z_ase1.yaml +export ZQ_USER=@zilliqa.com +export GITHUB_PAT= +``` + +### Login to Google Cloud (production) + +```sh +z login +``` + +### Login to 1password (production) + +```sh +eval $(op signin) +``` + +### Add the application to the production `z.yaml` file. Skip this step if it is an existing application + +1. Create a branch: + + ```sh + git checkout -b users//add_zilliqa_isolated_-_server_to_production_cluster + ``` + +2. In the file `infra/live/gcp/production/prj-p-prod-apps/z_ase1.yaml` add the following: + + - in `apps` stanza add: + + ```yaml + clusters: + production: + apps: + zilliqa-isolated-server: + repo: https://github.com/Zilliqa/zilliqa-developer + path: products/zilliqa-isolated-server/cd/overlays/production + registry: public + track: production + type: kustomize + ``` + + - in `subdomains` stanza add: + + ```yaml + infrastructure: + dns: + vars: + subdomains: + zilliqa-isolated-server: {} + ``` + +3. Push the changes + + ```sh + git add . + git commit -m "Add zilliqa-isolated-server to production cluster" + git push origin users//add_zilliqa_isolated_server_to_production_cluster + ``` + +4. Open a Pull Request to the main branch + +5. Apply the changes + + ```sh + z plan + z apply + ``` + +### Deploy the application (production) + +```sh +z app sync --cache-dir=.cache zilliqa-isolated-server +``` + +Verify your application is running correct from the staging URL and with `kubectl` commands (if required). diff --git a/products/zilliqa-isolated-server/boot.json b/products/zilliqa-isolated-server/boot.json new file mode 100644 index 000000000..c462538cb --- /dev/null +++ b/products/zilliqa-isolated-server/boot.json @@ -0,0 +1,47 @@ +{ + "d90f2e538ce0df89c8273cad3b63ec44a3c4ed82": { + "privateKey": "e53d1c3edaffc7a7bab5418eb836cf75819a82872b4a1a0f1c7fcf5c3e020b89", + "amount": "900000000000000000000000", + "nonce": 0 + }, + "381f4008505e940ad7681ec3468a719060caf796": { + "privateKey": "d96e9eb5b782a80ea153c937fa83e5948485fbfc8b7e7c069d7b914dbc350aba", + "amount": "900000000000000000000000", + "nonce": 0 + }, + "b028055ea3bc78d759d10663da40d171dec992aa": { + "privateKey": "e7f59a4beb997a02a13e0d5e025b39a6f0adc64d37bb1e6a849a4863b4680411", + "amount": "900000000000000000000000", + "nonce": 0 + }, + "f6dad9e193fa2959a849b81caf9cb6ecde466771": { + "privateKey": "589417286a3213dceb37f8f89bd164c3505a4cec9200c61f7c6db13a30a71b45", + "amount": "900000000000000000000000", + "nonce": 0 + }, + "10200e3da08ee88729469d6eabc055cb225821e7": { + "privateKey": "5430365143ce0154b682301d0ab731897221906a7054bbf5bd83c7663a6cbc40", + "amount": "900000000000000000000000", + "nonce": 0 + }, + "ac941274c3b6a50203cc5e7939b7dad9f32a0c12": { + "privateKey": "1080d2cca18ace8225354ac021f9977404cee46f1d12e9981af8c36322eac1a4", + "amount": "900000000000000000000000", + "nonce": 0 + }, + "ec902fe17d90203d0bddd943d97b29576ece3177": { + "privateKey": "254d9924fc1dcdca44ce92d80255c6a0bb690f867abde80e626fbfef4d357004", + "amount": "900000000000000000000000", + "nonce": 0 + }, + "c2035715831ab100ec42e562ce341b834bed1f4c": { + "privateKey": "b8fc4e270594d87d3f728d0873a38fb0896ea83bd6f96b4f3c9ff0a29122efe4", + "amount": "900000000000000000000000", + "nonce": 0 + }, + "6cd3667ba79310837e33f0aecbe13688a6cbca32": { + "privateKey": "b87f4ba7dcd6e60f2cca8352c89904e3993c5b2b0b608d255002edcda6374de4", + "amount": "900000000000000000000000", + "nonce": 0 + } +} diff --git a/products/zilliqa-isolated-server/build_docker.sh b/products/zilliqa-isolated-server/build_docker.sh new file mode 100755 index 000000000..0fe46b1ec --- /dev/null +++ b/products/zilliqa-isolated-server/build_docker.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +docker build -t zilliqaisolatedserver:1.0 . diff --git a/products/zilliqa-isolated-server/cd/base/deployment.yaml b/products/zilliqa-isolated-server/cd/base/deployment.yaml new file mode 100644 index 000000000..4d97abfe5 --- /dev/null +++ b/products/zilliqa-isolated-server/cd/base/deployment.yaml @@ -0,0 +1,44 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: zilliqa-isolated-server + namespace: zilliqa-isolated-server + labels: + app.kubernetes.io/name: zilliqa-isolated-server +spec: + progressDeadlineSeconds: 600 + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: zilliqa-isolated-server + strategy: + type: Recreate + template: + metadata: + labels: + app.kubernetes.io/name: zilliqa-isolated-server + spec: + restartPolicy: Always + terminationGracePeriodSeconds: 30 + volumes: + - emptyDir: {} + name: persistence-volume-ephemeral + containers: + - image: nginx + name: nginx + ports: + - containerPort: 80 + - image: zilliqa-isolated-server + name: zilliqa-isolated-server + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + volumeMounts: + - mountPath: /zilliqa/persistence + name: persistence-volume-ephemeral + ports: + - containerPort: 5555 + envFrom: + - configMapRef: + name: zilliqa-isolated-server + - secretRef: + name: zilliqa-isolated-server diff --git a/products/zilliqa-isolated-server/cd/base/ingress.yaml b/products/zilliqa-isolated-server/cd/base/ingress.yaml new file mode 100644 index 000000000..b5c5200d6 --- /dev/null +++ b/products/zilliqa-isolated-server/cd/base/ingress.yaml @@ -0,0 +1,21 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: zilliqa-isolated-server + namespace: zilliqa-isolated-server + labels: + app.kubernetes.io/name: zilliqa-isolated-server + annotations: + nginx.ingress.kubernetes.io/rewrite-target: /$2 +spec: + rules: + - host: localhost + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: zilliqa-isolated-server + port: + number: 5555 diff --git a/products/zilliqa-isolated-server/cd/base/kustomization.yaml b/products/zilliqa-isolated-server/cd/base/kustomization.yaml new file mode 100644 index 000000000..dcc83c044 --- /dev/null +++ b/products/zilliqa-isolated-server/cd/base/kustomization.yaml @@ -0,0 +1,7 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - namespace.yaml + - deployment.yaml + - svc.yaml + - ingress.yaml diff --git a/products/zilliqa-isolated-server/cd/base/namespace.yaml b/products/zilliqa-isolated-server/cd/base/namespace.yaml new file mode 100644 index 000000000..62097aa91 --- /dev/null +++ b/products/zilliqa-isolated-server/cd/base/namespace.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: zilliqa-isolated-server + labels: + app.kubernetes.io/name: zilliqa-isolated-server diff --git a/products/zilliqa-isolated-server/cd/base/svc.yaml b/products/zilliqa-isolated-server/cd/base/svc.yaml new file mode 100644 index 000000000..b56a64557 --- /dev/null +++ b/products/zilliqa-isolated-server/cd/base/svc.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: zilliqa-isolated-server + namespace: zilliqa-isolated-server + labels: + app.kubernetes.io/name: zilliqa-isolated-server +spec: + type: ClusterIP + ports: + - port: 5555 + targetPort: 5555 + protocol: TCP + name: http + selector: + app.kubernetes.io/name: zilliqa-isolated-server diff --git a/products/zilliqa-isolated-server/cd/overlays/production/app-secret.yaml b/products/zilliqa-isolated-server/cd/overlays/production/app-secret.yaml new file mode 100644 index 000000000..747ff6fb0 --- /dev/null +++ b/products/zilliqa-isolated-server/cd/overlays/production/app-secret.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Secret +metadata: + name: zilliqa-isolated-server + namespace: zilliqa-isolated-server + labels: + app.kubernetes.io/name: zilliqa-isolated-server + annotations: + zilliqa.com/autofill: prj-p-prod-apps +type: Opaque +data: + UUID: "zilliqa-isolated-server/UUID" diff --git a/products/zilliqa-isolated-server/cd/overlays/production/backend-config.yaml b/products/zilliqa-isolated-server/cd/overlays/production/backend-config.yaml new file mode 100644 index 000000000..9902b1aa6 --- /dev/null +++ b/products/zilliqa-isolated-server/cd/overlays/production/backend-config.yaml @@ -0,0 +1,12 @@ +apiVersion: cloud.google.com/v1 +kind: BackendConfig +metadata: + name: zilliqa-isolated-server + namespace: zilliqa-isolated-server + labels: + app.kubernetes.io/name: zilliqa-isolated-server +spec: + timeoutSec: 30 + healthCheck: + requestPath: / + port: 80 diff --git a/products/zilliqa-isolated-server/cd/overlays/production/certificate.yaml b/products/zilliqa-isolated-server/cd/overlays/production/certificate.yaml new file mode 100644 index 000000000..0ab460f0f --- /dev/null +++ b/products/zilliqa-isolated-server/cd/overlays/production/certificate.yaml @@ -0,0 +1,9 @@ +apiVersion: networking.gke.io/v1 +kind: ManagedCertificate +metadata: + name: zilliqa-isolated-server + labels: + app.kubernetes.io/name: zilliqa-isolated-server +spec: + domains: + - zilliqa-isolated-server.zilliqa.com diff --git a/products/zilliqa-isolated-server/cd/overlays/production/configmap.yaml b/products/zilliqa-isolated-server/cd/overlays/production/configmap.yaml new file mode 100644 index 000000000..5bde8494d --- /dev/null +++ b/products/zilliqa-isolated-server/cd/overlays/production/configmap.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: zilliqa-isolated-server + namespace: zilliqa-isolated-server + labels: + app.kubernetes.io/name: zilliqa-isolated-server +data: + AWS_INFRA_MODE: "false" + VALIDATOR_MODE: "false" diff --git a/products/zilliqa-isolated-server/cd/overlays/production/frontend-config.yaml b/products/zilliqa-isolated-server/cd/overlays/production/frontend-config.yaml new file mode 100644 index 000000000..8ebb038c9 --- /dev/null +++ b/products/zilliqa-isolated-server/cd/overlays/production/frontend-config.yaml @@ -0,0 +1,11 @@ +apiVersion: networking.gke.io/v1beta1 +kind: FrontendConfig +metadata: + name: zilliqa-isolated-server + namespace: zilliqa-isolated-server + labels: + app.kubernetes.io/name: zilliqa-isolated-server +spec: + redirectToHttps: + enabled: true + responseCodeName: RESPONSE_CODE diff --git a/products/zilliqa-isolated-server/cd/overlays/production/kustomization.yaml b/products/zilliqa-isolated-server/cd/overlays/production/kustomization.yaml new file mode 100644 index 000000000..61bf96de3 --- /dev/null +++ b/products/zilliqa-isolated-server/cd/overlays/production/kustomization.yaml @@ -0,0 +1,36 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +namespace: zilliqa-isolated-server-prd + +resources: + - ../../base + - configmap.yaml + - app-secret.yaml + - certificate.yaml + - backend-config.yaml + - frontend-config.yaml + +patches: + - target: + kind: Ingress + name: zilliqa-isolated-server + patch: |- + - op: replace + path: "/spec/rules/0/host" + value: zilliqa-isolated-server.zilliqa.com + - op: replace + path: /metadata/annotations + value: + kubernetes.io/ingress.class: gce + kubernetes.io/ingress.global-static-ip-name: zilliqa-isolated-server-zilliqa-com + networking.gke.io/managed-certificates: zilliqa-isolated-server + networking.gke.io/v1beta1.FrontendConfig: zilliqa-isolated-server + - target: + kind: Service + name: zilliqa-isolated-server + patch: |- + - op: add + path: /metadata/annotations + value: + beta.cloud.google.com/backend-config: '{"default": "zilliqa-isolated-server"}' diff --git a/products/zilliqa-isolated-server/constants.xml b/products/zilliqa-isolated-server/constants.xml new file mode 100644 index 000000000..2d86d1182 --- /dev/null +++ b/products/zilliqa-isolated-server/constants.xml @@ -0,0 +1,457 @@ + + + + + 3 + false + true + 50 + 222 + 3 + + 03B70CF2ABEAE4E86DAEF1A36243E44CD61138B89055099C0D220B58FB86FF588A + 1 + + . + 250000 + true + 200 + 0 + false + + + 1 + 1 + 2 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + + + false + 5 + 100000 + 5 + 10 + false + 33135 + 20 + 2 + + + + txn + 27017 + false + + 1000 + 10000 + + + 0.667 + 10 + 10 + 20 + 2 + 1 + 80 + 1000 + + + true + 10 + 10 + 3 + 5 + 5 + 10 + 5 + + + false + 1 + + + + 2000 + 10 + 3000 + 3000 + 3000 + 180 + 80 + 500 + 60 + 150 + 5 + 30000 + 15000 + 55 + 300 + 3 + 5 + 5 + 10 + 3 + 3 + 12 + 10 + 1 + + + 500000 + 400000 + 50 + 10 + 50 + 80 + 10 + 70 + 2000000000 + 2 + 10 + 5 + 15 + 10 + 5 + 127.0.0.1 + + + true + true + true + + 2 + 3 + 6 + + 10 + 10 + 1000 + 0 + 18 + true + true + + + + 0 + + 128 + 8192 + 0 + + + 128 + 8192 + 2 + 4 + + + + false + false + + 300 + 0.334 + 200 + + + 10 + + + + 4201 + 5 + + 4301 + 127.0.0.1 + true + /tmp/zilliqa.sock + /tmp/scilla-server.sock + scilla-server + false + 4401 + + false + 4501 + false + 2500 + 3 + 1000 + true + + 1 + + 0 + + + + 200 + 5 + + 0.05 + + 3 + + 50 + 10 + 10 + + + 60 + 600 + 3 + 600 + 200 + 3 + 128 + 1 + 128 + 5000000 + 0 + 10000000 + 5 + 100 + 20 + 5 + 5 + + + false + true + false + false + http://127.0.0.1:4202/api + 15000 + 5 + + 5 + + false + 4202 + 5 + 3 + 8 + 32 + 2 + 50 + + 99 + + 5 + 4 + + 1800 + + 1900 + 4 + 5 + + 120 + 10 + 2 + 3 + 360 + 5 + false + + + + 0 + false + 40 + 5 + Zilliqa + Zilliqa-Release + true + 30 + 5 + false + 1 + 2 + 5 + 1 + + + true + /scilla/0/ + bin/scilla-checker + bin/scilla-runner + scilla_files + _build + src/stdlib + init.json + input_state.json + input_blockchain.json + input_message.json + output.json + input + .scilla + .scillib + scilla_libs + false + _fields_map_depth + false + false + + + 0000000000000000000000000000000000000000 + + + 1500 + 10 + + + false + 100 + false + false + 0 + 0 + + false + + + 8400000000000000000000 + 176000000000000000 + 12600000000000000000000 + 20 + 40 + 76800 + 20 + 100 + 300 + 3600 + 50 + 0 + 1 + 1572864 + 1024 + 2000000 + true + 0 + 10 + 5 + xxxxxxxxxxx + txnsbackup + false + false + 0.000001 + 3 + + + + + + true + + + 10 + 15 + 10 + 600 + + + + + cc02a3c906612cc5bdb087a30e6093c9f0aa04fc + + + + + + ee06b3c906612cc5bdb087a30e6093c9f0aa04fd + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/products/zilliqa-isolated-server/dsnodes.xml b/products/zilliqa-isolated-server/dsnodes.xml new file mode 100644 index 000000000..c36564e03 --- /dev/null +++ b/products/zilliqa-isolated-server/dsnodes.xml @@ -0,0 +1,4 @@ + + + 03B70CF2ABEAE4E86DAEF1A36243E44CD61138B89055099C0D220B58FB86FF588A + diff --git a/products/zilliqa-isolated-server/local_scripts/download_persistence.sh b/products/zilliqa-isolated-server/local_scripts/download_persistence.sh new file mode 100755 index 000000000..c2dab2eb5 --- /dev/null +++ b/products/zilliqa-isolated-server/local_scripts/download_persistence.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +function print_help { + echo "Please input a mainnet-persistence WITHOUT the .tar.gz extension (eg: mainnet-istana-830788)" + echo "If you need to add access to the mainnet s3 persistence, add the following canonical id:" + echo $(aws s3api list-buckets --query Owner.ID --output text) + echo "to the persistence on mainnet s3, then run the command again" + echo + echo + echo +} + +if [ $# -eq 0 ]; then + print_help +else + echo "pwd is :$(pwd)" + echo "Checking if download directory exists" + if [ ! -d "$(pwd)/downloads" ]; then + echo "Directory does not exist!, creating a downloads folder" + mkdir -p "$(pwd)/downloads" + fi + echo "Persistence to be used: $1" + echo "Attempting to copy persistence" + if [ -f "$(pwd)/downloads/$1.tar.gz" ]; then + echo "$1.tar.gz exists, skipping download." + else + aws s3 cp s3://$BUCKET_ID/persistence/"$1.tar.gz" "$(pwd)/downloads/" + if [ $? -eq 0 ]; then + echo "Copy successful!" + else + print_help + exit + fi + fi +fi diff --git a/products/zilliqa-isolated-server/local_scripts/rebuild_image.sh b/products/zilliqa-isolated-server/local_scripts/rebuild_image.sh new file mode 100755 index 000000000..2aec626e6 --- /dev/null +++ b/products/zilliqa-isolated-server/local_scripts/rebuild_image.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +docker stop zilliqa-isolated-server +docker rm zilliqa-isolated-server +docker rmi zilliqa-isolated-server:1.0 +docker build -t zilliqa-isolated-server:1.0 . diff --git a/products/zilliqa-isolated-server/local_scripts/run_isolated_with_persistence.sh b/products/zilliqa-isolated-server/local_scripts/run_isolated_with_persistence.sh new file mode 100755 index 000000000..25a5b5164 --- /dev/null +++ b/products/zilliqa-isolated-server/local_scripts/run_isolated_with_persistence.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +function print_help { + echo "Please input a mainnet-persistence WITHOUT the .tar.gz extension (eg: mainnet-istana-830788)" + echo + echo + echo +} + +function print_help2 { + echo "Please make sure that $(pwd)/downloads/$1.tar.gz exists in $(pwd)/downloads folder." + echo + echo + echo +} + +if [ $# -eq 0 ]; then + print_help +else + echo "pwd is :$(pwd)" + echo "Checking if $(pwd).tar.gz exists" + if [ ! -f "$(pwd)/downloads/$1.tar.gz" ]; then + print_help2 + exit + else + echo "It's ok for errors to appear between the 2 arrows." + echo " |" + echo " v" + docker stop zilliqa-isolated-server + docker rm zilliqa-isolated-server + echo " ^" + echo " |" + + sudo rm -rf "$(pwd)/persistence/$1" + echo "Persistence to be used: $1" + + mkdir -p "$(pwd)/persistence/$1" + tar -xf "$(pwd)/downloads/$1.tar.gz" -C "$(pwd)/persistence/$1" + + docker run -d --name zilliqa-isolated-server -p 5555:5555 --env MODE="load" -v "$(pwd)/persistence/$1/persistence":"/zilliqa/persistence" zilliqa-isolated-server:1.0 + fi +fi diff --git a/products/zilliqa-isolated-server/local_scripts/stop_isolated.sh b/products/zilliqa-isolated-server/local_scripts/stop_isolated.sh new file mode 100755 index 000000000..ad34176ca --- /dev/null +++ b/products/zilliqa-isolated-server/local_scripts/stop_isolated.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +docker stop zilliqa-isolated-server +docker rm zilliqa-isolated-server diff --git a/products/zilliqa-isolated-server/run.sh b/products/zilliqa-isolated-server/run.sh new file mode 100755 index 000000000..0b67bb958 --- /dev/null +++ b/products/zilliqa-isolated-server/run.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +echo $AWS_INFRA_MODE +echo $VALIDATOR_MODE + +"${UUID:=uuid}" +"${T:=5000}" + +echo $T +echo $UUID + +if [ "$MANUAL_MODE" == "true" ]; then + isolatedServer -f boot.json -u "$UUID" | tee /zilliqa/logs/isolated-server.log +elif [ "$VALIDATOR_MODE" == "true" ]; then + echo "Running in validator mode." + ./validate.sh +else + echo "Running in non-validator mode." + if [ "$AWS_INFRA_MODE" == "true" ]; then + aws s3api head-object --bucket $S3_BUCKET_NAME --key latest_backup.txt || latest_backup_not_exist=true + if [ $latest_backup_not_exist ]; then + echo "latest_backup.txt does not exist, start from boot.json." + MODE="noload" + else + echo "latest_backup.txt exists, proceeding to download" + aws s3 cp "s3://$S3_BUCKET_NAME/latest_backup.txt" . + backup_name=$(cat latest_backup.txt) + echo "latest_backup is $backup_name" + aws s3api head-object --bucket $S3_BUCKET_NAME --key persistence/$backup_name || backup_file_not_exist=true + if [ $backup_file_not_exist ]; then + echo "latest backup file does not exist, start from boot.json." + MODE="noload" + else + aws s3 cp "s3://$S3_BUCKET_NAME/persistence/$backup_name" . + rm -rf persistence/* + mkdir -p persistence + tar -zxf $backup_name persistence + MODE="load" + fi + fi + fi + + echo $MODE + if [ "$MODE" == "load" ]; then + echo "loading persistence." + isolatedServer -l -t "$T" -u "$UUID" | tee /zilliqa/logs/isolated-server.log + else + echo "loading from file." + echo "UUID is: $UUID" + isolatedServer -t "$T" -f boot.json -u "$UUID" | tee /zilliqa/logs/isolated-server.log + fi +fi diff --git a/products/zilliqa-isolated-server/run_docker.sh b/products/zilliqa-isolated-server/run_docker.sh new file mode 100755 index 000000000..fb69c25a6 --- /dev/null +++ b/products/zilliqa-isolated-server/run_docker.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +docker stop zilliqaisolatedserver +docker rm zilliqaisolatedserver + +docker run -d -p 5555:5555 --name zilliqaisolatedserver zilliqaisolatedserver:1.0 diff --git a/products/zilliqa-isolated-server/upgrade_maintenance/UPGRADE.md b/products/zilliqa-isolated-server/upgrade_maintenance/UPGRADE.md new file mode 100644 index 000000000..e53447b60 --- /dev/null +++ b/products/zilliqa-isolated-server/upgrade_maintenance/UPGRADE.md @@ -0,0 +1,35 @@ +## Edit the constants.xml + +You would need to download the latest constants.xml file that can be found on the mainnet join page + +``` +curl -O https://mainnet-join.zilliqa.com/seed-configuration.tar.gz +tar -zxvf seed-configuration.tar.gz +vim constants.xml +``` + +Keep the following tags set to these values + +- `true` +- `222` +- `3` +- `03B70CF2ABEAE4E86DAEF1A36243E44CD61138B89055099C0D220B58FB86FF588A` +- `false` +- `true` +- `/scilla/0/` +- `input` +- `false` +- `true` +- `` is empty + +IGNORE the following sections and their subsections + +- `` +- `` +- `` +- `` +- `` +- `` +- `` +- `` +- `` diff --git a/products/zilliqa-isolated-server/validate.sh b/products/zilliqa-isolated-server/validate.sh new file mode 100755 index 000000000..623d470f9 --- /dev/null +++ b/products/zilliqa-isolated-server/validate.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +function validate_persistence() { + rm -rf validate_persistence + mkdir validate_persistence + rsync -r persistence/* validate_persistence + # Pause + curl -d '{"id": "1","jsonrpc": "2.0","method": "TogglePause","params": ["'$UUID'"]}' -H "Content-Type: application/json" -X POST "http://localhost:5555/" + curl -d '{"id": "1","jsonrpc": "2.0","method": "CheckPause","params": ["'$UUID'"]}' -H "Content-Type: application/json" -X POST "http://localhost:5555/" + rsync -r persistence/* validate_persistence + # Unpause + curl -d '{"id": "1","jsonrpc": "2.0","method": "TogglePause","params": ["'$UUID'"]}' -H "Content-Type: application/json" -X POST "http://localhost:5555/" + curl -d '{"id": "1","jsonrpc": "2.0","method": "CheckPause","params": ["'$UUID'"]}' -H "Content-Type: application/json" -X POST "http://localhost:5555/" + cp constants.xml validate_persistence + cp dsnodes.xml validate_persistence + + backup_name="persistence_$current_date""_""$current_time.tar.gz" + echo "$backup_name" + s3_bucket_name="$S3_BUCKET_NAME" + + base_dir=$(pwd) + cd validate_persistence + validate_output="$(validateDB)" + if echo $validate_output | grep -q "Success"; then + echo "validation successful!" + # zip persistence upload to s3 + echo $backup_name >latest_backup.txt + tar -zcf $backup_name persistence + aws s3 cp "$backup_name" "s3://$s3_bucket_name/persistence/$backup_name" + aws s3 cp "latest_backup.txt" "s3://$s3_bucket_name" + else + echo "validation failed." + fi + + cd $base_dir + sleep 1 +} + +while [ true ]; do + current_date="$(date +%Y%m%d)" + current_time="$(date +%H%M%S)" + + if [ $current_time = "160000" ]; then + validate_persistence + fi + + #temp_current_time="$(date +%S)" + #if [ $temp_current_time = "00" ]; then + # validate_persistence + #fi + + sleep 0.5 +done diff --git a/products/zilliqa-isolated-server/z.yaml b/products/zilliqa-isolated-server/z.yaml new file mode 100644 index 000000000..7f44527f0 --- /dev/null +++ b/products/zilliqa-isolated-server/z.yaml @@ -0,0 +1,17 @@ +backend: kind +default_cluster: main +kind: dev + +clusters: + main: + name: main + region: localhost + manifests: {} + apps: + zilliqa-isolated-server: + path: products/zilliqa-isolated-server/cd/base + track: development + type: kustomize + namespace: zilliqa-isolated-server + +databases: {}