diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c9cbdb5..2b0851e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,5 +42,5 @@ jobs: - name: Build and push image run: | - docker build . --file docker/Dockerfile --tag ${{ steps.image.outputs.name }} + docker build . --file cicd/Dockerfile --tag ${{ steps.image.outputs.name }} docker push ${{ steps.image.outputs.name }} \ No newline at end of file diff --git a/.github/workflows/pr_build.yml b/.github/workflows/pr_build.yml index b2c2184..8b2d57e 100644 --- a/.github/workflows/pr_build.yml +++ b/.github/workflows/pr_build.yml @@ -1,6 +1,6 @@ name: Build custom branch on: - pull_request_target: + pull_request: branches: - master @@ -47,5 +47,5 @@ jobs: - name: Build and push image run: | - docker build . --file docker/Dockerfile --tag ${{ steps.image.outputs.name }} + docker build . --file cicd/Dockerfile --tag ${{ steps.image.outputs.name }} docker push ${{ steps.image.outputs.name }} diff --git a/cicd/.env.example b/cicd/.env.example new file mode 100644 index 0000000..2680960 --- /dev/null +++ b/cicd/.env.example @@ -0,0 +1,4 @@ +PARENTNET_URL= +SUBNET_URL= +PARENTNET_WALLET_PK=0x2222222222222222222222222222222222222222222222222222222222222222 +SUBNET_WALLET_PK=0x1111111111111111111111111111111111111111111111111111111111111111 diff --git a/cicd/.gitignore b/cicd/.gitignore new file mode 100644 index 0000000..fff3db5 --- /dev/null +++ b/cicd/.gitignore @@ -0,0 +1,7 @@ +node_modules +.env +package-lock.json +mount/* +!mount/placeholder.txt +yarn.lock +other \ No newline at end of file diff --git a/cicd/Dockerfile b/cicd/Dockerfile new file mode 100644 index 0000000..b39b4f0 --- /dev/null +++ b/cicd/Dockerfile @@ -0,0 +1,11 @@ +FROM node:20-alpine + +COPY . /app + +WORKDIR /app +RUN yarn +RUN npx hardhat compile +WORKDIR /app/cicd +RUN yarn + +ENTRYPOINT ["node"] \ No newline at end of file diff --git a/cicd/Dockerfile.dockerignore b/cicd/Dockerfile.dockerignore new file mode 100644 index 0000000..64a4213 --- /dev/null +++ b/cicd/Dockerfile.dockerignore @@ -0,0 +1,2 @@ +**node_modules +**package-lock.json \ No newline at end of file diff --git a/cicd/README.md b/cicd/README.md new file mode 100644 index 0000000..49d4c29 --- /dev/null +++ b/cicd/README.md @@ -0,0 +1,70 @@ +# XDC CSC CICD + +## Deploy XDC CSC + +#### Step 1: Create a `.env` File + +Based on the provided `.env.example`, create your own `.env` file with the following details: + +- **`PARENTNET_URL`**: RPC URL for the parentnet endpoint. +- **`SUBNET_URL`**: RPC URL for the subnet. +- **`PARENTNET_WALLET_PK`**: Private key used for CSC deployment, there should be some funds. +- **`SUBNET_WALLET_PK`**: Private key for subnet deployment. (only required for reverse CSC) + +#### Step 2: Deploy CSC +You have a choice to deploy one of three types of CSC + +Full CSC: + +```shell +docker run --env-file .env xinfinorg/csc:latest full.js +``` + +Reverse CSC: + +```shell +docker run --env-file .env xinfinorg/csc:latest reversefull.js +``` + +Lite CSC: + +```shell +docker run --env-file .env xinfinorg/csc:latest lite.js +``` + + +## Deploy XDC CSC at Custom Block Height +#### Step 1: Create a `.env` File to cicd/mount + +Based on the provided `.env.example`, create your own `.env` file with the following details: + +- **`PARENTNET_URL`**: RPC URL for the parentnet endpoint. +- **`SUBNET_URL`**: RPC URL for the subnet. +- **`PARENTNET_WALLET_PK`**: Private key used for CSC deployment, there should be some funds. +- **`SUBNET_WALLET_PK`**: Private key for subnet deployment. (only required for reverse CSC) + +#### Step 2: Create a `deployment.config.json` File to cicd/mount + +Check the main README in upper directory and deployment.config.json.example to understand the configurations + +#### Step 3: Deploy CSC + +You have a choice to deploy one of three types of CSC + +Full CSC: + +```shell +docker run -v $(pwd)/mount:/app/cicd/mount xinfinorg/csc:latest full.js +``` + +Reverse CSC: + +```shell +docker run -v $(pwd)/mount:/app/cicd/mount xinfinorg/csc:latest reversefull.js +``` + +Lite CSC: + +```shell +docker run -v $(pwd)/mount:/app/cicd/mount xinfinorg/csc:latest lite.js +``` \ No newline at end of file diff --git a/cicd/full.js b/cicd/full.js new file mode 100644 index 0000000..67e8bce --- /dev/null +++ b/cicd/full.js @@ -0,0 +1,133 @@ +process.chdir(__dirname); +const { execSync } = require("child_process"); +const fs = require("node:fs"); +const env = require("dotenv").config({ path: "mount/.env" }); +const config = { + relativePath: "../", +}; +const u = require("./util.js"); + +main(); + +async function main() { + console.log("start deploying full CSC"); + initDeployFull(); + await configureFiles(); + deployFull(); + exportFull(); +} + +function initDeployFull() { + const reqENV = ["PARENTNET_URL", "SUBNET_URL", "PARENTNET_WALLET_PK"]; + const isEnabled = reqENV.every((envVar) => envVar in process.env); + if (!isEnabled) { + throw Error( + "incomplete ENVs, require PARENTNET_URL, SUBNET_URL, PARENTNET_WALLET_PK" + ); + } + parentnetPK = process.env.PARENTNET_WALLET_PK.startsWith("0x") + ? process.env.PARENTNET_WALLET_PK + : `0x${process.env.PARENTNET_WALLET_PK}`; + config["parentnetPK"] = parentnetPK; + config["parentnetURL"] = process.env.PARENTNET_URL; + config["subnetURL"] = process.env.SUBNET_URL; +} + +async function configureFiles() { + u.writeEnv(config.parentnetPK, config.relativePath); + u.writeNetworkJson(config); + + if (fs.existsSync("./mount/deployment.config.json")) { + const dpjs = JSON.parse( + fs.readFileSync("./mount/deployment.config.json", "utf8") + ); + console.log( + "copying mounted deployment.config.json, start subnet block:", + dpjs.subnet.gsbn + ); + + fs.copyFile( + "mount/deployment.config.json", + `${config.relativePath}/deployment.config.json`, + (err) => { + if (err) { + throw Error("error writing deployment.config.json, " + err); + } + } + ); + } else { + gap = await u.getGapSubnet(config); + writeFullDeployJson(gap); + } +} + +function deployFull() { + console.log("deploying full csc"); + fullDeployOut = u.callExec( + ` + cd ${config.relativePath}; + npx hardhat run scripts/FullCheckpointDeploy.js --network xdcparentnet + ` + ); + fullCSC = parseFullOut(fullDeployOut); + config["fullCSC"] = fullCSC; +} + +function exportFull() { + console.log( + "SUCCESS deploy full csc, please include the following line in your common.env" + ); + console.log(`CHECKPOINT_CONTRACT=${config.fullCSC}\n`); + fs.appendFileSync( + "mount/csc.env", + `\nFULL_CSC=${config.fullCSC}\n`, + "utf-8", + (err) => { + if (err) { + throw Error("error writing mount/csc.env, " + err); + } + } + ); +} + +function parseFullOut(outString) { + strArr = outString.split("\n"); + lastLine = strArr[strArr.length - 1]; + if (lastLine == "") { + strArr.pop(); + lastLine = strArr[strArr.length - 1]; + } + if (lastLine.includes("0x")) { + idx = lastLine.indexOf("0x"); + address = lastLine.slice(idx, idx + 42); + return address; + } else { + throw Error("invalid output string: " + outString); + } +} + +function writeFullDeployJson(gsbn) { + console.log("writing deployment configuration, start subnet block:", gsbn); + deployJson = { + subnet: { + gap: 450, + epoch: 900, + gsbn: gsbn, + }, + }; + fs.writeFileSync( + `${config.relativePath}/deployment.config.json`, + JSON.stringify(deployJson, null, 2), + "utf-8", + (err) => { + if (err) { + throw Error("error writing deployment.config.json, " + err); + } + } + ); + // "subnet": { + // "gap": 450, + // "epoch": 900, + // "gsbn": 1500751 + // }, +} diff --git a/cicd/lite.js b/cicd/lite.js new file mode 100644 index 0000000..edcc4d8 --- /dev/null +++ b/cicd/lite.js @@ -0,0 +1,129 @@ +process.chdir(__dirname); +const { execSync } = require("child_process"); +const fs = require("node:fs"); +const env = require("dotenv").config({ path: "mount/.env" }); +const config = { + relativePath: "../", +}; +const u = require("./util.js"); + +main(); + +async function main() { + console.log("start deploying lite CSC"); + initDeployLite(); + await configureFiles(); + deployLite(); + exportLite(); +} + +function initDeployLite() { + const reqENV = ["PARENTNET_URL", "SUBNET_URL", "PARENTNET_WALLET_PK"]; + const isEnabled = reqENV.every((envVar) => envVar in process.env); + if (!isEnabled) { + throw Error( + "incomplete ENVs, require PARENTNET_URL, SUBNET_URL, PARENTNET_WALLET_PK" + ); + } + parentnetPK = process.env.PARENTNET_WALLET_PK.startsWith("0x") + ? process.env.PARENTNET_WALLET_PK + : `0x${process.env.PARENTNET_WALLET_PK}`; + config["parentnetPK"] = parentnetPK; + config["parentnetURL"] = process.env.PARENTNET_URL; + config["subnetURL"] = process.env.SUBNET_URL; +} + +async function configureFiles() { + u.writeEnv(config.parentnetPK, config.relativePath); + u.writeNetworkJson(config); + + if (fs.existsSync("./mount/deployment.config.json")) { + const dpjs = JSON.parse( + fs.readFileSync("./mount/deployment.config.json", "utf8") + ); + console.log( + "copying mounted deployment.config.json, start subnet block:", + dpjs.subnet.gsbn + ); + + fs.copyFile( + "mount/deployment.config.json", + `${config.relativePath}/deployment.config.json`, + (err) => { + if (err) { + throw Error("error writing deployment.config.json, " + err); + } + } + ); + } else { + gap = await u.getGapSubnet(config); + writeLiteDeployJson(gap); + } +} + +function deployLite() { + console.log("deploying lite csc"); + liteDeployOut = u.callExec( + ` + cd ${config.relativePath}; + npx hardhat run scripts/LiteCheckpointDeploy.js --network xdcparentnet + ` + ); + liteCSC = parseLiteOut(liteDeployOut); + config["liteCSC"]=liteCSC +} + +function exportLite() { + console.log( + "SUCCESS deploy lite csc, please include the following line in your common.env" + ); + console.log(`CHECKPOINT_CONTRACT=${config.liteCSC}\n`); + fs.appendFileSync( + "mount/csc.env", + `\nLITE_CSC=${config.liteCSC}\n`, + "utf-8", + (err) => { + if (err) { + throw Error("error writing mount/csc.env, " + err); + } + } + ); +} + + +function parseLiteOut(outString) { + strArr = outString.split("\n"); + lastLine = strArr[strArr.length - 1]; + if (lastLine == "") { + strArr.pop(); + lastLine = strArr[strArr.length - 1]; + } + if (lastLine.includes("0x")) { + idx = lastLine.indexOf("0x"); + address = lastLine.slice(idx, idx + 42); + return address; + } else { + throw Error("invalid output string: " + outString); + } +} + +function writeLiteDeployJson(gsbn) { + console.log("writing deployment configuration, start subnet block:", gsbn); + deployJson = { + subnet: { + gap: 450, + epoch: 900, + gsbn: gsbn, + }, + }; + fs.writeFileSync( + `${config.relativePath}/deployment.config.json`, + JSON.stringify(deployJson, null, 2), + "utf-8", + (err) => { + if (err) { + throw Error("error writing deployment.config.json, " + err); + } + } + ); +} diff --git a/cicd/mount/placeholder.txt b/cicd/mount/placeholder.txt new file mode 100644 index 0000000..e69de29 diff --git a/cicd/package.json b/cicd/package.json new file mode 100644 index 0000000..6efbc58 --- /dev/null +++ b/cicd/package.json @@ -0,0 +1,8 @@ +{ + "name": "csc-cicd", + "dependencies": { + "dotenv": "^16.3.1", + "ethers": "^5.7.2", + "axios": "^1.7.2" + } +} diff --git a/cicd/reversefull.js b/cicd/reversefull.js new file mode 100644 index 0000000..695c4bc --- /dev/null +++ b/cicd/reversefull.js @@ -0,0 +1,134 @@ +process.chdir(__dirname); +const { execSync } = require("child_process"); +const fs = require("node:fs"); +const env = require("dotenv").config({ path: "mount/.env" }); +const config = { + relativePath: "../", +}; +const u = require("./util.js"); + +main(); + +async function main() { + console.log("start deploying reverse CSC"); + initDeployReverse(); + await configureFiles(); + deployReverse(); + exportReverse(); +} + +function initDeployReverse() { + const reqENV = ["PARENTNET_URL", "SUBNET_URL", "SUBNET_WALLET_PK"]; + const isEnabled = reqENV.every((envVar) => envVar in process.env); + if (!isEnabled) { + throw Error( + "incomplete ENVs, require PARENTNET_URL, SUBNET_URL, SUBNET_WALLET_PK" + ); + } + subnetPK = process.env.SUBNET_WALLET_PK.startsWith("0x") + ? process.env.SUBNET_WALLET_PK + : `0x${process.env.SUBNET_WALLET_PK}`; + config["parentnetURL"] = process.env.PARENTNET_URL; + config["subnetURL"] = process.env.SUBNET_URL; + config["subnetPK"] = subnetPK; +} + +async function configureFiles() { + u.writeEnv(config.subnetPK, config.relativePath); + u.writeNetworkJson(config); + + if (fs.existsSync("./mount/deployment.config.json")) { + const dpjs = JSON.parse( + fs.readFileSync("./mount/deployment.config.json", "utf8") + ); + console.log( + "copying mounted deployment.config.json, start parentnet block:", + dpjs.parentnet.v2esbn + ); + + fs.copyFile( + "mount/deployment.config.json", + `${config.relativePath}/deployment.config.json`, + (err) => { + if (err) { + throw Error("error writing deployment.config.json, " + err); + } + } + ); + } else { + epoch = await u.getEpochParentnet(config); + writeReverseDeployJson(epoch); + } +} + +function deployReverse() { + console.log("deploying reverse csc"); + reverseDeployOut = u.callExec( + ` + cd ${config.relativePath}; + npx hardhat run scripts/ReverseFullCheckpointDeploy.js --network xdcsubnet + ` + ); + reverseCSC = parseReverseOut(reverseDeployOut); + config["reverseCSC"] = reverseCSC; +} + +function exportReverse() { + console.log( + "SUCCESS deploy reverse csc, please include the following line in your common.env" + ); + console.log(`REVERSE_CHECKPOINT_CONTRACT=${config.reverseCSC}\n`); + fs.appendFileSync( + "mount/csc.env", + `\nREVERSE_CSC=${config.reverseCSC}\n`, + "utf-8", + (err) => { + if (err) { + throw Error("error writing mount/csc.env, " + err); + } + } + ); +} + +function parseReverseOut(outString) { + strArr = outString.split("\n"); + lastLine = strArr[strArr.length - 1]; + if (lastLine == "") { + strArr.pop(); + lastLine = strArr[strArr.length - 1]; + } + if (lastLine.includes("0x")) { + idx = lastLine.indexOf("0x"); + address = lastLine.slice(idx, idx + 42); + return address; + } else { + throw Error("invalid output string: " + outString); + } +} + +function writeReverseDeployJson(v2esbn) { + console.log( + "writing deployment configuration, start parentnet block:", v2esbn + ); + deployJson = { + parentnet:{ + epoch: 900, + v2esbn: v2esbn, + } + }; + fs.writeFileSync( + `${config.relativePath}/deployment.config.json`, + JSON.stringify(deployJson, null, 2), + "utf-8", + (err) => { + if (err) { + throw Error("error writing deployment.config.json, " + err); + } + } + ); + // "subnet": { + // "gap": 450, + // "epoch": 900, + // "gsbn": 1500751 + // }, +} diff --git a/cicd/util.js b/cicd/util.js new file mode 100644 index 0000000..35d6156 --- /dev/null +++ b/cicd/util.js @@ -0,0 +1,112 @@ +process.chdir(__dirname); +const { execSync } = require("child_process"); +const fs = require("node:fs"); +const env = require("dotenv").config({ path: "mount/.env" }); + +const { ethers } = require("ethers"); +const axios = require("axios"); + +function writeEnv(key, path) { + content = "PRIVATE_KEY=" + key; + fullPath = path + "/" + ".env"; + fs.writeFileSync(fullPath, content, (err) => { + if (err) { + throw Error(`error writing ${fullPath}, ` + err); + } + }); +} + +function writeNetworkJson(config) { + networkJson = { + xdcsubnet: config.subnetURL, + xdcparentnet: config.parentnetURL, + xdcdevnet: "", //dummy + xdctestnet: "", + }; + writeJson(networkJson, config.relativePath, "network.config.json"); +} + +function writeJson(obj, path, filename) { + fullPath = path + "/" + filename; + fs.writeFileSync(fullPath, JSON.stringify(obj, null, 2), "utf-8", (err) => { + if (err) { + throw Error(`error writing ${fullPath}, ` + err); + } + }); +} + +function callExec(command) { + try { + const stdout = execSync(command, { timeout: 200000 }); + // const stdout = execSync(command) + output = stdout.toString(); + // console.log(`${stdout}`); + console.log(output); + return output; + } catch (error) { + if (error.code) { + // Spawning child process failed + if (error.code == "ETIMEDOUT") { + throw Error("Timed out (200 seconds)"); + } else { + throw Error(error); + } + } else { + // Child was spawned but exited with non-zero exit code + // Error contains any stdout and stderr from the child + // const { stdout, stderr } = error; + // console.error({ stdout, stderr }); + throw Error(error); + } + } +} + +async function getGapSubnet(config) { + console.log("getting subnet latest gap block") + const data = { + jsonrpc: "2.0", + method: "XDPoS_getMissedRoundsInEpochByBlockNum", + params: ["latest"], + id: 1, + }; + await axios.post(config.subnetURL, data).then((response) => { + if (response.status == 200) { + epochBlockNum = response.data.result.EpochBlockNumber; + gapBlockNum = epochBlockNum-450+1 + } else { + console.log("response.status", response.status); + // console.log("response.data", response.data); + throw Error("could not get gapblock in subnet"); + } + }); + return gapBlockNum +} + +async function getEpochParentnet(config) { + console.log("getting parentnet latest epoch start block") + const data = { + jsonrpc: "2.0", + method: "XDPoS_getMissedRoundsInEpochByBlockNum", + params: ["latest"], + id: 1, + }; + await axios.post(config.parentnetURL, data).then((response) => { + if (response.status == 200) { + epochBlockNum = response.data.result.EpochBlockNumber; + console.log("epochBlockNum", epochBlockNum) + } else { + console.log("response.status", response.status); + // console.log("response.data", response.data); + throw Error("could not get epoch block in parentnet"); + } + }); + return epochBlockNum +} + +module.exports = { + callExec, + writeEnv, + writeNetworkJson, + getGapSubnet, + getEpochParentnet, +}; diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index e96f3fe..0000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM node:18.15 - -WORKDIR /app - -COPY . /app - -RUN yarn - -RUN chmod +x /app/docker/deploy_proxy.sh -RUN chmod +x /app/docker/upgrade_csc.sh - - -# ENTRYPOINT ["sleep", "infinity"] -# ENTRYPOINT ["bash -c","sleep 100"] -# ENTRYPOINT ["bash","/app/docker/deploy_csc.sh"] \ No newline at end of file diff --git a/docker/README_DOCKER b/docker/README_DOCKER deleted file mode 100644 index 3a8007b..0000000 --- a/docker/README_DOCKER +++ /dev/null @@ -1,18 +0,0 @@ - -1. Always specify entrypoint script, no default entrypoint. - - deploy_proxy.sh: deploy new proxy gateway and initialize CSC - - upgrade_csc.sh: upgrade proxy gateway to the CSC of the current image version. - - deploy_csc.sh: deploy non-upgradable CSC (old method) -2. Mount js configs to /app/config directory - - deployment.config.json: used in all scripts - - upgrade.config.json: used in 'upgrade_csc.sh' -3. ENV can be injected with '--env-file' - - PARENTNET_WALLET_PK or PRIVATE_KEY: either can be used - - PARENTNET: 'devnet' or 'testnet' - - RELAYER_MODE: 'full' or 'lite', only used in 'deploy_csc.sh' - -* The PARENTCHAIN_WALLET_PK that is used for upgrading CSC should be the same as the initilise CSC private key. - - -Example for mounting your current directory -docker run --env-file .env -v $PWD:/app/config --entrypoint './docker/deploy_proxy.sh' xinfinorg/csc:latest \ No newline at end of file diff --git a/docker/deploy_proxy.sh b/docker/deploy_proxy.sh deleted file mode 100755 index e15348d..0000000 --- a/docker/deploy_proxy.sh +++ /dev/null @@ -1,82 +0,0 @@ -#!/bin/bash -set -e - -cd /app -cp /app/config/deployment.config.json /app/deployment.config.json - -#1. check PARENTNET env -#2. check PRIVATE_KEY env -#3. check .env file - -if [[ -n "$PARENTNET_WALLET_PK" ]]; then - PRIVATE_KEY=${PARENTNET_WALLET_PK} -fi - - -if [[ -z "$PRIVATE_KEY" ]]; then - source /app/config/.env || echo '' -fi - -if [[ -z "$PRIVATE_KEY" ]]; then - if [[ -n "$PARENTNET_WALLET_PK" ]]; then - PRIVATE_KEY=${PARENTNET_WALLET_PK} - else - echo "PARENTNET_WALLET_PK or PRIVATE_KEY not set" - exit 1 - fi -fi - -if [[ ${PRIVATE_KEY::2} == "0x" ]]; then - PRIVATE_KEY=${PRIVATE_KEY:2} -fi -echo "PRIVATE_KEY=${PRIVATE_KEY}" > .env - -if [[ -z "$PARENTNET_URL" ]]; then - echo "PARENTNET_URL not specified" - exit 1 -else - cat network.config.json | sed -e "s@\"xdcparentnet\".*@\"xdcparentnet\": \"$PARENTNET_URL\",@" > temp.json - mv temp.json network.config.json -fi - -if [[ -z "$SUBNET_URL" ]]; then - echo "SUBNET_URL not specified" - exit 1 -else - cat network.config.json | sed -e "s@\"xdcsubnet\".*@\"xdcsubnet\": \"$SUBNET_URL\",@" > temp.json - mv temp.json network.config.json -fi - -DEPLOY=$(npx hardhat run scripts/proxy/ProxyGatewayDeploy.js --network xdcparentnet) -PROXY=$(echo $DEPLOY | awk '{print $NF}') -echo "Proxy Gateway Deployed: $PROXY" -JSON="{\"proxyGateway\": \"$PROXY\"}" -echo $JSON > upgrade.config.json -echo "" >> config/common.env || echo 'config not mounted' -echo "#Checkpoint Smart Contract (CSC) addresses" >> config/common.env || echo 'config not mounted' -echo "PROXY_GATEWAY=$PROXY" >> config/common.env || echo 'config not mounted' - - -UPGRADE=$(npx hardhat run scripts/proxy/UpgradeCSC.js --network xdcparentnet | awk '{print $NF}') -FULL_CSC=$(echo $UPGRADE | cut -d' ' -f4) -FULL_CSC_LINE="FULL_CSC=$FULL_CSC" -echo $FULL_CSC_LINE >> config/common.env || echo 'config not mounted' - - -LITE_CSC=$(echo $UPGRADE | cut -d' ' -f5) -LITE_CSC_LINE="LITE_CSC=$LITE_CSC" -echo $LITE_CSC_LINE >> config/common.env || echo 'config not mounted' -echo "Upgraded Proxy Gateway with CSC" -echo "$FULL_CSC_LINE" -echo "$LITE_CSC_LINE" - -if [[ $RELAYER_MODE == 'full' ]]; then - echo 'Relayer mode full, updating CHECKPOINT_CONTRACT' - cat config/common.env | sed -e "s/CHECKPOINT_CONTRACT.*/CHECKPOINT_CONTRACT=$FULL_CSC/" > temp.env - mv temp.env config/common.env -fi -if [[ $RELAYER_MODE == 'lite' ]]; then - echo 'Relayer mode lite, updating CHECKPOINT_CONTRACT' - cat config/common.env | sed -e "s/CHECKPOINT_CONTRACT.*/CHECKPOINT_CONTRACT=$LITE_CSC/" > temp.env - mv temp.env config/common.env -fi \ No newline at end of file diff --git a/docker/upgrade_csc.sh b/docker/upgrade_csc.sh deleted file mode 100644 index 974b194..0000000 --- a/docker/upgrade_csc.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash -cd /app -cp /app/config/deployment.config.json /app/deployment.config.json -if [[ -n "$PARENTNET_WALLET_PK" ]]; then - PRIVATE_KEY=${PARENTNET_WALLET_PK} -fi - - -if [[ -z "$PRIVATE_KEY" ]]; then - source /app/config/.env -fi - -if [[ -z "$PRIVATE_KEY" ]]; then - if [[ -n "$PARENTNET_WALLET_PK" ]]; then - PRIVATE_KEY=${PARENTNET_WALLET_PK} - else - echo "PARENTNET_WALLET_PK or PRIVATE_KEY not set" - exit 1 - fi -fi - -if [[ ${PRIVATE_KEY::2} == "0x" ]]; then - PRIVATE_KEY=${PRIVATE_KEY:2} -fi -echo "PRIVATE_KEY=${PRIVATE_KEY}" > .env - -if [[ -z "$PARENTNET_URL" ]]; then - echo "PARENTNET_URL not specified" - exit 1 -else - cat network.config.json | sed -e "s@\"xdcparentnet\".*@\"xdcparentnet\": \"$PARENTNET_URL\",@" > temp.json - mv temp.json network.config.json -fi - -if [[ -z "$SUBNET_URL" ]]; then - echo "SUBNET_URL not specified" - exit 1 -else - cat network.config.json | sed -e "s@\"xdcsubnet\".*@\"xdcsubnet\": \"$SUBNET_URL\",@" > temp.json - mv temp.json network.config.json -fi - -if [[ -z "$PROXY_GATEWAY" ]]; then - echo "PROXY_GATEWAY not specified" - exit 1 -else - JSON="{\"proxyGateway\": \"$PROXY_GATEWAY\"}" - echo $JSON > upgrade.config.json -fi - -npx hardhat run scripts/proxy/UpgradeCSC.js --network xdcparentnet \ No newline at end of file