# Delphinus Cross Chain Deployment Based on fe-lerna and be-lerna ## Summary This is a document about how to deploy zkc project based on zkcross-frontend-lerna repo and zkcross-backend-lerna repo. ## Deploy backend If it is the first time for you to deploy the system, visit [first time to deploy backend](https://hackmd.io/7pL5Lt7YTCm_E_D0X7vOJQ?both#It-is-the-first-time-to-deploy-Delphinus-Backend-on-the-machine). If you just want to upgrade the system which is already deployed and works well, visit [not the first time to deploy backend](https://hackmd.io/7pL5Lt7YTCm_E_D0X7vOJQ?view#It-is-not-the-first-time-to-deploy-Delphinus-Backend-on-the-machine). ### It is the first time to deploy Delphinus Backend on the machine #### Modules which will be installed and deployed * Caddy * Substrate Node * mongoDB * L1 and L2 monitors * History Server * Indexer monitor #### Environment preparing ``` git clone git@github.com:DelphinusLab/zkcross-backend-lerna.git cd zkcross-backend-lerna bash environment_linux.sh restart your shell to update environment variable(such as rustup) // wasm-pack will not be installed if environment variable about rust is not updated bash environment_linux.sh bash setup-backend.sh // Do repo branches changing to those you want deploy // Currently getblock still have issue so need change solity truffle config file to use availabe rpc source bash redobootstrap.sh ``` #### Change rpcSource of the system for deployment If we run `node init.js` in the step [`Deploy layer1 contracts`](https://hackmd.io/7pL5Lt7YTCm_E_D0X7vOJQ?both#Deploy-layer1-contracts), the default rpcSource in `deployment/config/eth-config.ts` maybe unstable. **1. Change `rpcSource` of `bsctestnet` in `deployment/config/eth-config.ts` to `https://data-seed-prebsc-1-s1.binance.org:8545` because rpcSource provided by ankr is unstable:** ``` { chainName: "bsctestnet", mongodbUrl: "mongodb://localhost:27017", syncEventsStep: 2000, bufferBlocks: 0, gasWarningAmount: "1", nativeCurrency: { name: "Test Binance Coin", symbol: "tBNB", // 2-6 characters long decimals: 18, }, blockExplorer: "https://testnet.bscscan.com", //rpcSource: //"https://data-seed-prebsc-1-s1.binance.org:8545", rpcSource: "https://rpc.ankr.com/bsc_testnet_chapel/" + secrets.ankr_id, //ankr is only for monitor reading, for deployment, please use the above common bsc rpc source. wsSource: "wss://rpc.ankr.com/bsc_testnet_chapel/ws/" + secrets.ankr_id, privateKey: secrets.accounts.deployer.priv, monitorAccount: "", deviceId: "97", l2Account: "//Smith", enabled: testnet, isSnap: false, } ``` **2. Change `rpcSource` of `goerli` in `deployment/config/eth-config.ts` to `"https://goerli.infura.io/v3/" + secrets.infura_id_goerli` because rpcSource provided by ankr is unstable:** If `rpcSource` is already infura, skip this step. ``` { chainName: "goerli", mongodbUrl: "mongodb://localhost:27017", syncEventsStep: 2000, //default step 0: sync to latest directly bufferBlocks: 0, gasWarningAmount: "1", nativeCurrency: { name: "Goerli ETH", symbol: "GoETH", // 2-6 characters long decimals: 18, }, blockExplorer: "https://goerli.etherscan.io", rpcSource: "https://goerli.infura.io/v3/" + secrets.infura_id_goerli, wsSource: "wss://goerli.infura.io/ws/v3/" + secrets.infura_id_goerli, //We find ankr's goerli provider is not stable so still use infura for goerli //rpcSource: "https://rpc.ankr.com/eth_goerli/" + secrets.ankr_id, //wsSource: "wss://rpc.ankr.com/eth_goerli/ws/" + secrets.ankr_id, privateKey: secrets.accounts.deployer.priv, monitorAccount: "", deviceId: "5", l2Account: "//Frank", enabled: testnet, isSnap: true, } ``` If these address is still unstable, you should find other alternatives. #### Change Credential of the system **1. In `deployment/config/eth-config.ts`, update `monitorAccount` of `bsctestnet`, `goerli`, `cronostestnet` and `rolluxtestnet`.** For example, this is the configure of `bsctestnet` and there is a key `monitorAccount`. Update `monitorAccount`'s value: ``` { chainName: "bsctestnet", mongodbUrl: "mongodb://localhost:27017", syncEventsStep: 2000, bufferBlocks: 0, gasWarningAmount: "1", nativeCurrency: { name: "Test Binance Coin", symbol: "tBNB", // 2-6 characters long decimals: 18, }, blockExplorer: "https://testnet.bscscan.com", //rpcSource: //"https://data-seed-prebsc-1-s1.binance.org:8545", rpcSource: "https://rpc.ankr.com/bsc_testnet_chapel/" + secrets.ankr_id, //ankr is only for monitor reading, for deployment, please use the above common bsc rpc source. wsSource: "wss://rpc.ankr.com/bsc_testnet_chapel/ws/" + secrets.ankr_id, privateKey: secrets.accounts.deployer.priv, monitorAccount: "", // update here deviceId: "97", l2Account: "//Smith", enabled: testnet, isSnap: false, } ``` **2. Update deployer priv key in `deployment/config/monitor-secrets.json`** ``` { "ankr_id":"", "infura_id_goerli":"", "getblock_key_bsctestnet":"", "getblock_key_goerli":"", "accounts": { "deployer": { "priv": "" // update here }, "tester": { "priv":"" }, "tester2": { "priv":"" }, "monitor": { "priv":"" } } } ``` **3. Run `npx tsx` in `deployment`** #### Start Caddy If you want to run Substrate node on **remote host**. A remote Substrate node can be accessible **only** after we set up a secure proxy for websocket connections. The TLS certificate is obtained automatically with `Caddy`. ***1. Install Caddy*** ``` sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list sudo apt update sudo apt install caddy ``` **2. Add a file named "Caddyfile" to directory `zkcross-backend-lerna`** ``` { auto_https disable_redirects } test.example.com:9944 { reverse_proxy 127.0.0.1:9966 } test.example.com:8090 { reverse_proxy 127.0.0.1:8091 } ``` **3. Start Caddy** ``` sudo caddy run --config ./Caddyfile ``` If we are using `127.0.0.1` for local testing, caddy can be ignored. #### Setup zkp and get verifier contract **1. Create ptau files**. In `zkp/circom`, run: ``` bash tools/setup.sh ``` **2. Create `verifier.sol`** In `zkp/circom`, run: ``` bash tools/compile.sh ``` #### Deploy layer1 contracts **0. Use tool to check we have enough eth for the testnetworks** In `zkcross-backend-lerna/`, run: `node packages/monitors/src/tools/ethBalanceCheck/eth-balance-check-tool.js goerli` `node packages/monitors/src/tools/ethBalanceCheck/eth-balance-check-tool.js bsctestnet` `node packages/monitors/src/tools/ethBalanceCheck/eth-balance-check-tool.js cronostestnet` `node packages/monitors/src/tools/ethBalanceCheck/eth-balance-check-tool.js rolluxtestnet` to check. Better both are above 1 unit. **1. If you deploy delphinus for the first time (normally we should skip this and go to point 2, especially when we deploy prod test server by default networks)** In `zkcross-lerna`, run **manually**: ``` cp packages/zkp/circom/verifier.sol packages/solidity/contracts/ZKPVerifier.sol sed -i "s/\^0.6.11/^0.8.0/" packages/solidity/contracts/ZKPVerifier.sol cd packages/monitors/src/tools node init_BlockHeight.js cd - cd packages/solidity npx truffle migrate --network goerli //Only do it if this is new network, do `npx truffle migrate --f 2 --to 2 --network goerli` instead if goerli is not new. npx truffle migrate --network bsctestnet //Only do it if this is new network, do `npx truffle migrate --f 2 --to 2 --network bsctestnet` instead if bsctestnet is not new. npx truffle migrate --network cronostestnet //Only do it if this is new network, do `npx truffle migrate --f 2 --to 2 --network cronostestnet` instead if cronostestnet is not new. npx truffle migrate --network rolluxtestnet //Only do it if this is new network, do `npx truffle migrate --f 2 --to 2 --network rolluxtestnet` instead if rolluxtestnet is not new. cd - cd packages/solidity/clients/ node config-contracts-info.js cd - cd packages/solidity/clients/tools/bridge node init.js goerli node init.js bsctestnet node init.js cronostestnet node init.js rolluxtestnet cd - ``` **2. It is not the first time to deploy delphinus on the config networks** Run `bash init_bridge.sh` in lerna folder (If your network is not that stable, normally we **manually** run each line inside). #### Confirm onchain status ``` node packages/solidity/clients/tools/bridge/status.js chainName ``` #### Check l1 deployment succeed ``` node packages/solidity/clients/tools/bridge/validate_l1_deployment.js ``` #### To deploy remotely for Front end, push configuration to github In order for the UI on frontend to use the same bridge and token contracts, make a new branch **CAUTION: Avoid working on main here as there may be several deployment configurations at a time.** **In `deployment`, run:** ``` git add ... // new difference git commit -m "" git checkout -b new-deployment git push ``` UI will require `deployment/config/contractsinfo.ts` to read configuration of bridge and token contract addresses. #### Change rpcSource back in eth-config.js **1. Change back `rpcSource` of `bsctestnet` and `goerli` in `deployment/config/eth-config.ts` to ankr for monitor reading** ``` { chainName: "bsctestnet", mongodbUrl: "mongodb://localhost:27017", syncEventsStep: 2000, bufferBlocks: 0, gasWarningAmount: "1", nativeCurrency: { name: "Test Binance Coin", symbol: "tBNB", // 2-6 characters long decimals: 18, }, blockExplorer: "https://testnet.bscscan.com", rpcSource: "https://data-seed-prebsc-1-s1.binance.org:8545", //rpcSource: "https://rpc.ankr.com/bsc_testnet_chapel/" + secrets.ankr_id, //ankr is only for monitor reading, for deployment, please use the above common bsc rpc source. wsSource: "wss://rpc.ankr.com/bsc_testnet_chapel/ws/" + secrets.ankr_id, privateKey: secrets.accounts.deployer.priv, monitorAccount: "", deviceId: "97", l2Account: "//Smith", enabled: testnet, isSnap: false, } ``` **2. Run `npx tsc` in `deployment`** #### Change deployment repo’s substrate-node.json file’s address **1. Access Substrate node on local machine** Substrate node default to websocket connection: port 9944 on localhost. We bind port 9944 of the docker container "delphinus-node" to port **9966** on 127.0.0.1 of the host machine in `zkcross-backend-lerna/docker-compose.yml`. `zkcross-backend-lerna/docker-compose.yml`: ``` version: "3.7" services: node: image: delphinus-node ports: - "9966:9944" volumes: - delphinus-node-data:/data restart: unless-stopped volumes: delphinus-node-data ``` **Change `packages/deployment/config/substrate-node.json` to**: ``` { "local_address": "ws://127.0.0.1", "address": "ws://127.0.0.1", "port": "9966" } ``` **2. Access Substrate node on remote host** Assume `test.example.com` is pointed to remote host on which the node is deployed. **Change `packages/deployment/config/substrate-node.json` to:** ``` { "local_address": "ws://127.0.0.1", "address": "wss://test.example.com", "port": "9944" } ``` port is set to 9944 because we set ``` test.example.com:9944 { reverse_proxy 127.0.0.1:9966 } ``` in `Caddyfile` in [Start Caddy](https://hackmd.io/7pL5Lt7YTCm_E_D0X7vOJQ?both#Start-Caddy). #### Deploy Substrate node Tips here: docker builder may take huge disk space. ```docker system df ``` can show the usage. If there are huge amount of disk space used by build cache, we can clean it by ```docker builder prune -a``` **1. Stop docker container and delete images** **Tips**: docker builder may take huge disk space. `docker system df` can show the usage. If there are huge amount of disk space used by build cache, we can clean it by `docker builder prune -a`. ``` docker ps -a docker rm [container id] docker ps -a docker volume ls docker volume rm [volume name] docker volume ls docker image ls docker image rm [repository name] docker image ls ``` Alternatively, you can clear the entire docker system (images, containers, networks and volumes) by using `docker system prune -a --volumes` **2. Custom l2 account** You can **skip** this step if you would like to use **default** config. **2.1. Modify `deployment/config/substrate-account-config.json`:** ``` { "secret_key_uri": [ "//Smith", "//Frank", "//Cindy//stash", "//Richard" ], "authorities_seeds": [ "Eve//stash" ], "pre_funded_seeds": [ "Smith", "Frank", "Cindy//stash", "Richard" ], "sudo_account_seed": "sudo" } ``` **2.2 Modify `deployment/config/eth-config.js`** Or modify `deployment/config/eth-config.ts` and run `npx tsc` in `deployment` ``` { chainName: "bsctestnet", mongodbUrl: "mongodb://localhost:27017", syncEventsStep: 2000, rpcSource: "https://bsc.getblock.io/testnet/?api_key=" + secrets.getblock_key, wsSource: "wss://bsc.getblock.io/testnet/?api_key=" + secrets.getblock_key, privateKey: secrets.accounts.deployer.priv, monitorAccount: "0xea9225F0013D64d12e75B89c19da9e3922C86556", deviceId: "97", l2Account: "//Smith", enabled: testnet, isSnap: false, }, { chainName: "goerli", mongodbUrl: "mongodb://localhost:27017", syncEventsStep: 2000, //default step 0: sync to latest directly gasWarningAmount: "1", rpcSource: "https://goerli.infura.io/v3/" + secrets.infura_id_goerli, wsSource: "wss://goerli.infura.io/ws/v3/" + secrets.infura_id_goerli, //We find ankr's goerli provider is not stable so still use infura for goerli //rpcSource: "https://rpc.ankr.com/eth_goerli/" + secrets.ankr_id, //wsSource: "wss://rpc.ankr.com/eth_goerli/ws/" + secrets.ankr_id, privateKey: secrets.accounts.deployer.priv, monitorAccount: "0xea9225F0013D64d12e75B89c19da9e3922C86556", deviceId: "5", l2Account: "//Frank", enabled: testnet, isSnap: true, }, { chainName: "cronostestnet", mongodbUrl: "mongodb://localhost:27017", syncEventsStep: 2000, rpcSource: "https://cronos-testnet-3.crypto.org:8545", wsSource: "wss://cronos-testnet-3.crypto.org:8546", privateKey: secrets.accounts.deployer.priv, monitorAccount: "0xea9225F0013D64d12e75B89c19da9e3922C86556", deviceId: "338", l2Account: "//Cindy//stash", enabled: testnet, isSnap: true, }, { chainName: "rolluxtestnet", mongodbUrl: "mongodb://localhost:27017", syncEventsStep: 20000, rpcSource: "https://testnet.rollux.com:2814/", wsSource: "", privateKey: secrets.accounts.deployer.priv, monitorAccount: "0xea9225F0013D64d12e75B89c19da9e3922C86556", deviceId: "2814", l2Account: "//Richard", enabled: testnet, isSnap: true, } ``` **3. Apply custom account to substrate-node repo** You **must do** this step even if you are using **default** config. Run `bash generate-config.sh` in `substrate-node`. **Tips**: **Do not modify** `substrate-node/generated_config` manually because `sed` in `substrate-node/generate-config.sh` will search specific string. **4. Set authorities_seeds** You can **skip** this step if you would like to use **default** config. Change `//Eve//stash` to `authorities_seeds` in `step 2.1` in `substrate-node/Dockerfile`: ``` RUN /usr/local/bin/node-swap key insert --chain dev --scheme Ed25519 --suri //Eve//stash --key-type gran && \ /usr/local/bin/node-swap key insert --chain dev --scheme Sr25519 --suri //Eve//stash --key-type aura ``` **Note**: need add "//" before `authorities_seeds`(Eve//stash). **5. Check if Accounts and Admins configs have been added successfully** Run following command in `substrate-node` ``` bash config-check.sh ``` **6. Compile and generate docker image** In `zkcross-backend-lerna` folder, run: ``` DOCKER_BUILDKIT=1 docker build . -t delphinus-node -f packages/substrate-node/Dockerfile ``` **7. Run the docker image in directory `zkcross-backend-lerna`** ``` docker-compose -f docker-compose.yml up ``` If you haven't start Caddy, please start it now. **8. Setkey and addPool in l2** Before do this, please check the [how to add pool](https://hackmd.io/7pL5Lt7YTCm_E_D0X7vOJQ?view#How-to-add-pools) section to see whether you need add additional pool for new networks. ``` node packages/monitors/src/tools/init-substrate.js ``` #### Run mongodb **1. Clear mongodb** ``` cd [DB_PATH_NAME] rm -r * ``` **2. Start mongodb** ``` mongod --dbpath [DB_PATH_NAME] ``` #### Run monitors **1. Start l1 monitors. In `monitors`, run:** ``` sh run_l1monitor.sh goerli sh run_l1monitor.sh bsctestnet sh run_l1monitor.sh cronostestnet sh run_l1monitor.sh rolluxtestnet ``` **2. Start l2 monitor. In `monitors`, run:** ``` sh run_l2monitor.sh -n // normal mode sh run_l2monitor.sh -v // verbose mode ``` `sh run_l2monitor.sh` is normal mode, too. #### Start Indexer monitor This is monitor to collect history info for UI To Start the indexer, run the following in `packages/monitors` repo ``` bash run_indexer.sh ``` To Restart the indexer and clear the mongodb collection, please run bash run_indexer.sh new and this will clear the DB, and start checking from block number 1. #### Server for History **1. For remote host deployment, you must add this to the Caddyfile in `zkcross-backend-lerna` as the UI will query this address.** ``` test.example.com:8090 { reverse_proxy 127.0.0.1:8091 } ``` **2. restart Caddy**: Stop Caddy and run: ``` sudo caddy run --config ./Caddyfile ``` **3. To start the server, from `deployment` run:** ``` npm run server ``` ### It is not the first time to deploy Delphinus Backend on the machine Assume the system is running and you want to upgrade something. #### Stop all pre running services if exists **1. Stop ui on frontend host** User cannot operate on ui now because we will upgrade the backend. **2. Stop Indexer monitor** Ui is shutdown, so we do not need indexer monitor and history server now. **3. Stop History Server** **4. Stop l1 monitors** If we stop substrateNode before l1 monitors, l2 can not handle event(deposit, ack, etc.) **5. Stop substrateNode** **6. Stop l2 monitor** l2 monitor will save pending reqs event into mongoDB, so stop it before mongoDB **7. Stop Caddy** There are no service need to access reverse proxy now. **8. Stop mongoDB** #### Environment preparing **Skip this step If you do not need to change repo branch.** ``` cd zkcross-backend-lerna // Do repo branches changing to those you want deploy // Currently getblock still have issue so need change solity truffle config file to use availabe rpc source bash redobootstrap.sh ``` #### Change rpcSource of the system for deployment If we run `node init.js` in the step [`Deploy layer1 contracts`](https://hackmd.io/7pL5Lt7YTCm_E_D0X7vOJQ?both#Deploy-layer1-contracts), the default rpcSource in `deployment/config/eth-config.ts` maybe unstable. **1. Change `rpcSource` of `bsctestnet` in `deployment/config/eth-config.ts` to `https://data-seed-prebsc-1-s1.binance.org:8545` because rpcSource provided by ankr is unstable:** ``` { chainName: "bsctestnet", mongodbUrl: "mongodb://localhost:27017", syncEventsStep: 2000, bufferBlocks: 0, gasWarningAmount: "1", nativeCurrency: { name: "Test Binance Coin", symbol: "tBNB", // 2-6 characters long decimals: 18, }, blockExplorer: "https://testnet.bscscan.com", //rpcSource: //"https://data-seed-prebsc-1-s1.binance.org:8545", rpcSource: "https://rpc.ankr.com/bsc_testnet_chapel/" + secrets.ankr_id, //ankr is only for monitor reading, for deployment, please use the above common bsc rpc source. wsSource: "wss://rpc.ankr.com/bsc_testnet_chapel/ws/" + secrets.ankr_id, privateKey: secrets.accounts.deployer.priv, monitorAccount: "", deviceId: "97", l2Account: "//Smith", enabled: testnet, isSnap: false, } ``` **2. Change `rpcSource` of `goerli` in `deployment/config/eth-config.ts` to `"https://goerli.infura.io/v3/" + secrets.infura_id_goerli` because rpcSource provided by ankr is unstable:** If `rpcSource` is already infura, skip this step. ``` { chainName: "goerli", mongodbUrl: "mongodb://localhost:27017", syncEventsStep: 2000, //default step 0: sync to latest directly bufferBlocks: 0, gasWarningAmount: "1", nativeCurrency: { name: "Goerli ETH", symbol: "GoETH", // 2-6 characters long decimals: 18, }, blockExplorer: "https://goerli.etherscan.io", rpcSource: "https://goerli.infura.io/v3/" + secrets.infura_id_goerli, wsSource: "wss://goerli.infura.io/ws/v3/" + secrets.infura_id_goerli, //We find ankr's goerli provider is not stable so still use infura for goerli //rpcSource: "https://rpc.ankr.com/eth_goerli/" + secrets.ankr_id, //wsSource: "wss://rpc.ankr.com/eth_goerli/ws/" + secrets.ankr_id, privateKey: secrets.accounts.deployer.priv, monitorAccount: "", deviceId: "5", l2Account: "//Frank", enabled: testnet, isSnap: true, } ``` If these address is still unstable, you should find other alternatives. #### Change Credential of the system **1. In `deployment/config/eth-config.ts`, update `monitorAccount` of `bsctestnet`, `goerli`, `cronostestnet` and `rolluxtestnet`.** For example, this is the configure of `bsctestnet` and there is a key `monitorAccount`. Update `monitorAccount`'s value: ``` { chainName: "bsctestnet", mongodbUrl: "mongodb://localhost:27017", syncEventsStep: 2000, bufferBlocks: 0, gasWarningAmount: "1", nativeCurrency: { name: "Test Binance Coin", symbol: "tBNB", // 2-6 characters long decimals: 18, }, blockExplorer: "https://testnet.bscscan.com", //rpcSource: //"https://data-seed-prebsc-1-s1.binance.org:8545", rpcSource: "https://rpc.ankr.com/bsc_testnet_chapel/" + secrets.ankr_id, //ankr is only for monitor reading, for deployment, please use the above common bsc rpc source. wsSource: "wss://rpc.ankr.com/bsc_testnet_chapel/ws/" + secrets.ankr_id, privateKey: secrets.accounts.deployer.priv, monitorAccount: "", // update here deviceId: "97", l2Account: "//Smith", enabled: testnet, isSnap: false, } ``` **2. Update deployer priv key in `deployment/config/monitor-secrets.json`** ``` { "ankr_id":"", "infura_id_goerli":"", "getblock_key_bsctestnet":"", "getblock_key_goerli":"", "accounts": { "deployer": { "priv": "" // update here }, "tester": { "priv":"" }, "tester2": { "priv":"" }, "monitor": { "priv":"" } } } ``` **3. Run `npx tsx` in `deployment`** #### Start Caddy If you want to run Substrate node on **remote host**. A remote Substrate node can be accessible **only** after we set up a secure proxy for websocket connections. The TLS certificate is obtained automatically with `Caddy`. **1. Modify `Caddyfile` in `zkcross-backend-lerna`** ``` { auto_https disable_redirects } test.example.com:9944 { reverse_proxy 127.0.0.1:9966 } test.example.com:8090 { reverse_proxy 127.0.0.1:8091 } ``` **2. Start Caddy** ``` sudo caddy run --config ./Caddyfile ``` If we are using `127.0.0.1` for local testing, caddy can be ignored. #### Update zkcross-backend-lerna to latest version Either if you have 100% confidence or want to custom adjusting, you can just reset deployment, solidty, substrateNode, ts-sdk, ui, zkp to the version you want Or you can just remove node_modules and packages in `zkcross-backend-lerna`, reset the `zkcross-backend-lerna` to latest main branch and do the setup again. #### Setup zkp and get verifier contract **1. Create ptau files**. **Skip this step if `pot23_final.ptau` exists in `zkp/circom` unless you need other ptau file such as `pot20_final.ptau`** In `zkp/circom`, run: ``` bash tools/setup.sh ``` **2. Create `verifier.sol`** In `zkp/circom`, run: ``` bash tools/compile.sh ``` #### Deploy layer1 contracts **0. Use tool to check we have enough eth for the testnetworks** In `zkcross-backend-lerna/`, run: `node packages/monitors/src/tools/ethBalanceCheck/eth-balance-check-tool.js goerli` `node packages/monitors/src/tools/ethBalanceCheck/eth-balance-check-tool.js bsctestnet` `node packages/monitors/src/tools/ethBalanceCheck/eth-balance-check-tool.js cronostestnet` `node packages/monitors/src/tools/ethBalanceCheck/eth-balance-check-tool.js rolluxtestnet` to check. Better both are above 1 unit. **1. It is not the first time to deploy delphinus on the config networks** Run `bash init_bridge.sh` in lerna folder (If your network is not that stable, normally we **manually** run each line inside). #### Confirm onchain status ``` node packages/solidity/clients/tools/bridge/status.js chainName ``` #### Check l1 deployment succeed ``` node packages/solidity/clients/tools/bridge/validate_l1_deployment.js ``` #### To deploy remotely for Front end, push configuration to github In order for the UI to use the same bridge and token contracts, please make a new branch for each deployment and push to this. **CAUTION: Avoid working on main here as there may be several deployment configurations at a time.** **Run following commands in `deployment`:** ``` git add ... git commit -m "" git checkout -b user-deployment git push ``` If you'd like, check that the `deployment/config/contracts-info.json` file contains the correct addresses in the `solidity/build/contracts/Bridge.json` From UI, we should use this new custom branch as a reference for **ALL** contract addresses. #### Change rpcSource back in eth-config.js **1. Change back `rpcSource` of `bsctestnet` and `goerli` in `deployment/config/eth-config.ts` to ankr for monitor reading** ``` { chainName: "bsctestnet", mongodbUrl: "mongodb://localhost:27017", syncEventsStep: 2000, bufferBlocks: 0, gasWarningAmount: "1", nativeCurrency: { name: "Test Binance Coin", symbol: "tBNB", // 2-6 characters long decimals: 18, }, blockExplorer: "https://testnet.bscscan.com", rpcSource: "https://data-seed-prebsc-1-s1.binance.org:8545", //rpcSource: "https://rpc.ankr.com/bsc_testnet_chapel/" + secrets.ankr_id, //ankr is only for monitor reading, for deployment, please use the above common bsc rpc source. wsSource: "wss://rpc.ankr.com/bsc_testnet_chapel/ws/" + secrets.ankr_id, privateKey: secrets.accounts.deployer.priv, monitorAccount: "", deviceId: "97", l2Account: "//Smith", enabled: testnet, isSnap: false, } ``` **2. Run `npx tsc` in `deployment`** #### Change deployment repo’s substrate-node.json file’s address **1. Access Substrate node on local machine** Substrate node default to websocket connection: port 9944 on localhost. We bind port 9944 of the docker container "delphinus-node" to port **9966** on 127.0.0.1 of the host machine in `zkcross-backend-lerna/docker-compose.yml`. `zkcross-backend-lerna/docker-compose.yml`: ``` version: "3.7" services: node: image: delphinus-node ports: - "9966:9944" volumes: - delphinus-node-data:/data restart: unless-stopped volumes: delphinus-node-data ``` **Change `packages/deployment/config/substrate-node.json` to**: ``` { "local_address": "ws://127.0.0.1", "address": "ws://127.0.0.1", "port": "9966" } ``` **2. Access Substrate node on remote host** Assume `test.example.com` is pointed to remote host on which the node is deployed. **Change `packages/deployment/config/substrate-node.json` to:** ``` { "local_address": "ws://127.0.0.1", "address": "wss://test.example.com", "port": "9944" } ``` port is set to 9944 because we set ``` test.example.com:9944 { reverse_proxy 127.0.0.1:9966 } ``` in `Caddyfile` in [Start Caddy](https://hackmd.io/7pL5Lt7YTCm_E_D0X7vOJQ?both#Start-Caddy1). #### Deploy Substrate node Tips here: docker builder may take huge disk space. ```docker system df ``` can show the usage. If there are huge amount of disk space used by build cache, we can clean it by ```docker builder prune -a``` **1. Stop docker container and delete images** **Tips**: docker builder may take huge disk space. `docker system df` can show the usage. If there are huge amount of disk space used by build cache, we can clean it by `docker builder prune -a`. ``` docker ps -a docker rm [container id] docker ps -a docker volume ls docker volume rm [volume name] docker volume ls docker image ls docker image rm [repository name] docker image ls ``` Alternatively, you can clear the entire docker system (images, containers, networks and volumes) by using `docker system prune -a --volumes` **2. Custom l2 account** You can **skip** this step if you would like to use **default** config. **2.1. Modify `deployment/config/substrate-account-config.json`:** ``` { "secret_key_uri": [ "//Smith", "//Frank", "//Cindy//stash", "//Richard" ], "authorities_seeds": [ "Eve//stash" ], "pre_funded_seeds": [ "Smith", "Frank", "Cindy//stash", "Richard" ], "sudo_account_seed": "sudo" } ``` **2.2 Modify `deployment/config/eth-config.js`** Or modify `deployment/config/eth-config.ts` and run `npx tsc` in `deployment` ``` { chainName: "bsctestnet", mongodbUrl: "mongodb://localhost:27017", syncEventsStep: 2000, rpcSource: "https://bsc.getblock.io/testnet/?api_key=" + secrets.getblock_key, wsSource: "wss://bsc.getblock.io/testnet/?api_key=" + secrets.getblock_key, privateKey: secrets.accounts.deployer.priv, monitorAccount: "0xea9225F0013D64d12e75B89c19da9e3922C86556", deviceId: "97", l2Account: "//Smith", enabled: testnet, isSnap: false, }, { chainName: "goerli", mongodbUrl: "mongodb://localhost:27017", syncEventsStep: 2000, //default step 0: sync to latest directly gasWarningAmount: "1", rpcSource: "https://goerli.infura.io/v3/" + secrets.infura_id_goerli, wsSource: "wss://goerli.infura.io/ws/v3/" + secrets.infura_id_goerli, //We find ankr's goerli provider is not stable so still use infura for goerli //rpcSource: "https://rpc.ankr.com/eth_goerli/" + secrets.ankr_id, //wsSource: "wss://rpc.ankr.com/eth_goerli/ws/" + secrets.ankr_id, privateKey: secrets.accounts.deployer.priv, monitorAccount: "0xea9225F0013D64d12e75B89c19da9e3922C86556", deviceId: "5", l2Account: "//Frank", enabled: testnet, isSnap: true, }, { chainName: "cronostestnet", mongodbUrl: "mongodb://localhost:27017", syncEventsStep: 2000, rpcSource: "https://cronos-testnet-3.crypto.org:8545", wsSource: "wss://cronos-testnet-3.crypto.org:8546", privateKey: secrets.accounts.deployer.priv, monitorAccount: "0xea9225F0013D64d12e75B89c19da9e3922C86556", deviceId: "338", l2Account: "//Cindy//stash", enabled: testnet, isSnap: true, }, { chainName: "rolluxtestnet", mongodbUrl: "mongodb://localhost:27017", syncEventsStep: 20000, rpcSource: "https://testnet.rollux.com:2814/", wsSource: "", privateKey: secrets.accounts.deployer.priv, monitorAccount: "0xea9225F0013D64d12e75B89c19da9e3922C86556", deviceId: "2814", l2Account: "//Richard", enabled: testnet, isSnap: true, } ``` **3. Apply custom account to substrate-node repo** You **must do** this step even if you are using **default** config. Run `bash generate-config.sh` in `substrate-node`. **Tips**: **Do not modify** `substrate-node/generated_config` manually because `sed` in `substrate-node/generate-config.sh` will search specific string. **4. Set authorities_seeds** You can **skip** this step if you would like to use **default** config. Change `//Eve//stash` to `authorities_seeds` in `step 2.1` in `substrate-node/Dockerfile`: ``` RUN /usr/local/bin/node-swap key insert --chain dev --scheme Ed25519 --suri //Eve//stash --key-type gran && \ /usr/local/bin/node-swap key insert --chain dev --scheme Sr25519 --suri //Eve//stash --key-type aura ``` **Note**: need add "//" before `authorities_seeds`(Eve//stash). **5. Check if Accounts and Admins configs have been added successfully** Run following command in `substrate-node` ``` bash config-check.sh ``` **6. Compile and generate docker image** In `zkcross-backend-lerna` folder, run: ``` DOCKER_BUILDKIT=1 docker build . -t delphinus-node -f packages/substrate-node/Dockerfile ``` **7. Run the docker image in directory `zkcross-backend-lerna`** ``` docker-compose -f docker-compose.yml up ``` If you haven't start Caddy, please start it now. **8. Setkey and addPool in l2** Before do this, please check the [how to add pool](https://hackmd.io/7pL5Lt7YTCm_E_D0X7vOJQ?view#How-to-add-pools) section to see whether you need add additional pool for new networks. ``` node packages/monitors/src/tools/init-substrate.js ``` #### Run mongodb **1. Clear mongodb** **Skip this step if you still need previous data** ``` cd [DB_PATH_NAME] rm -r * ``` **2. Start mongodb** ``` mongod --dbpath [DB_PATH_NAME] ``` #### Run monitors **1. Start l1 monitors. In `monitors`, run:** ``` sh run_l1monitor.sh goerli sh run_l1monitor.sh bsctestnet sh run_l1monitor.sh cronostestnet sh run_l1monitor.sh rolluxtestnet ``` **2. Start l2 monitor. In `monitors`, run:** ``` sh run_l2monitor.sh -n // normal mode sh run_l2monitor.sh -v // verbose mode ``` `sh run_l2monitor.sh` is normal mode, too. #### Start Indexer monitor This is monitor to collect history info for UI To Start the indexer, run the following in `packages/monitors` repo ``` bash run_indexer.sh ``` To Restart the indexer and clear the mongodb collection, please run bash run_indexer.sh new and this will clear the DB, and start checking from block number 1. #### Server for History **1. For remote host deployment, you must add this to the Caddyfile in `zkcross-backend-lerna` as the UI will query this address.** ``` test.example.com:8090 { reverse_proxy 127.0.0.1:8091 } ``` **2. restart Caddy**: Stop Caddy and run: ``` sudo caddy run --config ./Caddyfile ``` **3. To start the server, from `deployment` run:** ``` npm run server ``` ## Deploy frontend **backend need to be deployed and start first as we need grab info from backend.** If it is the first time for you to deploy the system, visit [first time to deploy frontend](https://hackmd.io/7pL5Lt7YTCm_E_D0X7vOJQ?view#It-is-the-first-time-to-deploy-Delphinus-Frontend-on-the-machine). If you just want to upgrade the system which is already deployed and works well, visit [not the first time to deploy frontend](https://hackmd.io/7pL5Lt7YTCm_E_D0X7vOJQ?view#It-is-not-the-first-time-to-deploy-Delphinus-Frontend-on-the-machine). ### It is the first time to deploy Delphinus Frontend on the machine #### Modules which will be installed and deployed **UI** is the only service which will be deployed on frontend host. #### Environment preparing ``` git clone git@github.com:DelphinusLab/zkcross-frontend-lerna.git cd zkcross-frontend-lerna bash environment_linux.sh restart your shell to update environment variable(such as rustup) // wasm-pack will not be installed if environment variable about rust is not updated bash environment_linux.sh bash setup-frontend.sh // Do repo branches changing to those you want deploy, especially change the UI branch to what you want (RIO or richard/zkpnew). // Do not forget to change UI repo to correct branch before redo setup bash redobootstrap.sh ``` #### Change deployment repo to the branch new-deployment The branch is made in [here](https://hackmd.io/7pL5Lt7YTCm_E_D0X7vOJQ?both#To-deploy-remotely-for-Front-end-push-configuration-to-github). **1. Change deployment branch to new-deployment** **2. Run `npx tsc` in `deployment`** #### Set Server URL/Address For UI to query L2 transaction history and fetch contract information from the history server which will be deployed on the backend host, **modify `deployment/config/server.json`**: **1. If history server is working locally(that is, you do not deploy the backend on another host)** ``` { "address": "http://127.0.0.1:8091", "port": "8091" } ``` **2. If the server is deployed on a remote host** The address must be changed to your server URL which is used by Caddy. For example, `https://test.example.com:8090` (The port number may or may not be required depending on Caddy configuration) ``` { "address": "https://test.example.com:8090", "port": "8091" } ``` #### Pull latest contract information from the Server **In `deployment`, run:** `bash setup-config.sh` to fetch the latest contract information that our substrate-node is also referencing. #### Set Node URL/Address For UI to read the substrate node address, **modify `deployment/config/substrate-node.json`:** **1. If your node is deployed locally(that is, you do not deploy the backend on another host)** Substrate node default websocket connection: port 9944 on localhost. We bind port 9944 of the docker container “delphinus-node” to port **9966** on 127.0.0.1 of the host machine (check `zkcross-backend-lerna/docker-compose.yml` on backend host). ``` { "local_address": "ws://127.0.0.1", "address": "ws://127.0.0.1", "port": "9966" } ``` **2. If your node is deployed on a remote host** Assume test.example.com is pointed to remote host on which the node is deployed. ``` { "local_address": "ws://127.0.0.1", "address": `wss://test.example.com` "port": "9944" } ``` Here we set the port to 9944 because ``` test.example.com:9944 { reverse_proxy 127.0.0.1:9966 } ``` in `Caddyfile` of backend. #### Start the UI **In `ui` repo, run:** `npm run start` main branches: * `main` * ZKC - `richard/zkpnew` * RIO - `rio` Choose the branch you want to use. For UI to utilise transaction history, please ``` git checkout history ``` in `ts-sdk` and `ui`. #### Access Delphinus user interface **Local machine:** Visit "http://localhost:3000" in the browser and do testing: * Activate * Charge * Deposit * WithDraw * ... **Server** Visit Here is the document of Delphinus user interface: https://github.com/DelphinusLab/delphinus-training/blob/main/Documents/DelphinusUI.md. ### It is not the first time to deploy Delphinus Frontend on the machine #### Stop all pre running services if exists Stop ui on frontend host #### Environment preparing **Skip this step If you do not need to change repo branch.** ``` cd zkcross-frontend-lerna // Do repo branches changing to those you want deploy, especially change the UI branch to what you want (RIO or richard/zkpnew). // Do not forget to change UI repo to correct branch before redo setup bash redobootstrap.sh ``` #### Change deployment repo to the branch user-deployment The branch is made in [here](https://hackmd.io/7pL5Lt7YTCm_E_D0X7vOJQ?view#To-deploy-remotely-for-Front-end-push-configuration-to-github1). **1. Change deployment branch to user-deployment** **2. Run `npx tsc` in `deployment`** #### Set Server URL/Address For UI to query L2 transaction history and fetch contract information from the history server which will be deployed on the backend host, **modify `deployment/config/server.json`**: **1. If history server is working locally(that is, you do not deploy the backend on another host)** ``` { "address": "http://127.0.0.1:8091", "port": "8091" } ``` **2. If the server is deployed on a remote host** The address must be changed to your server URL which is used by Caddy. For example, `https://test.example.com:8090` (The port number may or may not be required depending on Caddy configuration) ``` { "address": "https://test.example.com:8090", "port": "8091" } ``` #### Pull latest contract information from the Server **In `deployment`, run:** `bash setup-config.sh` to fetch the latest contract information that our substrate-node is also referencing. #### Set Node URL/Address For UI to read the substrate node address, **modify `deployment/config/substrate-node.json`:** **1. If your node is deployed locally(that is, you do not deploy the backend on another host)** Substrate node default websocket connection: port 9944 on localhost. We bind port 9944 of the docker container “delphinus-node” to port **9966** on 127.0.0.1 of the host machine (check `zkcross-backend-lerna/docker-compose.yml` on backend host). ``` { "local_address": "ws://127.0.0.1", "address": "ws://127.0.0.1", "port": "9966" } ``` **2. If your node is deployed on a remote host** Assume test.example.com is pointed to remote host on which the node is deployed. ``` { "local_address": "ws://127.0.0.1", "address": `wss://test.example.com` "port": "9944" } ``` Here we set the port to 9944 because ``` test.example.com:9944 { reverse_proxy 127.0.0.1:9966 } ``` in `Caddyfile` of backend. #### Start the UI **In `ui` repo, run:** `npm run start` main branches: * `main` * ZKC - `richard/zkpnew` * RIO - `rio` Choose the branch you want to use. For UI to utilise transaction history, please ``` git checkout history ``` in `ts-sdk` and `ui`. #### Access Delphinus user interface **Local machine:** Visit "http://localhost:3000" in the browser and do testing: * Activate * Charge * Deposit * WithDraw * ... **Server** Visit Here is the document of Delphinus user interface: https://github.com/DelphinusLab/delphinus-training/blob/main/Documents/DelphinusUI.md. ## Additional info * Better use latest npm version. We find some old version of npm and node will not work. (npm 8.13.2,node 16.14.2 works fine). * If you run `node-swap` locally, don't forget to run `./node-swap purge-chain --dev` and insert session key before `./node-swap --dev`. * Visit [Change code to add extra network](https://hackmd.io/7pL5Lt7YTCm_E_D0X7vOJQ?view#Change-code-to-add-extra-network) to add new network. * Visit [How to add pools](https://hackmd.io/7pL5Lt7YTCm_E_D0X7vOJQ?view#How-to-add-pools) to add new pool. * Visit [How to do deployment on feature branch](https://hackmd.io/7pL5Lt7YTCm_E_D0X7vOJQ?view#How-to-do-deployment-on-feature-branch) to use a repo's feature branch. ## Change code to add extra network Assume extra network is exampletestnet **1. Modify `delphinus-lerna/init_bridge.sh` to** ``` set -e if [ ! -f initbridge.lock ]; then cp packages/zkp/circom/verifier.sol packages/solidity/contracts/ZKPVerifier.sol sed -i "s/\^0.6.11/^0.8.0/" packages/solidity/contracts/ZKPVerifier.sol # Dont have to migrate the tokens again cd packages/solidity npx truffle migrate --f 2 --to 2 --network goerli npx truffle migrate --f 2 --to 2 --network bsctestnet npx truffle migrate --f 2 --to 2 --network cronostestnet npx truffle migrate --f 2 --to 2 --network rolluxtestnet npx truffle migrate --f 2 --to 2 --network exampletestnet cd - cd packages/solidity/clients/ node config-contracts-info.js cd - cd packages/solidity/clients/tools/bridge node init.js goerli node init.js bsctestnet node init.js cronostestnet node init.js rolluxtestnet node init.js exampletestnet cd - touch initbridge.lock fi echo "please start monitors" ``` **2. Insert a new config in `networks` in `solidity/truffle-config.js`** ``` development: { host: "127.0.0.1", // Localhost (default: none) port: 8545, // Standard Ethereum port (default: none) network_id: "*", // Any network (default: none) from: "0x6f6ef6dfe681b6593ddf27da3bfde22083aef88b", gas: 3100000, // Gas sent with each transaction (default: ~6700000) websocket: true // Enable EventEmitter interface for web3 (default: false) }, testnet1: { host: "127.0.0.1", // Localhost (default: none) port: 8545, // Standard Ethereum port (default: none) network_id: "*", // Any network (default: none) from: "0x6f6ef6dfe681b6593ddf27da3bfde22083aef88b", gas: 3100000, // Gas sent with each transaction (default: ~6700000) websocket: true // Enable EventEmitter interface for web3 (default: false) }, testnet2: { host: "127.0.0.1", // Localhost (default: none) port: 8745, // Standard Ethereum port (default: none) network_id: "*", // Any network (default: none) from: "0x6f6ef6dfe681b6593ddf27da3bfde22083aef88b", gas: 3100000, // Gas sent with each transaction (default: ~6700000) websocket: true // Enable EventEmitter interface for web3 (default: false) }, goerli: { //eth testnet provider: () => new HDWalletProvider(secrets.accounts.deployer.priv, http_provider("https://eth.getblock.io/goerli/?api_key=" + secrets.getblock_key_goerli) ), network_id: 5, // goerli's id gas: 5500000, // goerli has a lower block limit than mainnet confirmations: 2, // # of confs to wait between deployments. (default: 0) timeoutBlocks: 400, // # of blocks before a deployment times out (minimum/default: 50) skipDryRun: true // Skip dry run before migrations? (default: false for public nets ) }, bsctestnet: { //bsc provider: () => new HDWalletProvider(secrets.accounts.deployer.priv, http_provider(`https://data-seed-prebsc-1-s1.binance.org:8545`) //http_provider("https://bsc.getblock.io/testnet/?api_key="+secrets.getblock_key) ), network_id: 97, confirmations: 10, timeoutBlocks: 200, skipDryRun: true }, cronostestnet: { provider: () => new HDWalletProvider(secrets.accounts.deployer.priv, "wss://cronos-testnet-3.crypto.org:8546"), network_id: 338, confirmations: 2, timeoutBlocks: 200, skipDryRun: true }, rolluxtestnet: { provider: () => new HDWalletProvider(secrets.accounts.deployer.priv, http_provider("https://testnet.rollux.com:2814/")), network_id: 2814, confirmations: 2, timeoutBlocks: 200, skipDryRun: true }, exampletestnet: { provider: () => new HDWalletProvider(secrets.accounts.deployer.priv, ""), network_id:, confirmations: 2, timeoutBlocks: 200, skipDryRun: true } ``` You will find 5 objects in `networks` of files in `solidity/build/contracts` after `npx truffle migrate`. (Of course you will find empty networks if `solidity/migrations` does not deploy the contract) ![](https://i.imgur.com/QP2LsJY.png) **3. Insert a new config in `solidity/clients/config-contracts-info.js`** ``` tokens: [ { chainId: "15", address: (_a = TokenInfo.networks["15"]) === null || _a === void 0 ? void 0 : _a.address.replace("0x", ""), wei: 12, name: "tToken" }, { chainId: "15", address: (_b = GasTokenInfo.networks["15"]) === null || _b === void 0 ? void 0 : _b.address.replace("0x", ""), wei: 12, name: "rio" }, { chainId: "16", address: (_c = TokenInfo.networks["16"]) === null || _c === void 0 ? void 0 : _c.address.replace("0x", ""), wei: 12, name: "sToken", }, { chainId: "5", address: (_d = TokenInfo.networks["5"]) === null || _d === void 0 ? void 0 : _d.address.replace("0x", ""), wei: 12, name: "tToken" }, { chainId: "5", address: (_e = GasTokenInfo.networks["5"]) === null || _e === void 0 ? void 0 : _e.address.replace("0x", ""), wei: 12, name: "rio", }, { chainId: "97", address: (_f = TokenInfo.networks["97"]) === null || _f === void 0 ? void 0 : _f.address.replace("0x", ""), wei: 12, name: "tToken" }, { chainId: "338", address: (_g = TokenInfo.networks["338"]) === null || _g === void 0 ? void 0 : _g.address.replace("0x", ""), wei: 12, name: "tToken" }, { chainId: "2814", address: (_h = TokenInfo.networks["2814"]) === null || _h === void 0 ? void 0 : _h.address.replace("0x", ""), wei: 12, name: "tToken" }, { chainId: "", address: (_h = TokenInfo.networks[""]) === null || _h === void 0 ? void 0 : _h.address.replace("0x", ""), wei: 12, name: "tToken" } ] ``` **Add name for new testnet in `solidity/clients/config-contracts-info.ts`:** ``` export const Chains : Record<string, string> = { "15": "local-test-net1", "16": "local-test-net2", "5": "goerli", "97": "bsctestnet", "338": "cronostestnet", "2814": "rolluxtestnet" "chainNumber": "exampletestnet" } ``` **4. Add new seed into `deployment/config/substrate-account-config.json`** ``` { "secret_key_uri": [ "//Smith", "//Frank", "//Cindy//stash", "//Richard", "//exampleAccount" ], "authorities_seeds": [ "Eve//stash" ], "pre_funded_seeds": [ "Smith", "Frank", "Cindy//stash", "/Richard", "exampleAccount" ], "sudo_account_seed": "sudo" } ``` **5. Add new config into `deployment/config/eth-config.js`** ``` { chainName: "bsctestnet", mongodbUrl: "mongodb://localhost:27017", syncEventsStep: 2000, rpcSource: "https://bsc.getblock.io/testnet/?api_key=" + secrets.getblock_key, wsSource: "wss://bsc.getblock.io/testnet/?api_key=" + secrets.getblock_key, privateKey: secrets.accounts.deployer.priv, monitorAccount: "0x6f6ef6dfe681b6593ddf27da3bfde22083aef88b", deviceId: "97", l2Account: "//Smith", enabled: testnet, isSnap: false, }, { chainName: "goerli", mongodbUrl: "mongodb://localhost:27017", syncEventsStep: 2000, //default step 0: sync to latest directly gasWarningAmount: "1", rpcSource: "https://goerli.infura.io/v3/" + secrets.infura_id_goerli, wsSource: "wss://goerli.infura.io/ws/v3/" + secrets.infura_id_goerli, //We find ankr's goerli provider is not stable so still use infura for goerli //rpcSource: "https://rpc.ankr.com/eth_goerli/" + secrets.ankr_id, //wsSource: "wss://rpc.ankr.com/eth_goerli/ws/" + secrets.ankr_id, privateKey: secrets.accounts.deployer.priv, monitorAccount: "0x6f6eF6Dfe681b6593Ddf27da3BfDe22083AEF88b", deviceId: "5", l2Account: "//Frank", enabled: testnet, isSnap: true, }, { chainName: "cronostestnet", mongodbUrl: "mongodb://localhost:27017", syncEventsStep: 2000, rpcSource: "https://cronos-testnet-3.crypto.org:8545", wsSource: "wss://cronos-testnet-3.crypto.org:8546", privateKey: secrets.accounts.deployer.priv, monitorAccount: "0x6f6ef6dfe681b6593ddf27da3bfde22083aef88b", deviceId: "338", l2Account: "//Cindy//stash", enabled: testnet, isSnap: true, }, { chainName: "rolluxtestnet", mongodbUrl: "mongodb://localhost:27017", syncEventsStep: 20000, rpcSource: "https://testnet.rollux.com:2814/", wsSource: "", privateKey: secrets.accounts.deployer.priv, monitorAccount: "0x6f6ef6dfe681b6593ddf27da3bfde22083aef88b", deviceId: "2814", l2Account: "//Richard", enabled: testnet, isSnap: true, }, { chainName: "exampletestnet", mongodbUrl: "mongodb://localhost:27017", syncEventsStep: 20000, rpcSource: "", wsSource: "", privateKey: secrets.accounts.deployer.priv, monitorAccount: "0x6f6ef6dfe681b6593ddf27da3bfde22083aef88b", deviceId: "", l2Account: "//exampleAccount", enabled: testnet, isSnap: true, } ``` **Explanations** **1. Explanation to keys in config** * `secret_key_uri` is seed of `admins` in `substrate-node/runtime/admins_config.rs`. Only `secret_key_uri` has prefix "//". * `authorities_seeds` is accounts having authority to create and finalize blocks. Be sure to use unique seeds in this field. If two validators have the same keys, they produce conflicting blocks. * `l2Account` in `deployment/config/eth-config.js` is `origin` of functions in `substrate-node/pallets/swap`. `l2Account` must have enough balance to invoke functions in l2, so we should add it to `pre_funded_seeds`. **Do not set same `l2Account`** for different networks otherwise we don't know which l1 network is the origin of funtions in l2. * `sudo_account_seed` is the account we use to execute functions that require a Root call. Only one account can be the sudo key at a time. * `secret_key_uri`, `pre_funded_seeds`, and `l2Account` must be the same. Third party is not allowed to invoke functions such as `add_pool`. * `//Smith` in `secret_key_uri` is the same as `Smith` in `pre_funded_seeds` because input of `keyring.addFromUri`(line 85 of `monitors/src/substrate/client.ts`) and `get_from_seed`(line 22 of `substrate-node/node/src/chain_spec.rs`)/`get_account_id_from_seed`(line 31 of `substrate-node/node/src/chain_spec.rs`) is different. ![](https://i.imgur.com/QjDlTzY.png) * You can use two seeds form: `//Alice` or `//Alice//stash`. **Do not use** `//Alice/stash` which is not supported by chain specification of substrate node. * Block finalization requires at least **two-thirds of the validators** to add their keys to their respective keystores. For example, if there are 4 seeds in `authorities_seeds`, you should add `key insert` in `Dockerfile` and run at least 3(4 * 2 / 3) nodes. **2. Explanation to `/usr/local/bin/node-swap key insert --chain dev --scheme Ed25519 --suri //Eve --key-type gran`** * Session keys are used by validators to sign consensus-related messages. `key insert` will insert session keys to keystore. * `--chain dev` specifies insert keys to keystore of dev mode. * `--scheme` specifies signing algorithms(Ed25519 for grandpa and Sr25519 for aura). * `--suri` specifies seed of key. * `--key-type` specifies key type. The aura key type is required to enable block production. The gran key type is required to enable block finalization. ## How to add pools ### Default pools after standard init Add tToken in `config-contracts-info.ts` in `solidity/clients` folder ``` { chainId: "***", address:TokenInfo.networks["***"]?.address.replace("0x", ""), wei:12, name:"tToken" } ``` ### How to add pools for extra token pair Add extra token in `contractsinfo.ts` in `deployment/config` folder ``` { chainId: "***", name: "****", wei: **, address: "***************************" } ``` ## How to do deployment on feature branch 1. If lerna repo need feature branch, checkout feature branch first. 2. do `bash setup.sh` 3. go to the packages/[repo] folders and get the branch to the feature branch you want 4. got to the lerna root folder and do `bash redobootstrap.sh` 5. Then you can do the deployment as normal